#!/usr/bin/env python3
"""Seed the Take89 (Montreuil) master EDL from PLN's 2026-06-05 listening pass.

Turns the prose ear-feedback (performance_notes.md) into a typed, validated
MasterEDL — each decision replayable by a renderer AND usable as ground-truth for
the boundary/edge detectors (#25/#31). Re-run to regenerate; edit here, not the JSON.
"""
from datetime import date
from pathlib import Path

from models import (EditKind, EditOp, MasterEDL, MasterEdit, Provenance)

HERE = Path(__file__).parent
OUT = HERE / "master_edl_take89.json"
WH = "WH-1000XM5+phone"


def ear(loc):
    return Provenance(source="ear", locator=loc, as_of=date(2026, 6, 5),
                      note="phone + WH-1000XM5 resplit review")


EDITS = [
    MasterEdit(track_no=2, name="Piment Brésilien",
               tidal="live/collab/raph/piment_bresilien.tidal",
               op=EditOp.eq_highshelf, at="whole", value=-2.0, kind=EditKind.harsh,
               device=WH, provenance=ear("aigus perçants sur mobile quand le lead/keys "
               "montent + FX forts — tame ~4-8kHz, dynamic"),
               reason="highs piercing on mobile when lead/keys climb high under heavy FX"),
    MasterEdit(track_no=2, name="Piment Brésilien → Take 5 Drops",
               op=EditOp.trim_out, at="-5", kind=EditKind.bad_cut, device=WH,
               provenance=ear("on entend le changement de basse de la suivante AVANT le cut"),
               reason="boundary ~5s too early: next track's bass change bleeds into tail"),
    MasterEdit(track_no=3, name="Take 5 Drops → Super Sunny Side Up",
               tidal="live/midi/nova/lounge/take_5_drops.tidal",
               op=EditOp.crossfade, at="end", kind=EditKind.transition, device=WH,
               provenance=ear("silence à la fin de la 3 puis 4 démarre direct — abrupt"),
               reason="hard silence→onset butt-join; add short crossfade or trim-to-groove"),
    MasterEdit(track_no=4, name="Super Sunny Side Up",
               tidal="live/midi/nova/lounge/sunny_side_up.tidal",
               op=EditOp.fade_out, at="4:00", to="4:09", kind=EditKind.laborious,
               device=WH, provenance=ear("se terminerait à 4:00, ou 4:09 sur petit fade"),
               reason="outro laborious — end at 4:00, or 4:09 with a small fade"),
    MasterEdit(track_no=5, name="W.I.P. W.A.P.",
               tidal="live/midi/nova/dnb/wap.tidal",
               op=EditOp.trim_in, at="1.0", kind=EditKind.bad_cut, device=WH,
               provenance=ear("commence sur 1s+ de break puis vocal — start au vocal"),
               reason="trim ~1s break intro, start directly on the vocal"),
    MasterEdit(track_no=5, name="W.I.P. W.A.P.",
               tidal="live/midi/nova/dnb/wap.tidal",
               op=EditOp.investigate, at="3:29", to="3:31", kind=EditKind.anomaly,
               device=WH, provenance=ear("silence bizarre 3:29-3:31"),
               reason="~2s odd silence/dropout — investigate (stem gap? mute glitch?)"),
    MasterEdit(track_no=5, name="W.I.P. W.A.P. → 'Plosive",
               tidal="live/midi/nova/dnb/wap.tidal",
               op=EditOp.crossfade, at="3:26", to="3:45", kind=EditKind.transition,
               device=WH, provenance=ear("bordel jusqu'à 3:42; crossfade direct 3:26→3:45+ ; "
               "PLN veut tester des fragments"),
               reason="messy tail 3:31-3:42; test fragment crossfades ~3:26→3:45 into 'Plosive"),
    MasterEdit(track_no=6, name="'Plosive",
               tidal="live/midi/nova/dnb/plosive.tidal",
               op=EditOp.gain, at="kick", value=-2.0, kind=EditKind.level, device=WH,
               provenance=ear("kick trop fort vs basses+mélodie; trop loud vs le kick des "
               "autres pistes — set-relative match"),
               reason="kick hotter than rest of set; match kick gain across tracks"),
    MasterEdit(track_no=6, name="'Plosive → Jeudi Drill",
               tidal="live/midi/nova/dnb/plosive.tidal",
               op=EditOp.trim_out, at="2:59", kind=EditKind.bad_cut, device=WH,
               provenance=ear("2:59 'Plosive ends, next sound is Bogdan Jeudrill sample"),
               reason="runs into T7 Jeudi Drill (Bogdan voice) — cut the next-track head"),
]


def main():
    edl = MasterEDL(take="Take89", gig="2026/montreuil-algorave", edits=EDITS)
    OUT.write_text(edl.model_dump_json(indent=1))
    n_label = sum(1 for e in EDITS if e.kind == EditKind.bad_cut)
    print(f"✓ {OUT}  ({len(EDITS)} edits, {n_label} bad_cut ground-truth labels)")
    for e in edl.edits:
        print(f"  T{e.track_no or '?'} {e.name:<32} {e.op.value:<12} @{e.at:<6} "
              f"[{e.kind.value}]")


if __name__ == "__main__":
    main()
