@waveform-playlist/core 13.0.0-next.7 → 13.0.0-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,14 +63,15 @@ parseSpectrogramCanvasId(id);
63
63
  | `clipTimeHelpers` | `clipStartTime`, `clipEndTime`, `clipOffsetTime`, `clipDurationTime`, `clipPixelWidth`, `trackChannelCount` |
64
64
  | clip constructors (`types/clip`) | `createClip`, `createClipFromSeconds`, `createClipFromTicks`, `createTrack`, `createTimeline`, `getClipsInRange`, `getClipsAtSample`, `clipsOverlap`, `sortClipsByTime`, `findGaps` |
65
65
  | `fades` | `applyFadeIn`, `applyFadeOut`, `generateCurve`, `linearCurve`, `exponentialCurve`, `logarithmicCurve`, `sCurveCurve` |
66
- | `panStage` | `createPanStage`, `panMatrix`, `PanStage`, `PanMatrix`, `PanStageContext` |
66
+ | `panStage` | `createPanStage`, `panMatrix`, `PAN_LAW_RAMP_SECONDS`, `PanStage`, `PanMatrix`, `PanStageContext` |
67
+ | `panLaw` | `PanLaw`, `DecidedPanLaw`, `DEFAULT_PAN_LAW`, `isDecidedPanLaw`, `audioPanLaw`, `trackPanLaw`, `TrackPanLawSource` |
67
68
  | `utils/dBUtils` | `gainToDb`, `dBToNormalized`, `normalizedToDb`, `gainToNormalized` |
68
69
  | `utils/conversions` | `samplesToSeconds`, `secondsToSamples`, `samplesToPixels`, `pixelsToSamples`, `pixelsToSeconds`, `secondsToPixels` |
69
70
  | `utils/beatsAndBars` | `PPQN`, `ticksPerBeat`, `ticksPerBar`, `ticksToSamples`, `samplesToTicks`, `snapToGrid` |
70
71
  | `utils/musicalTicks` | `computeMusicalTicks`, `snapToTicks`, `snapTickToGrid`, `SnapTo`, `MusicalTick` |
71
72
  | `utils/meterDetection` | `MeterEntry`, `detectMeterChanges` |
72
73
  | `utils/peaksGenerator` | `generatePeaks`, `appendPeaks` |
73
- | `utils/audioBufferUtils` | `concatenateAudioData`, `createAudioBuffer`, `appendToAudioBuffer`, `calculateDuration` |
74
+ | `utils/audioBufferUtils` | `concatenateAudioData`, `createAudioBuffer`, `appendToAudioBuffer` |
74
75
  | `utils/latency` | `resolveRecordingOffsetSamples` — override-vs-auto recording latency compensation (shared by React + dawcore) |
75
76
  | `utils/carveClipRange` | `carveClipRange` — punch-in replace: carve a sample range out of a clip list (trim/remove/split) |
76
77
  | `keyboard` | `KeyboardShortcut`, `handleKeyboardEvent` |
@@ -91,17 +92,17 @@ MIT
91
92
 
92
93
  ## Pan stage
93
94
 
94
- `createPanStage(audioContext, pan, sourceChannelCount)` builds a track's pan stage from plain gain, splitter and merger nodes. Every renderer in this project pans with it — the native transport, the Tone.js adapter and both offline exports — instead of a Web Audio `StereoPannerNode` or a Tone.js `Panner`.
95
+ `createPanStage(audioContext, pan, panLaw)` builds a track's pan stage from plain gain, splitter and merger nodes. Every renderer in this project pans with it — the native transport, the Tone.js adapter and both offline exports — instead of a Web Audio `StereoPannerNode` or a Tone.js `Panner`.
95
96
 
96
97
  ```typescript
97
- import { createPanStage, trackChannelCount } from '@waveform-playlist/core';
98
+ import { createPanStage, trackPanLaw } from '@waveform-playlist/core';
98
99
 
99
- const stage = createPanStage(audioContext, track.pan, trackChannelCount(track));
100
+ const stage = createPanStage(audioContext, track.pan, trackPanLaw(track)); // 'mono' | 'stereo'
100
101
  faderNode.connect(stage.input);
101
102
  stage.output.connect(muteNode);
102
103
 
103
104
  stage.setPan(-0.5);
104
- stage.setSourceChannelCount(2); // the track gained a stereo clip
105
+ stage.setPanLaw('stereo'); // the four gains ramp over 10 ms
105
106
  stage.dispose();
106
107
  ```
107
108
 
@@ -110,7 +111,13 @@ Why not the built-in nodes:
110
111
  - **`StereoPannerNode`** chooses its pan law from the signal it receives: equal-power for mono input (−3 dB per side at centre), the stereo law for stereo input (unity at centre). Track effects are pre-fader inserts, so the panner would be fed by the effects chain and the law would follow the chain's output: a mono track would jump about 3 dB at centre as soon as a stereo effect was added.
