@sudobility/music_types 0.11.19 → 0.11.20
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/platform/audio.d.ts
CHANGED
|
@@ -38,6 +38,18 @@ export type RenderTrack = {
|
|
|
38
38
|
instrumentName: string;
|
|
39
39
|
/** From the track's clef, matching how live playback decides. */
|
|
40
40
|
isPercussion: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The GM program to voice this track from, resolved by music_lib: the kit's
|
|
43
|
+
* program on a percussion track, the track's own otherwise.
|
|
44
|
+
*
|
|
45
|
+
* Resolved there because **a percussion track's `midiProgram` names a drum
|
|
46
|
+
* kit, not an instrument** — Brush is 40 and program 40 is Violin — and only
|
|
47
|
+
* the GM tables know which kit an arbitrary address falls in. Carrying the
|
|
48
|
+
* answer is what lets the platform layer keep no catalogue of its own.
|
|
49
|
+
*/
|
|
50
|
+
voiceProgram: number;
|
|
51
|
+
/** The GM catalogue name for `voiceProgram` — the kit's name on a percussion track. */
|
|
52
|
+
voiceName: string;
|
|
41
53
|
/** 0..1 channel gain. */
|
|
42
54
|
volume: number;
|
|
43
55
|
/** -1..1. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/platform/audio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAClD,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC;IAC5C,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAA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C;CACrB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACjD;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,uCAAuC;IACvC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;CACzF"}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* things that import an audio library; everything that depends on playback
|
|
8
8
|
* depends on this file instead, so the engine stays swappable and mockable.
|
|
9
9
|
*/
|
|
10
|
-
import type {
|
|
10
|
+
import type { ScoreRange } from '../index.js';
|
|
11
|
+
import type { RenderTrack } from './audio.js';
|
|
11
12
|
export type TransportPlaybackState = 'stopped' | 'playing' | 'paused';
|
|
12
13
|
/**
|
|
13
14
|
* Callbacks the engine invokes as playback advances. `onPositionTick` fires at
|
|
@@ -53,6 +54,73 @@ export type PlaybackObserver = {
|
|
|
53
54
|
* digesting a soundfont reports nothing until it is done — so a caller can tell
|
|
54
55
|
* a real percentage from "busy, no idea how long".
|
|
55
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* Tick <-> second conversion, as playback needs it.
|
|
59
|
+
*
|
|
60
|
+
* An interface rather than a class so music_io can convert without importing
|
|
61
|
+
* music_lib's `TempoMap` — which satisfies this structurally, so music_lib
|
|
62
|
+
* passes the instance it already builds and no conversion code moves or is
|
|
63
|
+
* duplicated.
|
|
64
|
+
*/
|
|
65
|
+
export interface TempoConversion {
|
|
66
|
+
ticksToSeconds(tick: number): number;
|
|
67
|
+
secondsToTicks(seconds: number): number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A track as playback needs it: the offline render's track plus the two mix
|
|
71
|
+
* flags a live mix can change without reloading, plus the resolved GM voice.
|
|
72
|
+
*
|
|
73
|
+
* The resolved GM voice lives on `RenderTrack` itself, since the offline
|
|
74
|
+
* renderer needs it for exactly the same reason.
|
|
75
|
+
*/
|
|
76
|
+
export type PlaybackTrack = RenderTrack & {
|
|
77
|
+
muted: boolean;
|
|
78
|
+
solo: boolean;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A voice to audition, resolved from the GM tables **by the caller**.
|
|
82
|
+
*
|
|
83
|
+
* The engine cannot resolve it: a percussion voice's program addresses a drum
|
|
84
|
+
* kit, and only the GM tables know which kit an arbitrary address falls in.
|
|
85
|
+
* Resolving here is what lets the platform layer keep no catalogue of its own.
|
|
86
|
+
*/
|
|
87
|
+
export type AuditionVoice = {
|
|
88
|
+
/** The kit's program on a percussion voice, the instrument's own otherwise. */
|
|
89
|
+
program: number;
|
|
90
|
+
/** The GM catalogue name for `program`. */
|
|
91
|
+
name: string;
|
|
92
|
+
isPercussion: boolean;
|
|
93
|
+
};
|
|
94
|
+
/** One playback-ready note, in score ticks, carrying the ids playback reports back. */
|
|
95
|
+
export type PlaybackNote = {
|
|
96
|
+
tick: number;
|
|
97
|
+
durTicks: number;
|
|
98
|
+
midi: number;
|
|
99
|
+
velocity: number;
|
|
100
|
+
trackId: string;
|
|
101
|
+
noteId: string;
|
|
102
|
+
};
|
|
103
|
+
/** One metronome click. `accent` marks beat 1 of its measure. */
|
|
104
|
+
export type MetronomeClick = {
|
|
105
|
+
tick: number;
|
|
106
|
+
accent: boolean;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Everything live playback needs, and nothing about a `Score`.
|
|
110
|
+
*
|
|
111
|
+
* The live counterpart of `RenderPlan`: music_lib decides every musical
|
|
112
|
+
* question — ties joined, pitches resolved, mute and solo, the measure grid's
|
|
113
|
+
* beat positions, the tempo — and the engine only schedules and sounds what it
|
|
114
|
+
* is handed. This is the seam that keeps music_io free of the domain.
|
|
115
|
+
*/
|
|
116
|
+
export type PlaybackPlan = {
|
|
117
|
+
tracks: readonly PlaybackTrack[];
|
|
118
|
+
notes: readonly PlaybackNote[];
|
|
119
|
+
clicks: readonly MetronomeClick[];
|
|
120
|
+
tempo: TempoConversion;
|
|
121
|
+
/** The last tick any note ends on. */
|
|
122
|
+
durationTicks: number;
|
|
123
|
+
};
|
|
56
124
|
export type PlaybackLoadState = {
|
|
57
125
|
status: 'idle';
|
|
58
126
|
} | {
|
|
@@ -66,7 +134,8 @@ export type PlaybackLoadState = {
|
|
|
66
134
|
};
|
|
67
135
|
export interface PlaybackEngine {
|
|
68
136
|
initialize(): Promise<void>;
|
|
69
|
-
|
|
137
|
+
/** Adopts a plan. The engine is handed music, never a score. */
|
|
138
|
+
load(plan: PlaybackPlan): Promise<void>;
|
|
70
139
|
play(fromTick?: number): Promise<void>;
|
|
71
140
|
pause(): void;
|
|
72
141
|
stop(): void;
|
|
@@ -76,20 +145,21 @@ export interface PlaybackEngine {
|
|
|
76
145
|
setTrackMute(trackId: string, muted: boolean): void;
|
|
77
146
|
setTrackSolo(trackId: string, solo: boolean): void;
|
|
78
147
|
/**
|
|
79
|
-
* Re-reads every track's volume, pan, mute and solo
|
|
80
|
-
*
|
|
148
|
+
* Re-reads every track's volume, pan, mute and solo and pushes them,
|
|
149
|
+
* touching nothing that is scheduled.
|
|
81
150
|
*
|
|
82
|
-
* The mixing counterpart to `
|
|
83
|
-
*
|
|
84
|
-
*
|
|
151
|
+
* The mixing counterpart to `load`. Mute and solo had setters; volume and pan
|
|
152
|
+
* did not, and a track's volume was only ever read at load time — so once a
|
|
153
|
+
* mix change stopped reloading the score (the playback edit lock, see
|
|
85
154
|
* `music_lib`'s `score-slice`), moving a fader during playback moved the
|
|
86
155
|
* fader and not the sound.
|
|
87
156
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
157
|
+
* Takes only the tracks, so changing a gain does not rebuild every note —
|
|
158
|
+
* which is the whole reason this is separate from `load`. Idempotent, and
|
|
159
|
+
* takes them all rather than one property: the caller says "the mix changed,
|
|
160
|
+
* here it is" and does not work out which property it was.
|
|
91
161
|
*/
|
|
92
|
-
applyMix(
|
|
162
|
+
applyMix(tracks: readonly PlaybackTrack[]): void;
|
|
93
163
|
/** Toggles the metronome click. */
|
|
94
164
|
setMetronome(enabled: boolean): void;
|
|
95
165
|
/** Sets overall output level, 0-1 linear gain. */
|
|
@@ -98,16 +168,16 @@ export interface PlaybackEngine {
|
|
|
98
168
|
* Sounds `midi` immediately on `program`'s voice and holds it, independent of
|
|
99
169
|
* the transport — for auditioning a key while editing.
|
|
100
170
|
*
|
|
101
|
-
* `isPercussion` mirrors what playback does with a percussion-clef
|
|
102
|
-
* without it, tapping a note on a drum track auditioned a pitched
|
|
103
|
-
* while the same note played back as a drum.
|
|
171
|
+
* `voice.isPercussion` mirrors what playback does with a percussion-clef
|
|
172
|
+
* track: without it, tapping a note on a drum track auditioned a pitched
|
|
173
|
+
* instrument while the same note played back as a drum.
|
|
104
174
|
*
|
|
105
175
|
* Separate from `play` because the two answer different questions: `play`
|
|
106
176
|
* renders the written score along a timeline, this makes a sound *now*, for
|
|
107
177
|
* as long as the caller holds it, whether or not a score is even loaded.
|
|
108
178
|
* Implementations must not disturb transport state.
|
|
109
179
|
*/
|
|
110
|
-
noteOn(midi: number,
|
|
180
|
+
noteOn(midi: number, voice: AuditionVoice): void;
|
|
111
181
|
/** Releases a pitch started by `noteOn`. Silent no-op if it is not sounding. */
|
|
112
182
|
noteOff(midi: number): void;
|
|
113
183
|
/** Registers (or, with `null`, clears) the single observer receiving position/active-note/state updates. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playback.d.ts","sourceRoot":"","sources":["../../src/platform/playback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"playback.d.ts","sourceRoot":"","sources":["../../src/platform/playback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAC;IAChB,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC;;;;;;;OAOG;IACH,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAC3C,aAAa,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACnD;;;;;;;;OAQG;IACH,iBAAiB,CAAC,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;AACH;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;CACzC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE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