@libraz/libcantus 0.9.4 → 1.0.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/README.md +61 -261
- package/README_ja.md +115 -0
- package/dist/analyze/index.cjs +54 -7
- package/dist/analyze/index.cjs.map +1 -1
- package/dist/analyze/index.d.cts +213 -456
- package/dist/analyze/index.d.ts +213 -456
- package/dist/analyze/index.js +56 -9
- package/dist/chunk-3JXCW6DX.cjs +3220 -0
- package/dist/chunk-3JXCW6DX.cjs.map +1 -0
- package/dist/chunk-4A2RMUCC.js +7647 -0
- package/dist/chunk-4A2RMUCC.js.map +1 -0
- package/dist/chunk-6XPTBE7Y.cjs +49 -0
- package/dist/chunk-6XPTBE7Y.cjs.map +1 -0
- package/dist/chunk-AFM2ULJH.cjs +5121 -0
- package/dist/chunk-AFM2ULJH.cjs.map +1 -0
- package/dist/chunk-E3F4AHAH.cjs +690 -0
- package/dist/chunk-E3F4AHAH.cjs.map +1 -0
- package/dist/chunk-ELCTZUJJ.js +379 -0
- package/dist/chunk-ELCTZUJJ.js.map +1 -0
- package/dist/chunk-FVSI36UV.js +690 -0
- package/dist/chunk-FVSI36UV.js.map +1 -0
- package/dist/chunk-GEDTJHAC.cjs +1 -0
- package/dist/chunk-GEDTJHAC.cjs.map +1 -0
- package/dist/chunk-GOZG57ER.js +3220 -0
- package/dist/chunk-GOZG57ER.js.map +1 -0
- package/dist/chunk-H3VORETI.js +2243 -0
- package/dist/chunk-H3VORETI.js.map +1 -0
- package/dist/chunk-H42UHPYW.js +1577 -0
- package/dist/chunk-H42UHPYW.js.map +1 -0
- package/dist/chunk-HFPS7JFD.js +1 -0
- package/dist/chunk-INHVXP6Z.js +3053 -0
- package/dist/chunk-INHVXP6Z.js.map +1 -0
- package/dist/chunk-K4ZJUGF4.cjs +379 -0
- package/dist/chunk-K4ZJUGF4.cjs.map +1 -0
- package/dist/chunk-KNJEKLKV.js +49 -0
- package/dist/chunk-KNJEKLKV.js.map +1 -0
- package/dist/chunk-M4CWTJWJ.cjs +7647 -0
- package/dist/chunk-M4CWTJWJ.cjs.map +1 -0
- package/dist/chunk-MXO72PLY.cjs +211 -0
- package/dist/chunk-MXO72PLY.cjs.map +1 -0
- package/dist/chunk-NLEU4QSE.cjs +360 -0
- package/dist/chunk-NLEU4QSE.cjs.map +1 -0
- package/dist/chunk-OE6WK2Y2.cjs +1577 -0
- package/dist/chunk-OE6WK2Y2.cjs.map +1 -0
- package/dist/chunk-Q2WGKJNN.cjs +1064 -0
- package/dist/chunk-Q2WGKJNN.cjs.map +1 -0
- package/dist/chunk-QYQQ5J6E.js +1 -0
- package/dist/chunk-QYQQ5J6E.js.map +1 -0
- package/dist/chunk-RHIJ3S4I.cjs +1 -0
- package/dist/chunk-RHIJ3S4I.cjs.map +1 -0
- package/dist/chunk-TTCLJX6D.js +211 -0
- package/dist/chunk-TTCLJX6D.js.map +1 -0
- package/dist/chunk-UADYAYAT.cjs +3053 -0
- package/dist/chunk-UADYAYAT.cjs.map +1 -0
- package/dist/chunk-VOHZB45S.js +5121 -0
- package/dist/chunk-VOHZB45S.js.map +1 -0
- package/dist/chunk-VTI6FOLB.js +1064 -0
- package/dist/chunk-VTI6FOLB.js.map +1 -0
- package/dist/chunk-WWURE4XT.cjs +2243 -0
- package/dist/chunk-WWURE4XT.cjs.map +1 -0
- package/dist/chunk-YH3BIKHH.js +360 -0
- package/dist/chunk-YH3BIKHH.js.map +1 -0
- package/dist/core/index.cjs +103 -6
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +96 -345
- package/dist/core/index.d.ts +96 -345
- package/dist/core/index.js +104 -7
- package/dist/generate/index.cjs +89 -10
- package/dist/generate/index.cjs.map +1 -1
- package/dist/generate/index.d.cts +437 -1095
- package/dist/generate/index.d.ts +437 -1095
- package/dist/generate/index.js +94 -15
- package/dist/index-9wcMhG73.d.ts +1095 -0
- package/dist/{index-D6b6na69.d.cts → index-B4o55NDr.d.cts} +13 -9
- package/dist/index-B9MNZboQ.d.cts +770 -0
- package/dist/index-B9MNZboQ.d.ts +770 -0
- package/dist/index-BGFW-8P2.d.cts +2307 -0
- package/dist/index-BO6xE9YU.d.cts +1804 -0
- package/dist/index-BkGmlyI3.d.cts +470 -0
- package/dist/index-CCNJRG-P.d.cts +1095 -0
- package/dist/index-CGpRv5sl.d.cts +643 -0
- package/dist/index-C_8o--VE.d.cts +1242 -0
- package/dist/index-CgHqxdps.d.ts +2307 -0
- package/dist/index-Chbst3Jx.d.ts +1343 -0
- package/dist/index-Cj49F892.d.ts +470 -0
- package/dist/{index-tSQh-xwY.d.ts → index-CunYKLiu.d.ts} +13 -9
- package/dist/index-D57QRbVn.d.ts +1804 -0
- package/dist/index-DInQqT8Q.d.cts +66 -0
- package/dist/index-DInQqT8Q.d.ts +66 -0
- package/dist/index-Dzr13q3d.d.cts +1343 -0
- package/dist/index-G1uwGGWQ.d.ts +643 -0
- package/dist/index-szBv3496.d.ts +1242 -0
- package/dist/index.cjs +358 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -15
- package/dist/index.d.ts +17 -15
- package/dist/index.js +407 -64
- package/dist/masks-DYbE485J.d.cts +445 -0
- package/dist/masks-DYbE485J.d.ts +445 -0
- package/dist/model/index.cjs +39 -7
- package/dist/model/index.cjs.map +1 -1
- package/dist/model/index.d.cts +4685 -243
- package/dist/model/index.d.ts +4685 -243
- package/dist/model/index.js +40 -8
- package/dist/positional-Cptlj-xs.d.ts +287 -0
- package/dist/positional-DvH_sd8u.d.cts +287 -0
- package/dist/theory/index.cjs +101 -7
- package/dist/theory/index.cjs.map +1 -1
- package/dist/theory/index.d.cts +513 -173
- package/dist/theory/index.d.ts +513 -173
- package/dist/theory/index.js +118 -24
- package/package.json +16 -11
- package/dist/chunk-36N73KZ3.cjs +0 -246
- package/dist/chunk-36N73KZ3.cjs.map +0 -1
- package/dist/chunk-4HLLZPXT.cjs +0 -3077
- package/dist/chunk-4HLLZPXT.cjs.map +0 -1
- package/dist/chunk-7MGZ7D62.cjs +0 -498
- package/dist/chunk-7MGZ7D62.cjs.map +0 -1
- package/dist/chunk-7NKDPF74.js +0 -3077
- package/dist/chunk-7NKDPF74.js.map +0 -1
- package/dist/chunk-CAN76NCU.cjs +0 -679
- package/dist/chunk-CAN76NCU.cjs.map +0 -1
- package/dist/chunk-D2FAJBYL.js +0 -479
- package/dist/chunk-D2FAJBYL.js.map +0 -1
- package/dist/chunk-EHVEBWM5.js +0 -1449
- package/dist/chunk-EHVEBWM5.js.map +0 -1
- package/dist/chunk-FCANXBAT.cjs +0 -30
- package/dist/chunk-FCANXBAT.cjs.map +0 -1
- package/dist/chunk-FNDWXRRI.cjs +0 -479
- package/dist/chunk-FNDWXRRI.cjs.map +0 -1
- package/dist/chunk-GQSGS2N4.js +0 -173
- package/dist/chunk-GQSGS2N4.js.map +0 -1
- package/dist/chunk-HKGYCQ34.js +0 -53
- package/dist/chunk-HKGYCQ34.js.map +0 -1
- package/dist/chunk-I24MV65U.js +0 -106
- package/dist/chunk-I24MV65U.js.map +0 -1
- package/dist/chunk-KMHOICIY.js +0 -679
- package/dist/chunk-KMHOICIY.js.map +0 -1
- package/dist/chunk-LW53AHQU.cjs +0 -1117
- package/dist/chunk-LW53AHQU.cjs.map +0 -1
- package/dist/chunk-N6IHQUOX.js +0 -1
- package/dist/chunk-NKIBQ6PT.js +0 -30
- package/dist/chunk-NKIBQ6PT.js.map +0 -1
- package/dist/chunk-NP4NA2FB.cjs +0 -106
- package/dist/chunk-NP4NA2FB.cjs.map +0 -1
- package/dist/chunk-NVE34YGZ.cjs +0 -1449
- package/dist/chunk-NVE34YGZ.cjs.map +0 -1
- package/dist/chunk-NYYWMV2C.js +0 -327
- package/dist/chunk-NYYWMV2C.js.map +0 -1
- package/dist/chunk-Q2XUP227.js +0 -845
- package/dist/chunk-Q2XUP227.js.map +0 -1
- package/dist/chunk-Q6OP4U43.cjs +0 -327
- package/dist/chunk-Q6OP4U43.cjs.map +0 -1
- package/dist/chunk-RC6GBMCD.cjs +0 -845
- package/dist/chunk-RC6GBMCD.cjs.map +0 -1
- package/dist/chunk-RK35RIN7.js +0 -1117
- package/dist/chunk-RK35RIN7.js.map +0 -1
- package/dist/chunk-RUMU3UA6.cjs +0 -53
- package/dist/chunk-RUMU3UA6.cjs.map +0 -1
- package/dist/chunk-T64C7ZD7.cjs +0 -1
- package/dist/chunk-T64C7ZD7.cjs.map +0 -1
- package/dist/chunk-XEBG3G53.js +0 -498
- package/dist/chunk-XEBG3G53.js.map +0 -1
- package/dist/chunk-YLEMGEFH.js +0 -246
- package/dist/chunk-YLEMGEFH.js.map +0 -1
- package/dist/chunk-ZEJR4TKL.cjs +0 -173
- package/dist/chunk-ZEJR4TKL.cjs.map +0 -1
- package/dist/function-BtiZb9i9.d.ts +0 -208
- package/dist/function-DNugAOrt.d.cts +0 -208
- package/dist/index-6VR8-kit.d.ts +0 -143
- package/dist/index-70p168VM.d.ts +0 -192
- package/dist/index-Be74mcon.d.cts +0 -152
- package/dist/index-BtXT6UQ0.d.cts +0 -192
- package/dist/index-C5UBbQ4G.d.ts +0 -152
- package/dist/index-C83mZI1P.d.ts +0 -242
- package/dist/index-DXd9JikN.d.cts +0 -246
- package/dist/index-DXd9JikN.d.ts +0 -246
- package/dist/index-OG65ocOr.d.cts +0 -272
- package/dist/index-OG65ocOr.d.ts +0 -272
- package/dist/index-tJhkmQgE.d.cts +0 -143
- package/dist/index-y_ak9_Hi.d.cts +0 -242
- package/dist/styled-DIRkk9Uz.d.ts +0 -506
- package/dist/styled-DJbkJQfj.d.cts +0 -506
- package/dist/types-BN6_Q9Kl.d.cts +0 -39
- package/dist/types-BN6_Q9Kl.d.ts +0 -39
- /package/dist/{chunk-N6IHQUOX.js.map → chunk-HFPS7JFD.js.map} +0 -0
package/dist/theory/index.js
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import {
|
|
3
|
-
roleOf
|
|
4
|
-
} from "../chunk-NKIBQ6PT.js";
|
|
5
|
-
import {
|
|
6
|
-
NoteSafety,
|
|
7
|
-
ReasonFlag,
|
|
8
|
-
enumerateSafePitches,
|
|
9
|
-
evaluateSafety
|
|
10
|
-
} from "../chunk-NYYWMV2C.js";
|
|
1
|
+
import "../chunk-HFPS7JFD.js";
|
|
11
2
|
import {
|
|
12
3
|
SATB_RANGES,
|
|
4
|
+
TRANSPOSING_INSTRUMENTS,
|
|
13
5
|
availableTensions,
|
|
14
6
|
avoidNotes,
|
|
7
|
+
checkPartWriting,
|
|
8
|
+
checkSpecies,
|
|
15
9
|
chordScaleReport,
|
|
16
10
|
chordScales,
|
|
17
|
-
|
|
11
|
+
figuredBassOf,
|
|
12
|
+
figuredBassRealization,
|
|
13
|
+
instrumentTransposition,
|
|
18
14
|
nextVoicing,
|
|
19
|
-
|
|
20
|
-
parseChordSymbol,
|
|
15
|
+
realizeFiguredBass,
|
|
21
16
|
scaleMatchesChord,
|
|
22
17
|
scalesForChanges,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
spellPitchClass,
|
|
27
|
-
spellPitchClasses,
|
|
28
|
-
spellScale,
|
|
29
|
-
transposeChordSymbol,
|
|
18
|
+
spellVoicing,
|
|
19
|
+
toSoundingPitch,
|
|
20
|
+
toWrittenPitch,
|
|
30
21
|
voiceChord,
|
|
31
22
|
voiceChordStyled,
|
|
32
23
|
voiceLeadingCost,
|
|
33
24
|
voiceProgression
|
|
34
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-H3VORETI.js";
|
|
26
|
+
import {
|
|
27
|
+
roleOf
|
|
28
|
+
} from "../chunk-KNJEKLKV.js";
|
|
35
29
|
import {
|
|
36
30
|
ALTERED_MASK,
|
|
37
31
|
BLUES_MASK,
|
|
38
32
|
CHROMATIC_MASK,
|
|
39
33
|
DORIAN_MASK,
|
|
34
|
+
DOUBLE_HARMONIC_MASK,
|
|
40
35
|
HARMONIC_MINOR_MASK,
|
|
41
36
|
LOCRIAN_MASK,
|
|
42
37
|
LOCRIAN_NATURAL2_MASK,
|
|
@@ -44,21 +39,40 @@ import {
|
|
|
44
39
|
LYDIAN_MASK,
|
|
45
40
|
MAJOR_MASK,
|
|
46
41
|
MAJOR_PENTATONIC_MASK,
|
|
42
|
+
MARWA_MASK,
|
|
47
43
|
MELODIC_MINOR_MASK,
|
|
48
44
|
MINOR_PENTATONIC_MASK,
|
|
49
45
|
MIXOLYDIAN_B13_MASK,
|
|
50
46
|
MIXOLYDIAN_MASK,
|
|
47
|
+
MIYAKO_BUSHI_MASK,
|
|
51
48
|
NAMED_SCALES,
|
|
52
49
|
NATURAL_MINOR_MASK,
|
|
50
|
+
NoteSafety,
|
|
53
51
|
OCTATONIC_HALF_WHOLE_MASK,
|
|
54
52
|
OCTATONIC_WHOLE_HALF_MASK,
|
|
55
53
|
PHRYGIAN_DOMINANT_MASK,
|
|
56
54
|
PHRYGIAN_MASK,
|
|
55
|
+
PROFILE_WEIGHTS,
|
|
56
|
+
PURVI_MASK,
|
|
57
|
+
RITSU_MASK,
|
|
58
|
+
RYUKYU_MASK,
|
|
59
|
+
ReasonFlag,
|
|
60
|
+
SCALE_ALIASES,
|
|
61
|
+
SCALE_SYSTEMS,
|
|
62
|
+
TODI_MASK,
|
|
57
63
|
WHOLE_TONE_MASK,
|
|
64
|
+
WORLD_SCALES,
|
|
58
65
|
chordFromDegree,
|
|
66
|
+
chordFromSpan,
|
|
67
|
+
chordFromSpec,
|
|
59
68
|
chordPitchClasses,
|
|
60
69
|
chordQualities,
|
|
70
|
+
chordSpecIntervals,
|
|
71
|
+
chordSpecOf,
|
|
72
|
+
chordSpecQuality,
|
|
61
73
|
chordToneRole,
|
|
74
|
+
classifySpelledInterval,
|
|
75
|
+
createsBattuta,
|
|
62
76
|
createsHiddenParallelPerfect,
|
|
63
77
|
createsParallelOctave,
|
|
64
78
|
createsParallelPerfect,
|
|
@@ -69,30 +83,63 @@ import {
|
|
|
69
83
|
diatonicPitchClasses,
|
|
70
84
|
diatonicSeventh,
|
|
71
85
|
diatonicTriad,
|
|
86
|
+
dominantKeyOf,
|
|
87
|
+
enharmonicKeyOf,
|
|
88
|
+
enumerateSafePitches,
|
|
89
|
+
evaluateSafety,
|
|
72
90
|
exceedsSpacing,
|
|
91
|
+
formatChordSymbol,
|
|
73
92
|
intervalAboveRoot,
|
|
93
|
+
isAugmentedMelodicInterval,
|
|
74
94
|
isChordMember,
|
|
75
95
|
isForbiddenMelodicLeap,
|
|
76
96
|
isLeadingToneResolution,
|
|
77
97
|
isScaleTone,
|
|
98
|
+
keyFromFifths,
|
|
99
|
+
keyRelationBetween,
|
|
100
|
+
keySignatureFifths,
|
|
78
101
|
majorKey,
|
|
79
102
|
makeChord,
|
|
80
103
|
maskFromOffsets,
|
|
81
104
|
minorKey,
|
|
82
105
|
namedScaleMask,
|
|
83
106
|
nearestScaleTone,
|
|
107
|
+
noteNames,
|
|
108
|
+
parallelKeyOf,
|
|
109
|
+
parseChordSymbol,
|
|
84
110
|
pitchToScaleDegree,
|
|
111
|
+
profileWeights,
|
|
112
|
+
relatedKeysOf,
|
|
113
|
+
relativeKeyOf,
|
|
85
114
|
requireScaleMask,
|
|
115
|
+
resolveScaleName,
|
|
86
116
|
scaleByName,
|
|
117
|
+
scaleSystemOf,
|
|
87
118
|
scaleTonesInDegreeOrder,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
119
|
+
spanFromChord,
|
|
120
|
+
spellChord,
|
|
121
|
+
spellChordFromRoot,
|
|
122
|
+
spellPitch,
|
|
123
|
+
spellPitchClass,
|
|
124
|
+
spellPitchClasses,
|
|
125
|
+
spellScale,
|
|
126
|
+
spelledKeyOf,
|
|
127
|
+
subdominantKeyOf,
|
|
128
|
+
supportsFunctionalHarmony,
|
|
129
|
+
toChordData,
|
|
130
|
+
toKeyScale,
|
|
131
|
+
transposeChord,
|
|
132
|
+
transposeChordSymbol,
|
|
133
|
+
tryParseChordSymbol,
|
|
134
|
+
voiceIndependence
|
|
135
|
+
} from "../chunk-INHVXP6Z.js";
|
|
136
|
+
import "../chunk-VTI6FOLB.js";
|
|
91
137
|
export {
|
|
92
138
|
ALTERED_MASK,
|
|
93
139
|
BLUES_MASK,
|
|
94
140
|
CHROMATIC_MASK,
|
|
95
141
|
DORIAN_MASK,
|
|
142
|
+
DOUBLE_HARMONIC_MASK,
|
|
96
143
|
HARMONIC_MINOR_MASK,
|
|
97
144
|
LOCRIAN_MASK,
|
|
98
145
|
LOCRIAN_NATURAL2_MASK,
|
|
@@ -100,10 +147,12 @@ export {
|
|
|
100
147
|
LYDIAN_MASK,
|
|
101
148
|
MAJOR_MASK,
|
|
102
149
|
MAJOR_PENTATONIC_MASK,
|
|
150
|
+
MARWA_MASK,
|
|
103
151
|
MELODIC_MINOR_MASK,
|
|
104
152
|
MINOR_PENTATONIC_MASK,
|
|
105
153
|
MIXOLYDIAN_B13_MASK,
|
|
106
154
|
MIXOLYDIAN_MASK,
|
|
155
|
+
MIYAKO_BUSHI_MASK,
|
|
107
156
|
NAMED_SCALES,
|
|
108
157
|
NATURAL_MINOR_MASK,
|
|
109
158
|
NoteSafety,
|
|
@@ -111,17 +160,35 @@ export {
|
|
|
111
160
|
OCTATONIC_WHOLE_HALF_MASK,
|
|
112
161
|
PHRYGIAN_DOMINANT_MASK,
|
|
113
162
|
PHRYGIAN_MASK,
|
|
163
|
+
PROFILE_WEIGHTS,
|
|
164
|
+
PURVI_MASK,
|
|
165
|
+
RITSU_MASK,
|
|
166
|
+
RYUKYU_MASK,
|
|
114
167
|
ReasonFlag,
|
|
115
168
|
SATB_RANGES,
|
|
169
|
+
SCALE_ALIASES,
|
|
170
|
+
SCALE_SYSTEMS,
|
|
171
|
+
TODI_MASK,
|
|
172
|
+
TRANSPOSING_INSTRUMENTS,
|
|
116
173
|
WHOLE_TONE_MASK,
|
|
174
|
+
WORLD_SCALES,
|
|
117
175
|
availableTensions,
|
|
118
176
|
avoidNotes,
|
|
177
|
+
checkPartWriting,
|
|
178
|
+
checkSpecies,
|
|
119
179
|
chordFromDegree,
|
|
180
|
+
chordFromSpan,
|
|
181
|
+
chordFromSpec,
|
|
120
182
|
chordPitchClasses,
|
|
121
183
|
chordQualities,
|
|
122
184
|
chordScaleReport,
|
|
123
185
|
chordScales,
|
|
186
|
+
chordSpecIntervals,
|
|
187
|
+
chordSpecOf,
|
|
188
|
+
chordSpecQuality,
|
|
124
189
|
chordToneRole,
|
|
190
|
+
classifySpelledInterval,
|
|
191
|
+
createsBattuta,
|
|
125
192
|
createsHiddenParallelPerfect,
|
|
126
193
|
createsParallelOctave,
|
|
127
194
|
createsParallelPerfect,
|
|
@@ -132,15 +199,24 @@ export {
|
|
|
132
199
|
diatonicPitchClasses,
|
|
133
200
|
diatonicSeventh,
|
|
134
201
|
diatonicTriad,
|
|
202
|
+
dominantKeyOf,
|
|
203
|
+
enharmonicKeyOf,
|
|
135
204
|
enumerateSafePitches,
|
|
136
205
|
evaluateSafety,
|
|
137
206
|
exceedsSpacing,
|
|
207
|
+
figuredBassOf,
|
|
208
|
+
figuredBassRealization,
|
|
138
209
|
formatChordSymbol,
|
|
210
|
+
instrumentTransposition,
|
|
139
211
|
intervalAboveRoot,
|
|
212
|
+
isAugmentedMelodicInterval,
|
|
140
213
|
isChordMember,
|
|
141
214
|
isForbiddenMelodicLeap,
|
|
142
215
|
isLeadingToneResolution,
|
|
143
216
|
isScaleTone,
|
|
217
|
+
keyFromFifths,
|
|
218
|
+
keyRelationBetween,
|
|
219
|
+
keySignatureFifths,
|
|
144
220
|
majorKey,
|
|
145
221
|
makeChord,
|
|
146
222
|
maskFromOffsets,
|
|
@@ -149,24 +225,42 @@ export {
|
|
|
149
225
|
nearestScaleTone,
|
|
150
226
|
nextVoicing,
|
|
151
227
|
noteNames,
|
|
228
|
+
parallelKeyOf,
|
|
152
229
|
parseChordSymbol,
|
|
153
230
|
pitchToScaleDegree,
|
|
231
|
+
profileWeights,
|
|
232
|
+
realizeFiguredBass,
|
|
233
|
+
relatedKeysOf,
|
|
234
|
+
relativeKeyOf,
|
|
154
235
|
requireScaleMask,
|
|
236
|
+
resolveScaleName,
|
|
155
237
|
roleOf,
|
|
156
238
|
scaleByName,
|
|
157
239
|
scaleMatchesChord,
|
|
240
|
+
scaleSystemOf,
|
|
158
241
|
scaleTonesInDegreeOrder,
|
|
159
242
|
scalesForChanges,
|
|
243
|
+
spanFromChord,
|
|
160
244
|
spellChord,
|
|
161
245
|
spellChordFromRoot,
|
|
162
246
|
spellPitch,
|
|
163
247
|
spellPitchClass,
|
|
164
248
|
spellPitchClasses,
|
|
165
249
|
spellScale,
|
|
250
|
+
spellVoicing,
|
|
251
|
+
spelledKeyOf,
|
|
252
|
+
subdominantKeyOf,
|
|
253
|
+
supportsFunctionalHarmony,
|
|
254
|
+
toChordData,
|
|
255
|
+
toKeyScale,
|
|
256
|
+
toSoundingPitch,
|
|
257
|
+
toWrittenPitch,
|
|
166
258
|
transposeChord,
|
|
167
259
|
transposeChordSymbol,
|
|
260
|
+
tryParseChordSymbol,
|
|
168
261
|
voiceChord,
|
|
169
262
|
voiceChordStyled,
|
|
263
|
+
voiceIndependence,
|
|
170
264
|
voiceLeadingCost,
|
|
171
265
|
voiceProgression
|
|
172
266
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libraz/libcantus",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Pure-TypeScript music
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Pure-TypeScript music theory engine: harmonic analysis, chord and scale vocabulary, voicing, reharmonization, and seeded part generation over MIDI note events.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "libraz",
|
|
@@ -20,16 +20,18 @@
|
|
|
20
20
|
"scales",
|
|
21
21
|
"intervals",
|
|
22
22
|
"harmony",
|
|
23
|
-
"composition"
|
|
23
|
+
"composition",
|
|
24
|
+
"midi",
|
|
25
|
+
"chord-detection",
|
|
26
|
+
"voicing",
|
|
27
|
+
"reharmonization",
|
|
28
|
+
"arrangement",
|
|
29
|
+
"generative-music"
|
|
24
30
|
],
|
|
25
31
|
"engines": {
|
|
26
|
-
"node": ">=22
|
|
27
|
-
},
|
|
28
|
-
"packageManager": "yarn@4.17.0",
|
|
29
|
-
"volta": {
|
|
30
|
-
"node": "22.22.3",
|
|
31
|
-
"yarn": "4.17.0"
|
|
32
|
+
"node": ">=22"
|
|
32
33
|
},
|
|
34
|
+
"packageManager": "yarn@4.18.0",
|
|
33
35
|
"main": "./dist/index.cjs",
|
|
34
36
|
"module": "./dist/index.js",
|
|
35
37
|
"types": "./dist/index.d.ts",
|
|
@@ -118,6 +120,7 @@
|
|
|
118
120
|
"files": [
|
|
119
121
|
"dist",
|
|
120
122
|
"README.md",
|
|
123
|
+
"README_ja.md",
|
|
121
124
|
"LICENSE"
|
|
122
125
|
],
|
|
123
126
|
"sideEffects": false,
|
|
@@ -127,7 +130,8 @@
|
|
|
127
130
|
"lint": "biome check .",
|
|
128
131
|
"lint:fix": "biome check --write .",
|
|
129
132
|
"format": "biome format --write .",
|
|
130
|
-
"
|
|
133
|
+
"examples": "vitest list >/dev/null",
|
|
134
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json && yarn examples && tsc -p tsconfig.examples.json",
|
|
131
135
|
"test": "vitest run",
|
|
132
136
|
"test:watch": "vitest",
|
|
133
137
|
"test:coverage": "vitest run --coverage",
|
|
@@ -137,8 +141,9 @@
|
|
|
137
141
|
"prepublishOnly": "yarn build"
|
|
138
142
|
},
|
|
139
143
|
"devDependencies": {
|
|
140
|
-
"@biomejs/biome": "2.5.
|
|
144
|
+
"@biomejs/biome": "2.5.8",
|
|
141
145
|
"@libraz/typedoc-theme": "^0.1.1",
|
|
146
|
+
"@types/node": "^26.2.0",
|
|
142
147
|
"@vitest/coverage-v8": "4.1.10",
|
|
143
148
|
"tsup": "8.5.1",
|
|
144
149
|
"typedoc": "0.28.20",
|
package/dist/chunk-36N73KZ3.cjs
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _chunk7MGZ7D62cjs = require('./chunk-7MGZ7D62.cjs');
|
|
15
|
-
|
|
16
|
-
// src/core/meter/index.ts
|
|
17
|
-
var EPS = 1e-9;
|
|
18
|
-
function isMultiple(value, unit) {
|
|
19
|
-
if (unit === 0) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
const ratio = value / unit;
|
|
23
|
-
return Math.abs(ratio - Math.round(ratio)) < EPS;
|
|
24
|
-
}
|
|
25
|
-
function parseTimeSignature(text) {
|
|
26
|
-
const match = /^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(text);
|
|
27
|
-
if (!match) {
|
|
28
|
-
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(`Invalid time signature: ${text}`);
|
|
29
|
-
}
|
|
30
|
-
const numerator = Number.parseInt(_nullishCoalesce(match[1], () => ( "")), 10);
|
|
31
|
-
const denominator = Number.parseInt(_nullishCoalesce(match[2], () => ( "")), 10);
|
|
32
|
-
if (!Number.isSafeInteger(numerator) || !Number.isSafeInteger(denominator) || numerator <= 0 || denominator <= 0) {
|
|
33
|
-
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(`Invalid time signature: ${text}`);
|
|
34
|
-
}
|
|
35
|
-
return _chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, { numerator, denominator }, `time signature ${text}`);
|
|
36
|
-
}
|
|
37
|
-
function formatTimeSignature(ts, opts = {}) {
|
|
38
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
39
|
-
if (opts.grouping === true && ts.grouping !== void 0) {
|
|
40
|
-
return `${ts.grouping.join("+")}/${ts.denominator}`;
|
|
41
|
-
}
|
|
42
|
-
return `${ts.numerator}/${ts.denominator}`;
|
|
43
|
-
}
|
|
44
|
-
function isCompound(ts) {
|
|
45
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
46
|
-
return _chunk7MGZ7D62cjs.isCompoundNumerator.call(void 0, ts.numerator) && !_chunk7MGZ7D62cjs.isAdditiveReading.call(void 0, ts);
|
|
47
|
-
}
|
|
48
|
-
function beatsPerBar(ts) {
|
|
49
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
50
|
-
return _chunk7MGZ7D62cjs.barBeatsOf.call(void 0, ts);
|
|
51
|
-
}
|
|
52
|
-
function pulsesPerBar(ts) {
|
|
53
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
54
|
-
return _chunk7MGZ7D62cjs.pulseCountOf.call(void 0, ts);
|
|
55
|
-
}
|
|
56
|
-
function isGroupHead(grouping, pulseIndex) {
|
|
57
|
-
let acc = 0;
|
|
58
|
-
for (const g of grouping) {
|
|
59
|
-
if (acc === pulseIndex) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
acc += g;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
function beatToBarPosition(beatInQuarters, ts) {
|
|
67
|
-
_chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, beatInQuarters, "beat");
|
|
68
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
69
|
-
const barLen = _chunk7MGZ7D62cjs.barBeatsOf.call(void 0, ts);
|
|
70
|
-
const bar = Math.floor(beatInQuarters / barLen);
|
|
71
|
-
return { bar, beat: beatInQuarters - bar * barLen };
|
|
72
|
-
}
|
|
73
|
-
function pulseBeats(ts) {
|
|
74
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
75
|
-
return _chunk7MGZ7D62cjs.pulseBeatsOf.call(void 0, ts);
|
|
76
|
-
}
|
|
77
|
-
function barPositionToPulse(pos, ts) {
|
|
78
|
-
_chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, pos.beat, "position.beat");
|
|
79
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
80
|
-
return pos.beat / _chunk7MGZ7D62cjs.pulseBeatsOf.call(void 0, ts) + 1;
|
|
81
|
-
}
|
|
82
|
-
function formatBarPosition(beatInQuarters, ts, decimals = 2) {
|
|
83
|
-
const position = beatToBarPosition(beatInQuarters, ts);
|
|
84
|
-
const pulse = barPositionToPulse(position, ts);
|
|
85
|
-
const rounded = Number(pulse.toFixed(decimals));
|
|
86
|
-
return `${position.bar + 1}.${rounded}`;
|
|
87
|
-
}
|
|
88
|
-
function barPositionToBeat(pos, ts) {
|
|
89
|
-
_chunk7MGZ7D62cjs.assertInteger.call(void 0, pos.bar, "bar position bar");
|
|
90
|
-
_chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, pos.beat, "bar position beat");
|
|
91
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
92
|
-
return pos.bar * _chunk7MGZ7D62cjs.barBeatsOf.call(void 0, ts) + pos.beat;
|
|
93
|
-
}
|
|
94
|
-
function metricWeight(beatInQuarters, ts) {
|
|
95
|
-
_chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, beatInQuarters, "beat");
|
|
96
|
-
_chunk7MGZ7D62cjs.assertTimeSignature.call(void 0, ts);
|
|
97
|
-
const barLen = _chunk7MGZ7D62cjs.barBeatsOf.call(void 0, ts);
|
|
98
|
-
const beat = beatInQuarters - Math.floor(beatInQuarters / barLen) * barLen;
|
|
99
|
-
const pulse = _chunk7MGZ7D62cjs.pulseBeatsOf.call(void 0, ts);
|
|
100
|
-
if (!isMultiple(beat, pulse)) {
|
|
101
|
-
return 0;
|
|
102
|
-
}
|
|
103
|
-
const pulses = _chunk7MGZ7D62cjs.pulseCountOf.call(void 0, ts);
|
|
104
|
-
const pulseIndex = Math.round(beat / pulse) % pulses;
|
|
105
|
-
if (pulseIndex === 0) {
|
|
106
|
-
return 3;
|
|
107
|
-
}
|
|
108
|
-
const grouping = ts.grouping;
|
|
109
|
-
if (grouping !== void 0) {
|
|
110
|
-
return isGroupHead(grouping, pulseIndex) ? 2 : 1;
|
|
111
|
-
}
|
|
112
|
-
if (pulses % 2 === 0 && pulseIndex === pulses / 2) {
|
|
113
|
-
return 2;
|
|
114
|
-
}
|
|
115
|
-
return 1;
|
|
116
|
-
}
|
|
117
|
-
function isStrongBeat(beatInQuarters, ts) {
|
|
118
|
-
return metricWeight(beatInQuarters, ts) >= 2;
|
|
119
|
-
}
|
|
120
|
-
function tuplet(totalBeats, count) {
|
|
121
|
-
_chunk7MGZ7D62cjs.assertRange.call(void 0, totalBeats, 0, Number.MAX_SAFE_INTEGER, "tuplet total beats");
|
|
122
|
-
_chunk7MGZ7D62cjs.assertPositiveInt.call(void 0, count, "tuplet count");
|
|
123
|
-
return new Array(count).fill(totalBeats / count);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/core/event-index/index.ts
|
|
127
|
-
var EPS2 = 1e-9;
|
|
128
|
-
function upperBound(values, beat) {
|
|
129
|
-
let low = 0;
|
|
130
|
-
let high = values.length;
|
|
131
|
-
while (low < high) {
|
|
132
|
-
const middle = Math.floor((low + high) / 2);
|
|
133
|
-
if ((_nullishCoalesce(_optionalChain([values, 'access', _ => _[middle], 'optionalAccess', _2 => _2.note, 'access', _3 => _3.startBeat]), () => ( Number.POSITIVE_INFINITY))) <= beat) {
|
|
134
|
-
low = middle + 1;
|
|
135
|
-
} else {
|
|
136
|
-
high = middle;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return low;
|
|
140
|
-
}
|
|
141
|
-
function createNoteEventIndex(events, options = {}) {
|
|
142
|
-
_chunk7MGZ7D62cjs.assertNoteEvents.call(void 0, events, _nullishCoalesce(options.name, () => ( "note events")), options);
|
|
143
|
-
const tieBreak = _nullishCoalesce(options.tieBreak, () => ( "highest"));
|
|
144
|
-
const notes = events.map((note, originalIndex) => ({
|
|
145
|
-
note,
|
|
146
|
-
originalIndex,
|
|
147
|
-
endBeat: note.startBeat + note.durationBeat
|
|
148
|
-
})).sort((a, b) => a.note.startBeat - b.note.startBeat || a.originalIndex - b.originalIndex);
|
|
149
|
-
let prefixMaxEnd;
|
|
150
|
-
const maxEndUpTo = (index) => {
|
|
151
|
-
if (prefixMaxEnd === void 0) {
|
|
152
|
-
const prefix = [];
|
|
153
|
-
let maxEnd = Number.NEGATIVE_INFINITY;
|
|
154
|
-
for (const indexed of notes) {
|
|
155
|
-
maxEnd = Math.max(maxEnd, indexed.endBeat);
|
|
156
|
-
prefix.push(maxEnd);
|
|
157
|
-
}
|
|
158
|
-
prefixMaxEnd = prefix;
|
|
159
|
-
}
|
|
160
|
-
return _nullishCoalesce(prefixMaxEnd[index], () => ( Number.NEGATIVE_INFINITY));
|
|
161
|
-
};
|
|
162
|
-
return {
|
|
163
|
-
notes,
|
|
164
|
-
at(beat) {
|
|
165
|
-
let index = upperBound(notes, beat + EPS2) - 1;
|
|
166
|
-
let best;
|
|
167
|
-
while (index >= 0) {
|
|
168
|
-
if (maxEndUpTo(index) <= beat + EPS2) {
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
const indexed = notes[index];
|
|
172
|
-
index -= 1;
|
|
173
|
-
if (indexed === void 0 || indexed.note.durationBeat <= 0 || indexed.note.startBeat - EPS2 > beat || beat >= indexed.endBeat - EPS2) {
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (best === void 0) {
|
|
177
|
-
best = indexed;
|
|
178
|
-
if (tieBreak === "last") {
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
if (Math.abs(indexed.note.startBeat - best.note.startBeat) >= EPS2) {
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
const higher = indexed.note.pitch > best.note.pitch;
|
|
187
|
-
if (tieBreak === "highest" ? higher : !higher) {
|
|
188
|
-
best = indexed;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return best;
|
|
192
|
-
},
|
|
193
|
-
attacksAt(beat) {
|
|
194
|
-
let index = upperBound(notes, beat + EPS2) - 1;
|
|
195
|
-
while (index >= 0) {
|
|
196
|
-
const candidate = notes[index];
|
|
197
|
-
if (candidate === void 0 || Math.abs(candidate.note.startBeat - beat) >= EPS2) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
if (candidate.note.durationBeat > 0) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
index -= 1;
|
|
204
|
-
}
|
|
205
|
-
return false;
|
|
206
|
-
},
|
|
207
|
-
onsetsBetween(startBeat, endBeat) {
|
|
208
|
-
const result = [];
|
|
209
|
-
let index = upperBound(notes, startBeat + EPS2);
|
|
210
|
-
while (index < notes.length) {
|
|
211
|
-
const indexed = notes[index];
|
|
212
|
-
const onset = _optionalChain([indexed, 'optionalAccess', _4 => _4.note, 'access', _5 => _5.startBeat]);
|
|
213
|
-
if (indexed === void 0 || onset === void 0 || onset >= endBeat - EPS2) {
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
index += 1;
|
|
217
|
-
if (indexed.note.durationBeat <= 0) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const previous = result[result.length - 1];
|
|
221
|
-
if (previous === void 0 || Math.abs(previous - onset) >= EPS2) {
|
|
222
|
-
result.push(onset);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
exports.parseTimeSignature = parseTimeSignature; exports.formatTimeSignature = formatTimeSignature; exports.isCompound = isCompound; exports.beatsPerBar = beatsPerBar; exports.pulsesPerBar = pulsesPerBar; exports.beatToBarPosition = beatToBarPosition; exports.pulseBeats = pulseBeats; exports.barPositionToPulse = barPositionToPulse; exports.formatBarPosition = formatBarPosition; exports.barPositionToBeat = barPositionToBeat; exports.metricWeight = metricWeight; exports.isStrongBeat = isStrongBeat; exports.tuplet = tuplet; exports.createNoteEventIndex = createNoteEventIndex;
|
|
246
|
-
//# sourceMappingURL=chunk-36N73KZ3.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/libcantus/libcantus/dist/chunk-36N73KZ3.cjs","../src/core/meter/index.ts","../src/core/event-index/index.ts"],"names":[],"mappings":"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","file":"/home/runner/work/libcantus/libcantus/dist/chunk-36N73KZ3.cjs","sourcesContent":[null,"/**\n * Meter and time signatures: bar/beat arithmetic, simple vs. compound meters,\n * metric-accent hierarchy, and tuplet subdivision.\n *\n * Positions and durations are measured in quarter-note beats, matching the rest\n * of the library's beat convention (four quarter-note beats per bar in 4/4).\n */\n\nimport { InvalidInputError } from '../errors/index.js';\nimport {\n assertFiniteNumber,\n assertInteger,\n assertPositiveInt,\n assertRange,\n assertTimeSignature,\n} from '../validation/index.js';\nimport {\n barBeatsOf,\n isAdditiveReading,\n isCompoundNumerator,\n pulseBeatsOf,\n pulseCountOf,\n} from './internal.js';\n\n/**\n * A time signature as a numerator over a note-value denominator.\n *\n * @category Rhythm & Meter\n */\nexport type TimeSignature = {\n numerator: number;\n denominator: number;\n /**\n * Optional additive grouping of the bar's main pulses, as the felt-beat\n * lengths in pulses — e.g. `[2, 2, 3]` for a 2+2+3 reading of 7/8, or\n * `[3, 2]` for 5/8. The entries must be positive integers summing to the\n * numerator.\n *\n * A compound numerator accepts both readings. 9/8 groups its three dotted\n * pulses as `[1, 1, 1]`, or reads additively as `[2, 2, 2, 3]` quavers; a\n * grouping that sums to the numerator selects the additive reading, so\n * aksak and other additive metres are expressible. {@link pulsesPerBar}\n * and {@link isCompound} follow whichever reading the grouping selects.\n *\n * When present, the head pulse of each group (other than the downbeat) is\n * treated as a secondary strong pulse by\n * {@link metricWeight}/{@link isStrongBeat}; when absent, all main pulses\n * are weighted equally as flat, evenly divided pulses.\n */\n grouping?: number[];\n};\n\n/**\n * A position expressed as a bar index and a quarter-note offset within the bar.\n *\n * @category Rhythm & Meter\n */\nexport type BarPosition = {\n /** 0-based bar index. {@link formatBarPosition} renders it 1-based. */\n bar: number;\n /**\n * Quarter-note offset from the start of the bar — not the felt beat. In 6/8\n * the second felt beat is at `beat: 1.5`; {@link barPositionToPulse} converts\n * to felt-beat numbering.\n */\n beat: number;\n};\n\nconst EPS = 1e-9;\n\n/** Whether `value` is an integer multiple of `unit` (within a float tolerance). */\nfunction isMultiple(value: number, unit: number): boolean {\n if (unit === 0) {\n return false;\n }\n const ratio = value / unit;\n return Math.abs(ratio - Math.round(ratio)) < EPS;\n}\n\n/**\n * Parse a time signature such as `\"4/4\"` or `\"6/8\"`.\n *\n * @param text The signature text.\n * @returns The parsed time signature.\n * @throws If the text is not `n/d` with positive integers.\n * @example\n * ```ts\n * import { parseTimeSignature } from '@libraz/libcantus';\n * parseTimeSignature('6/8'); // { numerator: 6, denominator: 8 }\n * ```\n * @category Rhythm & Meter\n */\nexport function parseTimeSignature(text: string): TimeSignature {\n const match = /^\\s*(\\d+)\\s*\\/\\s*(\\d+)\\s*$/.exec(text);\n if (!match) {\n throw new InvalidInputError(`Invalid time signature: ${text}`);\n }\n const numerator = Number.parseInt(match[1] ?? '', 10);\n const denominator = Number.parseInt(match[2] ?? '', 10);\n if (\n !Number.isSafeInteger(numerator) ||\n !Number.isSafeInteger(denominator) ||\n numerator <= 0 ||\n denominator <= 0\n ) {\n throw new InvalidInputError(`Invalid time signature: ${text}`);\n }\n // The same signature every consumer validates, validated here too: parsing\n // a signature the rest of the library rejects only moves the failure.\n return assertTimeSignature({ numerator, denominator }, `time signature ${text}`);\n}\n\n/**\n * Render a time signature as `\"n/d\"`, or as `\"a+b+c/d\"` when it carries an\n * additive grouping and `grouping` is requested.\n *\n * The plain form drops the grouping, so a round trip through it reads 7/8 as\n * flat rather than as 2+2+3; ask for the additive form to keep it.\n *\n * @param ts The time signature.\n * @param opts Set `grouping: true` to render an additive grouping.\n * @returns The formatted signature.\n * @example\n * ```ts\n * import { formatTimeSignature } from '@libraz/libcantus';\n * const aksak = { numerator: 7, denominator: 8, grouping: [2, 2, 3] };\n * formatTimeSignature(aksak); // '7/8'\n * formatTimeSignature(aksak, { grouping: true }); // '2+2+3/8'\n * ```\n * @category Rhythm & Meter\n */\nexport function formatTimeSignature(ts: TimeSignature, opts: { grouping?: boolean } = {}): string {\n assertTimeSignature(ts);\n if (opts.grouping === true && ts.grouping !== undefined) {\n return `${ts.grouping.join('+')}/${ts.denominator}`;\n }\n return `${ts.numerator}/${ts.denominator}`;\n}\n\n/**\n * Whether a meter is compound: its main pulses each divide into three, as in\n * 6/8, 9/8, 12/8, or 6/4. Compound meters are those whose numerator is a\n * multiple of three greater than three, independent of the denominator. Meters\n * like 3/8 and 3/4 (simple triples, numerator 3) are not compound, and neither\n * is a signature whose {@link TimeSignature.grouping} selects the additive\n * reading (9/8 as 2+2+2+3).\n *\n * @param ts The time signature.\n * @returns True for compound meters.\n * @category Rhythm & Meter\n */\nexport function isCompound(ts: TimeSignature): boolean {\n assertTimeSignature(ts);\n return isCompoundNumerator(ts.numerator) && !isAdditiveReading(ts);\n}\n\n/**\n * Length of a bar in quarter-note beats.\n *\n * @param ts The time signature.\n * @returns The bar length in quarter notes.\n * @category Rhythm & Meter\n */\nexport function beatsPerBar(ts: TimeSignature): number {\n assertTimeSignature(ts);\n return barBeatsOf(ts);\n}\n\n/**\n * Number of main pulses (felt beats) per bar: the numerator for simple meters,\n * a third of it for compound meters.\n *\n * For additive/irregular meters such as 7/8 or 5/8 this counts the raw pulses\n * (7 and 5 respectively), which are otherwise felt as flat, evenly divided and\n * equally accented pulses. To recover a 2+2+3 or 3+2 felt-beat grouping, set\n * {@link TimeSignature.grouping}; {@link metricWeight} then accents each\n * group's head pulse.\n *\n * @param ts The time signature.\n * @returns The pulse count per bar.\n * @category Rhythm & Meter\n */\nexport function pulsesPerBar(ts: TimeSignature): number {\n assertTimeSignature(ts);\n return pulseCountOf(ts);\n}\n\n/** Whether `pulseIndex` is the head pulse of one of the additive groups. */\nfunction isGroupHead(grouping: number[], pulseIndex: number): boolean {\n let acc = 0;\n for (const g of grouping) {\n if (acc === pulseIndex) {\n return true;\n }\n acc += g;\n }\n return false;\n}\n\n/**\n * Convert an absolute quarter-note position to a bar index and in-bar offset.\n *\n * @param beatInQuarters Absolute position in quarter-note beats.\n * @param ts The time signature.\n * @returns The bar and in-bar quarter-note offset.\n * @example\n * ```ts\n * import { parseTimeSignature, beatToBarPosition } from '@libraz/libcantus';\n * const ts = parseTimeSignature('4/4');\n * beatToBarPosition(5, ts); // { bar: 1, beat: 1 }\n * ```\n * @category Rhythm & Meter\n */\nexport function beatToBarPosition(beatInQuarters: number, ts: TimeSignature): BarPosition {\n assertFiniteNumber(beatInQuarters, 'beat');\n assertTimeSignature(ts);\n const barLen = barBeatsOf(ts);\n const bar = Math.floor(beatInQuarters / barLen);\n return { bar, beat: beatInQuarters - bar * barLen };\n}\n\n/**\n * Length of one felt beat (main pulse) in quarter-note beats.\n *\n * A quarter note in simple meters, a dotted quarter in compound ones, and one\n * denominator unit in an additive metre. Position displays, click tracks, and\n * score export are all written against this length.\n *\n * @param ts The time signature.\n * @returns The pulse length in quarter-note beats.\n * @example\n * ```ts\n * import { parseTimeSignature, pulseBeats } from '@libraz/libcantus';\n * pulseBeats(parseTimeSignature('6/8')); // 1.5\n * ```\n * @category Rhythm & Meter\n */\nexport function pulseBeats(ts: TimeSignature): number {\n assertTimeSignature(ts);\n return pulseBeatsOf(ts);\n}\n\n/**\n * The felt-beat number of a bar position, 1-based.\n *\n * {@link BarPosition.beat} is a quarter-note offset, so in 6/8 the second felt\n * beat reads as 1.5. This is the number a musician says and a position display\n * shows.\n *\n * @param pos The bar position.\n * @param ts The time signature.\n * @returns The 1-based felt-beat number, fractional between pulses.\n * @example\n * ```ts\n * import { barPositionToPulse, parseTimeSignature } from '@libraz/libcantus';\n * barPositionToPulse({ bar: 0, beat: 1.5 }, parseTimeSignature('6/8')); // 2\n * ```\n * @category Rhythm & Meter\n */\nexport function barPositionToPulse(pos: BarPosition, ts: TimeSignature): number {\n assertFiniteNumber(pos.beat, 'position.beat');\n assertTimeSignature(ts);\n return pos.beat / pulseBeatsOf(ts) + 1;\n}\n\n/**\n * Render an absolute position as the `bar.beat` a DAW or a score shows:\n * 1-based bar, 1-based felt beat.\n *\n * @param beatInQuarters Absolute position in quarter-note beats.\n * @param ts The time signature.\n * @param decimals Digits of the fractional beat to keep.\n * @returns The formatted position, e.g. `'3.2'` for bar 3, felt beat 2.\n * @example\n * ```ts\n * import { formatBarPosition, parseTimeSignature } from '@libraz/libcantus';\n * formatBarPosition(7.5, parseTimeSignature('6/8')); // '3.2'\n * ```\n * @category Rhythm & Meter\n */\nexport function formatBarPosition(beatInQuarters: number, ts: TimeSignature, decimals = 2): string {\n const position = beatToBarPosition(beatInQuarters, ts);\n const pulse = barPositionToPulse(position, ts);\n const rounded = Number(pulse.toFixed(decimals));\n return `${position.bar + 1}.${rounded}`;\n}\n\n/**\n * Convert a bar index and in-bar offset back to an absolute quarter-note\n * position.\n *\n * @param pos The bar position.\n * @param ts The time signature.\n * @returns The absolute position in quarter-note beats.\n * @category Rhythm & Meter\n */\nexport function barPositionToBeat(pos: BarPosition, ts: TimeSignature): number {\n assertInteger(pos.bar, 'bar position bar');\n assertFiniteNumber(pos.beat, 'bar position beat');\n assertTimeSignature(ts);\n return pos.bar * barBeatsOf(ts) + pos.beat;\n}\n\n/**\n * Metric weight of a position within its bar, on a 0–3 scale:\n * 3 the downbeat, 2 a secondary strong pulse, 1 any other main pulse, and 0 an\n * off-pulse subdivision.\n *\n * The secondary strong pulse is the bar's midpoint in even simple/compound\n * meters. For an additive/irregular meter with {@link TimeSignature.grouping}\n * set (e.g. `[2, 2, 3]` for 7/8), each group's head pulse other than the\n * downbeat is the secondary strong pulse instead; without a grouping every\n * non-downbeat main pulse of such a meter weighs 1 (flat, evenly divided\n * pulses).\n *\n * @param beatInQuarters Absolute or in-bar quarter-note position.\n * @param ts The time signature.\n * @returns The metric weight (0–3).\n * @throws If the time signature is malformed, including a grouping that is not\n * a positive-integer list summing to the pulse count or the numerator.\n * @example\n * ```ts\n * import { parseTimeSignature, metricWeight } from '@libraz/libcantus';\n * const ts = parseTimeSignature('4/4');\n * metricWeight(0, ts); // 3 (the downbeat)\n * ```\n * @category Rhythm & Meter\n */\nexport function metricWeight(beatInQuarters: number, ts: TimeSignature): number {\n assertFiniteNumber(beatInQuarters, 'beat');\n assertTimeSignature(ts);\n const barLen = barBeatsOf(ts);\n const beat = beatInQuarters - Math.floor(beatInQuarters / barLen) * barLen;\n const pulse = pulseBeatsOf(ts);\n if (!isMultiple(beat, pulse)) {\n return 0;\n }\n const pulses = pulseCountOf(ts);\n const pulseIndex = Math.round(beat / pulse) % pulses;\n if (pulseIndex === 0) {\n return 3;\n }\n const grouping = ts.grouping;\n if (grouping !== undefined) {\n return isGroupHead(grouping, pulseIndex) ? 2 : 1;\n }\n if (pulses % 2 === 0 && pulseIndex === pulses / 2) {\n return 2;\n }\n return 1;\n}\n\n/**\n * Whether a position is metrically accented (weight 2 or more — a downbeat or a\n * secondary strong pulse).\n *\n * @param beatInQuarters Absolute or in-bar quarter-note position.\n * @param ts The time signature.\n * @returns True on strong beats.\n * @category Rhythm & Meter\n */\nexport function isStrongBeat(beatInQuarters: number, ts: TimeSignature): boolean {\n return metricWeight(beatInQuarters, ts) >= 2;\n}\n\n/**\n * Subdivide a span into `count` equal tuplet durations (e.g. an eighth-note\n * triplet is `tuplet(1, 3)`).\n *\n * @param totalBeats Total span in quarter-note beats.\n * @param count Number of equal parts.\n * @returns `count` equal durations summing to `totalBeats`.\n * @throws If `count` is not a positive integer.\n * @category Rhythm & Meter\n */\nexport function tuplet(totalBeats: number, count: number): number[] {\n assertRange(totalBeats, 0, Number.MAX_SAFE_INTEGER, 'tuplet total beats');\n assertPositiveInt(count, 'tuplet count');\n return new Array<number>(count).fill(totalBeats / count);\n}\n","import type { NoteEvent } from '../types.js';\nimport { assertNoteEvents } from '../validation/index.js';\n\n/**\n * A validated note retaining its position in the caller's original array.\n *\n * @category Core\n */\nexport type IndexedNoteEvent = {\n note: NoteEvent;\n originalIndex: number;\n endBeat: number;\n};\n\n/**\n * Which note wins when several sound from the same onset.\n *\n * `'highest'` and `'lowest'` name a voice, so the answer does not depend on the\n * order the caller happened to store the chord in; `'last'` takes the one\n * latest in the input array.\n *\n * @category Core\n */\nexport type OnsetTieBreak = 'highest' | 'lowest' | 'last';\n\n/**\n * Binary-searchable, stable-sorted index over note onsets and active spans.\n *\n * @category Core\n */\nexport type NoteEventIndex = {\n notes: IndexedNoteEvent[];\n /**\n * Latest-onset note sounding at `beat`. Simultaneous onsets are resolved by\n * the index's {@link OnsetTieBreak}.\n */\n at: (beat: number) => IndexedNoteEvent | undefined;\n /** Whether one or more sounding notes attack at `beat`. */\n attacksAt: (beat: number) => boolean;\n /** Unique sounding-note attack beats strictly inside `(startBeat, endBeat)`. */\n onsetsBetween: (startBeat: number, endBeat: number) => number[];\n};\n\nconst EPS = 1e-9;\n\nfunction upperBound(values: IndexedNoteEvent[], beat: number): number {\n let low = 0;\n let high = values.length;\n while (low < high) {\n const middle = Math.floor((low + high) / 2);\n if ((values[middle]?.note.startBeat ?? Number.POSITIVE_INFINITY) <= beat) {\n low = middle + 1;\n } else {\n high = middle;\n }\n }\n return low;\n}\n\n/**\n * Validate and stable-sort note events once, then expose logarithmic onset and\n * active-note lookups. Non-positive-duration notes may be retained for callers\n * that intentionally filter them later, but never count as sounding.\n *\n * @category Core\n */\nexport function createNoteEventIndex(\n events: readonly NoteEvent[],\n options: {\n allowNonPositiveDuration?: boolean;\n tieBreak?: OnsetTieBreak;\n budget?: number;\n /** What the events are, for the validation error message. */\n name?: string;\n } = {},\n): NoteEventIndex {\n assertNoteEvents(events, options.name ?? 'note events', options);\n const tieBreak = options.tieBreak ?? 'highest';\n const notes = events\n .map((note, originalIndex) => ({\n note,\n originalIndex,\n endBeat: note.startBeat + note.durationBeat,\n }))\n .sort((a, b) => a.note.startBeat - b.note.startBeat || a.originalIndex - b.originalIndex);\n // Built on the first `at` call rather than up front: several callers use this\n // only to validate and sort, and never ask what sounds at a beat.\n let prefixMaxEnd: number[] | undefined;\n const maxEndUpTo = (index: number): number => {\n if (prefixMaxEnd === undefined) {\n const prefix: number[] = [];\n let maxEnd = Number.NEGATIVE_INFINITY;\n for (const indexed of notes) {\n maxEnd = Math.max(maxEnd, indexed.endBeat);\n prefix.push(maxEnd);\n }\n prefixMaxEnd = prefix;\n }\n return prefixMaxEnd[index] ?? Number.NEGATIVE_INFINITY;\n };\n\n return {\n notes,\n at(beat) {\n let index = upperBound(notes, beat + EPS) - 1;\n let best: IndexedNoteEvent | undefined;\n while (index >= 0) {\n if (maxEndUpTo(index) <= beat + EPS) {\n break;\n }\n const indexed = notes[index];\n index -= 1;\n if (\n indexed === undefined ||\n indexed.note.durationBeat <= 0 ||\n indexed.note.startBeat - EPS > beat ||\n beat >= indexed.endBeat - EPS\n ) {\n continue;\n }\n if (best === undefined) {\n best = indexed;\n if (tieBreak === 'last') {\n break;\n }\n continue;\n }\n // Only notes from the same onset compete: a later onset always wins.\n if (Math.abs(indexed.note.startBeat - best.note.startBeat) >= EPS) {\n break;\n }\n const higher = indexed.note.pitch > best.note.pitch;\n if (tieBreak === 'highest' ? higher : !higher) {\n best = indexed;\n }\n }\n return best;\n },\n attacksAt(beat) {\n // Only a sounding note attacks: a zero-length artefact must not make\n // `attacksAt(b)` true on a beat where `at(b)` finds nothing.\n let index = upperBound(notes, beat + EPS) - 1;\n while (index >= 0) {\n const candidate = notes[index];\n if (candidate === undefined || Math.abs(candidate.note.startBeat - beat) >= EPS) {\n return false;\n }\n if (candidate.note.durationBeat > 0) {\n return true;\n }\n index -= 1;\n }\n return false;\n },\n onsetsBetween(startBeat, endBeat) {\n const result: number[] = [];\n let index = upperBound(notes, startBeat + EPS);\n while (index < notes.length) {\n const indexed = notes[index];\n const onset = indexed?.note.startBeat;\n if (indexed === undefined || onset === undefined || onset >= endBeat - EPS) {\n break;\n }\n index += 1;\n if (indexed.note.durationBeat <= 0) {\n continue;\n }\n const previous = result[result.length - 1];\n if (previous === undefined || Math.abs(previous - onset) >= EPS) {\n result.push(onset);\n }\n }\n return result;\n },\n };\n}\n"]}
|