@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.js
CHANGED
|
@@ -43,6 +43,9 @@ __export(index_exports, {
|
|
|
43
43
|
DownloadPackButton: () => DownloadPackButton,
|
|
44
44
|
EMPTY_FX_DETAIL_STATE: () => EMPTY_FX_DETAIL_STATE,
|
|
45
45
|
EMPTY_FX_STATE: () => EMPTY_FX_STATE,
|
|
46
|
+
ENSEMBLE_MAX_VOICES: () => ENSEMBLE_MAX_VOICES,
|
|
47
|
+
ENSEMBLE_MIN_VOICES: () => ENSEMBLE_MIN_VOICES,
|
|
48
|
+
ENSEMBLE_STYLES: () => ENSEMBLE_STYLES,
|
|
46
49
|
EQUAL_POWER_GAIN: () => EQUAL_POWER_GAIN,
|
|
47
50
|
FX_CATEGORIES: () => FX_CATEGORIES,
|
|
48
51
|
FX_CHAIN_ORDER: () => FX_CHAIN_ORDER,
|
|
@@ -58,6 +61,7 @@ __export(index_exports, {
|
|
|
58
61
|
ImportTrackModal: () => ImportTrackModal,
|
|
59
62
|
InstrumentDrawer: () => TrackDrawer,
|
|
60
63
|
LevelMeter: () => LevelMeter,
|
|
64
|
+
MIN_NOTE_DURATION_BEATS: () => MIN_NOTE_DURATION_BEATS,
|
|
61
65
|
Modal: () => Modal,
|
|
62
66
|
OffsetScrubber: () => OffsetScrubber,
|
|
63
67
|
PLUGIN_SDK_VERSION: () => PLUGIN_SDK_VERSION,
|
|
@@ -69,6 +73,8 @@ __export(index_exports, {
|
|
|
69
73
|
RESIZE_HANDLE_PX: () => RESIZE_HANDLE_PX,
|
|
70
74
|
ROW_HEIGHT: () => ROW_HEIGHT,
|
|
71
75
|
SLIDER_UNITY: () => SLIDER_UNITY,
|
|
76
|
+
STYLE_RULES: () => STYLE_RULES,
|
|
77
|
+
SUBMIT_ENSEMBLE_TOOL_NAME: () => SUBMIT_ENSEMBLE_TOOL_NAME,
|
|
72
78
|
SamplePackCTACard: () => SamplePackCTACard,
|
|
73
79
|
ScrollingWaveform: () => ScrollingWaveform,
|
|
74
80
|
SorceryProgressBar: () => SorceryProgressBar,
|
|
@@ -81,6 +87,7 @@ __export(index_exports, {
|
|
|
81
87
|
TransitionDesigner: () => TransitionDesigner,
|
|
82
88
|
VolumeSlider: () => VolumeSlider,
|
|
83
89
|
WaveformView: () => WaveformView,
|
|
90
|
+
analyzeEnsemble: () => analyzeEnsemble,
|
|
84
91
|
analyzeWavPeak: () => analyzeWavPeak,
|
|
85
92
|
asAudioEffect: () => asAudioEffect,
|
|
86
93
|
asCrossfadeMeta: () => asCrossfadeMeta,
|
|
@@ -88,8 +95,11 @@ __export(index_exports, {
|
|
|
88
95
|
asTransitionDesignerDraft: () => asTransitionDesignerDraft,
|
|
89
96
|
buildCrossfadeInpaintPrompt: () => buildCrossfadeInpaintPrompt,
|
|
90
97
|
buildCrossfadeVolumeCurves: () => buildCrossfadeVolumeCurves,
|
|
98
|
+
buildEnsembleSystemPrompt: () => buildEnsembleSystemPrompt,
|
|
91
99
|
buildFadeVolumeCurve: () => buildFadeVolumeCurve,
|
|
92
100
|
buildRowSlots: () => buildRowSlots,
|
|
101
|
+
buildSubmitEnsembleParameters: () => buildSubmitEnsembleParameters,
|
|
102
|
+
buildViolationRetrySuffix: () => buildViolationRetrySuffix,
|
|
93
103
|
calculateTimeBasedTarget: () => calculateTimeBasedTarget,
|
|
94
104
|
cellToPx: () => cellToPx,
|
|
95
105
|
centerScrollTop: () => centerScrollTop,
|
|
@@ -98,15 +108,21 @@ __export(index_exports, {
|
|
|
98
108
|
dbIdsFromKeys: () => dbIdsFromKeys,
|
|
99
109
|
dbToSlider: () => dbToSlider,
|
|
100
110
|
defaultFadeGesture: () => defaultFadeGesture,
|
|
111
|
+
defaultVoiceSpecs: () => defaultVoiceSpecs,
|
|
112
|
+
describeViolations: () => describeViolations,
|
|
101
113
|
drawWaveform: () => drawWaveform,
|
|
114
|
+
enforceVoice: () => enforceVoice,
|
|
115
|
+
foldPitchToRegister: () => foldPitchToRegister,
|
|
102
116
|
formatConcurrentTracks: () => formatConcurrentTracks,
|
|
103
117
|
hashString: () => hashString,
|
|
104
118
|
moveItem: () => moveItem,
|
|
119
|
+
nearestPitchWithPc: () => nearestPitchWithPc,
|
|
105
120
|
newTrackState: () => newTrackState,
|
|
106
121
|
normalizeSlots: () => normalizeSlots,
|
|
107
122
|
padPair: () => padPair,
|
|
108
123
|
padSlots: () => padSlots,
|
|
109
124
|
parseCrossfadePairs: () => parseCrossfadePairs,
|
|
125
|
+
parseEnsembleArgs: () => parseEnsembleArgs,
|
|
110
126
|
parseFades: () => parseFades,
|
|
111
127
|
parseLLMNoteResponse: () => parseLLMNoteResponse,
|
|
112
128
|
parseTrackGroups: () => parseTrackGroups,
|
|
@@ -8595,31 +8611,447 @@ function createSurgeSoundAdapter(host, overrides = {}) {
|
|
|
8595
8611
|
};
|
|
8596
8612
|
}
|
|
8597
8613
|
|
|
8614
|
+
// src/ensemble-core/voice-spec.ts
|
|
8615
|
+
var TOP = {
|
|
8616
|
+
label: "high florid line",
|
|
8617
|
+
role: "lead",
|
|
8618
|
+
registerLow: 72,
|
|
8619
|
+
registerHigh: 96,
|
|
8620
|
+
maxNotesPerBar: 8,
|
|
8621
|
+
rhythmPalette: "8ths and 16ths; melisma and short runs welcome",
|
|
8622
|
+
harmonicDiscipline: "freest voice \u2014 non-chord tones as passing/neighbor tones on weak beats, resolving by step",
|
|
8623
|
+
monoPreference: "high"
|
|
8624
|
+
};
|
|
8625
|
+
var COUNTER = {
|
|
8626
|
+
label: "countermelody",
|
|
8627
|
+
role: "strings",
|
|
8628
|
+
registerLow: 65,
|
|
8629
|
+
registerHigh: 86,
|
|
8630
|
+
maxNotesPerBar: 6,
|
|
8631
|
+
rhythmPalette: "8ths and quarters; move when the top voice rests",
|
|
8632
|
+
harmonicDiscipline: "mostly chord tones; may imitate the top voice's motifs a bar later",
|
|
8633
|
+
monoPreference: "high"
|
|
8634
|
+
};
|
|
8635
|
+
var INNER = {
|
|
8636
|
+
label: "inner voice",
|
|
8637
|
+
role: "strings",
|
|
8638
|
+
registerLow: 55,
|
|
8639
|
+
registerHigh: 76,
|
|
8640
|
+
maxNotesPerBar: 4,
|
|
8641
|
+
rhythmPalette: "quarters and halves",
|
|
8642
|
+
harmonicDiscipline: "chord tones with smooth stepwise motion between them",
|
|
8643
|
+
monoPreference: "high"
|
|
8644
|
+
};
|
|
8645
|
+
var INNER_2 = {
|
|
8646
|
+
label: "second inner voice",
|
|
8647
|
+
role: "strings",
|
|
8648
|
+
registerLow: 60,
|
|
8649
|
+
registerHigh: 81,
|
|
8650
|
+
maxNotesPerBar: 5,
|
|
8651
|
+
rhythmPalette: "quarters with occasional 8th-note motion",
|
|
8652
|
+
harmonicDiscipline: "chord tones; fill gaps the other inner voice leaves",
|
|
8653
|
+
monoPreference: "high"
|
|
8654
|
+
};
|
|
8655
|
+
var TENOR = {
|
|
8656
|
+
label: "low counterline",
|
|
8657
|
+
role: "strings",
|
|
8658
|
+
registerLow: 43,
|
|
8659
|
+
registerHigh: 64,
|
|
8660
|
+
maxNotesPerBar: 3,
|
|
8661
|
+
rhythmPalette: "quarters and halves; brief walking figures at cadences",
|
|
8662
|
+
harmonicDiscipline: "roots and fifths emphasized; passing tones only between chord tones",
|
|
8663
|
+
monoPreference: "low"
|
|
8664
|
+
};
|
|
8665
|
+
var BASS = {
|
|
8666
|
+
label: "bassline",
|
|
8667
|
+
role: "bass",
|
|
8668
|
+
registerLow: 36,
|
|
8669
|
+
registerHigh: 60,
|
|
8670
|
+
maxNotesPerBar: 3,
|
|
8671
|
+
rhythmPalette: "quarters and halves",
|
|
8672
|
+
harmonicDiscipline: "chord roots and fifths; stepwise approaches into chord changes",
|
|
8673
|
+
monoPreference: "low"
|
|
8674
|
+
};
|
|
8675
|
+
var SUB = {
|
|
8676
|
+
label: "sub anchor",
|
|
8677
|
+
role: "808s",
|
|
8678
|
+
registerLow: 24,
|
|
8679
|
+
registerHigh: 43,
|
|
8680
|
+
maxNotesPerBar: 2,
|
|
8681
|
+
rhythmPalette: "halves and whole notes; sustain into the bar",
|
|
8682
|
+
harmonicDiscipline: "ROOT pitch class only \u2014 the harmonic anchor",
|
|
8683
|
+
rootOnly: true,
|
|
8684
|
+
monoPreference: "low"
|
|
8685
|
+
};
|
|
8686
|
+
var ENSEMBLE_MIN_VOICES = 2;
|
|
8687
|
+
var ENSEMBLE_MAX_VOICES = 6;
|
|
8688
|
+
var SPEC_TABLES = {
|
|
8689
|
+
2: [TOP, BASS],
|
|
8690
|
+
3: [TOP, INNER, BASS],
|
|
8691
|
+
4: [TOP, COUNTER, TENOR, BASS],
|
|
8692
|
+
5: [TOP, COUNTER, INNER, TENOR, SUB],
|
|
8693
|
+
6: [TOP, COUNTER, INNER_2, INNER, TENOR, SUB]
|
|
8694
|
+
};
|
|
8695
|
+
function defaultVoiceSpecs(voiceCount) {
|
|
8696
|
+
const n = Math.max(ENSEMBLE_MIN_VOICES, Math.min(ENSEMBLE_MAX_VOICES, Math.round(voiceCount)));
|
|
8697
|
+
return SPEC_TABLES[n].map((spec, voiceIndex) => ({ ...spec, voiceIndex }));
|
|
8698
|
+
}
|
|
8699
|
+
|
|
8700
|
+
// src/ensemble-core/enforce-voice.ts
|
|
8701
|
+
var MIN_NOTE_DURATION_BEATS = 0.0625;
|
|
8702
|
+
var BEATS_PER_BAR = 4;
|
|
8703
|
+
function foldPitchToRegister(pitch, low, high) {
|
|
8704
|
+
let p = pitch;
|
|
8705
|
+
while (p < low) p += 12;
|
|
8706
|
+
while (p > high) p -= 12;
|
|
8707
|
+
if (p < low) p = low;
|
|
8708
|
+
if (p > high) p = high;
|
|
8709
|
+
return p;
|
|
8710
|
+
}
|
|
8711
|
+
function nearestPitchWithPc(reference, pc, low, high) {
|
|
8712
|
+
let best = null;
|
|
8713
|
+
for (let p = low; p <= high; p++) {
|
|
8714
|
+
if ((p % 12 + 12) % 12 !== pc) continue;
|
|
8715
|
+
if (best === null || Math.abs(p - reference) < Math.abs(best - reference)) best = p;
|
|
8716
|
+
}
|
|
8717
|
+
return best ?? foldPitchToRegister(reference, low, high);
|
|
8718
|
+
}
|
|
8719
|
+
function snapToNearestPc(pitch, pcs) {
|
|
8720
|
+
if (pcs.size === 0) return pitch;
|
|
8721
|
+
for (let d = 0; d <= 6; d++) {
|
|
8722
|
+
if (pcs.has(((pitch - d) % 12 + 12) % 12)) return pitch - d;
|
|
8723
|
+
if (pcs.has(((pitch + d) % 12 + 12) % 12)) return pitch + d;
|
|
8724
|
+
}
|
|
8725
|
+
return pitch;
|
|
8726
|
+
}
|
|
8727
|
+
function enforceVoice(rawNotes, spec, opts) {
|
|
8728
|
+
const repairs = [];
|
|
8729
|
+
const clipEnd = opts.bars * BEATS_PER_BAR;
|
|
8730
|
+
let notes = [];
|
|
8731
|
+
for (const n of rawNotes) {
|
|
8732
|
+
if (!Number.isFinite(n.pitch) || !Number.isFinite(n.startBeat) || !Number.isFinite(n.durationBeats)) continue;
|
|
8733
|
+
if (n.startBeat >= clipEnd || n.startBeat < 0) {
|
|
8734
|
+
repairs.push(`voice ${spec.voiceIndex}: dropped note outside the ${opts.bars}-bar clip (start ${n.startBeat})`);
|
|
8735
|
+
continue;
|
|
8736
|
+
}
|
|
8737
|
+
const durationBeats = Math.max(
|
|
8738
|
+
MIN_NOTE_DURATION_BEATS,
|
|
8739
|
+
Math.min(n.durationBeats, clipEnd - n.startBeat)
|
|
8740
|
+
);
|
|
8741
|
+
notes.push({ ...n, durationBeats });
|
|
8742
|
+
}
|
|
8743
|
+
notes = notes.map((n) => {
|
|
8744
|
+
const folded = foldPitchToRegister(Math.round(n.pitch), spec.registerLow, spec.registerHigh);
|
|
8745
|
+
if (folded !== n.pitch) {
|
|
8746
|
+
repairs.push(`voice ${spec.voiceIndex}: folded pitch ${n.pitch} into register ${spec.registerLow}-${spec.registerHigh} (${folded})`);
|
|
8747
|
+
}
|
|
8748
|
+
return { ...n, pitch: folded };
|
|
8749
|
+
});
|
|
8750
|
+
if (spec.rootOnly && opts.chordRootPcAtBar) {
|
|
8751
|
+
notes = notes.map((n) => {
|
|
8752
|
+
const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
|
|
8753
|
+
const rootPc = opts.chordRootPcAtBar(bar);
|
|
8754
|
+
if (rootPc === null) return n;
|
|
8755
|
+
const pinned = nearestPitchWithPc(n.pitch, rootPc, spec.registerLow, spec.registerHigh);
|
|
8756
|
+
if (pinned !== n.pitch) {
|
|
8757
|
+
repairs.push(`voice ${spec.voiceIndex}: pinned bar ${bar + 1} note to the chord root (${n.pitch} \u2192 ${pinned})`);
|
|
8758
|
+
}
|
|
8759
|
+
return { ...n, pitch: pinned };
|
|
8760
|
+
});
|
|
8761
|
+
}
|
|
8762
|
+
if (opts.scalePcs && opts.scalePcs.size > 0 && !spec.rootOnly) {
|
|
8763
|
+
notes = notes.map((n) => {
|
|
8764
|
+
const pc = (n.pitch % 12 + 12) % 12;
|
|
8765
|
+
if (opts.scalePcs.has(pc)) return n;
|
|
8766
|
+
const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
|
|
8767
|
+
const chordPcs = opts.chordPcsAtBar?.(bar);
|
|
8768
|
+
if (chordPcs?.has(pc)) return n;
|
|
8769
|
+
const snapped = foldPitchToRegister(
|
|
8770
|
+
snapToNearestPc(n.pitch, opts.scalePcs),
|
|
8771
|
+
spec.registerLow,
|
|
8772
|
+
spec.registerHigh
|
|
8773
|
+
);
|
|
8774
|
+
if (snapped !== n.pitch) {
|
|
8775
|
+
repairs.push(`voice ${spec.voiceIndex}: snapped out-of-key pitch ${n.pitch} \u2192 ${snapped}`);
|
|
8776
|
+
}
|
|
8777
|
+
return { ...n, pitch: snapped };
|
|
8778
|
+
});
|
|
8779
|
+
}
|
|
8780
|
+
notes.sort((a, b) => a.startBeat - b.startBeat || (spec.monoPreference === "high" ? b.pitch - a.pitch : a.pitch - b.pitch));
|
|
8781
|
+
const mono = [];
|
|
8782
|
+
for (const n of notes) {
|
|
8783
|
+
const prev = mono[mono.length - 1];
|
|
8784
|
+
if (prev && Math.abs(prev.startBeat - n.startBeat) < 1e-9) {
|
|
8785
|
+
repairs.push(`voice ${spec.voiceIndex}: dropped simultaneous note ${n.pitch} at beat ${n.startBeat} (voice is one line)`);
|
|
8786
|
+
continue;
|
|
8787
|
+
}
|
|
8788
|
+
if (prev && prev.startBeat + prev.durationBeats > n.startBeat) {
|
|
8789
|
+
prev.durationBeats = Math.max(MIN_NOTE_DURATION_BEATS, n.startBeat - prev.startBeat);
|
|
8790
|
+
}
|
|
8791
|
+
mono.push({ ...n });
|
|
8792
|
+
}
|
|
8793
|
+
const byBar = /* @__PURE__ */ new Map();
|
|
8794
|
+
for (const n of mono) {
|
|
8795
|
+
const bar = Math.floor(n.startBeat / BEATS_PER_BAR);
|
|
8796
|
+
const bucket = byBar.get(bar) ?? [];
|
|
8797
|
+
bucket.push(n);
|
|
8798
|
+
byBar.set(bar, bucket);
|
|
8799
|
+
}
|
|
8800
|
+
const kept = new Set(mono);
|
|
8801
|
+
for (const [bar, bucket] of byBar) {
|
|
8802
|
+
if (bucket.length <= spec.maxNotesPerBar) continue;
|
|
8803
|
+
const strength = (n) => {
|
|
8804
|
+
const beatInBar = n.startBeat - bar * BEATS_PER_BAR;
|
|
8805
|
+
const onDownbeat = Math.abs(beatInBar % 1) < 1e-9 ? 1 : 0;
|
|
8806
|
+
return n.durationBeats * 4 + n.velocity / 127 + onDownbeat * 2;
|
|
8807
|
+
};
|
|
8808
|
+
const ranked = [...bucket].sort((a, b) => strength(a) - strength(b));
|
|
8809
|
+
const excess = bucket.length - spec.maxNotesPerBar;
|
|
8810
|
+
for (let i = 0; i < excess; i++) {
|
|
8811
|
+
kept.delete(ranked[i]);
|
|
8812
|
+
}
|
|
8813
|
+
repairs.push(`voice ${spec.voiceIndex}: thinned bar ${bar + 1} from ${bucket.length} to ${spec.maxNotesPerBar} notes (density cap)`);
|
|
8814
|
+
}
|
|
8815
|
+
return { notes: mono.filter((n) => kept.has(n)), repairs };
|
|
8816
|
+
}
|
|
8817
|
+
|
|
8818
|
+
// src/ensemble-core/analyze-ensemble.ts
|
|
8819
|
+
var EPS = 1e-6;
|
|
8820
|
+
function pitchAt(voice, beat) {
|
|
8821
|
+
for (const n of voice) {
|
|
8822
|
+
if (n.startBeat - EPS <= beat && beat < n.startBeat + n.durationBeats - EPS) return n.pitch;
|
|
8823
|
+
}
|
|
8824
|
+
return null;
|
|
8825
|
+
}
|
|
8826
|
+
function onsetSet(voice) {
|
|
8827
|
+
return [...new Set(voice.map((n) => Math.round(n.startBeat * 96) / 96))].sort((a, b) => a - b);
|
|
8828
|
+
}
|
|
8829
|
+
function analyzeEnsemble(voices) {
|
|
8830
|
+
const pairs = [];
|
|
8831
|
+
for (let i = 0; i + 1 < voices.length; i++) {
|
|
8832
|
+
const upper = voices[i];
|
|
8833
|
+
const lower = voices[i + 1];
|
|
8834
|
+
const upperOnsets = onsetSet(upper);
|
|
8835
|
+
const lowerOnsets = new Set(onsetSet(lower));
|
|
8836
|
+
const shared = upperOnsets.filter((b) => lowerOnsets.has(b));
|
|
8837
|
+
const onsetIndependence = upperOnsets.length === 0 ? 1 : 1 - shared.length / upperOnsets.length;
|
|
8838
|
+
const motion = { contrary: 0, oblique: 0, similar: 0, parallel: 0 };
|
|
8839
|
+
const parallelPerfects = [];
|
|
8840
|
+
for (let s = 0; s + 1 < shared.length; s++) {
|
|
8841
|
+
const [b0, b1] = [shared[s], shared[s + 1]];
|
|
8842
|
+
const u0 = pitchAt(upper, b0);
|
|
8843
|
+
const u1 = pitchAt(upper, b1);
|
|
8844
|
+
const l0 = pitchAt(lower, b0);
|
|
8845
|
+
const l1 = pitchAt(lower, b1);
|
|
8846
|
+
if (u0 === null || u1 === null || l0 === null || l1 === null) continue;
|
|
8847
|
+
const du = Math.sign(u1 - u0);
|
|
8848
|
+
const dl = Math.sign(l1 - l0);
|
|
8849
|
+
let kind;
|
|
8850
|
+
if (du === 0 || dl === 0) kind = "oblique";
|
|
8851
|
+
else if (du !== dl) kind = "contrary";
|
|
8852
|
+
else {
|
|
8853
|
+
kind = u1 - l1 === u0 - l0 ? "parallel" : "similar";
|
|
8854
|
+
}
|
|
8855
|
+
motion[kind] += 1;
|
|
8856
|
+
if (kind === "parallel") {
|
|
8857
|
+
const intervalPc = ((u1 - l1) % 12 + 12) % 12;
|
|
8858
|
+
if (intervalPc === 0 || intervalPc === 7) {
|
|
8859
|
+
parallelPerfects.push({ atBeat: b1, intervalPc });
|
|
8860
|
+
}
|
|
8861
|
+
}
|
|
8862
|
+
}
|
|
8863
|
+
const crossings = [];
|
|
8864
|
+
for (const b of [...upperOnsets, ...onsetSet(lower)]) {
|
|
8865
|
+
const u = pitchAt(upper, b);
|
|
8866
|
+
const l = pitchAt(lower, b);
|
|
8867
|
+
if (u !== null && l !== null && u < l) crossings.push(b);
|
|
8868
|
+
}
|
|
8869
|
+
pairs.push({
|
|
8870
|
+
upperVoice: i,
|
|
8871
|
+
onsetIndependence,
|
|
8872
|
+
motion,
|
|
8873
|
+
parallelPerfects,
|
|
8874
|
+
crossings: [...new Set(crossings)].sort((a, b) => a - b)
|
|
8875
|
+
});
|
|
8876
|
+
}
|
|
8877
|
+
const allOnsets = voices.map(onsetSet);
|
|
8878
|
+
const union = new Set(allOnsets.flat());
|
|
8879
|
+
let sharedByAll = 0;
|
|
8880
|
+
for (const b of union) {
|
|
8881
|
+
if (allOnsets.every((o) => o.length === 0 || o.includes(b))) sharedByAll += 1;
|
|
8882
|
+
}
|
|
8883
|
+
const homorhythmScore = union.size === 0 ? 0 : sharedByAll / union.size;
|
|
8884
|
+
return { pairs, homorhythmScore };
|
|
8885
|
+
}
|
|
8886
|
+
function describeViolations(analysis, rules) {
|
|
8887
|
+
const out = [];
|
|
8888
|
+
for (const pair of analysis.pairs) {
|
|
8889
|
+
const label = `between voice ${pair.upperVoice + 1} and voice ${pair.upperVoice + 2}`;
|
|
8890
|
+
if (rules.forbidParallelPerfects) {
|
|
8891
|
+
for (const p of pair.parallelPerfects) {
|
|
8892
|
+
out.push(`Parallel ${p.intervalPc === 0 ? "octaves" : "fifths"} ${label} at beat ${p.atBeat} \u2014 approach perfect intervals by contrary or oblique motion.`);
|
|
8893
|
+
}
|
|
8894
|
+
}
|
|
8895
|
+
if (rules.forbidVoiceCrossing && pair.crossings.length > 0) {
|
|
8896
|
+
out.push(`Voice crossing ${label} at beat${pair.crossings.length > 1 ? "s" : ""} ${pair.crossings.join(", ")} \u2014 keep each voice inside its register lane.`);
|
|
8897
|
+
}
|
|
8898
|
+
if (pair.onsetIndependence < rules.minOnsetIndependence) {
|
|
8899
|
+
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.`);
|
|
8900
|
+
}
|
|
8901
|
+
}
|
|
8902
|
+
return out;
|
|
8903
|
+
}
|
|
8904
|
+
|
|
8905
|
+
// src/ensemble-core/styles.ts
|
|
8906
|
+
var ENSEMBLE_STYLES = ["counterpoint", "chorale", "interlock"];
|
|
8907
|
+
var STYLE_RULES = {
|
|
8908
|
+
counterpoint: {
|
|
8909
|
+
forbidParallelPerfects: true,
|
|
8910
|
+
forbidVoiceCrossing: true,
|
|
8911
|
+
minOnsetIndependence: 0.35,
|
|
8912
|
+
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."
|
|
8913
|
+
},
|
|
8914
|
+
chorale: {
|
|
8915
|
+
forbidParallelPerfects: true,
|
|
8916
|
+
forbidVoiceCrossing: true,
|
|
8917
|
+
minOnsetIndependence: 0,
|
|
8918
|
+
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."
|
|
8919
|
+
},
|
|
8920
|
+
interlock: {
|
|
8921
|
+
forbidParallelPerfects: false,
|
|
8922
|
+
forbidVoiceCrossing: false,
|
|
8923
|
+
minOnsetIndependence: 0.6,
|
|
8924
|
+
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."
|
|
8925
|
+
}
|
|
8926
|
+
};
|
|
8927
|
+
|
|
8928
|
+
// src/ensemble-core/ensemble-schema.ts
|
|
8929
|
+
var SUBMIT_ENSEMBLE_TOOL_NAME = "submit_ensemble";
|
|
8930
|
+
function buildSubmitEnsembleParameters(voiceCount) {
|
|
8931
|
+
return {
|
|
8932
|
+
type: "object",
|
|
8933
|
+
properties: {
|
|
8934
|
+
voices: {
|
|
8935
|
+
type: "array",
|
|
8936
|
+
description: `Exactly ${voiceCount} voices, voiceIndex 0 (top) through ${voiceCount - 1} (bottom).`,
|
|
8937
|
+
items: {
|
|
8938
|
+
type: "object",
|
|
8939
|
+
properties: {
|
|
8940
|
+
voiceIndex: { type: "integer", description: "0 = top voice" },
|
|
8941
|
+
notes: {
|
|
8942
|
+
type: "array",
|
|
8943
|
+
items: {
|
|
8944
|
+
type: "object",
|
|
8945
|
+
properties: {
|
|
8946
|
+
pitch: { type: "integer", description: "MIDI note number 0-127" },
|
|
8947
|
+
startBeat: { type: "number", description: "quarter-note beats from clip start" },
|
|
8948
|
+
durationBeats: { type: "number", description: "duration in quarter-note beats" },
|
|
8949
|
+
velocity: { type: "integer", description: "1-127" }
|
|
8950
|
+
},
|
|
8951
|
+
required: ["pitch", "startBeat", "durationBeats", "velocity"]
|
|
8952
|
+
}
|
|
8953
|
+
}
|
|
8954
|
+
},
|
|
8955
|
+
required: ["voiceIndex", "notes"]
|
|
8956
|
+
}
|
|
8957
|
+
}
|
|
8958
|
+
},
|
|
8959
|
+
required: ["voices"]
|
|
8960
|
+
};
|
|
8961
|
+
}
|
|
8962
|
+
function parseEnsembleArgs(args, voiceCount) {
|
|
8963
|
+
if (typeof args !== "object" || args === null) return null;
|
|
8964
|
+
const voicesRaw = args.voices;
|
|
8965
|
+
if (!Array.isArray(voicesRaw)) return null;
|
|
8966
|
+
const warnings = [];
|
|
8967
|
+
const voiceNotes = Array.from({ length: voiceCount }, () => []);
|
|
8968
|
+
for (const v of voicesRaw) {
|
|
8969
|
+
if (typeof v !== "object" || v === null) continue;
|
|
8970
|
+
const idxRaw = v.voiceIndex;
|
|
8971
|
+
const idx = typeof idxRaw === "number" ? Math.round(idxRaw) : NaN;
|
|
8972
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= voiceCount) {
|
|
8973
|
+
warnings.push(`ignored voice with out-of-range voiceIndex ${String(idxRaw)}`);
|
|
8974
|
+
continue;
|
|
8975
|
+
}
|
|
8976
|
+
const notesRaw = v.notes;
|
|
8977
|
+
if (!Array.isArray(notesRaw)) continue;
|
|
8978
|
+
const notes = [];
|
|
8979
|
+
let dropped = 0;
|
|
8980
|
+
for (const n of notesRaw) {
|
|
8981
|
+
const note = n;
|
|
8982
|
+
if (typeof note?.pitch === "number" && typeof note?.startBeat === "number" && typeof note?.durationBeats === "number" && typeof note?.velocity === "number" && note.durationBeats > 0 && note.startBeat >= 0) {
|
|
8983
|
+
notes.push({
|
|
8984
|
+
pitch: Math.max(0, Math.min(127, Math.round(note.pitch))),
|
|
8985
|
+
startBeat: note.startBeat,
|
|
8986
|
+
durationBeats: note.durationBeats,
|
|
8987
|
+
velocity: Math.max(1, Math.min(127, Math.round(note.velocity)))
|
|
8988
|
+
});
|
|
8989
|
+
} else {
|
|
8990
|
+
dropped += 1;
|
|
8991
|
+
}
|
|
8992
|
+
}
|
|
8993
|
+
if (dropped > 0) warnings.push(`voice ${idx}: dropped ${dropped} malformed note(s)`);
|
|
8994
|
+
voiceNotes[idx] = notes;
|
|
8995
|
+
}
|
|
8996
|
+
const returned = voicesRaw.length;
|
|
8997
|
+
if (returned !== voiceCount) {
|
|
8998
|
+
warnings.push(`model returned ${returned} voices for a ${voiceCount}-voice ensemble`);
|
|
8999
|
+
}
|
|
9000
|
+
const anyNotes = voiceNotes.some((v) => v.length > 0);
|
|
9001
|
+
return anyNotes ? { voiceNotes, warnings } : null;
|
|
9002
|
+
}
|
|
9003
|
+
|
|
9004
|
+
// src/ensemble-core/ensemble-prompt.ts
|
|
9005
|
+
function voiceContractLine(spec) {
|
|
9006
|
+
const root = spec.rootOnly ? " ROOT PITCH CLASS ONLY (each bar's chord root)." : "";
|
|
9007
|
+
return `- Voice ${spec.voiceIndex + 1} (${spec.label}): MIDI ${spec.registerLow}-${spec.registerHigh}, max ${spec.maxNotesPerBar} notes/bar, rhythm: ${spec.rhythmPalette}. ${spec.harmonicDiscipline}.${root}`;
|
|
9008
|
+
}
|
|
9009
|
+
function buildEnsembleSystemPrompt(specs, style) {
|
|
9010
|
+
const styleParagraph = STYLE_RULES[style].promptParagraph;
|
|
9011
|
+
return `You are an ensemble composer. Compose ${specs.length} voices as ONE piece of music \u2014 not ${specs.length} independent parts.
|
|
9012
|
+
|
|
9013
|
+
Submit your composition by calling the ${SUBMIT_ENSEMBLE_TOOL_NAME} tool with all ${specs.length} voices.
|
|
9014
|
+
|
|
9015
|
+
THE ENSEMBLE RULES (most important):
|
|
9016
|
+
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.
|
|
9017
|
+
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.
|
|
9018
|
+
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.
|
|
9019
|
+
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.
|
|
9020
|
+
5. Not every voice plays all the time \u2014 rests are structural. Avoid all voices attacking the same beat except at phrase boundaries.
|
|
9021
|
+
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).
|
|
9022
|
+
|
|
9023
|
+
${styleParagraph}
|
|
9024
|
+
|
|
9025
|
+
PER-VOICE CONTRACTS:
|
|
9026
|
+
${specs.map(voiceContractLine).join("\n")}`;
|
|
9027
|
+
}
|
|
9028
|
+
function buildViolationRetrySuffix(violations) {
|
|
9029
|
+
if (violations.length === 0) return "";
|
|
9030
|
+
return `
|
|
9031
|
+
|
|
9032
|
+
Your previous ensemble had these problems \u2014 fix them while keeping everything that worked:
|
|
9033
|
+
` + violations.map((v) => `- ${v}`).join("\n");
|
|
9034
|
+
}
|
|
9035
|
+
|
|
8598
9036
|
// src/constants/sdk-version.ts
|
|
8599
|
-
var PLUGIN_SDK_VERSION = "2.
|
|
9037
|
+
var PLUGIN_SDK_VERSION = "2.42.0";
|
|
8600
9038
|
|
|
8601
9039
|
// src/utils/format-concurrent-tracks.ts
|
|
8602
9040
|
function formatConcurrentTracks(ctx) {
|
|
8603
9041
|
const tracks = ctx.concurrentTracks;
|
|
8604
9042
|
if (!tracks || tracks.length === 0) return "";
|
|
8605
|
-
const
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
if (track.truncated && typeof track.originalNoteCount === "number") {
|
|
8618
|
-
const dropped = track.originalNoteCount - sumKeptNotes(track.notesByChord);
|
|
8619
|
-
if (dropped > 0) {
|
|
8620
|
-
lines.push(` \u2026 (${dropped} more notes truncated)`);
|
|
8621
|
-
}
|
|
8622
|
-
}
|
|
9043
|
+
const pinned = tracks.filter((t) => t.pinned);
|
|
9044
|
+
const ambient = tracks.filter((t) => !t.pinned);
|
|
9045
|
+
const lines = [];
|
|
9046
|
+
if (pinned.length > 0) {
|
|
9047
|
+
lines.push(
|
|
9048
|
+
"REFERENCE TRACKS (write in counterpoint against these \u2014 interlock with their rhythm, avoid doubling their onsets, favor contrary or oblique motion):"
|
|
9049
|
+
);
|
|
9050
|
+
for (const track of pinned) pushTrackLines(lines, track);
|
|
9051
|
+
}
|
|
9052
|
+
if (ambient.length > 0) {
|
|
9053
|
+
lines.push(`Concurrent tracks in scene (already generated):`);
|
|
9054
|
+
for (const track of ambient) pushTrackLines(lines, track);
|
|
8623
9055
|
}
|
|
8624
9056
|
if (ctx.truncatedTrackCount && ctx.truncatedTrackCount > 0) {
|
|
8625
9057
|
lines.push(
|
|
@@ -8628,6 +9060,25 @@ function formatConcurrentTracks(ctx) {
|
|
|
8628
9060
|
}
|
|
8629
9061
|
return lines.join("\n");
|
|
8630
9062
|
}
|
|
9063
|
+
function pushTrackLines(lines, track) {
|
|
9064
|
+
const nameStr = track.name ? ` name="${escapeQuotes(track.name)}"` : "";
|
|
9065
|
+
const promptStr = track.prompt ? ` prompt="${escapeQuotes(track.prompt)}"` : "";
|
|
9066
|
+
lines.push(` - role=${track.role ?? "unknown"}${nameStr}${promptStr}`);
|
|
9067
|
+
if (track.notesByChord.length === 0) {
|
|
9068
|
+
lines.push(` (no notes)`);
|
|
9069
|
+
} else {
|
|
9070
|
+
for (const segment of track.notesByChord) {
|
|
9071
|
+
if (segment.notes.length === 0) continue;
|
|
9072
|
+
lines.push(` ${formatChordSegment(segment)}`);
|
|
9073
|
+
}
|
|
9074
|
+
}
|
|
9075
|
+
if (track.truncated && typeof track.originalNoteCount === "number") {
|
|
9076
|
+
const dropped = track.originalNoteCount - sumKeptNotes(track.notesByChord);
|
|
9077
|
+
if (dropped > 0) {
|
|
9078
|
+
lines.push(` \u2026 (${dropped} more notes truncated)`);
|
|
9079
|
+
}
|
|
9080
|
+
}
|
|
9081
|
+
}
|
|
8631
9082
|
function formatChordSegment(segment) {
|
|
8632
9083
|
const [start, end] = segment.chordRangeQn;
|
|
8633
9084
|
const notesJson = JSON.stringify(segment.notes.map(compactNote2));
|
|
@@ -8753,6 +9204,9 @@ function pickTopKWeighted(scored, options = {}) {
|
|
|
8753
9204
|
DownloadPackButton,
|
|
8754
9205
|
EMPTY_FX_DETAIL_STATE,
|
|
8755
9206
|
EMPTY_FX_STATE,
|
|
9207
|
+
ENSEMBLE_MAX_VOICES,
|
|
9208
|
+
ENSEMBLE_MIN_VOICES,
|
|
9209
|
+
ENSEMBLE_STYLES,
|
|
8756
9210
|
EQUAL_POWER_GAIN,
|
|
8757
9211
|
FX_CATEGORIES,
|
|
8758
9212
|
FX_CHAIN_ORDER,
|
|
@@ -8768,6 +9222,7 @@ function pickTopKWeighted(scored, options = {}) {
|
|
|
8768
9222
|
ImportTrackModal,
|
|
8769
9223
|
InstrumentDrawer,
|
|
8770
9224
|
LevelMeter,
|
|
9225
|
+
MIN_NOTE_DURATION_BEATS,
|
|
8771
9226
|
Modal,
|
|
8772
9227
|
OffsetScrubber,
|
|
8773
9228
|
PLUGIN_SDK_VERSION,
|
|
@@ -8779,6 +9234,8 @@ function pickTopKWeighted(scored, options = {}) {
|
|
|
8779
9234
|
RESIZE_HANDLE_PX,
|
|
8780
9235
|
ROW_HEIGHT,
|
|
8781
9236
|
SLIDER_UNITY,
|
|
9237
|
+
STYLE_RULES,
|
|
9238
|
+
SUBMIT_ENSEMBLE_TOOL_NAME,
|
|
8782
9239
|
SamplePackCTACard,
|
|
8783
9240
|
ScrollingWaveform,
|
|
8784
9241
|
SorceryProgressBar,
|
|
@@ -8791,6 +9248,7 @@ function pickTopKWeighted(scored, options = {}) {
|
|
|
8791
9248
|
TransitionDesigner,
|
|
8792
9249
|
VolumeSlider,
|
|
8793
9250
|
WaveformView,
|
|
9251
|
+
analyzeEnsemble,
|
|
8794
9252
|
analyzeWavPeak,
|
|
8795
9253
|
asAudioEffect,
|
|
8796
9254
|
asCrossfadeMeta,
|
|
@@ -8798,8 +9256,11 @@ function pickTopKWeighted(scored, options = {}) {
|
|
|
8798
9256
|
asTransitionDesignerDraft,
|
|
8799
9257
|
buildCrossfadeInpaintPrompt,
|
|
8800
9258
|
buildCrossfadeVolumeCurves,
|
|
9259
|
+
buildEnsembleSystemPrompt,
|
|
8801
9260
|
buildFadeVolumeCurve,
|
|
8802
9261
|
buildRowSlots,
|
|
9262
|
+
buildSubmitEnsembleParameters,
|
|
9263
|
+
buildViolationRetrySuffix,
|
|
8803
9264
|
calculateTimeBasedTarget,
|
|
8804
9265
|
cellToPx,
|
|
8805
9266
|
centerScrollTop,
|
|
@@ -8808,15 +9269,21 @@ function pickTopKWeighted(scored, options = {}) {
|
|
|
8808
9269
|
dbIdsFromKeys,
|
|
8809
9270
|
dbToSlider,
|
|
8810
9271
|
defaultFadeGesture,
|
|
9272
|
+
defaultVoiceSpecs,
|
|
9273
|
+
describeViolations,
|
|
8811
9274
|
drawWaveform,
|
|
9275
|
+
enforceVoice,
|
|
9276
|
+
foldPitchToRegister,
|
|
8812
9277
|
formatConcurrentTracks,
|
|
8813
9278
|
hashString,
|
|
8814
9279
|
moveItem,
|
|
9280
|
+
nearestPitchWithPc,
|
|
8815
9281
|
newTrackState,
|
|
8816
9282
|
normalizeSlots,
|
|
8817
9283
|
padPair,
|
|
8818
9284
|
padSlots,
|
|
8819
9285
|
parseCrossfadePairs,
|
|
9286
|
+
parseEnsembleArgs,
|
|
8820
9287
|
parseFades,
|
|
8821
9288
|
parseLLMNoteResponse,
|
|
8822
9289
|
parseTrackGroups,
|