@signalsandsorcery/plugin-sdk 2.35.5 → 2.35.6
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.d.mts +322 -4
- package/dist/index.d.ts +322 -4
- package/dist/index.js +486 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +470 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8450,31 +8450,447 @@ function createSurgeSoundAdapter(host, overrides = {}) {
|
|
|
8450
8450
|
};
|
|
8451
8451
|
}
|
|
8452
8452
|
|
|
8453
|
+
// src/ensemble-core/voice-spec.ts
|
|
8454
|
+
var TOP = {
|
|
8455
|
+
label: "high florid line",
|
|
8456
|
+
role: "lead",
|
|
8457
|
+
registerLow: 72,
|
|
8458
|
+
registerHigh: 96,
|
|
8459
|
+
maxNotesPerBar: 8,
|
|
8460
|
+
rhythmPalette: "8ths and 16ths; melisma and short runs welcome",
|
|
8461
|
+
harmonicDiscipline: "freest voice \u2014 non-chord tones as passing/neighbor tones on weak beats, resolving by step",
|
|
8462
|
+
monoPreference: "high"
|
|
8463
|
+
};
|
|
8464
|
+
var COUNTER = {
|
|
8465
|
+
label: "countermelody",
|
|
8466
|
+
role: "strings",
|
|
8467
|
+
registerLow: 65,
|
|
8468
|
+
registerHigh: 86,
|
|
8469
|
+
maxNotesPerBar: 6,
|
|
8470
|
+
rhythmPalette: "8ths and quarters; move when the top voice rests",
|
|
8471
|
+
harmonicDiscipline: "mostly chord tones; may imitate the top voice's motifs a bar later",
|
|
8472
|
+
monoPreference: "high"
|
|
8473
|
+
};
|
|
8474
|
+
var INNER = {
|
|
8475
|
+
label: "inner voice",
|
|
8476
|
+
role: "strings",
|
|
8477
|
+
registerLow: 55,
|
|
8478
|
+
registerHigh: 76,
|
|
8479
|
+
maxNotesPerBar: 4,
|
|
8480
|
+
rhythmPalette: "quarters and halves",
|
|
8481
|
+
harmonicDiscipline: "chord tones with smooth stepwise motion between them",
|
|
8482
|
+
monoPreference: "high"
|
|
8483
|
+
};
|
|
8484
|
+
var INNER_2 = {
|
|
8485
|
+
label: "second inner voice",
|
|
8486
|
+
role: "strings",
|
|
8487
|
+
registerLow: 60,
|
|
8488
|
+
registerHigh: 81,
|
|
8489
|
+
maxNotesPerBar: 5,
|
|
8490
|
+
rhythmPalette: "quarters with occasional 8th-note motion",
|
|
8491
|
+
harmonicDiscipline: "chord tones; fill gaps the other inner voice leaves",
|
|
8492
|
+
monoPreference: "high"
|
|
8493
|
+
};
|
|
8494
|
+
var TENOR = {
|
|
8495
|
+
label: "low counterline",
|
|
8496
|
+
role: "strings",
|
|
8497
|
+
registerLow: 43,
|
|
8498
|
+
registerHigh: 64,
|
|
8499
|
+
maxNotesPerBar: 3,
|
|
8500
|
+
rhythmPalette: "quarters and halves; brief walking figures at cadences",
|
|
8501
|
+
harmonicDiscipline: "roots and fifths emphasized; passing tones only between chord tones",
|
|
8502
|
+
monoPreference: "low"
|
|
8503
|
+
};
|
|
8504
|
+
var BASS = {
|
|
8505
|
+
label: "bassline",
|
|
8506
|
+
role: "bass",
|
|
8507
|
+
registerLow: 36,
|
|
8508
|
+
registerHigh: 60,
|
|
8509
|
+
maxNotesPerBar: 3,
|
|
8510
|
+
rhythmPalette: "quarters and halves",
|
|
8511
|
+
harmonicDiscipline: "chord roots and fifths; stepwise approaches into chord changes",
|
|
8512
|
+
monoPreference: "low"
|
|
8513
|
+
};
|
|
8514
|
+
var SUB = {
|
|
8515
|
+
label: "sub anchor",
|
|
8516
|
+
role: "808s",
|
|
8517
|
+
registerLow: 24,
|
|
8518
|
+
registerHigh: 43,
|
|
8519
|
+
maxNotesPerBar: 2,
|
|
8520
|
+
rhythmPalette: "halves and whole notes; sustain into the bar",
|
|
8521
|
+
harmonicDiscipline: "ROOT pitch class only \u2014 the harmonic anchor",
|
|
8522
|
+
rootOnly: true,
|
|
8523
|
+
monoPreference: "low"
|
|
8524
|
+
};
|
|
8525
|
+
var ENSEMBLE_MIN_VOICES = 2;
|
|
8526
|
+
var ENSEMBLE_MAX_VOICES = 6;
|
|
8527
|
+
var SPEC_TABLES = {
|
|
8528
|
+
2: [TOP, BASS],
|
|
8529
|
+
3: [TOP, INNER, BASS],
|
|
8530
|
+
4: [TOP, COUNTER, TENOR, BASS],
|
|
8531
|
+
5: [TOP, COUNTER, INNER, TENOR, SUB],
|
|
8532
|
+
6: [TOP, COUNTER, INNER_2, INNER, TENOR, SUB]
|
|
8533
|
+
};
|
|
8534
|
+
function defaultVoiceSpecs(voiceCount) {
|
|
8535
|
+
const n = Math.max(ENSEMBLE_MIN_VOICES, Math.min(ENSEMBLE_MAX_VOICES, Math.round(voiceCount)));
|
|
8536
|
+
return SPEC_TABLES[n].map((spec, voiceIndex) => ({ ...spec, voiceIndex }));
|
|
8537
|
+
}
|
|
8538
|
+
|
|
8539
|
+
// src/ensemble-core/enforce-voice.ts
|
|
8540
|
+
var MIN_NOTE_DURATION_BEATS = 0.0625;
|
|
8541
|
+
var BEATS_PER_BAR = 4;
|
|
8542
|
+
function foldPitchToRegister(pitch, low, high) {
|
|
8543
|
+
let p = pitch;
|
|
8544
|
+
while (p < low) p += 12;
|
|
8545
|
+
while (p > high) p -= 12;
|
|
8546
|
+
if (p < low) p = low;
|
|
8547
|
+
if (p > high) p = high;
|
|
8548
|
+
return p;
|
|
8549
|
+
}
|
|
8550
|
+
function nearestPitchWithPc(reference, pc, low, high) {
|
|
8551
|
+
let best = null;
|
|
8552
|
+
for (let p = low; p <= high; p++) {
|
|
8553
|
+
if ((p % 12 + 12) % 12 !== pc) continue;
|
|
8554
|
+
if (best === null || Math.abs(p - reference) < Math.abs(best - reference)) best = p;
|
|
8555
|
+
}
|
|
8556
|
+
return best ?? foldPitchToRegister(reference, low, high);
|
|
8557
|
+
}
|
|
8558
|
+
function snapToNearestPc(pitch, pcs) {
|
|
8559
|
+
if (pcs.size === 0) return pitch;
|
|
8560
|
+
for (let d = 0; d <= 6; d++) {
|
|
8561
|
+
if (pcs.has(((pitch - d) % 12 + 12) % 12)) return pitch - d;
|
|
8562
|
+
if (pcs.has(((pitch + d) % 12 + 12) % 12)) return pitch + d;
|
|
8563
|
+
}
|
|
8564
|
+
return pitch;
|
|
8565
|
+
}
|
|
8566
|
+
function enforceVoice(rawNotes, spec, opts) {
|
|
8567
|
+
const repairs = [];
|
|
8568
|
+
const clipEnd = opts.bars * BEATS_PER_BAR;
|
|
8569
|
+
let notes = [];
|
|
8570
|
+
for (const n of rawNotes) {
|
|
8571
|
+
if (!Number.isFinite(n.pitch) || !Number.isFinite(n.startBeat) || !Number.isFinite(n.durationBeats)) continue;
|
|
8572
|
+
if (n.startBeat >= clipEnd || n.startBeat < 0) {
|
|
8573
|
+
repairs.push(`voice ${spec.voiceIndex}: dropped note outside the ${opts.bars}-bar clip (start ${n.startBeat})`);
|
|
8574
|
+
continue;
|
|
8575
|
+
}
|
|
8576
|
+
const durationBeats = Math.max(
|
|
8577
|
+
MIN_NOTE_DURATION_BEATS,
|
|
8578
|
+
Math.min(n.durationBeats, clipEnd - n.startBeat)
|
|
8579
|
+
);
|
|
8580
|
+
notes.push({ ...n, durationBeats });
|
|
8581
|
+
}
|
|
8582
|
+
notes = notes.map((n) => {
|
|
8583
|
+
const folded = foldPitchToRegister(Math.round(n.pitch), spec.registerLow, spec.registerHigh);
|
|
8584
|
+
if (folded !== n.pitch) {
|
|
8585
|
+
repairs.push(`voice ${spec.voiceIndex}: folded pitch ${n.pitch} into register ${spec.registerLow}-${spec.registerHigh} (${folded})`);
|
|
8586
|
+
}
|
|
8587
|
+
return { ...n, pitch: folded };
|
|
8588
|
+
});
|
|
8589
|
+
if (spec.rootOnly && opts.chordRootPcAtBar) {
|
|
8590
|
+
notes = notes.map((n) => {
|
|
8591
|
+
const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
|
|
8592
|
+
const rootPc = opts.chordRootPcAtBar(bar);
|
|
8593
|
+
if (rootPc === null) return n;
|
|
8594
|
+
const pinned = nearestPitchWithPc(n.pitch, rootPc, spec.registerLow, spec.registerHigh);
|
|
8595
|
+
if (pinned !== n.pitch) {
|
|
8596
|
+
repairs.push(`voice ${spec.voiceIndex}: pinned bar ${bar + 1} note to the chord root (${n.pitch} \u2192 ${pinned})`);
|
|
8597
|
+
}
|
|
8598
|
+
return { ...n, pitch: pinned };
|
|
8599
|
+
});
|
|
8600
|
+
}
|
|
8601
|
+
if (opts.scalePcs && opts.scalePcs.size > 0 && !spec.rootOnly) {
|
|
8602
|
+
notes = notes.map((n) => {
|
|
8603
|
+
const pc = (n.pitch % 12 + 12) % 12;
|
|
8604
|
+
if (opts.scalePcs.has(pc)) return n;
|
|
8605
|
+
const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
|
|
8606
|
+
const chordPcs = opts.chordPcsAtBar?.(bar);
|
|
8607
|
+
if (chordPcs?.has(pc)) return n;
|
|
8608
|
+
const snapped = foldPitchToRegister(
|
|
8609
|
+
snapToNearestPc(n.pitch, opts.scalePcs),
|
|
8610
|
+
spec.registerLow,
|
|
8611
|
+
spec.registerHigh
|
|
8612
|
+
);
|
|
8613
|
+
if (snapped !== n.pitch) {
|
|
8614
|
+
repairs.push(`voice ${spec.voiceIndex}: snapped out-of-key pitch ${n.pitch} \u2192 ${snapped}`);
|
|
8615
|
+
}
|
|
8616
|
+
return { ...n, pitch: snapped };
|
|
8617
|
+
});
|
|
8618
|
+
}
|
|
8619
|
+
notes.sort((a, b) => a.startBeat - b.startBeat || (spec.monoPreference === "high" ? b.pitch - a.pitch : a.pitch - b.pitch));
|
|
8620
|
+
const mono = [];
|
|
8621
|
+
for (const n of notes) {
|
|
8622
|
+
const prev = mono[mono.length - 1];
|
|
8623
|
+
if (prev && Math.abs(prev.startBeat - n.startBeat) < 1e-9) {
|
|
8624
|
+
repairs.push(`voice ${spec.voiceIndex}: dropped simultaneous note ${n.pitch} at beat ${n.startBeat} (voice is one line)`);
|
|
8625
|
+
continue;
|
|
8626
|
+
}
|
|
8627
|
+
if (prev && prev.startBeat + prev.durationBeats > n.startBeat) {
|
|
8628
|
+
prev.durationBeats = Math.max(MIN_NOTE_DURATION_BEATS, n.startBeat - prev.startBeat);
|
|
8629
|
+
}
|
|
8630
|
+
mono.push({ ...n });
|
|
8631
|
+
}
|
|
8632
|
+
const byBar = /* @__PURE__ */ new Map();
|
|
8633
|
+
for (const n of mono) {
|
|
8634
|
+
const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
|
|
8635
|
+
const bucket = byBar.get(bar) ?? [];
|
|
8636
|
+
bucket.push(n);
|
|
8637
|
+
byBar.set(bar, bucket);
|
|
8638
|
+
}
|
|
8639
|
+
const kept = new Set(mono);
|
|
8640
|
+
for (const [bar, bucket] of byBar) {
|
|
8641
|
+
if (bucket.length <= spec.maxNotesPerBar) continue;
|
|
8642
|
+
const strength = (n) => {
|
|
8643
|
+
const beatInBar = n.startBeat - bar * BEATS_PER_BAR;
|
|
8644
|
+
const onDownbeat = Math.abs(beatInBar % 1) < 1e-9 ? 1 : 0;
|
|
8645
|
+
return n.durationBeats * 4 + n.velocity / 127 + onDownbeat * 2;
|
|
8646
|
+
};
|
|
8647
|
+
const ranked = [...bucket].sort((a, b) => strength(a) - strength(b));
|
|
8648
|
+
const excess = bucket.length - spec.maxNotesPerBar;
|
|
8649
|
+
for (let i = 0; i < excess; i++) {
|
|
8650
|
+
kept.delete(ranked[i]);
|
|
8651
|
+
}
|
|
8652
|
+
repairs.push(`voice ${spec.voiceIndex}: thinned bar ${bar + 1} from ${bucket.length} to ${spec.maxNotesPerBar} notes (density cap)`);
|
|
8653
|
+
}
|
|
8654
|
+
return { notes: mono.filter((n) => kept.has(n)), repairs };
|
|
8655
|
+
}
|
|
8656
|
+
|
|
8657
|
+
// src/ensemble-core/analyze-ensemble.ts
|
|
8658
|
+
var EPS = 1e-6;
|
|
8659
|
+
function pitchAt(voice, beat) {
|
|
8660
|
+
for (const n of voice) {
|
|
8661
|
+
if (n.startBeat - EPS <= beat && beat < n.startBeat + n.durationBeats - EPS) return n.pitch;
|
|
8662
|
+
}
|
|
8663
|
+
return null;
|
|
8664
|
+
}
|
|
8665
|
+
function onsetSet(voice) {
|
|
8666
|
+
return [...new Set(voice.map((n) => Math.round(n.startBeat * 96) / 96))].sort((a, b) => a - b);
|
|
8667
|
+
}
|
|
8668
|
+
function analyzeEnsemble(voices) {
|
|
8669
|
+
const pairs = [];
|
|
8670
|
+
for (let i = 0; i + 1 < voices.length; i++) {
|
|
8671
|
+
const upper = voices[i];
|
|
8672
|
+
const lower = voices[i + 1];
|
|
8673
|
+
const upperOnsets = onsetSet(upper);
|
|
8674
|
+
const lowerOnsets = new Set(onsetSet(lower));
|
|
8675
|
+
const shared = upperOnsets.filter((b) => lowerOnsets.has(b));
|
|
8676
|
+
const onsetIndependence = upperOnsets.length === 0 ? 1 : 1 - shared.length / upperOnsets.length;
|
|
8677
|
+
const motion = { contrary: 0, oblique: 0, similar: 0, parallel: 0 };
|
|
8678
|
+
const parallelPerfects = [];
|
|
8679
|
+
for (let s = 0; s + 1 < shared.length; s++) {
|
|
8680
|
+
const [b0, b1] = [shared[s], shared[s + 1]];
|
|
8681
|
+
const u0 = pitchAt(upper, b0);
|
|
8682
|
+
const u1 = pitchAt(upper, b1);
|
|
8683
|
+
const l0 = pitchAt(lower, b0);
|
|
8684
|
+
const l1 = pitchAt(lower, b1);
|
|
8685
|
+
if (u0 === null || u1 === null || l0 === null || l1 === null) continue;
|
|
8686
|
+
const du = Math.sign(u1 - u0);
|
|
8687
|
+
const dl = Math.sign(l1 - l0);
|
|
8688
|
+
let kind;
|
|
8689
|
+
if (du === 0 || dl === 0) kind = "oblique";
|
|
8690
|
+
else if (du !== dl) kind = "contrary";
|
|
8691
|
+
else {
|
|
8692
|
+
kind = u1 - l1 === u0 - l0 ? "parallel" : "similar";
|
|
8693
|
+
}
|
|
8694
|
+
motion[kind] += 1;
|
|
8695
|
+
if (kind === "parallel") {
|
|
8696
|
+
const intervalPc = ((u1 - l1) % 12 + 12) % 12;
|
|
8697
|
+
if (intervalPc === 0 || intervalPc === 7) {
|
|
8698
|
+
parallelPerfects.push({ atBeat: b1, intervalPc });
|
|
8699
|
+
}
|
|
8700
|
+
}
|
|
8701
|
+
}
|
|
8702
|
+
const crossings = [];
|
|
8703
|
+
for (const b of [...upperOnsets, ...onsetSet(lower)]) {
|
|
8704
|
+
const u = pitchAt(upper, b);
|
|
8705
|
+
const l = pitchAt(lower, b);
|
|
8706
|
+
if (u !== null && l !== null && u < l) crossings.push(b);
|
|
8707
|
+
}
|
|
8708
|
+
pairs.push({
|
|
8709
|
+
upperVoice: i,
|
|
8710
|
+
onsetIndependence,
|
|
8711
|
+
motion,
|
|
8712
|
+
parallelPerfects,
|
|
8713
|
+
crossings: [...new Set(crossings)].sort((a, b) => a - b)
|
|
8714
|
+
});
|
|
8715
|
+
}
|
|
8716
|
+
const allOnsets = voices.map(onsetSet);
|
|
8717
|
+
const union = new Set(allOnsets.flat());
|
|
8718
|
+
let sharedByAll = 0;
|
|
8719
|
+
for (const b of union) {
|
|
8720
|
+
if (allOnsets.every((o) => o.length === 0 || o.includes(b))) sharedByAll += 1;
|
|
8721
|
+
}
|
|
8722
|
+
const homorhythmScore = union.size === 0 ? 0 : sharedByAll / union.size;
|
|
8723
|
+
return { pairs, homorhythmScore };
|
|
8724
|
+
}
|
|
8725
|
+
function describeViolations(analysis, rules) {
|
|
8726
|
+
const out = [];
|
|
8727
|
+
for (const pair of analysis.pairs) {
|
|
8728
|
+
const label = `between voice ${pair.upperVoice + 1} and voice ${pair.upperVoice + 2}`;
|
|
8729
|
+
if (rules.forbidParallelPerfects) {
|
|
8730
|
+
for (const p of pair.parallelPerfects) {
|
|
8731
|
+
out.push(`Parallel ${p.intervalPc === 0 ? "octaves" : "fifths"} ${label} at beat ${p.atBeat} \u2014 approach perfect intervals by contrary or oblique motion.`);
|
|
8732
|
+
}
|
|
8733
|
+
}
|
|
8734
|
+
if (rules.forbidVoiceCrossing && pair.crossings.length > 0) {
|
|
8735
|
+
out.push(`Voice crossing ${label} at beat${pair.crossings.length > 1 ? "s" : ""} ${pair.crossings.join(", ")} \u2014 keep each voice inside its register lane.`);
|
|
8736
|
+
}
|
|
8737
|
+
if (pair.onsetIndependence < rules.minOnsetIndependence) {
|
|
8738
|
+
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.`);
|
|
8739
|
+
}
|
|
8740
|
+
}
|
|
8741
|
+
return out;
|
|
8742
|
+
}
|
|
8743
|
+
|
|
8744
|
+
// src/ensemble-core/styles.ts
|
|
8745
|
+
var ENSEMBLE_STYLES = ["counterpoint", "chorale", "interlock"];
|
|
8746
|
+
var STYLE_RULES = {
|
|
8747
|
+
counterpoint: {
|
|
8748
|
+
forbidParallelPerfects: true,
|
|
8749
|
+
forbidVoiceCrossing: true,
|
|
8750
|
+
minOnsetIndependence: 0.35,
|
|
8751
|
+
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."
|
|
8752
|
+
},
|
|
8753
|
+
chorale: {
|
|
8754
|
+
forbidParallelPerfects: true,
|
|
8755
|
+
forbidVoiceCrossing: true,
|
|
8756
|
+
minOnsetIndependence: 0,
|
|
8757
|
+
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."
|
|
8758
|
+
},
|
|
8759
|
+
interlock: {
|
|
8760
|
+
forbidParallelPerfects: false,
|
|
8761
|
+
forbidVoiceCrossing: false,
|
|
8762
|
+
minOnsetIndependence: 0.6,
|
|
8763
|
+
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."
|
|
8764
|
+
}
|
|
8765
|
+
};
|
|
8766
|
+
|
|
8767
|
+
// src/ensemble-core/ensemble-schema.ts
|
|
8768
|
+
var SUBMIT_ENSEMBLE_TOOL_NAME = "submit_ensemble";
|
|
8769
|
+
function buildSubmitEnsembleParameters(voiceCount) {
|
|
8770
|
+
return {
|
|
8771
|
+
type: "object",
|
|
8772
|
+
properties: {
|
|
8773
|
+
voices: {
|
|
8774
|
+
type: "array",
|
|
8775
|
+
description: `Exactly ${voiceCount} voices, voiceIndex 0 (top) through ${voiceCount - 1} (bottom).`,
|
|
8776
|
+
items: {
|
|
8777
|
+
type: "object",
|
|
8778
|
+
properties: {
|
|
8779
|
+
voiceIndex: { type: "integer", description: "0 = top voice" },
|
|
8780
|
+
notes: {
|
|
8781
|
+
type: "array",
|
|
8782
|
+
items: {
|
|
8783
|
+
type: "object",
|
|
8784
|
+
properties: {
|
|
8785
|
+
pitch: { type: "integer", description: "MIDI note number 0-127" },
|
|
8786
|
+
startBeat: { type: "number", description: "quarter-note beats from clip start" },
|
|
8787
|
+
durationBeats: { type: "number", description: "duration in quarter-note beats" },
|
|
8788
|
+
velocity: { type: "integer", description: "1-127" }
|
|
8789
|
+
},
|
|
8790
|
+
required: ["pitch", "startBeat", "durationBeats", "velocity"]
|
|
8791
|
+
}
|
|
8792
|
+
}
|
|
8793
|
+
},
|
|
8794
|
+
required: ["voiceIndex", "notes"]
|
|
8795
|
+
}
|
|
8796
|
+
}
|
|
8797
|
+
},
|
|
8798
|
+
required: ["voices"]
|
|
8799
|
+
};
|
|
8800
|
+
}
|
|
8801
|
+
function parseEnsembleArgs(args, voiceCount) {
|
|
8802
|
+
if (typeof args !== "object" || args === null) return null;
|
|
8803
|
+
const voicesRaw = args.voices;
|
|
8804
|
+
if (!Array.isArray(voicesRaw)) return null;
|
|
8805
|
+
const warnings = [];
|
|
8806
|
+
const voiceNotes = Array.from({ length: voiceCount }, () => []);
|
|
8807
|
+
for (const v of voicesRaw) {
|
|
8808
|
+
if (typeof v !== "object" || v === null) continue;
|
|
8809
|
+
const idxRaw = v.voiceIndex;
|
|
8810
|
+
const idx = typeof idxRaw === "number" ? Math.round(idxRaw) : NaN;
|
|
8811
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= voiceCount) {
|
|
8812
|
+
warnings.push(`ignored voice with out-of-range voiceIndex ${String(idxRaw)}`);
|
|
8813
|
+
continue;
|
|
8814
|
+
}
|
|
8815
|
+
const notesRaw = v.notes;
|
|
8816
|
+
if (!Array.isArray(notesRaw)) continue;
|
|
8817
|
+
const notes = [];
|
|
8818
|
+
let dropped = 0;
|
|
8819
|
+
for (const n of notesRaw) {
|
|
8820
|
+
const note = n;
|
|
8821
|
+
if (typeof note?.pitch === "number" && typeof note?.startBeat === "number" && typeof note?.durationBeats === "number" && typeof note?.velocity === "number" && note.durationBeats > 0 && note.startBeat >= 0) {
|
|
8822
|
+
notes.push({
|
|
8823
|
+
pitch: Math.max(0, Math.min(127, Math.round(note.pitch))),
|
|
8824
|
+
startBeat: note.startBeat,
|
|
8825
|
+
durationBeats: note.durationBeats,
|
|
8826
|
+
velocity: Math.max(1, Math.min(127, Math.round(note.velocity)))
|
|
8827
|
+
});
|
|
8828
|
+
} else {
|
|
8829
|
+
dropped += 1;
|
|
8830
|
+
}
|
|
8831
|
+
}
|
|
8832
|
+
if (dropped > 0) warnings.push(`voice ${idx}: dropped ${dropped} malformed note(s)`);
|
|
8833
|
+
voiceNotes[idx] = notes;
|
|
8834
|
+
}
|
|
8835
|
+
const returned = voicesRaw.length;
|
|
8836
|
+
if (returned !== voiceCount) {
|
|
8837
|
+
warnings.push(`model returned ${returned} voices for a ${voiceCount}-voice ensemble`);
|
|
8838
|
+
}
|
|
8839
|
+
const anyNotes = voiceNotes.some((v) => v.length > 0);
|
|
8840
|
+
return anyNotes ? { voiceNotes, warnings } : null;
|
|
8841
|
+
}
|
|
8842
|
+
|
|
8843
|
+
// src/ensemble-core/ensemble-prompt.ts
|
|
8844
|
+
function voiceContractLine(spec) {
|
|
8845
|
+
const root = spec.rootOnly ? " ROOT PITCH CLASS ONLY (each bar's chord root)." : "";
|
|
8846
|
+
return `- Voice ${spec.voiceIndex + 1} (${spec.label}): MIDI ${spec.registerLow}-${spec.registerHigh}, max ${spec.maxNotesPerBar} notes/bar, rhythm: ${spec.rhythmPalette}. ${spec.harmonicDiscipline}.${root}`;
|
|
8847
|
+
}
|
|
8848
|
+
function buildEnsembleSystemPrompt(specs, style) {
|
|
8849
|
+
const styleParagraph = STYLE_RULES[style].promptParagraph;
|
|
8850
|
+
return `You are an ensemble composer. Compose ${specs.length} voices as ONE piece of music \u2014 not ${specs.length} independent parts.
|
|
8851
|
+
|
|
8852
|
+
Submit your composition by calling the ${SUBMIT_ENSEMBLE_TOOL_NAME} tool with all ${specs.length} voices.
|
|
8853
|
+
|
|
8854
|
+
THE ENSEMBLE RULES (most important):
|
|
8855
|
+
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.
|
|
8856
|
+
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.
|
|
8857
|
+
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.
|
|
8858
|
+
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.
|
|
8859
|
+
5. Not every voice plays all the time \u2014 rests are structural. Avoid all voices attacking the same beat except at phrase boundaries.
|
|
8860
|
+
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).
|
|
8861
|
+
|
|
8862
|
+
${styleParagraph}
|
|
8863
|
+
|
|
8864
|
+
PER-VOICE CONTRACTS:
|
|
8865
|
+
${specs.map(voiceContractLine).join("\n")}`;
|
|
8866
|
+
}
|
|
8867
|
+
function buildViolationRetrySuffix(violations) {
|
|
8868
|
+
if (violations.length === 0) return "";
|
|
8869
|
+
return `
|
|
8870
|
+
|
|
8871
|
+
Your previous ensemble had these problems \u2014 fix them while keeping everything that worked:
|
|
8872
|
+
` + violations.map((v) => `- ${v}`).join("\n");
|
|
8873
|
+
}
|
|
8874
|
+
|
|
8453
8875
|
// src/constants/sdk-version.ts
|
|
8454
|
-
var PLUGIN_SDK_VERSION = "2.
|
|
8876
|
+
var PLUGIN_SDK_VERSION = "2.42.0";
|
|
8455
8877
|
|
|
8456
8878
|
// src/utils/format-concurrent-tracks.ts
|
|
8457
8879
|
function formatConcurrentTracks(ctx) {
|
|
8458
8880
|
const tracks = ctx.concurrentTracks;
|
|
8459
8881
|
if (!tracks || tracks.length === 0) return "";
|
|
8460
|
-
const
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
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
|
-
}
|
|
8882
|
+
const pinned = tracks.filter((t) => t.pinned);
|
|
8883
|
+
const ambient = tracks.filter((t) => !t.pinned);
|
|
8884
|
+
const lines = [];
|
|
8885
|
+
if (pinned.length > 0) {
|
|
8886
|
+
lines.push(
|
|
8887
|
+
"REFERENCE TRACKS (write in counterpoint against these \u2014 interlock with their rhythm, avoid doubling their onsets, favor contrary or oblique motion):"
|
|
8888
|
+
);
|
|
8889
|
+
for (const track of pinned) pushTrackLines(lines, track);
|
|
8890
|
+
}
|
|
8891
|
+
if (ambient.length > 0) {
|
|
8892
|
+
lines.push(`Concurrent tracks in scene (already generated):`);
|
|
8893
|
+
for (const track of ambient) pushTrackLines(lines, track);
|
|
8478
8894
|
}
|
|
8479
8895
|
if (ctx.truncatedTrackCount && ctx.truncatedTrackCount > 0) {
|
|
8480
8896
|
lines.push(
|
|
@@ -8483,6 +8899,25 @@ function formatConcurrentTracks(ctx) {
|
|
|
8483
8899
|
}
|
|
8484
8900
|
return lines.join("\n");
|
|
8485
8901
|
}
|
|
8902
|
+
function pushTrackLines(lines, track) {
|
|
8903
|
+
const nameStr = track.name ? ` name="${escapeQuotes(track.name)}"` : "";
|
|
8904
|
+
const promptStr = track.prompt ? ` prompt="${escapeQuotes(track.prompt)}"` : "";
|
|
8905
|
+
lines.push(` - role=${track.role ?? "unknown"}${nameStr}${promptStr}`);
|
|
8906
|
+
if (track.notesByChord.length === 0) {
|
|
8907
|
+
lines.push(` (no notes)`);
|
|
8908
|
+
} else {
|
|
8909
|
+
for (const segment of track.notesByChord) {
|
|
8910
|
+
if (segment.notes.length === 0) continue;
|
|
8911
|
+
lines.push(` ${formatChordSegment(segment)}`);
|
|
8912
|
+
}
|
|
8913
|
+
}
|
|
8914
|
+
if (track.truncated && typeof track.originalNoteCount === "number") {
|
|
8915
|
+
const dropped = track.originalNoteCount - sumKeptNotes(track.notesByChord);
|
|
8916
|
+
if (dropped > 0) {
|
|
8917
|
+
lines.push(` \u2026 (${dropped} more notes truncated)`);
|
|
8918
|
+
}
|
|
8919
|
+
}
|
|
8920
|
+
}
|
|
8486
8921
|
function formatChordSegment(segment) {
|
|
8487
8922
|
const [start, end] = segment.chordRangeQn;
|
|
8488
8923
|
const notesJson = JSON.stringify(segment.notes.map(compactNote2));
|
|
@@ -8607,6 +9042,9 @@ export {
|
|
|
8607
9042
|
DownloadPackButton,
|
|
8608
9043
|
EMPTY_FX_DETAIL_STATE,
|
|
8609
9044
|
EMPTY_FX_STATE,
|
|
9045
|
+
ENSEMBLE_MAX_VOICES,
|
|
9046
|
+
ENSEMBLE_MIN_VOICES,
|
|
9047
|
+
ENSEMBLE_STYLES,
|
|
8610
9048
|
EQUAL_POWER_GAIN,
|
|
8611
9049
|
FX_CATEGORIES,
|
|
8612
9050
|
FX_CHAIN_ORDER,
|
|
@@ -8622,6 +9060,7 @@ export {
|
|
|
8622
9060
|
ImportTrackModal,
|
|
8623
9061
|
TrackDrawer as InstrumentDrawer,
|
|
8624
9062
|
LevelMeter,
|
|
9063
|
+
MIN_NOTE_DURATION_BEATS,
|
|
8625
9064
|
Modal,
|
|
8626
9065
|
OffsetScrubber,
|
|
8627
9066
|
PLUGIN_SDK_VERSION,
|
|
@@ -8633,6 +9072,8 @@ export {
|
|
|
8633
9072
|
RESIZE_HANDLE_PX,
|
|
8634
9073
|
ROW_HEIGHT,
|
|
8635
9074
|
SLIDER_UNITY,
|
|
9075
|
+
STYLE_RULES,
|
|
9076
|
+
SUBMIT_ENSEMBLE_TOOL_NAME,
|
|
8636
9077
|
SamplePackCTACard,
|
|
8637
9078
|
ScrollingWaveform,
|
|
8638
9079
|
SorceryProgressBar,
|
|
@@ -8645,6 +9086,7 @@ export {
|
|
|
8645
9086
|
TransitionDesigner,
|
|
8646
9087
|
VolumeSlider,
|
|
8647
9088
|
WaveformView,
|
|
9089
|
+
analyzeEnsemble,
|
|
8648
9090
|
analyzeWavPeak,
|
|
8649
9091
|
asAudioEffect,
|
|
8650
9092
|
asCrossfadeMeta,
|
|
@@ -8652,8 +9094,11 @@ export {
|
|
|
8652
9094
|
asTransitionDesignerDraft,
|
|
8653
9095
|
buildCrossfadeInpaintPrompt,
|
|
8654
9096
|
buildCrossfadeVolumeCurves,
|
|
9097
|
+
buildEnsembleSystemPrompt,
|
|
8655
9098
|
buildFadeVolumeCurve,
|
|
8656
9099
|
buildRowSlots,
|
|
9100
|
+
buildSubmitEnsembleParameters,
|
|
9101
|
+
buildViolationRetrySuffix,
|
|
8657
9102
|
calculateTimeBasedTarget,
|
|
8658
9103
|
cellToPx,
|
|
8659
9104
|
centerScrollTop,
|
|
@@ -8662,15 +9107,21 @@ export {
|
|
|
8662
9107
|
dbIdsFromKeys,
|
|
8663
9108
|
dbToSlider,
|
|
8664
9109
|
defaultFadeGesture,
|
|
9110
|
+
defaultVoiceSpecs,
|
|
9111
|
+
describeViolations,
|
|
8665
9112
|
drawWaveform,
|
|
9113
|
+
enforceVoice,
|
|
9114
|
+
foldPitchToRegister,
|
|
8666
9115
|
formatConcurrentTracks,
|
|
8667
9116
|
hashString,
|
|
8668
9117
|
moveItem,
|
|
9118
|
+
nearestPitchWithPc,
|
|
8669
9119
|
newTrackState,
|
|
8670
9120
|
normalizeSlots,
|
|
8671
9121
|
padPair,
|
|
8672
9122
|
padSlots,
|
|
8673
9123
|
parseCrossfadePairs,
|
|
9124
|
+
parseEnsembleArgs,
|
|
8674
9125
|
parseFades,
|
|
8675
9126
|
parseLLMNoteResponse,
|
|
8676
9127
|
parseTrackGroups,
|