@waveform-playlist/core 13.0.0-next.8 → 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 +13 -6
- package/dist/index.d.mts +71 -14
- package/dist/index.d.ts +71 -14
- package/dist/index.js +65 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,8 @@ 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` |
|
|
@@ -91,17 +92,17 @@ MIT
|
|
|
91
92
|
|
|
92
93
|
## Pan stage
|
|
93
94
|
|
|
94
|
-
`createPanStage(audioContext, pan,
|
|
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,
|
|
98
|
+
import { createPanStage, trackPanLaw } from '@waveform-playlist/core';
|
|
98
99
|
|
|
99
|
-
const stage = createPanStage(audioContext, track.pan,
|
|
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.
|
|
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,
|
|
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) */
|
|
@@ -1067,8 +1115,8 @@ interface TrackChannelSource {
|
|
|
1067
1115
|
}
|
|
1068
1116
|
/**
|
|
1069
1117
|
* Max audio channel count across a track's clips (1 for a track with no
|
|
1070
|
-
* decoded audio).
|
|
1071
|
-
*
|
|
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).
|
|
1072
1120
|
*/
|
|
1073
1121
|
declare function trackChannelCount(track: TrackChannelSource): number;
|
|
1074
1122
|
/**
|
|
@@ -1458,40 +1506,47 @@ interface PanMatrix {
|
|
|
1458
1506
|
rr: number;
|
|
1459
1507
|
}
|
|
1460
1508
|
/**
|
|
1461
|
-
* The pan law
|
|
1462
|
-
*
|
|
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.
|
|
1463
1512
|
*
|
|
1464
|
-
* -
|
|
1513
|
+
* - `'mono'` — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
|
|
1465
1514
|
* For a mono signal (taken as L = R) that is the mono law, L = m·cos θ and
|
|
1466
1515
|
* R = m·sin θ: −3 dB per side at centre. A stereo signal from the track's
|
|
1467
1516
|
* effects is balanced by the same gains, so it stays stereo at the same
|
|
1468
1517
|
* centre level as the dry signal.
|
|
1469
|
-
* -
|
|
1518
|
+
* - `'stereo'` — the stereo law: centre passes both channels at unity;
|
|
1470
1519
|
* panning left folds the right channel into the left
|
|
1471
1520
|
* (L + R·cos x, R·sin x with x = (pan + 1)·π/2), and symmetrically right.
|
|
1472
1521
|
*
|
|
1473
1522
|
* `pan` is clamped to −1 … 1; a non-finite value is treated as centre.
|
|
1474
1523
|
*/
|
|
1475
|
-
declare function panMatrix(pan: number,
|
|
1524
|
+
declare function panMatrix(pan: number, panLaw: DecidedPanLaw): PanMatrix;
|
|
1476
1525
|
/**
|
|
1477
1526
|
* The part of an audio context the pan stage needs. Any `AudioContext` or
|
|
1478
1527
|
* `OfflineAudioContext` satisfies it, and so does the `rawContext` behind
|
|
1479
1528
|
* Tone.js (native or standardized-audio-context).
|
|
1480
1529
|
*/
|
|
1481
|
-
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;
|
|
1482
1533
|
/** A track's pan stage: `input → … → output`, with `setPan(-1 … 1)`. */
|
|
1483
1534
|
interface PanStage {
|
|
1484
1535
|
readonly input: AudioNode;
|
|
1485
1536
|
readonly output: AudioNode;
|
|
1486
1537
|
setPan(pan: number): void;
|
|
1487
|
-
/**
|
|
1488
|
-
|
|
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;
|
|
1489
1544
|
/** Disconnect every node of the stage. */
|
|
1490
1545
|
dispose(): void;
|
|
1491
1546
|
}
|
|
1492
1547
|
/**
|
|
1493
|
-
* Build the pan stage for a track
|
|
1494
|
-
* `
|
|
1548
|
+
* Build the pan stage for a track with the pan law `panLaw` (core's
|
|
1549
|
+
* `trackPanLaw(track)`; `'mono'` for synth voices).
|
|
1495
1550
|
*
|
|
1496
1551
|
* Why this is not a `StereoPannerNode`: a track's pan stage is fed by its
|
|
1497
1552
|
* effects chain (pre-fader inserts), whose channel layout is not the
|
|
@@ -1505,7 +1560,7 @@ interface PanStage {
|
|
|
1505
1560
|
* nodes — none of which is restricted — so it behaves identically on every
|
|
1506
1561
|
* context, always passes stereo through, and takes its law from the caller.
|
|
1507
1562
|
*/
|
|
1508
|
-
declare function createPanStage(context: PanStageContext, pan: number,
|
|
1563
|
+
declare function createPanStage(context: PanStageContext, pan: number, panLaw: DecidedPanLaw): PanStage;
|
|
1509
1564
|
|
|
1510
1565
|
type SourceState<V> = {
|
|
1511
1566
|
status: 'pending';
|
|
@@ -1570,6 +1625,8 @@ interface AudioTrackOptions {
|
|
|
1570
1625
|
soloed?: boolean;
|
|
1571
1626
|
volume?: number;
|
|
1572
1627
|
pan?: number;
|
|
1628
|
+
/** The pan law the track enters with. Default: 'auto', decided by its first decoded audio. */
|
|
1629
|
+
panLaw?: PanLaw;
|
|
1573
1630
|
renderMode?: RenderMode;
|
|
1574
1631
|
spectrogramConfig?: SpectrogramConfig;
|
|
1575
1632
|
spectrogramColorMap?: ColorMapValue;
|
|
@@ -1728,4 +1785,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
|
|
|
1728
1785
|
declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
|
|
1729
1786
|
declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
|
|
1730
1787
|
|
|
1731
|
-
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, 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) */
|
|
@@ -1067,8 +1115,8 @@ interface TrackChannelSource {
|
|
|
1067
1115
|
}
|
|
1068
1116
|
/**
|
|
1069
1117
|
* Max audio channel count across a track's clips (1 for a track with no
|
|
1070
|
-
* decoded audio).
|
|
1071
|
-
*
|
|
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).
|
|
1072
1120
|
*/
|
|
1073
1121
|
declare function trackChannelCount(track: TrackChannelSource): number;
|
|
1074
1122
|
/**
|
|
@@ -1458,40 +1506,47 @@ interface PanMatrix {
|
|
|
1458
1506
|
rr: number;
|
|
1459
1507
|
}
|
|
1460
1508
|
/**
|
|
1461
|
-
* The pan law
|
|
1462
|
-
*
|
|
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.
|
|
1463
1512
|
*
|
|
1464
|
-
* -
|
|
1513
|
+
* - `'mono'` — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
|
|
1465
1514
|
* For a mono signal (taken as L = R) that is the mono law, L = m·cos θ and
|
|
1466
1515
|
* R = m·sin θ: −3 dB per side at centre. A stereo signal from the track's
|
|
1467
1516
|
* effects is balanced by the same gains, so it stays stereo at the same
|
|
1468
1517
|
* centre level as the dry signal.
|
|
1469
|
-
* -
|
|
1518
|
+
* - `'stereo'` — the stereo law: centre passes both channels at unity;
|
|
1470
1519
|
* panning left folds the right channel into the left
|
|
1471
1520
|
* (L + R·cos x, R·sin x with x = (pan + 1)·π/2), and symmetrically right.
|
|
1472
1521
|
*
|
|
1473
1522
|
* `pan` is clamped to −1 … 1; a non-finite value is treated as centre.
|
|
1474
1523
|
*/
|
|
1475
|
-
declare function panMatrix(pan: number,
|
|
1524
|
+
declare function panMatrix(pan: number, panLaw: DecidedPanLaw): PanMatrix;
|
|
1476
1525
|
/**
|
|
1477
1526
|
* The part of an audio context the pan stage needs. Any `AudioContext` or
|
|
1478
1527
|
* `OfflineAudioContext` satisfies it, and so does the `rawContext` behind
|
|
1479
1528
|
* Tone.js (native or standardized-audio-context).
|
|
1480
1529
|
*/
|
|
1481
|
-
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;
|
|
1482
1533
|
/** A track's pan stage: `input → … → output`, with `setPan(-1 … 1)`. */
|
|
1483
1534
|
interface PanStage {
|
|
1484
1535
|
readonly input: AudioNode;
|
|
1485
1536
|
readonly output: AudioNode;
|
|
1486
1537
|
setPan(pan: number): void;
|
|
1487
|
-
/**
|
|
1488
|
-
|
|
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;
|
|
1489
1544
|
/** Disconnect every node of the stage. */
|
|
1490
1545
|
dispose(): void;
|
|
1491
1546
|
}
|
|
1492
1547
|
/**
|
|
1493
|
-
* Build the pan stage for a track
|
|
1494
|
-
* `
|
|
1548
|
+
* Build the pan stage for a track with the pan law `panLaw` (core's
|
|
1549
|
+
* `trackPanLaw(track)`; `'mono'` for synth voices).
|
|
1495
1550
|
*
|
|
1496
1551
|
* Why this is not a `StereoPannerNode`: a track's pan stage is fed by its
|
|
1497
1552
|
* effects chain (pre-fader inserts), whose channel layout is not the
|
|
@@ -1505,7 +1560,7 @@ interface PanStage {
|
|
|
1505
1560
|
* nodes — none of which is restricted — so it behaves identically on every
|
|
1506
1561
|
* context, always passes stereo through, and takes its law from the caller.
|
|
1507
1562
|
*/
|
|
1508
|
-
declare function createPanStage(context: PanStageContext, pan: number,
|
|
1563
|
+
declare function createPanStage(context: PanStageContext, pan: number, panLaw: DecidedPanLaw): PanStage;
|
|
1509
1564
|
|
|
1510
1565
|
type SourceState<V> = {
|
|
1511
1566
|
status: 'pending';
|
|
@@ -1570,6 +1625,8 @@ interface AudioTrackOptions {
|
|
|
1570
1625
|
soloed?: boolean;
|
|
1571
1626
|
volume?: number;
|
|
1572
1627
|
pan?: number;
|
|
1628
|
+
/** The pan law the track enters with. Default: 'auto', decided by its first decoded audio. */
|
|
1629
|
+
panLaw?: PanLaw;
|
|
1573
1630
|
renderMode?: RenderMode;
|
|
1574
1631
|
spectrogramConfig?: SpectrogramConfig;
|
|
1575
1632
|
spectrogramColorMap?: ColorMapValue;
|
|
@@ -1728,4 +1785,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
|
|
|
1728
1785
|
declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
|
|
1729
1786
|
declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
|
|
1730
1787
|
|
|
1731
|
-
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, 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,6 +42,7 @@ __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
48
|
carveClipRange: () => carveClipRange,
|
|
@@ -78,6 +81,7 @@ __export(index_exports, {
|
|
|
78
81
|
getClipsInRange: () => getClipsInRange,
|
|
79
82
|
getEffectDefinitions: () => getEffectDefinitions,
|
|
80
83
|
handleKeyboardEvent: () => handleKeyboardEvent,
|
|
84
|
+
isDecidedPanLaw: () => isDecidedPanLaw,
|
|
81
85
|
isLoadingClip: () => isLoadingClip,
|
|
82
86
|
keyBelongsToFocusedControl: () => keyBelongsToFocusedControl,
|
|
83
87
|
linearCurve: () => linearCurve,
|
|
@@ -113,6 +117,7 @@ __export(index_exports, {
|
|
|
113
117
|
ticksToSamples: () => ticksToSamples,
|
|
114
118
|
trackChannelCount: () => trackChannelCount,
|
|
115
119
|
trackKind: () => trackKind,
|
|
120
|
+
trackPanLaw: () => trackPanLaw,
|
|
116
121
|
unregisterEffect: () => unregisterEffect,
|
|
117
122
|
updateAnnotationBoundaries: () => updateAnnotationBoundaries,
|
|
118
123
|
watchMicrophoneDevices: () => watchMicrophoneDevices
|
|
@@ -1427,9 +1432,9 @@ function applyAnnotationBounds(current, changes) {
|
|
|
1427
1432
|
|
|
1428
1433
|
// src/panStage.ts
|
|
1429
1434
|
var PREFIX = "[waveform-playlist] ";
|
|
1430
|
-
function panMatrix(pan,
|
|
1435
|
+
function panMatrix(pan, panLaw) {
|
|
1431
1436
|
const p = Number.isFinite(pan) ? Math.max(-1, Math.min(1, pan)) : 0;
|
|
1432
|
-
if (
|
|
1437
|
+
if (panLaw === "mono") {
|
|
1433
1438
|
const theta = (p + 1) * Math.PI / 4;
|
|
1434
1439
|
return { ll: Math.cos(theta), lr: 0, rl: 0, rr: Math.sin(theta) };
|
|
1435
1440
|
}
|
|
@@ -1440,7 +1445,8 @@ function panMatrix(pan, sourceChannelCount) {
|
|
|
1440
1445
|
const x = p * Math.PI / 2;
|
|
1441
1446
|
return { ll: Math.cos(x), lr: Math.sin(x), rl: 0, rr: 1 };
|
|
1442
1447
|
}
|
|
1443
|
-
|
|
1448
|
+
var PAN_LAW_RAMP_SECONDS = 0.01;
|
|
1449
|
+
function createPanStage(context, pan, panLaw) {
|
|
1444
1450
|
const upmix = context.createGain();
|
|
1445
1451
|
upmix.channelCount = 2;
|
|
1446
1452
|
upmix.channelCountMode = "explicit";
|
|
@@ -1452,13 +1458,32 @@ function createPanStage(context, pan, sourceChannelCount) {
|
|
|
1452
1458
|
const rl = context.createGain();
|
|
1453
1459
|
const rr = context.createGain();
|
|
1454
1460
|
let currentPan = pan;
|
|
1455
|
-
let
|
|
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
|
+
};
|
|
1456
1472
|
const apply = () => {
|
|
1457
|
-
const
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
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;
|
|
1462
1487
|
};
|
|
1463
1488
|
apply();
|
|
1464
1489
|
upmix.connect(split);
|
|
@@ -1477,9 +1502,10 @@ function createPanStage(context, pan, sourceChannelCount) {
|
|
|
1477
1502
|
currentPan = value;
|
|
1478
1503
|
apply();
|
|
1479
1504
|
},
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1505
|
+
setPanLaw: (value) => {
|
|
1506
|
+
if (value === currentLaw) return;
|
|
1507
|
+
currentLaw = value;
|
|
1508
|
+
ramp();
|
|
1483
1509
|
},
|
|
1484
1510
|
dispose: () => {
|
|
1485
1511
|
for (const node of [upmix, split, ll, lr, rl, rr, merge]) {
|
|
@@ -1493,6 +1519,26 @@ function createPanStage(context, pan, sourceChannelCount) {
|
|
|
1493
1519
|
};
|
|
1494
1520
|
}
|
|
1495
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
|
+
|
|
1496
1542
|
// src/valueSource.ts
|
|
1497
1543
|
function silentMeterLevels(channelCount) {
|
|
1498
1544
|
const count = Math.max(0, Math.floor(channelCount));
|
|
@@ -1728,7 +1774,8 @@ function audioTrack(options) {
|
|
|
1728
1774
|
...base,
|
|
1729
1775
|
id: options.id || base.id,
|
|
1730
1776
|
clips: [clip],
|
|
1731
|
-
renderMode: options.renderMode
|
|
1777
|
+
renderMode: options.renderMode,
|
|
1778
|
+
...options.panLaw !== void 0 && { panLaw: options.panLaw }
|
|
1732
1779
|
};
|
|
1733
1780
|
return track;
|
|
1734
1781
|
}
|
|
@@ -1899,6 +1946,7 @@ function createEffectInstance(type, audioContext, params = {}) {
|
|
|
1899
1946
|
0 && (module.exports = {
|
|
1900
1947
|
ANNOTATION_LINK_THRESHOLD_TICKS,
|
|
1901
1948
|
DEFAULT_ANNOTATION_SHORTCUTS,
|
|
1949
|
+
DEFAULT_PAN_LAW,
|
|
1902
1950
|
DEFAULT_SPECTROGRAM_COLOR_MAP,
|
|
1903
1951
|
InteractionState,
|
|
1904
1952
|
LINK_THRESHOLD,
|
|
@@ -1906,6 +1954,7 @@ function createEffectInstance(type, audioContext, params = {}) {
|
|
|
1906
1954
|
METER_PEAK_DECAY,
|
|
1907
1955
|
MIN_ANNOTATION_DURATION,
|
|
1908
1956
|
MIN_PIXELS_PER_UNIT,
|
|
1957
|
+
PAN_LAW_RAMP_SECONDS,
|
|
1909
1958
|
PPQN,
|
|
1910
1959
|
SPECTROGRAM_DEFAULTS,
|
|
1911
1960
|
TRACK_VIEW_FIELDS,
|
|
@@ -1917,6 +1966,7 @@ function createEffectInstance(type, audioContext, params = {}) {
|
|
|
1917
1966
|
applyFadeOut,
|
|
1918
1967
|
assertTrackKind,
|
|
1919
1968
|
audibleLatencySamples,
|
|
1969
|
+
audioPanLaw,
|
|
1920
1970
|
audioTrack,
|
|
1921
1971
|
buildSpectrogramCanvasId,
|
|
1922
1972
|
carveClipRange,
|
|
@@ -1955,6 +2005,7 @@ function createEffectInstance(type, audioContext, params = {}) {
|
|
|
1955
2005
|
getClipsInRange,
|
|
1956
2006
|
getEffectDefinitions,
|
|
1957
2007
|
handleKeyboardEvent,
|
|
2008
|
+
isDecidedPanLaw,
|
|
1958
2009
|
isLoadingClip,
|
|
1959
2010
|
keyBelongsToFocusedControl,
|
|
1960
2011
|
linearCurve,
|
|
@@ -1990,6 +2041,7 @@ function createEffectInstance(type, audioContext, params = {}) {
|
|
|
1990
2041
|
ticksToSamples,
|
|
1991
2042
|
trackChannelCount,
|
|
1992
2043
|
trackKind,
|
|
2044
|
+
trackPanLaw,
|
|
1993
2045
|
unregisterEffect,
|
|
1994
2046
|
updateAnnotationBoundaries,
|
|
1995
2047
|
watchMicrophoneDevices
|