@dawcore/components 0.0.24 → 0.0.26

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
@@ -53,18 +53,29 @@ __export(index_exports, {
53
53
  DawSelectionElement: () => DawSelectionElement,
54
54
  DawSpectrogramElement: () => DawSpectrogramElement,
55
55
  DawStopButtonElement: () => DawStopButtonElement,
56
+ DawTimeDisplayElement: () => DawTimeDisplayElement,
57
+ DawTimeFormatElement: () => DawTimeFormatElement,
56
58
  DawTrackControlsElement: () => DawTrackControlsElement,
57
59
  DawTrackElement: () => DawTrackElement,
58
60
  DawTransportButton: () => DawTransportButton,
59
61
  DawTransportElement: () => DawTransportElement,
60
62
  DawWaveformElement: () => DawWaveformElement,
63
+ PlaybackAnimationController: () => PlaybackAnimationController,
61
64
  RecordingController: () => RecordingController,
62
65
  SpectrogramController: () => SpectrogramController,
66
+ TIME_DISPLAY_FORMATS: () => TIME_DISPLAY_FORMATS,
63
67
  createEffectInstance: () => createEffectInstance,
68
+ formatDisplayTime: () => formatDisplayTime,
64
69
  getEffectDefinitions: () => getEffectDefinitions,
65
70
  isDomClip: () => isDomClip,
71
+ isTimeDisplayFormat: () => isTimeDisplayFormat,
72
+ parseDisplayTime: () => parseDisplayTime,
66
73
  registerEffect: () => registerEffect,
67
- splitAtPlayhead: () => splitAtPlayhead
74
+ resolveTransportTarget: () => resolveTransportTarget,
75
+ splitAtPlayhead: () => splitAtPlayhead,
76
+ targetSupports: () => targetSupports,
77
+ warnOnce: () => warnOnce,
78
+ warnUnsupportedOnce: () => warnUnsupportedOnce
68
79
  });
69
80
  module.exports = __toCommonJS(index_exports);
70
81
 