111
112
  - **Tone.js `Panner`** wraps a `StereoPannerNode` with a fixed channel count. On Tone's default context (standardized-audio-context) that setting cannot be changed, so a mono track's panner is locked to one channel and a stereo effect on the track is summed to mono before it is panned.
112
113
 
113
- The stage implements the same two laws as `StereoPannerNode` (`panMatrix(pan, sourceChannelCount)` is the pure math) but takes the law from the caller — the channel count of the track's source material — and always passes stereo through. It works on any `AudioContext` or `OfflineAudioContext`, and on the raw context behind Tone.js.
114
+ The stage implements the same two laws as `StereoPannerNode` (`panMatrix(pan, panLaw)` is the pure math) but takes the law from the caller and always passes stereo through. It works on any `AudioContext` or `OfflineAudioContext`, and on the raw context behind Tone.js.
115
+
116
+ ### A track's pan law
117
+
118
+ `PanLaw` is `'auto' | 'mono' | 'stereo'`. `'mono'` is equal power (−3 dB per side at centre, the channels never mixed); `'stereo'` is unity at centre with fold-over; `'auto'` means not decided yet. `ClipTrack.panLaw` is the law a track enters an arrangement with (default `'auto'`), and `audioTrack({ panLaw })` sets it.
119
+
120
+ `trackPanLaw(track)` is the law a renderer pans a track with: the track's own when it is `'mono'` or `'stereo'`, else the law of its clips (`audioPanLaw(track)`: `'stereo'` if a clip's buffer has two or more channels, `'mono'` if a clip has a buffer), else `'mono'`. In an arrangement (`@waveform-playlist/engine`) the law is a mixer value that the track's first decoded audio decides and its clips never change afterwards. The law converts no audio.
114
121
 
115
122
  ## Effect registry
116
123
 
package/dist/index.d.mts CHANGED
@@ -82,6 +82,48 @@ type SpectrogramDisplayConfig = Pick<SpectrogramConfig, 'frequencyScale' | 'minF
82
82
  */
83
83
  type RenderMode = 'waveform' | 'spectrogram' | 'both';
84
84
 
85
+ /**
86
+ * A track's pan law (#684).
87
+ *
88
+ * - `'mono'`: equal power, −3 dB per side at centre; the channels are never
89
+ * mixed.
90
+ * - `'stereo'`: unity at centre; panning folds one channel into the other.
91
+ * - `'auto'`: not decided yet. It is the default, and the first decoded
92
+ * audio a track holds decides it (an arrangement stores the result as a
93
+ * mixer value, and a track's clips never change it afterwards).
94
+ *
95
+ * The law says how a track is panned. It converts nothing: a stereo clip on
96
+ * a `'mono'` track still plays in stereo.
97
+ */
98
+ type PanLaw = 'auto' | 'mono' | 'stereo';
99
+ /** A law a pan stage can apply: every `PanLaw` except `'auto'`. */
100
+ type DecidedPanLaw = Exclude<PanLaw, 'auto'>;
101
+ declare const DEFAULT_PAN_LAW: PanLaw;
102
+ /** True for `'mono'` and `'stereo'` only; any other value, of any type, is not a decided law. */
103
+ declare function isDecidedPanLaw(value: unknown): value is DecidedPanLaw;
104
+ /** The part of a track `trackPanLaw` reads: `ClipTrack` satisfies it. */
105
+ interface TrackPanLawSource {
106
+ panLaw?: PanLaw;
107
+ clips: ReadonlyArray<{
108
+ audioBuffer?: {
109
+ numberOfChannels: number;
110
+ };
111
+ }>;
112
+ }
113
+ /**
114
+ * The law of the decoded audio a track holds: `'stereo'` when any clip's
115
+ * buffer has two or more channels, `'mono'` when at least one clip has a
116
+ * buffer, `null` when none has (an empty track, loading clips, MIDI clips,
117
+ * clips made from peaks alone).
118
+ */
119
+ declare function audioPanLaw(track: Pick<TrackPanLawSource, 'clips'>): DecidedPanLaw | null;
120
+ /**
121
+ * The law a renderer pans a track with: the track's own when it is decided;
122
+ * else (`'auto'`, no field, or a value that is not a law) the law of its
123
+ * audio; else `'mono'`.
124
+ */
125
+ declare function trackPanLaw(track: TrackPanLawSource): DecidedPanLaw;
126
+
85
127
  /**
86
128
  * Clip-Based Model Types
87
129
  *
@@ -274,6 +316,12 @@ interface ClipTrack {
274
316
  volume: number;
275
317
  /** Stereo pan (-1.0 = left, 0 = center, 1.0 = right) */
