@dawcore/components 0.0.26 → 0.0.27

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.mjs CHANGED
@@ -203,11 +203,11 @@ var DawTrackElement = class extends LitElement2 {
203
203
  }
204
204
  // --- Effects API (delegates to the owning <daw-editor>) ---
205
205
  addEffect(type, params) {
206
- return this._effectsEditor()._trackAddEffect(this.trackId, this, type, params);
206
+ return this._effectsEditor().addTrackEffect(this.trackId, type, params);
207
207
  }
208
208
  /** Load a WAM plugin (via the optional @dawcore/wam peer) into this track's chain. */
209
209
  addWamPlugin(url, initialState) {
210
- return this._effectsEditor()._trackAddWamPlugin(this.trackId, this, url, initialState);
210
+ return this._effectsEditor().addTrackWamPlugin(this.trackId, url, initialState);
211
211
  }
212
212
  /**
213
213
  * Compile Faust DSP source in the browser (via the optional @dawcore/faust
@@ -215,16 +215,16 @@ var DawTrackElement = class extends LitElement2 {
215
215
  * keep their Faust line/column diagnostics and leave the chain untouched.
216
216
  */
217
217
  addFaustEffect(dspCode, options) {
218
- return this._effectsEditor()._trackAddFaustEffect(this.trackId, this, dspCode, options);
218
+ return this._effectsEditor().addTrackFaustEffect(this.trackId, dspCode, options);
219
219
  }
220
220
  /** Snapshot this track's chain in its persisted form (see dawcore README). */
221
221
  getEffectsState() {
222
222
  const editor = this.closest("daw-editor");
223
- return editor?._trackGetEffectsState(this.trackId) ?? Promise.resolve([]);
223
+ return editor?.getTrackEffectsState(this.trackId) ?? Promise.resolve([]);
224
224
  }
225
225
  /** Replace this track's chain with a persisted snapshot. */
226
226
  setEffectsState(entries) {
227
- return this._effectsEditor()._trackSetEffectsState(this.trackId, this, entries);
227
+ return this._effectsEditor().setTrackEffectsState(this.trackId, entries);
228
228
  }
229
229
  /**
230
230
  * Open (lazily creating) the GUI for one of this track's effects into a
@@ -232,27 +232,27 @@ var DawTrackElement = class extends LitElement2 {
232
232
  * the element is cached for reopen. See <daw-editor>.openEffectGui.
233
233
  */
234
234
  openEffectGui(effectId, container) {
235
- return this._effectsEditor()._trackOpenEffectGui(this.trackId, this, effectId, container);
235
+ return this._effectsEditor().openTrackEffectGui(this.trackId, effectId, container);
236
236
  }
237
237
  /** Hide an effect's GUI (cached for reopen — never destroys). */
238
238
  closeEffectGui(effectId) {
239
- this._effectsEditor()._trackCloseEffectGui(this.trackId, effectId);
239
+ this._effectsEditor().closeTrackEffectGui(this.trackId, effectId);
240
240
  }
241
241
  removeEffect(effectId) {
242
- this._effectsEditor()._trackEffectOp(this.trackId, this, "remove", effectId);
242
+ this._effectsEditor().removeTrackEffect(this.trackId, effectId);
243
243
  }
244
244
  setEffectParams(effectId, params) {
245
- this._effectsEditor()._trackEffectOp(this.trackId, this, "setParams", effectId, params);
245
+ this._effectsEditor().setTrackEffectParams(this.trackId, effectId, params);
246
246
  }
247
247
  setEffectBypassed(effectId, bypassed) {
248
- this._effectsEditor()._trackEffectOp(this.trackId, this, "setBypassed", effectId, bypassed);
248
+ this._effectsEditor().setTrackEffectBypassed(this.trackId, effectId, bypassed);
249
249
  }
250
250
  moveEffect(effectId, newIndex) {
251
- this._effectsEditor()._trackEffectOp(this.trackId, this, "move", effectId, newIndex);
251
+ this._effectsEditor().moveTrackEffect(this.trackId, effectId, newIndex);
252
252
  }
