@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.mjs CHANGED
@@ -898,42 +898,9 @@ DawPianoRollElement = __decorateClass([
898
898
  // src/elements/daw-playhead.ts
899
899
  import { LitElement as LitElement5, html as html3, css as css3 } from "lit";
900
900
  import { customElement as customElement5 } from "lit/decorators.js";
901
-
902
- // src/controllers/animation-controller.ts
903
- var AnimationController = class {
904
- constructor(host) {
905
- this._rafId = null;
906
- this._callback = null;
907
- host.addController(this);
908
- }
909
- start(callback) {
910
- this.stop();
911
- this._callback = callback;
912
- const loop = () => {
913
- this._callback?.();
914
- this._rafId = requestAnimationFrame(loop);
915
- };
916
- this._rafId = requestAnimationFrame(loop);
917
- }
918
- stop() {
919
- if (this._rafId !== null) {
920
- cancelAnimationFrame(this._rafId);
921
- this._rafId = null;
922
- }
923
- this._callback = null;
924
- }
925
- hostConnected() {
926
- }
927
- hostDisconnected() {
928
- this.stop();
929
- }
930
- };
931
-
932
- // src/elements/daw-playhead.ts
933
901
  var DawPlayheadElement = class extends LitElement5 {
934
902
  constructor() {
935
903
  super(...arguments);
936
- this._animation = new AnimationController(this);
937
904
  this._line = null;
938
905
  }
939
906
  render() {
@@ -942,52 +909,10 @@ var DawPlayheadElement = class extends LitElement5 {
942
909
  firstUpdated() {
943
910
  this._line = this.shadowRoot.querySelector("div");
944
911
  }
945
- startAnimation(getTime, sampleRate, samplesPerPixel) {
946
- this._animation.start(() => {
947
- const time = getTime();
948
- const px = time * sampleRate / samplesPerPixel;
949
- if (this._line) {
950
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
951
- }
952
- });
953
- }
954
- stopAnimation(time, sampleRate, samplesPerPixel) {
955
- this._animation.stop();
956
- const px = time * sampleRate / samplesPerPixel;
957
- if (this._line) {
958
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
959
- }
960
- }
961
- startBeatsAnimation(getTime, bpm, ppqn, ticksPerPixel) {
962
- const ticksPerSecond = bpm * ppqn / 60;
963
- this._animation.start(() => {
964
- const time = getTime();
965
- const px = time * ticksPerSecond / ticksPerPixel;
966
- if (this._line) {
967
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
968
- }
969
- });
970
- }
971
- stopBeatsAnimation(time, bpm, ppqn, ticksPerPixel) {
972
- this._animation.stop();
973
- const px = time * bpm * ppqn / (60 * ticksPerPixel);
974
- if (this._line) {
975
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
976
- }
977
- }
978
- startBeatsAnimationWithMap(getTime, secondsToTicks, ticksPerPixel) {
979
- this._animation.start(() => {
980
- const time = getTime();
981
- const tick = secondsToTicks(time);
982
- const px = tick / ticksPerPixel;
983
- if (this._line) {
984
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
985
- }
986
- });
987
- }
988
- stopBeatsAnimationWithMap(time, secondsToTicks, ticksPerPixel) {
989
- this._animation.stop();
990
- const px = secondsToTicks(time) / ticksPerPixel;
912
+ /** Position the playhead line at an absolute pixel offset on the timeline.
913
+ * The editor's PlaybackAnimationController drives this each frame — the
914
+ * playhead owns no animation loop or time math of its own. */
915
+ setPosition(px) {
991
916
  if (this._line) {
992
917
  this._line.style.transform = `translate3d(${px}px, 0, 0)`;
993
918
  }
@@ -1045,12 +970,102 @@ import { customElement as customElement7, state } from "lit/decorators.js";
1045
970
 
1046
971
  // src/elements/daw-transport-button.ts
1047
972
  import { LitElement as LitElement7, css as css4 } from "lit";
973
+
974
+ // src/utils/transport-capability.ts
975
+ function resolveTransportTarget(el) {
976
+ const transport = el.closest("daw-transport");
977
+ return transport?.target ?? null;
978
+ }
979
+ function targetSupports(target, methods) {
980
+ if (!target) return false;
981
+ return methods.every((m) => typeof target[m] === "function");
982
+ }
983
+ function targetUndetermined(target) {
984
+ if (!target) return true;
985
+ const name = target.localName;
986
+ return name.includes("-") && customElements.get(name) === void 0;
987
+ }
988
+ var warned = /* @__PURE__ */ new WeakMap();
989
+ function warnOnce(element, message) {
990
+ let messages = warned.get(element);
991
+ if (!messages) {
992
+ messages = /* @__PURE__ */ new Set();
993
+ warned.set(element, messages);
994
+ }
995
+ if (messages.has(message)) return;
996
+ messages.add(message);
997
+ console.warn(message);
998
+ }
999
+ function warnNoTargetOnce(element, suffix) {
1000
+ warnOnce(
1001
+ element,
1002
+ `[dawcore] <${element.tagName.toLowerCase()}> has no target. Check <daw-transport for="..."> references a valid element id.` + (suffix ?? "")
1003
+ );
1004
+ }
1005
+ function warnUnsupportedOnce(element, methods) {
1006
+ warnOnce(
1007
+ element,
1008
+ `[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.`
1009
+ );
1010
+ }
1011
+
1012
+ // src/elements/daw-transport-button.ts
1048
1013
  var DawTransportButton = class extends LitElement7 {
1014
+ constructor() {
1015
+ super(...arguments);
1016
+ this._onCapabilityPointerEnter = () => {
1017
+ this.requestUpdate();
1018
+ };
1019
+ this._onCapabilityPointerDown = () => {
1020
+ const target = this.target;
1021
+ if (!target) {
1022
+ if (this._requiredMethods.length > 0) {
1023
+ warnNoTargetOnce(this);
1024
+ }
1025
+ return;
1026
+ }
1027
+ if (!this.targetSupported) {
1028
+ warnUnsupportedOnce(this, this._requiredMethods);
1029
+ }
1030
+ };
1031
+ }
1049
1032
  get target() {
1050
- const transport = this.closest("daw-transport");
1051
- return transport?.target ?? null;
1033
+ return resolveTransportTarget(this);
1034
+ }
1035
+ get _requiredMethods() {
1036
+ return this.constructor.requiredTargetMethods;
1037
+ }
1038
+ /**
1039
+ * False when this control declares requirements its target doesn't meet.
1040
+ * An undetermined target (missing, or a not-yet-upgraded custom element)
1041
+ * gets the benefit of the doubt and stays enabled — click-time resolution
1042
+ * warns if it's still unusable.
1043
+ */
1044
+ get targetSupported() {
1045
+ const required = this._requiredMethods;
1046
+ if (required.length === 0) return true;
1047
+ const target = this.target;
1048
+ if (targetUndetermined(target)) return true;
1049
+ return targetSupports(target, required);
1050
+ }
1051
+ connectedCallback() {
1052
+ super.connectedCallback();
1053
+ this.addEventListener("pointerdown", this._onCapabilityPointerDown);
1054
+ this.addEventListener("pointerenter", this._onCapabilityPointerEnter);
1055
+ requestAnimationFrame(() => {
1056
+ if (!this.isConnected) return;
1057
+ this.requestUpdate();
1058
+ });
1059
+ }
1060
+ disconnectedCallback() {
1061
+ super.disconnectedCallback();
1062
+ this.removeEventListener("pointerdown", this._onCapabilityPointerDown);
1063
+ this.removeEventListener("pointerenter", this._onCapabilityPointerEnter);
1052
1064
  }
1053
1065
  };
1066
+ /** Methods the transport target must implement for this control to be
1067
+ * enabled. Empty = works with any target. */
1068
+ DawTransportButton.requiredTargetMethods = [];
1054
1069
  DawTransportButton.styles = css4`
1055
1070
  button {
1056
1071
  cursor: pointer;
@@ -2693,7 +2708,12 @@ var AudioResumeController = class {
2693
2708
  };
2694
2709
 
2695
2710
  // src/controllers/recording-controller.ts
2696
- import { appendPeaks, concatenateAudioData, createAudioBuffer } from "@waveform-playlist/core";
2711
+ import {
2712
+ appendPeaks,
2713
+ concatenateAudioData,
2714
+ createAudioBuffer,
2715
+ resolveRecordingOffsetSamples
2716
+ } from "@waveform-playlist/core";
2697
2717
  var RecordingController = class {
2698
2718
  constructor(host) {
2699
2719
  this._sessions = /* @__PURE__ */ new Map();
@@ -2756,8 +2776,12 @@ var RecordingController = class {
2756
2776
  }
2757
2777
  const channelCount = detectedChannelCount ?? options.channelCount ?? 1;
2758
2778
  const startSample = options.startSample ?? Math.floor(this._host._currentTime * this._host.effectiveSampleRate);
2759
- const outputLatency = rawCtx.outputLatency ?? 0;
2760
- const latencySamples = Math.floor(outputLatency * rawCtx.sampleRate);
2779
+ const latencySamples = resolveRecordingOffsetSamples({
2780
+ overrideSeconds: options.latencyOffset,
2781
+ outputLatency: rawCtx.outputLatency ?? 0,
2782
+ lookAhead: 0,
2783
+ sampleRate: rawCtx.sampleRate
2784
+ });
2761
2785
  const source = this._host.createMediaStreamSource ? this._host.createMediaStreamSource(stream) : rawCtx.createMediaStreamSource(stream);
2762
2786
  const workletNode = this._host.createAudioWorkletNode ? this._host.createAudioWorkletNode("recording-processor", {
2763
2787
  channelCount,
@@ -3116,8 +3140,8 @@ var SpectrogramController = class {
3116
3140
  unregisterCanvas(canvasId) {
3117
3141
  this.orchestrator?.unregisterCanvas(canvasId);
3118
3142
  }
3119
- setViewport(state5) {
3120
- this.orchestrator?.setViewport(state5);
3143
+ setViewport(state7) {
3144
+ this.orchestrator?.setViewport(state7);
3121
3145
  }
3122
3146
  dispose() {
3123
3147
  if (this.orchestrator) {
@@ -3356,7 +3380,12 @@ var PointerHandler = class {
3356
3380
  if (h._engine) {
3357
3381
  h._engine.setSelection(0, 0);
3358
3382
  if (wasPlaying) {
3359
- h._engine.stop();
3383
+ h._inSeekTransition = true;
3384
+ try {
3385
+ h._engine.stop();
3386
+ } finally {
3387
+ h._inSeekTransition = false;
3388
+ }
3360
3389
  h._engine.play(time);
3361
3390
  h._startPlayhead();
3362
3391
  } else {
@@ -3697,6 +3726,57 @@ var ClipPointerHandler = class {
3697
3726
  }
3698
3727
  };
3699
3728
 
3729
+ // src/utils/time-display-format.ts
3730
+ var TIME_DISPLAY_FORMATS = [
3731
+ "hh:mm:ss.sss",
3732
+ "hh:mm:ss",
3733
+ "seconds"
3734
+ ];
3735
+ function isTimeDisplayFormat(value) {
3736
+ return TIME_DISPLAY_FORMATS.includes(value);
3737
+ }
3738
+ function clockFormat(totalSeconds, decimals) {
3739
+ const hours = Math.floor(totalSeconds / 3600);
3740
+ const minutes = Math.floor(totalSeconds / 60) % 60;
3741
+ const secsRem = totalSeconds % 60;
3742
+ let secs;
3743
+ if (decimals === 0) {
3744
+ secs = String(Math.min(Math.floor(secsRem + 1e-6), 59)).padStart(2, "0");
3745
+ } else {
3746
+ const factor = 10 ** decimals;
3747
+ const truncated = Math.min(Math.floor(secsRem * factor + 1e-6), 60 * factor - 1);
3748
+ secs = (truncated / factor).toFixed(decimals).padStart(decimals + 3, "0");
3749
+ }
3750
+ return String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0") + ":" + secs;
3751
+ }
3752
+ function formatDisplayTime(seconds, format) {
3753
+ const safe = Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
3754
+ switch (format) {
3755
+ case "seconds":
3756
+ return safe.toFixed(3);
3757
+ case "hh:mm:ss":
3758
+ return clockFormat(safe, 0);
3759
+ case "hh:mm:ss.sss":
3760
+ default:
3761
+ return clockFormat(safe, 3);
3762
+ }
3763
+ }
3764
+ function parseDisplayTime(value, format) {
3765
+ if (!value) return 0;
3766
+ let seconds = 0;
3767
+ if (format === "seconds") {
3768
+ seconds = parseFloat(value) || 0;
3769
+ } else {
3770
+ const parts = value.split(":");
3771
+ if (parts.length !== 3) return 0;
3772
+ const h = parseInt(parts[0], 10) || 0;
3773
+ const m = parseInt(parts[1], 10) || 0;
3774
+ const s = parseFloat(parts[2]) || 0;
3775
+ seconds = h * 3600 + m * 60 + s;
3776
+ }
3777
+ return Math.max(0, seconds);
3778
+ }
3779
+
3700
3780
  // src/interactions/file-loader.ts
3701
3781
  import { createClip, createTrack } from "@waveform-playlist/core";
3702
3782
  async function loadFiles(host, files) {
@@ -4015,9 +4095,9 @@ function splitAtPlayhead(host) {
4015
4095
  function canSplitAtTime(host, time) {
4016
4096
  const { engine } = host;
4017
4097
  if (!engine) return false;
4018
- const state5 = engine.getState();
4019
- if (!state5.selectedTrackId) return false;
4020
- const track = state5.tracks.find((t) => t.id === state5.selectedTrackId);
4098
+ const state7 = engine.getState();
4099
+ if (!state7.selectedTrackId) return false;
4100
+ const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
4021
4101
  if (!track) return false;
4022
4102
  const atSample = Math.round(time * host.effectiveSampleRate);
4023
4103
  const clip = findClipAtSample(track.clips, atSample);
@@ -4207,9 +4287,9 @@ var EffectsChainController = class {
4207
4287
  ...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
4208
4288
  };
4209
4289
  }
4210
- let state5;
4290
+ let state7;
4211
4291
  try {
4212
- state5 = await entry.instance.getState?.();
4292
+ state7 = await entry.instance.getState?.();
4213
4293
  } catch (err) {
4214
4294
  console.warn(
4215
4295
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4219,7 +4299,7 @@ var EffectsChainController = class {
4219
4299
  kind: "wam",
4220
4300
  ...sourceFields,
4221
4301
  bypassed: entry.bypassed,
4222
- ...state5 !== void 0 ? { state: state5 } : {}
4302
+ ...state7 !== void 0 ? { state: state7 } : {}
4223
4303
  };
4224
4304
  }
4225
4305
  return {
@@ -5391,6 +5471,75 @@ var ScrollSyncController = class {
5391
5471
  }
5392
5472
  };
5393
5473
 
5474
+ // src/controllers/animation-controller.ts
5475
+ var AnimationController = class {
5476
+ constructor(host) {
5477
+ this._rafId = null;
5478
+ this._callback = null;
5479
+ host.addController(this);
5480
+ }
5481
+ start(callback) {
5482
+ this.stop();
5483
+ this._callback = callback;
5484
+ const loop = () => {
5485
+ this._callback?.();
5486
+ this._rafId = requestAnimationFrame(loop);
5487
+ };
5488
+ this._rafId = requestAnimationFrame(loop);
5489
+ }
5490
+ stop() {
5491
+ if (this._rafId !== null) {
5492
+ cancelAnimationFrame(this._rafId);
5493
+ this._rafId = null;
5494
+ }
5495
+ this._callback = null;
5496
+ }
5497
+ hostConnected() {
5498
+ }
5499
+ hostDisconnected() {
5500
+ this.stop();
5501
+ }
5502
+ };
5503
+
5504
+ // src/controllers/playback-animation-controller.ts
5505
+ var PlaybackAnimationController = class {
5506
+ constructor(host, options) {
5507
+ this._running = false;
5508
+ this._lastDispatchedTime = null;
5509
+ this._host = host;
5510
+ this._options = options;
5511
+ this._animation = new AnimationController(host);
5512
+ }
5513
+ start(getTime) {
5514
+ this._running = true;
5515
+ this._animation.start(() => {
5516
+ const time = getTime();
5517
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
5518
+ this._dispatchTimeUpdate(time);
5519
+ });
5520
+ }
5521
+ stop(finalTime, opts) {
5522
+ const wasRunning = this._running;
5523
+ this._running = false;
5524
+ this._animation.stop();
5525
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(finalTime));
5526
+ if (opts?.dispatch === false) return;
5527
+ if (wasRunning || finalTime !== this._lastDispatchedTime) {
5528
+ this._dispatchTimeUpdate(finalTime);
5529
+ }
5530
+ }
5531
+ _dispatchTimeUpdate(time) {
5532
+ this._lastDispatchedTime = time;
5533
+ this._host.dispatchEvent(
5534
+ new CustomEvent("daw-timeupdate", {
5535
+ bubbles: true,
5536
+ composed: true,
5537
+ detail: { time }
5538
+ })
5539
+ );
5540
+ }
5541
+ };
5542
+
5394
5543
  // src/elements/daw-editor.ts
5395
5544
  var RULER_HEIGHT = 30;
5396
5545
  var NO_ADAPTER_ERROR = "No PlayoutAdapter set on <daw-editor>. Set editor.adapter before use.\n\n // Option 1: Native Web Audio (no Tone.js)\n npm install @dawcore/transport\n import { NativePlayoutAdapter } from '@dawcore/transport';\n editor.adapter = new NativePlayoutAdapter(new AudioContext());\n\n // Option 2: Tone.js (effects, MIDI synths)\n npm install @waveform-playlist/playout\n import { createToneAdapter } from '@waveform-playlist/playout';\n editor.adapter = createToneAdapter();";
@@ -5398,6 +5547,7 @@ var DawEditorElement = class extends LitElement11 {
5398
5547
  constructor() {
5399
5548
  super(...arguments);
5400
5549
  this._samplesPerPixel = 1024;
5550
+ this._timeFormat = "hh:mm:ss.sss";
5401
5551
  this.waveHeight = 128;
5402
5552
  this.timescale = false;
5403
5553
  this.mono = false;
@@ -5447,6 +5597,20 @@ var DawEditorElement = class extends LitElement11 {
5447
5597
  this._childObserver = null;
5448
5598
  this._audioResume = new AudioResumeController(this);
5449
5599
  this._recordingController = new RecordingController(this);
5600
+ // Closures (not direct references) — _timeToPixels/_getPlayhead are
5601
+ // declared later in the class body; class-field init order would read
5602
+ // `undefined` for a direct reference here.
5603
+ this._playbackAnimation = new PlaybackAnimationController(this, {
5604
+ timeToPixels: (time) => this._timeToPixels(time),
5605
+ getPlayhead: () => this._getPlayhead()
5606
+ });
5607
+ /**
5608
+ * True while a seek-while-playing stop+play transition is in flight.
5609
+ * Suppresses the transient settle dispatch from the engine 'stop' handler
5610
+ * (which would otherwise leak a backward-jumping daw-timeupdate at the
5611
+ * play-start position). Non-private: pointer-handler's seek path sets it.
5612
+ */
5613
+ this._inSeekTransition = false;
5450
5614
  this._spectrogramController = null;
5451
5615
  this._clipPointer = new ClipPointerHandler(this);
5452
5616
  this._pointer = new PointerHandler(this);
@@ -5652,6 +5816,14 @@ var DawEditorElement = class extends LitElement11 {
5652
5816
  /** Set in togglePauseRecording when Transport is paused alongside the
5653
5817
  * worklet, so resume can restart it. Cleared on resume and on stop. */
5654
5818
  this._wasPlayingDuringRecording = false;
5819
+ // --- Playback animation (single RAF loop: playhead + daw-timeupdate) ---
5820
+ /** Convert playback seconds to a timeline pixel offset for the active mode. */
5821
+ this._timeToPixels = (time) => {
5822
+ if (this.scaleMode === "beats") {
5823
+ return this._secondsToTicks(time) / this.ticksPerPixel;
5824
+ }
5825
+ return time * this.effectiveSampleRate / this.samplesPerPixel;
5826
+ };
5655
5827
  }
5656
5828
  get samplesPerPixel() {
5657
5829
  return this._samplesPerPixel;
@@ -5668,6 +5840,35 @@ var DawEditorElement = class extends LitElement11 {
5668
5840
  this._samplesPerPixel = clamped;
5669
5841
  this.requestUpdate("samplesPerPixel", old);
5670
5842
  }
5843
+ get timeFormat() {
5844
+ return this._timeFormat;
5845
+ }
5846
+ set timeFormat(value) {
5847
+ if (!isTimeDisplayFormat(value)) {
5848
+ console.warn(
5849
+ '[dawcore] timeFormat: invalid format "' + String(value) + '" ignored. Valid formats: ' + TIME_DISPLAY_FORMATS.join(", ")
5850
+ );
5851
+ if (this.hasAttribute("time-format") && this.getAttribute("time-format") !== this._timeFormat) {
5852
+ this.setAttribute("time-format", this._timeFormat);
5853
+ }
5854
+ return;
5855
+ }
5856
+ if (value === this._timeFormat) return;
5857
+ const old = this._timeFormat;
5858
+ this._timeFormat = value;
5859
+ this.requestUpdate("timeFormat", old);
5860
+ this.dispatchEvent(
5861
+ new CustomEvent("daw-time-format-change", {
5862
+ bubbles: true,
5863
+ composed: true,
5864
+ detail: { format: value }
5865
+ })
5866
+ );
5867
+ }
5868
+ /** Set the time display format. Sugar over the `timeFormat` property. */
5869
+ setTimeFormat(format) {
5870
+ this.timeFormat = format;
5871
+ }
5671
5872
  get spectrogramConfig() {
5672
5873
  return this._spectrogramConfig;
5673
5874
  }
@@ -6793,17 +6994,23 @@ var DawEditorElement = class extends LitElement11 {
6793
6994
  zoomLevels: [256, 512, 1024, 2048, 4096, 8192, this.samplesPerPixel].filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b)
6794
6995
  });
6795
6996
  let lastTracksVersion = -1;
6997
+ let lastMixerVersion = -1;
6796
6998
  engine.on("statechange", (engineState) => {
6797
6999
  this._isPlaying = engineState.isPlaying;
6798
7000
  this._duration = engineState.duration;
6799
7001
  this._selectedTrackId = engineState.selectedTrackId;
6800
- if (engineState.tracksVersion !== lastTracksVersion) {
7002
+ const structuralChange = engineState.tracksVersion !== lastTracksVersion;
7003
+ const mixerChange = engineState.mixerVersion !== lastMixerVersion;
7004
+ if (structuralChange || mixerChange) {
6801
7005
  lastTracksVersion = engineState.tracksVersion;
7006
+ lastMixerVersion = engineState.mixerVersion;
6802
7007
  const nextTracks = /* @__PURE__ */ new Map();
6803
7008
  for (const track of engineState.tracks) {
6804
7009
  nextTracks.set(track.id, track);
6805
7010
  }
6806
7011
  this._engineTracks = nextTracks;
7012
+ }
7013
+ if (structuralChange) {
6807
7014
  this._effectsManager?.rewireTrackChains();
6808
7015
  const audioTracks = engineState.tracks.filter((t) => {
6809
7016
  const desc = this._tracks.get(t.id);
@@ -7164,7 +7371,12 @@ var DawEditorElement = class extends LitElement11 {
7164
7371
  return;
7165
7372
  }
7166
7373
  if (this._isPlaying) {
7167
- this.stop();
7374
+ this._inSeekTransition = true;
7375
+ try {
7376
+ this.stop();
7377
+ } finally {
7378
+ this._inSeekTransition = false;
7379
+ }
7168
7380
  this.play(time);
7169
7381
  } else {
7170
7382
  this._engine.seek(time);
@@ -7223,6 +7435,14 @@ var DawEditorElement = class extends LitElement11 {
7223
7435
  }
7224
7436
  return this._currentTime;
7225
7437
  }
7438
+ /** Read-only: whether playback is running (HTMLMediaElement-adjacent). */
7439
+ get isPlaying() {
7440
+ return this._isPlaying;
7441
+ }
7442
+ /** Read-only: total content duration in seconds. */
7443
+ get duration() {
7444
+ return this._duration;
7445
+ }
7226
7446
  get isRecording() {
7227
7447
  return this._recordingController.isRecording;
7228
7448
  }
@@ -7313,33 +7533,15 @@ var DawEditorElement = class extends LitElement11 {
7313
7533
  `;
7314
7534
  });
7315
7535
  }
7316
- // --- Playhead ---
7317
7536
  _startPlayhead() {
7318
- const playhead = this._getPlayhead();
7319
- if (!playhead || !this._engine) return;
7537
+ if (!this._engine) return;
7320
7538
  const engine = this._engine;
7321
- const audibleTime = () => engine.getAudibleTime();
7322
- if (this.scaleMode === "beats") {
7323
- const secondsToTicksFn = (s) => this._secondsToTicks(s);
7324
- playhead.startBeatsAnimationWithMap(audibleTime, secondsToTicksFn, this.ticksPerPixel);
7325
- } else {
7326
- playhead.startAnimation(audibleTime, this.effectiveSampleRate, this.samplesPerPixel);
7327
- }
7539
+ this._playbackAnimation.start(() => engine.getAudibleTime());
7328
7540
  }
7329
7541
  _stopPlayhead() {
7330
- const playhead = this._getPlayhead();
7331
- if (!playhead) return;
7332
7542
  const t = this._currentTime;
7333
7543
  const visualTime = Number.isFinite(t) ? Math.max(0, t) : 0;
7334
- if (this.scaleMode === "beats") {
7335
- playhead.stopBeatsAnimationWithMap(
7336
- visualTime,
7337
- (s) => this._secondsToTicks(s),
7338
- this.ticksPerPixel
7339
- );
7340
- } else {
7341
- playhead.stopAnimation(visualTime, this.effectiveSampleRate, this.samplesPerPixel);
7342
- }
7544
+ this._playbackAnimation.stop(visualTime, { dispatch: !this._inSeekTransition });
7343
7545
  }
7344
7546
  _getPlayhead() {
7345
7547
  return this.shadowRoot?.querySelector("daw-playhead");
@@ -7684,6 +7886,9 @@ DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "mut
7684
7886
  __decorateClass([
7685
7887
  property9({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
7686
7888
  ], DawEditorElement.prototype, "samplesPerPixel", 1);
7889
+ __decorateClass([
7890
+ property9({ attribute: "time-format", reflect: true, noAccessor: true })
7891
+ ], DawEditorElement.prototype, "timeFormat", 1);
7687
7892
  __decorateClass([
7688
7893
  property9({ type: Number, attribute: "wave-height" })
7689
7894
  ], DawEditorElement.prototype, "waveHeight", 2);
@@ -7864,7 +8069,12 @@ var DawRecordButtonElement = class extends DawTransportButton {
7864
8069
  }
7865
8070
  render() {
7866
8071
  return html12`
7867
- <button part="button" ?data-recording=${this._isRecording} @click=${this._onClick}>
8072
+ <button
8073
+ part="button"
8074
+ ?disabled=${!this.targetSupported}
8075
+ ?data-recording=${this._isRecording}
8076
+ @click=${this._onClick}
8077
+ >
7868
8078
  <slot>Record</slot>
7869
8079
  </button>
7870
8080
  `;
@@ -7873,14 +8083,16 @@ var DawRecordButtonElement = class extends DawTransportButton {
7873
8083
  if (this._isRecording) return;
7874
8084
  const target = this.target;
7875
8085
  if (!target) {
7876
- console.warn(
7877
- '[dawcore] <daw-record-button> has no target. Check <daw-transport for="..."> references a valid <daw-editor> id.'
7878
- );
8086
+ warnNoTargetOnce(this);
7879
8087
  return;
7880
8088
  }
7881
8089
  target.startRecording(target.recordingStream);
7882
8090
  }
7883
8091
  };
8092
+ DawRecordButtonElement.requiredTargetMethods = [
8093
+ "startRecording",
8094
+ "stopRecording"
8095
+ ];
7884
8096
  DawRecordButtonElement.styles = [
7885
8097
  DawTransportButton.styles,
7886
8098
  css12`
@@ -8257,6 +8469,198 @@ __decorateClass([
8257
8469
  DawSpectrogramElement = __decorateClass([
8258
8470
  customElement17("daw-spectrogram")
8259
8471
  ], DawSpectrogramElement);
8472
+
8473
+ // src/elements/daw-time-display.ts
8474
+ import { LitElement as LitElement15, html as html14, css as css14 } from "lit";
8475
+ import { customElement as customElement18, state as state5 } from "lit/decorators.js";
8476
+ var DawTimeDisplayElement = class extends LitElement15 {
8477
+ constructor() {
8478
+ super(...arguments);
8479
+ this._time = null;
8480
+ this._format = "hh:mm:ss.sss";
8481
+ this._onTimeUpdate = (e) => {
8482
+ if (e.target !== this.target) return;
8483
+ if (this._time === null) {
8484
+ const timeFormat = e.target.timeFormat;
8485
+ if (isTimeDisplayFormat(timeFormat)) this._format = timeFormat;
8486
+ }
8487
+ this._time = e.detail.time;
8488
+ };
8489
+ this._onFormatChange = (e) => {
8490
+ if (e.target !== this.target) return;
8491
+ const detail = e.detail;
8492
+ if (isTimeDisplayFormat(detail.format)) {
8493
+ this._format = detail.format;
8494
+ }
8495
+ };
8496
+ }
8497
+ get target() {
8498
+ return resolveTransportTarget(this);
8499
+ }
8500
+ connectedCallback() {
8501
+ super.connectedCallback();
8502
+ document.addEventListener("daw-timeupdate", this._onTimeUpdate);
8503
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8504
+ requestAnimationFrame(() => this._syncFromTarget());
8505
+ }
8506
+ disconnectedCallback() {
8507
+ super.disconnectedCallback();
8508
+ document.removeEventListener("daw-timeupdate", this._onTimeUpdate);
8509
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8510
+ }
8511
+ _syncFromTarget() {
8512
+ if (!this.isConnected) return;
8513
+ const target = this.target;
8514
+ if (!target || typeof target.currentTime !== "number") {
8515
+ warnNoTargetOnce(
8516
+ this,
8517
+ " The display recovers automatically once the target dispatches daw-timeupdate."
8518
+ );
8519
+ return;
8520
+ }
8521
+ this._time = target.currentTime;
8522
+ const fmt = target.timeFormat;
8523
+ if (isTimeDisplayFormat(fmt)) {
8524
+ this._format = fmt;
8525
+ }
8526
+ }
8527
+ render() {
8528
+ const text = this._time === null ? "--:--:--" : formatDisplayTime(this._time, this._format);
8529
+ return html14`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
8530
+ }
8531
+ };
8532
+ DawTimeDisplayElement.styles = css14`
8533
+ span {
8534
+ display: inline-block;
8535
+ font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
8536
+ font-variant-numeric: tabular-nums;
8537
+ color: var(--daw-controls-text, #e0d4c8);
8538
+ background: var(--daw-controls-background, #1a1a2e);
8539
+ border: 1px solid currentColor;
8540
+ padding: 4px 8px;
8541
+ }
8542
+ `;
8543
+ __decorateClass([
8544
+ state5()
8545
+ ], DawTimeDisplayElement.prototype, "_time", 2);
8546
+ __decorateClass([
8547
+ state5()
8548
+ ], DawTimeDisplayElement.prototype, "_format", 2);
8549
+ DawTimeDisplayElement = __decorateClass([
8550
+ customElement18("daw-time-display")
8551
+ ], DawTimeDisplayElement);
8552
+
8553
+ // src/elements/daw-time-format.ts
8554
+ import { LitElement as LitElement16, html as html15, css as css15 } from "lit";
8555
+ import { customElement as customElement19, state as state6 } from "lit/decorators.js";
8556
+ var DawTimeFormatElement = class extends LitElement16 {
8557
+ constructor() {
8558
+ super(...arguments);
8559
+ this._format = "hh:mm:ss.sss";
8560
+ this._onFormatChange = (e) => {
8561
+ if (e.target !== this.target) return;
8562
+ const detail = e.detail;
8563
+ if (isTimeDisplayFormat(detail.format)) {
8564
+ this._format = detail.format;
8565
+ }
8566
+ };
8567
+ this._onPointerEnter = () => {
8568
+ this.requestUpdate();
8569
+ };
8570
+ this._onPointerDown = () => {
8571
+ const target = this.target;
8572
+ if (!target) {
8573
+ warnNoTargetOnce(this);
8574
+ return;
8575
+ }
8576
+ if (!this._targetSupported) {
8577
+ warnUnsupportedOnce(this, ["setTimeFormat"]);
8578
+ }
8579
+ };
8580
+ }
8581
+ get target() {
8582
+ return resolveTransportTarget(this);
8583
+ }
8584
+ /**
8585
+ * False when the target doesn't implement setTimeFormat. An undetermined
8586
+ * target (missing, or a not-yet-upgraded custom element) gets the benefit
8587
+ * of the doubt and stays enabled — interaction-time resolution warns if
8588
+ * it's still unusable.
8589
+ */
8590
+ get _targetSupported() {
8591
+ const target = this.target;
8592
+ if (targetUndetermined(target)) return true;
8593
+ return targetSupports(target, ["setTimeFormat"]);
8594
+ }
8595
+ connectedCallback() {
8596
+ super.connectedCallback();
8597
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8598
+ this.addEventListener("pointerdown", this._onPointerDown);
8599
+ this.addEventListener("pointerenter", this._onPointerEnter);
8600
+ requestAnimationFrame(() => {
8601
+ if (!this.isConnected) return;
8602
+ const target = this.target;
8603
+ if (target && isTimeDisplayFormat(target.timeFormat)) {
8604
+ this._format = target.timeFormat;
8605
+ }
8606
+ this.requestUpdate();
8607
+ });
8608
+ }
8609
+ disconnectedCallback() {
8610
+ super.disconnectedCallback();
8611
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8612
+ this.removeEventListener("pointerdown", this._onPointerDown);
8613
+ this.removeEventListener("pointerenter", this._onPointerEnter);
8614
+ }
8615
+ updated() {
8616
+ const select = this.shadowRoot?.querySelector("select");
8617
+ if (select && select.value !== this._format) {
8618
+ select.value = this._format;
8619
+ }
8620
+ }
8621
+ _onSelectChange(e) {
8622
+ const value = e.target.value;
8623
+ const target = this.target;
8624
+ if (!target) {
8625
+ warnNoTargetOnce(this);
8626
+ return;
8627
+ }
8628
+ target.setTimeFormat?.(value);
8629
+ }
8630
+ render() {
8631
+ return html15`
8632
+ <select
8633
+ aria-label="Time format"
8634
+ ?disabled=${!this._targetSupported}
8635
+ @change=${this._onSelectChange}
8636
+ >
8637
+ ${TIME_DISPLAY_FORMATS.map(
8638
+ (f) => html15`<option value=${f} ?selected=${f === this._format}>${f}</option>`
8639
+ )}
8640
+ </select>
8641
+ `;
8642
+ }
8643
+ };
8644
+ DawTimeFormatElement.styles = css15`
8645
+ select {
8646
+ cursor: pointer;
8647
+ background: var(--daw-controls-background, #1a1a2e);
8648
+ color: var(--daw-controls-text, #e0d4c8);
8649
+ border: 1px solid currentColor;
8650
+ padding: 4px 8px;
8651
+ font: inherit;
8652
+ }
8653
+ select:disabled {
8654
+ opacity: 0.4;
8655
+ cursor: default;
8656
+ }
8657
+ `;
8658
+ __decorateClass([
8659
+ state6()
8660
+ ], DawTimeFormatElement.prototype, "_format", 2);
8661
+ DawTimeFormatElement = __decorateClass([
8662
+ customElement19("daw-time-format")
8663
+ ], DawTimeFormatElement);
8260
8664
  export {
8261
8665
  AudioResumeController,
8262
8666
  ClipPointerHandler,
@@ -8273,17 +8677,28 @@ export {
8273
8677
  DawSelectionElement,
8274
8678
  DawSpectrogramElement,
8275
8679
  DawStopButtonElement,
8680
+ DawTimeDisplayElement,
8681
+ DawTimeFormatElement,
8276
8682
  DawTrackControlsElement,
8277
8683
  DawTrackElement,
8278
8684
  DawTransportButton,
8279
8685
  DawTransportElement,
8280
8686
  DawWaveformElement,
8687
+ PlaybackAnimationController,
8281
8688
  RecordingController,
8282
8689
  SpectrogramController,
8690
+ TIME_DISPLAY_FORMATS,
8283
8691
  createEffectInstance,
8692
+ formatDisplayTime,
8284
8693
  getEffectDefinitions,
8285
8694
  isDomClip,
8695
+ isTimeDisplayFormat,
8696
+ parseDisplayTime,
8286
8697
  registerEffect,
8287
- splitAtPlayhead
8698
+ resolveTransportTarget,
8699
+ splitAtPlayhead,
8700
+ targetSupports,
8701
+ warnOnce,
8702
+ warnUnsupportedOnce
8288
8703
  };
8289
8704
  //# sourceMappingURL=index.mjs.map