@schmooky/zvuk 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +144 -1
- package/dist/index.js +232 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,18 @@ interface BusConfig {
|
|
|
130
130
|
concurrency?: ConcurrencyConfig;
|
|
131
131
|
sidechain?: SidechainConfig;
|
|
132
132
|
}
|
|
133
|
+
interface SendOptions {
|
|
134
|
+
/** Send level (0..1). Default 1. */
|
|
135
|
+
amount?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Tap the source bus's output (post-fader, post-FX) when `true`,
|
|
138
|
+
* or input (pre-fader, pre-FX) when `false`. Default `true` — almost
|
|
139
|
+
* always what you want. Pre-fader sends are mainly useful for
|
|
140
|
+
* monitoring buses that should hear the dry signal regardless of how
|
|
141
|
+
* the user has faded the source bus down.
|
|
142
|
+
*/
|
|
143
|
+
post?: boolean;
|
|
144
|
+
}
|
|
133
145
|
interface MasterLimiterConfig {
|
|
134
146
|
/** Threshold in dB. Default -1 (just below 0 dBFS). */
|
|
135
147
|
threshold?: number;
|
|
@@ -578,6 +590,26 @@ declare class Voice {
|
|
|
578
590
|
private computeOffset;
|
|
579
591
|
}
|
|
580
592
|
|
|
593
|
+
/**
|
|
594
|
+
* One configured send from a source bus to a target bus. Returned by
|
|
595
|
+
* `bus.send(target, ...)`; held by callers so the level can be adjusted
|
|
596
|
+
* (or the send removed) at runtime.
|
|
597
|
+
*/
|
|
598
|
+
declare class Send {
|
|
599
|
+
readonly source: Bus;
|
|
600
|
+
readonly target: Bus;
|
|
601
|
+
readonly post: boolean;
|
|
602
|
+
private gainNode;
|
|
603
|
+
private ctx;
|
|
604
|
+
private disposed;
|
|
605
|
+
constructor(source: Bus, target: Bus, options: SendOptions, ctx: AudioContext);
|
|
606
|
+
/** Live send level (0..1). Setter ramps over 10 ms to avoid clicks. */
|
|
607
|
+
get amount(): number;
|
|
608
|
+
set amount(v: number);
|
|
609
|
+
/** Fade the send to `target` over `duration` seconds. */
|
|
610
|
+
fadeTo(target: number, duration: number, curve?: FadeCurve): Promise<void>;
|
|
611
|
+
dispose(): void;
|
|
612
|
+
}
|
|
581
613
|
/**
|
|
582
614
|
* A Bus is a named mix bucket with its own gain stage, optional FX inserts,
|
|
583
615
|
* a voice-concurrency limit, and an optional sidechain key.
|
|
@@ -597,12 +629,21 @@ declare class Bus {
|
|
|
597
629
|
readonly output: GainNode;
|
|
598
630
|
private _level;
|
|
599
631
|
private _muted;
|
|
632
|
+
private _soloed;
|
|
600
633
|
private readonly ctx;
|
|
601
634
|
private _concurrency;
|
|
602
635
|
private _voices;
|
|
603
636
|
private _fxChain;
|
|
637
|
+
private _sends;
|
|
604
638
|
private _meterAnalyser;
|
|
605
639
|
private _meterBuf;
|
|
640
|
+
/**
|
|
641
|
+
* Engine-injected callback fired when this bus's solo state changes.
|
|
642
|
+
* The Engine uses it to coordinate the global "any soloed → mute the
|
|
643
|
+
* rest" rule across every bus in the graph. Bus does not depend on
|
|
644
|
+
* Engine; the callback is the only escape hatch.
|
|
645
|
+
*/
|
|
646
|
+
notifySoloChange?: (bus: Bus, soloed: boolean) => void;
|
|
606
647
|
constructor(ctx: AudioContext, name: string, config?: BusConfig);
|
|
607
648
|
get level(): number;
|
|
608
649
|
set level(v: number);
|
|
@@ -642,6 +683,47 @@ declare class Bus {
|
|
|
642
683
|
* reacts to overall bus level, or implement custom voice-stealing rules.
|
|
643
684
|
*/
|
|
644
685
|
meter(): AudioLevel;
|
|
686
|
+
/**
|
|
687
|
+
* Route a copy of this bus's signal into another bus at the configured
|
|
688
|
+
* level. `target.input` mixes the send naturally with whatever else is
|
|
689
|
+
* already feeding it, so the typical pattern — "send 30 % of music to a
|
|
690
|
+
* dedicated reverb bus" — is just two lines:
|
|
691
|
+
*
|
|
692
|
+
* ```ts
|
|
693
|
+
* const verbSend = engine.bus('music').send(engine.bus('reverb'), { amount: 0.3 });
|
|
694
|
+
* verbSend.amount = 0.5; // turn it up live
|
|
695
|
+
* verbSend.dispose(); // remove the send entirely
|
|
696
|
+
* ```
|
|
697
|
+
*
|
|
698
|
+
* Default tap is post-fader / post-FX (`post: true`); set `post: false`
|
|
699
|
+
* if you want a monitor send that hears the dry pre-fader signal.
|
|
700
|
+
*/
|
|
701
|
+
send(target: Bus, options?: SendOptions): Send;
|
|
702
|
+
/** Remove a previously-created send. Idempotent. */
|
|
703
|
+
removeSend(send: Send): void;
|
|
704
|
+
/** Read-only snapshot of every active send originating on this bus. */
|
|
705
|
+
sends(): readonly Send[];
|
|
706
|
+
/**
|
|
707
|
+
* Solo this bus. The engine coordinates the global rule: while any bus
|
|
708
|
+
* is soloed, every non-soloed bus is muted. Soloing multiple buses is
|
|
709
|
+
* additive — they all stay audible. Calling `unsolo()` (or `solo(false)`)
|
|
710
|
+
* removes this bus from the soloed set.
|
|
711
|
+
*
|
|
712
|
+
* Solo state is independent of `muted`; un-soloing returns the bus to
|
|
713
|
+
* whatever its `muted` setting was. Useful in mixer UIs where the user
|
|
714
|
+
* wants to A/B a single channel without disturbing the rest of the mix.
|
|
715
|
+
*/
|
|
716
|
+
solo(on?: boolean): void;
|
|
717
|
+
/** Turn solo off on this bus. Equivalent to `solo(false)`. */
|
|
718
|
+
unsolo(): void;
|
|
719
|
+
/** True when this bus is in the engine's solo set. */
|
|
720
|
+
get soloed(): boolean;
|
|
721
|
+
/**
|
|
722
|
+
* Engine-only. Apply a transient mute (or restore) driven by the global
|
|
723
|
+
* solo state. Distinct from `muted` so un-soloing returns the bus to its
|
|
724
|
+
* user-visible mute state without re-rendering.
|
|
725
|
+
*/
|
|
726
|
+
applySoloVeil(soloMute: boolean): void;
|
|
645
727
|
private rewireFxChain;
|
|
646
728
|
private rampOutput;
|
|
647
729
|
private ramp;
|
|
@@ -814,6 +896,44 @@ declare function ensureStretchWorklet(ctx: AudioContext): Promise<void>;
|
|
|
814
896
|
*/
|
|
815
897
|
declare function createStretchWorkletNode(ctx: AudioContext, options?: StretchWorkletOptions): StretchWorkletNode;
|
|
816
898
|
|
|
899
|
+
/**
|
|
900
|
+
* A logical handle that addresses several buses at once. Doesn't change
|
|
901
|
+
* the audio graph — applies operations (level, fade, mute, solo) to every
|
|
902
|
+
* member in parallel. Useful when several buses form a sub-mix that should
|
|
903
|
+
* always be controlled together: combat = weapons + enemies + environment;
|
|
904
|
+
* voice = dialogue + effort sounds; etc.
|
|
905
|
+
*
|
|
906
|
+
* Construct via `engine.busGroup(name, members)`; look up via
|
|
907
|
+
* `engine.busGroup(name)`. Snapshots and parameters can target a group
|
|
908
|
+
* instead of repeating bus names.
|
|
909
|
+
*/
|
|
910
|
+
declare class BusGroup {
|
|
911
|
+
readonly name: string;
|
|
912
|
+
readonly members: readonly Bus[];
|
|
913
|
+
constructor(name: string, members: readonly Bus[]);
|
|
914
|
+
/** Set the level on every member. Same 10 ms ramp as direct `bus.level =`. */
|
|
915
|
+
set level(v: number);
|
|
916
|
+
/**
|
|
917
|
+
* Read the current level. Returns the average across members — useful
|
|
918
|
+
* when every member shares a level (the common case) and informational
|
|
919
|
+
* otherwise.
|
|
920
|
+
*/
|
|
921
|
+
get level(): number;
|
|
922
|
+
set muted(v: boolean);
|
|
923
|
+
/** True if every member is currently muted. */
|
|
924
|
+
get muted(): boolean;
|
|
925
|
+
/**
|
|
926
|
+
* Fade every member to `target` over `duration` seconds. Returns when
|
|
927
|
+
* the slowest leg completes — in practice they're all equal because
|
|
928
|
+
* each member uses the same duration.
|
|
929
|
+
*/
|
|
930
|
+
fadeTo(target: number, duration: number, curve?: FadeCurve): Promise<void>;
|
|
931
|
+
/** Solo every member of the group. Engine handles the global mute-the-rest rule. */
|
|
932
|
+
solo(on?: boolean): void;
|
|
933
|
+
/** Un-solo every member. */
|
|
934
|
+
unsolo(): void;
|
|
935
|
+
}
|
|
936
|
+
|
|
817
937
|
type ParameterCurve = FadeCurve;
|
|
818
938
|
type Subscriber = (value: number) => void;
|
|
819
939
|
/**
|
|
@@ -1174,6 +1294,20 @@ interface Engine {
|
|
|
1174
1294
|
hasStream(name: string): boolean;
|
|
1175
1295
|
sound(name: string): Sound;
|
|
1176
1296
|
bus(name: string): Bus;
|
|
1297
|
+
/**
|
|
1298
|
+
* Define (with `members`) or look up (without) a `BusGroup` — a logical
|
|
1299
|
+
* handle that addresses several buses at once. Setting `group.level` or
|
|
1300
|
+
* `group.muted`, calling `group.fadeTo`, or `group.solo()` applies to
|
|
1301
|
+
* every member in parallel. Doesn't change the audio graph; pure
|
|
1302
|
+
* convenience for sub-mixes that always move together.
|
|
1303
|
+
*/
|
|
1304
|
+
busGroup(name: string, members?: readonly Bus[]): BusGroup;
|
|
1305
|
+
/**
|
|
1306
|
+
* Live amplitude readout on the master input. Same `{ rms, peak }`
|
|
1307
|
+
* shape as `bus.meter()` and `voice.level()`, just at the top of the
|
|
1308
|
+
* chain. First call lazily attaches a passive AnalyserNode tap.
|
|
1309
|
+
*/
|
|
1310
|
+
masterMeter(): AudioLevel;
|
|
1177
1311
|
/**
|
|
1178
1312
|
* Crossfade helper. Stops `from` over `duration` seconds while playing `to`
|
|
1179
1313
|
* over the same window with `equal-power` curves so the perceived loudness
|
|
@@ -1227,6 +1361,8 @@ declare class Master {
|
|
|
1227
1361
|
private limiterNode;
|
|
1228
1362
|
private limiterCfg;
|
|
1229
1363
|
private destination;
|
|
1364
|
+
private _meterAnalyser;
|
|
1365
|
+
private _meterBuf;
|
|
1230
1366
|
constructor(ctx: AudioContext, config?: MasterConfig);
|
|
1231
1367
|
setHeadroom(db: number): void;
|
|
1232
1368
|
get headroom(): number;
|
|
@@ -1237,6 +1373,13 @@ declare class Master {
|
|
|
1237
1373
|
setLimiter(cfg: MasterLimiterConfig | null): void;
|
|
1238
1374
|
/** Live gain reduction in dB. 0 if no limiter is engaged. */
|
|
1239
1375
|
get reduction(): number;
|
|
1376
|
+
/**
|
|
1377
|
+
* Live amplitude readout on the master input. Returns `{ rms, peak }`
|
|
1378
|
+
* as linear values in [0..1]. The first call lazily attaches an
|
|
1379
|
+
* AnalyserNode as a passive sibling of the master gain — no audio-path
|
|
1380
|
+
* change. Same shape as `bus.meter()` and `voice.level()`.
|
|
1381
|
+
*/
|
|
1382
|
+
meter(): AudioLevel;
|
|
1240
1383
|
dispose(): void;
|
|
1241
1384
|
private rewire;
|
|
1242
1385
|
}
|
|
@@ -1296,4 +1439,4 @@ type NormalizeFlag = boolean | LoudnessOptions;
|
|
|
1296
1439
|
declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag): AudioBuffer;
|
|
1297
1440
|
declare function computeNormalizationGain(buffer: AudioBuffer, opts: Required<LoudnessOptions>): number;
|
|
1298
1441
|
|
|
1299
|
-
export { AggregateDecodeError, type ApplyOptions, type AssetResolver, type AudioLevel, type AudioMimeType, Bus, type BusConfig, BusNotFoundError, Compressor, type CompressorConfig, type ConcurrencyConfig, type CrossfadeOptions, type DecodeAttempt, DecodeError, Ducker, type DuckerConfig, type Engine, EngineClosedError, type EngineConfig, type EngineState, type FadeCurve, type FadeOptions, Filter, type FilterConfig, type FilterKind, type FxInsert, type LoadSoundOptions, type LoudnessOptions, Master, type MasterConfig, type MasterLimiterConfig, Music, type MusicLoadOptions, type MusicParts, type MusicPlayOptions, type MusicState, MusicVoice, type NormalizeFlag, Parameter, type ParameterCurve, type PlayOptions, PreloadError, type PreloadFailure, type PreloadItem, type PreloadOptions, type PreloadProgressEvent, type ResolveAssetContext, type ResolvedAsset, Reverb, type ReverbConfig, type SidechainConfig, type SkipToOutroOptions, Snapshot, type SnapshotState, Sound, SoundNotFoundError, type SpatialOptions, Spatializer, Sprite, type SpriteMap, type SpriteRegion, type SpriteRegionPlayOptions, type StopOptions, StreamSound, StretchProcessor, type StretchWorkletNode, type StretchWorkletOptions, type TickSource, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|
|
1442
|
+
export { AggregateDecodeError, type ApplyOptions, type AssetResolver, type AudioLevel, type AudioMimeType, Bus, type BusConfig, BusGroup, BusNotFoundError, Compressor, type CompressorConfig, type ConcurrencyConfig, type CrossfadeOptions, type DecodeAttempt, DecodeError, Ducker, type DuckerConfig, type Engine, EngineClosedError, type EngineConfig, type EngineState, type FadeCurve, type FadeOptions, Filter, type FilterConfig, type FilterKind, type FxInsert, type LoadSoundOptions, type LoudnessOptions, Master, type MasterConfig, type MasterLimiterConfig, Music, type MusicLoadOptions, type MusicParts, type MusicPlayOptions, type MusicState, MusicVoice, type NormalizeFlag, Parameter, type ParameterCurve, type PlayOptions, PreloadError, type PreloadFailure, type PreloadItem, type PreloadOptions, type PreloadProgressEvent, type ResolveAssetContext, type ResolvedAsset, Reverb, type ReverbConfig, Send, type SendOptions, type SidechainConfig, type SkipToOutroOptions, Snapshot, type SnapshotState, Sound, SoundNotFoundError, type SpatialOptions, Spatializer, Sprite, type SpriteMap, type SpriteRegion, type SpriteRegionPlayOptions, type StopOptions, StreamSound, StretchProcessor, type StretchWorkletNode, type StretchWorkletOptions, type TickSource, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|
package/dist/index.js
CHANGED
|
@@ -608,6 +608,48 @@ function ease(t, curve) {
|
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
// src/mixer/bus.ts
|
|
611
|
+
var Send = class {
|
|
612
|
+
source;
|
|
613
|
+
target;
|
|
614
|
+
post;
|
|
615
|
+
gainNode;
|
|
616
|
+
ctx;
|
|
617
|
+
disposed = false;
|
|
618
|
+
constructor(source, target, options, ctx) {
|
|
619
|
+
this.source = source;
|
|
620
|
+
this.target = target;
|
|
621
|
+
this.post = options.post ?? true;
|
|
622
|
+
this.ctx = ctx;
|
|
623
|
+
this.gainNode = ctx.createGain();
|
|
624
|
+
this.gainNode.gain.value = clamp01(options.amount ?? 1);
|
|
625
|
+
const tap = this.post ? source.output : source.input;
|
|
626
|
+
tap.connect(this.gainNode);
|
|
627
|
+
this.gainNode.connect(target.input);
|
|
628
|
+
}
|
|
629
|
+
/** Live send level (0..1). Setter ramps over 10 ms to avoid clicks. */
|
|
630
|
+
get amount() {
|
|
631
|
+
return this.gainNode.gain.value;
|
|
632
|
+
}
|
|
633
|
+
set amount(v) {
|
|
634
|
+
if (this.disposed) return;
|
|
635
|
+
applyRamp(this.gainNode.gain, this.ctx.currentTime, clamp01(v), 0.01, "linear");
|
|
636
|
+
}
|
|
637
|
+
/** Fade the send to `target` over `duration` seconds. */
|
|
638
|
+
fadeTo(target, duration, curve = "linear") {
|
|
639
|
+
if (this.disposed) return Promise.resolve();
|
|
640
|
+
applyRamp(this.gainNode.gain, this.ctx.currentTime, clamp01(target), duration, curve);
|
|
641
|
+
if (duration <= 0) return Promise.resolve();
|
|
642
|
+
return new Promise((res) => setTimeout(res, duration * 1e3));
|
|
643
|
+
}
|
|
644
|
+
dispose() {
|
|
645
|
+
if (this.disposed) return;
|
|
646
|
+
this.disposed = true;
|
|
647
|
+
try {
|
|
648
|
+
this.gainNode.disconnect();
|
|
649
|
+
} catch {
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
};
|
|
611
653
|
var Bus = class {
|
|
612
654
|
name;
|
|
613
655
|
input;
|
|
@@ -617,14 +659,23 @@ var Bus = class {
|
|
|
617
659
|
output;
|
|
618
660
|
_level;
|
|
619
661
|
_muted;
|
|
662
|
+
_soloed = false;
|
|
620
663
|
ctx;
|
|
621
664
|
_concurrency;
|
|
622
665
|
_voices = /* @__PURE__ */ new Set();
|
|
623
666
|
_fxChain = [];
|
|
667
|
+
_sends = [];
|
|
624
668
|
// Lazy meter tap. Connected as a passive sibling of bus.output → master.input
|
|
625
669
|
// so the audio path is unchanged.
|
|
626
670
|
_meterAnalyser = null;
|
|
627
671
|
_meterBuf = null;
|
|
672
|
+
/**
|
|
673
|
+
* Engine-injected callback fired when this bus's solo state changes.
|
|
674
|
+
* The Engine uses it to coordinate the global "any soloed → mute the
|
|
675
|
+
* rest" rule across every bus in the graph. Bus does not depend on
|
|
676
|
+
* Engine; the callback is the only escape hatch.
|
|
677
|
+
*/
|
|
678
|
+
notifySoloChange;
|
|
628
679
|
constructor(ctx, name, config = {}) {
|
|
629
680
|
this.ctx = ctx;
|
|
630
681
|
this.name = name;
|
|
@@ -747,6 +798,69 @@ var Bus = class {
|
|
|
747
798
|
}
|
|
748
799
|
return { rms: Math.sqrt(sumSq / buf.length), peak };
|
|
749
800
|
}
|
|
801
|
+
/**
|
|
802
|
+
* Route a copy of this bus's signal into another bus at the configured
|
|
803
|
+
* level. `target.input` mixes the send naturally with whatever else is
|
|
804
|
+
* already feeding it, so the typical pattern — "send 30 % of music to a
|
|
805
|
+
* dedicated reverb bus" — is just two lines:
|
|
806
|
+
*
|
|
807
|
+
* ```ts
|
|
808
|
+
* const verbSend = engine.bus('music').send(engine.bus('reverb'), { amount: 0.3 });
|
|
809
|
+
* verbSend.amount = 0.5; // turn it up live
|
|
810
|
+
* verbSend.dispose(); // remove the send entirely
|
|
811
|
+
* ```
|
|
812
|
+
*
|
|
813
|
+
* Default tap is post-fader / post-FX (`post: true`); set `post: false`
|
|
814
|
+
* if you want a monitor send that hears the dry pre-fader signal.
|
|
815
|
+
*/
|
|
816
|
+
send(target, options = {}) {
|
|
817
|
+
const send = new Send(this, target, options, this.ctx);
|
|
818
|
+
this._sends.push(send);
|
|
819
|
+
return send;
|
|
820
|
+
}
|
|
821
|
+
/** Remove a previously-created send. Idempotent. */
|
|
822
|
+
removeSend(send) {
|
|
823
|
+
const idx = this._sends.indexOf(send);
|
|
824
|
+
if (idx === -1) return;
|
|
825
|
+
this._sends.splice(idx, 1);
|
|
826
|
+
send.dispose();
|
|
827
|
+
}
|
|
828
|
+
/** Read-only snapshot of every active send originating on this bus. */
|
|
829
|
+
sends() {
|
|
830
|
+
return this._sends;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Solo this bus. The engine coordinates the global rule: while any bus
|
|
834
|
+
* is soloed, every non-soloed bus is muted. Soloing multiple buses is
|
|
835
|
+
* additive — they all stay audible. Calling `unsolo()` (or `solo(false)`)
|
|
836
|
+
* removes this bus from the soloed set.
|
|
837
|
+
*
|
|
838
|
+
* Solo state is independent of `muted`; un-soloing returns the bus to
|
|
839
|
+
* whatever its `muted` setting was. Useful in mixer UIs where the user
|
|
840
|
+
* wants to A/B a single channel without disturbing the rest of the mix.
|
|
841
|
+
*/
|
|
842
|
+
solo(on = true) {
|
|
843
|
+
if (this._soloed === on) return;
|
|
844
|
+
this._soloed = on;
|
|
845
|
+
this.notifySoloChange?.(this, on);
|
|
846
|
+
}
|
|
847
|
+
/** Turn solo off on this bus. Equivalent to `solo(false)`. */
|
|
848
|
+
unsolo() {
|
|
849
|
+
this.solo(false);
|
|
850
|
+
}
|
|
851
|
+
/** True when this bus is in the engine's solo set. */
|
|
852
|
+
get soloed() {
|
|
853
|
+
return this._soloed;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Engine-only. Apply a transient mute (or restore) driven by the global
|
|
857
|
+
* solo state. Distinct from `muted` so un-soloing returns the bus to its
|
|
858
|
+
* user-visible mute state without re-rendering.
|
|
859
|
+
*/
|
|
860
|
+
applySoloVeil(soloMute) {
|
|
861
|
+
const target = this._muted ? 0 : soloMute ? 0 : this._level;
|
|
862
|
+
this.rampOutput(target, 0.01);
|
|
863
|
+
}
|
|
750
864
|
rewireFxChain() {
|
|
751
865
|
try {
|
|
752
866
|
this.fxInput.disconnect();
|
|
@@ -819,6 +933,55 @@ function pickVictim(voices, strategy, newVoice) {
|
|
|
819
933
|
return victim;
|
|
820
934
|
}
|
|
821
935
|
|
|
936
|
+
// src/mixer/bus-group.ts
|
|
937
|
+
var BusGroup = class {
|
|
938
|
+
name;
|
|
939
|
+
members;
|
|
940
|
+
constructor(name, members) {
|
|
941
|
+
this.name = name;
|
|
942
|
+
this.members = members;
|
|
943
|
+
}
|
|
944
|
+
/** Set the level on every member. Same 10 ms ramp as direct `bus.level =`. */
|
|
945
|
+
set level(v) {
|
|
946
|
+
for (const b of this.members) b.level = v;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Read the current level. Returns the average across members — useful
|
|
950
|
+
* when every member shares a level (the common case) and informational
|
|
951
|
+
* otherwise.
|
|
952
|
+
*/
|
|
953
|
+
get level() {
|
|
954
|
+
if (this.members.length === 0) return 0;
|
|
955
|
+
let sum = 0;
|
|
956
|
+
for (const b of this.members) sum += b.level;
|
|
957
|
+
return sum / this.members.length;
|
|
958
|
+
}
|
|
959
|
+
set muted(v) {
|
|
960
|
+
for (const b of this.members) b.muted = v;
|
|
961
|
+
}
|
|
962
|
+
/** True if every member is currently muted. */
|
|
963
|
+
get muted() {
|
|
964
|
+
if (this.members.length === 0) return false;
|
|
965
|
+
return this.members.every((b) => b.muted);
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Fade every member to `target` over `duration` seconds. Returns when
|
|
969
|
+
* the slowest leg completes — in practice they're all equal because
|
|
970
|
+
* each member uses the same duration.
|
|
971
|
+
*/
|
|
972
|
+
fadeTo(target, duration, curve = "linear") {
|
|
973
|
+
return Promise.all(this.members.map((b) => b.fadeTo(target, duration, curve))).then(() => void 0);
|
|
974
|
+
}
|
|
975
|
+
/** Solo every member of the group. Engine handles the global mute-the-rest rule. */
|
|
976
|
+
solo(on = true) {
|
|
977
|
+
for (const b of this.members) b.solo(on);
|
|
978
|
+
}
|
|
979
|
+
/** Un-solo every member. */
|
|
980
|
+
unsolo() {
|
|
981
|
+
this.solo(false);
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
|
|
822
985
|
// src/params/parameter.ts
|
|
823
986
|
var Parameter = class {
|
|
824
987
|
name;
|
|
@@ -2373,6 +2536,8 @@ var Master = class {
|
|
|
2373
2536
|
limiterNode = null;
|
|
2374
2537
|
limiterCfg;
|
|
2375
2538
|
destination;
|
|
2539
|
+
_meterAnalyser = null;
|
|
2540
|
+
_meterBuf = null;
|
|
2376
2541
|
constructor(ctx, config = {}) {
|
|
2377
2542
|
this.ctx = ctx;
|
|
2378
2543
|
this.input = ctx.createGain();
|
|
@@ -2401,13 +2566,42 @@ var Master = class {
|
|
|
2401
2566
|
get reduction() {
|
|
2402
2567
|
return this.limiterNode?.reduction ?? 0;
|
|
2403
2568
|
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Live amplitude readout on the master input. Returns `{ rms, peak }`
|
|
2571
|
+
* as linear values in [0..1]. The first call lazily attaches an
|
|
2572
|
+
* AnalyserNode as a passive sibling of the master gain — no audio-path
|
|
2573
|
+
* change. Same shape as `bus.meter()` and `voice.level()`.
|
|
2574
|
+
*/
|
|
2575
|
+
meter() {
|
|
2576
|
+
if (!this._meterAnalyser) {
|
|
2577
|
+
const a = this.ctx.createAnalyser();
|
|
2578
|
+
a.fftSize = 1024;
|
|
2579
|
+
this.input.connect(a);
|
|
2580
|
+
this._meterAnalyser = a;
|
|
2581
|
+
this._meterBuf = new Float32Array(a.fftSize);
|
|
2582
|
+
}
|
|
2583
|
+
const buf = this._meterBuf;
|
|
2584
|
+
this._meterAnalyser.getFloatTimeDomainData(buf);
|
|
2585
|
+
let sumSq = 0;
|
|
2586
|
+
let peak = 0;
|
|
2587
|
+
for (let i = 0; i < buf.length; i++) {
|
|
2588
|
+
const s = buf[i] ?? 0;
|
|
2589
|
+
sumSq += s * s;
|
|
2590
|
+
const a = Math.abs(s);
|
|
2591
|
+
if (a > peak) peak = a;
|
|
2592
|
+
}
|
|
2593
|
+
return { rms: Math.sqrt(sumSq / buf.length), peak };
|
|
2594
|
+
}
|
|
2404
2595
|
dispose() {
|
|
2405
2596
|
try {
|
|
2406
2597
|
this.input.disconnect();
|
|
2407
2598
|
this.limiterNode?.disconnect();
|
|
2599
|
+
this._meterAnalyser?.disconnect();
|
|
2408
2600
|
} catch {
|
|
2409
2601
|
}
|
|
2410
2602
|
this.limiterNode = null;
|
|
2603
|
+
this._meterAnalyser = null;
|
|
2604
|
+
this._meterBuf = null;
|
|
2411
2605
|
}
|
|
2412
2606
|
rewire() {
|
|
2413
2607
|
try {
|
|
@@ -2481,6 +2675,8 @@ var EngineImpl = class {
|
|
|
2481
2675
|
sprites = /* @__PURE__ */ new Map();
|
|
2482
2676
|
streams = /* @__PURE__ */ new Map();
|
|
2483
2677
|
musics = /* @__PURE__ */ new Map();
|
|
2678
|
+
busGroups = /* @__PURE__ */ new Map();
|
|
2679
|
+
soloedBuses = /* @__PURE__ */ new Set();
|
|
2484
2680
|
voices = /* @__PURE__ */ new Map();
|
|
2485
2681
|
parameters = /* @__PURE__ */ new Map();
|
|
2486
2682
|
config;
|
|
@@ -2749,6 +2945,22 @@ var EngineImpl = class {
|
|
|
2749
2945
|
if (!b) throw new BusNotFoundError(suggest(name, [...this.buses.keys()]));
|
|
2750
2946
|
return b;
|
|
2751
2947
|
}
|
|
2948
|
+
busGroup(name, members) {
|
|
2949
|
+
if (members != null) {
|
|
2950
|
+
const group = new BusGroup(name, members);
|
|
2951
|
+
this.busGroups.set(name, group);
|
|
2952
|
+
return group;
|
|
2953
|
+
}
|
|
2954
|
+
const existing = this.busGroups.get(name);
|
|
2955
|
+
if (!existing) {
|
|
2956
|
+
throw new BusNotFoundError(suggest(name, [...this.busGroups.keys()]));
|
|
2957
|
+
}
|
|
2958
|
+
return existing;
|
|
2959
|
+
}
|
|
2960
|
+
masterMeter() {
|
|
2961
|
+
this.ensureGraph();
|
|
2962
|
+
return this.master.meter();
|
|
2963
|
+
}
|
|
2752
2964
|
scheduleAt(audioTime, fn) {
|
|
2753
2965
|
this.host.touch();
|
|
2754
2966
|
this.ensureGraph();
|
|
@@ -2798,10 +3010,29 @@ var EngineImpl = class {
|
|
|
2798
3010
|
const cfg = this.config.buses?.[name] ?? {};
|
|
2799
3011
|
const bus = new Bus(ctx, name, cfg);
|
|
2800
3012
|
bus.output.connect(this.master.input);
|
|
3013
|
+
bus.notifySoloChange = (b, soloed) => this.handleSoloChange(b, soloed);
|
|
2801
3014
|
this.buses.set(name, bus);
|
|
2802
3015
|
if (!this.voices.has(name)) this.voices.set(name, /* @__PURE__ */ new Set());
|
|
2803
3016
|
}
|
|
2804
3017
|
}
|
|
3018
|
+
/**
|
|
3019
|
+
* Coordinate the global solo rule. When any bus is in the solo set,
|
|
3020
|
+
* every non-soloed bus is muted via `applySoloVeil(true)`. When the
|
|
3021
|
+
* solo set drains, every bus is restored via `applySoloVeil(false)` —
|
|
3022
|
+
* which honours the bus's own `muted` setting independently.
|
|
3023
|
+
*/
|
|
3024
|
+
handleSoloChange(bus, soloed) {
|
|
3025
|
+
if (soloed) this.soloedBuses.add(bus);
|
|
3026
|
+
else this.soloedBuses.delete(bus);
|
|
3027
|
+
const anySoloed = this.soloedBuses.size > 0;
|
|
3028
|
+
for (const b of this.buses.values()) {
|
|
3029
|
+
if (!anySoloed) {
|
|
3030
|
+
b.applySoloVeil(false);
|
|
3031
|
+
} else {
|
|
3032
|
+
b.applySoloVeil(!this.soloedBuses.has(b));
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
2805
3036
|
};
|
|
2806
3037
|
function suggest(missing, candidates) {
|
|
2807
3038
|
if (candidates.length === 0) return missing;
|
|
@@ -2851,6 +3082,6 @@ function levenshtein(a, b) {
|
|
|
2851
3082
|
return prev[b.length];
|
|
2852
3083
|
}
|
|
2853
3084
|
|
|
2854
|
-
export { AggregateDecodeError, Bus, BusNotFoundError, Compressor, DecodeError, Ducker, EngineClosedError, Filter, Master, Music, MusicVoice, Parameter, PreloadError, Reverb, Snapshot, Sound, SoundNotFoundError, Spatializer, Sprite, StreamSound, StretchProcessor, Voice, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|
|
3085
|
+
export { AggregateDecodeError, Bus, BusGroup, BusNotFoundError, Compressor, DecodeError, Ducker, EngineClosedError, Filter, Master, Music, MusicVoice, Parameter, PreloadError, Reverb, Send, Snapshot, Sound, SoundNotFoundError, Spatializer, Sprite, StreamSound, StretchProcessor, Voice, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|
|
2855
3086
|
//# sourceMappingURL=index.js.map
|
|
2856
3087
|
//# sourceMappingURL=index.js.map
|