@@ -957,42 +968,9 @@ DawPianoRollElement = __decorateClass([
957
968
  // src/elements/daw-playhead.ts
958
969
  var import_lit5 = require("lit");
959
970
  var import_decorators5 = require("lit/decorators.js");
960
-
961
- // src/controllers/animation-controller.ts
962
- var AnimationController = class {
963
- constructor(host) {
964
- this._rafId = null;
965
- this._callback = null;
966
- host.addController(this);
967
- }
968
- start(callback) {
969
- this.stop();
970
- this._callback = callback;
971
- const loop = () => {
972
- this._callback?.();
973
- this._rafId = requestAnimationFrame(loop);
974
- };
975
- this._rafId = requestAnimationFrame(loop);
976
- }
977
- stop() {
978
- if (this._rafId !== null) {
979
- cancelAnimationFrame(this._rafId);
980
- this._rafId = null;
981
- }
982
- this._callback = null;
983
- }
984
- hostConnected() {
985
- }
986
- hostDisconnected() {
987
- this.stop();
988
- }
989
- };
990
-
991
- // src/elements/daw-playhead.ts
992
971
  var DawPlayheadElement = class extends import_lit5.LitElement {
993
972
  constructor() {
994
973
  super(...arguments);
995
- this._animation = new AnimationController(this);
996
974
  this._line = null;
997
975
  }
998
976
  render() {
@@ -1001,52 +979,10 @@ var DawPlayheadElement = class extends import_lit5.LitElement {
1001
979
  firstUpdated() {
1002
980
  this._line = this.shadowRoot.querySelector("div");
1003
981
  }
1004
- startAnimation(getTime, sampleRate, samplesPerPixel) {
1005
- this._animation.start(() => {
1006
- const time = getTime();
1007
- const px = time * sampleRate / samplesPerPixel;
1008
- if (this._line) {
1009
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1010
- }
1011
- });
1012
- }
1013
- stopAnimation(time, sampleRate, samplesPerPixel) {
1014
- this._animation.stop();
1015
- const px = time * sampleRate / samplesPerPixel;
1016
- if (this._line) {
1017
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1018
- }
1019
- }
1020
- startBeatsAnimation(getTime, bpm, ppqn, ticksPerPixel) {
1021
- const ticksPerSecond = bpm * ppqn / 60;
1022
- this._animation.start(() => {
1023
- const time = getTime();
1024
- const px = time * ticksPerSecond / ticksPerPixel;
1025
- if (this._line) {
1026
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1027
- }
1028
- });
1029
- }
1030
- stopBeatsAnimation(time, bpm, ppqn, ticksPerPixel) {
1031
- this._animation.stop();
1032
- const px = time * bpm * ppqn / (60 * ticksPerPixel);
1033
- if (this._line) {
1034
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1035
- }
1036
- }
1037
- startBeatsAnimationWithMap(getTime, secondsToTicks, ticksPerPixel) {
1038
- this._animation.start(() => {
1039
- const time = getTime();
1040
- const tick = secondsToTicks(time);
1041
- const px = tick / ticksPerPixel;
1042
- if (this._line) {
1043
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1044
- }
1045
- });
1046
- }
1047
- stopBeatsAnimationWithMap(time, secondsToTicks, ticksPerPixel) {
1048
- this._animation.stop();
1049
- const px = secondsToTicks(time) / ticksPerPixel;
982
+ /** Position the playhead line at an absolute pixel offset on the timeline.
983
+ * The editor's PlaybackAnimationController drives this each frame — the
984
+ * playhead owns no animation loop or time math of its own. */
985
+ setPosition(px) {
1050
986
  if (this._line) {
1051
987
  this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1052
988
  }
@@ -1104,12 +1040,102 @@ var import_decorators7 = require("lit/decorators.js");
1104
1040
 
1105
1041
  // src/elements/daw-transport-button.ts
1106
1042
  var import_lit7 = require("lit");
1043
+
1044
+ // src/utils/transport-capability.ts
1045
+ function resolveTransportTarget(el) {
1046
+ const transport = el.closest("daw-transport");
1047
+ return transport?.target ?? null;
1048
+ }
1049
+ function targetSupports(target, methods) {
1050
+ if (!target) return false;
1051
+ return methods.every((m) => typeof target[m] === "function");
1052
+ }
1053
+ function targetUndetermined(target) {
1054
+ if (!target) return true;
1055
+ const name = target.localName;
1056
+ return name.includes("-") && customElements.get(name) === void 0;
1057
+ }
1058
+ var warned = /* @__PURE__ */ new WeakMap();
1059
+ function warnOnce(element, message) {
1060
+ let messages = warned.get(element);
1061
+ if (!messages) {
1062
+ messages = /* @__PURE__ */ new Set();
1063
+ warned.set(element, messages);
1064
+ }
1065
+ if (messages.has(message)) return;
1066
+ messages.add(message);
1067
+ console.warn(message);
1068
+ }
1069
+ function warnNoTargetOnce(element, suffix) {
1070
+ warnOnce(
1071
+ element,
1072
+ `[dawcore] <${element.tagName.toLowerCase()}> has no target. Check <daw-transport for="..."> references a valid element id.` + (suffix ?? "")
1073
+ );
1074
+ }
1075
+ function warnUnsupportedOnce(element, methods) {
1076
+ warnOnce(
1077
+ element,
1078
+ `[dawcore] <${element.tagName.toLowerCase()}> is disabled: its transport target does not implement ${methods.join(", ")}. See the transport compatibility table in the docs for which controls work with which targets.`
1079
+ );
1080
+ }
1081
+
1082
+ // src/elements/daw-transport-button.ts
1107
1083
  var DawTransportButton = class extends import_lit7.LitElement {
1084
+ constructor() {
1085
+ super(...arguments);
1086
+ this._onCapabilityPointerEnter = () => {
1087
+ this.requestUpdate();
1088
+ };
1089
+ this._onCapabilityPointerDown = () => {
1090
+ const target = this.target;
1091
+ if (!target) {
1092
+ if (this._requiredMethods.length > 0) {
1093
+ warnNoTargetOnce(this);
1094
+ }
1095
+ return;
1096
+ }
1097
+ if (!this.targetSupported) {
1098
+ warnUnsupportedOnce(this, this._requiredMethods);
1099
+ }
1100
+ };
1101
+ }
1108
1102
  get target() {
1109
- const transport = this.closest("daw-transport");
1110
- return transport?.target ?? null;
1103
+ return resolveTransportTarget(this);
1104
+ }
1105
+ get _requiredMethods() {
1106
+ return this.constructor.requiredTargetMethods;
1107
+ }
1108
+ /**
1109
+ * False when this control declares requirements its target doesn't meet.
1110
+ * An undetermined target (missing, or a not-yet-upgraded custom element)
1111
+ * gets the benefit of the doubt and stays enabled — click-time resolution
1112
+ * warns if it's still unusable.
1113
+ */
1114
+ get targetSupported() {
1115
+ const required = this._requiredMethods;
1116
+ if (required.length === 0) return true;
1117
+ const target = this.target;
1118
+ if (targetUndetermined(target)) return true;
1119
+ return targetSupports(target, required);
1120
+ }
1121
+ connectedCallback() {
1122
+ super.connectedCallback();
1123
+ this.addEventListener("pointerdown", this._onCapabilityPointerDown);
1124
+ this.addEventListener("pointerenter", this._onCapabilityPointerEnter);
1125
+ requestAnimationFrame(() => {
1126
+ if (!this.isConnected) return;
1127
+ this.requestUpdate();
1128
+ });
1129
+ }
1130
+ disconnectedCallback() {
1131
+ super.disconnectedCallback();
1132
+ this.removeEventListener("pointerdown", this._onCapabilityPointerDown);
1133
+ this.removeEventListener("pointerenter", this._onCapabilityPointerEnter);
1111
1134
  }
1112
1135
  };
1136
+ /** Methods the transport target must implement for this control to be
1137
+ * enabled. Empty = works with any target. */
1138
+ DawTransportButton.requiredTargetMethods = [];
1113
1139
  DawTransportButton.styles = import_lit7.css`
1114
1140
  button {
1115
1141
  cursor: pointer;
@@ -2810,8 +2836,12 @@ var RecordingController = class {
2810
2836
  }
2811
2837
  const channelCount = detectedChannelCount ?? options.channelCount ?? 1;
2812
2838
  const startSample = options.startSample ?? Math.floor(this._host._currentTime * this._host.effectiveSampleRate);
2813
- const outputLatency = rawCtx.outputLatency ?? 0;
2814
- const latencySamples = Math.floor(outputLatency * rawCtx.sampleRate);
2839
+ const latencySamples = (0, import_core3.resolveRecordingOffsetSamples)({
2840
+ overrideSeconds: options.latencyOffset,
2841
+ outputLatency: rawCtx.outputLatency ?? 0,
2842
+ lookAhead: 0,
2843
+ sampleRate: rawCtx.sampleRate
2844
+ });
2815
2845
  const source = this._host.createMediaStreamSource ? this._host.createMediaStreamSource(stream) : rawCtx.createMediaStreamSource(stream);
2816
2846
  const workletNode = this._host.createAudioWorkletNode ? this._host.createAudioWorkletNode("recording-processor", {
2817
2847
  channelCount,
@@ -3165,8 +3195,8 @@ var SpectrogramController = class {
3165
3195
  unregisterCanvas(canvasId) {
3166
3196
  this.orchestrator?.unregisterCanvas(canvasId);
3167
3197
  }
3168
- setViewport(state5) {
3169
- this.orchestrator?.setViewport(state5);
3198
+ setViewport(state7) {
3199
+ this.orchestrator?.setViewport(state7);
3170
3200
  }
3171
3201
  dispose() {
3172
3202
  if (this.orchestrator) {
@@ -3405,7 +3435,12 @@ var PointerHandler = class {
3405
3435
  if (h._engine) {
3406
3436
  h._engine.setSelection(0, 0);
3407
3437
  if (wasPlaying) {
3408
- h._engine.stop();
3438
+ h._inSeekTransition = true;
3439
+ try {
3440
+ h._engine.stop();
3441
+ } finally {
3442
+ h._inSeekTransition = false;
3443
+ }
3409
3444
  h._engine.play(time);
3410
3445
  h._startPlayhead();
3411
3446
  } else {
@@ -3746,6 +3781,57 @@ var ClipPointerHandler = class {
3746
3781
  }
3747
3782
  };
3748
3783
 
3784
+ // src/utils/time-display-format.ts
3785
+ var TIME_DISPLAY_FORMATS = [
3786
+ "hh:mm:ss.sss",
3787
+ "hh:mm:ss",
3788
+ "seconds"
3789
+ ];
3790
+ function isTimeDisplayFormat(value) {
3791
+ return TIME_DISPLAY_FORMATS.includes(value);
3792
+ }
3793
+ function clockFormat(totalSeconds, decimals) {
3794
+ const hours = Math.floor(totalSeconds / 3600);
3795
+ const minutes = Math.floor(totalSeconds / 60) % 60;
3796
+ const secsRem = totalSeconds % 60;
3797
+ let secs;
3798
+ if (decimals === 0) {
3799
+ secs = String(Math.min(Math.floor(secsRem + 1e-6), 59)).padStart(2, "0");
3800
+ } else {
3801
+ const factor = 10 ** decimals;
3802
+ const truncated = Math.min(Math.floor(secsRem * factor + 1e-6), 60 * factor - 1);
3803
+ secs = (truncated / factor).toFixed(decimals).padStart(decimals + 3, "0");
3804
+ }
3805
+ return String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0") + ":" + secs;
3806
+ }
3807
+ function formatDisplayTime(seconds, format) {
3808
+ const safe = Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
3809
+ switch (format) {
3810
+ case "seconds":
3811
+ return safe.toFixed(3);
3812
+ case "hh:mm:ss":
3813
+ return clockFormat(safe, 0);
3814
+ case "hh:mm:ss.sss":
3815
+ default:
3816
+ return clockFormat(safe, 3);
3817
+ }
3818
+ }
3819
+ function parseDisplayTime(value, format) {
3820
+ if (!value) return 0;
3821
+ let seconds = 0;
3822
+ if (format === "seconds") {
3823
+ seconds = parseFloat(value) || 0;
3824
+ } else {
3825
+ const parts = value.split(":");
3826
+ if (parts.length !== 3) return 0;
3827
+ const h = parseInt(parts[0], 10) || 0;
3828
+ const m = parseInt(parts[1], 10) || 0;
3829
+ const s = parseFloat(parts[2]) || 0;
3830
+ seconds = h * 3600 + m * 60 + s;
3831
+ }
3832
+ return Math.max(0, seconds);
3833
+ }
3834
+
3749
3835
  // src/interactions/file-loader.ts
3750
3836
  var import_core7 = require("@waveform-playlist/core");
3751
3837
  async function loadFiles(host, files) {
@@ -4064,9 +4150,9 @@ function splitAtPlayhead(host) {
4064
4150
  function canSplitAtTime(host, time) {
4065
4151
  const { engine } = host;
4066
4152
  if (!engine) return false;
4067
- const state5 = engine.getState();
4068
- if (!state5.selectedTrackId) return false;
4069
- const track = state5.tracks.find((t) => t.id === state5.selectedTrackId);
4153
+ const state7 = engine.getState();
4154
+ if (!state7.selectedTrackId) return false;
4155
+ const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
4070
4156
  if (!track) return false;
4071
4157
  const atSample = Math.round(time * host.effectiveSampleRate);
4072
4158
  const clip = findClipAtSample(track.clips, atSample);
@@ -4256,9 +4342,9 @@ var EffectsChainController = class {
4256
4342
  ...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
4257
4343
  };
4258
4344
  }
4259
- let state5;
4345
+ let state7;
4260
4346
  try {
4261
- state5 = await entry.instance.getState?.();
4347
+ state7 = await entry.instance.getState?.();
4262
4348
  } catch (err) {
4263
4349
  console.warn(
4264
4350
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4268,7 +4354,7 @@ var EffectsChainController = class {
4268
4354
  kind: "wam",
4269
4355
  ...sourceFields,
4270
4356
  bypassed: entry.bypassed,
4271
- ...state5 !== void 0 ? { state: state5 } : {}
4357
+ ...state7 !== void 0 ? { state: state7 } : {}
4272
4358
  };
4273
4359
  }
4274
4360
  return {
@@ -5440,6 +5526,75 @@ var ScrollSyncController = class {
5440
5526
  }
5441
5527
  };
5442
5528
 
5529
+ // src/controllers/animation-controller.ts
5530
+ var AnimationController = class {
5531
+ constructor(host) {
5532
+ this._rafId = null;
5533
+ this._callback = null;
5534
+ host.addController(this);
5535
+ }
5536
+ start(callback) {
5537
+ this.stop();
5538
+ this._callback = callback;
5539
+ const loop = () => {
5540
+ this._callback?.();
5541
+ this._rafId = requestAnimationFrame(loop);
5542
+ };
5543
+ this._rafId = requestAnimationFrame(loop);
5544
+ }
5545
+ stop() {
5546
+ if (this._rafId !== null) {
5547
+ cancelAnimationFrame(this._rafId);
5548
+ this._rafId = null;
5549
+ }
5550
+ this._callback = null;
5551
+ }
5552
+ hostConnected() {
5553
+ }
5554
+ hostDisconnected() {
5555
+ this.stop();
5556
+ }
5557
+ };
5558
+
5559
+ // src/controllers/playback-animation-controller.ts
5560
+ var PlaybackAnimationController = class {
5561
+ constructor(host, options) {
5562
+ this._running = false;
5563
+ this._lastDispatchedTime = null;
5564
+ this._host = host;
5565
+ this._options = options;
5566
+ this._animation = new AnimationController(host);
5567
+ }
5568
+ start(getTime) {
5569
+ this._running = true;
5570
+ this._animation.start(() => {
5571
+ const time = getTime();
5572
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
5573
+ this._dispatchTimeUpdate(time);
5574
+ });
5575
+ }
5576
+ stop(finalTime, opts) {
5577
+ const wasRunning = this._running;
5578
+ this._running = false;
5579
+ this._animation.stop();
5580
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(finalTime));
5581
+ if (opts?.dispatch === false) return;
5582
+ if (wasRunning || finalTime !== this._lastDispatchedTime) {
5583
+ this._dispatchTimeUpdate(finalTime);
5584
+ }
5585
+ }
5586
+ _dispatchTimeUpdate(time) {
5587
+ this._lastDispatchedTime = time;
5588
+ this._host.dispatchEvent(
5589
+ new CustomEvent("daw-timeupdate", {
5590
+ bubbles: true,
5591
+ composed: true,
5592
+ detail: { time }
5593
+ })
5594
+ );
5595
+ }
5596
+ };
5597
+
5443
5598
  // src/elements/daw-editor.ts
5444
5599
  var import_meta = {};
5445
5600
  var RULER_HEIGHT = 30;
@@ -5448,6 +5603,7 @@ var DawEditorElement = class extends import_lit15.LitElement {
5448
5603
  constructor() {
5449
5604
  super(...arguments);
5450
5605
  this._samplesPerPixel = 1024;
5606
+ this._timeFormat = "hh:mm:ss.sss";
5451
5607
  this.waveHeight = 128;
5452
5608
  this.timescale = false;
5453
5609
  this.mono = false;
@@ -5497,6 +5653,20 @@ var DawEditorElement = class extends import_lit15.LitElement {
5497
5653
  this._childObserver = null;
5498
5654
  this._audioResume = new AudioResumeController(this);
5499
5655
  this._recordingController = new RecordingController(this);
5656
+ // Closures (not direct references) — _timeToPixels/_getPlayhead are
5657
+ // declared later in the class body; class-field init order would read
5658
+ // `undefined` for a direct reference here.
5659
+ this._playbackAnimation = new PlaybackAnimationController(this, {
5660
+ timeToPixels: (time) => this._timeToPixels(time),
5661
+ getPlayhead: () => this._getPlayhead()
5662
+ });
5663
+ /**
5664
+ * True while a seek-while-playing stop+play transition is in flight.
5665
+ * Suppresses the transient settle dispatch from the engine 'stop' handler
5666
+ * (which would otherwise leak a backward-jumping daw-timeupdate at the
5667
+ * play-start position). Non-private: pointer-handler's seek path sets it.
5668
+ */
5669
+ this._inSeekTransition = false;
5500
5670
  this._spectrogramController = null;
5501
5671
  this._clipPointer = new ClipPointerHandler(this);
5502
5672
  this._pointer = new PointerHandler(this);
@@ -5702,6 +5872,14 @@ var DawEditorElement = class extends import_lit15.LitElement {
5702
5872
  /** Set in togglePauseRecording when Transport is paused alongside the
5703
5873
  * worklet, so resume can restart it. Cleared on resume and on stop. */
5704
5874
  this._wasPlayingDuringRecording = false;
5875
+ // --- Playback animation (single RAF loop: playhead + daw-timeupdate) ---
5876
+ /** Convert playback seconds to a timeline pixel offset for the active mode. */
5877
+ this._timeToPixels = (time) => {
5878
+ if (this.scaleMode === "beats") {
5879
+ return this._secondsToTicks(time) / this.ticksPerPixel;
5880
+ }
5881
+ return time * this.effectiveSampleRate / this.samplesPerPixel;
5882
+ };
5705
5883
  }
5706
5884
  get samplesPerPixel() {
5707
5885
  return this._samplesPerPixel;
@@ -5718,6 +5896,35 @@ var DawEditorElement = class extends import_lit15.LitElement {
5718
5896
  this._samplesPerPixel = clamped;
5719
5897
  this.requestUpdate("samplesPerPixel", old);
5720
5898
  }
5899
+ get timeFormat() {
5900
+ return this._timeFormat;
5901
+ }
5902
+ set timeFormat(value) {
5903
+ if (!isTimeDisplayFormat(value)) {
5904
+ console.warn(
5905
+ '[dawcore] timeFormat: invalid format "' + String(value) + '" ignored. Valid formats: ' + TIME_DISPLAY_FORMATS.join(", ")
5906
+ );
5907
+ if (this.hasAttribute("time-format") && this.getAttribute("time-format") !== this._timeFormat) {
5908
+ this.setAttribute("time-format", this._timeFormat);
5909
+ }
5910
+ return;
5911
+ }
5912
+ if (value === this._timeFormat) return;
5913
+ const old = this._timeFormat;
5914
+ this._timeFormat = value;
5915
+ this.requestUpdate("timeFormat", old);
5916
+ this.dispatchEvent(
5917
+ new CustomEvent("daw-time-format-change", {
5918
+ bubbles: true,
5919
+ composed: true,
5920
+ detail: { format: value }
5921
+ })
5922
+ );
5923
+ }
5924
+ /** Set the time display format. Sugar over the `timeFormat` property. */
5925
+ setTimeFormat(format) {
5926
+ this.timeFormat = format;
5927
+ }
5721
5928
  get spectrogramConfig() {
5722
5929
  return this._spectrogramConfig;
5723
5930
  }
@@ -6843,17 +7050,23 @@ var DawEditorElement = class extends import_lit15.LitElement {
6843
7050
  zoomLevels: [256, 512, 1024, 2048, 4096, 8192, this.samplesPerPixel].filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b)
6844
7051
  });
6845
7052
  let lastTracksVersion = -1;
7053
+ let lastMixerVersion = -1;
6846
7054
  engine.on("statechange", (engineState) => {
6847
7055
  this._isPlaying = engineState.isPlaying;
6848
7056
  this._duration = engineState.duration;
6849
7057
  this._selectedTrackId = engineState.selectedTrackId;
6850
- if (engineState.tracksVersion !== lastTracksVersion) {
7058
+ const structuralChange = engineState.tracksVersion !== lastTracksVersion;
7059
+ const mixerChange = engineState.mixerVersion !== lastMixerVersion;
7060
+ if (structuralChange || mixerChange) {
6851
7061
  lastTracksVersion = engineState.tracksVersion;
7062
+ lastMixerVersion = engineState.mixerVersion;
6852
7063
  const nextTracks = /* @__PURE__ */ new Map();
6853
7064
  for (const track of engineState.tracks) {
6854
7065
  nextTracks.set(track.id, track);
6855
7066
  }
6856
7067
  this._engineTracks = nextTracks;
7068
+ }
7069
+ if (structuralChange) {
6857
7070
  this._effectsManager?.rewireTrackChains();
6858
7071
  const audioTracks = engineState.tracks.filter((t) => {
6859
7072
  const desc = this._tracks.get(t.id);
@@ -7214,7 +7427,12 @@ var DawEditorElement = class extends import_lit15.LitElement {
7214
7427
  return;
7215
7428
  }
7216
7429
  if (this._isPlaying) {
7217
- this.stop();
7430
+ this._inSeekTransition = true;
7431
+ try {
7432
+ this.stop();
7433
+ } finally {
7434
+ this._inSeekTransition = false;
7435
+ }
7218
7436
  this.play(time);
7219
7437
  } else {
7220
7438
  this._engine.seek(time);
@@ -7273,6 +7491,14 @@ var DawEditorElement = class extends import_lit15.LitElement {
7273
7491
  }
7274
7492
  return this._currentTime;
7275
7493
  }
7494
+ /** Read-only: whether playback is running (HTMLMediaElement-adjacent). */
7495
+ get isPlaying() {
7496
+ return this._isPlaying;
7497
+ }
7498
+ /** Read-only: total content duration in seconds. */
7499
+ get duration() {
7500
+ return this._duration;
7501
+ }
7276
7502
  get isRecording() {
7277
7503
  return this._recordingController.isRecording;
7278
7504
  }
@@ -7363,33 +7589,15 @@ var DawEditorElement = class extends import_lit15.LitElement {
7363
7589
  `;
7364
7590
  });
7365
7591
  }
7366
- // --- Playhead ---
7367
7592
  _startPlayhead() {
7368
- const playhead = this._getPlayhead();
7369
- if (!playhead || !this._engine) return;
7593
+ if (!this._engine) return;
7370
7594
  const engine = this._engine;
7371
- const audibleTime = () => engine.getAudibleTime();
7372
- if (this.scaleMode === "beats") {
7373
- const secondsToTicksFn = (s) => this._secondsToTicks(s);
7374
- playhead.startBeatsAnimationWithMap(audibleTime, secondsToTicksFn, this.ticksPerPixel);
7375
- } else {
7376
- playhead.startAnimation(audibleTime, this.effectiveSampleRate, this.samplesPerPixel);
7377
- }
7595
+ this._playbackAnimation.start(() => engine.getAudibleTime());
7378
7596
  }
7379
7597
  _stopPlayhead() {
7380
- const playhead = this._getPlayhead();
7381
- if (!playhead) return;
7382
7598
  const t = this._currentTime;
7383
7599
  const visualTime = Number.isFinite(t) ? Math.max(0, t) : 0;
7384
- if (this.scaleMode === "beats") {
7385
- playhead.stopBeatsAnimationWithMap(
7386
- visualTime,
7387
- (s) => this._secondsToTicks(s),
7388
- this.ticksPerPixel
7389
- );
7390
- } else {
7391
- playhead.stopAnimation(visualTime, this.effectiveSampleRate, this.samplesPerPixel);
7392
- }
7600
+ this._playbackAnimation.stop(visualTime, { dispatch: !this._inSeekTransition });
7393
7601
  }
7394
7602
  _getPlayhead() {
7395
7603
  return this.shadowRoot?.querySelector("daw-playhead");
@@ -7734,6 +7942,9 @@ DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "mut
7734
7942
  __decorateClass([
7735
7943
  (0, import_decorators13.property)({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
7736
7944
  ], DawEditorElement.prototype, "samplesPerPixel", 1);
7945
+ __decorateClass([
7946
+ (0, import_decorators13.property)({ attribute: "time-format", reflect: true, noAccessor: true })
7947
+ ], DawEditorElement.prototype, "timeFormat", 1);
7737
7948
  __decorateClass([
7738
7949
  (0, import_decorators13.property)({ type: Number, attribute: "wave-height" })
7739
7950
  ], DawEditorElement.prototype, "waveHeight", 2);
@@ -7914,7 +8125,12 @@ var DawRecordButtonElement = class extends DawTransportButton {
7914
8125
  }
7915
8126
  render() {
7916
8127
  return import_lit17.html`
7917
- <button part="button" ?data-recording=${this._isRecording} @click=${this._onClick}>
8128
+ <button
8129
+ part="button"
8130
+ ?disabled=${!this.targetSupported}
8131
+ ?data-recording=${this._isRecording}
8132
+ @click=${this._onClick}
8133
+ >
7918
8134
  <slot>Record</slot>
7919
8135
  </button>
7920
8136
  `;
@@ -7923,14 +8139,16 @@ var DawRecordButtonElement = class extends DawTransportButton {
7923
8139
  if (this._isRecording) return;
7924
8140
  const target = this.target;
7925
8141
  if (!target) {
7926
- console.warn(
7927
- '[dawcore] <daw-record-button> has no target. Check <daw-transport for="..."> references a valid <daw-editor> id.'
7928
- );
8142
+ warnNoTargetOnce(this);
7929
8143
  return;
7930
8144
  }
7931
8145
  target.startRecording(target.recordingStream);
7932
8146
  }
7933
8147
  };
8148
+ DawRecordButtonElement.requiredTargetMethods = [
8149
+ "startRecording",
8150
+ "stopRecording"
8151
+ ];
7934
8152
  DawRecordButtonElement.styles = [
7935
8153
  DawTransportButton.styles,
7936
8154
  import_lit17.css`
@@ -8307,6 +8525,198 @@ __decorateClass([
8307
8525
  DawSpectrogramElement = __decorateClass([
8308
8526
  (0, import_decorators17.customElement)("daw-spectrogram")
8309
8527
  ], DawSpectrogramElement);
8528
+
8529
+ // src/elements/daw-time-display.ts
8530
+ var import_lit20 = require("lit");
8531
+ var import_decorators18 = require("lit/decorators.js");
8532
+ var DawTimeDisplayElement = class extends import_lit20.LitElement {
8533
+ constructor() {
8534
+ super(...arguments);
8535
+ this._time = null;
8536
+ this._format = "hh:mm:ss.sss";
8537
+ this._onTimeUpdate = (e) => {
8538
+ if (e.target !== this.target) return;
8539
+ if (this._time === null) {
8540
+ const timeFormat = e.target.timeFormat;
8541
+ if (isTimeDisplayFormat(timeFormat)) this._format = timeFormat;
8542
+ }
8543
+ this._time = e.detail.time;
8544
+ };
8545
+ this._onFormatChange = (e) => {
8546
+ if (e.target !== this.target) return;
8547
+ const detail = e.detail;
8548
+ if (isTimeDisplayFormat(detail.format)) {
8549
+ this._format = detail.format;
8550
+ }
8551
+ };
8552
+ }
8553
+ get target() {
8554
+ return resolveTransportTarget(this);
8555
+ }
8556
+ connectedCallback() {
8557
+ super.connectedCallback();
8558
+ document.addEventListener("daw-timeupdate", this._onTimeUpdate);
8559
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8560
+ requestAnimationFrame(() => this._syncFromTarget());
8561
+ }
8562
+ disconnectedCallback() {
8563
+ super.disconnectedCallback();
8564
+ document.removeEventListener("daw-timeupdate", this._onTimeUpdate);
8565
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8566
+ }
8567
+ _syncFromTarget() {
8568
+ if (!this.isConnected) return;
8569
+ const target = this.target;
8570
+ if (!target || typeof target.currentTime !== "number") {
8571
+ warnNoTargetOnce(
8572
+ this,
8573
+ " The display recovers automatically once the target dispatches daw-timeupdate."
8574
+ );
8575
+ return;
8576
+ }
8577
+ this._time = target.currentTime;
8578
+ const fmt = target.timeFormat;
8579
+ if (isTimeDisplayFormat(fmt)) {
8580
+ this._format = fmt;
8581
+ }
8582
+ }
8583
+ render() {
8584
+ const text = this._time === null ? "--:--:--" : formatDisplayTime(this._time, this._format);
8585
+ return import_lit20.html`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
8586
+ }
8587
+ };
8588
+ DawTimeDisplayElement.styles = import_lit20.css`
8589
+ span {
8590
+ display: inline-block;
8591
+ font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
8592
+ font-variant-numeric: tabular-nums;
8593
+ color: var(--daw-controls-text, #e0d4c8);
8594
+ background: var(--daw-controls-background, #1a1a2e);
8595
+ border: 1px solid currentColor;
8596
+ padding: 4px 8px;
8597
+ }
8598
+ `;
8599
+ __decorateClass([
8600
+ (0, import_decorators18.state)()
8601
+ ], DawTimeDisplayElement.prototype, "_time", 2);
8602
+ __decorateClass([
8603
+ (0, import_decorators18.state)()
8604
+ ], DawTimeDisplayElement.prototype, "_format", 2);
8605
+ DawTimeDisplayElement = __decorateClass([
8606
+ (0, import_decorators18.customElement)("daw-time-display")
8607
+ ], DawTimeDisplayElement);
8608
+
8609
+ // src/elements/daw-time-format.ts
8610
+ var import_lit21 = require("lit");
8611
+ var import_decorators19 = require("lit/decorators.js");
8612
+ var DawTimeFormatElement = class extends import_lit21.LitElement {
8613
+ constructor() {
8614
+ super(...arguments);
8615
+ this._format = "hh:mm:ss.sss";
8616
+ this._onFormatChange = (e) => {
8617
+ if (e.target !== this.target) return;
8618
+ const detail = e.detail;
8619
+ if (isTimeDisplayFormat(detail.format)) {
8620
+ this._format = detail.format;
8621
+ }
8622
+ };
8623
+ this._onPointerEnter = () => {
8624
+ this.requestUpdate();
8625
+ };
8626
+ this._onPointerDown = () => {
8627
+ const target = this.target;
8628
+ if (!target) {
8629
+ warnNoTargetOnce(this);
8630
+ return;
8631
+ }
8632
+ if (!this._targetSupported) {
8633
+ warnUnsupportedOnce(this, ["setTimeFormat"]);
8634
+ }
8635
+ };
8636
+ }
8637
+ get target() {
8638
+ return resolveTransportTarget(this);
8639
+ }
8640
+ /**
8641
+ * False when the target doesn't implement setTimeFormat. An undetermined
8642
+ * target (missing, or a not-yet-upgraded custom element) gets the benefit
8643
+ * of the doubt and stays enabled — interaction-time resolution warns if
8644
+ * it's still unusable.
8645
+ */
8646
+ get _targetSupported() {
8647
+ const target = this.target;
8648
+ if (targetUndetermined(target)) return true;
8649
+ return targetSupports(target, ["setTimeFormat"]);
8650
+ }
8651
+ connectedCallback() {
8652
+ super.connectedCallback();
8653
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8654
+ this.addEventListener("pointerdown", this._onPointerDown);
8655
+ this.addEventListener("pointerenter", this._onPointerEnter);
8656
+ requestAnimationFrame(() => {
8657
+ if (!this.isConnected) return;
8658
+ const target = this.target;
8659
+ if (target && isTimeDisplayFormat(target.timeFormat)) {
8660
+ this._format = target.timeFormat;
8661
+ }
8662
+ this.requestUpdate();
8663
+ });
8664
+ }
8665
+ disconnectedCallback() {
8666
+ super.disconnectedCallback();
8667
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8668
+ this.removeEventListener("pointerdown", this._onPointerDown);
8669
+ this.removeEventListener("pointerenter", this._onPointerEnter);
8670
+ }
8671
+ updated() {
8672
+ const select = this.shadowRoot?.querySelector("select");
8673
+ if (select && select.value !== this._format) {
8674
+ select.value = this._format;
8675
+ }
8676
+ }
8677
+ _onSelectChange(e) {
8678
+ const value = e.target.value;
8679
+ const target = this.target;
8680
+ if (!target) {
8681
+ warnNoTargetOnce(this);
8682
+ return;
8683
+ }
8684
+ target.setTimeFormat?.(value);
8685
+ }
8686
+ render() {
8687
+ return import_lit21.html`
8688
+ <select
8689
+ aria-label="Time format"
8690
+ ?disabled=${!this._targetSupported}
8691
+ @change=${this._onSelectChange}
8692
+ >
8693
+ ${TIME_DISPLAY_FORMATS.map(
8694
+ (f) => import_lit21.html`<option value=${f} ?selected=${f === this._format}>${f}</option>`
8695
+ )}
8696
+ </select>
8697
+ `;
8698
+ }
8699
+ };
8700
+ DawTimeFormatElement.styles = import_lit21.css`
8701
+ select {
8702
+ cursor: pointer;
8703
+ background: var(--daw-controls-background, #1a1a2e);
8704
+ color: var(--daw-controls-text, #e0d4c8);
8705
+ border: 1px solid currentColor;
8706
+ padding: 4px 8px;
8707
+ font: inherit;
8708
+ }
8709
+ select:disabled {
8710
+ opacity: 0.4;
8711
+ cursor: default;
8712
+ }
8713
+ `;
8714
+ __decorateClass([
8715
+ (0, import_decorators19.state)()
8716
+ ], DawTimeFormatElement.prototype, "_format", 2);
8717
+ DawTimeFormatElement = __decorateClass([
8718
+ (0, import_decorators19.customElement)("daw-time-format")
8719
+ ], DawTimeFormatElement);
8310
8720
  // Annotate the CommonJS export names for ESM import in node:
8311
8721
  0 && (module.exports = {
8312
8722
  AudioResumeController,
@@ -8324,17 +8734,28 @@ DawSpectrogramElement = __decorateClass([
8324
8734
  DawSelectionElement,
8325
8735
  DawSpectrogramElement,
8326
8736
  DawStopButtonElement,
8737
+ DawTimeDisplayElement,
8738
+ DawTimeFormatElement,
8327
8739
  DawTrackControlsElement,
8328
8740
  DawTrackElement,
8329
8741
  DawTransportButton,
8330
8742
  DawTransportElement,
8331
8743
  DawWaveformElement,
8744
+ PlaybackAnimationController,
8332
8745
  RecordingController,
8333
8746
  SpectrogramController,
8747
+ TIME_DISPLAY_FORMATS,
8334
8748
  createEffectInstance,
8749
+ formatDisplayTime,
8335
8750
  getEffectDefinitions,
8336
8751
  isDomClip,
8752
+ isTimeDisplayFormat,
8753
+ parseDisplayTime,
8337
8754
  registerEffect,
8338
- splitAtPlayhead
8755
+ resolveTransportTarget,
8756
+ splitAtPlayhead,
8757
+ targetSupports,
8758
+ warnOnce,
8759
+ warnUnsupportedOnce
8339
8760
  });
8340
8761
  //# sourceMappingURL=index.js.map