@signalsandsorcery/plugin-sdk 2.35.5 → 2.35.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -7017,6 +7017,14 @@ function useGeneratorPanelCore({
7017
7017
  ...adapter.createTrackOptions()
7018
7018
  });
7019
7019
  setTracks((prev) => [...prev, newTrackState(handle)]);
7020
+ if (adapter.onTrackCreated) {
7021
+ try {
7022
+ await adapter.onTrackCreated(handle, { activeSceneId, trackDataKey });
7023
+ } catch (err) {
7024
+ console.warn(`[${logTag}] onTrackCreated failed (non-fatal):`, err);
7025
+ }
7026
+ await loadTracks(true);
7027
+ }
7020
7028
  onExpandSelf?.();
7021
7029
  setTimeout(() => {
7022
7030
  const inputs = document.querySelectorAll(
@@ -7033,7 +7041,7 @@ function useGeneratorPanelCore({
7033
7041
  isAddingTrackRef.current = false;
7034
7042
  setIsAddingTrack(false);
7035
7043
  }
7036
- }, [host, adapter, identity, activeSceneId, isConnected, isAuthenticated, tracks.length, onExpandSelf]);
7044
+ }, [host, adapter, identity, activeSceneId, isConnected, isAuthenticated, tracks.length, onExpandSelf, loadTracks, logTag]);
7037
7045
  const handlePortTrack = useCallback16(
7038
7046
  async (sel) => {
7039
7047
  if (!activeSceneId) {
@@ -7073,6 +7081,12 @@ function useGeneratorPanelCore({
7073
7081
  });
7074
7082
  }
7075
7083
  await adapter.applyPortedTrackSound(handle, sel.role);
7084
+ if (adapter.onTrackCreated) {
7085
+ try {
7086
+ await adapter.onTrackCreated(handle, { activeSceneId, trackDataKey });
7087
+ } catch {
7088
+ }
7089
+ }
7076
7090
  host.showToast(
7077
7091
  "success",
7078
7092
  `Imported to ${identity.familyKey}`,
@@ -8450,31 +8464,447 @@ function createSurgeSoundAdapter(host, overrides = {}) {
8450
8464
  };
8451
8465
  }
8452
8466
 
8467
+ // src/ensemble-core/voice-spec.ts
8468
+ var TOP = {
8469
+ label: "high florid line",
8470
+ role: "lead",
8471
+ registerLow: 72,
8472
+ registerHigh: 96,
8473
+ maxNotesPerBar: 8,
8474
+ rhythmPalette: "8ths and 16ths; melisma and short runs welcome",
8475
+ harmonicDiscipline: "freest voice \u2014 non-chord tones as passing/neighbor tones on weak beats, resolving by step",
8476
+ monoPreference: "high"
8477
+ };
8478
+ var COUNTER = {
8479
+ label: "countermelody",
8480
+ role: "strings",
8481
+ registerLow: 65,
8482
+ registerHigh: 86,
8483
+ maxNotesPerBar: 6,
8484
+ rhythmPalette: "8ths and quarters; move when the top voice rests",
8485
+ harmonicDiscipline: "mostly chord tones; may imitate the top voice's motifs a bar later",
8486
+ monoPreference: "high"
8487
+ };
8488
+ var INNER = {
8489
+ label: "inner voice",
8490
+ role: "strings",
8491
+ registerLow: 55,
8492
+ registerHigh: 76,
8493
+ maxNotesPerBar: 4,
8494
+ rhythmPalette: "quarters and halves",
8495
+ harmonicDiscipline: "chord tones with smooth stepwise motion between them",
8496
+ monoPreference: "high"
8497
+ };
8498
+ var INNER_2 = {
8499
+ label: "second inner voice",
8500
+ role: "strings",
8501
+ registerLow: 60,
8502
+ registerHigh: 81,
8503
+ maxNotesPerBar: 5,
8504
+ rhythmPalette: "quarters with occasional 8th-note motion",
8505
+ harmonicDiscipline: "chord tones; fill gaps the other inner voice leaves",
8506
+ monoPreference: "high"
8507
+ };
8508
+ var TENOR = {
8509
+ label: "low counterline",
8510
+ role: "strings",
8511
+ registerLow: 43,
8512
+ registerHigh: 64,
8513
+ maxNotesPerBar: 3,
8514
+ rhythmPalette: "quarters and halves; brief walking figures at cadences",
8515
+ harmonicDiscipline: "roots and fifths emphasized; passing tones only between chord tones",
8516
+ monoPreference: "low"
8517
+ };
8518
+ var BASS = {
8519
+ label: "bassline",
8520
+ role: "bass",
8521
+ registerLow: 36,
8522
+ registerHigh: 60,
8523
+ maxNotesPerBar: 3,
8524
+ rhythmPalette: "quarters and halves",
8525
+ harmonicDiscipline: "chord roots and fifths; stepwise approaches into chord changes",
8526
+ monoPreference: "low"
8527
+ };
8528
+ var SUB = {
8529
+ label: "sub anchor",
8530
+ role: "808s",
8531
+ registerLow: 24,
8532
+ registerHigh: 43,
8533
+ maxNotesPerBar: 2,
8534
+ rhythmPalette: "halves and whole notes; sustain into the bar",
8535
+ harmonicDiscipline: "ROOT pitch class only \u2014 the harmonic anchor",
8536
+ rootOnly: true,
8537
+ monoPreference: "low"
8538
+ };
8539
+ var ENSEMBLE_MIN_VOICES = 2;
8540
+ var ENSEMBLE_MAX_VOICES = 6;
8541
+ var SPEC_TABLES = {
8542
+ 2: [TOP, BASS],
8543
+ 3: [TOP, INNER, BASS],
8544
+ 4: [TOP, COUNTER, TENOR, BASS],
8545
+ 5: [TOP, COUNTER, INNER, TENOR, SUB],
8546
+ 6: [TOP, COUNTER, INNER_2, INNER, TENOR, SUB]
8547
+ };
8548
+ function defaultVoiceSpecs(voiceCount) {
8549
+ const n = Math.max(ENSEMBLE_MIN_VOICES, Math.min(ENSEMBLE_MAX_VOICES, Math.round(voiceCount)));
8550
+ return SPEC_TABLES[n].map((spec, voiceIndex) => ({ ...spec, voiceIndex }));
8551
+ }
8552
+
8553
+ // src/ensemble-core/enforce-voice.ts
8554
+ var MIN_NOTE_DURATION_BEATS = 0.0625;
8555
+ var BEATS_PER_BAR = 4;
8556
+ function foldPitchToRegister(pitch, low, high) {
8557
+ let p = pitch;
8558
+ while (p < low) p += 12;
8559
+ while (p > high) p -= 12;
8560
+ if (p < low) p = low;
8561
+ if (p > high) p = high;
8562
+ return p;
8563
+ }
8564
+ function nearestPitchWithPc(reference, pc, low, high) {
8565
+ let best = null;
8566
+ for (let p = low; p <= high; p++) {
8567
+ if ((p % 12 + 12) % 12 !== pc) continue;
8568
+ if (best === null || Math.abs(p - reference) < Math.abs(best - reference)) best = p;
8569
+ }
8570
+ return best ?? foldPitchToRegister(reference, low, high);
8571
+ }
8572
+ function snapToNearestPc(pitch, pcs) {
8573
+ if (pcs.size === 0) return pitch;
8574
+ for (let d = 0; d <= 6; d++) {
8575
+ if (pcs.has(((pitch - d) % 12 + 12) % 12)) return pitch - d;
8576
+ if (pcs.has(((pitch + d) % 12 + 12) % 12)) return pitch + d;
8577
+ }
8578
+ return pitch;
8579
+ }
8580
+ function enforceVoice(rawNotes, spec, opts) {
8581
+ const repairs = [];
8582
+ const clipEnd = opts.bars * BEATS_PER_BAR;
8583
+ let notes = [];
8584
+ for (const n of rawNotes) {
8585
+ if (!Number.isFinite(n.pitch) || !Number.isFinite(n.startBeat) || !Number.isFinite(n.durationBeats)) continue;
8586
+ if (n.startBeat >= clipEnd || n.startBeat < 0) {
8587
+ repairs.push(`voice ${spec.voiceIndex}: dropped note outside the ${opts.bars}-bar clip (start ${n.startBeat})`);
8588
+ continue;
8589
+ }
8590
+ const durationBeats = Math.max(
8591
+ MIN_NOTE_DURATION_BEATS,
8592
+ Math.min(n.durationBeats, clipEnd - n.startBeat)
8593
+ );
8594
+ notes.push({ ...n, durationBeats });
8595
+ }
8596
+ notes = notes.map((n) => {
8597
+ const folded = foldPitchToRegister(Math.round(n.pitch), spec.registerLow, spec.registerHigh);
8598
+ if (folded !== n.pitch) {
8599
+ repairs.push(`voice ${spec.voiceIndex}: folded pitch ${n.pitch} into register ${spec.registerLow}-${spec.registerHigh} (${folded})`);
8600
+ }
8601
+ return { ...n, pitch: folded };
8602
+ });
8603
+ if (spec.rootOnly && opts.chordRootPcAtBar) {
8604
+ notes = notes.map((n) => {
8605
+ const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
8606
+ const rootPc = opts.chordRootPcAtBar(bar);
8607
+ if (rootPc === null) return n;
8608
+ const pinned = nearestPitchWithPc(n.pitch, rootPc, spec.registerLow, spec.registerHigh);
8609
+ if (pinned !== n.pitch) {
8610
+ repairs.push(`voice ${spec.voiceIndex}: pinned bar ${bar + 1} note to the chord root (${n.pitch} \u2192 ${pinned})`);
8611
+ }
8612
+ return { ...n, pitch: pinned };
8613
+ });
8614
+ }
8615
+ if (opts.scalePcs && opts.scalePcs.size > 0 && !spec.rootOnly) {
8616
+ notes = notes.map((n) => {
8617
+ const pc = (n.pitch % 12 + 12) % 12;
8618
+ if (opts.scalePcs.has(pc)) return n;
8619
+ const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
8620
+ const chordPcs = opts.chordPcsAtBar?.(bar);
8621
+ if (chordPcs?.has(pc)) return n;
8622
+ const snapped = foldPitchToRegister(
8623
+ snapToNearestPc(n.pitch, opts.scalePcs),
8624
+ spec.registerLow,
8625
+ spec.registerHigh
8626
+ );
8627
+ if (snapped !== n.pitch) {
8628
+ repairs.push(`voice ${spec.voiceIndex}: snapped out-of-key pitch ${n.pitch} \u2192 ${snapped}`);
8629
+ }
8630
+ return { ...n, pitch: snapped };
8631
+ });
8632
+ }
8633
+ notes.sort((a, b) => a.startBeat - b.startBeat || (spec.monoPreference === "high" ? b.pitch - a.pitch : a.pitch - b.pitch));
8634
+ const mono = [];
8635
+ for (const n of notes) {
8636
+ const prev = mono[mono.length - 1];
8637
+ if (prev && Math.abs(prev.startBeat - n.startBeat) < 1e-9) {
8638
+ repairs.push(`voice ${spec.voiceIndex}: dropped simultaneous note ${n.pitch} at beat ${n.startBeat} (voice is one line)`);
8639
+ continue;
8640
+ }
8641
+ if (prev && prev.startBeat + prev.durationBeats > n.startBeat) {
8642
+ prev.durationBeats = Math.max(MIN_NOTE_DURATION_BEATS, n.startBeat - prev.startBeat);
8643
+ }
8644
+ mono.push({ ...n });
8645
+ }
8646
+ const byBar = /* @__PURE__ */ new Map();
8647
+ for (const n of mono) {
8648
+ const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
8649
+ const bucket = byBar.get(bar) ?? [];
8650
+ bucket.push(n);
8651
+ byBar.set(bar, bucket);
8652
+ }
8653
+ const kept = new Set(mono);
8654
+ for (const [bar, bucket] of byBar) {
8655
+ if (bucket.length <= spec.maxNotesPerBar) continue;
8656
+ const strength = (n) => {
8657
+ const beatInBar = n.startBeat - bar * BEATS_PER_BAR;
8658
+ const onDownbeat = Math.abs(beatInBar % 1) < 1e-9 ? 1 : 0;
8659
+ return n.durationBeats * 4 + n.velocity / 127 + onDownbeat * 2;
8660
+ };
8661
+ const ranked = [...bucket].sort((a, b) => strength(a) - strength(b));
8662
+ const excess = bucket.length - spec.maxNotesPerBar;
8663
+ for (let i = 0; i < excess; i++) {
8664
+ kept.delete(ranked[i]);
8665
+ }
8666
+ repairs.push(`voice ${spec.voiceIndex}: thinned bar ${bar + 1} from ${bucket.length} to ${spec.maxNotesPerBar} notes (density cap)`);
8667
+ }
8668
+ return { notes: mono.filter((n) => kept.has(n)), repairs };
8669
+ }
8670
+
8671
+ // src/ensemble-core/analyze-ensemble.ts
8672
+ var EPS = 1e-6;
8673
+ function pitchAt(voice, beat) {
8674
+ for (const n of voice) {
8675
+ if (n.startBeat - EPS <= beat && beat < n.startBeat + n.durationBeats - EPS) return n.pitch;
8676
+ }
8677
+ return null;
8678
+ }
8679
+ function onsetSet(voice) {
8680
+ return [...new Set(voice.map((n) => Math.round(n.startBeat * 96) / 96))].sort((a, b) => a - b);
8681
+ }
8682
+ function analyzeEnsemble(voices) {
8683
+ const pairs = [];
8684
+ for (let i = 0; i + 1 < voices.length; i++) {
8685
+ const upper = voices[i];
8686
+ const lower = voices[i + 1];
8687
+ const upperOnsets = onsetSet(upper);
8688
+ const lowerOnsets = new Set(onsetSet(lower));
8689
+ const shared = upperOnsets.filter((b) => lowerOnsets.has(b));
8690
+ const onsetIndependence = upperOnsets.length === 0 ? 1 : 1 - shared.length / upperOnsets.length;
8691
+ const motion = { contrary: 0, oblique: 0, similar: 0, parallel: 0 };
8692
+ const parallelPerfects = [];
8693
+ for (let s = 0; s + 1 < shared.length; s++) {
8694
+ const [b0, b1] = [shared[s], shared[s + 1]];
8695
+ const u0 = pitchAt(upper, b0);
8696
+ const u1 = pitchAt(upper, b1);
8697
+ const l0 = pitchAt(lower, b0);
8698
+ const l1 = pitchAt(lower, b1);
8699
+ if (u0 === null || u1 === null || l0 === null || l1 === null) continue;
8700
+ const du = Math.sign(u1 - u0);
8701
+ const dl = Math.sign(l1 - l0);
8702
+ let kind;
8703
+ if (du === 0 || dl === 0) kind = "oblique";
8704
+ else if (du !== dl) kind = "contrary";
8705
+ else {
8706
+ kind = u1 - l1 === u0 - l0 ? "parallel" : "similar";
8707
+ }
8708
+ motion[kind] += 1;
8709
+ if (kind === "parallel") {
8710
+ const intervalPc = ((u1 - l1) % 12 + 12) % 12;
8711
+ if (intervalPc === 0 || intervalPc === 7) {
8712
+ parallelPerfects.push({ atBeat: b1, intervalPc });
8713
+ }
8714
+ }
8715
+ }
8716
+ const crossings = [];
8717
+ for (const b of [...upperOnsets, ...onsetSet(lower)]) {
8718
+ const u = pitchAt(upper, b);
8719
+ const l = pitchAt(lower, b);
8720
+ if (u !== null && l !== null && u < l) crossings.push(b);
8721
+ }
8722
+ pairs.push({
8723
+ upperVoice: i,
8724
+ onsetIndependence,
8725
+ motion,
8726
+ parallelPerfects,
8727
+ crossings: [...new Set(crossings)].sort((a, b) => a - b)
8728
+ });
8729
+ }
8730
+ const allOnsets = voices.map(onsetSet);
8731
+ const union = new Set(allOnsets.flat());
8732
+ let sharedByAll = 0;
8733
+ for (const b of union) {
8734
+ if (allOnsets.every((o) => o.length === 0 || o.includes(b))) sharedByAll += 1;
8735
+ }
8736
+ const homorhythmScore = union.size === 0 ? 0 : sharedByAll / union.size;
8737
+ return { pairs, homorhythmScore };
8738
+ }
8739
+ function describeViolations(analysis, rules) {
8740
+ const out = [];
8741
+ for (const pair of analysis.pairs) {
8742
+ const label = `between voice ${pair.upperVoice + 1} and voice ${pair.upperVoice + 2}`;
8743
+ if (rules.forbidParallelPerfects) {
8744
+ for (const p of pair.parallelPerfects) {
8745
+ out.push(`Parallel ${p.intervalPc === 0 ? "octaves" : "fifths"} ${label} at beat ${p.atBeat} \u2014 approach perfect intervals by contrary or oblique motion.`);
8746
+ }
8747
+ }
8748
+ if (rules.forbidVoiceCrossing && pair.crossings.length > 0) {
8749
+ out.push(`Voice crossing ${label} at beat${pair.crossings.length > 1 ? "s" : ""} ${pair.crossings.join(", ")} \u2014 keep each voice inside its register lane.`);
8750
+ }
8751
+ if (pair.onsetIndependence < rules.minOnsetIndependence) {
8752
+ out.push(`Voices ${pair.upperVoice + 1} and ${pair.upperVoice + 2} attack together too often (independence ${pair.onsetIndependence.toFixed(2)} < ${rules.minOnsetIndependence}) \u2014 stagger entrances and let one voice move while the other holds.`);
8753
+ }
8754
+ }
8755
+ return out;
8756
+ }
8757
+
8758
+ // src/ensemble-core/styles.ts
8759
+ var ENSEMBLE_STYLES = ["counterpoint", "chorale", "interlock"];
8760
+ var STYLE_RULES = {
8761
+ counterpoint: {
8762
+ forbidParallelPerfects: true,
8763
+ forbidVoiceCrossing: true,
8764
+ minOnsetIndependence: 0.35,
8765
+ promptParagraph: "STYLE \u2014 COUNTERPOINT (modern, not strict species): independent singable lines. Favor contrary and oblique motion between neighbors; approach perfect intervals by contrary motion; imitate motifs between voices a bar apart; stagger entrances so voices converse instead of speaking at once."
8766
+ },
8767
+ chorale: {
8768
+ forbidParallelPerfects: true,
8769
+ forbidVoiceCrossing: true,
8770
+ minOnsetIndependence: 0,
8771
+ promptParagraph: "STYLE \u2014 CHORALE: homorhythmic block harmony. Voices move together on the same rhythm with smooth voice-leading \u2014 nearest chord tone, common tones held, no leaps larger than a fifth in inner voices."
8772
+ },
8773
+ interlock: {
8774
+ forbidParallelPerfects: false,
8775
+ forbidVoiceCrossing: false,
8776
+ minOnsetIndependence: 0.6,
8777
+ promptParagraph: "STYLE \u2014 INTERLOCK (minimal / systems music): short repeating cells that mesh like gears. Each voice keeps its own ostinato; onsets rarely coincide with the neighboring voice; parallel motion and doubling are welcome when the composite rhythm stays busy and even."
8778
+ }
8779
+ };
8780
+
8781
+ // src/ensemble-core/ensemble-schema.ts
8782
+ var SUBMIT_ENSEMBLE_TOOL_NAME = "submit_ensemble";
8783
+ function buildSubmitEnsembleParameters(voiceCount) {
8784
+ return {
8785
+ type: "object",
8786
+ properties: {
8787
+ voices: {
8788
+ type: "array",
8789
+ description: `Exactly ${voiceCount} voices, voiceIndex 0 (top) through ${voiceCount - 1} (bottom).`,
8790
+ items: {
8791
+ type: "object",
8792
+ properties: {
8793
+ voiceIndex: { type: "integer", description: "0 = top voice" },
8794
+ notes: {
8795
+ type: "array",
8796
+ items: {
8797
+ type: "object",
8798
+ properties: {
8799
+ pitch: { type: "integer", description: "MIDI note number 0-127" },
8800
+ startBeat: { type: "number", description: "quarter-note beats from clip start" },
8801
+ durationBeats: { type: "number", description: "duration in quarter-note beats" },
8802
+ velocity: { type: "integer", description: "1-127" }
8803
+ },
8804
+ required: ["pitch", "startBeat", "durationBeats", "velocity"]
8805
+ }
8806
+ }
8807
+ },
8808
+ required: ["voiceIndex", "notes"]
8809
+ }
8810
+ }
8811
+ },
8812
+ required: ["voices"]
8813
+ };
8814
+ }
8815
+ function parseEnsembleArgs(args, voiceCount) {
8816
+ if (typeof args !== "object" || args === null) return null;
8817
+ const voicesRaw = args.voices;
8818
+ if (!Array.isArray(voicesRaw)) return null;
8819
+ const warnings = [];
8820
+ const voiceNotes = Array.from({ length: voiceCount }, () => []);
8821
+ for (const v of voicesRaw) {
8822
+ if (typeof v !== "object" || v === null) continue;
8823
+ const idxRaw = v.voiceIndex;
8824
+ const idx = typeof idxRaw === "number" ? Math.round(idxRaw) : NaN;
8825
+ if (!Number.isInteger(idx) || idx < 0 || idx >= voiceCount) {
8826
+ warnings.push(`ignored voice with out-of-range voiceIndex ${String(idxRaw)}`);
8827
+ continue;
8828
+ }
8829
+ const notesRaw = v.notes;
8830
+ if (!Array.isArray(notesRaw)) continue;
8831
+ const notes = [];
8832
+ let dropped = 0;
8833
+ for (const n of notesRaw) {
8834
+ const note = n;
8835
+ if (typeof note?.pitch === "number" && typeof note?.startBeat === "number" && typeof note?.durationBeats === "number" && typeof note?.velocity === "number" && note.durationBeats > 0 && note.startBeat >= 0) {
8836
+ notes.push({
8837
+ pitch: Math.max(0, Math.min(127, Math.round(note.pitch))),
8838
+ startBeat: note.startBeat,
8839
+ durationBeats: note.durationBeats,
8840
+ velocity: Math.max(1, Math.min(127, Math.round(note.velocity)))
8841
+ });
8842
+ } else {
8843
+ dropped += 1;
8844
+ }
8845
+ }
8846
+ if (dropped > 0) warnings.push(`voice ${idx}: dropped ${dropped} malformed note(s)`);
8847
+ voiceNotes[idx] = notes;
8848
+ }
8849
+ const returned = voicesRaw.length;
8850
+ if (returned !== voiceCount) {
8851
+ warnings.push(`model returned ${returned} voices for a ${voiceCount}-voice ensemble`);
8852
+ }
8853
+ const anyNotes = voiceNotes.some((v) => v.length > 0);
8854
+ return anyNotes ? { voiceNotes, warnings } : null;
8855
+ }
8856
+
8857
+ // src/ensemble-core/ensemble-prompt.ts
8858
+ function voiceContractLine(spec) {
8859
+ const root = spec.rootOnly ? " ROOT PITCH CLASS ONLY (each bar's chord root)." : "";
8860
+ return `- Voice ${spec.voiceIndex + 1} (${spec.label}): MIDI ${spec.registerLow}-${spec.registerHigh}, max ${spec.maxNotesPerBar} notes/bar, rhythm: ${spec.rhythmPalette}. ${spec.harmonicDiscipline}.${root}`;
8861
+ }
8862
+ function buildEnsembleSystemPrompt(specs, style) {
8863
+ const styleParagraph = STYLE_RULES[style].promptParagraph;
8864
+ return `You are an ensemble composer. Compose ${specs.length} voices as ONE piece of music \u2014 not ${specs.length} independent parts.
8865
+
8866
+ Submit your composition by calling the ${SUBMIT_ENSEMBLE_TOOL_NAME} tool with all ${specs.length} voices.
8867
+
8868
+ THE ENSEMBLE RULES (most important):
8869
+ 1. The voices are composed TOGETHER. They must relate: imitate and answer each other's motifs, move in contrary or oblique motion against neighbors, and stagger entrances so lines converse.
8870
+ 2. Each voice is a SINGLE monophonic line \u2014 within one voice, no two notes overlap in time and no chords. Voices MAY and SHOULD overlap EACH OTHER; that overlap is the music.
8871
+ 3. Complexity decreases downward: the top voice is the most active and ornamented, the bottom voice the sparsest anchor. Respect each voice's register window and notes-per-bar cap exactly.
8872
+ 4. Follow the chord progression in the musical context exactly. Non-chord tones only as passing or neighbor tones on weak beats, resolving by step.
8873
+ 5. Not every voice plays all the time \u2014 rests are structural. Avoid all voices attacking the same beat except at phrase boundaries.
8874
+ 6. startBeat/durationBeats are in quarter-note beats from the start of the clip; fill the stated bar length, and make bar 1 land immediately (no long silent intro).
8875
+
8876
+ ${styleParagraph}
8877
+
8878
+ PER-VOICE CONTRACTS:
8879
+ ${specs.map(voiceContractLine).join("\n")}`;
8880
+ }
8881
+ function buildViolationRetrySuffix(violations) {
8882
+ if (violations.length === 0) return "";
8883
+ return `
8884
+
8885
+ Your previous ensemble had these problems \u2014 fix them while keeping everything that worked:
8886
+ ` + violations.map((v) => `- ${v}`).join("\n");
8887
+ }
8888
+
8453
8889
  // src/constants/sdk-version.ts
8454
- var PLUGIN_SDK_VERSION = "2.40.0";
8890
+ var PLUGIN_SDK_VERSION = "2.43.0";
8455
8891
 
8456
8892
  // src/utils/format-concurrent-tracks.ts
8457
8893
  function formatConcurrentTracks(ctx) {
8458
8894
  const tracks = ctx.concurrentTracks;
8459
8895
  if (!tracks || tracks.length === 0) return "";
8460
- const lines = [`Concurrent tracks in scene (already generated):`];
8461
- for (const track of tracks) {
8462
- const promptStr = track.prompt ? ` prompt="${escapeQuotes(track.prompt)}"` : "";
8463
- lines.push(` - role=${track.role ?? "unknown"}${promptStr}`);
8464
- if (track.notesByChord.length === 0) {
8465
- lines.push(` (no notes)`);
8466
- } else {
8467
- for (const segment of track.notesByChord) {
8468
- if (segment.notes.length === 0) continue;
8469
- lines.push(` ${formatChordSegment(segment)}`);
8470
- }
8471
- }
8472
- if (track.truncated && typeof track.originalNoteCount === "number") {
8473
- const dropped = track.originalNoteCount - sumKeptNotes(track.notesByChord);
8474
- if (dropped > 0) {
8475
- lines.push(` \u2026 (${dropped} more notes truncated)`);
8476
- }
8477
- }
8896
+ const pinned = tracks.filter((t) => t.pinned);
8897
+ const ambient = tracks.filter((t) => !t.pinned);
8898
+ const lines = [];
8899
+ if (pinned.length > 0) {
8900
+ lines.push(
8901
+ "REFERENCE TRACKS (write in counterpoint against these \u2014 interlock with their rhythm, avoid doubling their onsets, favor contrary or oblique motion):"
8902
+ );
8903
+ for (const track of pinned) pushTrackLines(lines, track);
8904
+ }
8905
+ if (ambient.length > 0) {
8906
+ lines.push(`Concurrent tracks in scene (already generated):`);
8907
+ for (const track of ambient) pushTrackLines(lines, track);
8478
8908
  }
8479
8909
  if (ctx.truncatedTrackCount && ctx.truncatedTrackCount > 0) {
8480
8910
  lines.push(
@@ -8483,6 +8913,25 @@ function formatConcurrentTracks(ctx) {
8483
8913
  }
8484
8914
  return lines.join("\n");
8485
8915
  }
8916
+ function pushTrackLines(lines, track) {
8917
+ const nameStr = track.name ? ` name="${escapeQuotes(track.name)}"` : "";
8918
+ const promptStr = track.prompt ? ` prompt="${escapeQuotes(track.prompt)}"` : "";
8919
+ lines.push(` - role=${track.role ?? "unknown"}${nameStr}${promptStr}`);
8920
+ if (track.notesByChord.length === 0) {
8921
+ lines.push(` (no notes)`);
8922
+ } else {
8923
+ for (const segment of track.notesByChord) {
8924
+ if (segment.notes.length === 0) continue;
8925
+ lines.push(` ${formatChordSegment(segment)}`);
8926
+ }
8927
+ }
8928
+ if (track.truncated && typeof track.originalNoteCount === "number") {
8929
+ const dropped = track.originalNoteCount - sumKeptNotes(track.notesByChord);
8930
+ if (dropped > 0) {
8931
+ lines.push(` \u2026 (${dropped} more notes truncated)`);
8932
+ }
8933
+ }
8934
+ }
8486
8935
  function formatChordSegment(segment) {
8487
8936
  const [start, end] = segment.chordRangeQn;
8488
8937
  const notesJson = JSON.stringify(segment.notes.map(compactNote2));
@@ -8607,6 +9056,9 @@ export {
8607
9056
  DownloadPackButton,
8608
9057
  EMPTY_FX_DETAIL_STATE,
8609
9058
  EMPTY_FX_STATE,
9059
+ ENSEMBLE_MAX_VOICES,
9060
+ ENSEMBLE_MIN_VOICES,
9061
+ ENSEMBLE_STYLES,
8610
9062
  EQUAL_POWER_GAIN,
8611
9063
  FX_CATEGORIES,
8612
9064
  FX_CHAIN_ORDER,
@@ -8622,6 +9074,7 @@ export {
8622
9074
  ImportTrackModal,
8623
9075
  TrackDrawer as InstrumentDrawer,
8624
9076
  LevelMeter,
9077
+ MIN_NOTE_DURATION_BEATS,
8625
9078
  Modal,
8626
9079
  OffsetScrubber,
8627
9080
  PLUGIN_SDK_VERSION,
@@ -8633,6 +9086,8 @@ export {
8633
9086
  RESIZE_HANDLE_PX,
8634
9087
  ROW_HEIGHT,
8635
9088
  SLIDER_UNITY,
9089
+ STYLE_RULES,
9090
+ SUBMIT_ENSEMBLE_TOOL_NAME,
8636
9091
  SamplePackCTACard,
8637
9092
  ScrollingWaveform,
8638
9093
  SorceryProgressBar,
@@ -8645,6 +9100,7 @@ export {
8645
9100
  TransitionDesigner,
8646
9101
  VolumeSlider,
8647
9102
  WaveformView,
9103
+ analyzeEnsemble,
8648
9104
  analyzeWavPeak,
8649
9105
  asAudioEffect,
8650
9106
  asCrossfadeMeta,
@@ -8652,8 +9108,11 @@ export {
8652
9108
  asTransitionDesignerDraft,
8653
9109
  buildCrossfadeInpaintPrompt,
8654
9110
  buildCrossfadeVolumeCurves,
9111
+ buildEnsembleSystemPrompt,
8655
9112
  buildFadeVolumeCurve,
8656
9113
  buildRowSlots,
9114
+ buildSubmitEnsembleParameters,
9115
+ buildViolationRetrySuffix,
8657
9116
  calculateTimeBasedTarget,
8658
9117
  cellToPx,
8659
9118
  centerScrollTop,
@@ -8662,15 +9121,21 @@ export {
8662
9121
  dbIdsFromKeys,
8663
9122
  dbToSlider,
8664
9123
  defaultFadeGesture,
9124
+ defaultVoiceSpecs,
9125
+ describeViolations,
8665
9126
  drawWaveform,
9127
+ enforceVoice,
9128
+ foldPitchToRegister,
8666
9129
  formatConcurrentTracks,
8667
9130
  hashString,
8668
9131
  moveItem,
9132
+ nearestPitchWithPc,
8669
9133
  newTrackState,
8670
9134
  normalizeSlots,
8671
9135
  padPair,
8672
9136
  padSlots,
8673
9137
  parseCrossfadePairs,
9138
+ parseEnsembleArgs,
8674
9139
  parseFades,
8675
9140
  parseLLMNoteResponse,
8676
9141
  parseTrackGroups,