@waveform-playlist/playout 12.5.1 → 12.5.3
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 +14 -16
- package/dist/index.d.ts +14 -16
- package/dist/index.js +243 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +214 -120
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -50,17 +50,16 @@ module.exports = __toCommonJS(index_exports);
|
|
|
50
50
|
|
|
51
51
|
// src/TonePlayout.ts
|
|
52
52
|
var import_tone4 = require("tone");
|
|
53
|
-
var
|
|
53
|
+
var import_core4 = require("@waveform-playlist/core");
|
|
54
54
|
|
|
55
55
|
// src/ToneTrack.ts
|
|
56
56
|
var import_tone = require("tone");
|
|
57
|
-
var
|
|
57
|
+
var import_core = require("@waveform-playlist/core");
|
|
58
58
|
|
|
59
59
|
// src/fades.ts
|
|
60
|
-
var import_core = require("@waveform-playlist/core");
|
|
61
60
|
var hasWarned = false;
|
|
62
61
|
function getUnderlyingAudioParam(signal) {
|
|
63
|
-
const param = signal
|
|
62
|
+
const param = signal?._param;
|
|
64
63
|
if (!param && !hasWarned) {
|
|
65
64
|
hasWarned = true;
|
|
66
65
|
console.warn(
|
|
@@ -83,7 +82,7 @@ var ToneTrack = class {
|
|
|
83
82
|
// clips at/after this offset.
|
|
84
83
|
this._scheduleGuardOffset = 0;
|
|
85
84
|
this.track = options.track;
|
|
86
|
-
this.volumeNode = new import_tone.Volume((0,
|
|
85
|
+
this.volumeNode = new import_tone.Volume((0, import_core.gainToDb)(options.track.gain));
|
|
87
86
|
this.panNode = new import_tone.Panner({
|
|
88
87
|
pan: options.track.stereoPan,
|
|
89
88
|
channelCount: options.channelCount ?? 1
|
|
@@ -143,8 +142,7 @@ var ToneTrack = class {
|
|
|
143
142
|
source.start(audioContextTime, offset, duration);
|
|
144
143
|
} catch (err) {
|
|
145
144
|
console.warn(
|
|
146
|
-
`[waveform-playlist] Failed to start source on track "${this.id}" (time=${audioContextTime}, offset=${offset}, duration=${duration})
|
|
147
|
-
err
|
|
145
|
+
`[waveform-playlist] Failed to start source on track "${this.id}" (time=${audioContextTime}, offset=${offset}, duration=${duration}): ` + String(err)
|
|
148
146
|
);
|
|
149
147
|
source.disconnect();
|
|
150
148
|
return;
|
|
@@ -303,6 +301,10 @@ var ToneTrack = class {
|
|
|
303
301
|
clipInfo.offset + Math.max(0, elapsed),
|
|
304
302
|
clipInfo.duration - Math.max(0, elapsed)
|
|
305
303
|
);
|
|
304
|
+
this.scheduleFades(scheduled, audioContextTime, clipInfo.offset + Math.max(0, elapsed));
|
|
305
|
+
} else if (absClipStart >= transportOffset) {
|
|
306
|
+
const delay = absClipStart - transportOffset;
|
|
307
|
+
this.scheduleFades(scheduled, audioContextTime + delay, clipInfo.offset);
|
|
306
308
|
}
|
|
307
309
|
}
|
|
308
310
|
}
|
|
@@ -321,7 +323,9 @@ var ToneTrack = class {
|
|
|
321
323
|
try {
|
|
322
324
|
source.stop();
|
|
323
325
|
} catch (err) {
|
|
324
|
-
console.warn(
|
|
326
|
+
console.warn(
|
|
327
|
+
`[waveform-playlist] Error stopping source on track "${this.id}": ` + String(err)
|
|
328
|
+
);
|
|
325
329
|
}
|
|
326
330
|
});
|
|
327
331
|
this.activeSources.clear();
|
|
@@ -422,7 +426,7 @@ var ToneTrack = class {
|
|
|
422
426
|
}
|
|
423
427
|
setVolume(gain) {
|
|
424
428
|
this.track.gain = gain;
|
|
425
|
-
this.volumeNode.volume.value = (0,
|
|
429
|
+
this.volumeNode.volume.value = (0, import_core.gainToDb)(gain);
|
|
426
430
|
}
|
|
427
431
|
setPan(pan) {
|
|
428
432
|
this.track.stereoPan = pan;
|
|
@@ -450,10 +454,16 @@ var ToneTrack = class {
|
|
|
450
454
|
'[waveform-playlist] Track "' + this.track.id + '" was built with a TrackEffectsFunction closure \u2014 transport effects hooks and closure effects are mutually exclusive.'
|
|
451
455
|
);
|
|
452
456
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
+
try {
|
|
458
|
+
if (this._effectsChainNode) {
|
|
459
|
+
this.muteGain.disconnect(this._effectsChainNode);
|
|
460
|
+
} else {
|
|
461
|
+
this.muteGain.disconnect(this._destination);
|
|
462
|
+
}
|
|
463
|
+
} catch (err) {
|
|
464
|
+
console.warn(
|
|
465
|
+
'[waveform-playlist] connectEffects disconnect on track "' + this.track.id + '": ' + String(err)
|
|
466
|
+
);
|
|
457
467
|
}
|
|
458
468
|
this.muteGain.connect(node);
|
|
459
469
|
this._effectsChainNode = node;
|
|
@@ -477,7 +487,9 @@ var ToneTrack = class {
|
|
|
477
487
|
try {
|
|
478
488
|
this.effectsCleanup();
|
|
479
489
|
} catch (err) {
|
|
480
|
-
console.warn(
|
|
490
|
+
console.warn(
|
|
491
|
+
`[waveform-playlist] Error during track "${this.id}" effects cleanup: ` + String(err)
|
|
492
|
+
);
|
|
481
493
|
}
|
|
482
494
|
}
|
|
483
495
|
this.stopAllSources();
|
|
@@ -486,42 +498,49 @@ var ToneTrack = class {
|
|
|
486
498
|
transport.clear(scheduled.scheduleId);
|
|
487
499
|
} catch (err) {
|
|
488
500
|
console.warn(
|
|
489
|
-
`[waveform-playlist] Error clearing schedule ${index} on track "${this.id}"
|
|
490
|
-
err
|
|
501
|
+
`[waveform-playlist] Error clearing schedule ${index} on track "${this.id}": ` + String(err)
|
|
491
502
|
);
|
|
492
503
|
}
|
|
493
504
|
try {
|
|
494
505
|
scheduled.fadeGainNode.disconnect();
|
|
495
506
|
} catch (err) {
|
|
496
507
|
console.warn(
|
|
497
|
-
`[waveform-playlist] Error disconnecting fadeGain ${index} on track "${this.id}"
|
|
498
|
-
err
|
|
508
|
+
`[waveform-playlist] Error disconnecting fadeGain ${index} on track "${this.id}": ` + String(err)
|
|
499
509
|
);
|
|
500
510
|
}
|
|
501
511
|
});
|
|
502
512
|
try {
|
|
503
513
|
this.volumeNode.dispose();
|
|
504
514
|
} catch (err) {
|
|
505
|
-
console.warn(
|
|
515
|
+
console.warn(
|
|
516
|
+
`[waveform-playlist] Error disposing volumeNode on track "${this.id}": ` + String(err)
|
|
517
|
+
);
|
|
506
518
|
}
|
|
507
519
|
try {
|
|
508
520
|
this.panNode.dispose();
|
|
509
521
|
} catch (err) {
|
|
510
|
-
console.warn(
|
|
522
|
+
console.warn(
|
|
523
|
+
`[waveform-playlist] Error disposing panNode on track "${this.id}": ` + String(err)
|
|
524
|
+
);
|
|
511
525
|
}
|
|
512
526
|
try {
|
|
513
527
|
this.muteGain.dispose();
|
|
514
528
|
} catch (err) {
|
|
515
|
-
console.warn(
|
|
529
|
+
console.warn(
|
|
530
|
+
`[waveform-playlist] Error disposing muteGain on track "${this.id}": ` + String(err)
|
|
531
|
+
);
|
|
516
532
|
}
|
|
517
533
|
}
|
|
518
534
|
get id() {
|
|
519
535
|
return this.track.id;
|
|
520
536
|
}
|
|
521
537
|
get duration() {
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
|
|
538
|
+
let max = 0;
|
|
539
|
+
for (const { clipInfo } of this.scheduledClips) {
|
|
540
|
+
const end = clipInfo.startTime + clipInfo.duration;
|
|
541
|
+
if (end > max) max = end;
|
|
542
|
+
}
|
|
543
|
+
return max;
|
|
525
544
|
}
|
|
526
545
|
get buffer() {
|
|
527
546
|
return this.scheduledClips[0]?.clipInfo.buffer;
|
|
@@ -536,7 +555,7 @@ var ToneTrack = class {
|
|
|
536
555
|
|
|
537
556
|
// src/MidiToneTrack.ts
|
|
538
557
|
var import_tone2 = require("tone");
|
|
539
|
-
var
|
|
558
|
+
var import_core2 = require("@waveform-playlist/core");
|
|
540
559
|
function getDrumCategory(midiNote) {
|
|
541
560
|
if (midiNote === 35 || midiNote === 36) return "kick";
|
|
542
561
|
if (midiNote >= 37 && midiNote <= 40) return "snare";
|
|
@@ -547,7 +566,7 @@ function getDrumCategory(midiNote) {
|
|
|
547
566
|
var MidiToneTrack = class {
|
|
548
567
|
constructor(options) {
|
|
549
568
|
this.track = options.track;
|
|
550
|
-
this.volumeNode = new import_tone2.Volume((0,
|
|
569
|
+
this.volumeNode = new import_tone2.Volume((0, import_core2.gainToDb)(options.track.gain));
|
|
551
570
|
this.panNode = new import_tone2.Panner(options.track.stereoPan);
|
|
552
571
|
this.muteGain = new import_tone2.Gain(options.track.muted ? 0 : 1);
|
|
553
572
|
this.volumeNode.chain(this.panNode, this.muteGain);
|
|
@@ -650,8 +669,7 @@ var MidiToneTrack = class {
|
|
|
650
669
|
this.snareSynth.triggerAttackRelease(duration, time, velocity);
|
|
651
670
|
} catch (err) {
|
|
652
671
|
console.warn(
|
|
653
|
-
"[waveform-playlist] Snare overlap \u2014 previous hit still decaying, skipped:"
|
|
654
|
-
err
|
|
672
|
+
"[waveform-playlist] Snare overlap \u2014 previous hit still decaying, skipped: " + String(err)
|
|
655
673
|
);
|
|
656
674
|
}
|
|
657
675
|
break;
|
|
@@ -712,8 +730,7 @@ var MidiToneTrack = class {
|
|
|
712
730
|
);
|
|
713
731
|
} catch (err) {
|
|
714
732
|
console.warn(
|
|
715
|
-
`[waveform-playlist] Failed to start mid-clip MIDI note "${note.name}" on track "${this.id}"
|
|
716
|
-
err
|
|
733
|
+
`[waveform-playlist] Failed to start mid-clip MIDI note "${note.name}" on track "${this.id}": ` + String(err)
|
|
717
734
|
);
|
|
718
735
|
}
|
|
719
736
|
}
|
|
@@ -726,14 +743,19 @@ var MidiToneTrack = class {
|
|
|
726
743
|
*/
|
|
727
744
|
stopAllSources() {
|
|
728
745
|
const now3 = (0, import_tone2.getContext)().rawContext.currentTime;
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
746
|
+
const release = (label, fn) => {
|
|
747
|
+
try {
|
|
748
|
+
fn();
|
|
749
|
+
} catch (err) {
|
|
750
|
+
console.warn(
|
|
751
|
+
`[waveform-playlist] Error releasing ${label} synth on track "${this.id}": ` + String(err)
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
release("melodic", () => this.synth.releaseAll(now3));
|
|
756
|
+
release("kick", () => this.kickSynth.releaseAll(now3));
|
|
757
|
+
release("cymbal", () => this.cymbalSynth.releaseAll(now3));
|
|
758
|
+
release("tom", () => this.tomSynth.releaseAll(now3));
|
|
737
759
|
}
|
|
738
760
|
/**
|
|
739
761
|
* No-op for MIDI — MIDI uses note velocity, not gain fades.
|
|
@@ -747,7 +769,7 @@ var MidiToneTrack = class {
|
|
|
747
769
|
}
|
|
748
770
|
setVolume(gain) {
|
|
749
771
|
this.track.gain = gain;
|
|
750
|
-
this.volumeNode.volume.value = (0,
|
|
772
|
+
this.volumeNode.volume.value = (0, import_core2.gainToDb)(gain);
|
|
751
773
|
}
|
|
752
774
|
setPan(pan) {
|
|
753
775
|
this.track.stereoPan = pan;
|
|
@@ -769,8 +791,7 @@ var MidiToneTrack = class {
|
|
|
769
791
|
this.effectsCleanup();
|
|
770
792
|
} catch (err) {
|
|
771
793
|
console.warn(
|
|
772
|
-
`[waveform-playlist] Error during MIDI track "${this.id}" effects cleanup
|
|
773
|
-
err
|
|
794
|
+
`[waveform-playlist] Error during MIDI track "${this.id}" effects cleanup: ` + String(err)
|
|
774
795
|
);
|
|
775
796
|
}
|
|
776
797
|
}
|
|
@@ -780,8 +801,7 @@ var MidiToneTrack = class {
|
|
|
780
801
|
part.dispose();
|
|
781
802
|
} catch (err) {
|
|
782
803
|
console.warn(
|
|
783
|
-
`[waveform-playlist] Error disposing Part ${index} on MIDI track "${this.id}"
|
|
784
|
-
err
|
|
804
|
+
`[waveform-playlist] Error disposing Part ${index} on MIDI track "${this.id}": ` + String(err)
|
|
785
805
|
);
|
|
786
806
|
}
|
|
787
807
|
});
|
|
@@ -796,35 +816,43 @@ var MidiToneTrack = class {
|
|
|
796
816
|
try {
|
|
797
817
|
s?.dispose();
|
|
798
818
|
} catch (err) {
|
|
799
|
-
console.warn(
|
|
819
|
+
console.warn(
|
|
820
|
+
`[waveform-playlist] Error disposing synth on MIDI track "${this.id}": ` + String(err)
|
|
821
|
+
);
|
|
800
822
|
}
|
|
801
823
|
}
|
|
802
824
|
try {
|
|
803
825
|
this.volumeNode.dispose();
|
|
804
826
|
} catch (err) {
|
|
805
827
|
console.warn(
|
|
806
|
-
`[waveform-playlist] Error disposing volumeNode on MIDI track "${this.id}"
|
|
807
|
-
err
|
|
828
|
+
`[waveform-playlist] Error disposing volumeNode on MIDI track "${this.id}": ` + String(err)
|
|
808
829
|
);
|
|
809
830
|
}
|
|
810
831
|
try {
|
|
811
832
|
this.panNode.dispose();
|
|
812
833
|
} catch (err) {
|
|
813
|
-
console.warn(
|
|
834
|
+
console.warn(
|
|
835
|
+
`[waveform-playlist] Error disposing panNode on MIDI track "${this.id}": ` + String(err)
|
|
836
|
+
);
|
|
814
837
|
}
|
|
815
838
|
try {
|
|
816
839
|
this.muteGain.dispose();
|
|
817
840
|
} catch (err) {
|
|
818
|
-
console.warn(
|
|
841
|
+
console.warn(
|
|
842
|
+
`[waveform-playlist] Error disposing muteGain on MIDI track "${this.id}": ` + String(err)
|
|
843
|
+
);
|
|
819
844
|
}
|
|
820
845
|
}
|
|
821
846
|
get id() {
|
|
822
847
|
return this.track.id;
|
|
823
848
|
}
|
|
824
849
|
get duration() {
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
|
|
850
|
+
let max = 0;
|
|
851
|
+
for (const { clipInfo } of this.scheduledClips) {
|
|
852
|
+
const end = clipInfo.startTime + clipInfo.duration;
|
|
853
|
+
if (end > max) max = end;
|
|
854
|
+
}
|
|
855
|
+
return max;
|
|
828
856
|
}
|
|
829
857
|
get muted() {
|
|
830
858
|
return this.track.muted;
|
|
@@ -836,15 +864,32 @@ var MidiToneTrack = class {
|
|
|
836
864
|
|
|
837
865
|
// src/SoundFontToneTrack.ts
|
|
838
866
|
var import_tone3 = require("tone");
|
|
839
|
-
var
|
|
840
|
-
|
|
867
|
+
var import_core3 = require("@waveform-playlist/core");
|
|
868
|
+
function envelopeValueAt(tRel, attack, hold, decay, peakGain, sustainGain) {
|
|
869
|
+
if (tRel <= 0) return 0;
|
|
870
|
+
if (tRel < attack) return peakGain * (tRel / attack);
|
|
871
|
+
const rampStart = hold > 1e-3 ? attack + hold : attack;
|
|
872
|
+
const rampEnd = attack + hold + decay;
|
|
873
|
+
if (tRel <= rampStart || rampEnd <= rampStart) {
|
|
874
|
+
return tRel >= rampEnd ? sustainGain : peakGain;
|
|
875
|
+
}
|
|
876
|
+
if (tRel < rampEnd) {
|
|
877
|
+
return peakGain + (sustainGain - peakGain) * ((tRel - rampStart) / (rampEnd - rampStart));
|
|
878
|
+
}
|
|
879
|
+
return sustainGain;
|
|
880
|
+
}
|
|
881
|
+
var SoundFontToneTrack = class {
|
|
841
882
|
constructor(options) {
|
|
883
|
+
/** Rate-limit missing sample warnings — one per track instance (a page-
|
|
884
|
+
* lifetime static would silence diagnostics for unrelated later tracks
|
|
885
|
+
* and soundfont swaps). */
|
|
886
|
+
this._missingSampleWarned = false;
|
|
842
887
|
this.activeSources = /* @__PURE__ */ new Set();
|
|
843
888
|
this.track = options.track;
|
|
844
889
|
this.soundFontCache = options.soundFontCache;
|
|
845
890
|
this.programNumber = options.programNumber ?? 0;
|
|
846
891
|
this.bankNumber = options.isPercussion ? 128 : 0;
|
|
847
|
-
this.volumeNode = new import_tone3.Volume((0,
|
|
892
|
+
this.volumeNode = new import_tone3.Volume((0, import_core3.gainToDb)(options.track.gain));
|
|
848
893
|
this.panNode = new import_tone3.Panner(options.track.stereoPan);
|
|
849
894
|
this.muteGain = new import_tone3.Gain(options.track.muted ? 0 : 1);
|
|
850
895
|
this.volumeNode.chain(this.panNode, this.muteGain);
|
|
@@ -881,7 +926,13 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
881
926
|
});
|
|
882
927
|
const part = new import_tone3.Part((time, event) => {
|
|
883
928
|
if (event.duration > 0) {
|
|
884
|
-
|
|
929
|
+
try {
|
|
930
|
+
this.triggerNote(event.midi, event.duration, time, event.velocity, event.channel);
|
|
931
|
+
} catch (err) {
|
|
932
|
+
console.warn(
|
|
933
|
+
`[waveform-playlist] Failed to trigger SoundFont note on track "${this.id}": ` + String(err)
|
|
934
|
+
);
|
|
935
|
+
}
|
|
885
936
|
}
|
|
886
937
|
}, partEvents);
|
|
887
938
|
part.start(0);
|
|
@@ -898,11 +949,11 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
898
949
|
const preset = channel === 9 ? 0 : this.programNumber;
|
|
899
950
|
const sfSample = this.soundFontCache.getAudioBuffer(midiNote, bank, preset);
|
|
900
951
|
if (!sfSample) {
|
|
901
|
-
if (!
|
|
952
|
+
if (!this._missingSampleWarned) {
|
|
902
953
|
console.warn(
|
|
903
|
-
`[waveform-playlist] SoundFont sample not found for MIDI note ${midiNote} (bank ${bank}, preset ${preset}). Subsequent missing samples will be silent.`
|
|
954
|
+
`[waveform-playlist] SoundFont sample not found for MIDI note ${midiNote} (bank ${bank}, preset ${preset}) on track "${this.id}". Subsequent missing samples on this track will be silent.`
|
|
904
955
|
);
|
|
905
|
-
|
|
956
|
+
this._missingSampleWarned = true;
|
|
906
957
|
}
|
|
907
958
|
return;
|
|
908
959
|
}
|
|
@@ -921,15 +972,34 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
921
972
|
const gainNode = rawContext.createGain();
|
|
922
973
|
const { attackVolEnv, holdVolEnv, decayVolEnv, sustainVolEnv, releaseVolEnv } = sfSample;
|
|
923
974
|
const sustainGain = peakGain * sustainVolEnv;
|
|
975
|
+
const noteOff = time + effectiveDuration;
|
|
976
|
+
const attackEnd = time + attackVolEnv;
|
|
977
|
+
const decayStart = time + attackVolEnv + holdVolEnv;
|
|
978
|
+
const decayEnd = decayStart + decayVolEnv;
|
|
979
|
+
const heldAtNoteOff = envelopeValueAt(
|
|
980
|
+
effectiveDuration,
|
|
981
|
+
attackVolEnv,
|
|
982
|
+
holdVolEnv,
|
|
983
|
+
decayVolEnv,
|
|
984
|
+
peakGain,
|
|
985
|
+
sustainGain
|
|
986
|
+
);
|
|
924
987
|
gainNode.gain.setValueAtTime(0, time);
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
988
|
+
if (noteOff < attackEnd) {
|
|
989
|
+
gainNode.gain.linearRampToValueAtTime(heldAtNoteOff, noteOff);
|
|
990
|
+
} else {
|
|
991
|
+
gainNode.gain.linearRampToValueAtTime(peakGain, attackEnd);
|
|
992
|
+
if (holdVolEnv > 1e-3 && decayStart < noteOff) {
|
|
993
|
+
gainNode.gain.setValueAtTime(peakGain, decayStart);
|
|
994
|
+
}
|
|
995
|
+
if (noteOff < decayEnd) {
|
|
996
|
+
gainNode.gain.linearRampToValueAtTime(heldAtNoteOff, noteOff);
|
|
997
|
+
} else {
|
|
998
|
+
gainNode.gain.linearRampToValueAtTime(sustainGain, decayEnd);
|
|
999
|
+
gainNode.gain.setValueAtTime(sustainGain, noteOff);
|
|
1000
|
+
}
|
|
928
1001
|
}
|
|
929
|
-
|
|
930
|
-
gainNode.gain.linearRampToValueAtTime(sustainGain, decayStart + decayVolEnv);
|
|
931
|
-
gainNode.gain.setValueAtTime(sustainGain, time + effectiveDuration);
|
|
932
|
-
gainNode.gain.linearRampToValueAtTime(0, time + effectiveDuration + releaseVolEnv);
|
|
1002
|
+
gainNode.gain.linearRampToValueAtTime(0, noteOff + releaseVolEnv);
|
|
933
1003
|
source.connect(gainNode);
|
|
934
1004
|
gainNode.connect(this.volumeNode.input.input);
|
|
935
1005
|
this.activeSources.add(source);
|
|
@@ -938,7 +1008,7 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
938
1008
|
try {
|
|
939
1009
|
gainNode.disconnect();
|
|
940
1010
|
} catch (err) {
|
|
941
|
-
console.warn("[waveform-playlist] GainNode already disconnected:"
|
|
1011
|
+
console.warn("[waveform-playlist] GainNode already disconnected: " + String(err));
|
|
942
1012
|
}
|
|
943
1013
|
};
|
|
944
1014
|
source.start(time);
|
|
@@ -973,8 +1043,7 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
973
1043
|
);
|
|
974
1044
|
} catch (err) {
|
|
975
1045
|
console.warn(
|
|
976
|
-
`[waveform-playlist] Failed to start mid-clip SoundFont note on track "${this.id}"
|
|
977
|
-
err
|
|
1046
|
+
`[waveform-playlist] Failed to start mid-clip SoundFont note on track "${this.id}": ` + String(err)
|
|
978
1047
|
);
|
|
979
1048
|
}
|
|
980
1049
|
}
|
|
@@ -990,7 +1059,9 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
990
1059
|
try {
|
|
991
1060
|
source.stop();
|
|
992
1061
|
} catch (err) {
|
|
993
|
-
console.warn(
|
|
1062
|
+
console.warn(
|
|
1063
|
+
"[waveform-playlist] Error stopping AudioBufferSourceNode: " + String(err)
|
|
1064
|
+
);
|
|
994
1065
|
}
|
|
995
1066
|
}
|
|
996
1067
|
this.activeSources.clear();
|
|
@@ -1003,7 +1074,7 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
1003
1074
|
}
|
|
1004
1075
|
setVolume(gain) {
|
|
1005
1076
|
this.track.gain = gain;
|
|
1006
|
-
this.volumeNode.volume.value = (0,
|
|
1077
|
+
this.volumeNode.volume.value = (0, import_core3.gainToDb)(gain);
|
|
1007
1078
|
}
|
|
1008
1079
|
setPan(pan) {
|
|
1009
1080
|
this.track.stereoPan = pan;
|
|
@@ -1025,8 +1096,7 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
1025
1096
|
this.effectsCleanup();
|
|
1026
1097
|
} catch (err) {
|
|
1027
1098
|
console.warn(
|
|
1028
|
-
`[waveform-playlist] Error during SoundFont track "${this.id}" effects cleanup
|
|
1029
|
-
err
|
|
1099
|
+
`[waveform-playlist] Error during SoundFont track "${this.id}" effects cleanup: ` + String(err)
|
|
1030
1100
|
);
|
|
1031
1101
|
}
|
|
1032
1102
|
}
|
|
@@ -1036,8 +1106,7 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
1036
1106
|
part.dispose();
|
|
1037
1107
|
} catch (err) {
|
|
1038
1108
|
console.warn(
|
|
1039
|
-
`[waveform-playlist] Error disposing Part ${index} on SoundFont track "${this.id}"
|
|
1040
|
-
err
|
|
1109
|
+
`[waveform-playlist] Error disposing Part ${index} on SoundFont track "${this.id}": ` + String(err)
|
|
1041
1110
|
);
|
|
1042
1111
|
}
|
|
1043
1112
|
});
|
|
@@ -1045,24 +1114,21 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
1045
1114
|
this.volumeNode.dispose();
|
|
1046
1115
|
} catch (err) {
|
|
1047
1116
|
console.warn(
|
|
1048
|
-
`[waveform-playlist] Error disposing volumeNode on SoundFont track "${this.id}"
|
|
1049
|
-
err
|
|
1117
|
+
`[waveform-playlist] Error disposing volumeNode on SoundFont track "${this.id}": ` + String(err)
|
|
1050
1118
|
);
|
|
1051
1119
|
}
|
|
1052
1120
|
try {
|
|
1053
1121
|
this.panNode.dispose();
|
|
1054
1122
|
} catch (err) {
|
|
1055
1123
|
console.warn(
|
|
1056
|
-
`[waveform-playlist] Error disposing panNode on SoundFont track "${this.id}"
|
|
1057
|
-
err
|
|
1124
|
+
`[waveform-playlist] Error disposing panNode on SoundFont track "${this.id}": ` + String(err)
|
|
1058
1125
|
);
|
|
1059
1126
|
}
|
|
1060
1127
|
try {
|
|
1061
1128
|
this.muteGain.dispose();
|
|
1062
1129
|
} catch (err) {
|
|
1063
1130
|
console.warn(
|
|
1064
|
-
`[waveform-playlist] Error disposing muteGain on SoundFont track "${this.id}"
|
|
1065
|
-
err
|
|
1131
|
+
`[waveform-playlist] Error disposing muteGain on SoundFont track "${this.id}": ` + String(err)
|
|
1066
1132
|
);
|
|
1067
1133
|
}
|
|
1068
1134
|
}
|
|
@@ -1070,9 +1136,12 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
1070
1136
|
return this.track.id;
|
|
1071
1137
|
}
|
|
1072
1138
|
get duration() {
|
|
1073
|
-
|
|
1074
|
-
const
|
|
1075
|
-
|
|
1139
|
+
let max = 0;
|
|
1140
|
+
for (const { clipInfo } of this.scheduledClips) {
|
|
1141
|
+
const end = clipInfo.startTime + clipInfo.duration;
|
|
1142
|
+
if (end > max) max = end;
|
|
1143
|
+
}
|
|
1144
|
+
return max;
|
|
1076
1145
|
}
|
|
1077
1146
|
get muted() {
|
|
1078
1147
|
return this.track.muted;
|
|
@@ -1081,9 +1150,6 @@ var _SoundFontToneTrack = class _SoundFontToneTrack {
|
|
|
1081
1150
|
return this.track.startTime;
|
|
1082
1151
|
}
|
|
1083
1152
|
};
|
|
1084
|
-
/** Rate-limit missing sample warnings — one per class lifetime */
|
|
1085
|
-
_SoundFontToneTrack._missingSampleWarned = false;
|
|
1086
|
-
var SoundFontToneTrack = _SoundFontToneTrack;
|
|
1087
1153
|
|
|
1088
1154
|
// src/TonePlayout.ts
|
|
1089
1155
|
var TonePlayout = class {
|
|
@@ -1098,7 +1164,7 @@ var TonePlayout = class {
|
|
|
1098
1164
|
this._loopStart = 0;
|
|
1099
1165
|
this._loopEnd = 0;
|
|
1100
1166
|
this._masterChainNode = null;
|
|
1101
|
-
this.masterVolume = new import_tone4.Volume((0,
|
|
1167
|
+
this.masterVolume = new import_tone4.Volume((0, import_core4.gainToDb)(options.masterGain ?? 1));
|
|
1102
1168
|
this._masterTap = new import_tone4.Gain(1);
|
|
1103
1169
|
if (options.effects) {
|
|
1104
1170
|
const cleanup = options.effects(this.masterVolume, this._masterTap, false);
|
|
@@ -1121,7 +1187,9 @@ var TonePlayout = class {
|
|
|
1121
1187
|
try {
|
|
1122
1188
|
(0, import_tone4.getTransport)().clear(this._completionEventId);
|
|
1123
1189
|
} catch (err) {
|
|
1124
|
-
console.warn(
|
|
1190
|
+
console.warn(
|
|
1191
|
+
"[waveform-playlist] Error clearing Transport completion event: " + String(err)
|
|
1192
|
+
);
|
|
1125
1193
|
}
|
|
1126
1194
|
this._completionEventId = null;
|
|
1127
1195
|
}
|
|
@@ -1216,6 +1284,7 @@ var TonePlayout = class {
|
|
|
1216
1284
|
const lookAhead = context.lookAhead ?? 0;
|
|
1217
1285
|
const audibleOffset = Math.max(0, transport.seconds - lookAhead);
|
|
1218
1286
|
track.startMidClipSources(audibleOffset, context.currentTime);
|
|
1287
|
+
track.prepareFades(context.currentTime, audibleOffset);
|
|
1219
1288
|
}
|
|
1220
1289
|
play(when, offset, duration) {
|
|
1221
1290
|
if (!this.isInitialized) {
|
|
@@ -1235,7 +1304,9 @@ var TonePlayout = class {
|
|
|
1235
1304
|
try {
|
|
1236
1305
|
this.onPlaybackCompleteCallback?.();
|
|
1237
1306
|
} catch (err) {
|
|
1238
|
-
console.warn(
|
|
1307
|
+
console.warn(
|
|
1308
|
+
"[waveform-playlist] Error in playback completion callback: " + String(err)
|
|
1309
|
+
);
|
|
1239
1310
|
}
|
|
1240
1311
|
}, transportOffset + duration);
|
|
1241
1312
|
}
|
|
@@ -1261,8 +1332,7 @@ var TonePlayout = class {
|
|
|
1261
1332
|
this.clearCompletionEvent();
|
|
1262
1333
|
this.tracks.forEach((track) => track.cancelFades());
|
|
1263
1334
|
console.warn(
|
|
1264
|
-
"[waveform-playlist] Transport.start() failed. Audio playback could not begin."
|
|
1265
|
-
err
|
|
1335
|
+
"[waveform-playlist] Transport.start() failed. Audio playback could not begin. " + String(err)
|
|
1266
1336
|
);
|
|
1267
1337
|
throw err;
|
|
1268
1338
|
}
|
|
@@ -1272,7 +1342,7 @@ var TonePlayout = class {
|
|
|
1272
1342
|
try {
|
|
1273
1343
|
transport.pause();
|
|
1274
1344
|
} catch (err) {
|
|
1275
|
-
console.warn("[waveform-playlist] Transport.pause() failed:"
|
|
1345
|
+
console.warn("[waveform-playlist] Transport.pause() failed: " + String(err));
|
|
1276
1346
|
}
|
|
1277
1347
|
this.tracks.forEach((track) => track.stopAllSources());
|
|
1278
1348
|
this.tracks.forEach((track) => track.cancelFades());
|
|
@@ -1283,13 +1353,13 @@ var TonePlayout = class {
|
|
|
1283
1353
|
try {
|
|
1284
1354
|
transport.stop();
|
|
1285
1355
|
} catch (err) {
|
|
1286
|
-
console.warn("[waveform-playlist] Transport.stop() failed:"
|
|
1356
|
+
console.warn("[waveform-playlist] Transport.stop() failed: " + String(err));
|
|
1287
1357
|
}
|
|
1288
1358
|
if (this._loopHandler) {
|
|
1289
1359
|
try {
|
|
1290
1360
|
transport.off("loop", this._loopHandler);
|
|
1291
1361
|
} catch (err) {
|
|
1292
|
-
console.warn("[waveform-playlist] Error removing loop handler:"
|
|
1362
|
+
console.warn("[waveform-playlist] Error removing loop handler: " + String(err));
|
|
1293
1363
|
}
|
|
1294
1364
|
this._loopHandler = null;
|
|
1295
1365
|
}
|
|
@@ -1297,20 +1367,24 @@ var TonePlayout = class {
|
|
|
1297
1367
|
try {
|
|
1298
1368
|
track.stopAllSources();
|
|
1299
1369
|
} catch (err) {
|
|
1300
|
-
console.warn(
|
|
1370
|
+
console.warn(
|
|
1371
|
+
`[waveform-playlist] Error stopping sources for track "${track.id}": ` + String(err)
|
|
1372
|
+
);
|
|
1301
1373
|
}
|
|
1302
1374
|
});
|
|
1303
1375
|
this.tracks.forEach((track) => {
|
|
1304
1376
|
try {
|
|
1305
1377
|
track.cancelFades();
|
|
1306
1378
|
} catch (err) {
|
|
1307
|
-
console.warn(
|
|
1379
|
+
console.warn(
|
|
1380
|
+
`[waveform-playlist] Error canceling fades for track "${track.id}": ` + String(err)
|
|
1381
|
+
);
|
|
1308
1382
|
}
|
|
1309
1383
|
});
|
|
1310
1384
|
this.clearCompletionEvent();
|
|
1311
1385
|
}
|
|
1312
1386
|
setMasterGain(gain) {
|
|
1313
|
-
this.masterVolume.volume.value = (0,
|
|
1387
|
+
this.masterVolume.volume.value = (0, import_core4.gainToDb)(gain);
|
|
1314
1388
|
}
|
|
1315
1389
|
/** The master output tap node. In the signal chain: masterVolume → tap → destination.
|
|
1316
1390
|
* Connect analyzers/effects/recorders here — parallel or serial.
|
|
@@ -1351,10 +1425,14 @@ var TonePlayout = class {
|
|
|
1351
1425
|
* effects] → tap → node (caller wires node.output → ctx.destination).
|
|
1352
1426
|
*/
|
|
1353
1427
|
connectMasterOutput(node) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1428
|
+
try {
|
|
1429
|
+
if (this._masterChainNode) {
|
|
1430
|
+
this._masterTap.disconnect(this._masterChainNode);
|
|
1431
|
+
} else {
|
|
1432
|
+
this._masterTap.disconnect((0, import_tone4.getDestination)());
|
|
1433
|
+
}
|
|
1434
|
+
} catch (err) {
|
|
1435
|
+
console.warn("[waveform-playlist] connectMasterOutput disconnect: " + String(err));
|
|
1358
1436
|
}
|
|
1359
1437
|
this._masterTap.connect(node);
|
|
1360
1438
|
this._masterChainNode = node;
|
|
@@ -1404,7 +1482,7 @@ var TonePlayout = class {
|
|
|
1404
1482
|
const track = this.tracks.get(trackId);
|
|
1405
1483
|
if (track) {
|
|
1406
1484
|
this.manualMuteState.set(trackId, muted);
|
|
1407
|
-
|
|
1485
|
+
this.updateSoloMuting();
|
|
1408
1486
|
}
|
|
1409
1487
|
}
|
|
1410
1488
|
setLoop(enabled, loopStart, loopEnd) {
|
|
@@ -1417,7 +1495,7 @@ var TonePlayout = class {
|
|
|
1417
1495
|
transport.loopEnd = loopEnd;
|
|
1418
1496
|
transport.loop = enabled;
|
|
1419
1497
|
} catch (err) {
|
|
1420
|
-
console.warn("[waveform-playlist] Error configuring Transport loop:"
|
|
1498
|
+
console.warn("[waveform-playlist] Error configuring Transport loop: " + String(err));
|
|
1421
1499
|
return;
|
|
1422
1500
|
}
|
|
1423
1501
|
if (enabled && !this._loopHandler) {
|
|
@@ -1432,8 +1510,7 @@ var TonePlayout = class {
|
|
|
1432
1510
|
track.prepareFades(currentTime, this._loopStart);
|
|
1433
1511
|
} catch (err) {
|
|
1434
1512
|
console.warn(
|
|
1435
|
-
`[waveform-playlist] Error re-scheduling track "${track.id}" on loop
|
|
1436
|
-
err
|
|
1513
|
+
`[waveform-playlist] Error re-scheduling track "${track.id}" on loop: ` + String(err)
|
|
1437
1514
|
);
|
|
1438
1515
|
}
|
|
1439
1516
|
});
|
|
@@ -1454,13 +1531,17 @@ var TonePlayout = class {
|
|
|
1454
1531
|
try {
|
|
1455
1532
|
this.stop();
|
|
1456
1533
|
} catch (err) {
|
|
1457
|
-
console.warn(
|
|
1534
|
+
console.warn(
|
|
1535
|
+
"[waveform-playlist] Error stopping Transport during dispose: " + String(err)
|
|
1536
|
+
);
|
|
1458
1537
|
}
|
|
1459
1538
|
this.tracks.forEach((track) => {
|
|
1460
1539
|
try {
|
|
1461
1540
|
track.dispose();
|
|
1462
1541
|
} catch (err) {
|
|
1463
|
-
console.warn(
|
|
1542
|
+
console.warn(
|
|
1543
|
+
`[waveform-playlist] Error disposing track "${track.id}": ` + String(err)
|
|
1544
|
+
);
|
|
1464
1545
|
}
|
|
1465
1546
|
});
|
|
1466
1547
|
this.tracks.clear();
|
|
@@ -1468,7 +1549,9 @@ var TonePlayout = class {
|
|
|
1468
1549
|
try {
|
|
1469
1550
|
this.effectsCleanup();
|
|
1470
1551
|
} catch (err) {
|
|
1471
|
-
console.warn(
|
|
1552
|
+
console.warn(
|
|
1553
|
+
"[waveform-playlist] Error during master effects cleanup: " + String(err)
|
|
1554
|
+
);
|
|
1472
1555
|
}
|
|
1473
1556
|
}
|
|
1474
1557
|
try {
|
|
@@ -1576,7 +1659,9 @@ var SoundFontCache = class _SoundFontCache {
|
|
|
1576
1659
|
async load(url, signal) {
|
|
1577
1660
|
const response = await fetch(url, { signal });
|
|
1578
1661
|
if (!response.ok) {
|
|
1579
|
-
throw new Error(
|
|
1662
|
+
throw new Error(
|
|
1663
|
+
`Failed to fetch SoundFont ${url}: ${response.status}${response.statusText ? ` ${response.statusText}` : ""}`
|
|
1664
|
+
);
|
|
1580
1665
|
}
|
|
1581
1666
|
const arrayBuffer = await response.arrayBuffer();
|
|
1582
1667
|
try {
|
|
@@ -1586,6 +1671,7 @@ var SoundFontCache = class _SoundFontCache {
|
|
|
1586
1671
|
`Failed to parse SoundFont ${url}: ${err instanceof Error ? err.message : String(err)}`
|
|
1587
1672
|
);
|
|
1588
1673
|
}
|
|
1674
|
+
this.audioBufferCache.clear();
|
|
1589
1675
|
}
|
|
1590
1676
|
/**
|
|
1591
1677
|
* Load from an already-fetched ArrayBuffer.
|
|
@@ -1598,6 +1684,7 @@ var SoundFontCache = class _SoundFontCache {
|
|
|
1598
1684
|
`Failed to parse SoundFont from buffer: ${err instanceof Error ? err.message : String(err)}`
|
|
1599
1685
|
);
|
|
1600
1686
|
}
|
|
1687
|
+
this.audioBufferCache.clear();
|
|
1601
1688
|
}
|
|
1602
1689
|
get isLoaded() {
|
|
1603
1690
|
return this.sf2 !== null;
|
|
@@ -1696,7 +1783,7 @@ function configureGlobalContext(options) {
|
|
|
1696
1783
|
"[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."
|
|
1697
1784
|
);
|
|
1698
1785
|
}
|
|
1699
|
-
globalToneContext = new import_tone5.Context();
|
|
1786
|
+
globalToneContext = options.latencyHint !== void 0 ? new import_tone5.Context({ latencyHint: options.latencyHint }) : new import_tone5.Context();
|
|
1700
1787
|
(0, import_tone5.setContext)(globalToneContext);
|
|
1701
1788
|
const actualRate = globalToneContext.rawContext.sampleRate;
|
|
1702
1789
|
if (options.sampleRate !== void 0 && options.sampleRate !== actualRate) {
|
|
@@ -1729,34 +1816,38 @@ function getGlobalAudioContextState() {
|
|
|
1729
1816
|
return globalToneContext?.rawContext.state || "suspended";
|
|
1730
1817
|
}
|
|
1731
1818
|
async function closeGlobalAudioContext() {
|
|
1732
|
-
if (globalToneContext
|
|
1819
|
+
if (!globalToneContext) return;
|
|
1820
|
+
if (globalToneContext.rawContext.state !== "closed") {
|
|
1733
1821
|
await globalToneContext.close();
|
|
1734
|
-
globalToneContext = null;
|
|
1735
|
-
_nativeMode = false;
|
|
1736
1822
|
}
|
|
1823
|
+
globalToneContext = null;
|
|
1824
|
+
_nativeMode = false;
|
|
1737
1825
|
}
|
|
1738
1826
|
|
|
1739
1827
|
// src/mediaStreamSourceManager.ts
|
|
1740
|
-
var import_tone6 = require("tone");
|
|
1741
1828
|
var streamSources = /* @__PURE__ */ new Map();
|
|
1742
1829
|
var streamCleanupHandlers = /* @__PURE__ */ new Map();
|
|
1743
1830
|
function getMediaStreamSource(stream) {
|
|
1744
1831
|
if (streamSources.has(stream)) {
|
|
1745
1832
|
return streamSources.get(stream);
|
|
1746
1833
|
}
|
|
1747
|
-
const context = (
|
|
1834
|
+
const context = getGlobalContext();
|
|
1748
1835
|
const source = context.createMediaStreamSource(stream);
|
|
1749
1836
|
streamSources.set(stream, source);
|
|
1837
|
+
const tracks = stream.getTracks();
|
|
1838
|
+
const onTrackEnded = () => {
|
|
1839
|
+
if (!stream.active) {
|
|
1840
|
+
cleanup();
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1750
1843
|
const cleanup = () => {
|
|
1751
1844
|
source.disconnect();
|
|
1752
1845
|
streamSources.delete(stream);
|
|
1753
1846
|
streamCleanupHandlers.delete(stream);
|
|
1754
|
-
|
|
1755
|
-
stream.removeEventListener("inactive", cleanup);
|
|
1847
|
+
tracks.forEach((track) => track.removeEventListener("ended", onTrackEnded));
|
|
1756
1848
|
};
|
|
1757
1849
|
streamCleanupHandlers.set(stream, cleanup);
|
|
1758
|
-
|
|
1759
|
-
stream.addEventListener("inactive", cleanup);
|
|
1850
|
+
tracks.forEach((track) => track.addEventListener("ended", onTrackEnded));
|
|
1760
1851
|
return source;
|
|
1761
1852
|
}
|
|
1762
1853
|
function releaseMediaStreamSource(stream) {
|
|
@@ -1770,8 +1861,8 @@ function hasMediaStreamSource(stream) {
|
|
|
1770
1861
|
}
|
|
1771
1862
|
|
|
1772
1863
|
// src/TonePlayoutAdapter.ts
|
|
1773
|
-
var
|
|
1774
|
-
var
|
|
1864
|
+
var import_core5 = require("@waveform-playlist/core");
|
|
1865
|
+
var import_tone6 = require("tone");
|
|
1775
1866
|
function isToneAdapter(adapter) {
|
|
1776
1867
|
return typeof adapter?.setSoundFontCache === "function";
|
|
1777
1868
|
}
|
|
@@ -1802,8 +1893,8 @@ function createToneAdapter(options) {
|
|
|
1802
1893
|
function addAudioTrackToPlayout(p, track) {
|
|
1803
1894
|
const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1804
1895
|
if (audioClips.length === 0) return;
|
|
1805
|
-
const startTime = Math.min(...audioClips.map(
|
|
1806
|
-
const endTime = Math.max(...audioClips.map(
|
|
1896
|
+
const startTime = Math.min(...audioClips.map(import_core5.clipStartTime));
|
|
1897
|
+
const endTime = Math.max(...audioClips.map(import_core5.clipEndTime));
|
|
1807
1898
|
const trackObj = {
|
|
1808
1899
|
id: track.id,
|
|
1809
1900
|
name: track.name,
|
|
@@ -1816,9 +1907,9 @@ function createToneAdapter(options) {
|
|
|
1816
1907
|
};
|
|
1817
1908
|
const clipInfos = audioClips.map((clip) => ({
|
|
1818
1909
|
buffer: clip.audioBuffer,
|
|
1819
|
-
startTime: (0,
|
|
1820
|
-
duration: (0,
|
|
1821
|
-
offset: (0,
|
|
1910
|
+
startTime: (0, import_core5.clipStartTime)(clip) - startTime,
|
|
1911
|
+
duration: (0, import_core5.clipDurationTime)(clip),
|
|
1912
|
+
offset: (0, import_core5.clipOffsetTime)(clip),
|
|
1822
1913
|
fadeIn: clip.fadeIn,
|
|
1823
1914
|
fadeOut: clip.fadeOut,
|
|
1824
1915
|
gain: clip.gain
|
|
@@ -1827,14 +1918,14 @@ function createToneAdapter(options) {
|
|
|
1827
1918
|
clips: clipInfos,
|
|
1828
1919
|
track: trackObj,
|
|
1829
1920
|
effects: track.effects,
|
|
1830
|
-
channelCount: (0,
|
|
1921
|
+
channelCount: (0, import_core5.trackChannelCount)(track)
|
|
1831
1922
|
});
|
|
1832
1923
|
}
|
|
1833
1924
|
function addMidiTrackToPlayout(p, track) {
|
|
1834
1925
|
const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
1835
1926
|
if (midiClips.length === 0) return;
|
|
1836
|
-
const startTime = Math.min(...midiClips.map(
|
|
1837
|
-
const endTime = Math.max(...midiClips.map(
|
|
1927
|
+
const startTime = Math.min(...midiClips.map(import_core5.clipStartTime));
|
|
1928
|
+
const endTime = Math.max(...midiClips.map(import_core5.clipEndTime));
|
|
1838
1929
|
const trackId = midiPlayoutTrackId(track);
|
|
1839
1930
|
const trackObj = {
|
|
1840
1931
|
id: trackId,
|
|
@@ -1848,9 +1939,9 @@ function createToneAdapter(options) {
|
|
|
1848
1939
|
};
|
|
1849
1940
|
const midiClipInfos = midiClips.map((clip) => ({
|
|
1850
1941
|
notes: clip.midiNotes,
|
|
1851
|
-
startTime: (0,
|
|
1852
|
-
duration: (0,
|
|
1853
|
-
offset: (0,
|
|
1942
|
+
startTime: (0, import_core5.clipStartTime)(clip) - startTime,
|
|
1943
|
+
duration: (0, import_core5.clipDurationTime)(clip),
|
|
1944
|
+
offset: (0, import_core5.clipOffsetTime)(clip)
|
|
1854
1945
|
}));
|
|
1855
1946
|
if (_soundFontCache?.isLoaded) {
|
|
1856
1947
|
const firstClip = midiClips[0];
|
|
@@ -1889,7 +1980,7 @@ function createToneAdapter(options) {
|
|
|
1889
1980
|
try {
|
|
1890
1981
|
playout.dispose();
|
|
1891
1982
|
} catch (err) {
|
|
1892
|
-
console.warn("[waveform-playlist] Error disposing previous playout:"
|
|
1983
|
+
console.warn("[waveform-playlist] Error disposing previous playout: " + String(err));
|
|
1893
1984
|
}
|
|
1894
1985
|
playout = null;
|
|
1895
1986
|
}
|
|
@@ -1901,8 +1992,7 @@ function createToneAdapter(options) {
|
|
|
1901
1992
|
if (_audioInitialized) {
|
|
1902
1993
|
_pendingInit = playout.init().catch((err) => {
|
|
1903
1994
|
console.warn(
|
|
1904
|
-
"[waveform-playlist] Failed to initialize playout. Audio playback will require another user gesture."
|
|
1905
|
-
err
|
|
1995
|
+
"[waveform-playlist] Failed to initialize playout. Audio playback will require another user gesture. " + String(err)
|
|
1906
1996
|
);
|
|
1907
1997
|
_audioInitialized = false;
|
|
1908
1998
|
});
|
|
@@ -1987,25 +2077,28 @@ function createToneAdapter(options) {
|
|
|
1987
2077
|
if (!playout) return;
|
|
1988
2078
|
const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1989
2079
|
if (audioClips.length > 0) {
|
|
1990
|
-
const startTime = Math.min(...audioClips.map(
|
|
2080
|
+
const startTime = Math.min(...audioClips.map(import_core5.clipStartTime));
|
|
1991
2081
|
const clipInfos = audioClips.map((clip) => ({
|
|
1992
2082
|
buffer: clip.audioBuffer,
|
|
1993
|
-
startTime: (0,
|
|
1994
|
-
duration: (0,
|
|
1995
|
-
offset: (0,
|
|
2083
|
+
startTime: (0, import_core5.clipStartTime)(clip) - startTime,
|
|
2084
|
+
duration: (0, import_core5.clipDurationTime)(clip),
|
|
2085
|
+
offset: (0, import_core5.clipOffsetTime)(clip),
|
|
1996
2086
|
fadeIn: clip.fadeIn,
|
|
1997
2087
|
fadeOut: clip.fadeOut,
|
|
1998
2088
|
gain: clip.gain
|
|
1999
2089
|
}));
|
|
2000
2090
|
const audioUpdated = playout.replaceTrackClips(trackId, clipInfos, startTime);
|
|
2001
2091
|
const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
2092
|
+
const midiTrackId = trackId + ":midi";
|
|
2002
2093
|
if (midiClips.length > 0) {
|
|
2003
|
-
const midiTrackId = trackId + ":midi";
|
|
2004
2094
|
playout.removeTrack(midiTrackId);
|
|
2005
2095
|
addMidiTrackToPlayout(playout, track);
|
|
2006
2096
|
if (_isPlaying) {
|
|
2007
2097
|
playout.resumeTrackMidPlayback(midiTrackId);
|
|
2008
2098
|
}
|
|
2099
|
+
} else {
|
|
2100
|
+
playout.removeTrack(midiTrackId);
|
|
2101
|
+
_midiTrackBuild.delete(midiTrackId);
|
|
2009
2102
|
}
|
|
2010
2103
|
if (audioUpdated) {
|
|
2011
2104
|
playout.applyInitialSoloState();
|
|
@@ -2051,7 +2144,7 @@ function createToneAdapter(options) {
|
|
|
2051
2144
|
return;
|
|
2052
2145
|
}
|
|
2053
2146
|
const duration = endTime !== void 0 ? endTime - startTime : void 0;
|
|
2054
|
-
playout.play((0,
|
|
2147
|
+
playout.play((0, import_tone6.now)(), startTime, duration);
|
|
2055
2148
|
_isPlaying = true;
|
|
2056
2149
|
},
|
|
2057
2150
|
pause() {
|
|
@@ -2074,25 +2167,34 @@ function createToneAdapter(options) {
|
|
|
2074
2167
|
setMasterVolume(volume) {
|
|
2075
2168
|
playout?.setMasterGain(volume);
|
|
2076
2169
|
},
|
|
2170
|
+
// Runtime controls must reach BOTH playout halves of a mixed audio+MIDI
|
|
2171
|
+
// track (trackId + trackId:midi) — otherwise muting a mixed track leaves
|
|
2172
|
+
// its MIDI playing and soloing it silences its own MIDI half. The :midi
|
|
2173
|
+
// calls no-op for audio-only and MIDI-only tracks (unknown playout id),
|
|
2174
|
+
// same blind-forwarding pattern as removeTrack.
|
|
2077
2175
|
setTrackVolume(trackId, volume) {
|
|
2078
2176
|
const existing = _currentTracks.get(trackId);
|
|
2079
2177
|
if (existing) _currentTracks.set(trackId, { ...existing, volume });
|
|
2080
2178
|
playout?.getTrack(trackId)?.setVolume(volume);
|
|
2179
|
+
playout?.getTrack(trackId + ":midi")?.setVolume(volume);
|
|
2081
2180
|
},
|
|
2082
2181
|
setTrackMute(trackId, muted) {
|
|
2083
2182
|
const existing = _currentTracks.get(trackId);
|
|
2084
2183
|
if (existing) _currentTracks.set(trackId, { ...existing, muted });
|
|
2085
2184
|
playout?.setMute(trackId, muted);
|
|
2185
|
+
playout?.setMute(trackId + ":midi", muted);
|
|
2086
2186
|
},
|
|
2087
2187
|
setTrackSolo(trackId, soloed) {
|
|
2088
2188
|
const existing = _currentTracks.get(trackId);
|
|
2089
2189
|
if (existing) _currentTracks.set(trackId, { ...existing, soloed });
|
|
2090
2190
|
playout?.setSolo(trackId, soloed);
|
|
2191
|
+
playout?.setSolo(trackId + ":midi", soloed);
|
|
2091
2192
|
},
|
|
2092
2193
|
setTrackPan(trackId, pan) {
|
|
2093
2194
|
const existing = _currentTracks.get(trackId);
|
|
2094
2195
|
if (existing) _currentTracks.set(trackId, { ...existing, pan });
|
|
2095
2196
|
playout?.getTrack(trackId)?.setPan(pan);
|
|
2197
|
+
playout?.getTrack(trackId + ":midi")?.setPan(pan);
|
|
2096
2198
|
},
|
|
2097
2199
|
setLoop(enabled, start2, end) {
|
|
2098
2200
|
_loopEnabled = enabled;
|