@dawcore/transport 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +66 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -756,28 +756,25 @@ var ClipPlayer = class {
|
|
|
756
756
|
}
|
|
757
757
|
generate(fromTick, toTick) {
|
|
758
758
|
const events = [];
|
|
759
|
-
const fromSample = this._sampleTimeline.ticksToSamples(fromTick);
|
|
760
|
-
const toSample = this._sampleTimeline.ticksToSamples(toTick);
|
|
761
759
|
for (const [trackId, state] of this._tracks) {
|
|
762
760
|
for (const clip of state.clips) {
|
|
763
761
|
if (clip.durationSamples === 0) continue;
|
|
764
762
|
if (!clip.audioBuffer) continue;
|
|
765
|
-
const
|
|
766
|
-
if (
|
|
767
|
-
if (
|
|
763
|
+
const clipTick = clip.startTick !== void 0 ? clip.startTick : this._sampleTimeline.samplesToTicks(clip.startSample);
|
|
764
|
+
if (clipTick < fromTick) continue;
|
|
765
|
+
if (clipTick >= toTick) continue;
|
|
768
766
|
const fadeInDurationSamples = clip.fadeIn ? clip.fadeIn.duration ?? 0 : 0;
|
|
769
767
|
const fadeOutDurationSamples = clip.fadeOut ? clip.fadeOut.duration ?? 0 : 0;
|
|
770
768
|
let durationSamples = clip.durationSamples;
|
|
771
|
-
if (this._loopEnabled &&
|
|
772
|
-
durationSamples = this._loopEndSamples -
|
|
769
|
+
if (this._loopEnabled && clip.startSample + durationSamples > this._loopEndSamples) {
|
|
770
|
+
durationSamples = this._loopEndSamples - clip.startSample;
|
|
773
771
|
}
|
|
774
|
-
const clipTick = this._sampleTimeline.samplesToTicks(clipStartSample);
|
|
775
772
|
events.push({
|
|
776
773
|
trackId,
|
|
777
774
|
clipId: clip.id,
|
|
778
775
|
audioBuffer: clip.audioBuffer,
|
|
779
776
|
tick: clipTick,
|
|
780
|
-
startSample:
|
|
777
|
+
startSample: clip.startSample,
|
|
781
778
|
offsetSamples: clip.offsetSamples,
|
|
782
779
|
durationSamples,
|
|
783
780
|
gain: clip.gain,
|
|
@@ -850,30 +847,30 @@ var ClipPlayer = class {
|
|
|
850
847
|
for (const clip of state.clips) {
|
|
851
848
|
if (clip.durationSamples === 0) continue;
|
|
852
849
|
if (!clip.audioBuffer) continue;
|
|
853
|
-
const
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
if (durationSamples <= 0) continue;
|
|
863
|
-
const fadeOutDurationSamples = clip.fadeOut ? clip.fadeOut.duration ?? 0 : 0;
|
|
864
|
-
this.consume({
|
|
865
|
-
trackId,
|
|
866
|
-
clipId: clip.id,
|
|
867
|
-
audioBuffer: clip.audioBuffer,
|
|
868
|
-
tick: newTick,
|
|
869
|
-
startSample: newSample,
|
|
870
|
-
offsetSamples,
|
|
871
|
-
durationSamples,
|
|
872
|
-
gain: clip.gain,
|
|
873
|
-
fadeInDurationSamples: 0,
|
|
874
|
-
fadeOutDurationSamples
|
|
875
|
-
});
|
|
850
|
+
const clipTick = clip.startTick !== void 0 ? clip.startTick : this._sampleTimeline.samplesToTicks(clip.startSample);
|
|
851
|
+
if (clipTick >= newTick) continue;
|
|
852
|
+
const clipEndSample = clip.startSample + clip.durationSamples;
|
|
853
|
+
if (clipEndSample <= newSample) continue;
|
|
854
|
+
const offsetIntoClipSamples = newSample - clip.startSample;
|
|
855
|
+
const offsetSamples = clip.offsetSamples + offsetIntoClipSamples;
|
|
856
|
+
let durationSamples = clipEndSample - newSample;
|
|
857
|
+
if (this._loopEnabled && newSample + durationSamples > this._loopEndSamples) {
|
|
858
|
+
durationSamples = this._loopEndSamples - newSample;
|
|
876
859
|
}
|
|
860
|
+
if (durationSamples <= 0) continue;
|
|
861
|
+
const fadeOutDurationSamples = clip.fadeOut ? clip.fadeOut.duration ?? 0 : 0;
|
|
862
|
+
this.consume({
|
|
863
|
+
trackId,
|
|
864
|
+
clipId: clip.id,
|
|
865
|
+
audioBuffer: clip.audioBuffer,
|
|
866
|
+
tick: newTick,
|
|
867
|
+
startSample: newSample,
|
|
868
|
+
offsetSamples,
|
|
869
|
+
durationSamples,
|
|
870
|
+
gain: clip.gain,
|
|
871
|
+
fadeInDurationSamples: 0,
|
|
872
|
+
fadeOutDurationSamples
|
|
873
|
+
});
|
|
877
874
|
}
|
|
878
875
|
}
|
|
879
876
|
}
|
|
@@ -1779,6 +1776,27 @@ var NativePlayoutAdapter = class {
|
|
|
1779
1776
|
}
|
|
1780
1777
|
if (this._audioContext.state === "suspended") {
|
|
1781
1778
|
await this._audioContext.resume();
|
|
1779
|
+
const MIN_WARMUP = 0.02;
|
|
1780
|
+
const warmupTarget = Math.max(MIN_WARMUP, this._audioContext.outputLatency ?? MIN_WARMUP);
|
|
1781
|
+
if (this._audioContext.currentTime < warmupTarget) {
|
|
1782
|
+
const MAX_WARMUP_MS = 2e3;
|
|
1783
|
+
await new Promise((resolve) => {
|
|
1784
|
+
const startMs = performance.now();
|
|
1785
|
+
const check = () => {
|
|
1786
|
+
if (this._audioContext.currentTime >= warmupTarget) {
|
|
1787
|
+
resolve();
|
|
1788
|
+
} else if (this._audioContext.state === "closed" || performance.now() - startMs > MAX_WARMUP_MS) {
|
|
1789
|
+
console.warn(
|
|
1790
|
+
"[waveform-playlist] AudioContext warmup timed out (currentTime=" + this._audioContext.currentTime + ", target=" + warmupTarget + ", state=" + this._audioContext.state + "). Proceeding without warmup."
|
|
1791
|
+
);
|
|
1792
|
+
resolve();
|
|
1793
|
+
} else {
|
|
1794
|
+
requestAnimationFrame(check);
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
requestAnimationFrame(check);
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1782
1800
|
}
|
|
1783
1801
|
}
|
|
1784
1802
|
setTracks(tracks) {
|
|
@@ -1844,6 +1862,22 @@ var NativePlayoutAdapter = class {
|
|
|
1844
1862
|
isCountingIn() {
|
|
1845
1863
|
return this._transport.isCountingIn();
|
|
1846
1864
|
}
|
|
1865
|
+
setTempo(bpm, atTick) {
|
|
1866
|
+
this._transport.setTempo(bpm, atTick !== void 0 ? atTick : void 0);
|
|
1867
|
+
}
|
|
1868
|
+
setMeter(numerator, denominator, atTick) {
|
|
1869
|
+
this._transport.setMeter(
|
|
1870
|
+
numerator,
|
|
1871
|
+
denominator,
|
|
1872
|
+
atTick !== void 0 ? atTick : void 0
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
ticksToSeconds(tick) {
|
|
1876
|
+
return this._transport.tickToTime(tick);
|
|
1877
|
+
}
|
|
1878
|
+
secondsToTicks(seconds) {
|
|
1879
|
+
return this._transport.timeToTick(seconds);
|
|
1880
|
+
}
|
|
1847
1881
|
dispose() {
|
|
1848
1882
|
this._transport.dispose();
|
|
1849
1883
|
}
|