@waveform-playlist/browser 16.0.1 → 17.0.0-next.0
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 +69 -33
- package/dist/index.d.mts +1272 -704
- package/dist/index.d.ts +1272 -704
- package/dist/index.js +5232 -3744
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5183 -3726
- package/dist/index.mjs.map +1 -1
- package/dist/tone.d.mts +162 -210
- package/dist/tone.d.ts +162 -210
- package/dist/tone.js +719 -1000
- package/dist/tone.js.map +1 -1
- package/dist/tone.mjs +702 -985
- package/dist/tone.mjs.map +1 -1
- package/package.json +15 -13
package/dist/tone.js
CHANGED
|
@@ -69,17 +69,18 @@ var tone_exports = {};
|
|
|
69
69
|
__export(tone_exports, {
|
|
70
70
|
ExportWavButton: () => ExportWavButton,
|
|
71
71
|
WamEffectGui: () => WamEffectGui,
|
|
72
|
+
createCustomEffectInstance: () => createCustomEffectInstance,
|
|
72
73
|
createEffectChain: () => createEffectChain,
|
|
73
74
|
createEffectInstance: () => createEffectInstance,
|
|
74
75
|
createWamEffectInstance: () => createWamEffectInstance,
|
|
75
76
|
effectCategories: () => effectCategories,
|
|
76
77
|
effectDefinitions: () => effectDefinitions,
|
|
78
|
+
getAvailableEffects: () => getAvailableEffects,
|
|
77
79
|
getEffectDefinition: () => getEffectDefinition,
|
|
78
80
|
getEffectsByCategory: () => getEffectsByCategory,
|
|
79
81
|
loadWamModule: () => loadWamModule,
|
|
80
|
-
|
|
82
|
+
useActiveEffects: () => useActiveEffects,
|
|
81
83
|
useDynamicEffects: () => useDynamicEffects,
|
|
82
|
-
useDynamicTracks: () => useDynamicTracks,
|
|
83
84
|
useExportWav: () => useExportWav,
|
|
84
85
|
useMasterAnalyser: () => useMasterAnalyser,
|
|
85
86
|
useOutputMeter: () => useOutputMeter,
|
|
@@ -87,214 +88,12 @@ __export(tone_exports, {
|
|
|
87
88
|
});
|
|
88
89
|
module.exports = __toCommonJS(tone_exports);
|
|
89
90
|
|
|
90
|
-
// src/hooks/useAudioTracks.ts
|
|
91
|
-
var import_react = require("react");
|
|
92
|
-
var Tone = __toESM(require("tone"));
|
|
93
|
-
|
|
94
|
-
// src/hooks/buildTrackFromConfig.ts
|
|
95
|
-
var import_core = require("@waveform-playlist/core");
|
|
96
|
-
function buildTrackFromConfig(config, index, audioBuffer, stableIds, contextSampleRate = 48e3, options = {}) {
|
|
97
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
98
|
-
const buffer = audioBuffer != null ? audioBuffer : config.audioBuffer;
|
|
99
|
-
const sampleRate = (_c = (_b = buffer == null ? void 0 : buffer.sampleRate) != null ? _b : (_a = config.waveformData) == null ? void 0 : _a.sample_rate) != null ? _c : contextSampleRate;
|
|
100
|
-
const sourceDuration = (_g = (_e = buffer == null ? void 0 : buffer.duration) != null ? _e : (_d = config.waveformData) == null ? void 0 : _d.duration) != null ? _g : config.duration != null ? config.duration + ((_f = config.offset) != null ? _f : 0) : void 0;
|
|
101
|
-
if (sourceDuration === void 0) {
|
|
102
|
-
if (!options.suppressMissingDurationWarning) {
|
|
103
|
-
console.warn(
|
|
104
|
-
`[waveform-playlist] Track ${index + 1} ("${(_h = config.name) != null ? _h : "unnamed"}"): Cannot create track \u2014 provide duration, audioBuffer, or waveformData with duration.`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
const clip = (0, import_core.createClipFromSeconds)({
|
|
110
|
-
audioBuffer: buffer,
|
|
111
|
-
sampleRate,
|
|
112
|
-
sourceDuration,
|
|
113
|
-
startTime: (_i = config.startTime) != null ? _i : 0,
|
|
114
|
-
duration: (_j = config.duration) != null ? _j : sourceDuration,
|
|
115
|
-
offset: (_k = config.offset) != null ? _k : 0,
|
|
116
|
-
name: config.name || `Track ${index + 1}`,
|
|
117
|
-
fadeIn: config.fadeIn,
|
|
118
|
-
fadeOut: config.fadeOut,
|
|
119
|
-
waveformData: config.waveformData
|
|
120
|
-
});
|
|
121
|
-
if (isNaN(clip.startSample) || isNaN(clip.durationSamples) || isNaN(clip.offsetSamples)) {
|
|
122
|
-
console.error(
|
|
123
|
-
`[waveform-playlist] Invalid clip values for track ${index + 1} ("${(_l = config.name) != null ? _l : "unnamed"}"): startSample=${clip.startSample}, durationSamples=${clip.durationSamples}, offsetSamples=${clip.offsetSamples}`
|
|
124
|
-
);
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
const track = __spreadProps(__spreadValues({}, (0, import_core.createTrack)({
|
|
128
|
-
name: config.name || `Track ${index + 1}`,
|
|
129
|
-
clips: [clip],
|
|
130
|
-
muted: (_m = config.muted) != null ? _m : false,
|
|
131
|
-
soloed: (_n = config.soloed) != null ? _n : false,
|
|
132
|
-
volume: (_o = config.volume) != null ? _o : 1,
|
|
133
|
-
pan: (_p = config.pan) != null ? _p : 0,
|
|
134
|
-
color: config.color
|
|
135
|
-
})), {
|
|
136
|
-
effects: config.effects,
|
|
137
|
-
renderMode: config.renderMode,
|
|
138
|
-
spectrogramConfig: config.spectrogramConfig,
|
|
139
|
-
spectrogramColorMap: config.spectrogramColorMap
|
|
140
|
-
});
|
|
141
|
-
const existingIds = stableIds.get(index);
|
|
142
|
-
if (existingIds) {
|
|
143
|
-
track.id = existingIds.trackId;
|
|
144
|
-
track.clips[0] = __spreadProps(__spreadValues({}, track.clips[0]), { id: existingIds.clipId });
|
|
145
|
-
} else {
|
|
146
|
-
stableIds.set(index, { trackId: track.id, clipId: track.clips[0].id });
|
|
147
|
-
}
|
|
148
|
-
return track;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// src/hooks/useAudioTracks.ts
|
|
152
|
-
function useAudioTracks(configs, options = {}) {
|
|
153
|
-
const { immediate = false, progressive = false } = options;
|
|
154
|
-
const isImmediate = immediate || progressive;
|
|
155
|
-
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
156
|
-
const [error, setError] = (0, import_react.useState)(null);
|
|
157
|
-
const [loadedCount, setLoadedCount] = (0, import_react.useState)(0);
|
|
158
|
-
const totalCount = configs.length;
|
|
159
|
-
const [loadedBuffers, setLoadedBuffers] = (0, import_react.useState)(/* @__PURE__ */ new Map());
|
|
160
|
-
const stableIdsRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
|
161
|
-
const contextSampleRateRef = (0, import_react.useRef)(48e3);
|
|
162
|
-
const derivedTracks = (0, import_react.useMemo)(() => {
|
|
163
|
-
if (!isImmediate) return null;
|
|
164
|
-
const result = [];
|
|
165
|
-
for (let i = 0; i < configs.length; i++) {
|
|
166
|
-
const pendingDecode = !loadedBuffers.has(i) && !configs[i].audioBuffer && configs[i].src != null;
|
|
167
|
-
const track = buildTrackFromConfig(
|
|
168
|
-
configs[i],
|
|
169
|
-
i,
|
|
170
|
-
loadedBuffers.get(i),
|
|
171
|
-
stableIdsRef.current,
|
|
172
|
-
contextSampleRateRef.current,
|
|
173
|
-
{ suppressMissingDurationWarning: pendingDecode }
|
|
174
|
-
);
|
|
175
|
-
if (track) result.push(track);
|
|
176
|
-
}
|
|
177
|
-
return result;
|
|
178
|
-
}, [isImmediate, configs, loadedBuffers]);
|
|
179
|
-
const [tracks, setTracks] = (0, import_react.useState)(derivedTracks != null ? derivedTracks : []);
|
|
180
|
-
const prevDerivedRef = (0, import_react.useRef)(derivedTracks);
|
|
181
|
-
if (derivedTracks !== prevDerivedRef.current) {
|
|
182
|
-
prevDerivedRef.current = derivedTracks;
|
|
183
|
-
if (derivedTracks) setTracks(derivedTracks);
|
|
184
|
-
}
|
|
185
|
-
(0, import_react.useEffect)(() => {
|
|
186
|
-
if (configs.length === 0) {
|
|
187
|
-
setTracks([]);
|
|
188
|
-
setLoading(false);
|
|
189
|
-
setLoadedCount(0);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
let cancelled = false;
|
|
193
|
-
const abortController = new AbortController();
|
|
194
|
-
const loadTracks = () => __async(null, null, function* () {
|
|
195
|
-
try {
|
|
196
|
-
setLoading(true);
|
|
197
|
-
setError(null);
|
|
198
|
-
setLoadedCount(0);
|
|
199
|
-
if (isImmediate) {
|
|
200
|
-
setLoadedBuffers(/* @__PURE__ */ new Map());
|
|
201
|
-
}
|
|
202
|
-
const audioContext = Tone.getContext().rawContext;
|
|
203
|
-
contextSampleRateRef.current = audioContext.sampleRate;
|
|
204
|
-
const loadPromises = configs.map((config, index) => __async(null, null, function* () {
|
|
205
|
-
if (config.audioBuffer) {
|
|
206
|
-
if (isImmediate && !cancelled) {
|
|
207
|
-
setLoadedBuffers((prev) => {
|
|
208
|
-
const next = new Map(prev);
|
|
209
|
-
next.set(index, config.audioBuffer);
|
|
210
|
-
return next;
|
|
211
|
-
});
|
|
212
|
-
setLoadedCount((prev) => prev + 1);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
return buildTrackFromConfig(
|
|
216
|
-
config,
|
|
217
|
-
index,
|
|
218
|
-
config.audioBuffer,
|
|
219
|
-
stableIdsRef.current,
|
|
220
|
-
audioContext.sampleRate
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
if (!config.src && config.waveformData) {
|
|
224
|
-
if (isImmediate && !cancelled) {
|
|
225
|
-
setLoadedCount((prev) => prev + 1);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
return buildTrackFromConfig(
|
|
229
|
-
config,
|
|
230
|
-
index,
|
|
231
|
-
void 0,
|
|
232
|
-
stableIdsRef.current,
|
|
233
|
-
audioContext.sampleRate
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
if (!config.src) {
|
|
237
|
-
throw new Error(`Track ${index + 1}: Must provide src, audioBuffer, or waveformData`);
|
|
238
|
-
}
|
|
239
|
-
const response = yield fetch(config.src, { signal: abortController.signal });
|
|
240
|
-
if (!response.ok) {
|
|
241
|
-
throw new Error(`Failed to fetch ${config.src}: ${response.statusText}`);
|
|
242
|
-
}
|
|
243
|
-
const arrayBuffer = yield response.arrayBuffer();
|
|
244
|
-
const audioBuffer = yield audioContext.decodeAudioData(arrayBuffer);
|
|
245
|
-
if (!audioBuffer || !audioBuffer.sampleRate || !audioBuffer.duration) {
|
|
246
|
-
throw new Error(`Invalid audio buffer for ${config.src}`);
|
|
247
|
-
}
|
|
248
|
-
if (isImmediate && !cancelled) {
|
|
249
|
-
setLoadedBuffers((prev) => {
|
|
250
|
-
const next = new Map(prev);
|
|
251
|
-
next.set(index, audioBuffer);
|
|
252
|
-
return next;
|
|
253
|
-
});
|
|
254
|
-
setLoadedCount((prev) => prev + 1);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
return buildTrackFromConfig(
|
|
258
|
-
config,
|
|
259
|
-
index,
|
|
260
|
-
audioBuffer,
|
|
261
|
-
stableIdsRef.current,
|
|
262
|
-
audioContext.sampleRate
|
|
263
|
-
);
|
|
264
|
-
}));
|
|
265
|
-
const loadedTracks = yield Promise.all(loadPromises);
|
|
266
|
-
if (!cancelled) {
|
|
267
|
-
if (!isImmediate) {
|
|
268
|
-
const validTracks = loadedTracks.filter((t) => t != null);
|
|
269
|
-
setTracks(validTracks);
|
|
270
|
-
setLoadedCount(validTracks.length);
|
|
271
|
-
}
|
|
272
|
-
setLoading(false);
|
|
273
|
-
}
|
|
274
|
-
} catch (err) {
|
|
275
|
-
if (!cancelled) {
|
|
276
|
-
const errorMessage = err instanceof Error ? err.message : "Unknown error loading audio";
|
|
277
|
-
setError(errorMessage);
|
|
278
|
-
setLoading(false);
|
|
279
|
-
console.error(`[waveform-playlist] Error loading audio tracks: ${errorMessage}`);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
loadTracks();
|
|
284
|
-
return () => {
|
|
285
|
-
cancelled = true;
|
|
286
|
-
abortController.abort();
|
|
287
|
-
};
|
|
288
|
-
}, [configs, isImmediate]);
|
|
289
|
-
return { tracks, loading, error, loadedCount, totalCount };
|
|
290
|
-
}
|
|
291
|
-
|
|
292
91
|
// src/hooks/useAudioEffects.ts
|
|
293
|
-
var
|
|
92
|
+
var import_react = require("react");
|
|
294
93
|
var import_tone = require("tone");
|
|
295
94
|
var useMasterAnalyser = (fftSize = 256) => {
|
|
296
|
-
const analyserRef = (0,
|
|
297
|
-
const masterEffects = (0,
|
|
95
|
+
const analyserRef = (0, import_react.useRef)(null);
|
|
96
|
+
const masterEffects = (0, import_react.useCallback)(
|
|
298
97
|
(masterGainNode, destination, _isOffline) => {
|
|
299
98
|
const analyserNode = new import_tone.Analyser("fft", fftSize);
|
|
300
99
|
masterGainNode.connect(analyserNode);
|
|
@@ -311,8 +110,13 @@ var useMasterAnalyser = (fftSize = 256) => {
|
|
|
311
110
|
};
|
|
312
111
|
|
|
313
112
|
// src/hooks/useDynamicEffects.ts
|
|
314
|
-
var
|
|
113
|
+
var import_react2 = require("react");
|
|
114
|
+
var import_tone7 = require("tone");
|
|
115
|
+
|
|
116
|
+
// src/effects/customEffectFactory.ts
|
|
117
|
+
var import_tone2 = require("tone");
|
|
315
118
|
var import_playout = require("@waveform-playlist/playout");
|
|
119
|
+
var import_core = require("@waveform-playlist/core");
|
|
316
120
|
|
|
317
121
|
// src/effects/effectDefinitions.ts
|
|
318
122
|
var effectDefinitions = [
|
|
@@ -860,32 +664,136 @@ var effectCategories = [
|
|
|
860
664
|
{ id: "spatial", name: "Spatial" }
|
|
861
665
|
];
|
|
862
666
|
|
|
667
|
+
// src/effects/customEffectFactory.ts
|
|
668
|
+
var converted = /* @__PURE__ */ new WeakMap();
|
|
669
|
+
function toEffectDefinition(type, definition) {
|
|
670
|
+
var _a;
|
|
671
|
+
const byType = (_a = converted.get(definition)) != null ? _a : /* @__PURE__ */ new Map();
|
|
672
|
+
converted.set(definition, byType);
|
|
673
|
+
const existing = byType.get(type);
|
|
674
|
+
if (existing) return existing;
|
|
675
|
+
const parameters = Object.entries(definition.params).map(([name, param]) => {
|
|
676
|
+
var _a2, _b;
|
|
677
|
+
return __spreadProps(__spreadValues(__spreadValues({
|
|
678
|
+
name,
|
|
679
|
+
label: (_a2 = param.label) != null ? _a2 : name,
|
|
680
|
+
type: "number",
|
|
681
|
+
min: param.min,
|
|
682
|
+
max: param.max
|
|
683
|
+
}, param.step !== void 0 ? { step: param.step } : {}), param.unit !== void 0 ? { unit: param.unit } : {}), {
|
|
684
|
+
default: (_b = definition.defaults[name]) != null ? _b : param.min
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
const result = {
|
|
688
|
+
id: type,
|
|
689
|
+
name: definition.label,
|
|
690
|
+
category: definition.category,
|
|
691
|
+
description: "",
|
|
692
|
+
parameters
|
|
693
|
+
};
|
|
694
|
+
byType.set(type, result);
|
|
695
|
+
return result;
|
|
696
|
+
}
|
|
697
|
+
var availableCache = null;
|
|
698
|
+
function getAvailableEffects() {
|
|
699
|
+
if (!(0, import_playout.isNativeGlobalContext)()) return effectDefinitions;
|
|
700
|
+
const custom = [];
|
|
701
|
+
(0, import_core.getEffectDefinitions)().forEach((definition, type) => {
|
|
702
|
+
if (definition.builtIn || getEffectDefinition(type)) return;
|
|
703
|
+
custom.push(toEffectDefinition(type, definition));
|
|
704
|
+
});
|
|
705
|
+
if (custom.length === 0) return effectDefinitions;
|
|
706
|
+
const cached = availableCache;
|
|
707
|
+
if (cached && cached.custom.length === custom.length && cached.custom.every((definition, i) => definition === custom[i])) {
|
|
708
|
+
return cached.list;
|
|
709
|
+
}
|
|
710
|
+
const list = [...effectDefinitions, ...custom];
|
|
711
|
+
availableCache = { custom, list };
|
|
712
|
+
return list;
|
|
713
|
+
}
|
|
714
|
+
function numericParams(params) {
|
|
715
|
+
const result = {};
|
|
716
|
+
for (const [name, value] of Object.entries(params)) {
|
|
717
|
+
if (typeof value === "number") result[name] = value;
|
|
718
|
+
}
|
|
719
|
+
return result;
|
|
720
|
+
}
|
|
721
|
+
var customInstanceCounter = 0;
|
|
722
|
+
function createCustomEffectInstance(type, audioContext, params = {}) {
|
|
723
|
+
const created = (0, import_core.createEffectInstance)(type, audioContext, numericParams(params));
|
|
724
|
+
const native = created.instance;
|
|
725
|
+
const current = __spreadValues({}, created.params);
|
|
726
|
+
const instanceId = "custom_" + ++customInstanceCounter;
|
|
727
|
+
const disconnectOutput = () => {
|
|
728
|
+
try {
|
|
729
|
+
(0, import_tone2.disconnect)(native.output);
|
|
730
|
+
} catch (err) {
|
|
731
|
+
console.warn(
|
|
732
|
+
'[waveform-playlist] Error disconnecting effect "' + type + '" (' + instanceId + "): " + (err instanceof Error ? err.message : String(err))
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
return {
|
|
737
|
+
kind: "custom",
|
|
738
|
+
native,
|
|
739
|
+
input: native.input,
|
|
740
|
+
output: native.output,
|
|
741
|
+
id: type,
|
|
742
|
+
instanceId,
|
|
743
|
+
dispose: () => {
|
|
744
|
+
var _a;
|
|
745
|
+
disconnectOutput();
|
|
746
|
+
try {
|
|
747
|
+
(_a = native.dispose) == null ? void 0 : _a.call(native);
|
|
748
|
+
} catch (err) {
|
|
749
|
+
console.warn(
|
|
750
|
+
'[waveform-playlist] Error disposing effect "' + type + '" (' + instanceId + "): " + (err instanceof Error ? err.message : String(err))
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
setParameter: (name, value) => {
|
|
755
|
+
if (typeof value !== "number") return;
|
|
756
|
+
current[name] = value;
|
|
757
|
+
native.applyParams({ [name]: value });
|
|
758
|
+
},
|
|
759
|
+
getParameter: (name) => current[name],
|
|
760
|
+
connect: (destination) => (0, import_tone2.connect)(native.output, destination),
|
|
761
|
+
disconnect: disconnectOutput
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/effects/effectsRack.ts
|
|
766
|
+
var import_tone6 = require("tone");
|
|
767
|
+
var import_playout3 = require("@waveform-playlist/playout");
|
|
768
|
+
var import_core3 = require("@waveform-playlist/core");
|
|
769
|
+
|
|
863
770
|
// src/effects/effectFactory.ts
|
|
864
|
-
var
|
|
771
|
+
var import_tone3 = require("tone");
|
|
772
|
+
var import_playout2 = require("@waveform-playlist/playout");
|
|
865
773
|
function asEffectConstructor(ctor) {
|
|
866
774
|
return ctor;
|
|
867
775
|
}
|
|
868
776
|
var effectConstructors = {
|
|
869
|
-
reverb: asEffectConstructor(
|
|
870
|
-
freeverb: asEffectConstructor(
|
|
871
|
-
jcReverb: asEffectConstructor(
|
|
872
|
-
feedbackDelay: asEffectConstructor(
|
|
873
|
-
pingPongDelay: asEffectConstructor(
|
|
874
|
-
chorus: asEffectConstructor(
|
|
875
|
-
phaser: asEffectConstructor(
|
|
876
|
-
tremolo: asEffectConstructor(
|
|
877
|
-
vibrato: asEffectConstructor(
|
|
878
|
-
autoPanner: asEffectConstructor(
|
|
879
|
-
autoFilter: asEffectConstructor(
|
|
880
|
-
autoWah: asEffectConstructor(
|
|
881
|
-
eq3: asEffectConstructor(
|
|
882
|
-
distortion: asEffectConstructor(
|
|
883
|
-
bitCrusher: asEffectConstructor(
|
|
884
|
-
chebyshev: asEffectConstructor(
|
|
885
|
-
compressor: asEffectConstructor(
|
|
886
|
-
limiter: asEffectConstructor(
|
|
887
|
-
gate: asEffectConstructor(
|
|
888
|
-
stereoWidener: asEffectConstructor(
|
|
777
|
+
reverb: asEffectConstructor(import_tone3.Reverb),
|
|
778
|
+
freeverb: asEffectConstructor(import_tone3.Freeverb),
|
|
779
|
+
jcReverb: asEffectConstructor(import_tone3.JCReverb),
|
|
780
|
+
feedbackDelay: asEffectConstructor(import_tone3.FeedbackDelay),
|
|
781
|
+
pingPongDelay: asEffectConstructor(import_tone3.PingPongDelay),
|
|
782
|
+
chorus: asEffectConstructor(import_tone3.Chorus),
|
|
783
|
+
phaser: asEffectConstructor(import_tone3.Phaser),
|
|
784
|
+
tremolo: asEffectConstructor(import_tone3.Tremolo),
|
|
785
|
+
vibrato: asEffectConstructor(import_tone3.Vibrato),
|
|
786
|
+
autoPanner: asEffectConstructor(import_tone3.AutoPanner),
|
|
787
|
+
autoFilter: asEffectConstructor(import_tone3.AutoFilter),
|
|
788
|
+
autoWah: asEffectConstructor(import_tone3.AutoWah),
|
|
789
|
+
eq3: asEffectConstructor(import_tone3.EQ3),
|
|
790
|
+
distortion: asEffectConstructor(import_tone3.Distortion),
|
|
791
|
+
bitCrusher: asEffectConstructor(import_tone3.BitCrusher),
|
|
792
|
+
chebyshev: asEffectConstructor(import_tone3.Chebyshev),
|
|
793
|
+
compressor: asEffectConstructor(import_tone3.Compressor),
|
|
794
|
+
limiter: asEffectConstructor(import_tone3.Limiter),
|
|
795
|
+
gate: asEffectConstructor(import_tone3.Gate),
|
|
796
|
+
stereoWidener: asEffectConstructor(import_tone3.StereoWidener)
|
|
889
797
|
};
|
|
890
798
|
var instanceCounter = 0;
|
|
891
799
|
var generateInstanceId = () => {
|
|
@@ -902,11 +810,13 @@ function createEffectInstance(definition, initialParams) {
|
|
|
902
810
|
const value = (_a = initialParams == null ? void 0 : initialParams[param.name]) != null ? _a : param.default;
|
|
903
811
|
options[param.name] = value;
|
|
904
812
|
});
|
|
813
|
+
(0, import_playout2.getGlobalContext)();
|
|
905
814
|
const effect = new Constructor(options);
|
|
906
815
|
const instanceId = generateInstanceId();
|
|
907
816
|
const effectRecord = effect;
|
|
908
817
|
return {
|
|
909
|
-
effect,
|
|
818
|
+
input: effect,
|
|
819
|
+
output: effect,
|
|
910
820
|
id: definition.id,
|
|
911
821
|
instanceId,
|
|
912
822
|
dispose() {
|
|
@@ -971,11 +881,11 @@ function createEffectChain(effects) {
|
|
|
971
881
|
throw new Error("Cannot create effect chain with no effects");
|
|
972
882
|
}
|
|
973
883
|
for (let i = 0; i < effects.length - 1; i++) {
|
|
974
|
-
(0,
|
|
884
|
+
(0, import_tone3.connect)(effects[i].output, effects[i + 1].input);
|
|
975
885
|
}
|
|
976
886
|
return {
|
|
977
|
-
input: effects[0].
|
|
978
|
-
output: effects[effects.length - 1].
|
|
887
|
+
input: effects[0].input,
|
|
888
|
+
output: effects[effects.length - 1].output,
|
|
979
889
|
dispose() {
|
|
980
890
|
effects.forEach((e) => e.dispose());
|
|
981
891
|
}
|
|
@@ -997,7 +907,7 @@ function loadWamModule() {
|
|
|
997
907
|
}
|
|
998
908
|
|
|
999
909
|
// src/effects/wamEffectFactory.ts
|
|
1000
|
-
var
|
|
910
|
+
var import_tone4 = require("tone");
|
|
1001
911
|
var wamInstanceCounter = 0;
|
|
1002
912
|
function createWamEffectInstance(plugin) {
|
|
1003
913
|
var _a, _b, _c;
|
|
@@ -1007,7 +917,8 @@ function createWamEffectInstance(plugin) {
|
|
|
1007
917
|
kind: "wam",
|
|
1008
918
|
plugin,
|
|
1009
919
|
url: plugin.url,
|
|
1010
|
-
|
|
920
|
+
input: node,
|
|
921
|
+
output: node,
|
|
1011
922
|
id: "wam:" + ((_c = (_b = (_a = plugin.descriptor) == null ? void 0 : _a.name) != null ? _b : plugin.url) != null ? _c : "plugin"),
|
|
1012
923
|
instanceId,
|
|
1013
924
|
dispose: () => {
|
|
@@ -1027,13 +938,14 @@ function createWamEffectInstance(plugin) {
|
|
|
1027
938
|
},
|
|
1028
939
|
getParameter: () => void 0,
|
|
1029
940
|
// WAM params are async; read via the plugin GUI
|
|
1030
|
-
connect: (destination) => (0,
|
|
1031
|
-
disconnect: () => (0,
|
|
941
|
+
connect: (destination) => (0, import_tone4.connect)(node, destination),
|
|
942
|
+
disconnect: () => (0, import_tone4.disconnect)(node)
|
|
1032
943
|
};
|
|
1033
944
|
}
|
|
1034
945
|
|
|
1035
946
|
// src/effects/offlineChain.ts
|
|
1036
|
-
var
|
|
947
|
+
var import_tone5 = require("tone");
|
|
948
|
+
var import_core2 = require("@waveform-playlist/core");
|
|
1037
949
|
function buildOfflineChain(entries, getLivePlugin, rawContext) {
|
|
1038
950
|
return __async(this, null, function* () {
|
|
1039
951
|
const instances = [];
|
|
@@ -1042,10 +954,15 @@ function buildOfflineChain(entries, getLivePlugin, rawContext) {
|
|
|
1042
954
|
};
|
|
1043
955
|
try {
|
|
1044
956
|
for (const entry of entries) {
|
|
1045
|
-
if (entry.kind === "
|
|
957
|
+
if (entry.kind === "tone") {
|
|
1046
958
|
instances.push(createEffectInstance(entry.definition, entry.params));
|
|
1047
959
|
continue;
|
|
1048
960
|
}
|
|
961
|
+
if (entry.kind === "custom") {
|
|
962
|
+
yield (0, import_core2.ensureEffectPrepared)(entry.definition.id, rawContext);
|
|
963
|
+
instances.push(createCustomEffectInstance(entry.definition.id, rawContext, entry.params));
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
1049
966
|
const livePlugin = getLivePlugin(entry.instanceId);
|
|
1050
967
|
if (!livePlugin) {
|
|
1051
968
|
throw new Error(
|
|
@@ -1067,597 +984,484 @@ function buildOfflineChain(entries, getLivePlugin, rawContext) {
|
|
|
1067
984
|
function connectOfflineChain(from, instances, to) {
|
|
1068
985
|
let current = from;
|
|
1069
986
|
for (const inst of instances) {
|
|
1070
|
-
(0,
|
|
1071
|
-
current = inst.
|
|
987
|
+
(0, import_tone5.connect)(current, inst.input);
|
|
988
|
+
current = inst.output;
|
|
1072
989
|
}
|
|
1073
|
-
(0,
|
|
990
|
+
(0, import_tone5.connect)(current, to);
|
|
1074
991
|
}
|
|
1075
992
|
|
|
1076
|
-
// src/
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
const params = {};
|
|
1122
|
-
definition.parameters.forEach((p) => {
|
|
1123
|
-
params[p.name] = p.default;
|
|
1124
|
-
});
|
|
1125
|
-
const instance = createEffectInstance(definition, params);
|
|
1126
|
-
effectInstancesRef.current.set(instance.instanceId, instance);
|
|
1127
|
-
const newActiveEffect = {
|
|
1128
|
-
instanceId: instance.instanceId,
|
|
1129
|
-
effectId: definition.id,
|
|
1130
|
-
kind: "native",
|
|
1131
|
-
definition,
|
|
1132
|
-
params,
|
|
1133
|
-
bypassed: false
|
|
1134
|
-
};
|
|
1135
|
-
setActiveEffects((prev) => [...prev, newActiveEffect]);
|
|
1136
|
-
}, []);
|
|
1137
|
-
const addWamEffect = (0, import_react3.useCallback)((url, initialState) => __async(null, null, function* () {
|
|
1138
|
-
var _a, _b;
|
|
1139
|
-
if (!(0, import_playout.isNativeGlobalContext)()) {
|
|
1140
|
-
throw new Error(
|
|
1141
|
-
"[waveform-playlist] WAM plugins require a native AudioContext. Call configureGlobalContext({ nativeAudioContext: true }) from @waveform-playlist/playout before any audio initialization."
|
|
1142
|
-
);
|
|
1143
|
-
}
|
|
1144
|
-
const wam = yield loadWamModule();
|
|
1145
|
-
const ctx = (0, import_playout.getGlobalAudioContext)();
|
|
1146
|
-
const { hostGroupId } = yield wam.ensureWamHost(ctx);
|
|
1147
|
-
const plugin = yield wam.createWamInstance(
|
|
1148
|
-
url,
|
|
1149
|
-
ctx,
|
|
1150
|
-
hostGroupId,
|
|
1151
|
-
initialState !== void 0 ? { initialState } : void 0
|
|
1152
|
-
);
|
|
1153
|
-
if (!isMountedRef.current) {
|
|
993
|
+
// src/effects/chainTopology.ts
|
|
994
|
+
function isDisconnectBypassed(effect) {
|
|
995
|
+
return effect.bypassed && effect.wetParam === void 0;
|
|
996
|
+
}
|
|
997
|
+
function chainTopologyKey(effects) {
|
|
998
|
+
return effects.filter((effect) => !isDisconnectBypassed(effect)).map((effect) => effect.instanceId).join("|");
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// src/effects/effectsRack.ts
|
|
1002
|
+
var NATIVE_CONTEXT_HINT = "Call configureGlobalContext({ nativeAudioContext: true }) from @waveform-playlist/playout before any audio initialization.";
|
|
1003
|
+
var NO_EFFECTS = [];
|
|
1004
|
+
var UNWIRED = "\0unwired";
|
|
1005
|
+
function message(err) {
|
|
1006
|
+
return err instanceof Error ? err.message : String(err);
|
|
1007
|
+
}
|
|
1008
|
+
var collectedRacks;
|
|
1009
|
+
function disposeWhenCollected(rack, instances) {
|
|
1010
|
+
if (collectedRacks === void 0) {
|
|
1011
|
+
const Registry = globalThis.FinalizationRegistry;
|
|
1012
|
+
collectedRacks = Registry ? new Registry((orphaned) => {
|
|
1013
|
+
orphaned.forEach((instance) => instance.dispose());
|
|
1014
|
+
orphaned.clear();
|
|
1015
|
+
}) : null;
|
|
1016
|
+
}
|
|
1017
|
+
collectedRacks == null ? void 0 : collectedRacks.register(rack, instances);
|
|
1018
|
+
}
|
|
1019
|
+
var EffectsRack = class {
|
|
1020
|
+
constructor() {
|
|
1021
|
+
this.handle = (0, import_core3.createValueSource)(NO_EFFECTS);
|
|
1022
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
1023
|
+
this.attachment = null;
|
|
1024
|
+
this.wiredKey = "";
|
|
1025
|
+
/** Bumped by clear(): an add that was awaiting across it is dropped. */
|
|
1026
|
+
this.generation = 0;
|
|
1027
|
+
/**
|
|
1028
|
+
* Put the chain between two nodes of the live graph. Returns the function
|
|
1029
|
+
* that detaches it from `to`, for when that part of the graph is disposed.
|
|
1030
|
+
* A second attach replaces the first; the first one's detach then only
|
|
1031
|
+
* removes its own edges.
|
|
1032
|
+
*/
|
|
1033
|
+
this.attach = (from, to) => {
|
|
1034
|
+
const previous = this.attachment;
|
|
1035
|
+
this.attachment = { from, to };
|
|
1154
1036
|
try {
|
|
1155
|
-
|
|
1037
|
+
this.wire(this.list(), false);
|
|
1156
1038
|
} catch (err) {
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1039
|
+
this.attachment = previous;
|
|
1040
|
+
this.wiredKey = UNWIRED;
|
|
1041
|
+
throw err;
|
|
1160
1042
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1043
|
+
return () => {
|
|
1044
|
+
var _a;
|
|
1045
|
+
this.instances.forEach((instance) => {
|
|
1046
|
+
try {
|
|
1047
|
+
(0, import_tone6.disconnect)(instance.output, to);
|
|
1048
|
+
} catch (e) {
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
if (((_a = this.attachment) == null ? void 0 : _a.to) === to) {
|
|
1052
|
+
this.attachment = null;
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1173
1055
|
};
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1056
|
+
/**
|
|
1057
|
+
* Add a built-in effect, or a type registered with `registerEffect()`, by
|
|
1058
|
+
* id. A built-in is in the list before this returns; a registered type is
|
|
1059
|
+
* added once its `prepare` hook has run on the live context. Resolves with
|
|
1060
|
+
* the new entry's instanceId; rejects for an unknown id.
|
|
1061
|
+
*/
|
|
1062
|
+
this.add = (effectId) => __async(this, null, function* () {
|
|
1063
|
+
const builtIn = getEffectDefinition(effectId);
|
|
1064
|
+
if (builtIn) {
|
|
1065
|
+
const params = {};
|
|
1066
|
+
builtIn.parameters.forEach((parameter) => {
|
|
1067
|
+
params[parameter.name] = parameter.default;
|
|
1068
|
+
});
|
|
1069
|
+
const instance2 = createEffectInstance(builtIn, params);
|
|
1070
|
+
return this.append(instance2, __spreadValues({
|
|
1071
|
+
effectId,
|
|
1072
|
+
kind: "tone",
|
|
1073
|
+
definition: builtIn,
|
|
1074
|
+
params,
|
|
1075
|
+
bypassed: false
|
|
1076
|
+
}, instance2.getParameter("wet") !== void 0 ? { wetParam: "wet" } : {}));
|
|
1184
1077
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
return (inst == null ? void 0 : inst.kind) === "wam" ? inst.plugin : void 0;
|
|
1191
|
-
}, []);
|
|
1192
|
-
const removeEffect = (0, import_react3.useCallback)((instanceId) => {
|
|
1193
|
-
const instance = effectInstancesRef.current.get(instanceId);
|
|
1194
|
-
if (instance) {
|
|
1195
|
-
instance.dispose();
|
|
1196
|
-
effectInstancesRef.current.delete(instanceId);
|
|
1197
|
-
}
|
|
1198
|
-
setActiveEffects((prev) => prev.filter((e) => e.instanceId !== instanceId));
|
|
1199
|
-
}, []);
|
|
1200
|
-
const updateParameter = (0, import_react3.useCallback)(
|
|
1201
|
-
(instanceId, paramName, value) => {
|
|
1202
|
-
const instance = effectInstancesRef.current.get(instanceId);
|
|
1203
|
-
if (instance) {
|
|
1204
|
-
instance.setParameter(paramName, value);
|
|
1078
|
+
const registered = (0, import_core3.getEffectDefinitions)().get(effectId);
|
|
1079
|
+
if (!registered) {
|
|
1080
|
+
throw new Error(
|
|
1081
|
+
'[waveform-playlist] Unknown effect "' + effectId + '". It is neither a built-in effect nor a type registered with registerEffect() from @waveform-playlist/core.'
|
|
1082
|
+
);
|
|
1205
1083
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
)
|
|
1210
|
-
);
|
|
1211
|
-
},
|
|
1212
|
-
[]
|
|
1213
|
-
);
|
|
1214
|
-
const toggleBypass = (0, import_react3.useCallback)((instanceId) => {
|
|
1215
|
-
var _a;
|
|
1216
|
-
const effect = activeEffectsRef.current.find((e) => e.instanceId === instanceId);
|
|
1217
|
-
if (!effect) return;
|
|
1218
|
-
const newBypassed = !effect.bypassed;
|
|
1219
|
-
if (effect.kind === "wam") {
|
|
1220
|
-
setActiveEffects(
|
|
1221
|
-
(prev) => prev.map((e) => e.instanceId === instanceId ? __spreadProps(__spreadValues({}, e), { bypassed: newBypassed }) : e)
|
|
1222
|
-
);
|
|
1223
|
-
return;
|
|
1224
|
-
}
|
|
1225
|
-
const instance = effectInstancesRef.current.get(instanceId);
|
|
1226
|
-
if (instance) {
|
|
1227
|
-
const originalWet = (_a = effect.params.wet) != null ? _a : 1;
|
|
1228
|
-
instance.setParameter("wet", newBypassed ? 0 : originalWet);
|
|
1229
|
-
}
|
|
1230
|
-
setActiveEffects(
|
|
1231
|
-
(prev) => prev.map((e) => e.instanceId === instanceId ? __spreadProps(__spreadValues({}, e), { bypassed: newBypassed }) : e)
|
|
1232
|
-
);
|
|
1233
|
-
}, []);
|
|
1234
|
-
const reorderEffects = (0, import_react3.useCallback)((fromIndex, toIndex) => {
|
|
1235
|
-
setActiveEffects((prev) => {
|
|
1236
|
-
const newEffects = [...prev];
|
|
1237
|
-
const [removed] = newEffects.splice(fromIndex, 1);
|
|
1238
|
-
newEffects.splice(toIndex, 0, removed);
|
|
1239
|
-
return newEffects;
|
|
1240
|
-
});
|
|
1241
|
-
}, []);
|
|
1242
|
-
const clearAllEffects = (0, import_react3.useCallback)(() => {
|
|
1243
|
-
effectInstancesRef.current.forEach((inst) => inst.dispose());
|
|
1244
|
-
effectInstancesRef.current.clear();
|
|
1245
|
-
setActiveEffects([]);
|
|
1246
|
-
}, []);
|
|
1247
|
-
(0, import_react3.useEffect)(() => {
|
|
1248
|
-
rebuildChain(activeEffects);
|
|
1249
|
-
}, [activeEffects, rebuildChain]);
|
|
1250
|
-
const masterEffects = (0, import_react3.useCallback)(
|
|
1251
|
-
(masterGainNode, destination, _isOffline) => {
|
|
1252
|
-
const analyserNode = new import_tone5.Analyser("fft", fftSize);
|
|
1253
|
-
analyserRef.current = analyserNode;
|
|
1254
|
-
graphNodesRef.current = {
|
|
1255
|
-
masterGainNode,
|
|
1256
|
-
destination,
|
|
1257
|
-
analyserNode
|
|
1258
|
-
};
|
|
1259
|
-
const effects = activeEffectsRef.current;
|
|
1260
|
-
const audible = effects.filter((ae) => !(ae.kind === "wam" && ae.bypassed));
|
|
1261
|
-
const instances = audible.map((ae) => effectInstancesRef.current.get(ae.instanceId)).filter((inst) => inst !== void 0);
|
|
1262
|
-
if (instances.length === 0) {
|
|
1263
|
-
masterGainNode.connect(analyserNode);
|
|
1264
|
-
analyserNode.connect(destination);
|
|
1265
|
-
} else {
|
|
1266
|
-
let currentNode = masterGainNode;
|
|
1267
|
-
instances.forEach((inst) => {
|
|
1268
|
-
(0, import_tone5.connect)(currentNode, inst.effect);
|
|
1269
|
-
currentNode = inst.effect;
|
|
1270
|
-
});
|
|
1271
|
-
(0, import_tone5.connect)(currentNode, analyserNode);
|
|
1272
|
-
analyserNode.connect(destination);
|
|
1084
|
+
if (!(0, import_playout3.isNativeGlobalContext)()) {
|
|
1085
|
+
throw new Error(
|
|
1086
|
+
"[waveform-playlist] Custom effects require a native AudioContext. " + NATIVE_CONTEXT_HINT
|
|
1087
|
+
);
|
|
1273
1088
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
};
|
|
1279
|
-
},
|
|
1280
|
-
[fftSize]
|
|
1281
|
-
// Only fftSize - reads effects from ref
|
|
1282
|
-
);
|
|
1283
|
-
(0, import_react3.useEffect)(() => {
|
|
1284
|
-
isMountedRef.current = true;
|
|
1285
|
-
const effectInstances = effectInstancesRef.current;
|
|
1286
|
-
return () => {
|
|
1287
|
-
isMountedRef.current = false;
|
|
1288
|
-
effectInstances.forEach((inst) => inst.dispose());
|
|
1289
|
-
effectInstances.clear();
|
|
1290
|
-
};
|
|
1291
|
-
}, []);
|
|
1292
|
-
const createOfflineEffectsFunction = (0, import_react3.useCallback)(() => {
|
|
1293
|
-
const nonBypassed = activeEffects.filter((e) => !e.bypassed);
|
|
1294
|
-
if (nonBypassed.length === 0) {
|
|
1295
|
-
return void 0;
|
|
1296
|
-
}
|
|
1297
|
-
const hasWam = nonBypassed.some((e) => e.kind === "wam");
|
|
1298
|
-
return (masterGainNode, destination, _isOffline) => __async(null, null, function* () {
|
|
1299
|
-
if (hasWam && !(0, import_playout.isNativeGlobalContext)()) {
|
|
1089
|
+
const audioContext = (0, import_playout3.getGlobalAudioContext)();
|
|
1090
|
+
const generation = this.generation;
|
|
1091
|
+
yield (0, import_core3.ensureEffectPrepared)(effectId, audioContext);
|
|
1092
|
+
if (generation !== this.generation) {
|
|
1300
1093
|
throw new Error(
|
|
1301
|
-
|
|
1094
|
+
'[waveform-playlist] addEffect("' + effectId + '") aborted: the effects chain was cleared before the effect was ready.'
|
|
1302
1095
|
);
|
|
1303
1096
|
}
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
activeEffects,
|
|
1319
|
-
availableEffects: effectDefinitions,
|
|
1320
|
-
addEffect,
|
|
1321
|
-
addWamEffect,
|
|
1322
|
-
getWamPlugin,
|
|
1323
|
-
removeEffect,
|
|
1324
|
-
updateParameter,
|
|
1325
|
-
toggleBypass,
|
|
1326
|
-
reorderEffects,
|
|
1327
|
-
clearAllEffects,
|
|
1328
|
-
masterEffects,
|
|
1329
|
-
createOfflineEffectsFunction,
|
|
1330
|
-
analyserRef
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
// src/hooks/useTrackDynamicEffects.ts
|
|
1335
|
-
var import_react4 = require("react");
|
|
1336
|
-
var import_playout2 = require("@waveform-playlist/playout");
|
|
1337
|
-
var import_tone6 = require("tone");
|
|
1338
|
-
function useTrackDynamicEffects() {
|
|
1339
|
-
const [trackEffectsState, setTrackEffectsState] = (0, import_react4.useState)(
|
|
1340
|
-
/* @__PURE__ */ new Map()
|
|
1341
|
-
);
|
|
1342
|
-
const trackEffectInstancesRef = (0, import_react4.useRef)(/* @__PURE__ */ new Map());
|
|
1343
|
-
const isMountedRef = (0, import_react4.useRef)(true);
|
|
1344
|
-
const trackGraphNodesRef = (0, import_react4.useRef)(/* @__PURE__ */ new Map());
|
|
1345
|
-
const rebuildTrackChain = (0, import_react4.useCallback)((trackId, trackEffects) => {
|
|
1346
|
-
const nodes = trackGraphNodesRef.current.get(trackId);
|
|
1347
|
-
if (!nodes) return;
|
|
1348
|
-
const { graphEnd, masterGainNode } = nodes;
|
|
1349
|
-
const instancesMap = trackEffectInstancesRef.current.get(trackId);
|
|
1350
|
-
try {
|
|
1351
|
-
graphEnd.disconnect();
|
|
1352
|
-
} catch (e) {
|
|
1353
|
-
console.warn(`[waveform-playlist] Error disconnecting track "${trackId}" effect chain:`, e);
|
|
1354
|
-
}
|
|
1355
|
-
const audible = trackEffects.filter((ae) => !(ae.kind === "wam" && ae.bypassed));
|
|
1356
|
-
const instances = audible.map((ae) => instancesMap == null ? void 0 : instancesMap.get(ae.instanceId)).filter((inst) => inst !== void 0);
|
|
1357
|
-
if (instances.length === 0) {
|
|
1358
|
-
graphEnd.connect(masterGainNode);
|
|
1359
|
-
} else {
|
|
1360
|
-
let currentNode = graphEnd;
|
|
1361
|
-
instances.forEach((inst) => {
|
|
1362
|
-
try {
|
|
1363
|
-
inst.disconnect();
|
|
1364
|
-
} catch (e) {
|
|
1365
|
-
console.warn(
|
|
1366
|
-
`[waveform-playlist] Error disconnecting effect "${inst.id}" on track "${trackId}":`,
|
|
1367
|
-
e
|
|
1368
|
-
);
|
|
1369
|
-
}
|
|
1370
|
-
(0, import_tone6.connect)(currentNode, inst.effect);
|
|
1371
|
-
currentNode = inst.effect;
|
|
1372
|
-
});
|
|
1373
|
-
(0, import_tone6.connect)(currentNode, masterGainNode);
|
|
1374
|
-
}
|
|
1375
|
-
}, []);
|
|
1376
|
-
const addEffectToTrack = (0, import_react4.useCallback)((trackId, effectId) => {
|
|
1377
|
-
const definition = getEffectDefinition(effectId);
|
|
1378
|
-
if (!definition) {
|
|
1379
|
-
console.error(`Unknown effect: ${effectId}`);
|
|
1380
|
-
return;
|
|
1381
|
-
}
|
|
1382
|
-
const params = {};
|
|
1383
|
-
definition.parameters.forEach((p) => {
|
|
1384
|
-
params[p.name] = p.default;
|
|
1385
|
-
});
|
|
1386
|
-
const instance = createEffectInstance(definition, params);
|
|
1387
|
-
if (!trackEffectInstancesRef.current.has(trackId)) {
|
|
1388
|
-
trackEffectInstancesRef.current.set(trackId, /* @__PURE__ */ new Map());
|
|
1389
|
-
}
|
|
1390
|
-
trackEffectInstancesRef.current.get(trackId).set(instance.instanceId, instance);
|
|
1391
|
-
const newActiveEffect = {
|
|
1392
|
-
instanceId: instance.instanceId,
|
|
1393
|
-
effectId: definition.id,
|
|
1394
|
-
kind: "native",
|
|
1395
|
-
definition,
|
|
1396
|
-
params,
|
|
1397
|
-
bypassed: false
|
|
1398
|
-
};
|
|
1399
|
-
setTrackEffectsState((prev) => {
|
|
1400
|
-
const newState = new Map(prev);
|
|
1401
|
-
const existing = newState.get(trackId) || [];
|
|
1402
|
-
newState.set(trackId, [...existing, newActiveEffect]);
|
|
1403
|
-
return newState;
|
|
1097
|
+
const definition = (0, import_core3.getEffectDefinitions)().get(effectId);
|
|
1098
|
+
if (!definition) {
|
|
1099
|
+
throw new Error(
|
|
1100
|
+
'[waveform-playlist] addEffect("' + effectId + '") aborted: the effect type was unregistered before the effect was ready.'
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
const instance = createCustomEffectInstance(effectId, audioContext, definition.defaults);
|
|
1104
|
+
return this.append(instance, __spreadValues({
|
|
1105
|
+
effectId,
|
|
1106
|
+
kind: "custom",
|
|
1107
|
+
definition: toEffectDefinition(effectId, definition),
|
|
1108
|
+
params: __spreadValues({}, definition.defaults),
|
|
1109
|
+
bypassed: false
|
|
1110
|
+
}, definition.wetParam !== void 0 ? { wetParam: definition.wetParam } : {}));
|
|
1404
1111
|
});
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
(trackId, url, initialState) => __async(null, null, function* () {
|
|
1112
|
+
/** Host a WAM plugin from a module URL and append it. Requires native-context mode. */
|
|
1113
|
+
this.addWam = (url, initialState) => __async(this, null, function* () {
|
|
1408
1114
|
var _a, _b;
|
|
1409
|
-
if (!(0,
|
|
1115
|
+
if (!(0, import_playout3.isNativeGlobalContext)()) {
|
|
1410
1116
|
throw new Error(
|
|
1411
|
-
"[waveform-playlist] WAM plugins require a native AudioContext.
|
|
1117
|
+
"[waveform-playlist] WAM plugins require a native AudioContext. " + NATIVE_CONTEXT_HINT
|
|
1412
1118
|
);
|
|
1413
1119
|
}
|
|
1120
|
+
const generation = this.generation;
|
|
1414
1121
|
const wam = yield loadWamModule();
|
|
1415
|
-
const
|
|
1416
|
-
const { hostGroupId } = yield wam.ensureWamHost(
|
|
1122
|
+
const audioContext = (0, import_playout3.getGlobalAudioContext)();
|
|
1123
|
+
const { hostGroupId } = yield wam.ensureWamHost(audioContext);
|
|
1417
1124
|
const plugin = yield wam.createWamInstance(
|
|
1418
1125
|
url,
|
|
1419
|
-
|
|
1126
|
+
audioContext,
|
|
1420
1127
|
hostGroupId,
|
|
1421
1128
|
initialState !== void 0 ? { initialState } : void 0
|
|
1422
1129
|
);
|
|
1423
|
-
if (
|
|
1130
|
+
if (generation !== this.generation) {
|
|
1424
1131
|
try {
|
|
1425
1132
|
plugin.destroy();
|
|
1426
1133
|
} catch (err) {
|
|
1427
1134
|
console.warn(
|
|
1428
|
-
"[waveform-playlist] Error destroying WAM plugin
|
|
1135
|
+
"[waveform-playlist] Error destroying a WAM plugin dropped by clear(): " + message(err)
|
|
1429
1136
|
);
|
|
1430
1137
|
}
|
|
1431
1138
|
throw new Error(
|
|
1432
|
-
"[waveform-playlist]
|
|
1139
|
+
"[waveform-playlist] addWamEffect aborted: the effects chain was cleared before the plugin finished loading."
|
|
1433
1140
|
);
|
|
1434
1141
|
}
|
|
1435
1142
|
const instance = createWamEffectInstance(plugin);
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
const existing = newState.get(trackId) || [];
|
|
1450
|
-
newState.set(trackId, [
|
|
1451
|
-
...existing,
|
|
1452
|
-
{
|
|
1453
|
-
instanceId: instance.instanceId,
|
|
1454
|
-
effectId: instance.id,
|
|
1455
|
-
kind: "wam",
|
|
1456
|
-
url,
|
|
1457
|
-
definition,
|
|
1458
|
-
params: {},
|
|
1459
|
-
bypassed: false
|
|
1460
|
-
}
|
|
1461
|
-
]);
|
|
1462
|
-
return newState;
|
|
1143
|
+
return this.append(instance, {
|
|
1144
|
+
effectId: instance.id,
|
|
1145
|
+
kind: "wam",
|
|
1146
|
+
url,
|
|
1147
|
+
definition: {
|
|
1148
|
+
id: instance.id,
|
|
1149
|
+
name: (_b = (_a = plugin.descriptor) == null ? void 0 : _a.name) != null ? _b : url,
|
|
1150
|
+
category: "wam",
|
|
1151
|
+
description: "WAM plugin",
|
|
1152
|
+
parameters: []
|
|
1153
|
+
},
|
|
1154
|
+
params: {},
|
|
1155
|
+
bypassed: false
|
|
1463
1156
|
});
|
|
1464
|
-
return instance.instanceId;
|
|
1465
|
-
}),
|
|
1466
|
-
[]
|
|
1467
|
-
);
|
|
1468
|
-
const getTrackWamPlugin = (0, import_react4.useCallback)(
|
|
1469
|
-
(trackId, instanceId) => {
|
|
1470
|
-
const instancesMap = trackEffectInstancesRef.current.get(trackId);
|
|
1471
|
-
const inst = instancesMap == null ? void 0 : instancesMap.get(instanceId);
|
|
1472
|
-
return (inst == null ? void 0 : inst.kind) === "wam" ? inst.plugin : void 0;
|
|
1473
|
-
},
|
|
1474
|
-
[]
|
|
1475
|
-
);
|
|
1476
|
-
const removeEffectFromTrack = (0, import_react4.useCallback)((trackId, instanceId) => {
|
|
1477
|
-
const instancesMap = trackEffectInstancesRef.current.get(trackId);
|
|
1478
|
-
const instance = instancesMap == null ? void 0 : instancesMap.get(instanceId);
|
|
1479
|
-
if (instance) {
|
|
1480
|
-
instance.dispose();
|
|
1481
|
-
instancesMap == null ? void 0 : instancesMap.delete(instanceId);
|
|
1482
|
-
}
|
|
1483
|
-
setTrackEffectsState((prev) => {
|
|
1484
|
-
const newState = new Map(prev);
|
|
1485
|
-
const existing = newState.get(trackId) || [];
|
|
1486
|
-
newState.set(
|
|
1487
|
-
trackId,
|
|
1488
|
-
existing.filter((e) => e.instanceId !== instanceId)
|
|
1489
|
-
);
|
|
1490
|
-
return newState;
|
|
1491
1157
|
});
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1158
|
+
/** Live plugin handle for a hosted WAM entry (for GUI mounting via WamEffectGui). */
|
|
1159
|
+
this.getWamPlugin = (instanceId) => {
|
|
1160
|
+
const instance = this.instances.get(instanceId);
|
|
1161
|
+
return (instance == null ? void 0 : instance.kind) === "wam" ? instance.plugin : void 0;
|
|
1162
|
+
};
|
|
1163
|
+
this.remove = (instanceId) => {
|
|
1164
|
+
const next = this.list().filter((effect) => effect.instanceId !== instanceId);
|
|
1165
|
+
if (next.length !== this.list().length) this.commit(next);
|
|
1166
|
+
const instance = this.instances.get(instanceId);
|
|
1497
1167
|
if (instance) {
|
|
1498
|
-
|
|
1168
|
+
this.instances.delete(instanceId);
|
|
1169
|
+
instance.dispose();
|
|
1499
1170
|
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
);
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1171
|
+
};
|
|
1172
|
+
/** Set a parameter on the live effect. Never rewires the chain. */
|
|
1173
|
+
this.updateParameter = (instanceId, name, value) => {
|
|
1174
|
+
var _a;
|
|
1175
|
+
const effect = this.list().find((entry) => entry.instanceId === instanceId);
|
|
1176
|
+
if (!effect) return;
|
|
1177
|
+
if (effect.kind === "custom" && typeof value !== "number") return;
|
|
1178
|
+
if (!(effect.bypassed && name === effect.wetParam)) {
|
|
1179
|
+
(_a = this.instances.get(instanceId)) == null ? void 0 : _a.setParameter(name, value);
|
|
1180
|
+
}
|
|
1181
|
+
this.commit(
|
|
1182
|
+
this.list().map(
|
|
1183
|
+
(entry) => entry.instanceId === instanceId ? __spreadProps(__spreadValues({}, entry), { params: __spreadProps(__spreadValues({}, entry.params), { [name]: value }) }) : entry
|
|
1184
|
+
)
|
|
1185
|
+
);
|
|
1186
|
+
};
|
|
1187
|
+
this.toggleBypass = (instanceId) => {
|
|
1188
|
+
var _a;
|
|
1189
|
+
const effect = this.list().find((entry) => entry.instanceId === instanceId);
|
|
1190
|
+
if (!effect) return;
|
|
1191
|
+
const bypassed = !effect.bypassed;
|
|
1192
|
+
if (effect.wetParam !== void 0) {
|
|
1193
|
+
const wet = effect.params[effect.wetParam];
|
|
1194
|
+
(_a = this.instances.get(instanceId)) == null ? void 0 : _a.setParameter(effect.wetParam, bypassed ? 0 : typeof wet === "number" ? wet : 1);
|
|
1195
|
+
}
|
|
1196
|
+
this.commit(
|
|
1197
|
+
this.list().map((entry) => entry.instanceId === instanceId ? __spreadProps(__spreadValues({}, entry), { bypassed }) : entry)
|
|
1198
|
+
);
|
|
1199
|
+
};
|
|
1200
|
+
this.reorder = (fromIndex, toIndex) => {
|
|
1201
|
+
const current = this.list();
|
|
1202
|
+
if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= current.length || toIndex < 0 || toIndex >= current.length) {
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
const next = [...current];
|
|
1206
|
+
const [moved] = next.splice(fromIndex, 1);
|
|
1207
|
+
next.splice(toIndex, 0, moved);
|
|
1208
|
+
this.commit(next);
|
|
1209
|
+
};
|
|
1210
|
+
/**
|
|
1211
|
+
* Remove and dispose every effect. An add that is still waiting (a
|
|
1212
|
+
* registered effect's `prepare`, a WAM plugin loading) is dropped too: its
|
|
1213
|
+
* promise rejects and nothing is appended after the clear.
|
|
1214
|
+
*/
|
|
1215
|
+
this.clear = () => {
|
|
1216
|
+
this.generation++;
|
|
1217
|
+
let failure;
|
|
1218
|
+
let failed = false;
|
|
1219
|
+
try {
|
|
1220
|
+
if (this.list().length > 0) this.commit(NO_EFFECTS);
|
|
1221
|
+
} catch (err) {
|
|
1222
|
+
failed = true;
|
|
1223
|
+
failure = err;
|
|
1224
|
+
}
|
|
1225
|
+
this.instances.forEach((instance) => instance.dispose());
|
|
1226
|
+
this.instances.clear();
|
|
1227
|
+
if (failed) {
|
|
1228
|
+
this.wiredKey = UNWIRED;
|
|
1229
|
+
this.handle.publish(NO_EFFECTS);
|
|
1230
|
+
throw failure;
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
/**
|
|
1234
|
+
* Builds this chain again on an offline context, for WAV export, from the
|
|
1235
|
+
* chain as it is when called: built-ins are re-created, WAM plugins
|
|
1236
|
+
* re-instantiated with the live plugin's state, registered effects prepared
|
|
1237
|
+
* and created on the offline context. With no active effect it connects
|
|
1238
|
+
* `from` straight to `to`. It rejects rather than render without an effect
|
|
1239
|
+
* the live chain has. Resolves with the cleanup for the offline instances.
|
|
1240
|
+
*/
|
|
1241
|
+
this.renderOffline = (from, to) => __async(this, null, function* () {
|
|
1242
|
+
const entries = this.list().filter((effect) => !effect.bypassed);
|
|
1243
|
+
if (entries.some((effect) => effect.kind !== "tone") && !(0, import_playout3.isNativeGlobalContext)()) {
|
|
1244
|
+
throw new Error(
|
|
1245
|
+
"[waveform-playlist] WAV export with WAM or custom effects requires a native AudioContext. " + NATIVE_CONTEXT_HINT
|
|
1527
1246
|
);
|
|
1528
|
-
|
|
1529
|
-
|
|
1247
|
+
}
|
|
1248
|
+
const rawContext = from.context.rawContext;
|
|
1249
|
+
const { instances, dispose } = yield buildOfflineChain(entries, this.getWamPlugin, rawContext);
|
|
1250
|
+
connectOfflineChain(from, instances, to);
|
|
1251
|
+
return dispose;
|
|
1252
|
+
});
|
|
1253
|
+
disposeWhenCollected(this, this.instances);
|
|
1254
|
+
}
|
|
1255
|
+
/** The effects in chain order. A new array on every change. */
|
|
1256
|
+
get effects() {
|
|
1257
|
+
return this.handle.source;
|
|
1258
|
+
}
|
|
1259
|
+
list() {
|
|
1260
|
+
return this.handle.source.getSnapshot();
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Wire the graph for `next` if its topology differs, then publish it. If
|
|
1264
|
+
* the wiring throws (a node on another context, for instance) the previous
|
|
1265
|
+
* list is wired back and nothing is published, so the list always describes
|
|
1266
|
+
* what is connected.
|
|
1267
|
+
*/
|
|
1268
|
+
commit(next) {
|
|
1269
|
+
if (chainTopologyKey(next) !== this.wiredKey) {
|
|
1270
|
+
const previous = this.list();
|
|
1271
|
+
try {
|
|
1272
|
+
this.wire(next, true);
|
|
1273
|
+
} catch (err) {
|
|
1274
|
+
try {
|
|
1275
|
+
this.wire(previous, true);
|
|
1276
|
+
} catch (restoreErr) {
|
|
1277
|
+
console.warn(
|
|
1278
|
+
"[waveform-playlist] Could not restore an effects chain after a failed change: " + message(restoreErr)
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
throw err;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
this.handle.publish(next);
|
|
1285
|
+
}
|
|
1286
|
+
audibleInstances(effects) {
|
|
1287
|
+
return effects.filter((effect) => !isDisconnectBypassed(effect)).map((effect) => this.instances.get(effect.instanceId)).filter((instance) => instance !== void 0);
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Connect from → effect 1 → … → to. `rewire` first cuts what was there:
|
|
1291
|
+
* `from`'s outgoing edges, and the output of EVERY instance, including the
|
|
1292
|
+
* ones a bypass has taken out of the chain (an effect that makes sound
|
|
1293
|
+
* with nothing connected to its input must fall silent as well).
|
|
1294
|
+
*/
|
|
1295
|
+
wire(effects, rewire) {
|
|
1296
|
+
const key = chainTopologyKey(effects);
|
|
1297
|
+
const attachment = this.attachment;
|
|
1298
|
+
if (!attachment) {
|
|
1299
|
+
this.wiredKey = key;
|
|
1530
1300
|
return;
|
|
1531
1301
|
}
|
|
1532
|
-
const
|
|
1533
|
-
|
|
1534
|
-
if (
|
|
1535
|
-
|
|
1536
|
-
|
|
1302
|
+
const { from, to } = attachment;
|
|
1303
|
+
this.wiredKey = UNWIRED;
|
|
1304
|
+
if (rewire) {
|
|
1305
|
+
try {
|
|
1306
|
+
from.disconnect();
|
|
1307
|
+
} catch (err) {
|
|
1308
|
+
console.warn("[waveform-playlist] Error disconnecting an effects chain: " + message(err));
|
|
1309
|
+
}
|
|
1537
1310
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
)
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
const instancesMap = trackEffectInstancesRef.current.get(trackId);
|
|
1550
|
-
if (instancesMap) {
|
|
1551
|
-
instancesMap.forEach((inst) => inst.dispose());
|
|
1552
|
-
instancesMap.clear();
|
|
1311
|
+
this.instances.forEach((instance) => instance.disconnect());
|
|
1312
|
+
const chain = this.audibleInstances(effects);
|
|
1313
|
+
if (chain.length === 0) {
|
|
1314
|
+
from.connect(to);
|
|
1315
|
+
} else {
|
|
1316
|
+
let current = from;
|
|
1317
|
+
for (const instance of chain) {
|
|
1318
|
+
(0, import_tone6.connect)(current, instance.input);
|
|
1319
|
+
current = instance.output;
|
|
1320
|
+
}
|
|
1321
|
+
(0, import_tone6.connect)(current, to);
|
|
1553
1322
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1323
|
+
this.wiredKey = key;
|
|
1324
|
+
}
|
|
1325
|
+
append(instance, entry) {
|
|
1326
|
+
this.instances.set(instance.instanceId, instance);
|
|
1327
|
+
try {
|
|
1328
|
+
this.commit([...this.list(), __spreadProps(__spreadValues({}, entry), { instanceId: instance.instanceId })]);
|
|
1329
|
+
} catch (err) {
|
|
1330
|
+
this.instances.delete(instance.instanceId);
|
|
1331
|
+
instance.dispose();
|
|
1332
|
+
throw err;
|
|
1333
|
+
}
|
|
1334
|
+
return instance.instanceId;
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
// src/hooks/useDynamicEffects.ts
|
|
1339
|
+
function useDynamicEffects(fftSize = 256) {
|
|
1340
|
+
const [rack] = (0, import_react2.useState)(() => new EffectsRack());
|
|
1341
|
+
const analyserRef = (0, import_react2.useRef)(null);
|
|
1342
|
+
const masterEffects = (0, import_react2.useCallback)(
|
|
1343
|
+
(masterGainNode, destination, _isOffline) => {
|
|
1344
|
+
const analyserNode = new import_tone7.Analyser("fft", fftSize);
|
|
1345
|
+
analyserRef.current = analyserNode;
|
|
1346
|
+
const detach = rack.attach(masterGainNode, analyserNode);
|
|
1347
|
+
analyserNode.connect(destination);
|
|
1348
|
+
return function cleanup() {
|
|
1349
|
+
detach();
|
|
1350
|
+
analyserNode.dispose();
|
|
1351
|
+
if (analyserRef.current === analyserNode) {
|
|
1352
|
+
analyserRef.current = null;
|
|
1582
1353
|
}
|
|
1583
|
-
return function cleanup() {
|
|
1584
|
-
trackGraphNodesRef.current.delete(trackId);
|
|
1585
|
-
};
|
|
1586
1354
|
};
|
|
1587
1355
|
},
|
|
1588
|
-
[]
|
|
1589
|
-
// No dependencies - stable function that reads from refs
|
|
1356
|
+
[rack, fftSize]
|
|
1590
1357
|
);
|
|
1591
|
-
(0,
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
(0,
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1358
|
+
const createOfflineEffectsFunction = (0, import_react2.useMemo)(() => {
|
|
1359
|
+
const offline = (masterGainNode, destination) => rack.renderOffline(masterGainNode, destination);
|
|
1360
|
+
return () => offline;
|
|
1361
|
+
}, [rack]);
|
|
1362
|
+
const availableEffects = getAvailableEffects();
|
|
1363
|
+
return (0, import_react2.useMemo)(
|
|
1364
|
+
() => ({
|
|
1365
|
+
effects: rack.effects,
|
|
1366
|
+
availableEffects,
|
|
1367
|
+
addEffect: rack.add,
|
|
1368
|
+
addWamEffect: rack.addWam,
|
|
1369
|
+
getWamPlugin: rack.getWamPlugin,
|
|
1370
|
+
removeEffect: rack.remove,
|
|
1371
|
+
updateParameter: rack.updateParameter,
|
|
1372
|
+
toggleBypass: rack.toggleBypass,
|
|
1373
|
+
reorderEffects: rack.reorder,
|
|
1374
|
+
clearAllEffects: rack.clear,
|
|
1375
|
+
masterEffects,
|
|
1376
|
+
createOfflineEffectsFunction,
|
|
1377
|
+
analyserRef
|
|
1378
|
+
}),
|
|
1379
|
+
[rack, availableEffects, masterEffects, createOfflineEffectsFunction]
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
// src/hooks/useTrackDynamicEffects.ts
|
|
1384
|
+
var import_react3 = require("react");
|
|
1385
|
+
function useTrackDynamicEffects() {
|
|
1386
|
+
const [store] = (0, import_react3.useState)(() => ({
|
|
1387
|
+
racks: /* @__PURE__ */ new Map(),
|
|
1388
|
+
effectsFunctions: /* @__PURE__ */ new Map(),
|
|
1389
|
+
offlineFunctions: /* @__PURE__ */ new Map()
|
|
1390
|
+
}));
|
|
1391
|
+
const rackFor = (0, import_react3.useCallback)(
|
|
1609
1392
|
(trackId) => {
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
const hasWam = nonBypassed.some((e) => e.kind === "wam");
|
|
1616
|
-
return (graphEnd, masterGainNode, _isOffline) => __async(null, null, function* () {
|
|
1617
|
-
if (hasWam && !(0, import_playout2.isNativeGlobalContext)()) {
|
|
1618
|
-
throw new Error(
|
|
1619
|
-
"[waveform-playlist] WAV export with WAM effects requires a native AudioContext. Call configureGlobalContext({ nativeAudioContext: true }) from @waveform-playlist/playout before any audio initialization."
|
|
1620
|
-
);
|
|
1621
|
-
}
|
|
1622
|
-
const rawContext = graphEnd.context.rawContext;
|
|
1623
|
-
const { instances, dispose } = yield buildOfflineChain(
|
|
1624
|
-
nonBypassed,
|
|
1625
|
-
(instanceId) => {
|
|
1626
|
-
var _a;
|
|
1627
|
-
const inst = (_a = trackEffectInstancesRef.current.get(trackId)) == null ? void 0 : _a.get(instanceId);
|
|
1628
|
-
return (inst == null ? void 0 : inst.kind) === "wam" ? inst.plugin : void 0;
|
|
1629
|
-
},
|
|
1630
|
-
rawContext
|
|
1631
|
-
);
|
|
1632
|
-
connectOfflineChain(graphEnd, instances, masterGainNode);
|
|
1633
|
-
return dispose;
|
|
1634
|
-
});
|
|
1393
|
+
const existing = store.racks.get(trackId);
|
|
1394
|
+
if (existing) return existing;
|
|
1395
|
+
const rack = new EffectsRack();
|
|
1396
|
+
store.racks.set(trackId, rack);
|
|
1397
|
+
return rack;
|
|
1635
1398
|
},
|
|
1636
|
-
[
|
|
1399
|
+
[store]
|
|
1637
1400
|
);
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1401
|
+
const actions = (0, import_react3.useMemo)(
|
|
1402
|
+
() => ({
|
|
1403
|
+
getTrackEffects: (trackId) => rackFor(trackId).effects,
|
|
1404
|
+
addEffectToTrack: (trackId, effectId) => rackFor(trackId).add(effectId),
|
|
1405
|
+
addWamEffectToTrack: (trackId, url, initialState) => rackFor(trackId).addWam(url, initialState),
|
|
1406
|
+
getTrackWamPlugin: (trackId, instanceId) => {
|
|
1407
|
+
var _a;
|
|
1408
|
+
return (_a = store.racks.get(trackId)) == null ? void 0 : _a.getWamPlugin(instanceId);
|
|
1409
|
+
},
|
|
1410
|
+
removeEffectFromTrack: (trackId, instanceId) => {
|
|
1411
|
+
var _a;
|
|
1412
|
+
return (_a = store.racks.get(trackId)) == null ? void 0 : _a.remove(instanceId);
|
|
1413
|
+
},
|
|
1414
|
+
updateTrackEffectParameter: (trackId, instanceId, paramName, value) => {
|
|
1415
|
+
var _a;
|
|
1416
|
+
return (_a = store.racks.get(trackId)) == null ? void 0 : _a.updateParameter(instanceId, paramName, value);
|
|
1417
|
+
},
|
|
1418
|
+
toggleBypass: (trackId, instanceId) => {
|
|
1419
|
+
var _a;
|
|
1420
|
+
return (_a = store.racks.get(trackId)) == null ? void 0 : _a.toggleBypass(instanceId);
|
|
1421
|
+
},
|
|
1422
|
+
reorderTrackEffects: (trackId, fromIndex, toIndex) => {
|
|
1423
|
+
var _a;
|
|
1424
|
+
return (_a = store.racks.get(trackId)) == null ? void 0 : _a.reorder(fromIndex, toIndex);
|
|
1425
|
+
},
|
|
1426
|
+
clearTrackEffects: (trackId) => {
|
|
1427
|
+
var _a;
|
|
1428
|
+
return (_a = store.racks.get(trackId)) == null ? void 0 : _a.clear();
|
|
1429
|
+
},
|
|
1430
|
+
getTrackEffectsFunction: (trackId) => {
|
|
1431
|
+
const existing = store.effectsFunctions.get(trackId);
|
|
1432
|
+
if (existing) return existing;
|
|
1433
|
+
const effectsFunction = (trackInput, faderInput, _isOffline) => rackFor(trackId).attach(trackInput, faderInput);
|
|
1434
|
+
store.effectsFunctions.set(trackId, effectsFunction);
|
|
1435
|
+
return effectsFunction;
|
|
1436
|
+
},
|
|
1437
|
+
createOfflineTrackEffectsFunction: (trackId) => {
|
|
1438
|
+
const existing = store.offlineFunctions.get(trackId);
|
|
1439
|
+
if (existing) return existing;
|
|
1440
|
+
const offline = (trackInput, faderInput) => rackFor(trackId).renderOffline(trackInput, faderInput);
|
|
1441
|
+
store.offlineFunctions.set(trackId, offline);
|
|
1442
|
+
return offline;
|
|
1443
|
+
}
|
|
1444
|
+
}),
|
|
1445
|
+
[store, rackFor]
|
|
1446
|
+
);
|
|
1447
|
+
const availableEffects = getAvailableEffects();
|
|
1448
|
+
return (0, import_react3.useMemo)(() => __spreadProps(__spreadValues({}, actions), { availableEffects }), [actions, availableEffects]);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// src/hooks/useActiveEffects.ts
|
|
1452
|
+
var import_react4 = require("react");
|
|
1453
|
+
function useActiveEffects(effects) {
|
|
1454
|
+
return (0, import_react4.useSyncExternalStore)(effects.subscribe, effects.getSnapshot, effects.getSnapshot);
|
|
1651
1455
|
}
|
|
1652
1456
|
|
|
1653
1457
|
// src/hooks/useExportWav.ts
|
|
1654
1458
|
var import_react5 = require("react");
|
|
1655
|
-
var
|
|
1656
|
-
var
|
|
1459
|
+
var import_core4 = require("@waveform-playlist/core");
|
|
1460
|
+
var import_playout5 = require("@waveform-playlist/playout");
|
|
1657
1461
|
|
|
1658
1462
|
// src/utils/renderToneOffline.ts
|
|
1659
|
-
var
|
|
1660
|
-
var
|
|
1463
|
+
var import_tone8 = require("tone");
|
|
1464
|
+
var import_playout4 = require("@waveform-playlist/playout");
|
|
1661
1465
|
var renderQueue = Promise.resolve();
|
|
1662
1466
|
function renderToneOffline(build, duration, channels, sampleRate) {
|
|
1663
1467
|
return __async(this, null, function* () {
|
|
@@ -1670,19 +1474,19 @@ function renderToneOffline(build, duration, channels, sampleRate) {
|
|
|
1670
1474
|
}
|
|
1671
1475
|
function renderToneOfflineSerial(build, duration, channels, sampleRate) {
|
|
1672
1476
|
return __async(this, null, function* () {
|
|
1673
|
-
const offlineContext = (0,
|
|
1477
|
+
const offlineContext = (0, import_playout4.isNativeGlobalContext)() ? new import_tone8.OfflineContext(
|
|
1674
1478
|
new OfflineAudioContext({
|
|
1675
1479
|
numberOfChannels: channels,
|
|
1676
1480
|
length: Math.round(duration * sampleRate),
|
|
1677
1481
|
sampleRate
|
|
1678
1482
|
})
|
|
1679
|
-
) : new
|
|
1680
|
-
const previousContext = (0,
|
|
1681
|
-
(0,
|
|
1483
|
+
) : new import_tone8.OfflineContext(channels, duration, sampleRate);
|
|
1484
|
+
const previousContext = (0, import_tone8.getContext)();
|
|
1485
|
+
(0, import_tone8.setContext)(offlineContext);
|
|
1682
1486
|
try {
|
|
1683
1487
|
yield build(offlineContext);
|
|
1684
1488
|
} finally {
|
|
1685
|
-
(0,
|
|
1489
|
+
(0, import_tone8.setContext)(previousContext);
|
|
1686
1490
|
}
|
|
1687
1491
|
const toneBuffer = yield offlineContext.render();
|
|
1688
1492
|
const audioBuffer = toneBuffer.get();
|
|
@@ -1790,7 +1594,7 @@ function useExportWav() {
|
|
|
1790
1594
|
if (mode === "individual" && (trackIndex === void 0 || trackIndex < 0 || trackIndex >= tracks.length)) {
|
|
1791
1595
|
throw new Error("Invalid track index for individual export");
|
|
1792
1596
|
}
|
|
1793
|
-
const sampleRate = (0,
|
|
1597
|
+
const sampleRate = (0, import_playout5.getGlobalAudioContext)().sampleRate;
|
|
1794
1598
|
let totalDurationSamples = 0;
|
|
1795
1599
|
for (const track of tracks) {
|
|
1796
1600
|
for (const clip of track.clips) {
|
|
@@ -1800,8 +1604,17 @@ function useExportWav() {
|
|
|
1800
1604
|
}
|
|
1801
1605
|
totalDurationSamples += Math.round(sampleRate * 0.1);
|
|
1802
1606
|
const duration = totalDurationSamples / sampleRate;
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1607
|
+
const stateOf = (index) => {
|
|
1608
|
+
var _a;
|
|
1609
|
+
return (_a = trackStates[index]) != null ? _a : {
|
|
1610
|
+
muted: tracks[index].muted,
|
|
1611
|
+
soloed: tracks[index].soloed,
|
|
1612
|
+
volume: tracks[index].volume,
|
|
1613
|
+
pan: tracks[index].pan
|
|
1614
|
+
};
|
|
1615
|
+
};
|
|
1616
|
+
const tracksToRender = mode === "individual" ? [{ track: tracks[trackIndex], state: stateOf(trackIndex), index: trackIndex }] : tracks.map((track, index) => ({ track, state: stateOf(index), index }));
|
|
1617
|
+
const hasSolo = mode === "master" && tracks.some((_, index) => stateOf(index).soloed);
|
|
1805
1618
|
const reportProgress = (p) => {
|
|
1806
1619
|
setProgress(p);
|
|
1807
1620
|
onProgress == null ? void 0 : onProgress(p);
|
|
@@ -1829,8 +1642,8 @@ function useExportWav() {
|
|
|
1829
1642
|
duration
|
|
1830
1643
|
};
|
|
1831
1644
|
} catch (err) {
|
|
1832
|
-
const
|
|
1833
|
-
setError(
|
|
1645
|
+
const message2 = err instanceof Error ? err.message : "Export failed";
|
|
1646
|
+
setError(message2);
|
|
1834
1647
|
throw err;
|
|
1835
1648
|
} finally {
|
|
1836
1649
|
setIsExporting(false);
|
|
@@ -1847,7 +1660,7 @@ function useExportWav() {
|
|
|
1847
1660
|
}
|
|
1848
1661
|
function renderOffline(tracksToRender, hasSolo, duration, sampleRate, applyEffects, effectsFunction, createOfflineTrackEffects, onProgress) {
|
|
1849
1662
|
return __async(this, null, function* () {
|
|
1850
|
-
const { Volume
|
|
1663
|
+
const { Volume, Gain, Player, ToneAudioBuffer, connect: connect6 } = yield import("tone");
|
|
1851
1664
|
onProgress(0.1);
|
|
1852
1665
|
const audibleTracks = tracksToRender.filter(({ state }) => {
|
|
1853
1666
|
if (state.muted && !state.soloed) return false;
|
|
@@ -1855,14 +1668,14 @@ function renderOffline(tracksToRender, hasSolo, duration, sampleRate, applyEffec
|
|
|
1855
1668
|
return true;
|
|
1856
1669
|
});
|
|
1857
1670
|
const outputChannels = audibleTracks.reduce(
|
|
1858
|
-
(max, { track }) => Math.max(max, (0,
|
|
1671
|
+
(max, { track }) => Math.max(max, (0, import_core4.trackChannelCount)(track)),
|
|
1859
1672
|
1
|
|
1860
1673
|
);
|
|
1861
1674
|
const cleanups = [];
|
|
1862
1675
|
try {
|
|
1863
1676
|
const audioBuffer = yield renderToneOffline(
|
|
1864
1677
|
(context) => __async(null, null, function* () {
|
|
1865
|
-
const masterVolume = new
|
|
1678
|
+
const masterVolume = new Volume(0);
|
|
1866
1679
|
if (effectsFunction && applyEffects) {
|
|
1867
1680
|
const cleanup = yield effectsFunction(masterVolume, context.destination, true);
|
|
1868
1681
|
if (cleanup) cleanups.push(cleanup);
|
|
@@ -1870,18 +1683,24 @@ function renderOffline(tracksToRender, hasSolo, duration, sampleRate, applyEffec
|
|
|
1870
1683
|
masterVolume.connect(context.destination);
|
|
1871
1684
|
}
|
|
1872
1685
|
for (const { track, state } of audibleTracks) {
|
|
1873
|
-
const
|
|
1874
|
-
const
|
|
1875
|
-
const
|
|
1686
|
+
const trackInput = new Gain({ gain: 1 });
|
|
1687
|
+
const trackVolume = new Volume((0, import_core4.gainToDb)(state.volume));
|
|
1688
|
+
const trackPan = (0, import_core4.createPanStage)(
|
|
1689
|
+
context.rawContext,
|
|
1690
|
+
state.pan,
|
|
1691
|
+
(0, import_core4.trackChannelCount)(track)
|
|
1692
|
+
);
|
|
1693
|
+
const trackMute = new Gain(state.muted ? 0 : 1);
|
|
1876
1694
|
const trackEffects = createOfflineTrackEffects == null ? void 0 : createOfflineTrackEffects(track.id);
|
|
1877
1695
|
if (trackEffects && applyEffects) {
|
|
1878
|
-
const cleanup = yield trackEffects(
|
|
1696
|
+
const cleanup = yield trackEffects(trackInput, trackVolume, true);
|
|
1879
1697
|
if (cleanup) cleanups.push(cleanup);
|
|
1880
1698
|
} else {
|
|
1881
|
-
|
|
1699
|
+
trackInput.connect(trackVolume);
|
|
1882
1700
|
}
|
|
1883
|
-
|
|
1884
|
-
|
|
1701
|
+
trackMute.connect(masterVolume);
|
|
1702
|
+
connect6(trackPan.output, trackMute);
|
|
1703
|
+
trackVolume.connect(trackPan.input);
|
|
1885
1704
|
for (const clip of track.clips) {
|
|
1886
1705
|
const {
|
|
1887
1706
|
audioBuffer: clipBuffer,
|
|
@@ -1903,18 +1722,18 @@ function renderOffline(tracksToRender, hasSolo, duration, sampleRate, applyEffec
|
|
|
1903
1722
|
const offset = offsetSamples / sampleRate;
|
|
1904
1723
|
const toneBuffer = new ToneAudioBuffer(clipBuffer);
|
|
1905
1724
|
const player = new Player(toneBuffer);
|
|
1906
|
-
const fadeGain = new
|
|
1725
|
+
const fadeGain = new Gain(clipGain);
|
|
1907
1726
|
player.connect(fadeGain);
|
|
1908
|
-
fadeGain.connect(
|
|
1727
|
+
fadeGain.connect(trackInput);
|
|
1909
1728
|
if (applyEffects) {
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1729
|
+
applyClipFades(
|
|
1730
|
+
fadeGain.input.gain,
|
|
1731
|
+
clipGain,
|
|
1732
|
+
startTime,
|
|
1733
|
+
clipDuration,
|
|
1734
|
+
fadeIn,
|
|
1735
|
+
fadeOut
|
|
1736
|
+
);
|
|
1918
1737
|
}
|
|
1919
1738
|
player.start(startTime, offset, clipDuration);
|
|
1920
1739
|
}
|
|
@@ -1951,168 +1770,41 @@ function applyClipFades(gainParam, clipGain, startTime, clipDuration, fadeIn, fa
|
|
|
1951
1770
|
gainParam.setValueAtTime(clipGain, startTime);
|
|
1952
1771
|
}
|
|
1953
1772
|
if (fadeIn) {
|
|
1954
|
-
(0,
|
|
1773
|
+
(0, import_core4.applyFadeIn)(gainParam, startTime, fadeIn.duration, fadeIn.type || "linear", 0, clipGain);
|
|
1955
1774
|
}
|
|
1956
1775
|
if (fadeOut) {
|
|
1957
1776
|
const fadeOutStart = startTime + clipDuration - fadeOut.duration;
|
|
1958
1777
|
if (!fadeIn || fadeIn.duration < clipDuration - fadeOut.duration) {
|
|
1959
1778
|
gainParam.setValueAtTime(clipGain, fadeOutStart);
|
|
1960
1779
|
}
|
|
1961
|
-
(0,
|
|
1780
|
+
(0, import_core4.applyFadeOut)(gainParam, fadeOutStart, fadeOut.duration, fadeOut.type || "linear", clipGain, 0);
|
|
1962
1781
|
}
|
|
1963
1782
|
}
|
|
1964
1783
|
|
|
1965
|
-
// src/hooks/useDynamicTracks.ts
|
|
1966
|
-
var import_react6 = require("react");
|
|
1967
|
-
var import_core3 = require("@waveform-playlist/core");
|
|
1968
|
-
var import_playout5 = require("@waveform-playlist/playout");
|
|
1969
|
-
function getSourceName(source) {
|
|
1970
|
-
var _a, _b, _c, _d, _e;
|
|
1971
|
-
if (source instanceof File) {
|
|
1972
|
-
return source.name.replace(/\.[^/.]+$/, "");
|
|
1973
|
-
}
|
|
1974
|
-
if (source instanceof Blob) {
|
|
1975
|
-
return "Untitled";
|
|
1976
|
-
}
|
|
1977
|
-
if (typeof source === "string") {
|
|
1978
|
-
return (_b = (_a = source.split("/").pop()) == null ? void 0 : _a.replace(/\.[^/.]+$/, "")) != null ? _b : "Untitled";
|
|
1979
|
-
}
|
|
1980
|
-
return (_e = (_d = source.name) != null ? _d : (_c = source.src.split("/").pop()) == null ? void 0 : _c.replace(/\.[^/.]+$/, "")) != null ? _e : "Untitled";
|
|
1981
|
-
}
|
|
1982
|
-
function decodeSource(source, audioContext, signal) {
|
|
1983
|
-
return __async(this, null, function* () {
|
|
1984
|
-
const name = getSourceName(source);
|
|
1985
|
-
if (source instanceof Blob) {
|
|
1986
|
-
const arrayBuffer2 = yield source.arrayBuffer();
|
|
1987
|
-
signal == null ? void 0 : signal.throwIfAborted();
|
|
1988
|
-
const audioBuffer2 = yield audioContext.decodeAudioData(arrayBuffer2);
|
|
1989
|
-
return { audioBuffer: audioBuffer2, name };
|
|
1990
|
-
}
|
|
1991
|
-
const url = typeof source === "string" ? source : source.src;
|
|
1992
|
-
const response = yield fetch(url, { signal });
|
|
1993
|
-
if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
1994
|
-
const arrayBuffer = yield response.arrayBuffer();
|
|
1995
|
-
signal == null ? void 0 : signal.throwIfAborted();
|
|
1996
|
-
const audioBuffer = yield audioContext.decodeAudioData(arrayBuffer);
|
|
1997
|
-
return { audioBuffer, name };
|
|
1998
|
-
});
|
|
1999
|
-
}
|
|
2000
|
-
function useDynamicTracks() {
|
|
2001
|
-
const [tracks, setTracks] = (0, import_react6.useState)([]);
|
|
2002
|
-
const [loadingCount, setLoadingCount] = (0, import_react6.useState)(0);
|
|
2003
|
-
const [errors, setErrors] = (0, import_react6.useState)([]);
|
|
2004
|
-
const cancelledRef = (0, import_react6.useRef)(false);
|
|
2005
|
-
const loadingIdsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
|
|
2006
|
-
const abortControllersRef = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
|
|
2007
|
-
(0, import_react6.useEffect)(() => {
|
|
2008
|
-
const controllers = abortControllersRef.current;
|
|
2009
|
-
return () => {
|
|
2010
|
-
cancelledRef.current = true;
|
|
2011
|
-
for (const controller of controllers.values()) {
|
|
2012
|
-
controller.abort();
|
|
2013
|
-
}
|
|
2014
|
-
controllers.clear();
|
|
2015
|
-
};
|
|
2016
|
-
}, []);
|
|
2017
|
-
const addTracks = (0, import_react6.useCallback)((sources) => {
|
|
2018
|
-
if (sources.length === 0) return;
|
|
2019
|
-
const audioContext = (0, import_playout5.getGlobalAudioContext)();
|
|
2020
|
-
const placeholders = sources.map((source) => ({
|
|
2021
|
-
track: (0, import_core3.createTrack)({ name: `${getSourceName(source)} (loading...)`, clips: [] }),
|
|
2022
|
-
source
|
|
2023
|
-
}));
|
|
2024
|
-
setTracks((prev) => [...prev, ...placeholders.map((p) => p.track)]);
|
|
2025
|
-
setLoadingCount((prev) => prev + sources.length);
|
|
2026
|
-
for (const { track, source } of placeholders) {
|
|
2027
|
-
loadingIdsRef.current.add(track.id);
|
|
2028
|
-
const controller = new AbortController();
|
|
2029
|
-
abortControllersRef.current.set(track.id, controller);
|
|
2030
|
-
(() => __async(null, null, function* () {
|
|
2031
|
-
try {
|
|
2032
|
-
const { audioBuffer, name } = yield decodeSource(source, audioContext, controller.signal);
|
|
2033
|
-
const clip = (0, import_core3.createClipFromSeconds)({
|
|
2034
|
-
audioBuffer,
|
|
2035
|
-
startTime: 0,
|
|
2036
|
-
duration: audioBuffer.duration,
|
|
2037
|
-
offset: 0,
|
|
2038
|
-
name
|
|
2039
|
-
});
|
|
2040
|
-
if (!cancelledRef.current && loadingIdsRef.current.has(track.id)) {
|
|
2041
|
-
setTracks(
|
|
2042
|
-
(prev) => prev.map((t) => t.id === track.id ? __spreadProps(__spreadValues({}, t), { name, clips: [clip] }) : t)
|
|
2043
|
-
);
|
|
2044
|
-
}
|
|
2045
|
-
} catch (error) {
|
|
2046
|
-
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
2047
|
-
console.warn("[waveform-playlist] Error loading audio:", error);
|
|
2048
|
-
if (!cancelledRef.current && loadingIdsRef.current.has(track.id)) {
|
|
2049
|
-
setTracks((prev) => prev.filter((t) => t.id !== track.id));
|
|
2050
|
-
setErrors((prev) => [
|
|
2051
|
-
...prev,
|
|
2052
|
-
{
|
|
2053
|
-
name: getSourceName(source),
|
|
2054
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
2055
|
-
}
|
|
2056
|
-
]);
|
|
2057
|
-
}
|
|
2058
|
-
} finally {
|
|
2059
|
-
abortControllersRef.current.delete(track.id);
|
|
2060
|
-
if (!cancelledRef.current && loadingIdsRef.current.delete(track.id)) {
|
|
2061
|
-
setLoadingCount((prev) => prev - 1);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
}))();
|
|
2065
|
-
}
|
|
2066
|
-
}, []);
|
|
2067
|
-
const removeTrack = (0, import_react6.useCallback)((trackId) => {
|
|
2068
|
-
setTracks((prev) => prev.filter((t) => t.id !== trackId));
|
|
2069
|
-
const controller = abortControllersRef.current.get(trackId);
|
|
2070
|
-
if (controller) {
|
|
2071
|
-
controller.abort();
|
|
2072
|
-
abortControllersRef.current.delete(trackId);
|
|
2073
|
-
}
|
|
2074
|
-
if (loadingIdsRef.current.delete(trackId)) {
|
|
2075
|
-
setLoadingCount((prev) => prev - 1);
|
|
2076
|
-
}
|
|
2077
|
-
}, []);
|
|
2078
|
-
return {
|
|
2079
|
-
tracks,
|
|
2080
|
-
addTracks,
|
|
2081
|
-
removeTrack,
|
|
2082
|
-
loadingCount,
|
|
2083
|
-
isLoading: loadingCount > 0,
|
|
2084
|
-
errors
|
|
2085
|
-
};
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
1784
|
// src/hooks/useOutputMeter.ts
|
|
2089
|
-
var
|
|
1785
|
+
var import_react6 = require("react");
|
|
2090
1786
|
var import_playout6 = require("@waveform-playlist/playout");
|
|
2091
|
-
var
|
|
1787
|
+
var import_core5 = require("@waveform-playlist/core");
|
|
2092
1788
|
var import_worklets = require("@waveform-playlist/worklets");
|
|
2093
|
-
var PEAK_DECAY = 0.98;
|
|
2094
1789
|
function useOutputMeter(options = {}) {
|
|
2095
1790
|
const { channelCount = 2, updateRate = 60, isPlaying = false } = options;
|
|
2096
|
-
const [
|
|
2097
|
-
|
|
2098
|
-
const [rmsLevels, setRmsLevels] = (0, import_react7.useState)(() => new Array(channelCount).fill(0));
|
|
2099
|
-
const workletNodeRef = (0, import_react7.useRef)(null);
|
|
2100
|
-
const smoothedPeakRef = (0, import_react7.useRef)(new Array(channelCount).fill(0));
|
|
2101
|
-
const [meterError, setMeterError] = (0, import_react7.useState)(null);
|
|
2102
|
-
const resetPeak = (0, import_react7.useCallback)(
|
|
2103
|
-
() => setPeakLevels(new Array(channelCount).fill(0)),
|
|
2104
|
-
[channelCount]
|
|
1791
|
+
const [{ source: meter, publish }] = (0, import_react6.useState)(
|
|
1792
|
+
() => (0, import_core5.createValueSource)((0, import_core5.silentMeterLevels)(channelCount))
|
|
2105
1793
|
);
|
|
2106
|
-
(0,
|
|
1794
|
+
const workletNodeRef = (0, import_react6.useRef)(null);
|
|
1795
|
+
const smoothedPeakRef = (0, import_react6.useRef)([]);
|
|
1796
|
+
const [meterError, setMeterError] = (0, import_react6.useState)(null);
|
|
1797
|
+
const resetPeak = (0, import_react6.useCallback)(() => {
|
|
1798
|
+
const current = meter.getSnapshot();
|
|
1799
|
+
publish(__spreadProps(__spreadValues({}, current), { peakLevels: current.peakLevels.map(() => 0) }));
|
|
1800
|
+
}, [meter, publish]);
|
|
1801
|
+
(0, import_react6.useEffect)(() => {
|
|
2107
1802
|
if (!isPlaying) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
setLevels(zeros);
|
|
2111
|
-
setRmsLevels(zeros);
|
|
2112
|
-
setPeakLevels(zeros);
|
|
1803
|
+
smoothedPeakRef.current = [];
|
|
1804
|
+
publish((0, import_core5.silentMeterLevels)(channelCount));
|
|
2113
1805
|
}
|
|
2114
|
-
}, [isPlaying, channelCount]);
|
|
2115
|
-
(0,
|
|
1806
|
+
}, [isPlaying, channelCount, publish]);
|
|
1807
|
+
(0, import_react6.useEffect)(() => {
|
|
2116
1808
|
let isMounted = true;
|
|
2117
1809
|
const setup = () => __async(null, null, function* () {
|
|
2118
1810
|
const context = (0, import_playout6.getGlobalContext)();
|
|
@@ -2133,26 +1825,16 @@ function useOutputMeter(options = {}) {
|
|
|
2133
1825
|
};
|
|
2134
1826
|
const destination = context.destination;
|
|
2135
1827
|
destination.chain(workletNode);
|
|
2136
|
-
smoothedPeakRef.current =
|
|
1828
|
+
smoothedPeakRef.current = [];
|
|
2137
1829
|
workletNode.port.onmessage = (event) => {
|
|
2138
|
-
var _a;
|
|
2139
1830
|
if (!isMounted) return;
|
|
2140
|
-
const
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
peakValues.push((0, import_core4.gainToNormalized)(smoothed[ch]));
|
|
2148
|
-
rmsValues.push((0, import_core4.gainToNormalized)(data[workletChannels + ch]));
|
|
2149
|
-
}
|
|
2150
|
-
setLevels(peakValues);
|
|
2151
|
-
setRmsLevels(rmsValues);
|
|
2152
|
-
setPeakLevels((prev) => peakValues.map((val, i) => {
|
|
2153
|
-
var _a2;
|
|
2154
|
-
return Math.max((_a2 = prev[i]) != null ? _a2 : 0, val);
|
|
2155
|
-
}));
|
|
1831
|
+
const reading = (0, import_core5.readMeterMessage)({
|
|
1832
|
+
data: event.data,
|
|
1833
|
+
previousSmoothedPeaks: smoothedPeakRef.current,
|
|
1834
|
+
heldPeakLevels: meter.getSnapshot().peakLevels
|
|
1835
|
+
});
|
|
1836
|
+
smoothedPeakRef.current = reading.smoothedPeaks;
|
|
1837
|
+
publish(reading.levels);
|
|
2156
1838
|
};
|
|
2157
1839
|
});
|
|
2158
1840
|
setup().catch((err) => {
|
|
@@ -2179,33 +1861,64 @@ function useOutputMeter(options = {}) {
|
|
|
2179
1861
|
workletNodeRef.current = null;
|
|
2180
1862
|
}
|
|
2181
1863
|
};
|
|
2182
|
-
}, [channelCount, updateRate]);
|
|
2183
|
-
return {
|
|
1864
|
+
}, [channelCount, updateRate, meter, publish]);
|
|
1865
|
+
return { meter, resetPeak, error: meterError };
|
|
2184
1866
|
}
|
|
2185
1867
|
|
|
2186
1868
|
// src/components/ExportControls.tsx
|
|
2187
|
-
var import_ui_components2 = require("@waveform-playlist/ui-components");
|
|
2188
|
-
|
|
2189
|
-
// src/WaveformPlaylistContext.tsx
|
|
2190
|
-
var import_react8 = require("react");
|
|
2191
|
-
var import_styled_components = require("styled-components");
|
|
2192
|
-
var import_engine = require("@waveform-playlist/engine");
|
|
2193
1869
|
var import_ui_components = require("@waveform-playlist/ui-components");
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
var
|
|
2197
|
-
var
|
|
2198
|
-
var
|
|
2199
|
-
var
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
1870
|
+
|
|
1871
|
+
// src/contexts/playlistContexts.ts
|
|
1872
|
+
var import_react7 = require("react");
|
|
1873
|
+
var WEB_AUDIO = "WaveformPlaylistProvider";
|
|
1874
|
+
var MEDIA_ELEMENT = "MediaElementPlaylistProvider";
|
|
1875
|
+
var BLOCKED = /* @__PURE__ */ Symbol("waveform-playlist.blocked-context");
|
|
1876
|
+
var slot = () => (0, import_react7.createContext)(null);
|
|
1877
|
+
var IsPlayingContext = slot();
|
|
1878
|
+
var PlaybackRefsContext = slot();
|
|
1879
|
+
var SelectionContext = slot();
|
|
1880
|
+
var CurrentTimeContext = slot();
|
|
1881
|
+
var ActiveAnnotationContext = slot();
|
|
1882
|
+
var AnnotationsContext = slot();
|
|
1883
|
+
var AnnotationOptionsContext = slot();
|
|
1884
|
+
var PlaybackControlsContext = slot();
|
|
1885
|
+
var PlaylistViewContext = slot();
|
|
1886
|
+
var PlaylistSettingsContext = slot();
|
|
1887
|
+
var PlaylistZoomContext = slot();
|
|
1888
|
+
var SelectedRowContext = slot();
|
|
1889
|
+
var ArrangementContext = slot();
|
|
1890
|
+
var EditorControlsContext = slot();
|
|
1891
|
+
var EngineRefsContext = slot();
|
|
1892
|
+
var LoopContext = slot();
|
|
1893
|
+
var SelectedTrackIdContext = slot();
|
|
1894
|
+
var UndoRedoContext = slot();
|
|
1895
|
+
var PlaylistTimelineContext = slot();
|
|
1896
|
+
var PlaylistMixerContext = slot();
|
|
1897
|
+
var TrackReorderPreviewContext = slot();
|
|
1898
|
+
var TrimPreviewContext = slot();
|
|
1899
|
+
var TrimPreviewPeaksContext = slot();
|
|
1900
|
+
var RecordingArmContext = slot();
|
|
1901
|
+
var PlaybackRateContext = slot();
|
|
1902
|
+
var MediaElementTrackContext = slot();
|
|
1903
|
+
function useSlot(context, hookName, needs) {
|
|
1904
|
+
const value = (0, import_react7.use)(context);
|
|
1905
|
+
if (value === BLOCKED) {
|
|
1906
|
+
const nearest = needs === WEB_AUDIO ? MEDIA_ELEMENT : WEB_AUDIO;
|
|
1907
|
+
throw new Error(
|
|
1908
|
+
`${hookName} needs ${needs}, and the nearest playlist provider here is ${nearest}, which does not provide it`
|
|
1909
|
+
);
|
|
2203
1910
|
}
|
|
2204
|
-
|
|
2205
|
-
};
|
|
1911
|
+
if (!value) {
|
|
1912
|
+
throw new Error(`${hookName} must be used within ${needs}`);
|
|
1913
|
+
}
|
|
1914
|
+
return value;
|
|
1915
|
+
}
|
|
1916
|
+
var EITHER = `${WEB_AUDIO} or ${MEDIA_ELEMENT}`;
|
|
1917
|
+
var usePlaylistTimeline = () => useSlot(PlaylistTimelineContext, "usePlaylistTimeline", WEB_AUDIO);
|
|
1918
|
+
var usePlaylistMixer = () => useSlot(PlaylistMixerContext, "usePlaylistMixer", WEB_AUDIO);
|
|
2206
1919
|
|
|
2207
1920
|
// src/components/ExportControls.tsx
|
|
2208
|
-
var
|
|
1921
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2209
1922
|
var ExportWavButton = ({
|
|
2210
1923
|
label = "Export WAV",
|
|
2211
1924
|
filename = "export",
|
|
@@ -2219,7 +1932,8 @@ var ExportWavButton = ({
|
|
|
2219
1932
|
onExportComplete,
|
|
2220
1933
|
onExportError
|
|
2221
1934
|
}) => {
|
|
2222
|
-
const { tracks
|
|
1935
|
+
const { tracks } = usePlaylistTimeline();
|
|
1936
|
+
const { trackStates } = usePlaylistMixer();
|
|
2223
1937
|
const { exportWav, isExporting, progress } = useExportWav();
|
|
2224
1938
|
const handleExport = () => __async(null, null, function* () {
|
|
2225
1939
|
try {
|
|
@@ -2239,8 +1953,8 @@ var ExportWavButton = ({
|
|
|
2239
1953
|
}
|
|
2240
1954
|
});
|
|
2241
1955
|
const buttonLabel = isExporting ? `Exporting ${Math.round(progress * 100)}%` : label;
|
|
2242
|
-
return /* @__PURE__ */ (0,
|
|
2243
|
-
|
|
1956
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1957
|
+
import_ui_components.BaseControlButton,
|
|
2244
1958
|
{
|
|
2245
1959
|
onClick: handleExport,
|
|
2246
1960
|
disabled: isExporting || tracks.length === 0,
|
|
@@ -2251,20 +1965,23 @@ var ExportWavButton = ({
|
|
|
2251
1965
|
};
|
|
2252
1966
|
|
|
2253
1967
|
// src/components/WamEffectGui.tsx
|
|
2254
|
-
var
|
|
2255
|
-
var
|
|
1968
|
+
var import_react8 = require("react");
|
|
1969
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
2256
1970
|
var WamEffectGui = ({ plugin, className }) => {
|
|
2257
|
-
const hostRef = (0,
|
|
2258
|
-
(0,
|
|
1971
|
+
const hostRef = (0, import_react8.useRef)(null);
|
|
1972
|
+
(0, import_react8.useEffect)(() => {
|
|
2259
1973
|
const host = hostRef.current;
|
|
2260
1974
|
if (!plugin || !host) return;
|
|
2261
1975
|
let cancelled = false;
|
|
2262
1976
|
let gui = null;
|
|
1977
|
+
let pluginOwnsGui = false;
|
|
2263
1978
|
(() => __async(null, null, function* () {
|
|
2264
1979
|
var _a;
|
|
2265
1980
|
try {
|
|
2266
|
-
|
|
2267
|
-
|
|
1981
|
+
const own = plugin.createGui ? yield plugin.createGui() : void 0;
|
|
1982
|
+
if (own instanceof HTMLElement) {
|
|
1983
|
+
gui = own;
|
|
1984
|
+
pluginOwnsGui = true;
|
|
2268
1985
|
} else {
|
|
2269
1986
|
const wam = yield loadWamModule();
|
|
2270
1987
|
gui = yield wam.createWamParameterPanel(
|
|
@@ -2272,7 +1989,7 @@ var WamEffectGui = ({ plugin, className }) => {
|
|
|
2272
1989
|
);
|
|
2273
1990
|
}
|
|
2274
1991
|
if (cancelled) {
|
|
2275
|
-
if (gui) {
|
|
1992
|
+
if (gui && pluginOwnsGui) {
|
|
2276
1993
|
try {
|
|
2277
1994
|
(_a = plugin.destroyGui) == null ? void 0 : _a.call(plugin, gui);
|
|
2278
1995
|
} catch (destroyErr) {
|
|
@@ -2297,6 +2014,7 @@ var WamEffectGui = ({ plugin, className }) => {
|
|
|
2297
2014
|
cancelled = true;
|
|
2298
2015
|
if (gui) {
|
|
2299
2016
|
gui.remove();
|
|
2017
|
+
if (!pluginOwnsGui) return;
|
|
2300
2018
|
try {
|
|
2301
2019
|
(_a = plugin.destroyGui) == null ? void 0 : _a.call(plugin, gui);
|
|
2302
2020
|
} catch (destroyErr) {
|
|
@@ -2307,23 +2025,24 @@ var WamEffectGui = ({ plugin, className }) => {
|
|
|
2307
2025
|
}
|
|
2308
2026
|
};
|
|
2309
2027
|
}, [plugin]);
|
|
2310
|
-
return /* @__PURE__ */ (0,
|
|
2028
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: hostRef, className: className != null ? className : "wam-effect-gui" });
|
|
2311
2029
|
};
|
|
2312
2030
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2313
2031
|
0 && (module.exports = {
|
|
2314
2032
|
ExportWavButton,
|
|
2315
2033
|
WamEffectGui,
|
|
2034
|
+
createCustomEffectInstance,
|
|
2316
2035
|
createEffectChain,
|
|
2317
2036
|
createEffectInstance,
|
|
2318
2037
|
createWamEffectInstance,
|
|
2319
2038
|
effectCategories,
|
|
2320
2039
|
effectDefinitions,
|
|
2040
|
+
getAvailableEffects,
|
|
2321
2041
|
getEffectDefinition,
|
|
2322
2042
|
getEffectsByCategory,
|
|
2323
2043
|
loadWamModule,
|
|
2324
|
-
|
|
2044
|
+
useActiveEffects,
|
|
2325
2045
|
useDynamicEffects,
|
|
2326
|
-
useDynamicTracks,
|
|
2327
2046
|
useExportWav,
|
|
2328
2047
|
useMasterAnalyser,
|
|
2329
2048
|
useOutputMeter,
|