253
253
  get effects() {
254
254
  const editor = this.closest("daw-editor");
255
- return editor?._trackEffects(this.trackId) ?? [];
255
+ return editor?.trackEffects(this.trackId) ?? [];
256
256
  }
257
257
  _effectsEditor() {
258
258
  const editor = this.closest("daw-editor");
@@ -6073,38 +6073,92 @@ var DawEditorElement = class extends LitElement11 {
6073
6073
  duration: this._duration,
6074
6074
  tracks: [...this._engineTracks.values()],
6075
6075
  getMasterEffectsState: () => this.getEffectsState(),
6076
- getTrackEffectsState: (trackId) => this._trackGetEffectsState(trackId)
6076
+ getTrackEffectsState: (trackId) => this.getTrackEffectsState(trackId)
6077
6077
  },
6078
6078
  options
6079
6079
  );
6080
6080
  }
6081
- /** Internal — <daw-track> effects API delegates here (dawcore-internal contract). */
6082
- _trackAddEffect(trackId, target, type, params) {
6083
- return this._effects.addTrackEffect(trackId, target, type, params);
6081
+ // --- Per-track effects API (public, keyed by trackId) ---
6082
+ // Mirrors the master-chain methods above and the <daw-track> element methods,
6083
+ // but addresses a track by id so element-less tracks (drag-dropped, or
6084
+ // programmatic tracks the consumer doesn't hold an element for) can carry
6085
+ // their own insert chain. Effect events dispatch from the track's <daw-track>
6086
+ // element when one exists, else from the editor (see _trackEventTarget).
6087
+ /** Add a native registry effect to a track's chain. */
6088
+ addTrackEffect(trackId, type, params) {
6089
+ return this._effects.addTrackEffect(trackId, this._trackEventTarget(trackId), type, params);
6090
+ }
6091
+ /** Snapshot of a track's effect chain (empty array for an unknown track). */
6092
+ trackEffects(trackId) {
6093
+ return this._effectsManager?.trackEffects(trackId) ?? [];
6084
6094
  }
6085
- _trackEffectOp(trackId, target, op, effectId, arg) {
6086
- this._effects.trackOp(trackId, target, op, effectId, arg);
6095
+ removeTrackEffect(trackId, effectId) {
6096
+ this._effects.trackOp(trackId, this._trackEventTarget(trackId), "remove", effectId);
6087
6097
  }
6088
- _trackEffects(trackId) {
6089
- return this._effectsManager?.trackEffects(trackId) ?? [];
6098
+ setTrackEffectParams(trackId, effectId, params) {
6099
+ this._effects.trackOp(trackId, this._trackEventTarget(trackId), "setParams", effectId, params);
6090
6100
  }
6091
- _trackAddWamPlugin(trackId, target, url, initialState) {
6092
- return this._effects.addTrackWamPlugin(trackId, target, url, initialState);
6101
+ setTrackEffectBypassed(trackId, effectId, bypassed) {
6102
+ this._effects.trackOp(
6103
+ trackId,
6104
+ this._trackEventTarget(trackId),
6105
+ "setBypassed",
6106
+ effectId,
6107
+ bypassed
6108
+ );
6093
6109
  }
6094
- _trackAddFaustEffect(trackId, target, dspCode, options) {
6095
- return this._effects.addTrackFaustEffect(trackId, target, dspCode, options);
6110
+ moveTrackEffect(trackId, effectId, newIndex) {
6111
+ this._effects.trackOp(trackId, this._trackEventTarget(trackId), "move", effectId, newIndex);
6096
6112
  }
6097
- _trackOpenEffectGui(trackId, target, effectId, container) {
6098
- return this._effects.openTrackEffectGui(trackId, target, effectId, container);
6113
+ /** Load a WAM plugin (via the optional @dawcore/wam peer) into a track's chain. */
6114
+ addTrackWamPlugin(trackId, url, initialState) {
6115
+ return this._effects.addTrackWamPlugin(
6116
+ trackId,
6117
+ this._trackEventTarget(trackId),
6118
+ url,
6119
+ initialState
6120
+ );
6121
+ }
6122
+ /** Compile Faust DSP (via the optional @dawcore/faust peer) into a track's chain. */
6123
+ addTrackFaustEffect(trackId, dspCode, options) {
6124
+ return this._effects.addTrackFaustEffect(
6125
+ trackId,
6126
+ this._trackEventTarget(trackId),
6127
+ dspCode,
6128
+ options
6129
+ );
6130
+ }
6131
+ /** Open (lazily creating) the GUI for a track-chain effect into a container. */
6132
+ openTrackEffectGui(trackId, effectId, container) {
6133
+ return this._effects.openTrackEffectGui(
6134
+ trackId,
6135
+ this._trackEventTarget(trackId),
6136
+ effectId,
6137
+ container
6138
+ );
6099
6139
  }
6100
- _trackCloseEffectGui(_trackId, effectId) {
6140
+ /** Hide a track-chain effect's GUI (cached for reopen — never destroys). */
6141
+ closeTrackEffectGui(_trackId, effectId) {
6101
6142
  this._effects.closeEffectGui(effectId);
6102
6143
  }
6103
- _trackGetEffectsState(trackId) {
6144
+ /** Snapshot a track's chain in its persisted form (see dawcore README). */
6145
+ getTrackEffectsState(trackId) {
6104
6146
  return this._effectsManager?.getTrackEffectsState(trackId) ?? Promise.resolve([]);
6105
6147
  }
6106
- _trackSetEffectsState(trackId, target, entries) {
6107
- return this._effects.setTrackEffectsState(trackId, target, entries);
6148
+ /** Replace a track's chain from a persisted snapshot. */
6149
+ setTrackEffectsState(trackId, entries) {
6150
+ return this._effects.setTrackEffectsState(trackId, this._trackEventTarget(trackId), entries);
6151
+ }
6152
+ /**
6153
+ * Event-dispatch source for a per-track effect op: the track's `<daw-track>`
6154
+ * element when one exists (so `daw-effect-*` bubble from it exactly as the
6155
+ * element-method path does), else the editor itself for element-less tracks
6156
+ * (drag-dropped / programmatic). Reads the `_trackElements` index the editor
6157
+ * already maintains across the track connect/remove lifecycle — O(1), and the
6158
+ * same resolution `removeTrack` uses — rather than re-querying the DOM per op.
6159
+ */
6160
+ _trackEventTarget(trackId) {
6161
+ return this._trackElements.get(trackId) ?? this;
6108
6162
  }
6109
6163
  get audioContext() {
6110
6164
  if (!this._externalAdapter) {
@@ -6215,7 +6269,10 @@ var DawEditorElement = class extends LitElement11 {
6215
6269
  this._selectedTrackId = trackId;
6216
6270
  }
6217
6271
  get tracks() {
6218
- return [...this._tracks.values()];
6272
+ return [...this._tracks.entries()].map(([trackId, descriptor]) => ({
6273
+ trackId,
6274
+ ...descriptor
6275
+ }));
6219
6276
  }
6220
6277
  get selectedTrackId() {
6221
6278
  return this._selectedTrackId;
@@ -6353,6 +6410,7 @@ var DawEditorElement = class extends LitElement11 {
6353
6410
  }
6354
6411
  }
6355
6412
  _onTrackRemoved(trackId) {
6413
+ const existed = this._tracks.has(trackId);
6356
6414
  this._trackElements.delete(trackId);
6357
6415
  this._effectsManager?.disposeTrackChain(trackId);
6358
6416
  const removedTrack = this._engineTracks.get(trackId);
@@ -6382,6 +6440,15 @@ var DawEditorElement = class extends LitElement11 {
6382
6440
  this._currentTime = 0;
6383
6441
  this._stopPlayhead();
6384
6442
  }
6443
+ if (existed && this.isConnected) {
6444
+ this.dispatchEvent(
6445
+ new CustomEvent("daw-track-removed", {
6446
+ bubbles: true,
6447
+ composed: true,
6448
+ detail: { trackId }
6449
+ })
6450
+ );
6451
+ }
6385
6452
  }
6386
6453
  /** Drop the controller when no spectrogram tracks remain. */
6387
6454
  _disposeSpectrogramControllerIfEmpty() {