@dawcore/components 0.0.37 → 0.0.39-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/dist/index.js CHANGED
@@ -69,13 +69,10 @@ __export(index_exports, {
69
69
  RecordingController: () => RecordingController,
70
70
  SpectrogramController: () => SpectrogramController,
71
71
  TIME_DISPLAY_FORMATS: () => TIME_DISPLAY_FORMATS,
72
- createEffectInstance: () => createEffectInstance,
73
72
  formatDisplayTime: () => formatDisplayTime,
74
- getEffectDefinitions: () => getEffectDefinitions,
75
73
  isDomClip: () => isDomClip,
76
74
  isTimeDisplayFormat: () => isTimeDisplayFormat,
77
75
  parseDisplayTime: () => parseDisplayTime,
78
- registerEffect: () => registerEffect,
79
76
  resolveTransportTarget: () => resolveTransportTarget,
80
77
  splitAtPlayhead: () => splitAtPlayhead,
81
78
  targetSupports: () => targetSupports,
@@ -306,10 +303,7 @@ var DawAnnotationTrackElement = class extends import_lit2.LitElement {
306
303
  this._onKeyDownCapture = (e) => {
307
304
  if (!this.keyboardControls) return;
308
305
  if (e.repeat) return;
309
- const target = e.target;
310
- if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
311
- return;
312
- }
306
+ if ((0, import_core.keyBelongsToFocusedControl)(e)) return;
313
307
  const match = this._shortcutEntries().find((entry) => (0, import_core.matchesKeyBinding)(e, entry.binding));
314
308
  if (!match) return;
315
309
  const hasSelection = this._activeAnnotationId !== null;
@@ -1047,6 +1041,24 @@ DawClipElement = __decorateClass([
1047
1041
  // src/elements/daw-track.ts
1048
1042
  var import_lit5 = require("lit");
1049
1043
  var import_decorators5 = require("lit/decorators.js");
1044
+
1045
+ // src/types.ts
1046
+ function normalizeRenderMode(value) {
1047
+ if (value === null || value === void 0) return "waveform";
1048
+ if (value === "waveform" || value === "spectrogram" || value === "both") return value;
1049
+ console.warn(
1050
+ '[dawcore] render-mode="' + String(value) + '" is not a render mode (waveform or spectrogram); using waveform.' + (value === "piano-roll" ? ' A piano roll is how a MIDI track is drawn: set kind="midi" on the track.' : "")
1051
+ );
1052
+ return "waveform";
1053
+ }
1054
+ function trackDescriptorRenderMode(kind, requested) {
1055
+ return kind === "midi" ? "waveform" : requested;
1056
+ }
1057
+ function isDomClip(desc) {
1058
+ return desc.kind === "dom";
1059
+ }
1060
+
1061
+ // src/elements/daw-track.ts
1050
1062
  var DawTrackElement = class extends import_lit5.LitElement {
1051
1063
  constructor() {
1052
1064
  super(...arguments);
@@ -1056,6 +1068,7 @@ var DawTrackElement = class extends import_lit5.LitElement {
1056
1068
  this.pan = 0;
1057
1069
  this.muted = false;
1058
1070
  this.soloed = false;
1071
+ this._kind = "audio";
1059
1072
  this._renderMode = "waveform";
1060
1073
  this.spectrogramConfig = null;
1061
1074
  this.trackId = crypto.randomUUID();
@@ -1064,12 +1077,26 @@ var DawTrackElement = class extends import_lit5.LitElement {
1064
1077
  // cannot bubble events to ancestors).
1065
1078
  this._hasRendered = false;
1066
1079
  }
1080
+ get kind() {
1081
+ return this._kind;
1082
+ }
1083
+ set kind(value) {
1084
+ if (value !== "audio" && value !== "midi") {
1085
+ console.warn(
1086
+ '[dawcore] <daw-track kind="' + String(value) + `"> is not a track kind ('audio' or 'midi'); keeping "` + this._kind + '"'
1087
+ );
1088
+ return;
1089
+ }
1090
+ const old = this._kind;
1091
+ this._kind = value;
1092
+ this.requestUpdate("kind", old);
1093
+ }
1067
1094
  get renderMode() {
1068
1095
  return this._renderMode;
1069
1096
  }
1070
1097
  set renderMode(value) {
1071
1098
  const old = this._renderMode;
1072
- let next = value;
1099
+ let next = normalizeRenderMode(value);
1073
1100
  if (next === "both") {
1074
1101
  console.warn(
1075
1102
  `[dawcore] <daw-track render-mode="both"> is not yet supported; falling back to 'spectrogram'`
@@ -1169,6 +1196,7 @@ var DawTrackElement = class extends import_lit5.LitElement {
1169
1196
  "soloed",
1170
1197
  "src",
1171
1198
  "name",
1199
+ "kind",
1172
1200
  "renderMode",
1173
1201
  "spectrogramConfig"
1174
1202
  ];
@@ -1202,6 +1230,9 @@ __decorateClass([
1202
1230
  __decorateClass([
1203
1231
  (0, import_decorators5.property)({ type: Boolean })
1204
1232
  ], DawTrackElement.prototype, "soloed", 2);
1233
+ __decorateClass([
1234
+ (0, import_decorators5.property)({ reflect: true, noAccessor: true })
1235
+ ], DawTrackElement.prototype, "kind", 1);
1205
1236
  __decorateClass([
1206
1237
  (0, import_decorators5.property)({ attribute: "render-mode", noAccessor: true })
1207
1238
  ], DawTrackElement.prototype, "renderMode", 1);
@@ -1233,6 +1264,19 @@ function aggregatePeaks(data, bits, startIndex, endIndex) {
1233
1264
  }
1234
1265
  return { min: minPeak, max: maxPeak };
1235
1266
  }
1267
+ function clampToFullScale(value) {
1268
+ return Math.max(-1, Math.min(1, value));
1269
+ }
1270
+ function scalePeakByGain(peak, gain) {
1271
+ if (gain === 1 || !Number.isFinite(gain)) {
1272
+ return peak;
1273
+ }
1274
+ const factor = Math.abs(gain);
1275
+ return {
1276
+ min: clampToFullScale(peak.min * factor),
1277
+ max: clampToFullScale(peak.max * factor)
1278
+ };
1279
+ }
1236
1280
  function calculateBarRects(x, barWidth, halfHeight, minPeak, maxPeak, drawMode) {
1237
1281
  const min = Math.abs(minPeak * halfHeight);
1238
1282
  const max = Math.abs(maxPeak * halfHeight);
@@ -1274,7 +1318,8 @@ var LAYOUT_PROPS = /* @__PURE__ */ new Set([
1274
1318
  "barWidth",
1275
1319
  "barGap",
1276
1320
  "roundedBars",
1277
- "segments"
1321
+ "segments",
1322
+ "gain"
1278
1323
  ]);
1279
1324
  function groupDirtyByChunk(dirtyPixels, step, barWidth) {
1280
1325
  const dirtyByChunk = /* @__PURE__ */ new Map();
@@ -1314,6 +1359,7 @@ var DawWaveformElement = class extends import_lit6.LitElement {
1314
1359
  this.barWidth = 1;
1315
1360
  this.barGap = 0;
1316
1361
  this.roundedBars = false;
1362
+ this.gain = 1;
1317
1363
  this.visibleStart = -Infinity;
1318
1364
  this.visibleEnd = Infinity;
1319
1365
  this.originX = 0;
@@ -1426,8 +1472,9 @@ var DawWaveformElement = class extends import_lit6.LitElement {
1426
1472
  const barRadius = this.roundedBars ? this.barWidth / 2 : null;
1427
1473
  if (barRadius !== null) ctx.beginPath();
1428
1474
  for (let bar = Math.max(0, firstBar); bar < regionEnd; bar += step) {
1429
- const peak = aggregatePeaks(this._peaks, bits, bar, bar + step);
1430
- if (!peak) continue;
1475
+ const source = aggregatePeaks(this._peaks, bits, bar, bar + step);
1476
+ if (!source) continue;
1477
+ const peak = scalePeakByGain(source, this.gain);
1431
1478
  const rects = calculateBarRects(
1432
1479
  bar - globalOffset,
1433
1480
  this.barWidth,
@@ -1475,8 +1522,9 @@ var DawWaveformElement = class extends import_lit6.LitElement {
1475
1522
  const pxInSeg = px + globalOffset - seg.pixelStart;
1476
1523
  const peakPos = seg.peakStart + pxInSeg * peaksPerPixel;
1477
1524
  const peakEnd = peakPos + step * peaksPerPixel;
1478
- const peak = aggregatePeaks(this._peaks, bits, Math.floor(peakPos), Math.ceil(peakEnd));
1479
- if (!peak) continue;
1525
+ const source = aggregatePeaks(this._peaks, bits, Math.floor(peakPos), Math.ceil(peakEnd));
1526
+ if (!source) continue;
1527
+ const peak = scalePeakByGain(source, this.gain);
1480
1528
  const rects = calculateBarRects(
1481
1529
  px,
1482
1530
  this.barWidth,
@@ -1578,6 +1626,9 @@ __decorateClass([
1578
1626
  __decorateClass([
1579
1627
  (0, import_decorators6.property)({ type: Boolean, attribute: false })
1580
1628
  ], DawWaveformElement.prototype, "roundedBars", 2);
1629
+ __decorateClass([
1630
+ (0, import_decorators6.property)({ type: Number, attribute: false })
1631
+ ], DawWaveformElement.prototype, "gain", 2);
1581
1632
  __decorateClass([
1582
1633
  (0, import_decorators6.property)({ type: Number, attribute: false })
1583
1634
  ], DawWaveformElement.prototype, "visibleStart", 2);
@@ -2225,14 +2276,7 @@ DawStopButtonElement = __decorateClass([
2225
2276
  // src/elements/daw-editor.ts
2226
2277
  var import_lit19 = require("lit");
2227
2278
  var import_decorators16 = require("lit/decorators.js");
2228
-
2229
- // src/types.ts
2230
- function isDomClip(desc) {
2231
- return desc.kind === "dom";
2232
- }
2233
-
2234
- // src/elements/daw-editor.ts
2235
- var import_core12 = require("@waveform-playlist/core");
2279
+ var import_core16 = require("@waveform-playlist/core");
2236
2280
 
2237
2281
  // src/workers/peaksWorker.ts
2238
2282
  var import_waveform_data = __toESM(require("waveform-data"));
@@ -5569,7 +5613,7 @@ async function loadMidiImpl(host, source, options = {}) {
5569
5613
  parsed.tracks.map(
5570
5614
  (t) => host.addTrack({
5571
5615
  name: t.name,
5572
- renderMode: "piano-roll",
5616
+ kind: "midi",
5573
5617
  clips: [
5574
5618
  {
5575
5619
  midiNotes: t.notes,
@@ -5685,6 +5729,9 @@ function addRecordedClip(host, trackId, buf, startSample, durSamples, offsetSamp
5685
5729
  const sr = host.effectiveSampleRate;
5686
5730
  const clipDesc = {
5687
5731
  kind: "drop",
5732
+ // The take has no <daw-clip> element — the engine id is the only
5733
+ // handle updateClip()/removeClip() can address it by (#659).
5734
+ clipId: clip.id,
5688
5735
  src: "",
5689
5736
  peaksSrc: "",
5690
5737
  start: startSample / sr,
@@ -5711,6 +5758,15 @@ function addRecordedClip(host, trackId, buf, startSample, durSamples, offsetSamp
5711
5758
  } else {
5712
5759
  host._engine?.setTracks([...host._engineTracks.values()]);
5713
5760
  }
5761
+ if (host.isConnected) {
5762
+ host.dispatchEvent(
5763
+ new CustomEvent("daw-recording-clip-add", {
5764
+ bubbles: true,
5765
+ composed: true,
5766
+ detail: { trackId, clipId: clip.id }
5767
+ })
5768
+ );
5769
+ }
5714
5770
  }).catch((err) => {
5715
5771
  console.warn("[dawcore] Failed to generate peaks for recorded clip: " + String(err));
5716
5772
  const next = new Map(host._clipBuffers);
@@ -6107,37 +6163,92 @@ function loadFaustModule(feature) {
6107
6163
  return loadOptionalModule(() => import("@dawcore/faust"), "@dawcore/faust", feature);
6108
6164
  }
6109
6165
 
6166
+ // src/effects/effects-manager.ts
6167
+ var import_core13 = require("@waveform-playlist/core");
6168
+
6110
6169
  // src/effects/effect-registry.ts
6170
+ var import_core12 = require("@waveform-playlist/core");
6111
6171
  var MAX_DELAY_SECONDS = 10;
6112
- var registry = /* @__PURE__ */ new Map();
6113
- function registerEffect(type, definition) {
6114
- if (registry.has(type)) {
6115
- console.warn(
6116
- '[waveform-playlist] registerEffect: overwriting existing effect type "' + type + '"'
6117
- );
6118
- }
6119
- registry.set(type, definition);
6120
- }
6121
- function getEffectDefinitions() {
6122
- return new Map(registry);
6172
+ function singleNode(node, applyParams) {
6173
+ return { input: node, output: node, applyParams };
6123
6174
  }
6124
- function createEffectInstance(type, audioContext, params = {}) {
6125
- const definition = registry.get(type);
6126
- if (!definition) {
6127
- throw new Error(
6128
- '[waveform-playlist] createEffectInstance: unknown effect type "' + type + '". Available types: ' + [...registry.keys()].join(", ")
6129
- );
6175
+ var BIQUAD_PARAM_DEFS = {
6176
+ frequency: { min: 20, max: 2e4, step: 1, unit: "Hz" },
6177
+ q: { min: 0.1, max: 20, step: 0.1 },
6178
+ gain: { min: -24, max: 24, step: 0.5, unit: "dB" }
6179
+ };
6180
+ var RESONANCE_DB_PARAM_DEF = { min: -12, max: 24, step: 0.1, unit: "dB" };
6181
+ var BUTTERWORTH_RESONANCE_DB = -3;
6182
+ var BIQUAD_FILTERS = {
6183
+ // Unchanged since before #661 — including its q range, which predates the
6184
+ // dB reading above (q here is also resonance in dB; persisted chains rely
6185
+ // on these exact defaults and bounds).
6186
+ "native-filter": {
6187
+ label: "Lowpass Filter",
6188
+ biquadType: "lowpass",
6189
+ defaults: { frequency: 1e3, q: 1 }
6190
+ },
6191
+ "native-highpass": {
6192
+ label: "Highpass Filter",
6193
+ biquadType: "highpass",
6194
+ defaults: { frequency: 80, q: BUTTERWORTH_RESONANCE_DB },
6195
+ paramDefs: { q: RESONANCE_DB_PARAM_DEF }
6196
+ },
6197
+ "native-bandpass": {
6198
+ label: "Bandpass Filter",
6199
+ biquadType: "bandpass",
6200
+ defaults: { frequency: 1e3, q: 1 }
6201
+ },
6202
+ "native-notch": {
6203
+ label: "Notch Filter",
6204
+ biquadType: "notch",
6205
+ defaults: { frequency: 1e3, q: 1 }
6206
+ },
6207
+ "native-peaking": {
6208
+ label: "Peaking EQ",
6209
+ biquadType: "peaking",
6210
+ defaults: { frequency: 1e3, q: 1, gain: 0 }
6211
+ },
6212
+ "native-lowshelf": {
6213
+ label: "Low Shelf",
6214
+ biquadType: "lowshelf",
6215
+ defaults: { frequency: 200, gain: 0 }
6216
+ },
6217
+ "native-highshelf": {
6218
+ label: "High Shelf",
6219
+ biquadType: "highshelf",
6220
+ defaults: { frequency: 4e3, gain: 0 }
6130
6221
  }
6131
- const merged = { ...definition.defaults, ...params };
6132
- const instance = definition.create(audioContext, merged);
6133
- instance.applyParams(merged);
6134
- return { instance, params: merged, wetParam: definition.wetParam };
6222
+ };
6223
+ function biquadDefinition(spec) {
6224
+ const names = Object.keys(spec.defaults);
6225
+ return {
6226
+ label: spec.label,
6227
+ category: "filter",
6228
+ defaults: { ...spec.defaults },
6229
+ params: Object.fromEntries(
6230
+ names.map((name) => [name, spec.paramDefs?.[name] ?? BIQUAD_PARAM_DEFS[name]])
6231
+ ),
6232
+ create: (ctx) => {
6233
+ const node = ctx.createBiquadFilter();
6234
+ node.type = spec.biquadType;
6235
+ return singleNode(node, (p) => {
6236
+ if (names.includes("frequency") && p.frequency !== void 0) {
6237
+ node.frequency.value = p.frequency;
6238
+ }
6239
+ if (names.includes("q") && p.q !== void 0) node.Q.value = p.q;
6240
+ if (names.includes("gain") && p.gain !== void 0) node.gain.value = p.gain;
6241
+ });
6242
+ }
6243
+ };
6135
6244
  }
6136
- function singleNode(node, applyParams) {
6137
- return { input: node, output: node, applyParams };
6245
+ function registerBuiltIn(type, definition) {
6246
+ if (!(0, import_core12.getEffectDefinitions)().has(type)) {
6247
+ (0, import_core12.registerEffect)(type, { ...definition, builtIn: true });
6248
+ }
6138
6249
  }
6139
6250
  function registerBuiltIns() {
6140
- registry.set("native-gain", {
6251
+ registerBuiltIn("native-gain", {
6141
6252
  label: "Gain",
6142
6253
  category: "dynamics",
6143
6254
  defaults: { gain: 1 },
@@ -6149,24 +6260,10 @@ function registerBuiltIns() {
6149
6260
  });
6150
6261
  }
6151
6262
  });
6152
- registry.set("native-filter", {
6153
- label: "Lowpass Filter",
6154
- category: "filter",
6155
- defaults: { frequency: 1e3, q: 1 },
6156
- params: {
6157
- frequency: { min: 20, max: 2e4, step: 1, unit: "Hz" },
6158
- q: { min: 0.1, max: 20, step: 0.1 }
6159
- },
6160
- create: (ctx) => {
6161
- const node = ctx.createBiquadFilter();
6162
- node.type = "lowpass";
6163
- return singleNode(node, (p) => {
6164
- if (p.frequency !== void 0) node.frequency.value = p.frequency;
6165
- if (p.q !== void 0) node.Q.value = p.q;
6166
- });
6167
- }
6168
- });
6169
- registry.set("native-compressor", {
6263
+ for (const [type, definition] of Object.entries(BIQUAD_FILTERS)) {
6264
+ registerBuiltIn(type, biquadDefinition(definition));
6265
+ }
6266
+ registerBuiltIn("native-compressor", {
6170
6267
  label: "Compressor",
6171
6268
  category: "dynamics",
6172
6269
  defaults: { threshold: -24, knee: 30, ratio: 12, attack: 3e-3, release: 0.25 },
@@ -6188,7 +6285,7 @@ function registerBuiltIns() {
6188
6285
  });
6189
6286
  }
6190
6287
  });
6191
- registry.set("native-stereo-panner", {
6288
+ registerBuiltIn("native-stereo-panner", {
6192
6289
  label: "Stereo Panner",
6193
6290
  category: "spatial",
6194
6291
  defaults: { pan: 0 },
@@ -6200,7 +6297,7 @@ function registerBuiltIns() {
6200
6297
  });
6201
6298
  }
6202
6299
  });
6203
- registry.set("native-delay", {
6300
+ registerBuiltIn("native-delay", {
6204
6301
  label: "Delay",
6205
6302
  category: "delay",
6206
6303
  defaults: { delayTime: 0.25, feedback: 0.4, wet: 0.35 },
@@ -6299,6 +6396,11 @@ var EffectsManager = class {
6299
6396
  validateSerializedEntries(entries);
6300
6397
  await this._restoreChain(this._ensureMasterChain(), this._masterTarget, entries);
6301
6398
  }
6399
+ /** Run a registered effect's async `prepare` hook on the adapter's
6400
+ * context, so the synchronous addEffect() can create it. */
6401
+ async prepareEffect(type) {
6402
+ await (0, import_core13.prepareEffect)(type, this._requireWiring().audioContext);
6403
+ }
6302
6404
  // --- Track chains ---
6303
6405
  addTrackEffect(trackId, target, type, params) {
6304
6406
  const chain = this._ensureTrackChain(trackId);
@@ -6350,8 +6452,7 @@ var EffectsManager = class {
6350
6452
  const transport = this._getAdapter()?.transport;
6351
6453
  if (!transport) return;
6352
6454
  for (const [trackId, chain] of this._trackChains) {
6353
- transport.connectTrackOutput(trackId, chain.input);
6354
- chain.output.connect(transport.masterOutputNode);
6455
+ transport.connectTrackEffects(trackId, chain.input, chain.output);
6355
6456
  }
6356
6457
  }
6357
6458
  disposeTrackChain(trackId) {
@@ -6362,7 +6463,7 @@ var EffectsManager = class {
6362
6463
  this._destroyGui(entry.id);
6363
6464
  }
6364
6465
  try {
6365
- this._getAdapter()?.transport?.disconnectTrackOutput(trackId);
6466
+ this._getAdapter()?.transport?.disconnectTrackEffects(trackId);
6366
6467
  } catch (err) {
6367
6468
  console.warn(PREFIX2 + "EffectsManager: error disconnecting track output: " + String(err));
6368
6469
  }
@@ -6397,9 +6498,10 @@ var EffectsManager = class {
6397
6498
  );
6398
6499
  }
6399
6500
  const { audioContext, transport } = adapter;
6400
- if (!audioContext || !transport || typeof transport.connectTrackOutput !== "function") {
6501
+ if (!audioContext || !transport || typeof transport.connectTrackEffects !== "function") {
6502
+ const outdated = typeof transport?.connectTrackOutput === "function";
6401
6503
  throw new Error(
6402
- PREFIX2 + "the current adapter does not expose effects hooks (transport.connectTrackOutput / connectMasterOutput)."
6504
+ PREFIX2 + (outdated ? "the current adapter exposes the old post-fader effects hook (transport.connectTrackOutput). Track effects are pre-fader inserts now \u2014 upgrade @dawcore/transport (>= 0.0.16) or @waveform-playlist/playout (>= 13) for transport.connectTrackEffects." : "the current adapter does not expose effects hooks (transport.connectTrackEffects / connectMasterOutput).")
6403
6505
  );
6404
6506
  }
6405
6507
  return { audioContext, transport };
@@ -6478,7 +6580,9 @@ var EffectsManager = class {
6478
6580
  if (typeof instance.createGui === "function") {
6479
6581
  try {
6480
6582
  const element2 = await instance.createGui();
6481
- return makeGuiRecord(element2, () => instance.destroyGui?.(element2));
6583
+ if (element2 instanceof HTMLElement) {
6584
+ return makeGuiRecord(element2, () => instance.destroyGui?.(element2));
6585
+ }
6482
6586
  } catch (err) {
6483
6587
  console.warn(
6484
6588
  PREFIX2 + 'openEffectGui: plugin createGui failed for "' + effectId + '" \u2014 falling back to the generic parameter panel: ' + String(err)
@@ -6500,7 +6604,7 @@ var EffectsManager = class {
6500
6604
  this._runOp(chain, target, "setParams", effectId, { [paramId]: value });
6501
6605
  };
6502
6606
  if (entry.kind === "native") {
6503
- const definition = getEffectDefinitions().get(entry.type);
6607
+ const definition = (0, import_core13.getEffectDefinitions)().get(entry.type);
6504
6608
  if (!definition) {
6505
6609
  throw new Error(
6506
6610
  PREFIX2 + 'openEffectGui: no registry definition for effect type "' + entry.type + '"'
@@ -6553,14 +6657,13 @@ var EffectsManager = class {
6553
6657
  if (existing) return existing;
6554
6658
  const { audioContext, transport } = this._requireWiring();
6555
6659
  const chain = new EffectsChainController(audioContext);
6556
- transport.connectTrackOutput(trackId, chain.input);
6557
- chain.output.connect(transport.masterOutputNode);
6660
+ transport.connectTrackEffects(trackId, chain.input, chain.output);
6558
6661
  this._trackChains.set(trackId, chain);
6559
6662
  return chain;
6560
6663
  }
6561
6664
  _addToChain(chain, target, type, params) {
6562
6665
  const audioContext = this._requireWiring().audioContext;
6563
- const created = createEffectInstance(type, audioContext, params);
6666
+ const created = (0, import_core13.createEffectInstance)(type, audioContext, params);
6564
6667
  const effectId = chain.add({
6565
6668
  kind: "native",
6566
6669
  type,
@@ -6731,6 +6834,11 @@ var EffectsManager = class {
6731
6834
  if (superseded()) return;
6732
6835
  if (entry.kind === "native") {
6733
6836
  try {
6837
+ const liveContext = this._requireWiring().audioContext;
6838
+ if ((0, import_core13.needsPrepare)(entry.type, liveContext)) {
6839
+ await (0, import_core13.ensureEffectPrepared)(entry.type, liveContext);
6840
+ if (superseded() || chain.disposed) return;
6841
+ }
6734
6842
  const id = this._addToChain(chain, target, entry.type, entry.params);
6735
6843
  if (entry.bypassed) {
6736
6844
  this._runOp(chain, target, "setBypassed", id, true);
@@ -6903,6 +7011,8 @@ function toWamParameterMap(params) {
6903
7011
  }
6904
7012
 
6905
7013
  // src/interactions/export-audio.ts
7014
+ var import_core14 = require("@waveform-playlist/core");
7015
+ var import_core15 = require("@waveform-playlist/core");
6906
7016
  var PREFIX3 = "[waveform-playlist] ";
6907
7017
  async function exportAudioImpl(host, options = {}) {
6908
7018
  const sampleRate = options.sampleRate ?? host.effectiveSampleRate;
@@ -6937,13 +7047,13 @@ async function exportAudioImpl(host, options = {}) {
6937
7047
  cleanups.push(chain.dispose);
6938
7048
  const volume = ctx.createGain();
6939
7049
  volume.gain.value = track.volume;
6940
- const panner = ctx.createStereoPanner();
6941
- panner.pan.value = track.pan;
6942
- volume.connect(panner);
6943
- panner.connect(chain.input);
6944
- chain.output.connect(masterVolume);
7050
+ const panStage = (0, import_core14.createPanStage)(ctx, track.pan, (0, import_core14.trackChannelCount)(track));
7051
+ cleanups.push(panStage.dispose);
7052
+ chain.output.connect(volume);
7053
+ volume.connect(panStage.input);
7054
+ panStage.output.connect(masterVolume);
6945
7055
  for (const clip of track.clips) {
6946
- scheduleClip(ctx, clip, startTime, duration, volume);
7056
+ scheduleClip(ctx, clip, startTime, duration, chain.input);
6947
7057
  }
6948
7058
  }
6949
7059
  return await ctx.startRendering();
@@ -7019,12 +7129,13 @@ async function buildOfflineChain(ctx, entries) {
7019
7129
  continue;
7020
7130
  }
7021
7131
  if (entry.kind === "native") {
7022
- const created = createEffectInstance(entry.type, ctx, entry.params);
7023
- if (entry.bypassed) {
7024
- if (!created.wetParam) {
7025
- created.instance.dispose?.();
7026
- continue;
7027
- }
7132
+ const definition = (0, import_core15.getEffectDefinitions)().get(entry.type);
7133
+ if (entry.bypassed && definition && !definition.wetParam) {
7134
+ continue;
7135
+ }
7136
+ await (0, import_core15.ensureEffectPrepared)(entry.type, ctx);
7137
+ const created = (0, import_core15.createEffectInstance)(entry.type, ctx, entry.params);
7138
+ if (entry.bypassed && created.wetParam) {
7028
7139
  created.instance.applyParams({ [created.wetParam]: 0 });
7029
7140
  }
7030
7141
  if (created.instance.dispose) {
@@ -7310,6 +7421,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
7310
7421
  this.roundedBars = false;
7311
7422
  this.fileDrop = false;
7312
7423
  this.clipHeaders = false;
7424
+ this.gainScaledWaveforms = false;
7313
7425
  this.clipHeaderHeight = 20;
7314
7426
  this.interactiveClips = false;
7315
7427
  this.indefinitePlayback = false;
@@ -7337,11 +7449,11 @@ var DawEditorElement = class extends import_lit19.LitElement {
7337
7449
  this._selectionEndTime = 0;
7338
7450
  this._currentTime = 0;
7339
7451
  // Bounded-playback watermark for the current play(start, end) call
7340
- // (selection/annotation playback). The adapter's own auto-stop at
7341
- // endTime (e.g. native Transport's internal timer) tears down audio but
7342
- // never notifies isPlaying/daw-stop back up — the _startPlayhead rAF
7343
- // loop below is the sole place that detects reaching it, same pattern
7344
- // as the whole-track _duration check.
7452
+ // (selection/annotation playback). Adapters with the engine's
7453
+ // onPlaybackEnded hook (Tone, and native since #636) report their
7454
+ // endTime self-stop through the engine's `stop` event; this watermark is
7455
+ // the fallback check in the _startPlayhead loop for adapters without the
7456
+ // hook, same pattern as the whole-track _duration check.
7345
7457
  this._activePlayEndTime = null;
7346
7458
  this._externalAdapter = null;
7347
7459
  /** True after a disconnect disposed the consumer's adapter via the engine
@@ -7457,7 +7569,21 @@ var DawEditorElement = class extends import_lit19.LitElement {
7457
7569
  const trackEl = e.target.closest("daw-track");
7458
7570
  if (!trackEl) return;
7459
7571
  const oldDescriptor = this._tracks.get(trackId);
7460
- const descriptor = this._readTrackDescriptor(trackEl);
7572
+ let descriptor = this._readTrackDescriptor(trackEl);
7573
+ if (oldDescriptor && oldDescriptor.kind !== descriptor.kind) {
7574
+ console.warn(
7575
+ '[dawcore] <daw-track> "' + descriptor.name + '": kind cannot change after the track has loaded (still "' + oldDescriptor.kind + '"). Remove the track and add one of the other kind.'
7576
+ );
7577
+ descriptor = {
7578
+ ...descriptor,
7579
+ kind: oldDescriptor.kind,
7580
+ renderMode: trackDescriptorRenderMode(oldDescriptor.kind, trackEl.renderMode)
7581
+ };
7582
+ const keptKind = oldDescriptor.kind;
7583
+ queueMicrotask(() => {
7584
+ trackEl.kind = keptKind;
7585
+ });
7586
+ }
7461
7587
  this._tracks = new Map(this._tracks).set(trackId, descriptor);
7462
7588
  if (this._engine) {
7463
7589
  if (oldDescriptor?.volume !== descriptor.volume)
@@ -7859,6 +7985,16 @@ var DawEditorElement = class extends import_lit19.LitElement {
7859
7985
  }
7860
7986
  return this._effectsManager;
7861
7987
  }
7988
+ /**
7989
+ * Run a registered effect type's async `prepare` hook (e.g. an
7990
+ * `audioWorklet.addModule`) on this editor's audio context. Await it before
7991
+ * the synchronous `addEffect`/`addTrackEffect` for effect types that define
7992
+ * one; `setEffectsState()` and `exportAudio()` run it themselves. Idempotent
7993
+ * per context, and a no-op for types without a hook.
7994
+ */
7995
+ prepareEffect(type) {
7996
+ return this._effects.prepareEffect(type);
7997
+ }
7862
7998
  /** Master effects chain — inserted between the master bus and the destination. */
7863
7999
  addEffect(type, params) {
7864
8000
  return this._effects.addMasterEffect(type, params);
@@ -8394,7 +8530,8 @@ var DawEditorElement = class extends import_lit19.LitElement {
8394
8530
  pan: track.pan ?? 0,
8395
8531
  muted: track.muted ?? false,
8396
8532
  soloed: track.soloed ?? false,
8397
- renderMode: track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0) ? "piano-roll" : "waveform",
8533
+ kind: (0, import_core16.trackKind)(track),
8534
+ renderMode: trackDescriptorRenderMode((0, import_core16.trackKind)(track), "waveform"),
8398
8535
  clips: []
8399
8536
  });
8400
8537
  }
@@ -8405,10 +8542,50 @@ var DawEditorElement = class extends import_lit19.LitElement {
8405
8542
  next ?? (next = new Map(this._tracks));
8406
8543
  next.delete(trackId);
8407
8544
  }
8545
+ for (const track of tracks) {
8546
+ const desc = (next ?? this._tracks).get(track.id);
8547
+ if (!desc || !desc.clips.some((c) => !isDomClip(c) && c.clipId !== void 0)) continue;
8548
+ const reconciled = this._reconcileIdentifiedDropClips(desc.clips, track);
8549
+ if (reconciled === desc.clips) continue;
8550
+ next ?? (next = new Map(this._tracks));
8551
+ next.set(track.id, { ...desc, clips: reconciled });
8552
+ }
8408
8553
  if (next) {
8409
8554
  this._tracks = next;
8410
8555
  }
8411
8556
  }
8557
+ /** Prune id-bearing drop descriptors the engine no longer has, and refresh
8558
+ * the rest from their engine clip. Returns the SAME array when nothing
8559
+ * changed, so an unchanged track never triggers a re-render. */
8560
+ _reconcileIdentifiedDropClips(clips, track) {
8561
+ const engineClips = new Map(track.clips.map((c) => [c.id, c]));
8562
+ let changed = false;
8563
+ const result = [];
8564
+ for (const desc of clips) {
8565
+ if (isDomClip(desc) || desc.clipId === void 0) {
8566
+ result.push(desc);
8567
+ continue;
8568
+ }
8569
+ const clip = engineClips.get(desc.clipId);
8570
+ if (!clip) {
8571
+ changed = true;
8572
+ continue;
8573
+ }
8574
+ const sr = clip.sampleRate ?? this.effectiveSampleRate;
8575
+ const start = clip.startSample / sr;
8576
+ const duration = clip.durationSamples / sr;
8577
+ const offset = clip.offsetSamples / sr;
8578
+ const gain = clip.gain ?? desc.gain;
8579
+ const name = clip.name ?? desc.name;
8580
+ if (desc.start === start && desc.duration === duration && desc.offset === offset && desc.gain === gain && desc.name === name) {
8581
+ result.push(desc);
8582
+ continue;
8583
+ }
8584
+ changed = true;
8585
+ result.push({ ...desc, start, duration, offset, gain, name });
8586
+ }
8587
+ return changed ? result : clips;
8588
+ }
8412
8589
  _onClipRemovedFromDom(clipEl) {
8413
8590
  const clipId = clipEl.clipId;
8414
8591
  for (const [trackId, t] of this._engineTracks.entries()) {
@@ -8429,6 +8606,9 @@ var DawEditorElement = class extends import_lit19.LitElement {
8429
8606
  const clipId = clipDesc.clipId;
8430
8607
  let insertedClipId = null;
8431
8608
  try {
8609
+ const trackDesc = this._tracks.get(trackId);
8610
+ const kindError = trackDesc ? this._clipKindError(trackDesc.name, trackDesc.kind, false, clipDesc.name || clipDesc.src) : null;
8611
+ if (kindError) throw kindError;
8432
8612
  const waveformDataPromise = clipDesc.peaksSrc ? this._resolvePeaks(clipDesc.peaksSrc) : Promise.resolve(null);
8433
8613
  const audioPromise = this._fetchAndDecode(clipDesc.src);
8434
8614
  const [waveformData, audioBuffer] = await Promise.all([waveformDataPromise, audioPromise]);
@@ -8508,7 +8688,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
8508
8688
  let clip;
8509
8689
  if (waveformData) {
8510
8690
  const wdRate = waveformData.sample_rate;
8511
- clip = (0, import_core12.createClip)({
8691
+ clip = (0, import_core16.createClip)({
8512
8692
  audioBuffer,
8513
8693
  waveformData,
8514
8694
  startSample: Math.round(clipDesc.start * wdRate),
@@ -8521,7 +8701,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
8521
8701
  });
8522
8702
  this._peakPipeline.cacheWaveformData(audioBuffer, waveformData);
8523
8703
  } else {
8524
- clip = (0, import_core12.createClipFromSeconds)({
8704
+ clip = (0, import_core16.createClipFromSeconds)({
8525
8705
  audioBuffer,
8526
8706
  startTime: clipDesc.start,
8527
8707
  duration: clipDesc.duration || audioBuffer.duration,
@@ -8600,7 +8780,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
8600
8780
  const noteSpanSeconds = notes.length ? notes.reduce((max, n) => Math.max(max, n.time + n.duration), 0) : 0;
8601
8781
  const sourceDurationSamples = Math.ceil(Math.max(noteSpanSeconds, clipDesc.duration, 1) * sr);
8602
8782
  const requestedDurationSamples = clipDesc.duration > 0 ? Math.round(clipDesc.duration * sr) : sourceDurationSamples;
8603
- const clip = (0, import_core12.createClip)({
8783
+ const clip = (0, import_core16.createClip)({
8604
8784
  startSample: Math.round(clipDesc.start * sr),
8605
8785
  durationSamples: requestedDurationSamples,
8606
8786
  offsetSamples: Math.round(clipDesc.offset * sr),
@@ -8654,8 +8834,20 @@ var DawEditorElement = class extends import_lit19.LitElement {
8654
8834
  }
8655
8835
  const oldClip = t.clips[idx];
8656
8836
  const sr = oldClip.sampleRate ?? this.effectiveSampleRate;
8657
- const isMidiNow = clipEl.midiNotes != null;
8837
+ const isMidiNow = clipEl.midiNotes != null && !clipEl.src;
8658
8838
  const wasMidi = oldClip.midiNotes != null;
8839
+ if (isMidiNow && (0, import_core16.trackKind)(t) !== "midi") {
8840
+ const kindError = this._clipKindError(t.name, "audio", true, clipEl.name || clipId);
8841
+ console.warn("[dawcore] _applyClipUpdate: " + kindError?.message);
8842
+ this.dispatchEvent(
8843
+ new CustomEvent("daw-clip-error", {
8844
+ bubbles: true,
8845
+ composed: true,
8846
+ detail: { trackId, clipId, error: kindError }
8847
+ })
8848
+ );
8849
+ return;
8850
+ }
8659
8851
  if (isMidiNow || wasMidi) {
8660
8852
  const notes = this._validMidiNotes(clipEl.midiNotes ?? []);
8661
8853
  const noteSpanSeconds = notes.length ? notes.reduce((max, n) => Math.max(max, n.time + n.duration), 0) : 0;
@@ -8736,9 +8928,9 @@ var DawEditorElement = class extends import_lit19.LitElement {
8736
8928
  if (desc) {
8737
8929
  this._tracks = new Map(this._tracks).set(trackId, {
8738
8930
  ...desc,
8739
- // Only DOM-sourced clips have an id to match; drop-sourced clips are
8740
- // filtered through unchanged (their identity is the descriptor itself).
8741
- clips: desc.clips.filter((c) => !(isDomClip(c) && c.clipId === clipId))
8931
+ // Descriptors without an id (file drops, the <daw-track src>
8932
+ // shorthand) are kept — their identity is the descriptor itself.
8933
+ clips: desc.clips.filter((c) => c.clipId !== clipId)
8742
8934
  });
8743
8935
  }
8744
8936
  this._commitTrackChange(trackId, updatedTrack);
@@ -8791,18 +8983,55 @@ var DawEditorElement = class extends import_lit19.LitElement {
8791
8983
  pan: trackEl.pan,
8792
8984
  muted: trackEl.muted,
8793
8985
  soloed: trackEl.soloed,
8794
- renderMode: trackEl.renderMode,
8986
+ kind: trackEl.kind,
8987
+ renderMode: trackDescriptorRenderMode(trackEl.kind, trackEl.renderMode),
8795
8988
  clips
8796
8989
  };
8797
8990
  }
8991
+ /**
8992
+ * The error for a clip whose kind is not its track's (#756), or null. A clip
8993
+ * with no `src` is a MIDI clip (see _isMidiDescriptor).
8994
+ */
8995
+ _clipKindError(trackName, kind, clipIsMidi, clipLabel) {
8996
+ if (clipIsMidi === (kind === "midi")) return null;
8997
+ return new Error(
8998
+ clipIsMidi ? 'clip "' + clipLabel + '" is a MIDI clip (no src) on audio track "' + trackName + `". A track holds one kind of clip: set kind="midi" on the <daw-track> (or kind: 'midi' in addTrack) for a track of MIDI clips.` : 'clip "' + clipLabel + '" is an audio clip on MIDI track "' + trackName + '". A track holds one kind of clip: put the clip on an audio track.'
8999
+ );
9000
+ }
8798
9001
  // --- Audio Loading ---
8799
9002
  async _loadTrack(trackId, descriptor) {
8800
9003
  this._loadingTracks.add(trackId);
8801
9004
  const sppAtLoadStart = this._samplesPerPixel;
8802
9005
  try {
8803
9006
  const clips = [];
9007
+ let refusedMidiClips = 0;
8804
9008
  for (const clipDesc of descriptor.clips) {
8805
- if (this._isMidiDescriptor(clipDesc)) {
9009
+ const clipIsMidi = this._isMidiDescriptor(clipDesc);
9010
+ const kindError = this._clipKindError(
9011
+ descriptor.name,
9012
+ descriptor.kind,
9013
+ clipIsMidi,
9014
+ clipDesc.name || clipDesc.src || (isDomClip(clipDesc) ? clipDesc.clipId : "")
9015
+ );
9016
+ if (kindError) {
9017
+ console.warn("[dawcore] _loadTrack: " + kindError.message);
9018
+ if (this.isConnected) {
9019
+ this.dispatchEvent(
9020
+ new CustomEvent("daw-clip-error", {
9021
+ bubbles: true,
9022
+ composed: true,
9023
+ detail: {
9024
+ trackId,
9025
+ clipId: isDomClip(clipDesc) ? clipDesc.clipId : "",
9026
+ error: kindError
9027
+ }
9028
+ })
9029
+ );
9030
+ }
9031
+ if (clipIsMidi) refusedMidiClips++;
9032
+ continue;
9033
+ }
9034
+ if (clipIsMidi) {
8806
9035
  clips.push(this._buildMidiClip(clipDesc));
8807
9036
  continue;
8808
9037
  }
@@ -8812,7 +9041,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
8812
9041
  const waveformData = await waveformDataPromise;
8813
9042
  if (waveformData) {
8814
9043
  const wdRate = waveformData.sample_rate;
8815
- const clip2 = (0, import_core12.createClip)({
9044
+ const clip2 = (0, import_core16.createClip)({
8816
9045
  waveformData,
8817
9046
  startSample: Math.round(clipDesc.start * wdRate),
8818
9047
  durationSamples: Math.round((clipDesc.duration || waveformData.duration) * wdRate),
@@ -8838,8 +9067,9 @@ var DawEditorElement = class extends import_lit19.LitElement {
8838
9067
  this._peaksData = new Map(this._peaksData).set(clip2.id, peakData);
8839
9068
  this._raiseZoomFloor(waveformData.scale);
8840
9069
  if (this._tracks.has(trackId)) {
8841
- const previewTrack = (0, import_core12.createTrack)({
9070
+ const previewTrack = (0, import_core16.createTrack)({
8842
9071
  name: descriptor.name,
9072
+ kind: descriptor.kind,
8843
9073
  clips: [clip2],
8844
9074
  volume: descriptor.volume,
8845
9075
  pan: descriptor.pan,
@@ -8915,15 +9145,16 @@ var DawEditorElement = class extends import_lit19.LitElement {
8915
9145
  trackWasRemoved ? "removed" : "disconnected"
8916
9146
  );
8917
9147
  }
8918
- const track = (0, import_core12.createTrack)({
9148
+ const track = (0, import_core16.createTrack)({
8919
9149
  name: descriptor.name,
9150
+ kind: descriptor.kind,
8920
9151
  clips,
8921
9152
  volume: descriptor.volume,
8922
9153
  pan: descriptor.pan,
8923
9154
  muted: descriptor.muted,
8924
9155
  soloed: descriptor.soloed
8925
9156
  });
8926
- const requestedClips = descriptor.clips.filter((c) => c.src).length;
9157
+ const requestedClips = descriptor.clips.filter((c) => c.src).length + refusedMidiClips;
8927
9158
  if (requestedClips > 0 && clips.length === 0) {
8928
9159
  throw new Error(
8929
9160
  "all " + requestedClips + " clip(s) failed to load \u2014 see prior daw-clip-error events"
@@ -9068,10 +9299,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
9068
9299
  this._syncDomToEngineOrder(engineState.tracks);
9069
9300
  }
9070
9301
  this._effectsManager?.rewireTrackChains();
9071
- const audioTracks = engineState.tracks.filter((t) => {
9072
- const desc = this._tracks.get(t.id);
9073
- return desc?.renderMode !== "piano-roll";
9074
- });
9302
+ const audioTracks = engineState.tracks.filter((t) => (0, import_core16.trackKind)(t) !== "midi");
9075
9303
  syncPeaksForChangedClips(this, audioTracks);
9076
9304
  }
9077
9305
  if (engineState.bpm !== this._lastAnnotationBpm) {
@@ -9171,8 +9399,9 @@ var DawEditorElement = class extends import_lit19.LitElement {
9171
9399
  if (config.pan !== void 0) trackEl.pan = config.pan;
9172
9400
  if (config.muted) trackEl.setAttribute("muted", "");
9173
9401
  if (config.soloed) trackEl.setAttribute("soloed", "");
9174
- const renderMode = config.renderMode ?? (config.midi ? "piano-roll" : void 0);
9175
- if (renderMode !== void 0) trackEl.setAttribute("render-mode", renderMode);
9402
+ const kind = config.kind ?? (config.midi ? "midi" : void 0);
9403
+ if (kind !== void 0) trackEl.setAttribute("kind", kind);
9404
+ if (config.renderMode !== void 0) trackEl.setAttribute("render-mode", config.renderMode);
9176
9405
  const clipConfigs = [...config.clips ?? []];
9177
9406
  if (config.midi) {
9178
9407
  clipConfigs.push({
@@ -9260,7 +9489,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
9260
9489
  }
9261
9490
  const oldDesc = this._tracks.get(trackId);
9262
9491
  if (!oldDesc) return;
9263
- let normalizedRenderMode = partial.renderMode;
9492
+ let normalizedRenderMode = partial.renderMode === void 0 ? void 0 : normalizeRenderMode(partial.renderMode);
9264
9493
  if (normalizedRenderMode === "both") {
9265
9494
  console.warn(
9266
9495
  `[dawcore] render-mode="both" is not yet supported; falling back to 'spectrogram'`
@@ -9274,7 +9503,9 @@ var DawEditorElement = class extends import_lit19.LitElement {
9274
9503
  ...partial.pan !== void 0 && { pan: partial.pan },
9275
9504
  ...partial.muted !== void 0 && { muted: partial.muted },
9276
9505
  ...partial.soloed !== void 0 && { soloed: partial.soloed },
9277
- ...normalizedRenderMode !== void 0 && { renderMode: normalizedRenderMode }
9506
+ ...normalizedRenderMode !== void 0 && {
9507
+ renderMode: trackDescriptorRenderMode(oldDesc.kind, normalizedRenderMode)
9508
+ }
9278
9509
  };
9279
9510
  this._tracks = new Map(this._tracks).set(trackId, newDesc);
9280
9511
  if (this._engine) {
@@ -9395,6 +9626,22 @@ var DawEditorElement = class extends import_lit19.LitElement {
9395
9626
  updatedClips[idx] = updatedClip;
9396
9627
  const updatedTrack = { ...t, clips: updatedClips };
9397
9628
  this._engineTracks = new Map(this._engineTracks).set(trackId, updatedTrack);
9629
+ const desc = this._tracks.get(trackId);
9630
+ if (desc?.clips.some((c) => c.clipId === clipId)) {
9631
+ this._tracks = new Map(this._tracks).set(trackId, {
9632
+ ...desc,
9633
+ clips: desc.clips.map(
9634
+ (c) => c.clipId === clipId ? {
9635
+ ...c,
9636
+ start: updatedClip.startSample / sr,
9637
+ duration: updatedClip.durationSamples / sr,
9638
+ offset: updatedClip.offsetSamples / sr,
9639
+ ...partial.gain !== void 0 && { gain: partial.gain },
9640
+ ...partial.name !== void 0 && { name: partial.name }
9641
+ } : c
9642
+ )
9643
+ });
9644
+ }
9398
9645
  this._commitTrackChange(trackId, updatedTrack);
9399
9646
  }
9400
9647
  _buildClipElement(config) {
@@ -9647,6 +9894,22 @@ var DawEditorElement = class extends import_lit19.LitElement {
9647
9894
  console.warn("[dawcore] startRecording: no stream provided and recordingStream is null");
9648
9895
  return;
9649
9896
  }
9897
+ const targetId = options?.trackId ?? this._selectedTrackId;
9898
+ const target = targetId ? this._tracks.get(targetId) : void 0;
9899
+ if (targetId && target?.kind === "midi") {
9900
+ const error = new Error(
9901
+ 'Cannot record onto MIDI track "' + target.name + '": a recording is audio. Select or create an audio track first.'
9902
+ );
9903
+ console.warn("[dawcore] startRecording: " + error.message);
9904
+ this.dispatchEvent(
9905
+ new CustomEvent("daw-recording-error", {
9906
+ bubbles: true,
9907
+ composed: true,
9908
+ detail: { trackId: targetId, error }
9909
+ })
9910
+ );
9911
+ return;
9912
+ }
9650
9913
  await this._recordingController.startRecording(s, options);
9651
9914
  }
9652
9915
  /** Live-recording preview left/width. Beats mode uses the same tick-space
@@ -9945,7 +10208,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
9945
10208
  width = Math.round(endTick / this.ticksPerPixel) - clipLeft;
9946
10209
  } else {
9947
10210
  clipLeft = Math.floor(clip.startSample / spp);
9948
- width = (0, import_core12.clipPixelWidth)(clip.startSample, clip.durationSamples, spp);
10211
+ width = (0, import_core16.clipPixelWidth)(clip.startSample, clip.durationSamples, spp);
9949
10212
  }
9950
10213
  let clipSegments;
9951
10214
  let segmentChannels;
@@ -10005,7 +10268,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
10005
10268
  >
10006
10269
  <span>${clip.name || t.descriptor?.name || ""}</span>
10007
10270
  </div>` : ""}
10008
- ${t.descriptor?.renderMode === "piano-roll" ? import_lit19.html`<daw-piano-roll
10271
+ ${t.descriptor?.kind === "midi" ? import_lit19.html`<daw-piano-roll
10009
10272
  style="position:absolute;left:0;top:${hdrH}px;"
10010
10273
  .midiNotes=${clip.midiNotes ?? []}
10011
10274
  .length=${peakData?.length ?? width}
@@ -10041,6 +10304,7 @@ var DawEditorElement = class extends import_lit19.LitElement {
10041
10304
  .barWidth=${this.barWidth}
10042
10305
  .barGap=${this.barGap}
10043
10306
  .roundedBars=${this.roundedBars}
10307
+ .gain=${this.gainScaledWaveforms ? clip.gain ?? 1 : 1}
10044
10308
  .visibleStart=${this._viewport.visibleStart}
10045
10309
  .visibleEnd=${this._viewport.visibleEnd}
10046
10310
  .originX=${clipLeft}
@@ -10248,6 +10512,9 @@ __decorateClass([
10248
10512
  __decorateClass([
10249
10513
  (0, import_decorators16.property)({ type: Boolean, attribute: "clip-headers" })
10250
10514
  ], DawEditorElement.prototype, "clipHeaders", 2);
10515
+ __decorateClass([
10516
+ (0, import_decorators16.property)({ type: Boolean, attribute: "gain-scaled-waveforms" })
10517
+ ], DawEditorElement.prototype, "gainScaledWaveforms", 2);
10251
10518
  __decorateClass([
10252
10519
  (0, import_decorators16.property)({ type: Number, attribute: "clip-header-height" })
10253
10520
  ], DawEditorElement.prototype, "clipHeaderHeight", 2);
@@ -10466,7 +10733,7 @@ DawRecordButtonElement = __decorateClass([
10466
10733
  // src/elements/daw-keyboard-shortcuts.ts
10467
10734
  var import_lit22 = require("lit");
10468
10735
  var import_decorators19 = require("lit/decorators.js");
10469
- var import_core13 = require("@waveform-playlist/core");
10736
+ var import_core17 = require("@waveform-playlist/core");
10470
10737
  var DawKeyboardShortcutsElement = class extends import_lit22.LitElement {
10471
10738
  constructor() {
10472
10739
  super(...arguments);
@@ -10491,7 +10758,7 @@ var DawKeyboardShortcutsElement = class extends import_lit22.LitElement {
10491
10758
  const shortcuts = this.shortcuts;
10492
10759
  if (shortcuts.length === 0) return;
10493
10760
  try {
10494
- (0, import_core13.handleKeyboardEvent)(e, shortcuts, true);
10761
+ (0, import_core17.handleKeyboardEvent)(e, shortcuts, true);
10495
10762
  } catch (err) {
10496
10763
  console.warn("[dawcore] Keyboard shortcut failed (key=" + e.key + "): " + String(err));
10497
10764
  const target = this._editor ?? this;
@@ -10681,7 +10948,7 @@ DawKeyboardShortcutsElement = __decorateClass([
10681
10948
  // src/elements/daw-spectrogram.ts
10682
10949
  var import_lit23 = require("lit");
10683
10950
  var import_decorators20 = require("lit/decorators.js");
10684
- var import_core14 = require("@waveform-playlist/core");
10951
+ var import_core18 = require("@waveform-playlist/core");
10685
10952
  var DawSpectrogramElement = class extends import_lit23.LitElement {
10686
10953
  constructor() {
10687
10954
  super(...arguments);
@@ -10746,11 +11013,11 @@ var DawSpectrogramElement = class extends import_lit23.LitElement {
10746
11013
  this._unregisterAllCanvases();
10747
11014
  this._canvases = [];
10748
11015
  if (this.length <= 0) return;
10749
- const chunkCount = Math.ceil(this.length / import_core14.MAX_CANVAS_WIDTH);
11016
+ const chunkCount = Math.ceil(this.length / import_core18.MAX_CANVAS_WIDTH);
10750
11017
  for (let i = 0; i < chunkCount; i++) {
10751
- const widthPx = Math.min(import_core14.MAX_CANVAS_WIDTH, this.length - i * import_core14.MAX_CANVAS_WIDTH);
11018
+ const widthPx = Math.min(import_core18.MAX_CANVAS_WIDTH, this.length - i * import_core18.MAX_CANVAS_WIDTH);
10752
11019
  const canvas = document.createElement("canvas");
10753
- canvas.style.left = i * import_core14.MAX_CANVAS_WIDTH + "px";
11020
+ canvas.style.left = i * import_core18.MAX_CANVAS_WIDTH + "px";
10754
11021
  canvas.style.width = widthPx + "px";
10755
11022
  const dpr = window.devicePixelRatio || 1;
10756
11023
  canvas.width = widthPx * dpr;
@@ -10776,7 +11043,7 @@ var DawSpectrogramElement = class extends import_lit23.LitElement {
10776
11043
  }
10777
11044
  for (let i = 0; i < this._canvases.length; i++) {
10778
11045
  const canvas = this._canvases[i];
10779
- const canvasId = (0, import_core14.buildSpectrogramCanvasId)({
11046
+ const canvasId = (0, import_core18.buildSpectrogramCanvasId)({
10780
11047
  clipId: this.clipId,
10781
11048
  channelIndex: this.channelIndex,
10782
11049
  chunkIndex: i
@@ -10797,7 +11064,7 @@ var DawSpectrogramElement = class extends import_lit23.LitElement {
10797
11064
  trackId: this.trackId,
10798
11065
  channelIndex: this.channelIndex,
10799
11066
  chunkIndex: i,
10800
- globalPixelOffset: this.originX + i * import_core14.MAX_CANVAS_WIDTH,
11067
+ globalPixelOffset: this.originX + i * import_core18.MAX_CANVAS_WIDTH,
10801
11068
  widthPx: parseFloat(canvas.style.width),
10802
11069
  heightPx: this.waveHeight
10803
11070
  });
@@ -11435,13 +11702,10 @@ DawPlayerElement = __decorateClass([
11435
11702
  RecordingController,
11436
11703
  SpectrogramController,
11437
11704
  TIME_DISPLAY_FORMATS,
11438
- createEffectInstance,
11439
11705
  formatDisplayTime,
11440
- getEffectDefinitions,
11441
11706
  isDomClip,
11442
11707
  isTimeDisplayFormat,
11443
11708
  parseDisplayTime,
11444
- registerEffect,
11445
11709
  resolveTransportTarget,
11446
11710
  splitAtPlayhead,
11447
11711
  targetSupports,