276
318
  pan: number;
319
+ /**
320
+ * The pan law this track enters with (default `'auto'`: decided by its
321
+ * first decoded audio). While the track is in an arrangement, the
322
+ * arrangement's mixer holds the value (#684).
323
+ */
324
+ panLaw?: PanLaw;
277
325
  /** Optional track color for visual distinction */
278
326
  color?: string;
279
327
  /** Track height in pixels (for UI) */
@@ -882,10 +930,6 @@ declare function createAudioBuffer(audioContext: AudioContext, channelData: Floa
882
930
  * Append new samples to an existing AudioBuffer (mono convenience)
883
931
  */
884
932
  declare function appendToAudioBuffer(audioContext: AudioContext, existingBuffer: AudioBuffer | null, newSamples: Float32Array, sampleRate: number): AudioBuffer;
885
- /**
886
- * Calculate duration in seconds from sample count and sample rate
887
- */
888
- declare function calculateDuration(sampleCount: number, sampleRate: number): number;
889
933
 
890
934
  /**
891
935
  * Sample count corresponding to the audible-latency window
@@ -1071,8 +1115,8 @@ interface TrackChannelSource {
1071
1115
  }
1072
1116
  /**
1073
1117
  * Max audio channel count across a track's clips (1 for a track with no
1074
- * decoded audio). Selects the track's pan law (`createPanStage`) and the
1075
- * offline render's output channels.
1118
+ * decoded audio). Read for the React export's output channels. The track's
1119
+ * pan law is not chosen from it: that is `trackPanLaw(track)` (#684).
1076
1120
  */
1077
1121
  declare function trackChannelCount(track: TrackChannelSource): number;
1078
1122
  /**
@@ -1462,40 +1506,47 @@ interface PanMatrix {
1462
1506
  rr: number;
1463
1507
  }
1464
1508
  /**
1465
- * The pan law for a track, chosen by the channel count of its SOURCE
1466
- * material — exactly the two algorithms of the Web Audio `StereoPannerNode`.
1509
+ * The gains of a pan law at a pan position: exactly the two algorithms of
1510
+ * the Web Audio `StereoPannerNode`. Which law a track has is the track's own
1511
+ * value (`trackPanLaw`), not a property of the signal that reaches the stage.
1467
1512
  *
1468
- * - Mono source — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
1513
+ * - `'mono'` — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
1469
1514
  * For a mono signal (taken as L = R) that is the mono law, L = m·cos θ and
1470
1515
  * R = m·sin θ: −3 dB per side at centre. A stereo signal from the track's
1471
1516
  * effects is balanced by the same gains, so it stays stereo at the same
1472
1517
  * centre level as the dry signal.
1473
- * - Stereo source — the stereo law: centre passes both channels at unity;
1518
+ * - `'stereo'` — the stereo law: centre passes both channels at unity;
1474
1519
  * panning left folds the right channel into the left
1475
1520
  * (L + R·cos x, R·sin x with x = (pan + 1)·π/2), and symmetrically right.
1476
1521
  *
1477
1522
  * `pan` is clamped to −1 … 1; a non-finite value is treated as centre.
1478
1523
  */
1479
- declare function panMatrix(pan: number, sourceChannelCount: number): PanMatrix;
1524
+ declare function panMatrix(pan: number, panLaw: DecidedPanLaw): PanMatrix;
1480
1525
  /**
1481
1526
  * The part of an audio context the pan stage needs. Any `AudioContext` or
1482
1527
  * `OfflineAudioContext` satisfies it, and so does the `rawContext` behind
1483
1528
  * Tone.js (native or standardized-audio-context).
1484
1529
  */
1485
- type PanStageContext = Pick<BaseAudioContext, 'createGain' | 'createChannelSplitter' | 'createChannelMerger'>;
1530
+ type PanStageContext = Pick<BaseAudioContext, 'createGain' | 'createChannelSplitter' | 'createChannelMerger' | 'currentTime'>;
1531
+ /** How long a switch of pan law takes: the four gains ramp, so a switch during playback does not click (#684). */
1532
+ declare const PAN_LAW_RAMP_SECONDS = 0.01;
1486
1533
  /** A track's pan stage: `input → … → output`, with `setPan(-1 … 1)`. */
1487
1534
  interface PanStage {
1488
1535
  readonly input: AudioNode;
1489
1536
  readonly output: AudioNode;
1490
1537
  setPan(pan: number): void;
1491
- /** Switch the pan law (1 = mono law, 2+ = stereo law), keeping the pan. */
1492
- setSourceChannelCount(sourceChannelCount: number): void;
1538
+ /**
1539
+ * Switch the pan law, keeping the pan. The four gains ramp to the new
1540
+ * matrix over `PAN_LAW_RAMP_SECONDS`; the law the stage already has does
1541
+ * nothing.
1542
+ */
1543
+ setPanLaw(panLaw: DecidedPanLaw): void;
1493
1544
  /** Disconnect every node of the stage. */
1494
1545
  dispose(): void;
1495
1546
  }
1496
1547
  /**
1497
- * Build the pan stage for a track whose source material has
1498
- * `sourceChannelCount` channels (1 for mono clips and synth voices).
1548
+ * Build the pan stage for a track with the pan law `panLaw` (core's
1549
+ * `trackPanLaw(track)`; `'mono'` for synth voices).
1499
1550
  *
1500
1551
  * Why this is not a `StereoPannerNode`: a track's pan stage is fed by its
1501
1552
  * effects chain (pre-fader inserts), whose channel layout is not the
@@ -1509,7 +1560,7 @@ interface PanStage {
1509
1560
  * nodes — none of which is restricted — so it behaves identically on every
1510
1561
  * context, always passes stereo through, and takes its law from the caller.
1511
1562
  */
1512
- declare function createPanStage(context: PanStageContext, pan: number, sourceChannelCount: number): PanStage;
1563
+ declare function createPanStage(context: PanStageContext, pan: number, panLaw: DecidedPanLaw): PanStage;
1513
1564
 
1514
1565
  type SourceState<V> = {
1515
1566
  status: 'pending';
@@ -1574,6 +1625,8 @@ interface AudioTrackOptions {
1574
1625
  soloed?: boolean;
1575
1626
  volume?: number;
1576
1627
  pan?: number;
1628
+ /** The pan law the track enters with. Default: 'auto', decided by its first decoded audio. */
1629
+ panLaw?: PanLaw;
1577
1630
  renderMode?: RenderMode;
1578
1631
  spectrogramConfig?: SpectrogramConfig;
1579
1632
  spectrogramColorMap?: ColorMapValue;
@@ -1732,4 +1785,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1732
1785
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1733
1786
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1734
1787
 
1735
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1788
+ export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_PAN_LAW, DEFAULT_SPECTROGRAM_COLOR_MAP, type DecidedPanLaw, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PAN_LAW_RAMP_SECONDS, PPQN, type PanLaw, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackPanLawSource, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioPanLaw, audioTrack, buildSpectrogramCanvasId, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isDecidedPanLaw, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, trackPanLaw, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.d.ts CHANGED
@@ -82,6 +82,48 @@ type SpectrogramDisplayConfig = Pick<SpectrogramConfig, 'frequencyScale' | 'minF
82
82
  */
83
83
  type RenderMode = 'waveform' | 'spectrogram' | 'both';
84
84
 
85
+ /**
86
+ * A track's pan law (#684).
87
+ *
88
+ * - `'mono'`: equal power, −3 dB per side at centre; the channels are never
89
+ * mixed.
90
+ * - `'stereo'`: unity at centre; panning folds one channel into the other.
91
+ * - `'auto'`: not decided yet. It is the default, and the first decoded
92
+ * audio a track holds decides it (an arrangement stores the result as a
93
+ * mixer value, and a track's clips never change it afterwards).
94
+ *
95
+ * The law says how a track is panned. It converts nothing: a stereo clip on
96
+ * a `'mono'` track still plays in stereo.
97
+ */
98
+ type PanLaw = 'auto' | 'mono' | 'stereo';
99
+ /** A law a pan stage can apply: every `PanLaw` except `'auto'`. */
100
+ type DecidedPanLaw = Exclude<PanLaw, 'auto'>;
101
+ declare const DEFAULT_PAN_LAW: PanLaw;
102
+ /** True for `'mono'` and `'stereo'` only; any other value, of any type, is not a decided law. */
103
+ declare function isDecidedPanLaw(value: unknown): value is DecidedPanLaw;
104
+ /** The part of a track `trackPanLaw` reads: `ClipTrack` satisfies it. */
105
+ interface TrackPanLawSource {
106
+ panLaw?: PanLaw;
107
+ clips: ReadonlyArray<{
108
+ audioBuffer?: {
109
+ numberOfChannels: number;
110
+ };
111
+ }>;
112
+ }
113
+ /**
114
+ * The law of the decoded audio a track holds: `'stereo'` when any clip's
115
+ * buffer has two or more channels, `'mono'` when at least one clip has a
116
+ * buffer, `null` when none has (an empty track, loading clips, MIDI clips,
117
+ * clips made from peaks alone).
118
+ */
119
+ declare function audioPanLaw(track: Pick<TrackPanLawSource, 'clips'>): DecidedPanLaw | null;
120
+ /**
121
+ * The law a renderer pans a track with: the track's own when it is decided;
122
+ * else (`'auto'`, no field, or a value that is not a law) the law of its
123
+ * audio; else `'mono'`.
124
+ */
125
+ declare function trackPanLaw(track: TrackPanLawSource): DecidedPanLaw;
126
+
85
127
  /**
86
128
  * Clip-Based Model Types
87
129
  *
@@ -274,6 +316,12 @@ interface ClipTrack {
274
316
  volume: number;
275
317
  /** Stereo pan (-1.0 = left, 0 = center, 1.0 = right) */
276
318
  pan: number;
319
+ /**
320
+ * The pan law this track enters with (default `'auto'`: decided by its
321
+ * first decoded audio). While the track is in an arrangement, the
322
+ * arrangement's mixer holds the value (#684).
323
+ */
324
+ panLaw?: PanLaw;
277
325
  /** Optional track color for visual distinction */
278
326
  color?: string;
279
327
  /** Track height in pixels (for UI) */
@@ -882,10 +930,6 @@ declare function createAudioBuffer(audioContext: AudioContext, channelData: Floa
882
930
  * Append new samples to an existing AudioBuffer (mono convenience)
883
931
  */
884
932
  declare function appendToAudioBuffer(audioContext: AudioContext, existingBuffer: AudioBuffer | null, newSamples: Float32Array, sampleRate: number): AudioBuffer;
885
- /**
886
- * Calculate duration in seconds from sample count and sample rate
887
- */
888
- declare function calculateDuration(sampleCount: number, sampleRate: number): number;
889
933
 
890
934
  /**
891
935
  * Sample count corresponding to the audible-latency window
@@ -1071,8 +1115,8 @@ interface TrackChannelSource {
1071
1115
  }
1072
1116
  /**
1073
1117
  * Max audio channel count across a track's clips (1 for a track with no
1074
- * decoded audio). Selects the track's pan law (`createPanStage`) and the
1075
- * offline render's output channels.
1118
+ * decoded audio). Read for the React export's output channels. The track's
1119
+ * pan law is not chosen from it: that is `trackPanLaw(track)` (#684).
1076
1120
  */
1077
1121
  declare function trackChannelCount(track: TrackChannelSource): number;
1078
1122
  /**
@@ -1462,40 +1506,47 @@ interface PanMatrix {
1462
1506
  rr: number;
1463
1507
  }
1464
1508
  /**
1465
- * The pan law for a track, chosen by the channel count of its SOURCE
1466
- * material — exactly the two algorithms of the Web Audio `StereoPannerNode`.
1509
+ * The gains of a pan law at a pan position: exactly the two algorithms of
1510
+ * the Web Audio `StereoPannerNode`. Which law a track has is the track's own
1511
+ * value (`trackPanLaw`), not a property of the signal that reaches the stage.
1467
1512
  *
1468
- * - Mono source — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
1513
+ * - `'mono'` — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
1469
1514
  * For a mono signal (taken as L = R) that is the mono law, L = m·cos θ and
1470
1515
  * R = m·sin θ: −3 dB per side at centre. A stereo signal from the track's
1471
1516
  * effects is balanced by the same gains, so it stays stereo at the same
1472
1517
  * centre level as the dry signal.
1473
- * - Stereo source — the stereo law: centre passes both channels at unity;
1518
+ * - `'stereo'` — the stereo law: centre passes both channels at unity;
1474
1519
  * panning left folds the right channel into the left
1475
1520
  * (L + R·cos x, R·sin x with x = (pan + 1)·π/2), and symmetrically right.
1476
1521
  *
1477
1522
  * `pan` is clamped to −1 … 1; a non-finite value is treated as centre.
1478
1523
  */
1479
- declare function panMatrix(pan: number, sourceChannelCount: number): PanMatrix;
1524
+ declare function panMatrix(pan: number, panLaw: DecidedPanLaw): PanMatrix;
1480
1525
  /**
1481
1526
  * The part of an audio context the pan stage needs. Any `AudioContext` or
1482
1527
  * `OfflineAudioContext` satisfies it, and so does the `rawContext` behind
1483
1528
  * Tone.js (native or standardized-audio-context).
1484
1529
  */
1485
- type PanStageContext = Pick<BaseAudioContext, 'createGain' | 'createChannelSplitter' | 'createChannelMerger'>;
1530
+ type PanStageContext = Pick<BaseAudioContext, 'createGain' | 'createChannelSplitter' | 'createChannelMerger' | 'currentTime'>;
1531
+ /** How long a switch of pan law takes: the four gains ramp, so a switch during playback does not click (#684). */
1532
+ declare const PAN_LAW_RAMP_SECONDS = 0.01;
1486
1533
  /** A track's pan stage: `input → … → output`, with `setPan(-1 … 1)`. */
1487
1534
  interface PanStage {
1488
1535
  readonly input: AudioNode;
1489
1536
  readonly output: AudioNode;
1490
1537
  setPan(pan: number): void;
1491
- /** Switch the pan law (1 = mono law, 2+ = stereo law), keeping the pan. */
1492
- setSourceChannelCount(sourceChannelCount: number): void;
1538
+ /**
1539
+ * Switch the pan law, keeping the pan. The four gains ramp to the new
1540
+ * matrix over `PAN_LAW_RAMP_SECONDS`; the law the stage already has does
1541
+ * nothing.
1542
+ */
1543
+ setPanLaw(panLaw: DecidedPanLaw): void;
1493
1544
  /** Disconnect every node of the stage. */
1494
1545
  dispose(): void;
1495
1546
  }
1496
1547
  /**
1497
- * Build the pan stage for a track whose source material has
1498
- * `sourceChannelCount` channels (1 for mono clips and synth voices).
1548
+ * Build the pan stage for a track with the pan law `panLaw` (core's
1549
+ * `trackPanLaw(track)`; `'mono'` for synth voices).
1499
1550
  *
1500
1551
  * Why this is not a `StereoPannerNode`: a track's pan stage is fed by its
1501
1552
  * effects chain (pre-fader inserts), whose channel layout is not the
@@ -1509,7 +1560,7 @@ interface PanStage {
1509
1560
  * nodes — none of which is restricted — so it behaves identically on every
1510
1561
  * context, always passes stereo through, and takes its law from the caller.
1511
1562
  */
1512
- declare function createPanStage(context: PanStageContext, pan: number, sourceChannelCount: number): PanStage;
1563
+ declare function createPanStage(context: PanStageContext, pan: number, panLaw: DecidedPanLaw): PanStage;
1513
1564
 
1514
1565
  type SourceState<V> = {
1515
1566
  status: 'pending';
@@ -1574,6 +1625,8 @@ interface AudioTrackOptions {
1574
1625
  soloed?: boolean;
1575
1626
  volume?: number;
1576
1627
  pan?: number;
1628
+ /** The pan law the track enters with. Default: 'auto', decided by its first decoded audio. */
1629
+ panLaw?: PanLaw;
1577
1630
  renderMode?: RenderMode;
1578
1631
  spectrogramConfig?: SpectrogramConfig;
1579
1632
  spectrogramColorMap?: ColorMapValue;
@@ -1732,4 +1785,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1732
1785
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1733
1786
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1734
1787
 
1735
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1788
+ export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_PAN_LAW, DEFAULT_SPECTROGRAM_COLOR_MAP, type DecidedPanLaw, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PAN_LAW_RAMP_SECONDS, PPQN, type PanLaw, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackPanLawSource, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioPanLaw, audioTrack, buildSpectrogramCanvasId, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isDecidedPanLaw, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, trackPanLaw, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ANNOTATION_LINK_THRESHOLD_TICKS: () => ANNOTATION_LINK_THRESHOLD_TICKS,
24
24
  DEFAULT_ANNOTATION_SHORTCUTS: () => DEFAULT_ANNOTATION_SHORTCUTS,
25
+ DEFAULT_PAN_LAW: () => DEFAULT_PAN_LAW,
25
26
  DEFAULT_SPECTROGRAM_COLOR_MAP: () => DEFAULT_SPECTROGRAM_COLOR_MAP,
26
27
  InteractionState: () => InteractionState,
27
28
  LINK_THRESHOLD: () => LINK_THRESHOLD,
@@ -29,6 +30,7 @@ __export(index_exports, {
29
30
  METER_PEAK_DECAY: () => METER_PEAK_DECAY,
30
31
  MIN_ANNOTATION_DURATION: () => MIN_ANNOTATION_DURATION,
31
32
  MIN_PIXELS_PER_UNIT: () => MIN_PIXELS_PER_UNIT,
33
+ PAN_LAW_RAMP_SECONDS: () => PAN_LAW_RAMP_SECONDS,
32
34
  PPQN: () => PPQN,
33
35
  SPECTROGRAM_DEFAULTS: () => SPECTROGRAM_DEFAULTS,
34
36
  TRACK_VIEW_FIELDS: () => TRACK_VIEW_FIELDS,
@@ -40,9 +42,9 @@ __export(index_exports, {
40
42
  applyFadeOut: () => applyFadeOut,
41
43
  assertTrackKind: () => assertTrackKind,
42
44
  audibleLatencySamples: () => audibleLatencySamples,
45
+ audioPanLaw: () => audioPanLaw,
43
46
  audioTrack: () => audioTrack,
44
47
  buildSpectrogramCanvasId: () => buildSpectrogramCanvasId,
45
- calculateDuration: () => calculateDuration,
46
48
  carveClipRange: () => carveClipRange,
47
49
  clipDurationTime: () => clipDurationTime,
48
50
  clipEndTime: () => clipEndTime,
@@ -79,6 +81,7 @@ __export(index_exports, {
79
81
  getClipsInRange: () => getClipsInRange,
80
82
  getEffectDefinitions: () => getEffectDefinitions,
81
83
  handleKeyboardEvent: () => handleKeyboardEvent,
84
+ isDecidedPanLaw: () => isDecidedPanLaw,
82
85
  isLoadingClip: () => isLoadingClip,
83
86
  keyBelongsToFocusedControl: () => keyBelongsToFocusedControl,
84
87
  linearCurve: () => linearCurve,
@@ -114,6 +117,7 @@ __export(index_exports, {
114
117
  ticksToSamples: () => ticksToSamples,
115
118
  trackChannelCount: () => trackChannelCount,
116
119
  trackKind: () => trackKind,
120
+ trackPanLaw: () => trackPanLaw,
117
121
  unregisterEffect: () => unregisterEffect,
118
122
  updateAnnotationBoundaries: () => updateAnnotationBoundaries,
119
123
  watchMicrophoneDevices: () => watchMicrophoneDevices
@@ -789,9 +793,6 @@ function appendToAudioBuffer(audioContext, existingBuffer, newSamples, sampleRat
789
793
  const combined = concatenateAudioData([existingData, newSamples]);
790
794
  return createAudioBuffer(audioContext, [combined], sampleRate);
791
795
  }
792
- function calculateDuration(sampleCount, sampleRate) {
793
- return sampleCount / sampleRate;
794
- }
795
796
 
796
797
  // src/utils/latency.ts
797
798
  function audibleLatencySamples(outputLatency, lookAhead, sampleRate) {
@@ -1431,9 +1432,9 @@ function applyAnnotationBounds(current, changes) {
1431
1432
 
1432
1433
  // src/panStage.ts
1433
1434
  var PREFIX = "[waveform-playlist] ";
1434
- function panMatrix(pan, sourceChannelCount) {
1435
+ function panMatrix(pan, panLaw) {
1435
1436
  const p = Number.isFinite(pan) ? Math.max(-1, Math.min(1, pan)) : 0;
1436
- if (sourceChannelCount < 2) {
1437
+ if (panLaw === "mono") {
1437
1438
  const theta = (p + 1) * Math.PI / 4;
1438
1439
  return { ll: Math.cos(theta), lr: 0, rl: 0, rr: Math.sin(theta) };
1439
1440
  }
@@ -1444,7 +1445,8 @@ function panMatrix(pan, sourceChannelCount) {
1444
1445
  const x = p * Math.PI / 2;
1445
1446
  return { ll: Math.cos(x), lr: Math.sin(x), rl: 0, rr: 1 };
1446
1447
  }
1447
- function createPanStage(context, pan, sourceChannelCount) {
1448
+ var PAN_LAW_RAMP_SECONDS = 0.01;
1449
+ function createPanStage(context, pan, panLaw) {
1448
1450
  const upmix = context.createGain();
1449
1451
  upmix.channelCount = 2;
1450
1452
  upmix.channelCountMode = "explicit";
@@ -1456,13 +1458,32 @@ function createPanStage(context, pan, sourceChannelCount) {
1456
1458
  const rl = context.createGain();
1457
1459
  const rr = context.createGain();
1458
1460
  let currentPan = pan;
1459
- let currentChannelCount = sourceChannelCount;
1461
+ let currentLaw = panLaw;
1462
+ let rampScheduled = false;
1463
+ const targets = () => {
1464
+ const matrix = panMatrix(currentPan, currentLaw);
1465
+ return [
1466
+ [ll, matrix.ll],
1467
+ [lr, matrix.lr],
1468
+ [rl, matrix.rl],
1469
+ [rr, matrix.rr]
1470
+ ];
1471
+ };
1460
1472
  const apply = () => {
1461
- const matrix = panMatrix(currentPan, currentChannelCount);
1462
- ll.gain.value = matrix.ll;
1463
- lr.gain.value = matrix.lr;
1464
- rl.gain.value = matrix.rl;
1465
- rr.gain.value = matrix.rr;
1473
+ for (const [node, value] of targets()) {
1474
+ if (rampScheduled) node.gain.cancelScheduledValues(context.currentTime);
1475
+ node.gain.value = value;
1476
+ }
1477
+ rampScheduled = false;
1478
+ };
1479
+ const ramp = () => {
1480
+ const now = context.currentTime;
1481
+ for (const [node, value] of targets()) {
1482
+ node.gain.cancelScheduledValues(now);
1483
+ node.gain.setValueAtTime(node.gain.value, now);
1484
+ node.gain.linearRampToValueAtTime(value, now + PAN_LAW_RAMP_SECONDS);
1485
+ }
1486
+ rampScheduled = true;
1466
1487
  };
1467
1488
  apply();
1468
1489
  upmix.connect(split);
@@ -1481,9 +1502,10 @@ function createPanStage(context, pan, sourceChannelCount) {
1481
1502
  currentPan = value;
1482
1503
  apply();
1483
1504
  },
1484
- setSourceChannelCount: (value) => {
1485
- currentChannelCount = value;
1486
- apply();
1505
+ setPanLaw: (value) => {
1506
+ if (value === currentLaw) return;
1507
+ currentLaw = value;
1508
+ ramp();
1487
1509
  },
1488
1510
  dispose: () => {
1489
1511
  for (const node of [upmix, split, ll, lr, rl, rr, merge]) {
@@ -1497,6 +1519,26 @@ function createPanStage(context, pan, sourceChannelCount) {
1497
1519
  };
1498
1520
  }
1499
1521
 
1522
+ // src/panLaw.ts
1523
+ var DEFAULT_PAN_LAW = "auto";
1524
+ function isDecidedPanLaw(value) {
1525
+ return value === "mono" || value === "stereo";
1526
+ }
1527
+ function audioPanLaw(track) {
1528
+ let law = null;
1529
+ for (const clip of track.clips) {
1530
+ const channels = clip.audioBuffer?.numberOfChannels;
1531
+ if (channels === void 0) continue;
1532
+ if (channels >= 2) return "stereo";
1533
+ law = "mono";
1534
+ }
1535
+ return law;
1536
+ }
1537
+ function trackPanLaw(track) {
1538
+ if (isDecidedPanLaw(track.panLaw)) return track.panLaw;
1539
+ return audioPanLaw(track) ?? "mono";
1540
+ }
1541
+
1500
1542
  // src/valueSource.ts
1501
1543
  function silentMeterLevels(channelCount) {
1502
1544
  const count = Math.max(0, Math.floor(channelCount));
@@ -1732,7 +1774,8 @@ function audioTrack(options) {
1732
1774
  ...base,
1733
1775
  id: options.id || base.id,
1734
1776
  clips: [clip],
1735
- renderMode: options.renderMode
1777
+ renderMode: options.renderMode,
1778
+ ...options.panLaw !== void 0 && { panLaw: options.panLaw }
1736
1779
  };
1737
1780
  return track;
1738
1781
  }
@@ -1903,6 +1946,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1903
1946
  0 && (module.exports = {
1904
1947
  ANNOTATION_LINK_THRESHOLD_TICKS,
1905
1948
  DEFAULT_ANNOTATION_SHORTCUTS,
1949
+ DEFAULT_PAN_LAW,
1906
1950
  DEFAULT_SPECTROGRAM_COLOR_MAP,
1907
1951
  InteractionState,
1908
1952
  LINK_THRESHOLD,
@@ -1910,6 +1954,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1910
1954
  METER_PEAK_DECAY,
1911
1955
  MIN_ANNOTATION_DURATION,
1912
1956
  MIN_PIXELS_PER_UNIT,
1957
+ PAN_LAW_RAMP_SECONDS,
1913
1958
  PPQN,
1914
1959
  SPECTROGRAM_DEFAULTS,
1915
1960
  TRACK_VIEW_FIELDS,
@@ -1921,9 +1966,9 @@ function createEffectInstance(type, audioContext, params = {}) {
1921
1966
  applyFadeOut,
1922
1967
  assertTrackKind,
1923
1968
  audibleLatencySamples,
1969
+ audioPanLaw,
1924
1970
  audioTrack,
1925
1971
  buildSpectrogramCanvasId,
1926
- calculateDuration,
1927
1972
  carveClipRange,
1928
1973
  clipDurationTime,
1929
1974
  clipEndTime,
@@ -1960,6 +2005,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1960
2005
  getClipsInRange,
1961
2006
  getEffectDefinitions,
1962
2007
  handleKeyboardEvent,
2008
+ isDecidedPanLaw,
1963
2009
  isLoadingClip,
1964
2010
  keyBelongsToFocusedControl,
1965
2011
  linearCurve,
@@ -1995,6 +2041,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1995
2041
  ticksToSamples,
1996
2042
  trackChannelCount,
1997
2043
  trackKind,
2044
+ trackPanLaw,
1998
2045
  unregisterEffect,
1999
2046
  updateAnnotationBoundaries,
2000
2047
  watchMicrophoneDevices