@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yohanes@Nodelyra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nodelyra/not-angka
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/lumentut/not-angka/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@nodelyra/not-angka)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Render **numbered music notation for human voices** (Not Angka, SATB choir scores) from JSON, and play it in the browser.
|
|
8
|
+
Plain DOM and SVG, Web Audio for sound, typed, no framework needed.
|
|
9
|
+
|
|
10
|
+
**[Documentation](https://lumentut.github.io/not-angka/)** · **[Live demo](https://lumentut.github.io/not-angka/demo)**
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @nodelyra/not-angka
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { createScorePlayer } from "@nodelyra/not-angka";
|
|
18
|
+
|
|
19
|
+
// `score` is the score JSON; see the documentation for the format.
|
|
20
|
+
createScorePlayer(document.getElementById("score"), score);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or without a build step:
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<div id="score"></div>
|
|
27
|
+
<script src="https://unpkg.com/@nodelyra/not-angka"></script>
|
|
28
|
+
<script>
|
|
29
|
+
NodelyraPlayer.createScorePlayer(document.getElementById("score"), score);
|
|
30
|
+
</script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- **Player** (`createScorePlayer`): a whole song on paper-sized pages, with transport, tempo, loop and a part mixer.
|
|
34
|
+
- **Excerpt** (`createExcerptPlayer`, `mountExcerpts`): a few bars inside an article, isolated in a shadow tree.
|
|
35
|
+
- **Server side:** `renderScoreToSvg(score)` returns the score as an SVG string.
|
|
36
|
+
|
|
37
|
+
Examples are in [`examples/`](examples). Released under the [MIT licence](LICENSE).
|
|
38
|
+
|
|
39
|
+
INDNJC
|
package/THIRD_PARTY.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Third-party software
|
|
2
|
+
|
|
3
|
+
## Fonts
|
|
4
|
+
|
|
5
|
+
Three fonts are embedded in the player's stylesheet (`assets/fonts/*.woff2`, latin subsets, regenerated into
|
|
6
|
+
`src/player/embeddedFonts.ts` by `scripts/embed-fonts.mjs`), so the notation looks the same on every site. All
|
|
7
|
+
three are licensed under the SIL Open Font License 1.1 (<https://openfontlicense.org>). They are bundled
|
|
8
|
+
unmodified apart from the subset and the WOFF2 packaging; none is sold on its own, and their names are not used
|
|
9
|
+
for anything else.
|
|
10
|
+
|
|
11
|
+
- **Geist Mono** (the digits), Copyright (c) 2023 Vercel, in collaboration with basement.studio.
|
|
12
|
+
Source: <https://github.com/vercel/geist-font>.
|
|
13
|
+
- **Plus Jakarta Sans** (chords and text), Copyright 2020 The Plus Jakarta Sans Project Authors (Tokotype).
|
|
14
|
+
Source: <https://github.com/tokotype/PlusJakartaSans>.
|
|
15
|
+
- **Sofia Sans Extra Condensed** (lyrics), Copyright 2019 The Sofia Sans Project Authors (Lyajka Sofia).
|
|
16
|
+
Source: <https://github.com/lyajka/sofia-sans>.
|
|
17
|
+
|
|
18
|
+
## Dynamics (p, m, f)
|
|
19
|
+
|
|
20
|
+
The dynamic marks (`rendering/dynamicGlyphs.ts`) are drawn as vector shapes whose outlines come from **Tinos**
|
|
21
|
+
Bold Italic (SIL Open Font License 1.1, Copyright 2026 The Tinos Project Authors,
|
|
22
|
+
<https://github.com/googlefonts/tinos>), the open font with the same design and metrics as Times New Roman. The
|
|
23
|
+
outlines are converted to SVG path data; the letter f has a hand-adjusted ball terminal and tail. No font file is
|
|
24
|
+
shipped for them.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import type { ElementBox } from "../layout/elementBoxes.js";
|
|
3
|
+
import type { Page } from "../layout/LayoutEngine.js";
|
|
4
|
+
import type { BeatPosition } from "./beatDot.js";
|
|
5
|
+
/**
|
|
6
|
+
* The chord in effect at the playing beat: the last chord written at that beat or before it, in
|
|
7
|
+
* its bar or an earlier one (a chord holds until the next). A chord stored off the beat counts from
|
|
8
|
+
* its beat, where it is drawn. Null before the first chord, or when nothing plays.
|
|
9
|
+
*/
|
|
10
|
+
export declare function activeChordKey(music: Pick<ScoreMusic, "measures">, at: Pick<BeatPosition, "measureId" | "beat" | "beatDuration"> | null): string | null;
|
|
11
|
+
/** Where the chord with `key` is drawn on `page` (widened like a playing note), or null. */
|
|
12
|
+
export declare function activeChordBox(page: Page, key: string | null): ElementBox | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { onPage } from "./pageBoxes.js";
|
|
2
|
+
import { PLAYING_PAD_X } from "./playbackCursor.js";
|
|
3
|
+
import { targetKey } from "./target.js";
|
|
4
|
+
/** The last chord of a bar at or before tick `before` (exclusive), by its position. */
|
|
5
|
+
const lastChord = (chords, before) => chords.filter((c) => c.at < before).reduce((last, c) => (!last || c.at > last.at ? c : last), undefined);
|
|
6
|
+
/**
|
|
7
|
+
* The chord in effect at the playing beat: the last chord written at that beat or before it, in
|
|
8
|
+
* its bar or an earlier one (a chord holds until the next). A chord stored off the beat counts from
|
|
9
|
+
* its beat, where it is drawn. Null before the first chord, or when nothing plays.
|
|
10
|
+
*/
|
|
11
|
+
export function activeChordKey(music, at) {
|
|
12
|
+
if (!at)
|
|
13
|
+
return null;
|
|
14
|
+
const index = music.measures.findIndex((m) => m.id === at.measureId);
|
|
15
|
+
for (let i = index; i >= 0; i -= 1) {
|
|
16
|
+
const before = i === index ? (at.beat + 1) * at.beatDuration : Infinity;
|
|
17
|
+
const chord = lastChord(music.measures[i].chords ?? [], before);
|
|
18
|
+
if (chord)
|
|
19
|
+
return targetKey({ kind: "chord", measureId: music.measures[i].id, at: chord.at });
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/** Where the chord with `key` is drawn on `page` (widened like a playing note), or null. */
|
|
24
|
+
export function activeChordBox(page, key) {
|
|
25
|
+
if (!key)
|
|
26
|
+
return null;
|
|
27
|
+
for (const system of page.systems) {
|
|
28
|
+
const box = system.boxes.find((b) => b.key === key);
|
|
29
|
+
if (!box)
|
|
30
|
+
continue;
|
|
31
|
+
const placed = onPage(box, system);
|
|
32
|
+
const pad = PLAYING_PAD_X * system.scale;
|
|
33
|
+
return { ...placed, x: placed.x - pad, width: placed.width + 2 * pad };
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Page, PlacedSystem } from "../layout/LayoutEngine.js";
|
|
2
|
+
/** The beat to mark: which beat of which measure, and the lengths that place it. */
|
|
3
|
+
export type BeatPosition = {
|
|
4
|
+
measureId: string;
|
|
5
|
+
/** Beats from the measure's start. */
|
|
6
|
+
beat: number;
|
|
7
|
+
/** The bar's first beat (a pickup bar has none); absent = beat 0 is the downbeat. */
|
|
8
|
+
downbeat?: boolean;
|
|
9
|
+
beatDuration: number;
|
|
10
|
+
measureDuration: number;
|
|
11
|
+
};
|
|
12
|
+
/** The beat dot on a page (page-notation px): above its system, bigger on the downbeat. */
|
|
13
|
+
export type BeatDot = {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
downbeat: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** The dot's radius in page px: on a beat, and (larger) on the downbeat. */
|
|
19
|
+
export declare const DOT_RADIUS: {
|
|
20
|
+
readonly beat: 3.5;
|
|
21
|
+
readonly downbeat: 5;
|
|
22
|
+
};
|
|
23
|
+
/** How far above the top of what its system draws the dot sits, in page px. */
|
|
24
|
+
export declare const BEAT_DOT_RISE = 11;
|
|
25
|
+
/** Higher over a system with chords, so the dot clears the chord names (and the green box behind the playing chord). */
|
|
26
|
+
export declare const BEAT_DOT_RISE_OVER_CHORDS = 12;
|
|
27
|
+
/** How far above `system` its dot sits: higher when the score has chords. */
|
|
28
|
+
export declare const beatDotRise: (system: Pick<PlacedSystem, "markings">) => number;
|
|
29
|
+
/** The dot for `at` on `page`, or null when its measure is on another page. */
|
|
30
|
+
export declare function beatDot(page: Page, at: BeatPosition | null): BeatDot | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { holdsTick } from "../layout/measureSegments.js";
|
|
2
|
+
import { drawnTop } from "./drawnTop.js";
|
|
3
|
+
/** The dot's radius in page px: on a beat, and (larger) on the downbeat. */
|
|
4
|
+
export const DOT_RADIUS = { beat: 3.5, downbeat: 5 };
|
|
5
|
+
/** How far above the top of what its system draws the dot sits, in page px. */
|
|
6
|
+
export const BEAT_DOT_RISE = 11;
|
|
7
|
+
/** Higher over a system with chords, so the dot clears the chord names (and the green box behind the playing chord). */
|
|
8
|
+
export const BEAT_DOT_RISE_OVER_CHORDS = 12;
|
|
9
|
+
/** How far above `system` its dot sits: higher when the score has chords. */
|
|
10
|
+
export const beatDotRise = (system) => system.markings.chords.length > 0 ? BEAT_DOT_RISE_OVER_CHORDS : BEAT_DOT_RISE;
|
|
11
|
+
/**
|
|
12
|
+
* Where the beat is written in a system (layout units): every beat of written music starts a
|
|
13
|
+
* piece (a digit, a rest or a continuation dash), and an unwritten measure has a blank beat x.
|
|
14
|
+
* Otherwise the beat is placed in proportion across the measure.
|
|
15
|
+
*/
|
|
16
|
+
function beatX(system, bounds, at) {
|
|
17
|
+
const onset = at.beat * at.beatDuration;
|
|
18
|
+
for (const row of system.rows) {
|
|
19
|
+
const measure = row.measures.find((m) => m.measureIndex === bounds.measureIndex);
|
|
20
|
+
const slice = measure?.slices.find((s) => s.onset === onset);
|
|
21
|
+
if (slice)
|
|
22
|
+
return slice.x;
|
|
23
|
+
// A split bar's second part has blank beats from where it starts.
|
|
24
|
+
const blank = measure?.blankBeatXs[at.beat - Math.round(bounds.from / at.beatDuration)];
|
|
25
|
+
if (blank !== undefined)
|
|
26
|
+
return blank;
|
|
27
|
+
}
|
|
28
|
+
const span = (bounds.to ?? at.measureDuration) - bounds.from;
|
|
29
|
+
const middle = (onset - bounds.from + at.beatDuration / 2) / Math.max(1, span);
|
|
30
|
+
return bounds.x + bounds.width * Math.min(1, middle);
|
|
31
|
+
}
|
|
32
|
+
/** The dot for `at` on `page`, or null when its measure is on another page. */
|
|
33
|
+
export function beatDot(page, at) {
|
|
34
|
+
if (!at)
|
|
35
|
+
return null;
|
|
36
|
+
for (const system of page.systems) {
|
|
37
|
+
// A split bar is on two systems: the beat is on the one with its part of the bar.
|
|
38
|
+
const onset = at.beat * at.beatDuration;
|
|
39
|
+
const bounds = system.measures.find((m) => m.measureId === at.measureId && holdsTick(m, onset));
|
|
40
|
+
if (!bounds)
|
|
41
|
+
continue;
|
|
42
|
+
return {
|
|
43
|
+
x: beatX(system, bounds, at) * system.scale,
|
|
44
|
+
y: drawnTop(system) - beatDotRise(system),
|
|
45
|
+
downbeat: at.downbeat ?? at.beat === 0,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PlacedSystem } from "../layout/LayoutEngine.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where what `system` draws starts, in page-notation px. Every system gets the headroom the
|
|
4
|
+
* busiest one needs (a volta band, a band for section labels and key changes), so a system
|
|
5
|
+
* without them starts with empty room. A "1 = C" framed at the bracket sits outside the music's
|
|
6
|
+
* column, so it does not count. The playback cursor and beat dot start here, right over the
|
|
7
|
+
* chords, rather than at the top of that empty room.
|
|
8
|
+
*/
|
|
9
|
+
export declare function drawnTop(system: Pick<PlacedSystem, "y" | "scale" | "headroom" | "markings">): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NOTATION } from "../layout/notationMetrics.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where what `system` draws starts, in page-notation px. Every system gets the headroom the
|
|
4
|
+
* busiest one needs (a volta band, a band for section labels and key changes), so a system
|
|
5
|
+
* without them starts with empty room. A "1 = C" framed at the bracket sits outside the music's
|
|
6
|
+
* column, so it does not count. The playback cursor and beat dot start here, right over the
|
|
7
|
+
* chords, rather than at the top of that empty room.
|
|
8
|
+
*/
|
|
9
|
+
export function drawnTop(system) {
|
|
10
|
+
const { markings } = system;
|
|
11
|
+
const bands = Number(markings.voltas.length > 0) +
|
|
12
|
+
Number(markings.labels.length > 0 || markings.tempos.length > 0 || markings.keys.some((k) => !k.atBracket));
|
|
13
|
+
// Chords and directions float above the first row, and may reach above the system's own top.
|
|
14
|
+
const used = Math.max(markings.reach, markings.bandLift + bands * NOTATION.headroom);
|
|
15
|
+
return system.y + (system.headroom - used) * system.scale;
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ElementBox } from "../layout/elementBoxes.js";
|
|
2
|
+
import type { Page, PlacedSystem } from "../layout/LayoutEngine.js";
|
|
3
|
+
/** A box in a system's layout units, in page-notation px (systems are stacked by `y`, scaled). */
|
|
4
|
+
export declare const onPage: (b: ElementBox, s: Pick<PlacedSystem, "y" | "scale">) => ElementBox;
|
|
5
|
+
/** Every element box of a page, in page-notation px. */
|
|
6
|
+
export declare const pageBoxes: (page: Page) => ElementBox[];
|
|
7
|
+
/** Where an element is drawn: its page and box, or null when it is not on any page. */
|
|
8
|
+
export declare function findBox(pages: readonly Page[], key: string): {
|
|
9
|
+
pageIndex: number;
|
|
10
|
+
box: ElementBox;
|
|
11
|
+
} | null;
|
|
12
|
+
/** Where the chord editor opens for a chord at `at` in a bar, whether or not it has one yet. */
|
|
13
|
+
export declare function chordSlot(pages: readonly Page[], measureId: string, at: number): {
|
|
14
|
+
pageIndex: number;
|
|
15
|
+
box: ElementBox;
|
|
16
|
+
} | null;
|
|
17
|
+
/** The place a syllable of `line` goes under a note, whether or not it has one yet. */
|
|
18
|
+
export declare function lyricSlot(pages: readonly Page[], eventId: string, line: number): {
|
|
19
|
+
pageIndex: number;
|
|
20
|
+
box: ElementBox;
|
|
21
|
+
} | null;
|
|
22
|
+
/** The keys a rubber-band rectangle selects: notes and syllables, or measures if it holds none. */
|
|
23
|
+
export declare function keysInRect(boxes: readonly ElementBox[], rect: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}): string[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { holdsTick } from "../layout/measureSegments.js";
|
|
2
|
+
import { NOTATION } from "../layout/notationMetrics.js";
|
|
3
|
+
import { chordCenter } from "../layout/markings.js";
|
|
4
|
+
import { beatX } from "../layout/systemLayout.js";
|
|
5
|
+
import { eventKey, targetKey } from "./target.js";
|
|
6
|
+
/** A box in a system's layout units, in page-notation px (systems are stacked by `y`, scaled). */
|
|
7
|
+
export const onPage = (b, s) => ({
|
|
8
|
+
key: b.key,
|
|
9
|
+
x: b.x * s.scale,
|
|
10
|
+
y: s.y + b.y * s.scale,
|
|
11
|
+
width: b.width * s.scale,
|
|
12
|
+
height: b.height * s.scale,
|
|
13
|
+
});
|
|
14
|
+
/** Every element box of a page, in page-notation px. */
|
|
15
|
+
export const pageBoxes = (page) => page.systems.flatMap((s) => s.boxes.map((b) => onPage(b, s)));
|
|
16
|
+
/** Where an element is drawn: its page and box, or null when it is not on any page. */
|
|
17
|
+
export function findBox(pages, key) {
|
|
18
|
+
for (const [pageIndex, page] of pages.entries()) {
|
|
19
|
+
const box = pageBoxes(page).find((b) => b.key === key);
|
|
20
|
+
if (box)
|
|
21
|
+
return { pageIndex, box };
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/** Where the chord editor opens for a chord at `at` in a bar, whether or not it has one yet. */
|
|
26
|
+
export function chordSlot(pages, measureId, at) {
|
|
27
|
+
for (const [pageIndex, page] of pages.entries())
|
|
28
|
+
for (const system of page.systems) {
|
|
29
|
+
const bounds = system.measures.find((m) => m.measureId === measureId && holdsTick(m, at));
|
|
30
|
+
if (!bounds)
|
|
31
|
+
continue;
|
|
32
|
+
const width = 72 / system.scale; // the editor keeps its page size at any note size
|
|
33
|
+
const height = 20 / system.scale;
|
|
34
|
+
const x = beatX(bounds, at);
|
|
35
|
+
const slot = {
|
|
36
|
+
key: targetKey({ kind: "chord", measureId, at }),
|
|
37
|
+
x: x - width / 2,
|
|
38
|
+
y: chordCenter(system.headroom) - height / 2,
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
};
|
|
42
|
+
return { pageIndex, box: onPage(slot, system) };
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/** The place a syllable of `line` goes under a note, whether or not it has one yet. */
|
|
47
|
+
export function lyricSlot(pages, eventId, line) {
|
|
48
|
+
const key = eventKey(eventId);
|
|
49
|
+
for (const [pageIndex, page] of pages.entries())
|
|
50
|
+
for (const system of page.systems) {
|
|
51
|
+
const note = system.boxes.find((b) => b.key === key);
|
|
52
|
+
if (!note)
|
|
53
|
+
continue;
|
|
54
|
+
const rowTop = note.y - 2; // event boxes are inset by 2 from the row's top
|
|
55
|
+
const width = 64 / system.scale; // the editor box keeps its page size at any note size
|
|
56
|
+
const slot = {
|
|
57
|
+
key: `l:${eventId}:${line}`,
|
|
58
|
+
x: note.x + note.width / 2 - width / 2,
|
|
59
|
+
y: rowTop + NOTATION.noteRowHeight + line * system.lyricLineHeight,
|
|
60
|
+
width,
|
|
61
|
+
height: system.lyricLineHeight + 4,
|
|
62
|
+
};
|
|
63
|
+
return { pageIndex, box: onPage(slot, system) };
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/** The keys a rubber-band rectangle selects: notes and syllables, or measures if it holds none. */
|
|
68
|
+
export function keysInRect(boxes, rect) {
|
|
69
|
+
const hit = boxes.filter((b) => b.x < rect.x + rect.width &&
|
|
70
|
+
b.x + b.width > rect.x &&
|
|
71
|
+
b.y < rect.y + rect.height &&
|
|
72
|
+
b.y + b.height > rect.y);
|
|
73
|
+
const elements = hit.filter((b) => !b.key.startsWith("m:"));
|
|
74
|
+
return (elements.length ? elements : hit).map((b) => b.key);
|
|
75
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ElementBox } from "../layout/elementBoxes.js";
|
|
2
|
+
import type { Page } from "../layout/LayoutEngine.js";
|
|
3
|
+
/** A vertical line through a whole system (from the top of what it draws), in page-notation px. */
|
|
4
|
+
export type CursorLine = {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
/** What the playback cursor draws on one page. */
|
|
10
|
+
export type CursorMarks = {
|
|
11
|
+
notes: ElementBox[];
|
|
12
|
+
line: CursorLine | null;
|
|
13
|
+
};
|
|
14
|
+
export declare const NO_CURSOR: CursorMarks;
|
|
15
|
+
/**
|
|
16
|
+
* Extra width each side of a playing note's highlight, in layout units (it scales with the note
|
|
17
|
+
* size): wider than the selection box, which hugs the digit.
|
|
18
|
+
*/
|
|
19
|
+
export declare const PLAYING_PAD_X = 4;
|
|
20
|
+
/**
|
|
21
|
+
* Where the playing events are drawn on `page`: a box per note or rest (wider than its selection
|
|
22
|
+
* box), and a line through the system at the event that began most recently (the last of
|
|
23
|
+
* `eventIds`, which are in start order).
|
|
24
|
+
*/
|
|
25
|
+
export declare function cursorMarks(page: Page, eventIds: readonly string[]): CursorMarks;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { drawnTop } from "./drawnTop.js";
|
|
2
|
+
import { onPage } from "./pageBoxes.js";
|
|
3
|
+
import { eventKey } from "./target.js";
|
|
4
|
+
export const NO_CURSOR = { notes: [], line: null };
|
|
5
|
+
/**
|
|
6
|
+
* Extra width each side of a playing note's highlight, in layout units (it scales with the note
|
|
7
|
+
* size): wider than the selection box, which hugs the digit.
|
|
8
|
+
*/
|
|
9
|
+
export const PLAYING_PAD_X = 4;
|
|
10
|
+
/** A box widened by `pad` on each side, keeping its centre. */
|
|
11
|
+
const widened = (box, pad) => ({
|
|
12
|
+
...box,
|
|
13
|
+
x: box.x - pad,
|
|
14
|
+
width: box.width + 2 * pad,
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Where the playing events are drawn on `page`: a box per note or rest (wider than its selection
|
|
18
|
+
* box), and a line through the system at the event that began most recently (the last of
|
|
19
|
+
* `eventIds`, which are in start order).
|
|
20
|
+
*/
|
|
21
|
+
export function cursorMarks(page, eventIds) {
|
|
22
|
+
if (eventIds.length === 0)
|
|
23
|
+
return NO_CURSOR;
|
|
24
|
+
const rank = new Map(eventIds.map((id, i) => [eventKey(id), i]));
|
|
25
|
+
const notes = [];
|
|
26
|
+
let lead = null;
|
|
27
|
+
for (const system of page.systems)
|
|
28
|
+
for (const box of system.boxes) {
|
|
29
|
+
const order = rank.get(box.key);
|
|
30
|
+
if (order === undefined)
|
|
31
|
+
continue;
|
|
32
|
+
const placed = onPage(box, system);
|
|
33
|
+
notes.push(widened(placed, PLAYING_PAD_X * system.scale));
|
|
34
|
+
if (!lead || order > lead.rank) {
|
|
35
|
+
// From where the system's drawing starts (under the beat dot), not from its empty headroom.
|
|
36
|
+
const top = drawnTop(system);
|
|
37
|
+
const line = { x: placed.x + placed.width / 2, y: top, height: system.y + system.height * system.scale - top };
|
|
38
|
+
lead = { rank: order, box: placed, line };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { notes, line: lead?.line ?? null };
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** How much bigger a playing glyph is drawn (it grows around its own centre). */
|
|
2
|
+
export declare const PLAYING_GLYPH_SCALE = 1.15;
|
|
3
|
+
/**
|
|
4
|
+
* A stylesheet that draws the digits and rests of `eventIds` bold and a little bigger, under
|
|
5
|
+
* `scope` (a CSS selector for the notation that is playing: the editor canvas, or one player), by
|
|
6
|
+
* their `data-owner`. The glyph grows around its own centre, so nothing moves, and the SVG stays a
|
|
7
|
+
* pure drawing of the score. Ids only use [A-Za-z0-9_-], so they are safe in a selector; anything
|
|
8
|
+
* else is dropped. Pure.
|
|
9
|
+
*/
|
|
10
|
+
export declare function playingNoteCss(eventIds: readonly string[], scope: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* A stylesheet that draws the chord in effect (`chordKey`, a chord's selection key) bold under
|
|
13
|
+
* `scope`. Keys are "c:<measure id>:<ticks>" with ids from [A-Za-z0-9_-]; anything else is
|
|
14
|
+
* dropped. Pure.
|
|
15
|
+
*/
|
|
16
|
+
export declare function playingChordCss(chordKey: string | null, scope: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The glyphs that show a note's pitch or a rest: what stands out while it plays. */
|
|
2
|
+
const PLAYING_ROLES = ["digit", "rest"];
|
|
3
|
+
/** How much bigger a playing glyph is drawn (it grows around its own centre). */
|
|
4
|
+
export const PLAYING_GLYPH_SCALE = 1.15;
|
|
5
|
+
/**
|
|
6
|
+
* A stylesheet that draws the digits and rests of `eventIds` bold and a little bigger, under
|
|
7
|
+
* `scope` (a CSS selector for the notation that is playing: the editor canvas, or one player), by
|
|
8
|
+
* their `data-owner`. The glyph grows around its own centre, so nothing moves, and the SVG stays a
|
|
9
|
+
* pure drawing of the score. Ids only use [A-Za-z0-9_-], so they are safe in a selector; anything
|
|
10
|
+
* else is dropped. Pure.
|
|
11
|
+
*/
|
|
12
|
+
export function playingNoteCss(eventIds, scope) {
|
|
13
|
+
const safe = eventIds.filter((id) => /^[A-Za-z0-9_-]+$/.test(id));
|
|
14
|
+
if (safe.length === 0)
|
|
15
|
+
return "";
|
|
16
|
+
const selectors = safe.flatMap((id) => PLAYING_ROLES.map((role) => `${scope} [data-role="${role}"][data-owner="${id}"]`));
|
|
17
|
+
const look = [
|
|
18
|
+
"font-weight:700",
|
|
19
|
+
"transform-box:fill-box",
|
|
20
|
+
"transform-origin:center",
|
|
21
|
+
`transform:scale(${PLAYING_GLYPH_SCALE})`,
|
|
22
|
+
].join(";");
|
|
23
|
+
return `${selectors.join(",")}{${look}}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A stylesheet that draws the chord in effect (`chordKey`, a chord's selection key) bold under
|
|
27
|
+
* `scope`. Keys are "c:<measure id>:<ticks>" with ids from [A-Za-z0-9_-]; anything else is
|
|
28
|
+
* dropped. Pure.
|
|
29
|
+
*/
|
|
30
|
+
export function playingChordCss(chordKey, scope) {
|
|
31
|
+
if (!chordKey || !/^c:[A-Za-z0-9_-]+:\d+$/.test(chordKey))
|
|
32
|
+
return "";
|
|
33
|
+
return `${scope} [data-role="chord"][data-owner="${chordKey}"]{font-weight:700}`;
|
|
34
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PartTone } from "../model/partColors.js";
|
|
2
|
+
/** How a playing note is marked: its part's tone (a color, or light blue) while heard, light gray while muted. */
|
|
3
|
+
export type NoteTone = PartTone | "muted";
|
|
4
|
+
/**
|
|
5
|
+
* The tone of each playing note, by selection key: its part's tone when the part is heard (the
|
|
6
|
+
* mix), "muted" when it is not. Notes whose part is unknown are left out. Pure.
|
|
7
|
+
*/
|
|
8
|
+
export declare function playingTones(playing: readonly string[], heard: readonly string[], partOf: ReadonlyMap<string, string>, colors: Readonly<Record<string, PartTone>>): Map<string, NoteTone>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { eventKey } from "./target.js";
|
|
2
|
+
/**
|
|
3
|
+
* The tone of each playing note, by selection key: its part's tone when the part is heard (the
|
|
4
|
+
* mix), "muted" when it is not. Notes whose part is unknown are left out. Pure.
|
|
5
|
+
*/
|
|
6
|
+
export function playingTones(playing, heard, partOf, colors) {
|
|
7
|
+
const heardIds = new Set(heard);
|
|
8
|
+
const tones = new Map();
|
|
9
|
+
for (const eventId of playing) {
|
|
10
|
+
const partId = partOf.get(eventId);
|
|
11
|
+
if (partId === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
tones.set(eventKey(eventId), heardIds.has(eventId) ? colors[partId] : "muted");
|
|
14
|
+
}
|
|
15
|
+
return tones;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DirectionType } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* What can be selected on the canvas. Selection lives in the editor session (never inside the
|
|
4
|
+
* score), as string keys so a set of them is cheap to compare and the SVG can carry one in a
|
|
5
|
+
* `data-target` attribute. Ids only use [A-Za-z0-9_-], so ":" is a safe separator.
|
|
6
|
+
*/
|
|
7
|
+
export type SelectionTarget = {
|
|
8
|
+
kind: "event";
|
|
9
|
+
eventId: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "lyric";
|
|
12
|
+
eventId: string;
|
|
13
|
+
line: number;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "measure";
|
|
16
|
+
partId: string;
|
|
17
|
+
measureId: string;
|
|
18
|
+
}
|
|
19
|
+
/** A chord symbol: its bar and its position in ticks from the bar's start. */
|
|
20
|
+
| {
|
|
21
|
+
kind: "chord";
|
|
22
|
+
measureId: string;
|
|
23
|
+
at: number;
|
|
24
|
+
}
|
|
25
|
+
/** A direction above the system (ADR 0011): its bar, position and type (one of each per position). */
|
|
26
|
+
| {
|
|
27
|
+
kind: "direction";
|
|
28
|
+
measureId: string;
|
|
29
|
+
at: number;
|
|
30
|
+
type: DirectionType;
|
|
31
|
+
};
|
|
32
|
+
/** A syllable: its note and lyric line. */
|
|
33
|
+
export type LyricTarget = {
|
|
34
|
+
eventId: string;
|
|
35
|
+
line: number;
|
|
36
|
+
};
|
|
37
|
+
export declare function targetKey(target: SelectionTarget): string;
|
|
38
|
+
export declare function parseTarget(key: string): SelectionTarget | null;
|
|
39
|
+
/** The note or rest a target sits on (a syllable's note); null for a measure or a chord. */
|
|
40
|
+
export declare const eventIdOf: (target: SelectionTarget) => string | null;
|
|
41
|
+
export declare const eventKey: (eventId: string) => string;
|
|
42
|
+
/** The event ids among selection keys (lyrics count as their note). */
|
|
43
|
+
export declare function selectedEventIds(selection: readonly string[]): string[];
|
|
44
|
+
/** The selected syllables: their note and lyric line. */
|
|
45
|
+
export declare const selectedLyrics: (selection: readonly string[]) => LyricTarget[];
|
|
46
|
+
/** The last selected target: where input goes and what the properties panel shows. */
|
|
47
|
+
export declare const focusTarget: (selection: readonly string[]) => SelectionTarget | null;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const CODECS = {
|
|
2
|
+
event: {
|
|
3
|
+
prefix: "e",
|
|
4
|
+
encode: (t) => [t.eventId],
|
|
5
|
+
decode: ([eventId]) => (eventId ? { kind: "event", eventId } : null),
|
|
6
|
+
},
|
|
7
|
+
lyric: {
|
|
8
|
+
prefix: "l",
|
|
9
|
+
encode: (t) => [t.eventId, String(t.line)],
|
|
10
|
+
decode: ([eventId, line]) => eventId && /^\d+$/.test(line ?? "")
|
|
11
|
+
? { kind: "lyric", eventId, line: Number(line) }
|
|
12
|
+
: null,
|
|
13
|
+
},
|
|
14
|
+
measure: {
|
|
15
|
+
prefix: "m",
|
|
16
|
+
encode: (t) => [t.partId, t.measureId],
|
|
17
|
+
decode: ([partId, measureId]) => partId && measureId ? { kind: "measure", partId, measureId } : null,
|
|
18
|
+
},
|
|
19
|
+
chord: {
|
|
20
|
+
prefix: "c",
|
|
21
|
+
encode: (t) => [t.measureId, String(t.at)],
|
|
22
|
+
decode: ([measureId, at]) => measureId && /^\d+$/.test(at ?? "") ? { kind: "chord", measureId, at: Number(at) } : null,
|
|
23
|
+
},
|
|
24
|
+
direction: {
|
|
25
|
+
prefix: "d",
|
|
26
|
+
encode: (t) => [t.measureId, String(t.at), t.type],
|
|
27
|
+
decode: ([measureId, at, type]) => measureId && /^\d+$/.test(at ?? "") && isDirectionType(type)
|
|
28
|
+
? { kind: "direction", measureId, at: Number(at), type }
|
|
29
|
+
: null,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const DIRECTION_TYPES = ["dynamic", "text", "hairpin"];
|
|
33
|
+
const isDirectionType = (type) => DIRECTION_TYPES.includes(type);
|
|
34
|
+
export function targetKey(target) {
|
|
35
|
+
const codec = CODECS[target.kind];
|
|
36
|
+
return [codec.prefix, ...codec.encode(target)].join(":");
|
|
37
|
+
}
|
|
38
|
+
export function parseTarget(key) {
|
|
39
|
+
const [prefix, ...rest] = key.split(":");
|
|
40
|
+
const codec = Object.values(CODECS).find((c) => c.prefix === prefix);
|
|
41
|
+
return codec ? codec.decode(rest) : null;
|
|
42
|
+
}
|
|
43
|
+
/** The note or rest a target sits on (a syllable's note); null for a measure or a chord. */
|
|
44
|
+
export const eventIdOf = (target) => "eventId" in target ? target.eventId : null;
|
|
45
|
+
export const eventKey = (eventId) => targetKey({ kind: "event", eventId });
|
|
46
|
+
/** The event ids among selection keys (lyrics count as their note). */
|
|
47
|
+
export function selectedEventIds(selection) {
|
|
48
|
+
const ids = new Set();
|
|
49
|
+
for (const key of selection) {
|
|
50
|
+
const target = parseTarget(key);
|
|
51
|
+
const eventId = target && eventIdOf(target);
|
|
52
|
+
if (eventId)
|
|
53
|
+
ids.add(eventId);
|
|
54
|
+
}
|
|
55
|
+
return [...ids];
|
|
56
|
+
}
|
|
57
|
+
/** The selected syllables: their note and lyric line. */
|
|
58
|
+
export const selectedLyrics = (selection) => selection.flatMap((key) => {
|
|
59
|
+
const target = parseTarget(key);
|
|
60
|
+
return target?.kind === "lyric" ? [{ eventId: target.eventId, line: target.line }] : [];
|
|
61
|
+
});
|
|
62
|
+
/** The last selected target: where input goes and what the properties panel shows. */
|
|
63
|
+
export const focusTarget = (selection) => selection.length ? parseTarget(selection[selection.length - 1]) : null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PageMetrics } from "../geometry/metrics.js";
|
|
2
|
+
import type { PageSetup } from "../geometry/pageSetup.js";
|
|
3
|
+
import type { TextPrimitive } from "../rendering/primitives.js";
|
|
4
|
+
import { type TextContext } from "../text/headerFooter.js";
|
|
5
|
+
/** Title, subtitle, info lines (left) and credits (right) at the top of page 1. */
|
|
6
|
+
export declare function headingText(setup: PageSetup, m: PageMetrics, title: string, subtitle: string, context: TextContext): TextPrimitive[];
|
|
7
|
+
/** Header and footer text in the margins, and the running title on pages 2+. */
|
|
8
|
+
export declare function marginText(setup: PageSetup, m: PageMetrics, context: TextContext, firstPage: boolean): TextPrimitive[];
|