@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,23 @@
|
|
|
1
|
+
import type { HiddenPart, ScoreEvent, ScoreMeasure, ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import { type TickRange } from "./tickRanges.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parts hidden over (part of) a bar (ADR 0013): a part that sings no note there may be left out,
|
|
5
|
+
* so a system where it is hidden throughout has no row for it. Rests are allowed (they are silent).
|
|
6
|
+
*/
|
|
7
|
+
type Hidden = Pick<ScoreMeasure, "hidden_parts">;
|
|
8
|
+
/** The bar's hidden stretches, older plain ids read as the whole bar. */
|
|
9
|
+
export declare const hiddenOf: (measure: Hidden | undefined) => HiddenPart[];
|
|
10
|
+
/** Whether the part is hidden over all of `range` in this bar. */
|
|
11
|
+
export declare const hiddenOver: (measure: Hidden | undefined, partId: string, range: TickRange) => boolean;
|
|
12
|
+
/** Whether the part is hidden in the whole bar. */
|
|
13
|
+
export declare const hiddenWhole: (measure: Hidden | undefined, partId: string) => boolean;
|
|
14
|
+
/** Whether the part is hidden at a tick of the bar. */
|
|
15
|
+
export declare const hiddenAtTick: (measure: Hidden | undefined, partId: string, tick: number) => boolean;
|
|
16
|
+
/** Whether a note sounds anywhere in `range` (rests are silent). */
|
|
17
|
+
export declare function soundsIn(events: readonly ScoreEvent[], range: TickRange): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The score without hidden stretches that no longer hold: a part that was removed, or that now
|
|
20
|
+
* sings there (notes were written or pasted), shows again. Same score when all hold.
|
|
21
|
+
*/
|
|
22
|
+
export declare function keepValidHiddenParts(music: ScoreMusic): ScoreMusic;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { coversRange, holdsTickIn } from "./tickRanges.js";
|
|
2
|
+
/** The bar's hidden stretches, older plain ids read as the whole bar. */
|
|
3
|
+
export const hiddenOf = (measure) => (measure?.hidden_parts ?? []).map((entry) => typeof entry === "string" ? { part: entry, from: 0, to: null } : entry);
|
|
4
|
+
/** Whether the part is hidden over all of `range` in this bar. */
|
|
5
|
+
export const hiddenOver = (measure, partId, range) => hiddenOf(measure).some((h) => h.part === partId && coversRange(h, range));
|
|
6
|
+
/** Whether the part is hidden in the whole bar. */
|
|
7
|
+
export const hiddenWhole = (measure, partId) => hiddenOver(measure, partId, { from: 0, to: null });
|
|
8
|
+
/** Whether the part is hidden at a tick of the bar. */
|
|
9
|
+
export const hiddenAtTick = (measure, partId, tick) => hiddenOf(measure).some((h) => h.part === partId && holdsTickIn(h, tick));
|
|
10
|
+
/** Whether a note sounds anywhere in `range` (rests are silent). */
|
|
11
|
+
export function soundsIn(events, range) {
|
|
12
|
+
let tick = 0;
|
|
13
|
+
for (const event of events) {
|
|
14
|
+
const end = tick + event.duration;
|
|
15
|
+
if (event.type === "note" && end > range.from && (range.to === null || tick < range.to))
|
|
16
|
+
return true;
|
|
17
|
+
tick = end;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The score without hidden stretches that no longer hold: a part that was removed, or that now
|
|
23
|
+
* sings there (notes were written or pasted), shows again. Same score when all hold.
|
|
24
|
+
*/
|
|
25
|
+
export function keepValidHiddenParts(music) {
|
|
26
|
+
let changed = false;
|
|
27
|
+
const measures = music.measures.map((measure, measureIndex) => {
|
|
28
|
+
const hidden = hiddenOf(measure);
|
|
29
|
+
const kept = hidden.filter((h) => {
|
|
30
|
+
const part = music.parts.find((p) => p.id === h.part);
|
|
31
|
+
return part !== undefined && !soundsIn(part.measures[measureIndex]?.events ?? [], h);
|
|
32
|
+
});
|
|
33
|
+
if (kept.length === (measure.hidden_parts ?? []).length)
|
|
34
|
+
return measure;
|
|
35
|
+
changed = true;
|
|
36
|
+
return { ...measure, hidden_parts: kept };
|
|
37
|
+
});
|
|
38
|
+
return changed ? { ...music, measures } : music;
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ScoreEvent, ScoreMusic } from "../schema/types.js";
|
|
2
|
+
/** Where an event sits in the score. */
|
|
3
|
+
export type EventLocation = {
|
|
4
|
+
partIndex: number;
|
|
5
|
+
measureIndex: number;
|
|
6
|
+
eventIndex: number;
|
|
7
|
+
event: ScoreEvent;
|
|
8
|
+
};
|
|
9
|
+
/** Find an event by id, or null when no part holds it. */
|
|
10
|
+
export declare function locateEvent(music: ScoreMusic, eventId: string): EventLocation | null;
|
|
11
|
+
/** The events of one part in reading order (across measures). */
|
|
12
|
+
export declare const partEvents: (music: ScoreMusic, partIndex: number) => ScoreEvent[];
|
|
13
|
+
/** The event before (-1) or after (+1) an event in its part, across bar lines; null at an end. */
|
|
14
|
+
export declare function neighbourEvent(music: ScoreMusic, eventId: string, direction: -1 | 1): ScoreEvent | null;
|
|
15
|
+
/** Every event id of the score, in part order then reading order. */
|
|
16
|
+
export declare const allEventIds: (music: ScoreMusic) => string[];
|
|
17
|
+
/** The part each event belongs to: event id -> part id. */
|
|
18
|
+
export declare const eventParts: (music: ScoreMusic) => Map<string, string>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Find an event by id, or null when no part holds it. */
|
|
2
|
+
export function locateEvent(music, eventId) {
|
|
3
|
+
for (const [partIndex, part] of music.parts.entries()) {
|
|
4
|
+
for (const [measureIndex, measure] of part.measures.entries()) {
|
|
5
|
+
const eventIndex = measure.events.findIndex((e) => e.id === eventId);
|
|
6
|
+
if (eventIndex >= 0)
|
|
7
|
+
return {
|
|
8
|
+
partIndex,
|
|
9
|
+
measureIndex,
|
|
10
|
+
eventIndex,
|
|
11
|
+
event: measure.events[eventIndex],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/** The events of one part in reading order (across measures). */
|
|
18
|
+
export const partEvents = (music, partIndex) => music.parts[partIndex]?.measures.flatMap((m) => m.events) ?? [];
|
|
19
|
+
/** The event before (-1) or after (+1) an event in its part, across bar lines; null at an end. */
|
|
20
|
+
export function neighbourEvent(music, eventId, direction) {
|
|
21
|
+
const at = locateEvent(music, eventId);
|
|
22
|
+
if (!at)
|
|
23
|
+
return null;
|
|
24
|
+
const events = partEvents(music, at.partIndex);
|
|
25
|
+
const index = events.findIndex((e) => e.id === eventId);
|
|
26
|
+
return events[index + direction] ?? null;
|
|
27
|
+
}
|
|
28
|
+
/** Every event id of the score, in part order then reading order. */
|
|
29
|
+
export const allEventIds = (music) => music.parts.flatMap((p) => p.measures.flatMap((m) => m.events.map((e) => e.id)));
|
|
30
|
+
/** The part each event belongs to: event id -> part id. */
|
|
31
|
+
export const eventParts = (music) => new Map(music.parts.flatMap((part) => part.measures.flatMap((measure) => measure.events.map((e) => [e.id, part.id]))));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScorePart } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a part is a tenor, countertenor, baritone or bass, by its name ("Tenor 1", "Counter
|
|
4
|
+
* Tenor", "Bariton", "Bas") or, failing that, its abbreviation. The score does not record a part's
|
|
5
|
+
* voice, so the name is what says it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isLowVoicePart(part: Pick<ScorePart, "name" | "abbreviation">): boolean;
|
|
8
|
+
/** How many octaves to draw a part's notes above where they are written. */
|
|
9
|
+
export declare const octaveShiftOf: (part: Pick<ScorePart, "name" | "abbreviation">, lowVoicesUp: boolean | undefined) => number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Voices a numbered score writes an octave above where they sound (the F-clef voices). */
|
|
2
|
+
const LOW_VOICE_WORDS = new Set(["tenor", "countertenor", "baritone", "bariton", "bass", "bas"]);
|
|
3
|
+
/** Their abbreviations: T, CT, Bar, B, with a number for a divided part (T1, B2). */
|
|
4
|
+
const LOW_VOICE_ABBREVIATION = /^(t|ct|bar|b)\d*$/i;
|
|
5
|
+
const wordsOf = (text) => text.toLowerCase().split(/[^a-z]+/).filter(Boolean);
|
|
6
|
+
/**
|
|
7
|
+
* Whether a part is a tenor, countertenor, baritone or bass, by its name ("Tenor 1", "Counter
|
|
8
|
+
* Tenor", "Bariton", "Bas") or, failing that, its abbreviation. The score does not record a part's
|
|
9
|
+
* voice, so the name is what says it.
|
|
10
|
+
*/
|
|
11
|
+
export function isLowVoicePart(part) {
|
|
12
|
+
const words = wordsOf(part.name);
|
|
13
|
+
if (words.length > 0) {
|
|
14
|
+
const joined = words.join("");
|
|
15
|
+
return words.some((w) => LOW_VOICE_WORDS.has(w)) || joined.includes("countertenor");
|
|
16
|
+
}
|
|
17
|
+
return LOW_VOICE_ABBREVIATION.test(part.abbreviation.trim());
|
|
18
|
+
}
|
|
19
|
+
/** How many octaves to draw a part's notes above where they are written. */
|
|
20
|
+
export const octaveShiftOf = (part, lowVoicesUp) => (lowVoicesUp ?? true) && isLowVoicePart(part) ? 1 : 0;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PartColor, ScorePart } from "../schema/types.js";
|
|
2
|
+
/** The palette a part can be given, in the order the menu lists it. */
|
|
3
|
+
export declare const PART_COLORS: readonly PartColor[];
|
|
4
|
+
/** A part's color while it plays: one from the palette, or the default light blue (none given). */
|
|
5
|
+
export type PartTone = PartColor | "default";
|
|
6
|
+
/** The tones the menu offers: the default first, then the palette. */
|
|
7
|
+
export declare const PART_TONES: readonly PartTone[];
|
|
8
|
+
/** A part's tone: the color it was given, or the default light blue. */
|
|
9
|
+
export declare const partToneOf: (part: Pick<ScorePart, "color">) => PartTone;
|
|
10
|
+
/** Every part's tone, by part id. */
|
|
11
|
+
export declare const partTones: (parts: readonly Pick<ScorePart, "id" | "color">[]) => Record<string, PartTone>;
|
|
12
|
+
/** What a part stores for a tone: the color, or null for the default. */
|
|
13
|
+
export declare const storedColor: (tone: PartTone) => PartColor | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The palette a part can be given, in the order the menu lists it. */
|
|
2
|
+
export const PART_COLORS = ["orchid", "periwinkle", "sky", "ivory", "sage"];
|
|
3
|
+
/** The tones the menu offers: the default first, then the palette. */
|
|
4
|
+
export const PART_TONES = ["default", ...PART_COLORS];
|
|
5
|
+
/** A part's tone: the color it was given, or the default light blue. */
|
|
6
|
+
export const partToneOf = (part) => part.color ?? "default";
|
|
7
|
+
/** Every part's tone, by part id. */
|
|
8
|
+
export const partTones = (parts) => Object.fromEntries(parts.map((part) => [part.id, partToneOf(part)]));
|
|
9
|
+
/** What a part stores for a tone: the color, or null for the default. */
|
|
10
|
+
export const storedColor = (tone) => (tone === "default" ? null : tone);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PartSpan, ScoreMeasure, ScoreMusic, ScorePart } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The bars a part plays. A part with a span (one that joins later or leaves early) is blank
|
|
4
|
+
* outside it: no row on systems it does not reach, nothing drawn and nothing written in its
|
|
5
|
+
* other measures. A part without one plays the whole score.
|
|
6
|
+
*/
|
|
7
|
+
/** First and last measure index a part plays (the whole score when it has no span). */
|
|
8
|
+
export declare function spanIndices(measures: readonly Pick<ScoreMeasure, "id">[], part: Pick<ScorePart, "span">): {
|
|
9
|
+
first: number;
|
|
10
|
+
last: number;
|
|
11
|
+
};
|
|
12
|
+
/** Whether a part plays the measure at `measureIndex`. */
|
|
13
|
+
export declare function plays(music: Pick<ScoreMusic, "measures">, part: Pick<ScorePart, "span">, measureIndex: number): boolean;
|
|
14
|
+
/** Whether a part plays any of the measures at these indices (it has a row on that system). */
|
|
15
|
+
export declare const playsAny: (music: Pick<ScoreMusic, "measures">, part: Pick<ScorePart, "span">, indices: readonly number[]) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The span for bars `fromBar` to `toBar` (1-based, either may be left out: from the first, to the
|
|
18
|
+
* last bar). Null when the range is the whole score; undefined when it is not a valid range.
|
|
19
|
+
*/
|
|
20
|
+
export declare function spanOfBars(measures: readonly Pick<ScoreMeasure, "id">[], fromBar: number | null, toBar: number | null): PartSpan | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* A part's span once the measures where `keep` is false are deleted: it shrinks to the measures
|
|
23
|
+
* of its range that remain. Undefined when none remain (the part has no bars left).
|
|
24
|
+
*/
|
|
25
|
+
export declare function spanAfterDelete(music: Pick<ScoreMusic, "measures">, part: Pick<ScorePart, "span">, keep: readonly boolean[]): PartSpan | null | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bars a part plays. A part with a span (one that joins later or leaves early) is blank
|
|
3
|
+
* outside it: no row on systems it does not reach, nothing drawn and nothing written in its
|
|
4
|
+
* other measures. A part without one plays the whole score.
|
|
5
|
+
*/
|
|
6
|
+
/** First and last measure index a part plays (the whole score when it has no span). */
|
|
7
|
+
export function spanIndices(measures, part) {
|
|
8
|
+
const whole = { first: 0, last: measures.length - 1 };
|
|
9
|
+
if (!part.span)
|
|
10
|
+
return whole;
|
|
11
|
+
const first = measures.findIndex((m) => m.id === part.span.from);
|
|
12
|
+
const last = measures.findIndex((m) => m.id === part.span.to);
|
|
13
|
+
return first >= 0 && last >= first ? { first, last } : whole;
|
|
14
|
+
}
|
|
15
|
+
/** Whether a part plays the measure at `measureIndex`. */
|
|
16
|
+
export function plays(music, part, measureIndex) {
|
|
17
|
+
const { first, last } = spanIndices(music.measures, part);
|
|
18
|
+
return measureIndex >= first && measureIndex <= last;
|
|
19
|
+
}
|
|
20
|
+
/** Whether a part plays any of the measures at these indices (it has a row on that system). */
|
|
21
|
+
export const playsAny = (music, part, indices) => indices.some((i) => plays(music, part, i));
|
|
22
|
+
/**
|
|
23
|
+
* The span for bars `fromBar` to `toBar` (1-based, either may be left out: from the first, to the
|
|
24
|
+
* last bar). Null when the range is the whole score; undefined when it is not a valid range.
|
|
25
|
+
*/
|
|
26
|
+
export function spanOfBars(measures, fromBar, toBar) {
|
|
27
|
+
const first = (fromBar ?? 1) - 1;
|
|
28
|
+
const last = (toBar ?? measures.length) - 1;
|
|
29
|
+
if (!Number.isInteger(first) || !Number.isInteger(last))
|
|
30
|
+
return undefined;
|
|
31
|
+
if (first < 0 || last >= measures.length || first > last)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (first === 0 && last === measures.length - 1)
|
|
34
|
+
return null;
|
|
35
|
+
return { from: measures[first].id, to: measures[last].id };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A part's span once the measures where `keep` is false are deleted: it shrinks to the measures
|
|
39
|
+
* of its range that remain. Undefined when none remain (the part has no bars left).
|
|
40
|
+
*/
|
|
41
|
+
export function spanAfterDelete(music, part, keep) {
|
|
42
|
+
if (!part.span)
|
|
43
|
+
return null;
|
|
44
|
+
const { first, last } = spanIndices(music.measures, part);
|
|
45
|
+
const kept = music.measures.slice(first, last + 1).filter((_, i) => keep[first + i]);
|
|
46
|
+
if (!kept.length)
|
|
47
|
+
return undefined;
|
|
48
|
+
return { from: kept[0].id, to: kept[kept.length - 1].id };
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ScoreMeasure, ScoreMusic, ScorePart } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a part's bar is drawn on its row: it plays the bar, does not sing another part's notes
|
|
4
|
+
* over all of it (ADR 0012), and is not hidden in all of it (ADR 0013). Otherwise its row is blank there
|
|
5
|
+
* (no rests, bar lines or hit areas), like a part outside the bars it plays.
|
|
6
|
+
*/
|
|
7
|
+
export declare const drawnIn: (music: Pick<ScoreMusic, "measures">, part: Pick<ScorePart, "id" | "span">, measureIndex: number) => boolean;
|
|
8
|
+
/** Whether a part has nothing of its own over ticks `from`..`to` of a bar: merged into the row above, or hidden. */
|
|
9
|
+
export declare const absentOver: (measure: Pick<ScoreMeasure, "unisons" | "hidden_parts"> | undefined, partId: string, from: number, to: number | null) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the part's own notes at a tick of the bar are drawn on its row: not sung in the row of a
|
|
12
|
+
* part above (ADR 0012) and not hidden (ADR 0013) there.
|
|
13
|
+
*/
|
|
14
|
+
export declare const shownAt: (measure: Pick<ScoreMeasure, "unisons" | "hidden_parts"> | undefined, partId: string, tick: number) => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { hiddenAtTick, hiddenOver, hiddenWhole } from "./hiddenParts.js";
|
|
2
|
+
import { plays } from "./partSpan.js";
|
|
3
|
+
import { follows, hiddenAt, mergedOver } from "./unisons.js";
|
|
4
|
+
/**
|
|
5
|
+
* Whether a part's bar is drawn on its row: it plays the bar, does not sing another part's notes
|
|
6
|
+
* over all of it (ADR 0012), and is not hidden in all of it (ADR 0013). Otherwise its row is blank there
|
|
7
|
+
* (no rests, bar lines or hit areas), like a part outside the bars it plays.
|
|
8
|
+
*/
|
|
9
|
+
export const drawnIn = (music, part, measureIndex) => {
|
|
10
|
+
const measure = music.measures[measureIndex];
|
|
11
|
+
return plays(music, part, measureIndex) && !follows(measure, part.id) && !hiddenWhole(measure, part.id);
|
|
12
|
+
};
|
|
13
|
+
/** Whether a part has nothing of its own over ticks `from`..`to` of a bar: merged into the row above, or hidden. */
|
|
14
|
+
export const absentOver = (measure, partId, from, to) => hiddenOver(measure, partId, { from, to }) || mergedOver(measure, partId, from, to);
|
|
15
|
+
/**
|
|
16
|
+
* Whether the part's own notes at a tick of the bar are drawn on its row: not sung in the row of a
|
|
17
|
+
* part above (ADR 0012) and not hidden (ADR 0013) there.
|
|
18
|
+
*/
|
|
19
|
+
export const shownAt = (measure, partId, tick) => !hiddenAt(measure, partId, tick) && !hiddenAtTick(measure, partId, tick);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ScoreEvent, ScoreMeasure, ScoreMusic, SharedLyrics } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parts sharing lyrics (ADR 0014): neighbouring parts that sing the words of the bottom one (the
|
|
4
|
+
* last in a group) over a stretch of a bar. Every part keeps its own copy of the syllables (to be
|
|
5
|
+
* sung later); only the bottom part's are drawn, and edits there are copied to the others.
|
|
6
|
+
*/
|
|
7
|
+
type Shared = Pick<ScoreMeasure, "shared_lyrics">;
|
|
8
|
+
/** The bar's shared-lyrics groups. */
|
|
9
|
+
export declare const sharedLyricsOf: (measure: Shared | undefined) => SharedLyrics[];
|
|
10
|
+
/** Whether the part's syllables at a tick are not drawn: it shares the lyrics of a part below it there. */
|
|
11
|
+
export declare const lyricsHiddenAt: (measure: Shared | undefined, partId: string, tick: number) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A part's events with the syllables of the source part: each note gets the syllables of the
|
|
14
|
+
* source's note that starts at the same tick (none when the source has no note starting there).
|
|
15
|
+
* Notes where `keeps` says so are left alone: where the part is merged into the row above (ADR
|
|
16
|
+
* 0012), its words come from that part instead.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withSourceLyrics(events: readonly ScoreEvent[], source: readonly ScoreEvent[], range: Pick<SharedLyrics, "from" | "to">, keeps?: (onset: number) => boolean): ScoreEvent[];
|
|
19
|
+
/** The score with every group's parts holding the bottom part's syllables. Same score when nothing changes. */
|
|
20
|
+
export declare function syncSharedLyrics(music: ScoreMusic): ScoreMusic;
|
|
21
|
+
/** The score without groups that no longer hold (a part was removed or moved away). Same score when all hold. */
|
|
22
|
+
export declare function keepValidSharedLyrics(music: ScoreMusic): ScoreMusic;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { holdsTickIn } from "./tickRanges.js";
|
|
2
|
+
import { hiddenAt, neighbouring, withOnsets } from "./unisons.js";
|
|
3
|
+
/** The bar's shared-lyrics groups. */
|
|
4
|
+
export const sharedLyricsOf = (measure) => measure?.shared_lyrics ?? [];
|
|
5
|
+
/** Whether the part's syllables at a tick are not drawn: it shares the lyrics of a part below it there. */
|
|
6
|
+
export const lyricsHiddenAt = (measure, partId, tick) => sharedLyricsOf(measure).some((g) => g.parts.slice(0, -1).includes(partId) && holdsTickIn(g, tick));
|
|
7
|
+
const lyricsKey = (event) => JSON.stringify(event.lyrics);
|
|
8
|
+
/**
|
|
9
|
+
* A part's events with the syllables of the source part: each note gets the syllables of the
|
|
10
|
+
* source's note that starts at the same tick (none when the source has no note starting there).
|
|
11
|
+
* Notes where `keeps` says so are left alone: where the part is merged into the row above (ADR
|
|
12
|
+
* 0012), its words come from that part instead.
|
|
13
|
+
*/
|
|
14
|
+
export function withSourceLyrics(events, source, range, keeps = () => false) {
|
|
15
|
+
const sourceAt = new Map(withOnsets(source).flatMap(({ onset, event }) => (event.type === "note" ? [[onset, event]] : [])));
|
|
16
|
+
let changed = false;
|
|
17
|
+
const next = withOnsets(events).map(({ onset, event }) => {
|
|
18
|
+
if (event.type !== "note" || !holdsTickIn(range, onset) || keeps(onset))
|
|
19
|
+
return event;
|
|
20
|
+
const lyrics = sourceAt.get(onset)?.lyrics ?? [];
|
|
21
|
+
if (lyricsKey(event) === JSON.stringify(lyrics))
|
|
22
|
+
return event;
|
|
23
|
+
changed = true;
|
|
24
|
+
return { ...event, lyrics: [...lyrics] };
|
|
25
|
+
});
|
|
26
|
+
return changed ? next : events;
|
|
27
|
+
}
|
|
28
|
+
/** The score with every group's parts holding the bottom part's syllables. Same score when nothing changes. */
|
|
29
|
+
export function syncSharedLyrics(music) {
|
|
30
|
+
let next = music;
|
|
31
|
+
music.measures.forEach((measure, measureIndex) => {
|
|
32
|
+
for (const group of sharedLyricsOf(measure)) {
|
|
33
|
+
const source = next.parts.find((p) => p.id === group.parts[group.parts.length - 1]);
|
|
34
|
+
if (!source)
|
|
35
|
+
continue;
|
|
36
|
+
const sourceEvents = source.measures[measureIndex]?.events ?? [];
|
|
37
|
+
next = {
|
|
38
|
+
...next,
|
|
39
|
+
parts: next.parts.map((part) => {
|
|
40
|
+
if (!group.parts.slice(0, -1).includes(part.id))
|
|
41
|
+
return part;
|
|
42
|
+
const events = part.measures[measureIndex]?.events ?? [];
|
|
43
|
+
const synced = withSourceLyrics(events, sourceEvents, group, (onset) => hiddenAt(measure, part.id, onset));
|
|
44
|
+
if (synced === events)
|
|
45
|
+
return part;
|
|
46
|
+
return { ...part, measures: part.measures.map((m, i) => (i === measureIndex ? { events: synced } : m)) };
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return next.parts.every((p, i) => p === music.parts[i]) ? music : next;
|
|
52
|
+
}
|
|
53
|
+
/** The score without groups that no longer hold (a part was removed or moved away). Same score when all hold. */
|
|
54
|
+
export function keepValidSharedLyrics(music) {
|
|
55
|
+
let changed = false;
|
|
56
|
+
const measures = music.measures.map((measure) => {
|
|
57
|
+
const groups = sharedLyricsOf(measure);
|
|
58
|
+
const kept = groups.filter((g) => {
|
|
59
|
+
const indices = g.parts.map((id) => music.parts.findIndex((p) => p.id === id));
|
|
60
|
+
return g.parts.length >= 2 && indices.every((i) => i >= 0) && neighbouring(indices);
|
|
61
|
+
});
|
|
62
|
+
if (kept.length === groups.length)
|
|
63
|
+
return measure;
|
|
64
|
+
changed = true;
|
|
65
|
+
return { ...measure, shared_lyrics: kept };
|
|
66
|
+
});
|
|
67
|
+
return changed ? { ...music, measures } : music;
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ScoreMeasure, ScoreMusic, ScorePart } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Text bars (ADR 0009): a bar that writes text across every part ("2 bars instr.") instead of
|
|
4
|
+
* notes, and stands for that many bars of rest. Nothing is typed or pasted into one.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isTextBar: (measure: Pick<ScoreMeasure, "text_bar"> | undefined) => boolean;
|
|
7
|
+
/** The bar number each measure starts at, as printed: a text bar of 2 bars takes two numbers. */
|
|
8
|
+
export declare function barNumbers(measures: readonly Pick<ScoreMeasure, "text_bar">[]): number[];
|
|
9
|
+
/** The bar number the measure at `index` starts at. */
|
|
10
|
+
export declare const barNumberOf: (measures: readonly Pick<ScoreMeasure, "text_bar">[], index: number) => number;
|
|
11
|
+
/** Whether notes can be written in a part's measure: a bar it plays that is not a text bar. */
|
|
12
|
+
export declare const takesNotes: (music: Pick<ScoreMusic, "measures">, part: Pick<ScorePart, "span">, measureIndex: number) => boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { plays } from "./partSpan.js";
|
|
2
|
+
/**
|
|
3
|
+
* Text bars (ADR 0009): a bar that writes text across every part ("2 bars instr.") instead of
|
|
4
|
+
* notes, and stands for that many bars of rest. Nothing is typed or pasted into one.
|
|
5
|
+
*/
|
|
6
|
+
export const isTextBar = (measure) => !!measure?.text_bar;
|
|
7
|
+
/** How many bars a measure counts as: a text bar its `bars`, every other measure one. */
|
|
8
|
+
const barsOf = (measure) => measure.text_bar?.bars ?? 1;
|
|
9
|
+
/** The bar number each measure starts at, as printed: a text bar of 2 bars takes two numbers. */
|
|
10
|
+
export function barNumbers(measures) {
|
|
11
|
+
let next = 1;
|
|
12
|
+
return measures.map((measure) => {
|
|
13
|
+
const number = next;
|
|
14
|
+
next += barsOf(measure);
|
|
15
|
+
return number;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** The bar number the measure at `index` starts at. */
|
|
19
|
+
export const barNumberOf = (measures, index) => barNumbers(measures.slice(0, index + 1))[index] ?? index + 1;
|
|
20
|
+
/** Whether notes can be written in a part's measure: a bar it plays that is not a text bar. */
|
|
21
|
+
export const takesNotes = (music, part, measureIndex) => plays(music, part, measureIndex) && !isTextBar(music.measures[measureIndex]);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stretches of a bar in ticks from its start: `from` up to `to` (null = the bar's end). Shared by
|
|
3
|
+
* parts merged over part of a bar (ADR 0012) and parts hidden over part of one (ADR 0013).
|
|
4
|
+
*/
|
|
5
|
+
export type TickRange = {
|
|
6
|
+
from: number;
|
|
7
|
+
to: number | null;
|
|
8
|
+
};
|
|
9
|
+
/** The end of a range as a number (null = the bar's end, past every tick). */
|
|
10
|
+
export declare const endOf: (range: TickRange) => number;
|
|
11
|
+
/** Whether `outer` covers all of `inner`. */
|
|
12
|
+
export declare const coversRange: (outer: TickRange, inner: TickRange) => boolean;
|
|
13
|
+
/** Whether two ranges share any tick. */
|
|
14
|
+
export declare const overlapsRange: (a: TickRange, b: TickRange) => boolean;
|
|
15
|
+
/** Whether a tick lies in the range. */
|
|
16
|
+
export declare const holdsTickIn: (range: TickRange, tick: number) => boolean;
|
|
17
|
+
/** The range of one bar that a stretch from `from` in the first bar to `to` in the last covers. */
|
|
18
|
+
export declare function rangeInBar(stretch: Partial<TickRange>, indices: readonly number[], measureIndex: number): TickRange;
|
|
19
|
+
/** An item's range less `range`: none, one or two pieces (the rest of the item is kept). */
|
|
20
|
+
export declare function cutRange<T extends TickRange>(item: T, range: TickRange): T[];
|
|
21
|
+
/** Items with the same key whose ranges touch or overlap, joined into one. */
|
|
22
|
+
export declare function joinRanges<T extends TickRange>(items: readonly T[], key: (item: T) => string): T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The end of a range as a number (null = the bar's end, past every tick). */
|
|
2
|
+
export const endOf = (range) => range.to ?? Number.POSITIVE_INFINITY;
|
|
3
|
+
const asEnd = (tick) => (Number.isFinite(tick) ? tick : null);
|
|
4
|
+
/** Whether `outer` covers all of `inner`. */
|
|
5
|
+
export const coversRange = (outer, inner) => outer.from <= inner.from && endOf(outer) >= endOf(inner);
|
|
6
|
+
/** Whether two ranges share any tick. */
|
|
7
|
+
export const overlapsRange = (a, b) => a.from < endOf(b) && b.from < endOf(a);
|
|
8
|
+
/** Whether a tick lies in the range. */
|
|
9
|
+
export const holdsTickIn = (range, tick) => range.from <= tick && tick < endOf(range);
|
|
10
|
+
/** The range of one bar that a stretch from `from` in the first bar to `to` in the last covers. */
|
|
11
|
+
export function rangeInBar(stretch, indices, measureIndex) {
|
|
12
|
+
const first = measureIndex === indices[0];
|
|
13
|
+
const last = measureIndex === indices[indices.length - 1];
|
|
14
|
+
return { from: first ? (stretch.from ?? 0) : 0, to: last ? (stretch.to ?? null) : null };
|
|
15
|
+
}
|
|
16
|
+
/** An item's range less `range`: none, one or two pieces (the rest of the item is kept). */
|
|
17
|
+
export function cutRange(item, range) {
|
|
18
|
+
if (endOf(range) <= item.from || endOf(item) <= range.from)
|
|
19
|
+
return [item];
|
|
20
|
+
return [
|
|
21
|
+
...(item.from < range.from ? [{ ...item, to: range.from }] : []),
|
|
22
|
+
...(endOf(range) < endOf(item) ? [{ ...item, from: endOf(range) }] : []),
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
/** Items with the same key whose ranges touch or overlap, joined into one. */
|
|
26
|
+
export function joinRanges(items, key) {
|
|
27
|
+
const sorted = items.toSorted((a, b) => key(a).localeCompare(key(b)) || a.from - b.from);
|
|
28
|
+
return sorted.reduce((out, item) => {
|
|
29
|
+
const last = out.at(-1);
|
|
30
|
+
if (!last || key(last) !== key(item) || item.from > endOf(last))
|
|
31
|
+
return [...out, item];
|
|
32
|
+
return [...out.slice(0, -1), { ...last, to: asEnd(Math.max(endOf(last), endOf(item))) }];
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ScoreEvent, ScoreMeasure, ScoreMusic, ScorePart, Unison } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parts singing in unison (ADR 0012): neighbouring parts that sing the same notes and lyrics are
|
|
4
|
+
* drawn as one row ("SA."). A group covers ticks `from`..`to` of a bar (`to` null = its end).
|
|
5
|
+
* Over the whole bar only the first part holds the notes and the others hold none (playback gives
|
|
6
|
+
* them the first one's). Over part of a bar every part keeps its own notes, the same inside the
|
|
7
|
+
* range, and the editor hides the others' there.
|
|
8
|
+
*/
|
|
9
|
+
type Groups = Pick<ScoreMeasure, "unisons">;
|
|
10
|
+
/** The unison groups of a bar. */
|
|
11
|
+
export declare const unisonsOf: (measure: Groups | undefined) => Unison[];
|
|
12
|
+
/** Whether a group covers the whole bar (its lower parts then hold no notes). */
|
|
13
|
+
export declare const coversWholeBar: (group: Pick<Unison, "from" | "to">) => boolean;
|
|
14
|
+
/** Whether a group covers the ticks `from`..`to` of its bar (`to` null = to the bar's end). */
|
|
15
|
+
export declare const coversRange: (group: Pick<Unison, "from" | "to">, from: number, to: number | null) => boolean;
|
|
16
|
+
/** Whether the part sings another part's notes over the whole bar (it holds none there). */
|
|
17
|
+
export declare const follows: (measure: Groups | undefined, partId: string) => boolean;
|
|
18
|
+
/** Whether the part's notes at `tick` are hidden: it sings in the row of a part above it there. */
|
|
19
|
+
export declare const hiddenAt: (measure: Groups | undefined, partId: string, tick: number) => boolean;
|
|
20
|
+
/** Whether the part is merged into the row above over all of ticks `from`..`to` of the bar. */
|
|
21
|
+
export declare const mergedOver: (measure: Groups | undefined, partId: string, from: number, to: number | null) => boolean;
|
|
22
|
+
/** A piece of a bar on a system: ticks `from`..`to` (null = the bar's end). */
|
|
23
|
+
export type BarPiece = {
|
|
24
|
+
measure: Groups | undefined;
|
|
25
|
+
from: number;
|
|
26
|
+
to: number | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The parts a part leads over every one of these pieces of bars (the same parts each time), or
|
|
30
|
+
* undefined. Only then does the system draw the group as one row with the joined abbreviations.
|
|
31
|
+
*/
|
|
32
|
+
export declare function groupLedThroughout(pieces: readonly BarPiece[], partId: string): string[] | undefined;
|
|
33
|
+
/** "S." + "A." = "SA.": the abbreviations without their full stops, joined, with one at the end. */
|
|
34
|
+
export declare function joinedLabel(parts: readonly Pick<ScorePart, "abbreviation">[]): string;
|
|
35
|
+
/** Every joined label the score uses (for the room the widest label needs). */
|
|
36
|
+
export declare function joinedLabels(music: ScoreMusic): string[];
|
|
37
|
+
/** What a part sings in a bar: its own notes, or its lead part's when it follows one over the whole bar. */
|
|
38
|
+
export declare function sungEvents(music: ScoreMusic, partIndex: number, measureIndex: number): ScoreEvent[];
|
|
39
|
+
/** Each event with its start, in ticks from the bar's start. */
|
|
40
|
+
export declare const withOnsets: (events: readonly ScoreEvent[]) => {
|
|
41
|
+
onset: number;
|
|
42
|
+
event: ScoreEvent;
|
|
43
|
+
}[];
|
|
44
|
+
/** Where events start, and where the last one ends. */
|
|
45
|
+
export declare const edgesOf: (events: readonly ScoreEvent[]) => Set<number>;
|
|
46
|
+
/** The events that start inside ticks `from`..`to` (null = to the end). */
|
|
47
|
+
export declare const eventsWithin: (events: readonly ScoreEvent[], from: number, to: number | null) => ScoreEvent[];
|
|
48
|
+
/** Whether two runs of events hold the same notes (lyrics aside). */
|
|
49
|
+
export declare const sameNotes: (a: readonly ScoreEvent[], b: readonly ScoreEvent[]) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether parts can merge over ticks `from`..`to`: notes that start and end on the range's edges,
|
|
52
|
+
* the same notes inside it, and the other parts' lyrics there empty or the same as the lead's.
|
|
53
|
+
*/
|
|
54
|
+
export declare function canSingTogether(bars: readonly (readonly ScoreEvent[])[], from: number, to: number | null): boolean;
|
|
55
|
+
/** Whether the part indices are neighbours in score order (one after the other). */
|
|
56
|
+
export declare const neighbouring: (indices: readonly number[]) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The score without unison groups that no longer hold (a part was typed or pasted into, removed or
|
|
59
|
+
* moved, or a note inside a part-bar group changed in one part only). Returns the same score when
|
|
60
|
+
* every group holds.
|
|
61
|
+
*/
|
|
62
|
+
export declare function keepValidUnisons(music: ScoreMusic): ScoreMusic;
|
|
63
|
+
/**
|
|
64
|
+
* The score with the lower parts of part-bar groups singing the lead's syllables there (the row
|
|
65
|
+
* shows the lead's), so writing lyrics in the merged row never splits it. Returns the same score
|
|
66
|
+
* when nothing changes.
|
|
67
|
+
*/
|
|
68
|
+
export declare function syncUnisonLyrics(music: ScoreMusic): ScoreMusic;
|
|
69
|
+
export {};
|