@waveform-playlist/playout 12.5.5 → 13.0.0-next.1
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/README.md +13 -0
- package/dist/index.d.mts +72 -21
- package/dist/index.d.ts +72 -21
- package/dist/index.js +177 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +193 -132
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -14,31 +14,21 @@ import { gainToDb as gainToDb4 } from "@waveform-playlist/core";
|
|
|
14
14
|
import {
|
|
15
15
|
Volume,
|
|
16
16
|
Gain,
|
|
17
|
-
|
|
17
|
+
connect,
|
|
18
18
|
getDestination,
|
|
19
19
|
getTransport,
|
|
20
20
|
getContext
|
|
21
21
|
} from "tone";
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!param && !hasWarned) {
|
|
29
|
-
hasWarned = true;
|
|
30
|
-
console.warn(
|
|
31
|
-
"[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Mute scheduling may not work correctly."
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return param;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/ToneTrack.ts
|
|
22
|
+
import {
|
|
23
|
+
gainToDb,
|
|
24
|
+
applyFadeIn,
|
|
25
|
+
applyFadeOut,
|
|
26
|
+
createPanStage
|
|
27
|
+
} from "@waveform-playlist/core";
|
|
38
28
|
var ToneTrack = class {
|
|
39
29
|
constructor(options) {
|
|
40
30
|
this.activeSources = /* @__PURE__ */ new Set();
|
|
41
|
-
this.
|
|
31
|
+
this._effectsChain = null;
|
|
42
32
|
// Guard against ghost tick schedule callbacks. After stop/start cycles with
|
|
43
33
|
// loops, stale Clock._lastUpdate causes ticks from the previous cycle to fire
|
|
44
34
|
// Transport.schedule() callbacks at past positions (e.g., time 0 clips fire
|
|
@@ -47,22 +37,25 @@ var ToneTrack = class {
|
|
|
47
37
|
// clips at/after this offset.
|
|
48
38
|
this._scheduleGuardOffset = 0;
|
|
49
39
|
this.track = options.track;
|
|
40
|
+
this.inputGain = new Gain({ gain: 1 });
|
|
50
41
|
this.volumeNode = new Volume(gainToDb(options.track.gain));
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
this.panStage = createPanStage(
|
|
43
|
+
getContext().rawContext,
|
|
44
|
+
options.track.stereoPan,
|
|
45
|
+
options.channelCount ?? 1
|
|
46
|
+
);
|
|
55
47
|
this.muteGain = new Gain(options.track.muted ? 0 : 1);
|
|
56
|
-
this.volumeNode.
|
|
57
|
-
this.
|
|
48
|
+
this.volumeNode.connect(this.panStage.input);
|
|
49
|
+
connect(this.panStage.output, this.muteGain);
|
|
50
|
+
this.muteGain.connect(options.destination || getDestination());
|
|
58
51
|
this._hasClosureEffects = Boolean(options.effects);
|
|
59
52
|
if (options.effects) {
|
|
60
|
-
const cleanup = options.effects(this.
|
|
53
|
+
const cleanup = options.effects(this.inputGain, this.volumeNode, false);
|
|
61
54
|
if (cleanup) {
|
|
62
55
|
this.effectsCleanup = cleanup;
|
|
63
56
|
}
|
|
64
57
|
} else {
|
|
65
|
-
this.
|
|
58
|
+
this.inputGain.connect(this.volumeNode);
|
|
66
59
|
}
|
|
67
60
|
const clipInfos = options.clips || (options.buffer ? [
|
|
68
61
|
{
|
|
@@ -77,11 +70,11 @@ var ToneTrack = class {
|
|
|
77
70
|
] : []);
|
|
78
71
|
const transport = getTransport();
|
|
79
72
|
const rawContext = getContext().rawContext;
|
|
80
|
-
const
|
|
73
|
+
const trackNativeInput = this.inputGain.input;
|
|
81
74
|
this.scheduledClips = clipInfos.map((clipInfo) => {
|
|
82
75
|
const fadeGainNode = rawContext.createGain();
|
|
83
76
|
fadeGainNode.gain.value = clipInfo.gain;
|
|
84
|
-
fadeGainNode.connect(
|
|
77
|
+
fadeGainNode.connect(trackNativeInput);
|
|
85
78
|
const absTransportTime = this.track.startTime + clipInfo.startTime;
|
|
86
79
|
const scheduleId = transport.schedule((audioContextTime) => {
|
|
87
80
|
if (absTransportTime < this._scheduleGuardOffset) {
|
|
@@ -158,10 +151,9 @@ var ToneTrack = class {
|
|
|
158
151
|
addClip(clipInfo) {
|
|
159
152
|
const transport = getTransport();
|
|
160
153
|
const rawContext = getContext().rawContext;
|
|
161
|
-
const volumeNativeInput = this.volumeNode.input.input;
|
|
162
154
|
const fadeGainNode = rawContext.createGain();
|
|
163
155
|
fadeGainNode.gain.value = clipInfo.gain;
|
|
164
|
-
fadeGainNode.connect(
|
|
156
|
+
fadeGainNode.connect(this.inputGain.input);
|
|
165
157
|
const absTransportTime = this.track.startTime + clipInfo.startTime;
|
|
166
158
|
const scheduleId = transport.schedule((audioContextTime) => {
|
|
167
159
|
if (absTransportTime < this._scheduleGuardOffset) return;
|
|
@@ -195,6 +187,15 @@ var ToneTrack = class {
|
|
|
195
187
|
}
|
|
196
188
|
this.scheduledClips.splice(index, 1);
|
|
197
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Select the pan law from the track's source material: 1 = mono law,
|
|
192
|
+
* 2+ = stereo law. Call when the track's clips change — a stereo clip
|
|
193
|
+
* joining a mono track moves it to the stereo law (same rule as the
|
|
194
|
+
* native transport and the offline export).
|
|
195
|
+
*/
|
|
196
|
+
setSourceChannelCount(sourceChannelCount) {
|
|
197
|
+
this.panStage.setSourceChannelCount(sourceChannelCount);
|
|
198
|
+
}
|
|
198
199
|
/**
|
|
199
200
|
* Replace clips on this track. Diffs old vs new by buffer + timing —
|
|
200
201
|
* unchanged clips keep their active sources playing (no audible interruption).
|
|
@@ -395,56 +396,71 @@ var ToneTrack = class {
|
|
|
395
396
|
}
|
|
396
397
|
setPan(pan) {
|
|
397
398
|
this.track.stereoPan = pan;
|
|
398
|
-
this.
|
|
399
|
+
this.panStage.setPan(pan);
|
|
399
400
|
}
|
|
400
401
|
setMute(muted) {
|
|
401
402
|
this.track.muted = muted;
|
|
402
403
|
const value = muted ? 0 : 1;
|
|
403
|
-
|
|
404
|
-
audioParam?.setValueAtTime(value, 0);
|
|
404
|
+
this.muteGain.input.gain.setValueAtTime(value, 0);
|
|
405
405
|
this.muteGain.gain.value = value;
|
|
406
406
|
}
|
|
407
407
|
setSolo(soloed) {
|
|
408
408
|
this.track.soloed = soloed;
|
|
409
409
|
}
|
|
410
|
+
/** Native node behind the Volume stage — where an external chain returns. */
|
|
411
|
+
get _faderNativeInput() {
|
|
412
|
+
return this.volumeNode.input.input;
|
|
413
|
+
}
|
|
410
414
|
/**
|
|
411
|
-
* Insert an external effects chain
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
+
* Insert an external effects chain PRE-FADER (#660):
|
|
416
|
+
* `inputGain → input … output → volume → pan → mute`. The track owns both
|
|
417
|
+
* edges; the caller only builds what lies between the two nodes (pass the
|
|
418
|
+
* same node twice for a single-node effect). Replaces any chain connected
|
|
419
|
+
* earlier. Mutually exclusive with the TrackEffectsFunction closure model.
|
|
415
420
|
*/
|
|
416
|
-
connectEffects(
|
|
421
|
+
connectEffects(input, output) {
|
|
417
422
|
if (this._hasClosureEffects) {
|
|
418
423
|
throw new Error(
|
|
419
424
|
'[waveform-playlist] Track "' + this.track.id + '" was built with a TrackEffectsFunction closure \u2014 transport effects hooks and closure effects are mutually exclusive.'
|
|
420
425
|
);
|
|
421
426
|
}
|
|
427
|
+
this._releaseEffectsChain();
|
|
422
428
|
try {
|
|
423
|
-
|
|
424
|
-
this.muteGain.disconnect(this._effectsChainNode);
|
|
425
|
-
} else {
|
|
426
|
-
this.muteGain.disconnect(this._destination);
|
|
427
|
-
}
|
|
429
|
+
this.inputGain.disconnect();
|
|
428
430
|
} catch (err) {
|
|
429
431
|
console.warn(
|
|
430
432
|
'[waveform-playlist] connectEffects disconnect on track "' + this.track.id + '": ' + String(err)
|
|
431
433
|
);
|
|
432
434
|
}
|
|
433
|
-
this.
|
|
434
|
-
this.
|
|
435
|
+
this.inputGain.connect(input);
|
|
436
|
+
output.connect(this._faderNativeInput);
|
|
437
|
+
this._effectsChain = { input, output };
|
|
435
438
|
}
|
|
436
|
-
/** Restore the direct
|
|
439
|
+
/** Restore the direct inputGain → volume connection. Safe when nothing is connected. */
|
|
437
440
|
disconnectEffects() {
|
|
438
|
-
if (!this.
|
|
441
|
+
if (!this._effectsChain) return;
|
|
442
|
+
this._releaseEffectsChain();
|
|
439
443
|
try {
|
|
440
|
-
this.
|
|
444
|
+
this.inputGain.disconnect();
|
|
441
445
|
} catch (err) {
|
|
442
446
|
console.warn(
|
|
443
447
|
"[waveform-playlist] disconnectEffects: " + (err instanceof Error ? err.message : String(err))
|
|
444
448
|
);
|
|
445
449
|
}
|
|
446
|
-
this.
|
|
447
|
-
|
|
450
|
+
this.inputGain.connect(this.volumeNode);
|
|
451
|
+
}
|
|
452
|
+
/** Targeted disconnect of the chain's return edge (output → volume); a
|
|
453
|
+
* consumer may have disposed its chain first, so failures only warn. */
|
|
454
|
+
_releaseEffectsChain() {
|
|
455
|
+
if (!this._effectsChain) return;
|
|
456
|
+
try {
|
|
457
|
+
this._effectsChain.output.disconnect(this._faderNativeInput);
|
|
458
|
+
} catch (err) {
|
|
459
|
+
console.warn(
|
|
460
|
+
'[waveform-playlist] effects chain was already disconnected from track "' + this.track.id + '": ' + String(err)
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
this._effectsChain = null;
|
|
448
464
|
}
|
|
449
465
|
dispose() {
|
|
450
466
|
const transport = getTransport();
|
|
@@ -474,6 +490,14 @@ var ToneTrack = class {
|
|
|
474
490
|
);
|
|
475
491
|
}
|
|
476
492
|
});
|
|
493
|
+
this._releaseEffectsChain();
|
|
494
|
+
try {
|
|
495
|
+
this.inputGain.dispose();
|
|
496
|
+
} catch (err) {
|
|
497
|
+
console.warn(
|
|
498
|
+
`[waveform-playlist] Error disposing inputGain on track "${this.id}": ` + String(err)
|
|
499
|
+
);
|
|
500
|
+
}
|
|
477
501
|
try {
|
|
478
502
|
this.volumeNode.dispose();
|
|
479
503
|
} catch (err) {
|
|
@@ -482,7 +506,7 @@ var ToneTrack = class {
|
|
|
482
506
|
);
|
|
483
507
|
}
|
|
484
508
|
try {
|
|
485
|
-
this.
|
|
509
|
+
this.panStage.dispose();
|
|
486
510
|
} catch (err) {
|
|
487
511
|
console.warn(
|
|
488
512
|
`[waveform-playlist] Error disposing panNode on track "${this.id}": ` + String(err)
|
|
@@ -522,17 +546,20 @@ var ToneTrack = class {
|
|
|
522
546
|
import {
|
|
523
547
|
Volume as Volume2,
|
|
524
548
|
Gain as Gain2,
|
|
525
|
-
Panner as Panner2,
|
|
526
549
|
PolySynth,
|
|
527
550
|
Synth,
|
|
528
551
|
MembraneSynth,
|
|
529
552
|
MetalSynth,
|
|
530
553
|
NoiseSynth,
|
|
531
554
|
Part,
|
|
555
|
+
connect as connect2,
|
|
532
556
|
getDestination as getDestination2,
|
|
533
557
|
getContext as getContext2
|
|
534
558
|
} from "tone";
|
|
535
|
-
import {
|
|
559
|
+
import {
|
|
560
|
+
gainToDb as gainToDb2,
|
|
561
|
+
createPanStage as createPanStage2
|
|
562
|
+
} from "@waveform-playlist/core";
|
|
536
563
|
function getDrumCategory(midiNote) {
|
|
537
564
|
if (midiNote === 35 || midiNote === 36) return "kick";
|
|
538
565
|
if (midiNote >= 37 && midiNote <= 40) return "snare";
|
|
@@ -543,12 +570,18 @@ function getDrumCategory(midiNote) {
|
|
|
543
570
|
var MidiToneTrack = class {
|
|
544
571
|
constructor(options) {
|
|
545
572
|
this.track = options.track;
|
|
573
|
+
this.inputGain = new Gain2({ gain: 1 });
|
|
546
574
|
this.volumeNode = new Volume2(gainToDb2(options.track.gain));
|
|
547
|
-
this.
|
|
575
|
+
this.panStage = createPanStage2(
|
|
576
|
+
getContext2().rawContext,
|
|
577
|
+
options.track.stereoPan,
|
|
578
|
+
1
|
|
579
|
+
);
|
|
548
580
|
this.muteGain = new Gain2(options.track.muted ? 0 : 1);
|
|
549
|
-
this.volumeNode.
|
|
581
|
+
this.volumeNode.connect(this.panStage.input);
|
|
582
|
+
connect2(this.panStage.output, this.muteGain);
|
|
550
583
|
this.synth = new PolySynth(Synth, options.synthOptions);
|
|
551
|
-
this.synth.connect(this.
|
|
584
|
+
this.synth.connect(this.inputGain);
|
|
552
585
|
this.kickSynth = new PolySynth(MembraneSynth, {
|
|
553
586
|
voice: MembraneSynth,
|
|
554
587
|
options: {
|
|
@@ -579,18 +612,19 @@ var MidiToneTrack = class {
|
|
|
579
612
|
envelope: { attack: 1e-3, decay: 0.3, sustain: 0, release: 0.1 }
|
|
580
613
|
}
|
|
581
614
|
});
|
|
582
|
-
this.kickSynth.connect(this.
|
|
583
|
-
this.snareSynth.connect(this.
|
|
584
|
-
this.cymbalSynth.connect(this.
|
|
585
|
-
this.tomSynth.connect(this.
|
|
615
|
+
this.kickSynth.connect(this.inputGain);
|
|
616
|
+
this.snareSynth.connect(this.inputGain);
|
|
617
|
+
this.cymbalSynth.connect(this.inputGain);
|
|
618
|
+
this.tomSynth.connect(this.inputGain);
|
|
586
619
|
const destination = options.destination || getDestination2();
|
|
620
|
+
this.muteGain.connect(destination);
|
|
587
621
|
if (options.effects) {
|
|
588
|
-
const cleanup = options.effects(this.
|
|
622
|
+
const cleanup = options.effects(this.inputGain, this.volumeNode, false);
|
|
589
623
|
if (cleanup) {
|
|
590
624
|
this.effectsCleanup = cleanup;
|
|
591
625
|
}
|
|
592
626
|
} else {
|
|
593
|
-
this.
|
|
627
|
+
this.inputGain.connect(this.volumeNode);
|
|
594
628
|
}
|
|
595
629
|
this.scheduledClips = options.clips.map((clipInfo) => {
|
|
596
630
|
const visibleNotes = clipInfo.notes.filter((note) => {
|
|
@@ -750,13 +784,12 @@ var MidiToneTrack = class {
|
|
|
750
784
|
}
|
|
751
785
|
setPan(pan) {
|
|
752
786
|
this.track.stereoPan = pan;
|
|
753
|
-
this.
|
|
787
|
+
this.panStage.setPan(pan);
|
|
754
788
|
}
|
|
755
789
|
setMute(muted) {
|
|
756
790
|
this.track.muted = muted;
|
|
757
791
|
const value = muted ? 0 : 1;
|
|
758
|
-
|
|
759
|
-
audioParam?.setValueAtTime(value, 0);
|
|
792
|
+
this.muteGain.input.gain.setValueAtTime(value, 0);
|
|
760
793
|
this.muteGain.gain.value = value;
|
|
761
794
|
}
|
|
762
795
|
setSolo(soloed) {
|
|
@@ -798,6 +831,13 @@ var MidiToneTrack = class {
|
|
|
798
831
|
);
|
|
799
832
|
}
|
|
800
833
|
}
|
|
834
|
+
try {
|
|
835
|
+
this.inputGain.dispose();
|
|
836
|
+
} catch (err) {
|
|
837
|
+
console.warn(
|
|
838
|
+
`[waveform-playlist] Error disposing inputGain on MIDI track "${this.id}": ` + String(err)
|
|
839
|
+
);
|
|
840
|
+
}
|
|
801
841
|
try {
|
|
802
842
|
this.volumeNode.dispose();
|
|
803
843
|
} catch (err) {
|
|
@@ -806,7 +846,7 @@ var MidiToneTrack = class {
|
|
|
806
846
|
);
|
|
807
847
|
}
|
|
808
848
|
try {
|
|
809
|
-
this.
|
|
849
|
+
this.panStage.dispose();
|
|
810
850
|
} catch (err) {
|
|
811
851
|
console.warn(
|
|
812
852
|
`[waveform-playlist] Error disposing panNode on MIDI track "${this.id}": ` + String(err)
|
|
@@ -840,8 +880,8 @@ var MidiToneTrack = class {
|
|
|
840
880
|
};
|
|
841
881
|
|
|
842
882
|
// src/SoundFontToneTrack.ts
|
|
843
|
-
import { Volume as Volume3, Gain as Gain3,
|
|
844
|
-
import { gainToDb as gainToDb3 } from "@waveform-playlist/core";
|
|
883
|
+
import { Volume as Volume3, Gain as Gain3, Part as Part2, connect as connect3, getDestination as getDestination3, getContext as getContext3 } from "tone";
|
|
884
|
+
import { gainToDb as gainToDb3, createPanStage as createPanStage3 } from "@waveform-playlist/core";
|
|
845
885
|
function envelopeValueAt(tRel, attack, hold, decay, peakGain, sustainGain) {
|
|
846
886
|
if (tRel <= 0) return 0;
|
|
847
887
|
if (tRel < attack) return peakGain * (tRel / attack);
|
|
@@ -866,18 +906,25 @@ var SoundFontToneTrack = class {
|
|
|
866
906
|
this.soundFontCache = options.soundFontCache;
|
|
867
907
|
this.programNumber = options.programNumber ?? 0;
|
|
868
908
|
this.bankNumber = options.isPercussion ? 128 : 0;
|
|
909
|
+
this.inputGain = new Gain3({ gain: 1 });
|
|
869
910
|
this.volumeNode = new Volume3(gainToDb3(options.track.gain));
|
|
870
|
-
this.
|
|
911
|
+
this.panStage = createPanStage3(
|
|
912
|
+
getContext3().rawContext,
|
|
913
|
+
options.track.stereoPan,
|
|
914
|
+
1
|
|
915
|
+
);
|
|
871
916
|
this.muteGain = new Gain3(options.track.muted ? 0 : 1);
|
|
872
|
-
this.volumeNode.
|
|
917
|
+
this.volumeNode.connect(this.panStage.input);
|
|
918
|
+
connect3(this.panStage.output, this.muteGain);
|
|
873
919
|
const destination = options.destination || getDestination3();
|
|
920
|
+
this.muteGain.connect(destination);
|
|
874
921
|
if (options.effects) {
|
|
875
|
-
const cleanup = options.effects(this.
|
|
922
|
+
const cleanup = options.effects(this.inputGain, this.volumeNode, false);
|
|
876
923
|
if (cleanup) {
|
|
877
924
|
this.effectsCleanup = cleanup;
|
|
878
925
|
}
|
|
879
926
|
} else {
|
|
880
|
-
this.
|
|
927
|
+
this.inputGain.connect(this.volumeNode);
|
|
881
928
|
}
|
|
882
929
|
this.scheduledClips = options.clips.map((clipInfo) => {
|
|
883
930
|
const visibleNotes = clipInfo.notes.filter((note) => {
|
|
@@ -978,7 +1025,7 @@ var SoundFontToneTrack = class {
|
|
|
978
1025
|
}
|
|
979
1026
|
gainNode.gain.linearRampToValueAtTime(0, noteOff + releaseVolEnv);
|
|
980
1027
|
source.connect(gainNode);
|
|
981
|
-
gainNode.connect(this.
|
|
1028
|
+
gainNode.connect(this.inputGain.input);
|
|
982
1029
|
this.activeSources.add(source);
|
|
983
1030
|
source.onended = () => {
|
|
984
1031
|
this.activeSources.delete(source);
|
|
@@ -1055,13 +1102,12 @@ var SoundFontToneTrack = class {
|
|
|
1055
1102
|
}
|
|
1056
1103
|
setPan(pan) {
|
|
1057
1104
|
this.track.stereoPan = pan;
|
|
1058
|
-
this.
|
|
1105
|
+
this.panStage.setPan(pan);
|
|
1059
1106
|
}
|
|
1060
1107
|
setMute(muted) {
|
|
1061
1108
|
this.track.muted = muted;
|
|
1062
1109
|
const value = muted ? 0 : 1;
|
|
1063
|
-
|
|
1064
|
-
audioParam?.setValueAtTime(value, 0);
|
|
1110
|
+
this.muteGain.input.gain.setValueAtTime(value, 0);
|
|
1065
1111
|
this.muteGain.gain.value = value;
|
|
1066
1112
|
}
|
|
1067
1113
|
setSolo(soloed) {
|
|
@@ -1087,6 +1133,13 @@ var SoundFontToneTrack = class {
|
|
|
1087
1133
|
);
|
|
1088
1134
|
}
|
|
1089
1135
|
});
|
|
1136
|
+
try {
|
|
1137
|
+
this.inputGain.dispose();
|
|
1138
|
+
} catch (err) {
|
|
1139
|
+
console.warn(
|
|
1140
|
+
`[waveform-playlist] Error disposing inputGain on SoundFont track "${this.id}": ` + String(err)
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1090
1143
|
try {
|
|
1091
1144
|
this.volumeNode.dispose();
|
|
1092
1145
|
} catch (err) {
|
|
@@ -1095,7 +1148,7 @@ var SoundFontToneTrack = class {
|
|
|
1095
1148
|
);
|
|
1096
1149
|
}
|
|
1097
1150
|
try {
|
|
1098
|
-
this.
|
|
1151
|
+
this.panStage.dispose();
|
|
1099
1152
|
} catch (err) {
|
|
1100
1153
|
console.warn(
|
|
1101
1154
|
`[waveform-playlist] Error disposing panNode on SoundFont track "${this.id}": ` + String(err)
|
|
@@ -1240,11 +1293,17 @@ var TonePlayout = class {
|
|
|
1240
1293
|
/**
|
|
1241
1294
|
* Replace clips on a track, preserving the track's audio graph.
|
|
1242
1295
|
* Only works for ToneTrack (audio clips), not MidiToneTrack.
|
|
1296
|
+
* `sourceChannelCount` (max channel count across the new clips) re-selects
|
|
1297
|
+
* the track's pan law; omit to leave it unchanged.
|
|
1243
1298
|
*/
|
|
1244
|
-
replaceTrackClips(trackId, newClips, newStartTime) {
|
|
1299
|
+
replaceTrackClips(trackId, newClips, newStartTime, sourceChannelCount) {
|
|
1245
1300
|
const track = this.tracks.get(trackId);
|
|
1246
1301
|
if (!track || !("replaceClips" in track)) return false;
|
|
1247
|
-
track
|
|
1302
|
+
const toneTrack = track;
|
|
1303
|
+
toneTrack.replaceClips(newClips, newStartTime);
|
|
1304
|
+
if (sourceChannelCount !== void 0) {
|
|
1305
|
+
toneTrack.setSourceChannelCount(sourceChannelCount);
|
|
1306
|
+
}
|
|
1248
1307
|
return true;
|
|
1249
1308
|
}
|
|
1250
1309
|
/**
|
|
@@ -1377,21 +1436,24 @@ var TonePlayout = class {
|
|
|
1377
1436
|
get masterBusInputNode() {
|
|
1378
1437
|
return this.masterVolume.input.input;
|
|
1379
1438
|
}
|
|
1380
|
-
/**
|
|
1381
|
-
|
|
1439
|
+
/**
|
|
1440
|
+
* Insert an external chain on a track, PRE-FADER (#660): clips → input …
|
|
1441
|
+
* output → volume → pan → mute. The track wires both edges.
|
|
1442
|
+
*/
|
|
1443
|
+
connectTrackEffects(trackId, input, output) {
|
|
1382
1444
|
const track = this.tracks.get(trackId);
|
|
1383
1445
|
if (!track) {
|
|
1384
|
-
throw new Error('[waveform-playlist]
|
|
1446
|
+
throw new Error('[waveform-playlist] connectTrackEffects: unknown track "' + trackId + '"');
|
|
1385
1447
|
}
|
|
1386
1448
|
if (!(track instanceof ToneTrack)) {
|
|
1387
1449
|
throw new Error(
|
|
1388
|
-
'[waveform-playlist]
|
|
1450
|
+
'[waveform-playlist] connectTrackEffects: per-track effects chains are not supported for MIDI tracks on the Tone adapter (track "' + trackId + '")'
|
|
1389
1451
|
);
|
|
1390
1452
|
}
|
|
1391
|
-
track.connectEffects(
|
|
1453
|
+
track.connectEffects(input, output);
|
|
1392
1454
|
}
|
|
1393
1455
|
/** Restore a track's direct connection. No-op for unknown or MIDI tracks. */
|
|
1394
|
-
|
|
1456
|
+
disconnectTrackEffects(trackId) {
|
|
1395
1457
|
const track = this.tracks.get(trackId);
|
|
1396
1458
|
if (track instanceof ToneTrack) {
|
|
1397
1459
|
track.disconnectEffects();
|
|
@@ -1760,7 +1822,11 @@ function configureGlobalContext(options) {
|
|
|
1760
1822
|
"[playout] nativeAudioContext requested but this browser does not implement the AudioListener AudioParams Tone.js needs on a native context (Firefox). Falling back to the standardized-audio-context default \u2014 WAM plugin hosting is unavailable."
|
|
1761
1823
|
);
|
|
1762
1824
|
}
|
|
1763
|
-
|
|
1825
|
+
const contextOptions = {
|
|
1826
|
+
...options.latencyHint !== void 0 ? { latencyHint: options.latencyHint } : {},
|
|
1827
|
+
...options.sampleRate !== void 0 ? { sampleRate: options.sampleRate } : {}
|
|
1828
|
+
};
|
|
1829
|
+
globalToneContext = Object.keys(contextOptions).length > 0 ? new Context(contextOptions) : new Context();
|
|
1764
1830
|
setContext(globalToneContext);
|
|
1765
1831
|
const actualRate = globalToneContext.rawContext.sampleRate;
|
|
1766
1832
|
if (options.sampleRate !== void 0 && options.sampleRate !== actualRate) {
|
|
@@ -1837,13 +1903,27 @@ function hasMediaStreamSource(stream) {
|
|
|
1837
1903
|
return streamSources.has(stream);
|
|
1838
1904
|
}
|
|
1839
1905
|
|
|
1906
|
+
// src/fades.ts
|
|
1907
|
+
var hasWarned = false;
|
|
1908
|
+
function getUnderlyingAudioParam(signal) {
|
|
1909
|
+
const param = signal?._param;
|
|
1910
|
+
if (!param && !hasWarned) {
|
|
1911
|
+
hasWarned = true;
|
|
1912
|
+
console.warn(
|
|
1913
|
+
"[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Mute scheduling may not work correctly."
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
return param;
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1840
1919
|
// src/TonePlayoutAdapter.ts
|
|
1841
1920
|
import {
|
|
1842
1921
|
clipStartTime,
|
|
1843
1922
|
clipEndTime,
|
|
1844
1923
|
clipOffsetTime,
|
|
1845
1924
|
clipDurationTime,
|
|
1846
|
-
trackChannelCount
|
|
1925
|
+
trackChannelCount,
|
|
1926
|
+
trackKind
|
|
1847
1927
|
} from "@waveform-playlist/core";
|
|
1848
1928
|
import { now as now2 } from "tone";
|
|
1849
1929
|
function isToneAdapter(adapter) {
|
|
@@ -1871,12 +1951,11 @@ function createToneAdapter(options) {
|
|
|
1871
1951
|
let _soundFontCache = options?.soundFontCache;
|
|
1872
1952
|
const _currentTracks = /* @__PURE__ */ new Map();
|
|
1873
1953
|
const _midiTrackBuild = /* @__PURE__ */ new Map();
|
|
1874
|
-
function
|
|
1875
|
-
|
|
1876
|
-
return hasAudio ? `${track.id}:midi` : track.id;
|
|
1954
|
+
function playableAudioClips(track) {
|
|
1955
|
+
return track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1877
1956
|
}
|
|
1878
1957
|
function addAudioTrackToPlayout(p, track) {
|
|
1879
|
-
const audioClips = track
|
|
1958
|
+
const audioClips = playableAudioClips(track);
|
|
1880
1959
|
if (audioClips.length === 0) return;
|
|
1881
1960
|
const startTime = Math.min(...audioClips.map(clipStartTime));
|
|
1882
1961
|
const endTime = Math.max(...audioClips.map(clipEndTime));
|
|
@@ -1902,7 +1981,7 @@ function createToneAdapter(options) {
|
|
|
1902
1981
|
p.addTrack({
|
|
1903
1982
|
clips: clipInfos,
|
|
1904
1983
|
track: trackObj,
|
|
1905
|
-
effects: track.
|
|
1984
|
+
effects: options?.trackEffects?.(track.id),
|
|
1906
1985
|
channelCount: trackChannelCount(track)
|
|
1907
1986
|
});
|
|
1908
1987
|
}
|
|
@@ -1911,7 +1990,7 @@ function createToneAdapter(options) {
|
|
|
1911
1990
|
if (midiClips.length === 0) return;
|
|
1912
1991
|
const startTime = Math.min(...midiClips.map(clipStartTime));
|
|
1913
1992
|
const endTime = Math.max(...midiClips.map(clipEndTime));
|
|
1914
|
-
const trackId =
|
|
1993
|
+
const trackId = track.id;
|
|
1915
1994
|
const trackObj = {
|
|
1916
1995
|
id: trackId,
|
|
1917
1996
|
name: track.name,
|
|
@@ -1922,6 +2001,7 @@ function createToneAdapter(options) {
|
|
|
1922
2001
|
startTime,
|
|
1923
2002
|
endTime
|
|
1924
2003
|
};
|
|
2004
|
+
const effects = options?.trackEffects?.(track.id);
|
|
1925
2005
|
const midiClipInfos = midiClips.map((clip) => ({
|
|
1926
2006
|
notes: clip.midiNotes,
|
|
1927
2007
|
startTime: clipStartTime(clip) - startTime,
|
|
@@ -1939,7 +2019,7 @@ function createToneAdapter(options) {
|
|
|
1939
2019
|
soundFontCache: _soundFontCache,
|
|
1940
2020
|
programNumber,
|
|
1941
2021
|
isPercussion,
|
|
1942
|
-
effects
|
|
2022
|
+
effects
|
|
1943
2023
|
});
|
|
1944
2024
|
_midiTrackBuild.set(trackId, _soundFontCache);
|
|
1945
2025
|
} else {
|
|
@@ -1951,14 +2031,17 @@ function createToneAdapter(options) {
|
|
|
1951
2031
|
p.addMidiTrack({
|
|
1952
2032
|
clips: midiClipInfos,
|
|
1953
2033
|
track: trackObj,
|
|
1954
|
-
effects
|
|
2034
|
+
effects
|
|
1955
2035
|
});
|
|
1956
2036
|
_midiTrackBuild.set(trackId, null);
|
|
1957
2037
|
}
|
|
1958
2038
|
}
|
|
1959
2039
|
function addTrackToPlayout(p, track) {
|
|
1960
|
-
|
|
1961
|
-
|
|
2040
|
+
if (trackKind(track) === "midi") {
|
|
2041
|
+
addMidiTrackToPlayout(p, track);
|
|
2042
|
+
} else {
|
|
2043
|
+
addAudioTrackToPlayout(p, track);
|
|
2044
|
+
}
|
|
1962
2045
|
}
|
|
1963
2046
|
function buildPlayout(tracks) {
|
|
1964
2047
|
if (playout) {
|
|
@@ -2006,8 +2089,8 @@ function createToneAdapter(options) {
|
|
|
2006
2089
|
return playout;
|
|
2007
2090
|
}
|
|
2008
2091
|
const effectsTransport = {
|
|
2009
|
-
|
|
2010
|
-
|
|
2092
|
+
connectTrackEffects: (trackId, input, output) => requireEffectsPlayout().connectTrackEffects(trackId, input, output),
|
|
2093
|
+
disconnectTrackEffects: (trackId) => requireEffectsPlayout().disconnectTrackEffects(trackId),
|
|
2011
2094
|
connectMasterOutput: (node) => requireEffectsPlayout().connectMasterOutput(node),
|
|
2012
2095
|
disconnectMasterOutput: () => requireEffectsPlayout().disconnectMasterOutput(),
|
|
2013
2096
|
get masterOutputNode() {
|
|
@@ -2046,7 +2129,6 @@ function createToneAdapter(options) {
|
|
|
2046
2129
|
for (const track of tracks) {
|
|
2047
2130
|
if (oldTrackIds.has(track.id)) {
|
|
2048
2131
|
playout.removeTrack(track.id);
|
|
2049
|
-
playout.removeTrack(track.id + ":midi");
|
|
2050
2132
|
}
|
|
2051
2133
|
addTrackToPlayout(playout, track);
|
|
2052
2134
|
}
|
|
@@ -2054,14 +2136,13 @@ function createToneAdapter(options) {
|
|
|
2054
2136
|
if (_isPlaying) {
|
|
2055
2137
|
for (const track of tracks) {
|
|
2056
2138
|
playout.resumeTrackMidPlayback(track.id);
|
|
2057
|
-
playout.resumeTrackMidPlayback(track.id + ":midi");
|
|
2058
2139
|
}
|
|
2059
2140
|
}
|
|
2060
2141
|
},
|
|
2061
2142
|
updateTrack(trackId, track) {
|
|
2062
2143
|
_currentTracks.set(trackId, track);
|
|
2063
2144
|
if (!playout) return;
|
|
2064
|
-
const audioClips = track
|
|
2145
|
+
const audioClips = trackKind(track) === "midi" ? [] : playableAudioClips(track);
|
|
2065
2146
|
if (audioClips.length > 0) {
|
|
2066
2147
|
const startTime = Math.min(...audioClips.map(clipStartTime));
|
|
2067
2148
|
const clipInfos = audioClips.map((clip) => ({
|
|
@@ -2073,33 +2154,23 @@ function createToneAdapter(options) {
|
|
|
2073
2154
|
fadeOut: clip.fadeOut,
|
|
2074
2155
|
gain: clip.gain
|
|
2075
2156
|
}));
|
|
2076
|
-
const audioUpdated = playout.replaceTrackClips(
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
if (_isPlaying) {
|
|
2083
|
-
playout.resumeTrackMidPlayback(midiTrackId);
|
|
2084
|
-
}
|
|
2085
|
-
} else {
|
|
2086
|
-
playout.removeTrack(midiTrackId);
|
|
2087
|
-
_midiTrackBuild.delete(midiTrackId);
|
|
2088
|
-
}
|
|
2157
|
+
const audioUpdated = playout.replaceTrackClips(
|
|
2158
|
+
trackId,
|
|
2159
|
+
clipInfos,
|
|
2160
|
+
startTime,
|
|
2161
|
+
trackChannelCount(track)
|
|
2162
|
+
);
|
|
2089
2163
|
if (audioUpdated) {
|
|
2090
2164
|
playout.applyInitialSoloState();
|
|
2091
2165
|
return;
|
|
2092
2166
|
}
|
|
2093
2167
|
}
|
|
2094
2168
|
playout.removeTrack(trackId);
|
|
2095
|
-
playout.removeTrack(trackId + ":midi");
|
|
2096
2169
|
_midiTrackBuild.delete(trackId);
|
|
2097
|
-
_midiTrackBuild.delete(trackId + ":midi");
|
|
2098
2170
|
addTrackToPlayout(playout, track);
|
|
2099
2171
|
playout.applyInitialSoloState();
|
|
2100
2172
|
if (_isPlaying) {
|
|
2101
2173
|
playout.resumeTrackMidPlayback(trackId);
|
|
2102
|
-
playout.resumeTrackMidPlayback(trackId + ":midi");
|
|
2103
2174
|
}
|
|
2104
2175
|
},
|
|
2105
2176
|
addTrack(track) {
|
|
@@ -2116,10 +2187,8 @@ function createToneAdapter(options) {
|
|
|
2116
2187
|
removeTrack(trackId) {
|
|
2117
2188
|
_currentTracks.delete(trackId);
|
|
2118
2189
|
_midiTrackBuild.delete(trackId);
|
|
2119
|
-
_midiTrackBuild.delete(trackId + ":midi");
|
|
2120
2190
|
if (!playout) return;
|
|
2121
2191
|
playout.removeTrack(trackId);
|
|
2122
|
-
playout.removeTrack(trackId + ":midi");
|
|
2123
2192
|
playout.applyInitialSoloState();
|
|
2124
2193
|
},
|
|
2125
2194
|
play(startTime, endTime) {
|
|
@@ -2156,34 +2225,25 @@ function createToneAdapter(options) {
|
|
|
2156
2225
|
setMasterVolume(volume) {
|
|
2157
2226
|
playout?.setMasterGain(volume);
|
|
2158
2227
|
},
|
|
2159
|
-
// Runtime controls must reach BOTH playout halves of a mixed audio+MIDI
|
|
2160
|
-
// track (trackId + trackId:midi) — otherwise muting a mixed track leaves
|
|
2161
|
-
// its MIDI playing and soloing it silences its own MIDI half. The :midi
|
|
2162
|
-
// calls no-op for audio-only and MIDI-only tracks (unknown playout id),
|
|
2163
|
-
// same blind-forwarding pattern as removeTrack.
|
|
2164
2228
|
setTrackVolume(trackId, volume) {
|
|
2165
2229
|
const existing = _currentTracks.get(trackId);
|
|
2166
2230
|
if (existing) _currentTracks.set(trackId, { ...existing, volume });
|
|
2167
2231
|
playout?.getTrack(trackId)?.setVolume(volume);
|
|
2168
|
-
playout?.getTrack(trackId + ":midi")?.setVolume(volume);
|
|
2169
2232
|
},
|
|
2170
2233
|
setTrackMute(trackId, muted) {
|
|
2171
2234
|
const existing = _currentTracks.get(trackId);
|
|
2172
2235
|
if (existing) _currentTracks.set(trackId, { ...existing, muted });
|
|
2173
2236
|
playout?.setMute(trackId, muted);
|
|
2174
|
-
playout?.setMute(trackId + ":midi", muted);
|
|
2175
2237
|
},
|
|
2176
2238
|
setTrackSolo(trackId, soloed) {
|
|
2177
2239
|
const existing = _currentTracks.get(trackId);
|
|
2178
2240
|
if (existing) _currentTracks.set(trackId, { ...existing, soloed });
|
|
2179
2241
|
playout?.setSolo(trackId, soloed);
|
|
2180
|
-
playout?.setSolo(trackId + ":midi", soloed);
|
|
2181
2242
|
},
|
|
2182
2243
|
setTrackPan(trackId, pan) {
|
|
2183
2244
|
const existing = _currentTracks.get(trackId);
|
|
2184
2245
|
if (existing) _currentTracks.set(trackId, { ...existing, pan });
|
|
2185
2246
|
playout?.getTrack(trackId)?.setPan(pan);
|
|
2186
|
-
playout?.getTrack(trackId + ":midi")?.setPan(pan);
|
|
2187
2247
|
},
|
|
2188
2248
|
setLoop(enabled, start2, end) {
|
|
2189
2249
|
_loopEnabled = enabled;
|
|
@@ -2261,9 +2321,10 @@ function createToneAdapter(options) {
|
|
|
2261
2321
|
const effective = cache?.isLoaded ? cache : null;
|
|
2262
2322
|
let changed = false;
|
|
2263
2323
|
for (const track of _currentTracks.values()) {
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2324
|
+
if (trackKind(track) !== "midi") continue;
|
|
2325
|
+
const hasNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
2326
|
+
if (!hasNotes) continue;
|
|
2327
|
+
const midiTrackId = track.id;
|
|
2267
2328
|
if (_midiTrackBuild.get(midiTrackId) === effective) continue;
|
|
2268
2329
|
try {
|
|
2269
2330
|
playout.removeTrack(midiTrackId);
|