@nodelyra/not-angka 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +38 -2
- package/THIRD_PARTY.md +24 -0
- package/dist/esm/cursor/activeChord.d.ts +12 -0
- package/dist/esm/cursor/activeChord.js +36 -0
- package/dist/esm/cursor/beatDot.d.ts +30 -0
- package/dist/esm/cursor/beatDot.js +49 -0
- package/dist/esm/cursor/drawnTop.d.ts +9 -0
- package/dist/esm/cursor/drawnTop.js +16 -0
- package/dist/esm/cursor/pageBoxes.d.ts +28 -0
- package/dist/esm/cursor/pageBoxes.js +75 -0
- package/dist/esm/cursor/playbackCursor.d.ts +25 -0
- package/dist/esm/cursor/playbackCursor.js +42 -0
- package/dist/esm/cursor/playingStyle.d.ts +16 -0
- package/dist/esm/cursor/playingStyle.js +34 -0
- package/dist/esm/cursor/playingTones.d.ts +8 -0
- package/dist/esm/cursor/playingTones.js +16 -0
- package/dist/esm/cursor/target.d.ts +47 -0
- package/dist/esm/cursor/target.js +63 -0
- package/dist/esm/export/pageText.d.ts +8 -0
- package/dist/esm/export/pageText.js +80 -0
- package/dist/esm/export/svgExport.d.ts +46 -0
- package/dist/esm/export/svgExport.js +88 -0
- package/dist/esm/geometry/metrics.d.ts +42 -0
- package/dist/esm/geometry/metrics.js +52 -0
- package/dist/esm/geometry/pageSetup.d.ts +61 -0
- package/dist/esm/geometry/pageSetup.js +85 -0
- package/dist/esm/geometry/paper.d.ts +16 -0
- package/dist/esm/geometry/paper.js +16 -0
- package/dist/esm/index.d.ts +35 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/layout/LayoutEngine.d.ts +64 -0
- package/dist/esm/layout/LayoutEngine.js +92 -0
- package/dist/esm/layout/arcs.d.ts +20 -0
- package/dist/esm/layout/arcs.js +53 -0
- package/dist/esm/layout/barlineShapes.d.ts +52 -0
- package/dist/esm/layout/barlineShapes.js +71 -0
- package/dist/esm/layout/directions.d.ts +48 -0
- package/dist/esm/layout/directions.js +122 -0
- package/dist/esm/layout/elementBoxes.d.ts +17 -0
- package/dist/esm/layout/elementBoxes.js +72 -0
- package/dist/esm/layout/floating.d.ts +29 -0
- package/dist/esm/layout/floating.js +39 -0
- package/dist/esm/layout/keyMarks.d.ts +26 -0
- package/dist/esm/layout/keyMarks.js +30 -0
- package/dist/esm/layout/lyricAlign.d.ts +6 -0
- package/dist/esm/layout/lyricAlign.js +15 -0
- package/dist/esm/layout/lyricWords.d.ts +13 -0
- package/dist/esm/layout/lyricWords.js +27 -0
- package/dist/esm/layout/lyricsLayout.d.ts +55 -0
- package/dist/esm/layout/lyricsLayout.js +122 -0
- package/dist/esm/layout/markings.d.ts +97 -0
- package/dist/esm/layout/markings.js +150 -0
- package/dist/esm/layout/measurePlan.d.ts +74 -0
- package/dist/esm/layout/measurePlan.js +232 -0
- package/dist/esm/layout/measureSegments.d.ts +24 -0
- package/dist/esm/layout/measureSegments.js +64 -0
- package/dist/esm/layout/notationMetrics.d.ts +110 -0
- package/dist/esm/layout/notationMetrics.js +122 -0
- package/dist/esm/layout/systemBreaking.d.ts +59 -0
- package/dist/esm/layout/systemBreaking.js +137 -0
- package/dist/esm/layout/systemLayout.d.ts +138 -0
- package/dist/esm/layout/systemLayout.js +266 -0
- package/dist/esm/layout/tupletSpacing.d.ts +9 -0
- package/dist/esm/layout/tupletSpacing.js +33 -0
- package/dist/esm/layout/tuplets.d.ts +30 -0
- package/dist/esm/layout/tuplets.js +39 -0
- package/dist/esm/model/hiddenParts.d.ts +23 -0
- package/dist/esm/model/hiddenParts.js +39 -0
- package/dist/esm/model/locate.d.ts +18 -0
- package/dist/esm/model/locate.js +31 -0
- package/dist/esm/model/lowVoices.d.ts +9 -0
- package/dist/esm/model/lowVoices.js +20 -0
- package/dist/esm/model/partColors.d.ts +13 -0
- package/dist/esm/model/partColors.js +10 -0
- package/dist/esm/model/partSpan.d.ts +25 -0
- package/dist/esm/model/partSpan.js +49 -0
- package/dist/esm/model/rowPresence.d.ts +14 -0
- package/dist/esm/model/rowPresence.js +19 -0
- package/dist/esm/model/sharedLyrics.d.ts +23 -0
- package/dist/esm/model/sharedLyrics.js +68 -0
- package/dist/esm/model/textBars.d.ts +12 -0
- package/dist/esm/model/textBars.js +21 -0
- package/dist/esm/model/tickRanges.d.ts +22 -0
- package/dist/esm/model/tickRanges.js +34 -0
- package/dist/esm/model/unisons.d.ts +69 -0
- package/dist/esm/model/unisons.js +181 -0
- package/dist/esm/notation/chords.d.ts +12 -0
- package/dist/esm/notation/chords.js +29 -0
- package/dist/esm/notation/elision.d.ts +24 -0
- package/dist/esm/notation/elision.js +47 -0
- package/dist/esm/notation/keys.d.ts +50 -0
- package/dist/esm/notation/keys.js +59 -0
- package/dist/esm/notation/lyricAlign.d.ts +7 -0
- package/dist/esm/notation/lyricAlign.js +15 -0
- package/dist/esm/notation/navigation.d.ts +3 -0
- package/dist/esm/notation/navigation.js +5 -0
- package/dist/esm/notation/pitch.d.ts +39 -0
- package/dist/esm/notation/pitch.js +74 -0
- package/dist/esm/notation/pitchName.d.ts +2 -0
- package/dist/esm/notation/pitchName.js +3 -0
- package/dist/esm/notation/profile.d.ts +35 -0
- package/dist/esm/notation/profile.js +16 -0
- package/dist/esm/notation/rhythm.d.ts +59 -0
- package/dist/esm/notation/rhythm.js +116 -0
- package/dist/esm/notation/time.d.ts +98 -0
- package/dist/esm/notation/time.js +85 -0
- package/dist/esm/performance/compilePerformance.d.ts +7 -0
- package/dist/esm/performance/compilePerformance.js +8 -0
- package/dist/esm/performance/dynamics.d.ts +6 -0
- package/dist/esm/performance/dynamics.js +78 -0
- package/dist/esm/performance/model.d.ts +56 -0
- package/dist/esm/performance/model.js +1 -0
- package/dist/esm/performance/playOrder.d.ts +16 -0
- package/dist/esm/performance/playOrder.js +64 -0
- package/dist/esm/performance/readScore.d.ts +4 -0
- package/dist/esm/performance/readScore.js +58 -0
- package/dist/esm/performance/timeline.d.ts +10 -0
- package/dist/esm/performance/timeline.js +144 -0
- package/dist/esm/playback/audioOutput.d.ts +46 -0
- package/dist/esm/playback/audioOutput.js +106 -0
- package/dist/esm/playback/clock.d.ts +16 -0
- package/dist/esm/playback/clock.js +44 -0
- package/dist/esm/playback/createPlayerStore.d.ts +79 -0
- package/dist/esm/playback/createPlayerStore.js +135 -0
- package/dist/esm/playback/cues.d.ts +34 -0
- package/dist/esm/playback/cues.js +52 -0
- package/dist/esm/playback/errors.d.ts +6 -0
- package/dist/esm/playback/errors.js +6 -0
- package/dist/esm/playback/metronome.d.ts +13 -0
- package/dist/esm/playback/metronome.js +15 -0
- package/dist/esm/playback/mix.d.ts +9 -0
- package/dist/esm/playback/mix.js +8 -0
- package/dist/esm/playback/pass.d.ts +27 -0
- package/dist/esm/playback/pass.js +36 -0
- package/dist/esm/playback/schedule.d.ts +7 -0
- package/dist/esm/playback/schedule.js +12 -0
- package/dist/esm/playback/session.d.ts +46 -0
- package/dist/esm/playback/session.js +107 -0
- package/dist/esm/playback/source.d.ts +6 -0
- package/dist/esm/playback/source.js +1 -0
- package/dist/esm/playback/start.d.ts +28 -0
- package/dist/esm/playback/start.js +38 -0
- package/dist/esm/playback/timing.d.ts +14 -0
- package/dist/esm/playback/timing.js +11 -0
- package/dist/esm/playback/types.d.ts +60 -0
- package/dist/esm/playback/types.js +1 -0
- package/dist/esm/playback/volume.d.ts +12 -0
- package/dist/esm/playback/volume.js +8 -0
- package/dist/esm/player/ControlBar.d.ts +22 -0
- package/dist/esm/player/ControlBar.js +77 -0
- package/dist/esm/player/CursorPainter.d.ts +17 -0
- package/dist/esm/player/CursorPainter.js +53 -0
- package/dist/esm/player/InfoLine.d.ts +6 -0
- package/dist/esm/player/InfoLine.js +23 -0
- package/dist/esm/player/PageView.d.ts +10 -0
- package/dist/esm/player/PageView.js +16 -0
- package/dist/esm/player/actions.d.ts +24 -0
- package/dist/esm/player/actions.js +26 -0
- package/dist/esm/player/balanceSystems.d.ts +8 -0
- package/dist/esm/player/balanceSystems.js +18 -0
- package/dist/esm/player/createExcerptPlayer.d.ts +33 -0
- package/dist/esm/player/createExcerptPlayer.js +169 -0
- package/dist/esm/player/createScorePlayer.d.ts +24 -0
- package/dist/esm/player/createScorePlayer.js +118 -0
- package/dist/esm/player/dom.d.ts +6 -0
- package/dist/esm/player/dom.js +15 -0
- package/dist/esm/player/embeddedFonts.d.ts +1 -0
- package/dist/esm/player/embeddedFonts.js +3 -0
- package/dist/esm/player/exclusivePlayback.d.ts +10 -0
- package/dist/esm/player/exclusivePlayback.js +13 -0
- package/dist/esm/player/followCursor.d.ts +5 -0
- package/dist/esm/player/followCursor.js +16 -0
- package/dist/esm/player/icons.d.ts +7 -0
- package/dist/esm/player/icons.js +9 -0
- package/dist/esm/player/injectFonts.d.ts +8 -0
- package/dist/esm/player/injectFonts.js +19 -0
- package/dist/esm/player/loadExcerpt.d.ts +21 -0
- package/dist/esm/player/loadExcerpt.js +123 -0
- package/dist/esm/player/loadScore.d.ts +12 -0
- package/dist/esm/player/loadScore.js +12 -0
- package/dist/esm/player/mountExcerpts.d.ts +30 -0
- package/dist/esm/player/mountExcerpts.js +109 -0
- package/dist/esm/player/playhead.d.ts +12 -0
- package/dist/esm/player/playhead.js +14 -0
- package/dist/esm/player/shadowStyles.d.ts +5 -0
- package/dist/esm/player/shadowStyles.js +23 -0
- package/dist/esm/player/staticSvg.d.ts +7 -0
- package/dist/esm/player/staticSvg.js +10 -0
- package/dist/esm/player/styles.d.ts +28 -0
- package/dist/esm/player/styles.js +98 -0
- package/dist/esm/player/theme.d.ts +8 -0
- package/dist/esm/player/theme.js +13 -0
- package/dist/esm/player/types.d.ts +76 -0
- package/dist/esm/player/types.js +12 -0
- package/dist/esm/rendering/SystemRenderer.d.ts +6 -0
- package/dist/esm/rendering/SystemRenderer.js +58 -0
- package/dist/esm/rendering/accidentalRenderer.d.ts +4 -0
- package/dist/esm/rendering/accidentalRenderer.js +41 -0
- package/dist/esm/rendering/arcRenderer.d.ts +9 -0
- package/dist/esm/rendering/arcRenderer.js +32 -0
- package/dist/esm/rendering/barlineRenderer.d.ts +8 -0
- package/dist/esm/rendering/barlineRenderer.js +59 -0
- package/dist/esm/rendering/directionRenderer.d.ts +4 -0
- package/dist/esm/rendering/directionRenderer.js +50 -0
- package/dist/esm/rendering/durationLineRenderer.d.ts +9 -0
- package/dist/esm/rendering/durationLineRenderer.js +27 -0
- package/dist/esm/rendering/dynamicGlyphs.d.ts +25 -0
- package/dist/esm/rendering/dynamicGlyphs.js +56 -0
- package/dist/esm/rendering/frameRenderer.d.ts +17 -0
- package/dist/esm/rendering/frameRenderer.js +252 -0
- package/dist/esm/rendering/keyMarkRenderer.d.ts +8 -0
- package/dist/esm/rendering/keyMarkRenderer.js +57 -0
- package/dist/esm/rendering/lyricsRenderer.d.ts +4 -0
- package/dist/esm/rendering/lyricsRenderer.js +44 -0
- package/dist/esm/rendering/primitives.d.ts +64 -0
- package/dist/esm/rendering/primitives.js +1 -0
- package/dist/esm/rendering/sliceRenderer.d.ts +19 -0
- package/dist/esm/rendering/sliceRenderer.js +79 -0
- package/dist/esm/rendering/textBarRenderer.d.ts +8 -0
- package/dist/esm/rendering/textBarRenderer.js +28 -0
- package/dist/esm/rendering/tupletRenderer.d.ts +7 -0
- package/dist/esm/rendering/tupletRenderer.js +42 -0
- package/dist/esm/schema/normalize.d.ts +14 -0
- package/dist/esm/schema/normalize.js +123 -0
- package/dist/esm/schema/pageMeta.d.ts +11 -0
- package/dist/esm/schema/pageMeta.js +1 -0
- package/dist/esm/schema/scoreJson.d.ts +59 -0
- package/dist/esm/schema/scoreJson.js +1 -0
- package/dist/esm/schema/scoreView.d.ts +16 -0
- package/dist/esm/schema/scoreView.js +24 -0
- package/dist/esm/schema/types.d.ts +339 -0
- package/dist/esm/schema/types.js +1 -0
- package/dist/esm/text/creditLines.d.ts +12 -0
- package/dist/esm/text/creditLines.js +11 -0
- package/dist/esm/text/fonts.d.ts +50 -0
- package/dist/esm/text/fonts.js +98 -0
- package/dist/esm/text/headerFooter.d.ts +13 -0
- package/dist/esm/text/headerFooter.js +21 -0
- package/dist/esm/text/textLines.d.ts +7 -0
- package/dist/esm/text/textLines.js +13 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/nodelyra-player.global.js +65 -0
- package/dist/nodelyra-player.global.js.map +1 -0
- package/dist/nodelyra-player.lite.global.js +63 -0
- package/dist/nodelyra-player.lite.global.js.map +1 -0
- package/examples/blog-excerpt.html +54 -0
- package/examples/twinkle.html +23 -0
- package/examples/twinkle.json +91 -0
- package/package.json +70 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TickClock } from "./clock.js";
|
|
2
|
+
import type { Cue, Performance, PlayedMeasure } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* What the cursor follows, ready to look up by time: cues and played measures (both sorted by
|
|
5
|
+
* start), with the longest cue to bound the search.
|
|
6
|
+
*/
|
|
7
|
+
export type CueTrack = {
|
|
8
|
+
cues: readonly Cue[];
|
|
9
|
+
measures: readonly PlayedMeasure[];
|
|
10
|
+
clock: TickClock;
|
|
11
|
+
longest: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function cueTrack({ cues, measures }: Pick<Performance, "cues" | "measures">, clock: TickClock): CueTrack;
|
|
14
|
+
/**
|
|
15
|
+
* The events playing `seconds` into the performance, earliest start first (so the last one is
|
|
16
|
+
* the note that began most recently). An event repeated by a repeat appears once.
|
|
17
|
+
*/
|
|
18
|
+
export declare function playingEventIds(track: CueTrack, seconds: number,
|
|
19
|
+
/** Keep only the events of parts this accepts (e.g. the parts being heard). */
|
|
20
|
+
ofPart?: (partId: string) => boolean): string[];
|
|
21
|
+
/** The beat being played: which pass through which measure, and which beat of it. */
|
|
22
|
+
export type PlayingBeat = {
|
|
23
|
+
/** Index among the played measures (a repeated measure has one per pass). */
|
|
24
|
+
pass: number;
|
|
25
|
+
measureId: string;
|
|
26
|
+
/** Beats from the measure's start (0 = its first beat). */
|
|
27
|
+
beat: number;
|
|
28
|
+
/** The bar's first beat: beat 0 of a measure that starts on beat one (not a pickup bar). */
|
|
29
|
+
downbeat: boolean;
|
|
30
|
+
beatDuration: number;
|
|
31
|
+
measureDuration: number;
|
|
32
|
+
};
|
|
33
|
+
/** The beat `seconds` into the performance, or null before the start and after the end. */
|
|
34
|
+
export declare function playingBeat(track: CueTrack, seconds: number): PlayingBeat | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function cueTrack({ cues, measures }, clock) {
|
|
2
|
+
const longest = cues.reduce((most, cue) => Math.max(most, cue.duration), 0);
|
|
3
|
+
return { cues, measures, clock, longest };
|
|
4
|
+
}
|
|
5
|
+
/** Index of the first item that starts after `tick` (items are sorted by start). */
|
|
6
|
+
function firstAfter(items, tick) {
|
|
7
|
+
let low = 0;
|
|
8
|
+
let high = items.length;
|
|
9
|
+
while (low < high) {
|
|
10
|
+
const middle = (low + high) >> 1;
|
|
11
|
+
if (items[middle].start <= tick)
|
|
12
|
+
low = middle + 1;
|
|
13
|
+
else
|
|
14
|
+
high = middle;
|
|
15
|
+
}
|
|
16
|
+
return low;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The events playing `seconds` into the performance, earliest start first (so the last one is
|
|
20
|
+
* the note that began most recently). An event repeated by a repeat appears once.
|
|
21
|
+
*/
|
|
22
|
+
export function playingEventIds(track, seconds,
|
|
23
|
+
/** Keep only the events of parts this accepts (e.g. the parts being heard). */
|
|
24
|
+
ofPart = () => true) {
|
|
25
|
+
const tick = track.clock.tick(seconds);
|
|
26
|
+
const ids = [];
|
|
27
|
+
for (let i = firstAfter(track.cues, tick) - 1; i >= 0; i -= 1) {
|
|
28
|
+
const cue = track.cues[i];
|
|
29
|
+
if (cue.start < tick - track.longest)
|
|
30
|
+
break;
|
|
31
|
+
if (tick < cue.start + cue.duration && ofPart(cue.part_id) && !ids.includes(cue.event_id))
|
|
32
|
+
ids.unshift(cue.event_id);
|
|
33
|
+
}
|
|
34
|
+
return ids;
|
|
35
|
+
}
|
|
36
|
+
/** The beat `seconds` into the performance, or null before the start and after the end. */
|
|
37
|
+
export function playingBeat(track, seconds) {
|
|
38
|
+
const tick = track.clock.tick(seconds);
|
|
39
|
+
const pass = firstAfter(track.measures, tick) - 1;
|
|
40
|
+
const measure = track.measures[pass];
|
|
41
|
+
if (!measure || tick >= measure.start + measure.duration)
|
|
42
|
+
return null;
|
|
43
|
+
const beat = Math.floor((tick - measure.start) / measure.beat_duration);
|
|
44
|
+
return {
|
|
45
|
+
pass,
|
|
46
|
+
measureId: measure.measure_id,
|
|
47
|
+
beat,
|
|
48
|
+
downbeat: beat === 0 && !measure.phase,
|
|
49
|
+
beatDuration: measure.beat_duration,
|
|
50
|
+
measureDuration: measure.duration,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PlayedMeasure } from "./types.js";
|
|
2
|
+
import type { PlayRange } from "./start.js";
|
|
3
|
+
/** One metronome click, in ticks; the downbeat (first beat of a measure) is accented. */
|
|
4
|
+
export type Click = {
|
|
5
|
+
start: number;
|
|
6
|
+
downbeat: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A click on every beat of the played measures inside `range`, in order. Beats count from each
|
|
10
|
+
* measure's start in its own beat length; only a measure that starts on beat one (not a pickup
|
|
11
|
+
* bar, `phase` > 0) accents its first click.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clicksIn(measures: readonly PlayedMeasure[], { from, to }: PlayRange): Click[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A click on every beat of the played measures inside `range`, in order. Beats count from each
|
|
3
|
+
* measure's start in its own beat length; only a measure that starts on beat one (not a pickup
|
|
4
|
+
* bar, `phase` > 0) accents its first click.
|
|
5
|
+
*/
|
|
6
|
+
export function clicksIn(measures, { from, to }) {
|
|
7
|
+
const clicks = [];
|
|
8
|
+
for (const measure of measures) {
|
|
9
|
+
const end = measure.start + measure.duration;
|
|
10
|
+
for (let tick = measure.start; tick < end; tick += measure.beat_duration)
|
|
11
|
+
if (tick >= from && tick < to)
|
|
12
|
+
clicks.push({ start: tick, downbeat: tick === measure.start && !measure.phase });
|
|
13
|
+
}
|
|
14
|
+
return clicks;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Which parts are heard: a soloed part silences every part that is not soloed. */
|
|
2
|
+
export type Mix = {
|
|
3
|
+
muted: readonly string[];
|
|
4
|
+
solo: readonly string[];
|
|
5
|
+
};
|
|
6
|
+
export declare const FULL_MIX: Mix;
|
|
7
|
+
export declare function isAudible(partId: string, mix: Mix): boolean;
|
|
8
|
+
/** The list with `id` added, or taken out when it is there. */
|
|
9
|
+
export declare const toggled: (ids: readonly string[], id: string) => string[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const FULL_MIX = { muted: [], solo: [] };
|
|
2
|
+
export function isAudible(partId, mix) {
|
|
3
|
+
if (mix.solo.length > 0)
|
|
4
|
+
return mix.solo.includes(partId);
|
|
5
|
+
return !mix.muted.includes(partId);
|
|
6
|
+
}
|
|
7
|
+
/** The list with `id` added, or taken out when it is there. */
|
|
8
|
+
export const toggled = (ids, id) => ids.includes(id) ? ids.filter((x) => x !== id) : [...ids, id];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PartKind } from "../schema/types.js";
|
|
2
|
+
import type { TickClock } from "./clock.js";
|
|
3
|
+
import type { Performance } from "./types.js";
|
|
4
|
+
import type { AudioOutput } from "./audioOutput.js";
|
|
5
|
+
import type { Mix } from "./mix.js";
|
|
6
|
+
import { type PlayRange } from "./start.js";
|
|
7
|
+
export type PassDeps = {
|
|
8
|
+
performance: Performance;
|
|
9
|
+
device: AudioOutput;
|
|
10
|
+
/** The part of the range this pass plays (a resumed pass starts part-way). */
|
|
11
|
+
range: PlayRange;
|
|
12
|
+
/** When (output clock) tick 0 of the performance would sound in this pass. */
|
|
13
|
+
startAt: number;
|
|
14
|
+
clock: TickClock;
|
|
15
|
+
kinds: ReadonlyMap<string, PartKind>;
|
|
16
|
+
/** Read at booking time, so mute, solo and the metronome switch apply within the look-ahead. */
|
|
17
|
+
mix: () => Mix;
|
|
18
|
+
metronome: () => boolean;
|
|
19
|
+
};
|
|
20
|
+
/** One run through a range, booked bit by bit up to a horizon. */
|
|
21
|
+
export type Pass = {
|
|
22
|
+
/** When tick 0 sounds in this pass; the clock reads ticks against it. */
|
|
23
|
+
startAt: number;
|
|
24
|
+
/** Book the notes and clicks that start before `untilTick` and are not booked yet. */
|
|
25
|
+
book: (untilTick: number) => void;
|
|
26
|
+
};
|
|
27
|
+
export declare function createPass(deps: PassDeps): Pass;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clicksIn } from "./metronome.js";
|
|
2
|
+
import { dueNotes } from "./schedule.js";
|
|
3
|
+
import { notesIn } from "./start.js";
|
|
4
|
+
export function createPass(deps) {
|
|
5
|
+
const { device, startAt, clock } = deps;
|
|
6
|
+
const notes = notesIn(deps.performance.notes, deps.range);
|
|
7
|
+
const clicks = clicksIn(deps.performance.measures, deps.range);
|
|
8
|
+
let next = 0;
|
|
9
|
+
let nextClick = 0;
|
|
10
|
+
const bookNotes = (untilTick) => {
|
|
11
|
+
const { due, next: after } = dueNotes(notes, next, untilTick, deps.mix());
|
|
12
|
+
next = after;
|
|
13
|
+
for (const note of due)
|
|
14
|
+
device.play({
|
|
15
|
+
partId: note.part_id,
|
|
16
|
+
pitch: note.pitch,
|
|
17
|
+
at: startAt + clock.seconds(note.start),
|
|
18
|
+
duration: clock.seconds(note.start + note.duration) - clock.seconds(note.start),
|
|
19
|
+
level: note.level ?? 1,
|
|
20
|
+
kind: deps.kinds.get(note.part_id) ?? "vocal",
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const bookClicks = (untilTick) => {
|
|
24
|
+
const on = deps.metronome();
|
|
25
|
+
for (; nextClick < clicks.length && clicks[nextClick].start < untilTick; nextClick += 1)
|
|
26
|
+
if (on)
|
|
27
|
+
device.click(startAt + clock.seconds(clicks[nextClick].start), clicks[nextClick].downbeat);
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
startAt,
|
|
31
|
+
book: (untilTick) => {
|
|
32
|
+
bookNotes(untilTick);
|
|
33
|
+
bookClicks(untilTick);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PerformedNote } from "./types.js";
|
|
2
|
+
import { type Mix } from "./mix.js";
|
|
3
|
+
/** The notes that start before `untilTick`, from `from` on, and the index to continue from. */
|
|
4
|
+
export declare function dueNotes(notes: readonly PerformedNote[], from: number, untilTick: number, mix: Mix): {
|
|
5
|
+
due: PerformedNote[];
|
|
6
|
+
next: number;
|
|
7
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isAudible } from "./mix.js";
|
|
2
|
+
/** The notes that start before `untilTick`, from `from` on, and the index to continue from. */
|
|
3
|
+
export function dueNotes(notes, from, untilTick, mix) {
|
|
4
|
+
let next = from;
|
|
5
|
+
const due = [];
|
|
6
|
+
while (next < notes.length && notes[next].start < untilTick) {
|
|
7
|
+
if (isAudible(notes[next].part_id, mix))
|
|
8
|
+
due.push(notes[next]);
|
|
9
|
+
next += 1;
|
|
10
|
+
}
|
|
11
|
+
return { due, next };
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Performance } from "./types.js";
|
|
2
|
+
import type { AudioOutput } from "./audioOutput.js";
|
|
3
|
+
import { type CueTrack } from "./cues.js";
|
|
4
|
+
import type { Mix } from "./mix.js";
|
|
5
|
+
import type { PlayRange } from "./start.js";
|
|
6
|
+
/** Calls `tick` every `ms` until the returned function is called. */
|
|
7
|
+
export type Repeat = (tick: () => void, ms: number) => () => void;
|
|
8
|
+
/** Where playing is, in seconds at the tempo being played. */
|
|
9
|
+
export type SessionProgress = {
|
|
10
|
+
position: number;
|
|
11
|
+
duration: number;
|
|
12
|
+
track: CueTrack;
|
|
13
|
+
};
|
|
14
|
+
export type SessionDeps = {
|
|
15
|
+
performance: Performance;
|
|
16
|
+
device: AudioOutput;
|
|
17
|
+
range: PlayRange;
|
|
18
|
+
/** The tempo to play at (BPM); null = the score's. */
|
|
19
|
+
tempo: number | null;
|
|
20
|
+
repeat: Repeat;
|
|
21
|
+
/** Read at booking time, so mute and solo apply within the look-ahead. */
|
|
22
|
+
mix: () => Mix;
|
|
23
|
+
/** Whether to click the beats; read at booking time, so it can be switched while playing. */
|
|
24
|
+
metronome: () => boolean;
|
|
25
|
+
/** Whether to go back to the start of the range at its end; read as the end comes near. */
|
|
26
|
+
loop: () => boolean;
|
|
27
|
+
onProgress: (progress: SessionProgress) => void;
|
|
28
|
+
/** The range has been played to its end. */
|
|
29
|
+
onEnd: () => void;
|
|
30
|
+
};
|
|
31
|
+
export type Session = {
|
|
32
|
+
/** Play on at another tempo from where playing is now (null = the score's). */
|
|
33
|
+
setTempo: (tempo: number | null) => void;
|
|
34
|
+
/** Hold at the current place: sound stops, the place is kept. */
|
|
35
|
+
pause: () => void;
|
|
36
|
+
/** Play on from where it was paused. */
|
|
37
|
+
resume: () => void;
|
|
38
|
+
stop: () => void;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* One play of a range: books its notes on the output's clock (the timer only wakes it). The
|
|
42
|
+
* clock is anchored to a tick: changing the tempo or resuming re-anchors at the current (or
|
|
43
|
+
* paused) tick and re-books from there, so playing goes on without a jump. With loop on, the
|
|
44
|
+
* next pass through the range is booked ahead as the end nears, so the seam has no gap.
|
|
45
|
+
*/
|
|
46
|
+
export declare function startSession(deps: SessionDeps): Session;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { cueTrack } from "./cues.js";
|
|
2
|
+
import { createPass } from "./pass.js";
|
|
3
|
+
import { tickClock } from "./clock.js";
|
|
4
|
+
/** How often the scheduler wakes, and how far ahead of the clock it books notes (seconds). */
|
|
5
|
+
const TICK_MS = 25;
|
|
6
|
+
const LOOKAHEAD = 0.15;
|
|
7
|
+
/** Delay before the first note (and after a tempo change), so nothing is booked in the past. */
|
|
8
|
+
const START_DELAY = 0.1;
|
|
9
|
+
const RETEMPO_DELAY = 0.03;
|
|
10
|
+
/**
|
|
11
|
+
* One play of a range: books its notes on the output's clock (the timer only wakes it). The
|
|
12
|
+
* clock is anchored to a tick: changing the tempo or resuming re-anchors at the current (or
|
|
13
|
+
* paused) tick and re-books from there, so playing goes on without a jump. With loop on, the
|
|
14
|
+
* next pass through the range is booked ahead as the end nears, so the seam has no gap.
|
|
15
|
+
*/
|
|
16
|
+
export function startSession(deps) {
|
|
17
|
+
const { performance, device, range } = deps;
|
|
18
|
+
const kinds = new Map(performance.parts.map((part) => [part.id, part.kind]));
|
|
19
|
+
let clock = tickClock(performance);
|
|
20
|
+
let floor = range.from; // the tick this pass (re)started at; progress never shows less
|
|
21
|
+
let track;
|
|
22
|
+
let current;
|
|
23
|
+
let following = null; // the next loop pass, once booking has reached it
|
|
24
|
+
let cancel = () => { };
|
|
25
|
+
let tempo = deps.tempo;
|
|
26
|
+
let pausedAt = null;
|
|
27
|
+
const stop = () => {
|
|
28
|
+
cancel();
|
|
29
|
+
cancel = () => { }; // stopping twice (at the end, then by the store) is harmless
|
|
30
|
+
device.silence();
|
|
31
|
+
};
|
|
32
|
+
const passFrom = (from, startAt) => createPass({ ...deps, range: { from, to: range.to }, startAt, clock, kinds });
|
|
33
|
+
/** The pass after `current`: the whole range again, its start right where `current` ends. */
|
|
34
|
+
const loopPass = () => passFrom(range.from, current.startAt + clock.seconds(range.to) - clock.seconds(range.from));
|
|
35
|
+
const anchor = (tick, delay) => {
|
|
36
|
+
clock = tickClock(performance, tempo);
|
|
37
|
+
floor = tick;
|
|
38
|
+
track = cueTrack(performance, clock);
|
|
39
|
+
current = passFrom(tick, device.now() + delay - clock.seconds(tick));
|
|
40
|
+
following = null;
|
|
41
|
+
};
|
|
42
|
+
const tickNow = () => clock.tick(device.now() - current.startAt);
|
|
43
|
+
const report = (tick) => deps.onProgress({
|
|
44
|
+
position: clock.seconds(Math.max(floor, tick)),
|
|
45
|
+
duration: clock.seconds(performance.duration),
|
|
46
|
+
track,
|
|
47
|
+
});
|
|
48
|
+
/** At the end of the range: go round again (loop on), or finish. False when finished. */
|
|
49
|
+
const turn = () => {
|
|
50
|
+
if (!deps.loop()) {
|
|
51
|
+
stop();
|
|
52
|
+
deps.onEnd();
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
current = following ?? loopPass();
|
|
56
|
+
following = null;
|
|
57
|
+
floor = range.from;
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
const wake = () => {
|
|
61
|
+
if (tickNow() >= range.to && !turn())
|
|
62
|
+
return;
|
|
63
|
+
const tick = tickNow();
|
|
64
|
+
const horizon = clock.tick(clock.seconds(tick) + LOOKAHEAD);
|
|
65
|
+
current.book(horizon);
|
|
66
|
+
if (horizon > range.to && deps.loop()) {
|
|
67
|
+
following ?? (following = loopPass());
|
|
68
|
+
// The same stretch of time past the end of the range, counted from its start.
|
|
69
|
+
following.book(clock.tick(clock.seconds(range.from) + clock.seconds(horizon) - clock.seconds(range.to)));
|
|
70
|
+
}
|
|
71
|
+
report(tick);
|
|
72
|
+
};
|
|
73
|
+
const run = (tick, delay) => {
|
|
74
|
+
anchor(tick, delay);
|
|
75
|
+
cancel = deps.repeat(wake, TICK_MS);
|
|
76
|
+
wake();
|
|
77
|
+
};
|
|
78
|
+
run(range.from, START_DELAY);
|
|
79
|
+
return {
|
|
80
|
+
setTempo: (next) => {
|
|
81
|
+
tempo = next;
|
|
82
|
+
if (pausedAt !== null) {
|
|
83
|
+
anchor(pausedAt, 0); // takes effect on resume; the place shows in the new seconds
|
|
84
|
+
return report(pausedAt);
|
|
85
|
+
}
|
|
86
|
+
const tick = Math.max(floor, tickNow());
|
|
87
|
+
device.silence(); // notes booked at the old tempo
|
|
88
|
+
anchor(tick, RETEMPO_DELAY);
|
|
89
|
+
wake();
|
|
90
|
+
},
|
|
91
|
+
pause: () => {
|
|
92
|
+
if (pausedAt !== null)
|
|
93
|
+
return;
|
|
94
|
+
pausedAt = Math.max(floor, tickNow());
|
|
95
|
+
stop();
|
|
96
|
+
report(pausedAt);
|
|
97
|
+
},
|
|
98
|
+
resume: () => {
|
|
99
|
+
if (pausedAt === null)
|
|
100
|
+
return;
|
|
101
|
+
const tick = pausedAt;
|
|
102
|
+
pausedAt = null;
|
|
103
|
+
run(tick, START_DELAY);
|
|
104
|
+
},
|
|
105
|
+
stop,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ScoreInput } from "../schema/types.js";
|
|
2
|
+
import type { Performance } from "./types.js";
|
|
3
|
+
/** Where the player gets the notes of a score. It depends on this, not on how they are made. */
|
|
4
|
+
export interface PerformanceSource {
|
|
5
|
+
perform(input: ScoreInput): Promise<Performance>;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Performance, PerformedNote } from "./types.js";
|
|
2
|
+
/** A place playing can start or stop at: a written note or rest, or a measure. */
|
|
3
|
+
export type StartPoint = {
|
|
4
|
+
eventId: string;
|
|
5
|
+
} | {
|
|
6
|
+
measureId: string;
|
|
7
|
+
};
|
|
8
|
+
/** The part of the performance to play, in ticks: from `from` up to (not including) `to`. */
|
|
9
|
+
export type PlayRange = {
|
|
10
|
+
from: number;
|
|
11
|
+
to: number;
|
|
12
|
+
};
|
|
13
|
+
type Starts = Pick<Performance, "cues" | "measures" | "duration">;
|
|
14
|
+
/**
|
|
15
|
+
* What to play for the selected points: from the earliest to the end of the latest when two or
|
|
16
|
+
* more places are selected; from the one place to the end; or everything when none is played.
|
|
17
|
+
*/
|
|
18
|
+
export declare function playRange(performance: Starts, points: readonly StartPoint[]): PlayRange;
|
|
19
|
+
/**
|
|
20
|
+
* The notes heard in `range`: notes outside it are dropped, and a note crossing either edge (a
|
|
21
|
+
* held note in another part) is cut to the range. Stays sorted by start.
|
|
22
|
+
*/
|
|
23
|
+
export declare function notesIn(notes: readonly PerformedNote[], { from, to }: PlayRange): PerformedNote[];
|
|
24
|
+
/** What Play will do with the selection: play everything, from one place, or a passage. */
|
|
25
|
+
export type PlayScope = "all" | "from" | "range";
|
|
26
|
+
/** The scope for the selected points, before the score is compiled (for the Play button). */
|
|
27
|
+
export declare function playScope(points: readonly StartPoint[]): PlayScope;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Where a point is first played (its first pass through a repeat), or null. */
|
|
2
|
+
function placeOf(performance, point) {
|
|
3
|
+
const found = "eventId" in point
|
|
4
|
+
? performance.cues.find((cue) => cue.event_id === point.eventId)
|
|
5
|
+
: performance.measures.find((measure) => measure.measure_id === point.measureId);
|
|
6
|
+
return found ?? null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* What to play for the selected points: from the earliest to the end of the latest when two or
|
|
10
|
+
* more places are selected; from the one place to the end; or everything when none is played.
|
|
11
|
+
*/
|
|
12
|
+
export function playRange(performance, points) {
|
|
13
|
+
const places = points.map((p) => placeOf(performance, p)).filter((p) => p !== null);
|
|
14
|
+
const whole = { from: 0, to: performance.duration };
|
|
15
|
+
if (places.length === 0)
|
|
16
|
+
return whole;
|
|
17
|
+
const from = Math.min(...places.map((p) => p.start));
|
|
18
|
+
const distinct = new Set(places.map((p) => `${p.start}:${p.duration}`)).size;
|
|
19
|
+
if (distinct < 2)
|
|
20
|
+
return { ...whole, from };
|
|
21
|
+
return { from, to: Math.max(...places.map((p) => p.start + p.duration)) };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The notes heard in `range`: notes outside it are dropped, and a note crossing either edge (a
|
|
25
|
+
* held note in another part) is cut to the range. Stays sorted by start.
|
|
26
|
+
*/
|
|
27
|
+
export function notesIn(notes, { from, to }) {
|
|
28
|
+
return notes.flatMap((note) => {
|
|
29
|
+
const start = Math.max(note.start, from);
|
|
30
|
+
const end = Math.min(note.start + note.duration, to);
|
|
31
|
+
return end > start ? [{ ...note, start, duration: end - start }] : [];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** The scope for the selected points, before the score is compiled (for the Play button). */
|
|
35
|
+
export function playScope(points) {
|
|
36
|
+
const places = new Set(points.map((p) => ("eventId" in p ? `e:${p.eventId}` : `m:${p.measureId}`)));
|
|
37
|
+
return places.size === 0 ? "all" : places.size === 1 ? "from" : "range";
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Performance } from "./types.js";
|
|
2
|
+
type Tempo = Pick<Performance, "tempo" | "ticks_per_quarter">;
|
|
3
|
+
/** Seconds per tick at the performance's tempo (beats are quarter notes). */
|
|
4
|
+
export declare const secondsPerTick: ({ tempo, ticks_per_quarter }: Tempo) => number;
|
|
5
|
+
/** The tempos a score can be played at (BPM), the same range as the score's tempo setting. */
|
|
6
|
+
export declare const PLAY_TEMPO: {
|
|
7
|
+
readonly min: 30;
|
|
8
|
+
readonly max: 300;
|
|
9
|
+
};
|
|
10
|
+
/** A tempo within `PLAY_TEMPO`, rounded to a whole BPM (an unreadable value reads as the slowest). */
|
|
11
|
+
export declare const clampPlayTempo: (tempo: number) => number;
|
|
12
|
+
/** "m:ss" for a time in seconds (negative reads as 0). */
|
|
13
|
+
export declare function clockText(seconds: number): string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Seconds per tick at the performance's tempo (beats are quarter notes). */
|
|
2
|
+
export const secondsPerTick = ({ tempo, ticks_per_quarter }) => 60 / (tempo * ticks_per_quarter);
|
|
3
|
+
/** The tempos a score can be played at (BPM), the same range as the score's tempo setting. */
|
|
4
|
+
export const PLAY_TEMPO = { min: 30, max: 300 };
|
|
5
|
+
/** A tempo within `PLAY_TEMPO`, rounded to a whole BPM (an unreadable value reads as the slowest). */
|
|
6
|
+
export const clampPlayTempo = (tempo) => Math.min(PLAY_TEMPO.max, Math.max(PLAY_TEMPO.min, Math.round(tempo) || PLAY_TEMPO.min));
|
|
7
|
+
/** "m:ss" for a time in seconds (negative reads as 0). */
|
|
8
|
+
export function clockText(seconds) {
|
|
9
|
+
const whole = Math.max(0, Math.floor(seconds));
|
|
10
|
+
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { PartKind } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mirrors backend/apps/playback (POST /playback/performance). Times are integer ticks
|
|
4
|
+
* (`ticks_per_quarter` per quarter note); the player turns them into seconds with `tempo`.
|
|
5
|
+
*/
|
|
6
|
+
export type PerformancePart = {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
kind: PartKind;
|
|
10
|
+
};
|
|
11
|
+
/** One measure as played; a repeated measure appears once per pass. */
|
|
12
|
+
export type PlayedMeasure = {
|
|
13
|
+
measure_id: string;
|
|
14
|
+
start: number;
|
|
15
|
+
duration: number;
|
|
16
|
+
/** One beat of the measure's time signature (an eighth in 6/8). */
|
|
17
|
+
beat_duration: number;
|
|
18
|
+
/**
|
|
19
|
+
* Ticks into its bar where it starts: a pickup bar's first note is not beat one, so it has no
|
|
20
|
+
* downbeat. Absent (older servers) = 0.
|
|
21
|
+
*/
|
|
22
|
+
phase?: number;
|
|
23
|
+
};
|
|
24
|
+
/** A sounding note: tied notes are already joined; `pitch` is a MIDI note number. */
|
|
25
|
+
export type PerformedNote = {
|
|
26
|
+
part_id: string;
|
|
27
|
+
event_id: string;
|
|
28
|
+
pitch: number;
|
|
29
|
+
start: number;
|
|
30
|
+
duration: number;
|
|
31
|
+
/** Loudness from the dynamics in force when it starts, 0..1 (ADR 0011). Absent (older servers) = full. */
|
|
32
|
+
level?: number;
|
|
33
|
+
};
|
|
34
|
+
/** A written note or rest as played (one per written note, rests too): what the cursor shows. */
|
|
35
|
+
export type Cue = {
|
|
36
|
+
part_id: string;
|
|
37
|
+
event_id: string;
|
|
38
|
+
start: number;
|
|
39
|
+
duration: number;
|
|
40
|
+
};
|
|
41
|
+
/** From `start` ticks on the music goes at `tempo` quarter notes per minute. */
|
|
42
|
+
export type TempoChange = {
|
|
43
|
+
start: number;
|
|
44
|
+
tempo: number;
|
|
45
|
+
};
|
|
46
|
+
export type Performance = {
|
|
47
|
+
tempo: number;
|
|
48
|
+
ticks_per_quarter: number;
|
|
49
|
+
duration: number;
|
|
50
|
+
parts: PerformancePart[];
|
|
51
|
+
measures: PlayedMeasure[];
|
|
52
|
+
notes: PerformedNote[];
|
|
53
|
+
/** Sorted by start. */
|
|
54
|
+
cues: Cue[];
|
|
55
|
+
/**
|
|
56
|
+
* Where the tempo changes after the start (schema 4), sorted by start. Absent (older servers) or
|
|
57
|
+
* empty = `tempo` throughout.
|
|
58
|
+
*/
|
|
59
|
+
tempo_changes?: TempoChange[];
|
|
60
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What can be turned up or down on its own: the score's notes, and the metronome. */
|
|
2
|
+
export type VolumeChannel = "music" | "metronome";
|
|
3
|
+
/** A level per channel, 0 (silent) to 1 (full). */
|
|
4
|
+
export type Volumes = Record<VolumeChannel, number>;
|
|
5
|
+
/** Full music; the click a little under it, so it keeps time without covering the notes. */
|
|
6
|
+
export declare const DEFAULT_VOLUMES: Volumes;
|
|
7
|
+
/** A level within 0..1 (an unreadable value reads as silent). */
|
|
8
|
+
export declare const clampVolume: (level: number) => number;
|
|
9
|
+
/** The gain for a level: squared, so equal slider steps sound like equal steps in loudness. */
|
|
10
|
+
export declare const gainOf: (level: number) => number;
|
|
11
|
+
/** A part's level (0..1); a part never set plays at full. */
|
|
12
|
+
export declare const partLevel: (levels: Readonly<Record<string, number>>, partId: string) => number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Full music; the click a little under it, so it keeps time without covering the notes. */
|
|
2
|
+
export const DEFAULT_VOLUMES = { music: 1, metronome: 0.7 };
|
|
3
|
+
/** A level within 0..1 (an unreadable value reads as silent). */
|
|
4
|
+
export const clampVolume = (level) => Math.min(1, Math.max(0, level || 0));
|
|
5
|
+
/** The gain for a level: squared, so equal slider steps sound like equal steps in loudness. */
|
|
6
|
+
export const gainOf = (level) => clampVolume(level) ** 2;
|
|
7
|
+
/** A part's level (0..1); a part never set plays at full. */
|
|
8
|
+
export const partLevel = (levels, partId) => levels[partId] ?? 1;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PlayerControls, PlayerLabels, PlayerSnapshot } from "./types.js";
|
|
2
|
+
export type ControlBar = {
|
|
3
|
+
element: HTMLElement;
|
|
4
|
+
update(snapshot: PlayerSnapshot): void;
|
|
5
|
+
};
|
|
6
|
+
type Part = {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
/** Which optional controls the bar shows (play, stop and the clock always). */
|
|
11
|
+
export type ControlFeatures = {
|
|
12
|
+
tempo: boolean;
|
|
13
|
+
loop: boolean;
|
|
14
|
+
metronome: boolean;
|
|
15
|
+
mixer: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const FULL_CONTROLS: ControlFeatures;
|
|
18
|
+
/** What a blog excerpt needs: play/pause/resume, stop and the time. */
|
|
19
|
+
export declare const BASIC_CONTROLS: ControlFeatures;
|
|
20
|
+
/** The control bar: transport, clock, tempo, loop, metronome and (for several parts) a mixer. */
|
|
21
|
+
export declare function createControlBar(doc: Document, controls: PlayerControls, labels: PlayerLabels, parts: readonly Part[], scoreTempo: number, getSnapshot: () => PlayerSnapshot, features?: ControlFeatures): ControlBar;
|
|
22
|
+
export {};
|