@ac-kit/media-music-notation 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/CHANGELOG.md +24 -0
- package/LICENSE +28 -0
- package/README.md +43 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/infer/_beat-grid.d.ts +21 -0
- package/dist/infer/_beat-grid.d.ts.map +1 -0
- package/dist/infer/_beat-grid.js +72 -0
- package/dist/infer/_beat-grid.js.map +1 -0
- package/dist/infer/_voices.d.ts +16 -0
- package/dist/infer/_voices.d.ts.map +1 -0
- package/dist/infer/_voices.js +36 -0
- package/dist/infer/_voices.js.map +1 -0
- package/dist/infer/infer-notation.d.ts +50 -0
- package/dist/infer/infer-notation.d.ts.map +1 -0
- package/dist/infer/infer-notation.js +488 -0
- package/dist/infer/infer-notation.js.map +1 -0
- package/dist/key/estimate-key.d.ts +25 -0
- package/dist/key/estimate-key.d.ts.map +1 -0
- package/dist/key/estimate-key.js +51 -0
- package/dist/key/estimate-key.js.map +1 -0
- package/package.json +68 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @ac-kit/media-music-notation
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8ee20f3: First release of `@ac-kit/media-music-notation`: `inferNotation` writes a song
|
|
8
|
+
without notation, such as a MIDI file, as a `@ac-kit/model-notation` score —
|
|
9
|
+
quantized note values and tuplets, chords, voices, ties, rests, beams, clefs,
|
|
10
|
+
key and pitch spelling — and `estimateKey` finds the key of a passage.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [47e39a2]
|
|
15
|
+
- Updated dependencies [8ee20f3]
|
|
16
|
+
- Updated dependencies [8ee20f3]
|
|
17
|
+
- Updated dependencies [8ee20f3]
|
|
18
|
+
- Updated dependencies [8ee20f3]
|
|
19
|
+
- @ac-kit/core@0.6.0
|
|
20
|
+
- @ac-kit/math-integer@0.3.0
|
|
21
|
+
- @ac-kit/math-stats@0.2.0
|
|
22
|
+
- @ac-kit/model-music@0.4.0
|
|
23
|
+
- @ac-kit/model-notation@0.1.0
|
|
24
|
+
- @ac-kit/algo@0.2.3
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/media-music-notation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A song that has no score — a MIDI file, a recorded performance — written as one:
|
|
4
|
+
the `@ac-kit/model-notation` `Score` a notation program would show for it.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { parseMidiFile } from "@ac-kit/format-midi";
|
|
8
|
+
import { composeMidiSong } from "@ac-kit/format-midi/song";
|
|
9
|
+
import { printMusicXml } from "@ac-kit/format-musicxml";
|
|
10
|
+
import { inferNotation } from "@ac-kit/media-music-notation";
|
|
11
|
+
|
|
12
|
+
const score = inferNotation(composeMidiSong(parseMidiFile(bytes)));
|
|
13
|
+
const musicXml = printMusicXml(score); // for any MusicXML renderer
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What it exposes
|
|
17
|
+
|
|
18
|
+
- `inferNotation` — the score a `Song` would be written as. Onsets and
|
|
19
|
+
releases snap beat by beat to the plainest grid that fits (16ths, eighth
|
|
20
|
+
triplets, 32nds, 16th triplets); notes struck and released together form
|
|
21
|
+
chords; overlapping chords go into separate voices; durations become tied
|
|
22
|
+
note values by the engraving rules; gaps become rests; eighths and shorter
|
|
23
|
+
beam by beat; pitches are spelled by key and context; each staff gets a
|
|
24
|
+
clef. Options regroup notes into parts and staves, such as a MIDI file's two
|
|
25
|
+
hand tracks into one piano part.
|
|
26
|
+
- `estimateKey` — the major or minor key of a passage, by the
|
|
27
|
+
Krumhansl–Schmuckler algorithm, for a source that gives none.
|
|
28
|
+
|
|
29
|
+
The rules it applies — the beats of a meter, splitting a duration into note
|
|
30
|
+
values, beaming — are `@ac-kit/model-notation`'s; spelling a pitch on the line
|
|
31
|
+
of fifths is `@ac-kit/model-music`'s. This package makes the guesses those
|
|
32
|
+
rules need as input: which grid a played note meant, which voice it belongs to,
|
|
33
|
+
which key the passage is in.
|
|
34
|
+
|
|
35
|
+
Portable: no Node.js built-ins.
|
|
36
|
+
|
|
37
|
+
See the
|
|
38
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/media-music-notation/)
|
|
39
|
+
for the full reference.
|
|
40
|
+
|
|
41
|
+
## Further reading
|
|
42
|
+
|
|
43
|
+
- David Temperley, _The Cognition of Basic Musical Structures_ (MIT Press,
|
|
44
|
+
2001) — the line-of-fifths spelling model and the key-finding background.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** A beat of the whole song, in output divisions. */
|
|
2
|
+
export type GridBeat_ = {
|
|
3
|
+
/** Index of its measure. */
|
|
4
|
+
measure: number;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
};
|
|
8
|
+
/** Whether a grid unit divides beats into triplets. */
|
|
9
|
+
export declare function isTripletUnit_(unit: number): boolean;
|
|
10
|
+
/** The beat a position falls in: the last starting at or before it. */
|
|
11
|
+
export declare function beatIndexOf_(beats: readonly GridBeat_[], position: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Each beat's grid unit: the one whose squared snapping error over the onsets
|
|
14
|
+
* and ends in the beat, plus its complexity, is least.
|
|
15
|
+
*/
|
|
16
|
+
export declare function chooseBeatUnits_(beats: readonly GridBeat_[], onsets: readonly number[], ends: readonly number[]): number[];
|
|
17
|
+
/** An onset on its beat's grid; one just before a beat lands on it. */
|
|
18
|
+
export declare function snapOnset_(beats: readonly GridBeat_[], units: readonly number[], position: number): number;
|
|
19
|
+
/** An end on its beat's grid; one just after a beat lands on it. */
|
|
20
|
+
export declare function snapEnd_(beats: readonly GridBeat_[], units: readonly number[], position: number): number;
|
|
21
|
+
//# sourceMappingURL=_beat-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_beat-grid.d.ts","sourceRoot":"","sources":["../../src/infer/_beat-grid.ts"],"names":[],"mappings":"AAIA,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG;IACvB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAaF,uDAAuD;AACvD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAC3B,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,QAAQ,EAAE,MAAM,GACd,MAAM,CAKR;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,IAAI,EAAE,SAAS,MAAM,EAAE,GACrB,MAAM,EAAE,CAoCV;AAED,uEAAuE;AACvE,wBAAgB,UAAU,CACzB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,GACd,MAAM,CAIR;AAED,oEAAoE;AACpE,wBAAgB,QAAQ,CACvB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,GACd,MAAM,CAIR"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { bisectRight } from "@ac-kit/algo";
|
|
2
|
+
import { clamp } from "@ac-kit/core";
|
|
3
|
+
import { numberGcd } from "@ac-kit/math-integer";
|
|
4
|
+
// Grid units in 48ths of a quarter note, from the plainest: 16th, eighth
|
|
5
|
+
// triplet, 32nd, 16th triplet. The nth costs `n × COMPLEXITY_COST_` in squared
|
|
6
|
+
// quarter notes: a 16th played up to a 17th of a quarter off still reads as a
|
|
7
|
+
// 16th, and an exact eighth triplet, a 12th off the 16th grid, as a triplet.
|
|
8
|
+
const UNITS_ = [12, 16, 6, 8];
|
|
9
|
+
const COMPLEXITY_COST_ = 0.003;
|
|
10
|
+
// An end weighs less than an onset: players release notes loosely.
|
|
11
|
+
const END_WEIGHT_ = 0.25;
|
|
12
|
+
// An onset this early still belongs to the next beat: a 16th of a quarter.
|
|
13
|
+
const EARLY_ONSET_ = 3;
|
|
14
|
+
/** Whether a grid unit divides beats into triplets. */
|
|
15
|
+
export function isTripletUnit_(unit) {
|
|
16
|
+
return unit === 16 || unit === 8;
|
|
17
|
+
}
|
|
18
|
+
/** The beat a position falls in: the last starting at or before it. */
|
|
19
|
+
export function beatIndexOf_(beats, position) {
|
|
20
|
+
return Math.max(0, bisectRight(beats, position, (beat, value) => beat.start - value) - 1);
|
|
21
|
+
}
|
|
22
|
+
const snap_ = (beat, unit, position) => clamp(beat.start + Math.round((position - beat.start) / unit) * unit, beat.start, beat.end);
|
|
23
|
+
/**
|
|
24
|
+
* Each beat's grid unit: the one whose squared snapping error over the onsets
|
|
25
|
+
* and ends in the beat, plus its complexity, is least.
|
|
26
|
+
*/
|
|
27
|
+
export function chooseBeatUnits_(beats, onsets, ends) {
|
|
28
|
+
const times = beats.map(() => []);
|
|
29
|
+
for (const position of onsets) {
|
|
30
|
+
times[beatIndexOf_(beats, position + EARLY_ONSET_)].push({
|
|
31
|
+
position,
|
|
32
|
+
weight: 1,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
for (const position of ends) {
|
|
36
|
+
times[beatIndexOf_(beats, position - EARLY_ONSET_)].push({
|
|
37
|
+
position,
|
|
38
|
+
weight: END_WEIGHT_,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return beats.map((beat, index) => {
|
|
42
|
+
const length = beat.end - beat.start;
|
|
43
|
+
const units = UNITS_.filter((unit) => length % unit === 0);
|
|
44
|
+
if (units.length === 0) {
|
|
45
|
+
return numberGcd(length, 12);
|
|
46
|
+
}
|
|
47
|
+
let best = units[0];
|
|
48
|
+
let bestCost = Infinity;
|
|
49
|
+
for (const unit of units) {
|
|
50
|
+
let cost = (UNITS_.indexOf(unit) + 1) * COMPLEXITY_COST_;
|
|
51
|
+
for (const { position, weight } of times[index]) {
|
|
52
|
+
cost += weight * ((position - snap_(beat, unit, position)) / 48) ** 2;
|
|
53
|
+
}
|
|
54
|
+
if (cost < bestCost) {
|
|
55
|
+
best = unit;
|
|
56
|
+
bestCost = cost;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return best;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** An onset on its beat's grid; one just before a beat lands on it. */
|
|
63
|
+
export function snapOnset_(beats, units, position) {
|
|
64
|
+
const index = beatIndexOf_(beats, position + EARLY_ONSET_);
|
|
65
|
+
return snap_(beats[index], units[index], position);
|
|
66
|
+
}
|
|
67
|
+
/** An end on its beat's grid; one just after a beat lands on it. */
|
|
68
|
+
export function snapEnd_(beats, units, position) {
|
|
69
|
+
const index = beatIndexOf_(beats, position - EARLY_ONSET_);
|
|
70
|
+
return snap_(beats[index], units[index], position);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=_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EAAE,MAAM,EAAE,IAAI,KAAK,CAAC,KAAK,CAAE,EAAE,CAAC;gBAClD,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YACvE,CAAC;YACD,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;gBACrB,IAAI,GAAG,IAAI,CAAC;gBACZ,QAAQ,GAAG,IAAI,CAAC;YACjB,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,UAAU,CACzB,KAA2B,EAC3B,KAAwB,EACxB,QAAgB;IAEhB,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,YAAY,CAAC,CAAC;IAE3D,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,KAAK,CAAE,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,QAAQ,CACvB,KAA2B,EAC3B,KAAwB,EACxB,QAAgB;IAEhB,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,YAAY,CAAC,CAAC;IAE3D,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,KAAK,CAAE,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Chords of one staff struck together and released together. */
|
|
2
|
+
export type VoiceChord_ = {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
/** Indices into the song's notes, from the lowest pitch. */
|
|
6
|
+
notes: number[];
|
|
7
|
+
/** The highest pitch. */
|
|
8
|
+
top: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Separates a staff's chords into voices, each without overlap: in order of
|
|
12
|
+
* onset, highest first, each chord goes to the free voice whose last chord is
|
|
13
|
+
* nearest in pitch, or opens a new one.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assignVoices_(chords: readonly VoiceChord_[]): VoiceChord_[][];
|
|
16
|
+
//# sourceMappingURL=_voices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_voices.d.ts","sourceRoot":"","sources":["../../src/infer/_voices.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAMF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,EAAE,EAAE,CA6B7E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A chord overlapping a voice's last one by a 16th or less still continues
|
|
2
|
+
// that voice, cutting the last one short: legato playing, not a second voice.
|
|
3
|
+
const LEGATO_OVERLAP_ = 12;
|
|
4
|
+
/**
|
|
5
|
+
* Separates a staff's chords into voices, each without overlap: in order of
|
|
6
|
+
* onset, highest first, each chord goes to the free voice whose last chord is
|
|
7
|
+
* nearest in pitch, or opens a new one.
|
|
8
|
+
*/
|
|
9
|
+
export function assignVoices_(chords) {
|
|
10
|
+
const voices = [];
|
|
11
|
+
const ordered = chords.toSorted((left, right) => left.start - right.start || right.top - left.top);
|
|
12
|
+
for (const chord of ordered) {
|
|
13
|
+
let best;
|
|
14
|
+
let bestDistance = Infinity;
|
|
15
|
+
for (const voice of voices) {
|
|
16
|
+
const last = voice.at(-1);
|
|
17
|
+
const free = last.end <= chord.start ||
|
|
18
|
+
(last.start < chord.start && last.end - chord.start <= LEGATO_OVERLAP_);
|
|
19
|
+
const distance = Math.abs(last.top - chord.top);
|
|
20
|
+
if (free && distance < bestDistance) {
|
|
21
|
+
best = voice;
|
|
22
|
+
bestDistance = distance;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (best === undefined) {
|
|
26
|
+
voices.push([chord]);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const last = best.at(-1);
|
|
30
|
+
last.end = Math.min(last.end, chord.start);
|
|
31
|
+
best.push(chord);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return voices;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=_voices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_voices.js","sourceRoot":"","sources":["../../src/infer/_voices.ts"],"names":[],"mappings":"AAUA,2EAA2E;AAC3E,8EAA8E;AAC9E,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAA8B;IAC3D,MAAM,MAAM,GAAoB,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAC9B,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CACjE,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,IAA+B,CAAC;QACpC,IAAI,YAAY,GAAG,QAAQ,CAAC;QAC5B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;YAC3B,MAAM,IAAI,GACT,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK;gBACvB,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,IAAI,eAAe,CAAC,CAAC;YACzE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAChD,IAAI,IAAI,IAAI,QAAQ,GAAG,YAAY,EAAE,CAAC;gBACrC,IAAI,GAAG,KAAK,CAAC;gBACb,YAAY,GAAG,QAAQ,CAAC;YACzB,CAAC;QACF,CAAC;QACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACtB,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import { type Song, type SongNote, type SongPart } from "@ac-kit/model-music";
|
|
3
|
+
import { type Score } from "@ac-kit/model-notation";
|
|
4
|
+
/** Where a note is written: a part, by index, and a staff of it, from 1. */
|
|
5
|
+
export type NotePlace = {
|
|
6
|
+
part: number;
|
|
7
|
+
staff: number;
|
|
8
|
+
};
|
|
9
|
+
/** How {@link inferNotation} lays a song's notes out. */
|
|
10
|
+
export type InferNotationOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* The parts to write, when `placeOf` regroups the song's; the song's by
|
|
13
|
+
* default.
|
|
14
|
+
*/
|
|
15
|
+
parts?: readonly SongPart[] | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Where a note is written. By default in its own part, on its own staff, or,
|
|
18
|
+
* when it has none on a part of two staves or more, on the upper staff from
|
|
19
|
+
* middle C up and the lower one below.
|
|
20
|
+
*/
|
|
21
|
+
placeOf?: Callable<[note: SongNote], NotePlace> | undefined;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The score a song would be written as, for a song that sounds but has no
|
|
25
|
+
* notation — a MIDI file:
|
|
26
|
+
*
|
|
27
|
+
* - Onsets and releases snap, beat by beat, to the plainest grid that fits:
|
|
28
|
+
* 16ths, eighth triplets, 32nds or 16th triplets.
|
|
29
|
+
* - Notes of a staff struck and released together form chords, and chords that
|
|
30
|
+
* overlap go into separate voices, by nearest pitch.
|
|
31
|
+
* - Durations become tied note values by the engraving rules (`splitNoteValues`),
|
|
32
|
+
* gaps become rests, and eighths and shorter beam by beat (`voiceBeams`).
|
|
33
|
+
* - Pitches are spelled on the line of fifths around the key and the passage
|
|
34
|
+
* (`spellPitch`); the key is the song's, else {@link estimateKey}'s.
|
|
35
|
+
* - Each staff gets a treble or bass clef by its median pitch; measures, meters,
|
|
36
|
+
* tempos, rehearsal marks, pedals and lyrics come from the song, and a
|
|
37
|
+
* dynamic from each measure's mean loudness when it changes.
|
|
38
|
+
*
|
|
39
|
+
* Positions count 48 divisions per quarter note. A note keeps its spelling and
|
|
40
|
+
* fingering when the song gives them, and a grace note becomes a grace chord
|
|
41
|
+
* before the chord it leads to; the song's own voices are not read. The result
|
|
42
|
+
* plays back, through `composeScoreSong`, as the quantized song.
|
|
43
|
+
*
|
|
44
|
+
* Time O(n log n + n × m) in the notes and measures. Memory O(n + m).
|
|
45
|
+
*
|
|
46
|
+
* @throws {RangeError} When `placeOf` gives a part or staff that does not
|
|
47
|
+
* exist.
|
|
48
|
+
*/
|
|
49
|
+
export declare function inferNotation(song: Song, options?: InferNotationOptions): Score;
|
|
50
|
+
//# sourceMappingURL=infer-notation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-notation.d.ts","sourceRoot":"","sources":["../../src/infer/infer-notation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAMN,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIN,KAAK,KAAK,EAYV,MAAM,wBAAwB,CAAC;AAahC,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,yDAAyD;AACzD,MAAM,MAAM,oBAAoB,GAAG;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,QAAQ,EAAE,GAAG,SAAS,CAAC;IACxC;;;;OAIG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC;CAC5D,CAAC;AAWF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,oBAAoB,GAC5B,KAAK,CA0ZP"}
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { bisectRight } from "@ac-kit/algo";
|
|
2
|
+
import { mean, median } from "@ac-kit/math-stats";
|
|
3
|
+
import { dynamicOfLoudness, keyCenterOnLineOfFifths, lineOfFifthsPosition, spellPitch, } from "@ac-kit/model-music";
|
|
4
|
+
import { meterBeats, noteValueOfQuarters, splitNoteValues, voiceBeams, } from "@ac-kit/model-notation";
|
|
5
|
+
import { estimateKey } from "../key/estimate-key.js";
|
|
6
|
+
import { beatIndexOf_, chooseBeatUnits_, isTripletUnit_, snapEnd_, snapOnset_, } from "./_beat-grid.js";
|
|
7
|
+
import { assignVoices_ } from "./_voices.js";
|
|
8
|
+
// 48 per quarter counts every grid: 16ths, 32nds, eighth and 16th triplets.
|
|
9
|
+
const DIVISIONS_ = 48;
|
|
10
|
+
// How fast the spelling centre follows the passage away from the key's: the
|
|
11
|
+
// weight of each new note in the running average.
|
|
12
|
+
const SPELLING_MEMORY_ = 0.3;
|
|
13
|
+
// How far a lyric may sit from the chord it belongs to: a 16th.
|
|
14
|
+
const LYRIC_REACH_ = 12;
|
|
15
|
+
const C_MAJOR_ = { fifths: 0, mode: "major" };
|
|
16
|
+
/**
|
|
17
|
+
* The score a song would be written as, for a song that sounds but has no
|
|
18
|
+
* notation — a MIDI file:
|
|
19
|
+
*
|
|
20
|
+
* - Onsets and releases snap, beat by beat, to the plainest grid that fits:
|
|
21
|
+
* 16ths, eighth triplets, 32nds or 16th triplets.
|
|
22
|
+
* - Notes of a staff struck and released together form chords, and chords that
|
|
23
|
+
* overlap go into separate voices, by nearest pitch.
|
|
24
|
+
* - Durations become tied note values by the engraving rules (`splitNoteValues`),
|
|
25
|
+
* gaps become rests, and eighths and shorter beam by beat (`voiceBeams`).
|
|
26
|
+
* - Pitches are spelled on the line of fifths around the key and the passage
|
|
27
|
+
* (`spellPitch`); the key is the song's, else {@link estimateKey}'s.
|
|
28
|
+
* - Each staff gets a treble or bass clef by its median pitch; measures, meters,
|
|
29
|
+
* tempos, rehearsal marks, pedals and lyrics come from the song, and a
|
|
30
|
+
* dynamic from each measure's mean loudness when it changes.
|
|
31
|
+
*
|
|
32
|
+
* Positions count 48 divisions per quarter note. A note keeps its spelling and
|
|
33
|
+
* fingering when the song gives them, and a grace note becomes a grace chord
|
|
34
|
+
* before the chord it leads to; the song's own voices are not read. The result
|
|
35
|
+
* plays back, through `composeScoreSong`, as the quantized song.
|
|
36
|
+
*
|
|
37
|
+
* Time O(n log n + n × m) in the notes and measures. Memory O(n + m).
|
|
38
|
+
*
|
|
39
|
+
* @throws {RangeError} When `placeOf` gives a part or staff that does not
|
|
40
|
+
* exist.
|
|
41
|
+
*/
|
|
42
|
+
export function inferNotation(song, options) {
|
|
43
|
+
const scale = DIVISIONS_ / song.tempoMap.divisionsPerQuarterNote;
|
|
44
|
+
const toOutput = (division) => Math.round(division * scale);
|
|
45
|
+
const parts = options?.parts ?? song.parts;
|
|
46
|
+
const placeOf = options?.placeOf ??
|
|
47
|
+
((note) => {
|
|
48
|
+
const staves = parts[note.part]?.staves ?? 1;
|
|
49
|
+
return {
|
|
50
|
+
part: note.part,
|
|
51
|
+
staff: note.staff ?? (staves >= 2 && note.pitch < 60 ? 2 : 1),
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
// Measures and their beats, in output divisions.
|
|
55
|
+
const measureStarts = song.measures.map(({ startDivision }) => toOutput(startDivision));
|
|
56
|
+
const measureEnds = song.measures.map(({ endDivision }) => toOutput(endDivision));
|
|
57
|
+
const measureBeats = song.measures.map((measure, index) => meterBeats(measure, measureEnds[index] - measureStarts[index], DIVISIONS_));
|
|
58
|
+
const gridBeats = [];
|
|
59
|
+
const firstBeatOf = [];
|
|
60
|
+
for (const [index, beats] of measureBeats.entries()) {
|
|
61
|
+
firstBeatOf.push(gridBeats.length);
|
|
62
|
+
for (const beat of beats) {
|
|
63
|
+
const start = measureStarts[index] + beat.offsetDivisions;
|
|
64
|
+
gridBeats.push({
|
|
65
|
+
measure: index,
|
|
66
|
+
start,
|
|
67
|
+
end: start + beat.durationDivisions,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const songEnd = measureEnds.at(-1) ?? 0;
|
|
72
|
+
const measureOf = (position) => Math.max(0, bisectRight(measureStarts, position, (start, value) => start - value) - 1);
|
|
73
|
+
// Place, quantize and chord every staff's notes.
|
|
74
|
+
const places = song.notes.map((note) => {
|
|
75
|
+
const place = placeOf(note);
|
|
76
|
+
const part = parts[place.part];
|
|
77
|
+
if (part === undefined ||
|
|
78
|
+
!Number.isInteger(place.staff) ||
|
|
79
|
+
place.staff < 1 ||
|
|
80
|
+
place.staff > part.staves) {
|
|
81
|
+
throw new RangeError(`no staff ${place.staff} of part ${place.part}`);
|
|
82
|
+
}
|
|
83
|
+
return place;
|
|
84
|
+
});
|
|
85
|
+
const starts = Array.from({ length: song.notes.length });
|
|
86
|
+
const staffUnits = parts.map((part) => Array.from({ length: part.staves }, () => []));
|
|
87
|
+
const staffVoices = parts.map((part) => Array.from({ length: part.staves }, () => []));
|
|
88
|
+
// Grace chords, by the index of the voice they lead into.
|
|
89
|
+
const staffGraces = parts.map((part) => Array.from({ length: part.staves }, () => []));
|
|
90
|
+
for (const [partIndex, part] of parts.entries()) {
|
|
91
|
+
for (let staff = 1; staff <= part.staves; staff++) {
|
|
92
|
+
const indices = song.notes.flatMap((_note, index) => places[index].part === partIndex && places[index].staff === staff
|
|
93
|
+
? [index]
|
|
94
|
+
: []);
|
|
95
|
+
const units = chooseBeatUnits_(gridBeats, indices.map((index) => song.notes[index].startDivision * scale), indices.map((index) => song.notes[index].endDivision * scale));
|
|
96
|
+
const chords = new Map();
|
|
97
|
+
for (const index of indices) {
|
|
98
|
+
const note = song.notes[index];
|
|
99
|
+
let start = snapOnset_(gridBeats, units, note.startDivision * scale);
|
|
100
|
+
let end = note.grace
|
|
101
|
+
? start
|
|
102
|
+
: snapEnd_(gridBeats, units, note.endDivision * scale);
|
|
103
|
+
if (end <= start && note.grace !== true) {
|
|
104
|
+
end = start + units[beatIndexOf_(gridBeats, start)];
|
|
105
|
+
if (end > songEnd) {
|
|
106
|
+
start -= end - songEnd;
|
|
107
|
+
end = songEnd;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
starts[index] = start;
|
|
111
|
+
const key = `${start}:${end}`;
|
|
112
|
+
const chord = chords.get(key) ?? {
|
|
113
|
+
start,
|
|
114
|
+
end,
|
|
115
|
+
notes: [],
|
|
116
|
+
top: -Infinity,
|
|
117
|
+
};
|
|
118
|
+
chords.set(key, chord);
|
|
119
|
+
if (!chord.notes.some((other) => song.notes[other].pitch === note.pitch)) {
|
|
120
|
+
chord.notes.push(index);
|
|
121
|
+
chord.top = Math.max(chord.top, note.pitch);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const chord of chords.values()) {
|
|
125
|
+
chord.notes.sort((left, right) => song.notes[left].pitch - song.notes[right].pitch);
|
|
126
|
+
}
|
|
127
|
+
const graces = [...chords.values()].filter(({ start, end }) => start === end);
|
|
128
|
+
const voices = assignVoices_([...chords.values()].filter(({ start, end }) => start < end));
|
|
129
|
+
const gracesByVoice = voices.map(() => []);
|
|
130
|
+
for (const grace of graces) {
|
|
131
|
+
const voice = voices.findIndex((chordsOfVoice) => chordsOfVoice.some(({ start }) => start === grace.start));
|
|
132
|
+
(gracesByVoice[Math.max(0, voice)] ??= []).push(grace);
|
|
133
|
+
}
|
|
134
|
+
staffUnits[partIndex][staff - 1] = units;
|
|
135
|
+
staffVoices[partIndex][staff - 1] = voices;
|
|
136
|
+
staffGraces[partIndex][staff - 1] = gracesByVoice;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Keys, and each note's spelling.
|
|
140
|
+
const keySignatures = song.keySignatures.length > 0
|
|
141
|
+
? song.keySignatures
|
|
142
|
+
: (() => {
|
|
143
|
+
const estimated = estimateKey(song.notes.flatMap((note, index) => parts[places[index].part].percussion
|
|
144
|
+
? []
|
|
145
|
+
: [
|
|
146
|
+
{
|
|
147
|
+
pitch: note.pitch,
|
|
148
|
+
duration: note.endDivision - note.startDivision,
|
|
149
|
+
},
|
|
150
|
+
]));
|
|
151
|
+
return estimated === undefined ? [] : [{ division: 0, ...estimated }];
|
|
152
|
+
})();
|
|
153
|
+
const keyStarts = keySignatures.map(({ division }) => toOutput(division));
|
|
154
|
+
const keyAt = (position) => {
|
|
155
|
+
const index = bisectRight(keyStarts, position, (start, value) => start - value) - 1;
|
|
156
|
+
const signature = keySignatures[index];
|
|
157
|
+
return signature === undefined
|
|
158
|
+
? { ...C_MAJOR_ }
|
|
159
|
+
: { fifths: signature.fifths, mode: signature.mode };
|
|
160
|
+
};
|
|
161
|
+
const spellings = Array.from({ length: song.notes.length });
|
|
162
|
+
const partNotes = parts.map((_part, partIndex) => song.notes
|
|
163
|
+
.flatMap((_note, index) => places[index].part === partIndex ? [index] : [])
|
|
164
|
+
.sort((left, right) => starts[left] - starts[right] ||
|
|
165
|
+
song.notes[left].pitch - song.notes[right].pitch));
|
|
166
|
+
for (const indices of partNotes) {
|
|
167
|
+
let fifths;
|
|
168
|
+
let recent = 0;
|
|
169
|
+
for (const index of indices) {
|
|
170
|
+
const key = keyAt(starts[index]);
|
|
171
|
+
const keyCenter = keyCenterOnLineOfFifths(key.fifths);
|
|
172
|
+
if (key.fifths !== fifths) {
|
|
173
|
+
fifths = key.fifths;
|
|
174
|
+
recent = keyCenter;
|
|
175
|
+
}
|
|
176
|
+
const note = song.notes[index];
|
|
177
|
+
const spelling = note.spelling ?? spellPitch(note.pitch, (keyCenter + recent) / 2);
|
|
178
|
+
spellings[index] = spelling;
|
|
179
|
+
recent += SPELLING_MEMORY_ * (lineOfFifthsPosition(spelling) - recent);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// The measures every part shares.
|
|
183
|
+
const measures = song.measures.map((measure, index) => {
|
|
184
|
+
const previous = song.measures[index - 1];
|
|
185
|
+
const timeChanges = previous === undefined ||
|
|
186
|
+
previous.numerator !== measure.numerator ||
|
|
187
|
+
previous.denominator !== measure.denominator;
|
|
188
|
+
return {
|
|
189
|
+
label: measure.label,
|
|
190
|
+
durationDivisions: measureEnds[index] - measureStarts[index],
|
|
191
|
+
time: timeChanges
|
|
192
|
+
? { numerator: measure.numerator, denominator: measure.denominator }
|
|
193
|
+
: undefined,
|
|
194
|
+
tempos: [],
|
|
195
|
+
repeatStart: false,
|
|
196
|
+
repeatEnd: undefined,
|
|
197
|
+
ending: undefined,
|
|
198
|
+
rehearsal: undefined,
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
for (const change of song.tempoMap.changes) {
|
|
202
|
+
const position = toOutput(change.division);
|
|
203
|
+
const index = measureOf(position);
|
|
204
|
+
measures[index].tempos.push({
|
|
205
|
+
offsetDivisions: position - measureStarts[index],
|
|
206
|
+
quarterNotesPerMinute: change.quarterNotesPerMinute,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
for (const marker of song.markers) {
|
|
210
|
+
const measure = measures[measureOf(toOutput(marker.division))];
|
|
211
|
+
if (marker.kind === "rehearsal" && measure.rehearsal === undefined) {
|
|
212
|
+
measure.rehearsal = marker.text;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Pedals and lyrics name the song's parts: each goes to the part most of
|
|
216
|
+
// that part's notes went to.
|
|
217
|
+
const partOfSongPart = song.parts.map((_part, songPart) => {
|
|
218
|
+
const counts = new Map();
|
|
219
|
+
for (const [index, note] of song.notes.entries()) {
|
|
220
|
+
if (note.part === songPart) {
|
|
221
|
+
counts.set(places[index].part, (counts.get(places[index].part) ?? 0) + 1);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
let best = songPart < parts.length ? songPart : 0;
|
|
225
|
+
for (const [part, count] of counts) {
|
|
226
|
+
if (count > (counts.get(best) ?? 0)) {
|
|
227
|
+
best = part;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return best;
|
|
231
|
+
});
|
|
232
|
+
const scoreParts = parts.map((part, partIndex) => {
|
|
233
|
+
const clefs = Array.from({ length: part.staves }, (_clef, staffIndex) => {
|
|
234
|
+
const pitches = song.notes.flatMap((note, index) => places[index].part === partIndex &&
|
|
235
|
+
places[index].staff === staffIndex + 1
|
|
236
|
+
? [note.pitch]
|
|
237
|
+
: []);
|
|
238
|
+
const treble = pitches.length > 0
|
|
239
|
+
? median(pitches) >= 60
|
|
240
|
+
: staffIndex === 0 || part.staves === 1;
|
|
241
|
+
return part.percussion
|
|
242
|
+
? {
|
|
243
|
+
offsetDivisions: 0,
|
|
244
|
+
staff: staffIndex + 1,
|
|
245
|
+
sign: "percussion",
|
|
246
|
+
line: 3,
|
|
247
|
+
octaveChange: 0,
|
|
248
|
+
}
|
|
249
|
+
: {
|
|
250
|
+
offsetDivisions: 0,
|
|
251
|
+
staff: staffIndex + 1,
|
|
252
|
+
sign: treble ? "G" : "F",
|
|
253
|
+
line: treble ? 2 : 4,
|
|
254
|
+
octaveChange: 0,
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
const partMeasures = measures.map((_measure, index) => ({
|
|
258
|
+
key: undefined,
|
|
259
|
+
transpose: undefined,
|
|
260
|
+
clefs: index === 0 ? clefs : [],
|
|
261
|
+
voices: [],
|
|
262
|
+
dynamics: [],
|
|
263
|
+
pedals: [],
|
|
264
|
+
}));
|
|
265
|
+
let lastKey;
|
|
266
|
+
let lastDynamic;
|
|
267
|
+
let noteCursor = 0;
|
|
268
|
+
const notes = partNotes[partIndex];
|
|
269
|
+
for (const [index, partMeasure] of partMeasures.entries()) {
|
|
270
|
+
const key = keyAt(measureStarts[index]);
|
|
271
|
+
if (lastKey === undefined ||
|
|
272
|
+
key.fifths !== lastKey.fifths ||
|
|
273
|
+
key.mode !== lastKey.mode) {
|
|
274
|
+
partMeasure.key = key;
|
|
275
|
+
lastKey = key;
|
|
276
|
+
}
|
|
277
|
+
const loudness = [];
|
|
278
|
+
while (noteCursor < notes.length &&
|
|
279
|
+
starts[notes[noteCursor]] < measureEnds[index]) {
|
|
280
|
+
loudness.push(song.notes[notes[noteCursor]].loudness);
|
|
281
|
+
noteCursor++;
|
|
282
|
+
}
|
|
283
|
+
const dynamic = loudness.length > 0 ? dynamicOfLoudness(mean(loudness)) : undefined;
|
|
284
|
+
if (dynamic !== undefined && dynamic !== lastDynamic) {
|
|
285
|
+
partMeasure.dynamics.push({ offsetDivisions: 0, staff: 1, dynamic });
|
|
286
|
+
lastDynamic = dynamic;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const pedal of song.pedals) {
|
|
290
|
+
if (partOfSongPart[pedal.part] === partIndex) {
|
|
291
|
+
const position = toOutput(pedal.division);
|
|
292
|
+
const index = measureOf(position);
|
|
293
|
+
partMeasures[index].pedals.push({
|
|
294
|
+
offsetDivisions: position - measureStarts[index],
|
|
295
|
+
pedal: pedal.pedal,
|
|
296
|
+
value: pedal.value,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Voices, numbered on from one staff to the next.
|
|
301
|
+
const chordsAt = new Map();
|
|
302
|
+
let voiceNumber = 0;
|
|
303
|
+
for (let staff = 1; staff <= part.staves; staff++) {
|
|
304
|
+
const units = staffUnits[partIndex][staff - 1];
|
|
305
|
+
const voices = staffVoices[partIndex][staff - 1];
|
|
306
|
+
const graces = staffGraces[partIndex][staff - 1];
|
|
307
|
+
const voiceCount = Math.max(1, voices.length);
|
|
308
|
+
for (const [index, partMeasure] of partMeasures.entries()) {
|
|
309
|
+
const measureStart = measureStarts[index];
|
|
310
|
+
const measureEnd = measureEnds[index];
|
|
311
|
+
const beats = measureBeats[index].map((beat, beatIndex) => isTripletUnit_(units[firstBeatOf[index] + beatIndex])
|
|
312
|
+
? { ...beat, timeModification: { actual: 3, normal: 2 } }
|
|
313
|
+
: { ...beat });
|
|
314
|
+
for (let local = 0; local < voiceCount; local++) {
|
|
315
|
+
const chords = (voices[local] ?? []).filter((chord) => chord.start < measureEnd && chord.end > measureStart);
|
|
316
|
+
const voiceGraces = (graces[local] ?? []).filter((grace) => grace.start >= measureStart && grace.start < measureEnd);
|
|
317
|
+
if (local > 0 && chords.length === 0 && voiceGraces.length === 0) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const events = voiceEvents_(chords, voiceGraces, measureStart, measureEnd, beats, staff, (noteIndex, isFirst, isLast) => ({
|
|
321
|
+
pitch: song.notes[noteIndex].pitch,
|
|
322
|
+
spelling: { ...spellings[noteIndex] },
|
|
323
|
+
tieStart: !isLast,
|
|
324
|
+
tieStop: !isFirst,
|
|
325
|
+
fingering: song.notes[noteIndex].fingering,
|
|
326
|
+
loudness: song.notes[noteIndex].loudness,
|
|
327
|
+
}), (chord, event) => {
|
|
328
|
+
const existing = chordsAt.get(chord.start);
|
|
329
|
+
if (existing === undefined || existing.staff > event.staff) {
|
|
330
|
+
chordsAt.set(chord.start, event);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
const voice = { voice: voiceNumber + local + 1, events };
|
|
334
|
+
partMeasure.voices.push(voice);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
voiceNumber += voiceCount;
|
|
338
|
+
}
|
|
339
|
+
attachLyrics_(song, partIndex, partOfSongPart, toOutput, chordsAt);
|
|
340
|
+
return {
|
|
341
|
+
name: part.name,
|
|
342
|
+
sound: part.sound,
|
|
343
|
+
percussion: part.percussion,
|
|
344
|
+
staves: part.staves,
|
|
345
|
+
measures: partMeasures,
|
|
346
|
+
};
|
|
347
|
+
});
|
|
348
|
+
return {
|
|
349
|
+
title: song.title,
|
|
350
|
+
divisionsPerQuarterNote: DIVISIONS_,
|
|
351
|
+
measures,
|
|
352
|
+
parts: scoreParts,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* One voice's events in a measure: its chords' pieces, tied across the
|
|
357
|
+
* measure's beats and barlines, rests between, tuplet brackets and beams, and
|
|
358
|
+
* grace chords before the chord they lead to.
|
|
359
|
+
*/
|
|
360
|
+
function voiceEvents_(chords, graces, measureStart, measureEnd, beats, staff, noteOf, onChordStart) {
|
|
361
|
+
if (chords.length === 0 && graces.length === 0) {
|
|
362
|
+
const duration = measureEnd - measureStart;
|
|
363
|
+
return [
|
|
364
|
+
{
|
|
365
|
+
kind: "rest",
|
|
366
|
+
offsetDivisions: 0,
|
|
367
|
+
durationDivisions: duration,
|
|
368
|
+
value: noteValueOfQuarters(duration / DIVISIONS_, 1) ?? {
|
|
369
|
+
type: "whole",
|
|
370
|
+
dots: 0,
|
|
371
|
+
},
|
|
372
|
+
staff,
|
|
373
|
+
tuplet: undefined,
|
|
374
|
+
measureRest: true,
|
|
375
|
+
},
|
|
376
|
+
];
|
|
377
|
+
}
|
|
378
|
+
const events = [];
|
|
379
|
+
const rests = (from, to) => {
|
|
380
|
+
if (from < to) {
|
|
381
|
+
for (const piece of splitNoteValues(from - measureStart, to - measureStart, beats, DIVISIONS_)) {
|
|
382
|
+
events.push({
|
|
383
|
+
kind: "rest",
|
|
384
|
+
...piece,
|
|
385
|
+
staff,
|
|
386
|
+
tuplet: undefined,
|
|
387
|
+
measureRest: false,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
let cursor = measureStart;
|
|
393
|
+
for (const chord of chords) {
|
|
394
|
+
const from = Math.max(chord.start, measureStart);
|
|
395
|
+
const to = Math.min(chord.end, measureEnd);
|
|
396
|
+
rests(cursor, from);
|
|
397
|
+
for (const piece of splitNoteValues(from - measureStart, to - measureStart, beats, DIVISIONS_)) {
|
|
398
|
+
const isFirst = piece.offsetDivisions + measureStart === chord.start;
|
|
399
|
+
const isLast = piece.offsetDivisions + piece.durationDivisions + measureStart ===
|
|
400
|
+
chord.end;
|
|
401
|
+
const event = {
|
|
402
|
+
kind: "chord",
|
|
403
|
+
...piece,
|
|
404
|
+
staff,
|
|
405
|
+
tuplet: undefined,
|
|
406
|
+
notes: chord.notes.map((noteIndex) => noteOf(noteIndex, isFirst, isLast)),
|
|
407
|
+
grace: false,
|
|
408
|
+
beams: [],
|
|
409
|
+
lyrics: [],
|
|
410
|
+
};
|
|
411
|
+
events.push(event);
|
|
412
|
+
if (isFirst) {
|
|
413
|
+
onChordStart(chord, event);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
cursor = to;
|
|
417
|
+
}
|
|
418
|
+
rests(cursor, measureEnd);
|
|
419
|
+
for (const beat of beats) {
|
|
420
|
+
if (beat.timeModification === undefined) {
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
const inBeat = events.filter((event) => event.value.timeModification !== undefined &&
|
|
424
|
+
event.offsetDivisions >= beat.offsetDivisions &&
|
|
425
|
+
event.offsetDivisions < beat.offsetDivisions + beat.durationDivisions);
|
|
426
|
+
if (inBeat.length >= 2) {
|
|
427
|
+
inBeat[0].tuplet = "start";
|
|
428
|
+
inBeat.at(-1).tuplet = "stop";
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
for (const [index, beams] of voiceBeams(events, beats).entries()) {
|
|
432
|
+
const event = events[index];
|
|
433
|
+
if (event.kind === "chord") {
|
|
434
|
+
event.beams = beams;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
for (const grace of graces) {
|
|
438
|
+
const offset = grace.start - measureStart;
|
|
439
|
+
// After the graces already there, before the chord they lead to.
|
|
440
|
+
const index = events.findIndex((event) => event.offsetDivisions > offset ||
|
|
441
|
+
(event.offsetDivisions === offset &&
|
|
442
|
+
!(event.kind === "chord" && event.grace)));
|
|
443
|
+
events.splice(index === -1 ? events.length : index, 0, {
|
|
444
|
+
kind: "chord",
|
|
445
|
+
offsetDivisions: offset,
|
|
446
|
+
durationDivisions: 0,
|
|
447
|
+
value: { type: "eighth", dots: 0 },
|
|
448
|
+
staff,
|
|
449
|
+
tuplet: undefined,
|
|
450
|
+
notes: grace.notes.map((noteIndex) => noteOf(noteIndex, true, true)),
|
|
451
|
+
grace: true,
|
|
452
|
+
beams: [],
|
|
453
|
+
lyrics: [],
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
return events;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Puts a part's lyrics under the chords nearest them, one verse per syllable
|
|
460
|
+
* there.
|
|
461
|
+
*/
|
|
462
|
+
function attachLyrics_(song, partIndex, partOfSongPart, toOutput, chordsAt) {
|
|
463
|
+
const lyrics = song.lyrics.filter((lyric) => partOfSongPart[lyric.part ?? 0] === partIndex);
|
|
464
|
+
let startsWord = true;
|
|
465
|
+
for (const lyric of lyrics) {
|
|
466
|
+
const continues = /-\s*$/u.test(lyric.text);
|
|
467
|
+
const endsWord = !continues && (/\s$/u.test(lyric.text) || lyric === lyrics.at(-1));
|
|
468
|
+
const text = lyric.text.trim().replace(/-$/u, "");
|
|
469
|
+
const syllabic = startsWord
|
|
470
|
+
? endsWord
|
|
471
|
+
? "single"
|
|
472
|
+
: "begin"
|
|
473
|
+
: endsWord
|
|
474
|
+
? "end"
|
|
475
|
+
: "middle";
|
|
476
|
+
startsWord = endsWord;
|
|
477
|
+
const position = toOutput(lyric.division);
|
|
478
|
+
let chord;
|
|
479
|
+
for (let distance = 0; distance <= LYRIC_REACH_ && chord === undefined; distance++) {
|
|
480
|
+
chord =
|
|
481
|
+
chordsAt.get(position - distance) ?? chordsAt.get(position + distance);
|
|
482
|
+
}
|
|
483
|
+
if (chord !== undefined && text !== "") {
|
|
484
|
+
chord.lyrics.push({ verse: chord.lyrics.length + 1, text, syllabic });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
//# sourceMappingURL=infer-notation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-notation.js","sourceRoot":"","sources":["../../src/infer/infer-notation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAEN,iBAAiB,EACjB,uBAAuB,EAEvB,oBAAoB,EAKpB,UAAU,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEN,UAAU,EACV,mBAAmB,EAWnB,eAAe,EACf,UAAU,GACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACN,YAAY,EACZ,gBAAgB,EAEhB,cAAc,EACd,QAAQ,EACR,UAAU,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAoB,MAAM,cAAc,CAAC;AAuB/D,4EAA4E;AAC5E,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,4EAA4E;AAC5E,kDAAkD;AA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G,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,UAAU;YAC1B,CAAC,CAAC,QAAQ;gBACT,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,OAAO;YACV,CAAC,CAAC,QAAQ;gBACT,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,QAAQ,CAAC;QACb,UAAU,GAAG,QAAQ,CAAC;QAEtB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,KAA6B,CAAC;QAClC,KACC,IAAI,QAAQ,GAAG,CAAC,EAChB,QAAQ,IAAI,YAAY,IAAI,KAAK,KAAK,SAAS,EAC/C,QAAQ,EAAE,EACT,CAAC;YACF,KAAK;gBACJ,QAAQ,CAAC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACxC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type KeyMode } from "@ac-kit/model-music";
|
|
2
|
+
/** A key a passage is in: its signature's fifths and its mode. */
|
|
3
|
+
export type EstimatedKey = {
|
|
4
|
+
fifths: number;
|
|
5
|
+
mode: Extract<KeyMode, "major" | "minor">;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The key of a passage, by the Krumhansl–Schmuckler algorithm: the major or
|
|
9
|
+
* minor key whose tonal profile correlates best with how long each pitch class
|
|
10
|
+
* sounds. Six accidentals come out as flats: G♭ major is -6, never F♯ major's 6.
|
|
11
|
+
*
|
|
12
|
+
* Reach for it when a source gives no key signature, as many MIDI files do not;
|
|
13
|
+
* a written key signature is better evidence. `undefined` when nothing sounds.
|
|
14
|
+
*
|
|
15
|
+
* Time O(n + 24 × 12) in the notes. Memory O(1).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* estimateKey([{ pitch: 62, duration: 1 }, { pitch: 66, duration: 1 }, { pitch: 69, duration: 2 }]);
|
|
19
|
+
* // { fifths: 2, mode: "major" }
|
|
20
|
+
*/
|
|
21
|
+
export declare function estimateKey(notes: Iterable<{
|
|
22
|
+
pitch: number;
|
|
23
|
+
duration: number;
|
|
24
|
+
}>): EstimatedKey | undefined;
|
|
25
|
+
//# sourceMappingURL=estimate-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimate-key.d.ts","sourceRoot":"","sources":["../../src/key/estimate-key.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,qBAAqB,CAAC;AAE/D,kEAAkE;AAClE,MAAM,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;CAC1C,CAAC;AAUF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,GAClD,YAAY,GAAG,SAAS,CAiC1B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { mod } from "@ac-kit/core";
|
|
2
|
+
import { pearsonCorrelation } from "@ac-kit/math-stats";
|
|
3
|
+
import { pitchClass } from "@ac-kit/model-music";
|
|
4
|
+
// Krumhansl and Kessler's probe-tone profiles (1982), from the tonic up.
|
|
5
|
+
const MAJOR_PROFILE_ = [
|
|
6
|
+
6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, 5.19, 2.39, 3.66, 2.29, 2.88,
|
|
7
|
+
];
|
|
8
|
+
const MINOR_PROFILE_ = [
|
|
9
|
+
6.33, 2.68, 3.52, 5.38, 2.6, 3.53, 2.54, 4.75, 3.98, 2.69, 3.34, 3.17,
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* The key of a passage, by the Krumhansl–Schmuckler algorithm: the major or
|
|
13
|
+
* minor key whose tonal profile correlates best with how long each pitch class
|
|
14
|
+
* sounds. Six accidentals come out as flats: G♭ major is -6, never F♯ major's 6.
|
|
15
|
+
*
|
|
16
|
+
* Reach for it when a source gives no key signature, as many MIDI files do not;
|
|
17
|
+
* a written key signature is better evidence. `undefined` when nothing sounds.
|
|
18
|
+
*
|
|
19
|
+
* Time O(n + 24 × 12) in the notes. Memory O(1).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* estimateKey([{ pitch: 62, duration: 1 }, { pitch: 66, duration: 1 }, { pitch: 69, duration: 2 }]);
|
|
23
|
+
* // { fifths: 2, mode: "major" }
|
|
24
|
+
*/
|
|
25
|
+
export function estimateKey(notes) {
|
|
26
|
+
const weights = Array.from({ length: 12 }).fill(0);
|
|
27
|
+
for (const { pitch, duration } of notes) {
|
|
28
|
+
weights[pitchClass(Math.round(pitch))] += Math.max(0, duration);
|
|
29
|
+
}
|
|
30
|
+
if (weights.every((weight) => weight === 0)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
let best;
|
|
34
|
+
for (const [mode, profile] of [
|
|
35
|
+
["major", MAJOR_PROFILE_],
|
|
36
|
+
["minor", MINOR_PROFILE_],
|
|
37
|
+
]) {
|
|
38
|
+
for (let tonic = 0; tonic < 12; tonic++) {
|
|
39
|
+
const correlation = pearsonCorrelation(weights, weights.map((_weight, index) => profile[mod(index - tonic, 12)]));
|
|
40
|
+
if (best === undefined || correlation > best.correlation) {
|
|
41
|
+
best = { tonic, mode, correlation };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// A major key's fifths is its tonic's place on the circle of fifths; a minor
|
|
46
|
+
// key shares its relative major's, three semitones up.
|
|
47
|
+
const majorTonic = best.mode === "major" ? best.tonic : mod(best.tonic + 3, 12);
|
|
48
|
+
const fifths = mod(majorTonic * 7 + 6, 12) - 6;
|
|
49
|
+
return { fifths, mode: best.mode };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=estimate-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimate-key.js","sourceRoot":"","sources":["../../src/key/estimate-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAgB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQ/D,yEAAyE;AACzE,MAAM,cAAc,GAAG;IACtB,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACtE,CAAC;AACF,MAAM,cAAc,GAAG;IACtB,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACrE,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAoD;IAEpD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3D,KAAK,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IA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AC,GAAG,CAAC,CAAC;IAE/C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAK,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/media-music-notation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Music notation inferred from a performance: quantized note values, voices, ties, beams, key and pitch spelling for a song that has no score, such as a MIDI file.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"midi",
|
|
7
|
+
"music",
|
|
8
|
+
"notation",
|
|
9
|
+
"quantization",
|
|
10
|
+
"score",
|
|
11
|
+
"transcription"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/media-music-notation/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "BSD-3-Clause",
|
|
18
|
+
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
|
|
22
|
+
"directory": "packages/media-music-notation"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"compile": "tsc -p ./tsconfig.build.json -outDir dist",
|
|
42
|
+
"compile:check": "tsc -noEmit -p ./tsconfig.json",
|
|
43
|
+
"clean": "rimraf dist",
|
|
44
|
+
"build": "yarn clean && yarn compile",
|
|
45
|
+
"test": "yarn run -T vitest run",
|
|
46
|
+
"prepack": "yarn build"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@ac-kit/algo": "^0.2.3",
|
|
50
|
+
"@ac-kit/core": "^0.6.0",
|
|
51
|
+
"@ac-kit/math-integer": "^0.3.0",
|
|
52
|
+
"@ac-kit/math-stats": "^0.2.0",
|
|
53
|
+
"@ac-kit/model-music": "^0.4.0",
|
|
54
|
+
"@ac-kit/model-notation": "^0.1.0",
|
|
55
|
+
"@types/web": "^0.0.362"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@ac-kit/format-musicxml": "^0.1.0",
|
|
59
|
+
"@ac-kit/tsconfig": "0.1.0",
|
|
60
|
+
"@ac-kit/typedoc-config": "0.1.0",
|
|
61
|
+
"@ac-kit/vitest-config": "0.1.1",
|
|
62
|
+
"@types/node": "^26.5.1",
|
|
63
|
+
"@typescript/native": "typescript@7.0.2",
|
|
64
|
+
"rimraf": "6.1.4",
|
|
65
|
+
"typedoc": "0.28.20",
|
|
66
|
+
"typescript": "@typescript/typescript6@6.0.2"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=24"
|
|
70
|
+
}
|
|
6
71
|
}
|