@tspro/web-music-score 5.2.0 → 5.4.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/README.md +15 -12
- package/dist/audio/index.d.mts +1 -1
- package/dist/audio/index.d.ts +1 -1
- package/dist/audio/index.js +3 -3
- package/dist/audio/index.mjs +6 -6
- package/dist/audio-cg/index.js +1 -1
- package/dist/audio-cg/index.mjs +3 -3
- package/dist/audio-synth/index.js +1 -1
- package/dist/audio-synth/index.mjs +3 -3
- package/dist/{chunk-LC5JMIVF.mjs → chunk-AUT4C6TY.mjs} +2 -2
- package/dist/{chunk-XUGM7SCC.mjs → chunk-MHDBTCVG.mjs} +21 -21
- package/dist/{chunk-6S5BDSCM.mjs → chunk-QGMOI7AP.mjs} +2 -2
- package/dist/chunk-ZWUBO5EW.mjs +37 -0
- package/dist/core/index.js +2 -2
- package/dist/core/index.mjs +6 -31
- package/dist/{guitar-BsSayRsH.d.ts → guitar-CarHGDAt.d.ts} +1 -1
- package/dist/{guitar-DdexKdN6.d.mts → guitar-DXlB-9vK.d.mts} +1 -1
- package/dist/iife/audio-cg.global.js +1 -1
- package/dist/iife/index.global.js +18 -11
- package/dist/{music-objects-CwPOlqFi.d.ts → music-objects-3Esbz7ij.d.ts} +261 -381
- package/dist/{music-objects-CB05XryE.d.mts → music-objects-ONIuVUgs.d.mts} +261 -381
- package/dist/{note-CgCIBwvR.d.ts → note-CJuq5aBy.d.ts} +13 -1
- package/dist/{note-eA2xPPiG.d.mts → note-RVXvpfyV.d.mts} +13 -1
- package/dist/pieces/index.d.mts +13 -4
- package/dist/pieces/index.d.ts +13 -4
- package/dist/pieces/index.js +20 -9
- package/dist/pieces/index.mjs +20 -10
- package/dist/react-ui/index.d.mts +10 -10
- package/dist/react-ui/index.d.ts +10 -10
- package/dist/react-ui/index.js +19 -21
- package/dist/react-ui/index.mjs +23 -25
- package/dist/{scale-CBW4eTz7.d.ts → scale-C8gHC448.d.mts} +3 -3
- package/dist/{scale-DQP3b9Zx.d.mts → scale-DulPFco_.d.ts} +3 -3
- package/dist/score/index.d.mts +235 -7
- package/dist/score/index.d.ts +235 -7
- package/dist/score/index.js +2064 -1807
- package/dist/score/index.mjs +1897 -1671
- package/dist/{tempo-dkctPkCS.d.mts → tempo-BlCGZuYg.d.mts} +14 -2
- package/dist/{tempo-DMt3iwz9.d.ts → tempo-BnUjm25M.d.ts} +14 -2
- package/dist/theory/index.d.mts +6 -6
- package/dist/theory/index.d.ts +6 -6
- package/dist/theory/index.js +88 -86
- package/dist/theory/index.mjs +85 -81
- package/package.json +5 -4
package/dist/theory/index.mjs
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
/* WebMusicScore v5.
|
|
1
|
+
/* WebMusicScore v5.4.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
|
|
2
2
|
import {
|
|
3
3
|
NoteLength,
|
|
4
4
|
NoteLengthProps,
|
|
5
5
|
RhythmProps,
|
|
6
6
|
Tuplet,
|
|
7
|
+
isNoteLength,
|
|
8
|
+
isTupletRatio,
|
|
7
9
|
validateNoteLength,
|
|
8
10
|
validateTupletRatio
|
|
9
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-MHDBTCVG.mjs";
|
|
10
12
|
import {
|
|
11
13
|
__publicField
|
|
12
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-AUT4C6TY.mjs";
|
|
13
15
|
|
|
14
16
|
// src/theory/chord.ts
|
|
15
|
-
import { Utils as
|
|
17
|
+
import { IndexArray, Utils as Utils4 } from "@tspro/ts-utils-lib";
|
|
16
18
|
|
|
17
19
|
// src/theory/note.ts
|
|
18
|
-
import {
|
|
20
|
+
import { Guard as Guard2, UniMap } from "@tspro/ts-utils-lib";
|
|
19
21
|
|
|
20
22
|
// src/theory/types.ts
|
|
21
|
-
import { Utils } from "@tspro/ts-utils-lib";
|
|
23
|
+
import { Guard, Utils } from "@tspro/ts-utils-lib";
|
|
22
24
|
import { MusicError, MusicErrorType } from "@tspro/web-music-score/core";
|
|
23
25
|
var SymbolSet = /* @__PURE__ */ ((SymbolSet2) => {
|
|
24
26
|
SymbolSet2[SymbolSet2["Ascii"] = 0] = "Ascii";
|
|
@@ -33,7 +35,7 @@ var PitchNotation = /* @__PURE__ */ ((PitchNotation2) => {
|
|
|
33
35
|
var PitchNotationList = Utils.Enum.getEnumValues(PitchNotation);
|
|
34
36
|
var DefaultPitchNotation = 0 /* Scientific */;
|
|
35
37
|
function validatePitchNotation(pn) {
|
|
36
|
-
if (
|
|
38
|
+
if (Guard.isEnumValue(pn, PitchNotation)) {
|
|
37
39
|
return pn;
|
|
38
40
|
} else {
|
|
39
41
|
throw new MusicError(MusicErrorType.InvalidArg, `Invalid pitchNotation: ${pn}`);
|
|
@@ -51,7 +53,7 @@ var GuitarNoteLabel = /* @__PURE__ */ ((GuitarNoteLabel2) => {
|
|
|
51
53
|
var DefaultGuitarNoteLabel = "Default" /* Default */;
|
|
52
54
|
var GuitarNoteLabelList = Utils.Enum.getEnumValues(GuitarNoteLabel);
|
|
53
55
|
function validateGuitarNoteLabel(label) {
|
|
54
|
-
if (
|
|
56
|
+
if (Guard.isEnumValue(label, GuitarNoteLabel)) {
|
|
55
57
|
return label;
|
|
56
58
|
} else {
|
|
57
59
|
throw new MusicError(MusicErrorType.Timesignature, `Invalid guitarNoteLabel: ${label}`);
|
|
@@ -151,19 +153,32 @@ var _Note = class _Note {
|
|
|
151
153
|
* @returns - Note.
|
|
152
154
|
*/
|
|
153
155
|
static getNote(noteName) {
|
|
154
|
-
|
|
155
|
-
if (note === void 0) {
|
|
156
|
+
return this.noteCache.getOrCreate(noteName, () => {
|
|
156
157
|
let p = _Note.parseNote(noteName);
|
|
157
|
-
if (!p)
|
|
158
|
-
throw new MusicError2(MusicErrorType2.Note, `Invalid
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
if (!p)
|
|
159
|
+
throw new MusicError2(MusicErrorType2.Note, `Invalid note "${noteName}".`);
|
|
160
|
+
if (p.octave === void 0)
|
|
161
|
+
throw new MusicError2(MusicErrorType2.Note, `Invalid note "${noteName}" (missing octave).`);
|
|
162
|
+
return new _Note(p.noteLetter, p.accidental, p.octave);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Test if given note name valid.
|
|
167
|
+
* @param noteName - Note name.
|
|
168
|
+
* @returns - True/false.
|
|
169
|
+
*/
|
|
170
|
+
static isNote(noteName) {
|
|
171
|
+
let p = _Note.parseNote(noteName);
|
|
172
|
+
return p !== void 0 && p.octave !== void 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Validate given note name.
|
|
176
|
+
* @param noteName - Note name.
|
|
177
|
+
* @returns - True or throws.
|
|
178
|
+
*/
|
|
179
|
+
static validateNote(noteName) {
|
|
180
|
+
if (this.isNote(noteName)) return true;
|
|
181
|
+
throw new MusicError2(MusicErrorType2.Note, `Invalid note "${noteName}"`);
|
|
167
182
|
}
|
|
168
183
|
/**
|
|
169
184
|
* Get chromatic note. There are number of alternatives, this function uses simple logic to choose one.
|
|
@@ -171,21 +186,11 @@ var _Note = class _Note {
|
|
|
171
186
|
* @returns - Note.
|
|
172
187
|
*/
|
|
173
188
|
static getChromaticNote(chromaticId) {
|
|
174
|
-
|
|
175
|
-
if (note === void 0) {
|
|
189
|
+
return this.chromaticNoteCache.getOrCreate(chromaticId, () => {
|
|
176
190
|
const NoteNameList = ["C/B#", "C#/Db", "D", "D#/Eb", "E/Fb", "F/E#", "F#/Gb", "G", "G#/Ab", "A", "A#/Bb", "B/Cb"];
|
|
177
191
|
let noteName = NoteNameList[_Note.getChromaticClass(chromaticId)].split("/")[0] + _Note.getOctaveFromChromaticId(chromaticId);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
throw new MusicError2(MusicErrorType2.Note, `Invalid noteName: ${noteName}`);
|
|
181
|
-
}
|
|
182
|
-
if (p.octave === void 0) {
|
|
183
|
-
throw new MusicError2(MusicErrorType2.Note, `Octave is required for note.`);
|
|
184
|
-
}
|
|
185
|
-
note = new _Note(p.noteLetter, p.accidental, p.octave);
|
|
186
|
-
this.chromaticNoteCache.set(chromaticId, note);
|
|
187
|
-
}
|
|
188
|
-
return note;
|
|
192
|
+
return _Note.getNote(noteName);
|
|
193
|
+
});
|
|
189
194
|
}
|
|
190
195
|
static getDiatonicClass(arg) {
|
|
191
196
|
if (typeof arg === "number") {
|
|
@@ -354,7 +359,7 @@ var _Note = class _Note {
|
|
|
354
359
|
* @returns - Valid diatonic id or throws.
|
|
355
360
|
*/
|
|
356
361
|
static validateDiatonicId(diatonicId) {
|
|
357
|
-
if (
|
|
362
|
+
if (Guard2.isInteger(diatonicId)) {
|
|
358
363
|
return diatonicId;
|
|
359
364
|
} else {
|
|
360
365
|
throw new MusicError2(MusicErrorType2.Note, `Invalid diatonicId: ${diatonicId}`);
|
|
@@ -366,7 +371,7 @@ var _Note = class _Note {
|
|
|
366
371
|
* @returns - Valid diatonic class or throws.
|
|
367
372
|
*/
|
|
368
373
|
static validateDiatonicClass(diatonicClass) {
|
|
369
|
-
if (
|
|
374
|
+
if (Guard2.isIntegerBetween(diatonicClass, 0, 6)) {
|
|
370
375
|
return diatonicClass;
|
|
371
376
|
} else {
|
|
372
377
|
throw new MusicError2(MusicErrorType2.Note, `Invalid diatonicClass: ${diatonicClass}`);
|
|
@@ -378,7 +383,7 @@ var _Note = class _Note {
|
|
|
378
383
|
* @returns - Valid chromatic id, or throws.
|
|
379
384
|
*/
|
|
380
385
|
static validateChromaticId(chromaticId) {
|
|
381
|
-
if (
|
|
386
|
+
if (Guard2.isInteger(chromaticId)) {
|
|
382
387
|
return chromaticId;
|
|
383
388
|
} else {
|
|
384
389
|
throw new MusicError2(MusicErrorType2.Note, `Invalid chromaticId: ${chromaticId}`);
|
|
@@ -390,7 +395,7 @@ var _Note = class _Note {
|
|
|
390
395
|
* @returns - Valid chromatic class, or throws.
|
|
391
396
|
*/
|
|
392
397
|
static validatechromaticClass(chromaticClass) {
|
|
393
|
-
if (
|
|
398
|
+
if (Guard2.isIntegerBetween(chromaticClass, 0, 11)) {
|
|
394
399
|
return chromaticClass;
|
|
395
400
|
} else {
|
|
396
401
|
throw new MusicError2(MusicErrorType2.Note, `Invalid chromaticClass: ${chromaticClass}`);
|
|
@@ -414,7 +419,7 @@ var _Note = class _Note {
|
|
|
414
419
|
* @returns - Valid octave or throws.
|
|
415
420
|
*/
|
|
416
421
|
static validateOctave(octave) {
|
|
417
|
-
if (
|
|
422
|
+
if (Guard2.isInteger(octave)) {
|
|
418
423
|
return octave;
|
|
419
424
|
} else {
|
|
420
425
|
throw new MusicError2(MusicErrorType2.Note, `Invalid octave: ${octave}`);
|
|
@@ -426,7 +431,7 @@ var _Note = class _Note {
|
|
|
426
431
|
* @returns - Valid accidental or thorws.
|
|
427
432
|
*/
|
|
428
433
|
static validateAccidental(acc) {
|
|
429
|
-
if (
|
|
434
|
+
if (Guard2.isIntegerBetween(acc, -2, 2)) {
|
|
430
435
|
return acc;
|
|
431
436
|
} else {
|
|
432
437
|
throw new MusicError2(MusicErrorType2.Note, `Invalid accidental: ${acc}`);
|
|
@@ -476,15 +481,15 @@ var _Note = class _Note {
|
|
|
476
481
|
}
|
|
477
482
|
}
|
|
478
483
|
};
|
|
479
|
-
__publicField(_Note, "
|
|
480
|
-
__publicField(_Note, "chromaticNoteCache",
|
|
484
|
+
__publicField(_Note, "noteCache", new UniMap());
|
|
485
|
+
__publicField(_Note, "chromaticNoteCache", new UniMap());
|
|
481
486
|
var Note = _Note;
|
|
482
487
|
|
|
483
488
|
// src/theory/scale.ts
|
|
484
|
-
import { Utils as
|
|
489
|
+
import { Guard as Guard5, UniMap as UniMap3, SignedIndexArray, Utils as Utils3 } from "@tspro/ts-utils-lib";
|
|
485
490
|
|
|
486
491
|
// src/theory/key-signature.ts
|
|
487
|
-
import {
|
|
492
|
+
import { Guard as Guard3 } from "@tspro/ts-utils-lib";
|
|
488
493
|
import { MusicError as MusicError3, MusicErrorType as MusicErrorType3 } from "@tspro/web-music-score/core";
|
|
489
494
|
function getAccidental(chromaticId, diatonicId) {
|
|
490
495
|
let a = Note.getChromaticClass(chromaticId) - new Note(diatonicId, 0).chromaticClass;
|
|
@@ -505,7 +510,7 @@ function parseDegree(degree) {
|
|
|
505
510
|
}
|
|
506
511
|
let acc = (_b = Note.getAccidental((_a = m[1]) != null ? _a : "")) != null ? _b : 0;
|
|
507
512
|
let deg = +m[2];
|
|
508
|
-
if (!
|
|
513
|
+
if (!Guard3.isInteger(acc) || acc < -2 || acc > 2 || !Guard3.isInteger(deg) || deg < 1) {
|
|
509
514
|
throw new MusicError3(MusicErrorType3.KeySignature, `Invalid degree: ${degree}`);
|
|
510
515
|
} else {
|
|
511
516
|
return { deg, acc };
|
|
@@ -541,7 +546,7 @@ var _KeySignature = class _KeySignature {
|
|
|
541
546
|
__publicField(this, "naturalScaleNotes");
|
|
542
547
|
__publicField(this, "accidentalByDiatonicClass");
|
|
543
548
|
__publicField(this, "orderedAccidentedNotes");
|
|
544
|
-
if (!
|
|
549
|
+
if (!Guard3.isEnumValue(mode, Mode)) {
|
|
545
550
|
throw new MusicError3(MusicErrorType3.KeySignature, `Invalid mode: ${mode}`);
|
|
546
551
|
}
|
|
547
552
|
let intervals = [2, 2, 1, 2, 2, 2, 1];
|
|
@@ -659,9 +664,9 @@ __publicField(_KeySignature, "OrderOfFlats", "BEADGCF");
|
|
|
659
664
|
var KeySignature = _KeySignature;
|
|
660
665
|
|
|
661
666
|
// src/theory/interval.ts
|
|
662
|
-
import { Utils as
|
|
667
|
+
import { Guard as Guard4, UniMap as UniMap2, Utils as Utils2 } from "@tspro/ts-utils-lib";
|
|
663
668
|
import { MusicError as MusicError4, MusicErrorType as MusicErrorType4 } from "@tspro/web-music-score/core";
|
|
664
|
-
var IntervalQualityAbbrMap =
|
|
669
|
+
var IntervalQualityAbbrMap = new UniMap2([
|
|
665
670
|
["Major", "M"],
|
|
666
671
|
["minor", "m"],
|
|
667
672
|
["Perfect", "P"],
|
|
@@ -764,10 +769,10 @@ function validateIntervalQuality(q) {
|
|
|
764
769
|
}
|
|
765
770
|
}
|
|
766
771
|
function formatQuantity(q) {
|
|
767
|
-
if (!
|
|
772
|
+
if (!Guard4.isIntegerGte(q, 1)) {
|
|
768
773
|
throw new MusicError4(MusicErrorType4.InvalidArg, `Invalid interval quantity: ${q}`);
|
|
769
774
|
} else {
|
|
770
|
-
return
|
|
775
|
+
return Utils2.Math.toOrdinalNumber(q);
|
|
771
776
|
}
|
|
772
777
|
}
|
|
773
778
|
var InvalidIntervalException = class extends Error {
|
|
@@ -837,9 +842,8 @@ var Interval = class _Interval {
|
|
|
837
842
|
* @returns - Interval abbrevated string.
|
|
838
843
|
*/
|
|
839
844
|
toAbbrString() {
|
|
840
|
-
var _a;
|
|
841
845
|
let direction = this.direction === "Descending" ? "\u2193" : "";
|
|
842
|
-
let quality =
|
|
846
|
+
let quality = IntervalQualityAbbrMap.getOrDefault(this.quality, "?");
|
|
843
847
|
let quantity = this.quantity;
|
|
844
848
|
return direction + quality + quantity;
|
|
845
849
|
}
|
|
@@ -945,7 +949,7 @@ var Scale = class extends KeySignature {
|
|
|
945
949
|
__publicField(this, "scaleNotes");
|
|
946
950
|
/** Degrees (or undefined) of chromatic classes. */
|
|
947
951
|
__publicField(this, "chromaticClassDegree");
|
|
948
|
-
__publicField(this, "
|
|
952
|
+
__publicField(this, "preferredChromaticIdNoteCache", new SignedIndexArray());
|
|
949
953
|
switch (scaleType) {
|
|
950
954
|
case "Harmonic Minor" /* HarmonicMinor */:
|
|
951
955
|
this.scaleDegrees = [1, 2, 3, 4, 5, 6, "#7"];
|
|
@@ -1010,7 +1014,7 @@ var Scale = class extends KeySignature {
|
|
|
1010
1014
|
* @returns - Array of scale notes.
|
|
1011
1015
|
*/
|
|
1012
1016
|
getScaleNotes(bottomNote, numOctaves) {
|
|
1013
|
-
if (!
|
|
1017
|
+
if (!Guard5.isIntegerGte(numOctaves, 1)) {
|
|
1014
1018
|
throw new MusicError5(MusicErrorType5.Scale, `Invalid numOctaves: ${numOctaves}`);
|
|
1015
1019
|
}
|
|
1016
1020
|
let scaleNoteList = [];
|
|
@@ -1039,7 +1043,7 @@ var Scale = class extends KeySignature {
|
|
|
1039
1043
|
let chromaticIds = this.getScaleNotes("C4", 1).map((note) => note.chromaticId);
|
|
1040
1044
|
let steps = [];
|
|
1041
1045
|
for (let i = 0; i < chromaticIds.length - 1; i++) {
|
|
1042
|
-
steps.push(
|
|
1046
|
+
steps.push(Utils3.Math.mod(chromaticIds[i + 1] - chromaticIds[i], 12));
|
|
1043
1047
|
}
|
|
1044
1048
|
return steps;
|
|
1045
1049
|
}
|
|
@@ -1086,6 +1090,7 @@ var Scale = class extends KeySignature {
|
|
|
1086
1090
|
return interval;
|
|
1087
1091
|
}
|
|
1088
1092
|
}
|
|
1093
|
+
// Can it be negative case?
|
|
1089
1094
|
/**
|
|
1090
1095
|
* Get preferred chromatic note from given chromatic id.
|
|
1091
1096
|
* @param chromaticId - Chromatic id.
|
|
@@ -1093,7 +1098,7 @@ var Scale = class extends KeySignature {
|
|
|
1093
1098
|
*/
|
|
1094
1099
|
getPreferredChromaticNote(chromaticId) {
|
|
1095
1100
|
Note.validateChromaticId(chromaticId);
|
|
1096
|
-
let note = this.
|
|
1101
|
+
let note = this.preferredChromaticIdNoteCache.get(chromaticId);
|
|
1097
1102
|
if (note) {
|
|
1098
1103
|
return note;
|
|
1099
1104
|
}
|
|
@@ -1109,7 +1114,7 @@ var Scale = class extends KeySignature {
|
|
|
1109
1114
|
});
|
|
1110
1115
|
note = scaleNotes.find((note2) => Note.getChromaticClass(chromaticId) === note2.chromaticClass);
|
|
1111
1116
|
if (note) {
|
|
1112
|
-
this.
|
|
1117
|
+
this.preferredChromaticIdNoteCache.set(chromaticId, note);
|
|
1113
1118
|
return note;
|
|
1114
1119
|
}
|
|
1115
1120
|
let diatonicIdMid = getNaturalDiatonicId(chromaticId);
|
|
@@ -1122,13 +1127,13 @@ var Scale = class extends KeySignature {
|
|
|
1122
1127
|
for (let diatonicId = Math.max(0, diatonicIdStart); diatonicId <= diatonicIdEnd; diatonicId++) {
|
|
1123
1128
|
note = new Note(diatonicId, acc);
|
|
1124
1129
|
if (chromaticId === note.chromaticId) {
|
|
1125
|
-
this.
|
|
1130
|
+
this.preferredChromaticIdNoteCache.set(chromaticId, note);
|
|
1126
1131
|
return note;
|
|
1127
1132
|
}
|
|
1128
1133
|
}
|
|
1129
1134
|
}
|
|
1130
1135
|
note = Note.getChromaticNote(chromaticId);
|
|
1131
|
-
this.
|
|
1136
|
+
this.preferredChromaticIdNoteCache.set(chromaticId, note);
|
|
1132
1137
|
return note;
|
|
1133
1138
|
}
|
|
1134
1139
|
};
|
|
@@ -1248,7 +1253,7 @@ var ScaleFactoryList = [
|
|
|
1248
1253
|
function getScaleFactoryList() {
|
|
1249
1254
|
return ScaleFactoryList;
|
|
1250
1255
|
}
|
|
1251
|
-
var ScaleFactoryMap =
|
|
1256
|
+
var ScaleFactoryMap = new UniMap3();
|
|
1252
1257
|
ScaleFactoryList.forEach((factory) => {
|
|
1253
1258
|
if (factory instanceof ScaleFactory) {
|
|
1254
1259
|
ScaleFactoryMap.set(factory.getType(), factory);
|
|
@@ -1263,7 +1268,7 @@ function getScaleFactory(scaleType) {
|
|
|
1263
1268
|
}
|
|
1264
1269
|
}
|
|
1265
1270
|
function validateScaleType(scaleType) {
|
|
1266
|
-
if (
|
|
1271
|
+
if (Guard5.isEnumValue(scaleType, ScaleType)) {
|
|
1267
1272
|
return scaleType;
|
|
1268
1273
|
} else {
|
|
1269
1274
|
throw new MusicError5(MusicErrorType5.Scale, `Invalid scaleType: "${scaleType}"`);
|
|
@@ -1307,18 +1312,15 @@ var OkayRootNoteList = [
|
|
|
1307
1312
|
"B",
|
|
1308
1313
|
"Cb"
|
|
1309
1314
|
].map((noteName) => Note.getNote(noteName + "0"));
|
|
1310
|
-
var okayRootNoteCache =
|
|
1315
|
+
var okayRootNoteCache = new IndexArray();
|
|
1311
1316
|
function getOkayRootNote(wantedRootNote) {
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
if (!rootNote) {
|
|
1315
|
-
rootNote = OkayRootNoteList.find((note) => isEqualNote(note, wantedRootNote));
|
|
1317
|
+
return okayRootNoteCache.getOrCreate(wantedRootNote.chromaticClass, () => {
|
|
1318
|
+
let rootNote = OkayRootNoteList.find((note) => isEqualNote(note, wantedRootNote));
|
|
1316
1319
|
if (!rootNote) {
|
|
1317
1320
|
throw new MusicError6(MusicErrorType6.InvalidArg, `Invalid chord root note: ${wantedRootNote.formatOmitOctave(1 /* Unicode */)}`);
|
|
1318
1321
|
}
|
|
1319
|
-
|
|
1320
|
-
}
|
|
1321
|
-
return rootNote;
|
|
1322
|
+
return rootNote;
|
|
1323
|
+
});
|
|
1322
1324
|
}
|
|
1323
1325
|
function getChordNoteByDegree(chordRootNote, degree) {
|
|
1324
1326
|
let chordRootNoteStr = chordRootNote.formatOmitOctave(0 /* Ascii */);
|
|
@@ -1326,7 +1328,7 @@ function getChordNoteByDegree(chordRootNote, degree) {
|
|
|
1326
1328
|
return ks.getNoteByDegree(degree);
|
|
1327
1329
|
}
|
|
1328
1330
|
function removeNoteDuplicates(notes) {
|
|
1329
|
-
return
|
|
1331
|
+
return Utils4.Arr.removeDuplicates(notes, isEqualNote);
|
|
1330
1332
|
}
|
|
1331
1333
|
var ChordInfoList = [
|
|
1332
1334
|
// Power chord
|
|
@@ -1524,7 +1526,7 @@ var Chord = class _Chord {
|
|
|
1524
1526
|
};
|
|
1525
1527
|
|
|
1526
1528
|
// src/theory/guitar.ts
|
|
1527
|
-
import {
|
|
1529
|
+
import { Guard as Guard6, LRUCache } from "@tspro/ts-utils-lib";
|
|
1528
1530
|
|
|
1529
1531
|
// src/theory/assets/tunings.json
|
|
1530
1532
|
var tunings_default = {
|
|
@@ -1783,7 +1785,7 @@ var Handedness = /* @__PURE__ */ ((Handedness2) => {
|
|
|
1783
1785
|
})(Handedness || {});
|
|
1784
1786
|
var DefaultHandedness = 0 /* RightHanded */;
|
|
1785
1787
|
function validateHandedness(h) {
|
|
1786
|
-
if (
|
|
1788
|
+
if (Guard6.isEnumValue(h, Handedness)) {
|
|
1787
1789
|
return h;
|
|
1788
1790
|
} else {
|
|
1789
1791
|
throw new MusicError7(MusicErrorType7.InvalidArg, `Invalid handedness: ${h}`);
|
|
@@ -1807,7 +1809,7 @@ function getTuningStrings(tuningName) {
|
|
|
1807
1809
|
throw new MusicError7(MusicErrorType7.InvalidArg, `Invalid tuningName: ${tuningName}`);
|
|
1808
1810
|
}
|
|
1809
1811
|
tuningStrings = tuningData.strings.slice().reverse().map((noteName) => Note.getNote(noteName));
|
|
1810
|
-
if (!
|
|
1812
|
+
if (!Guard6.isIntegerEq(tuningStrings.length, 6)) {
|
|
1811
1813
|
throw new MusicError7(MusicErrorType7.Unknown, `Tuning has ${tuningStrings.length} strings.`);
|
|
1812
1814
|
}
|
|
1813
1815
|
TuningStringsCache.set(tuningName, tuningStrings);
|
|
@@ -1816,7 +1818,7 @@ function getTuningStrings(tuningName) {
|
|
|
1816
1818
|
}
|
|
1817
1819
|
|
|
1818
1820
|
// src/theory/time-signature.ts
|
|
1819
|
-
import {
|
|
1821
|
+
import { Guard as Guard7 } from "@tspro/ts-utils-lib";
|
|
1820
1822
|
import { MusicError as MusicError8, MusicErrorType as MusicErrorType8 } from "@tspro/web-music-score/core";
|
|
1821
1823
|
var TimeSignatures = /* @__PURE__ */ ((TimeSignatures2) => {
|
|
1822
1824
|
TimeSignatures2["_2_4"] = "2/4";
|
|
@@ -1850,25 +1852,25 @@ var TimeSignature = class {
|
|
|
1850
1852
|
/** Beam groups (e.g. [[2], [2]] or [[2, 2], [2, 2]] (first try as [[4], [4]])). */
|
|
1851
1853
|
__publicField(this, "beamGroupSizes", []);
|
|
1852
1854
|
let beamGrouping;
|
|
1853
|
-
if (
|
|
1855
|
+
if (Guard7.isEnumValue(args[0], TimeSignatures)) {
|
|
1854
1856
|
let parts = args[0].split("/");
|
|
1855
1857
|
this.beatCount = +parts[0];
|
|
1856
1858
|
this.beatSize = +parts[1];
|
|
1857
|
-
if (
|
|
1859
|
+
if (Guard7.isEnumValue(args[1], BeamGrouping)) {
|
|
1858
1860
|
beamGrouping = args[1];
|
|
1859
1861
|
}
|
|
1860
|
-
} else if (
|
|
1862
|
+
} else if (Guard7.isIntegerGte(args[0], 2) && Guard7.isIntegerGte(args[1], 2)) {
|
|
1861
1863
|
this.beatCount = args[0];
|
|
1862
1864
|
this.beatSize = args[1];
|
|
1863
|
-
if (
|
|
1865
|
+
if (Guard7.isEnumValue(args[2], BeamGrouping)) {
|
|
1864
1866
|
beamGrouping = args[2];
|
|
1865
1867
|
}
|
|
1866
1868
|
} else {
|
|
1867
1869
|
throw new MusicError8(MusicErrorType8.Timesignature, `Invalid args: ${args}`);
|
|
1868
1870
|
}
|
|
1869
|
-
if (!
|
|
1871
|
+
if (!Guard7.isIntegerGte(this.beatCount, 1)) {
|
|
1870
1872
|
throw new MusicError8(MusicErrorType8.Timesignature, `Invalid beatCount: ${this.beatCount}`);
|
|
1871
|
-
} else if (!
|
|
1873
|
+
} else if (!Guard7.isIntegerGte(this.beatSize, 1)) {
|
|
1872
1874
|
throw new MusicError8(MusicErrorType8.Timesignature, `Invalid beatSize: ${this.beatSize}`);
|
|
1873
1875
|
}
|
|
1874
1876
|
let { noteLength, ticks } = NoteLengthProps.create(this.beatSize);
|
|
@@ -1883,7 +1885,7 @@ var TimeSignature = class {
|
|
|
1883
1885
|
} else if (this.is(3, 8)) {
|
|
1884
1886
|
this.beamGroupSizes = [[3]];
|
|
1885
1887
|
} else if (this.is(5, 8)) {
|
|
1886
|
-
if (!
|
|
1888
|
+
if (!Guard7.isUndefined(beamGrouping) && beamGrouping !== "2-3" /* _2_3 */ && beamGrouping !== "3-2" /* _3_2 */) {
|
|
1887
1889
|
throw new MusicError8(MusicErrorType8.Timesignature, `Invalid beam grouping "${beamGrouping}" for time signature "${this.toString()}".`);
|
|
1888
1890
|
} else {
|
|
1889
1891
|
this.beamGroupSizes = beamGrouping === "3-2" /* _3_2 */ ? [[3], [2]] : [[2], [3]];
|
|
@@ -1892,7 +1894,7 @@ var TimeSignature = class {
|
|
|
1892
1894
|
} else if (this.is(6, 8)) {
|
|
1893
1895
|
this.beamGroupSizes = [[3], [3]];
|
|
1894
1896
|
} else if (this.is(7, 8)) {
|
|
1895
|
-
if (!
|
|
1897
|
+
if (!Guard7.isUndefined(beamGrouping) && beamGrouping !== "2-2-3" /* _2_2_3 */ && beamGrouping !== "3-2-2" /* _3_2_2 */) {
|
|
1896
1898
|
throw new MusicError8(MusicErrorType8.Timesignature, `Invalid beam grouping "${beamGrouping}" for time signature "${this.toString()}".`);
|
|
1897
1899
|
} else {
|
|
1898
1900
|
this.beamGroupSizes = beamGrouping === "3-2-2" /* _3_2_2 */ ? [[3], [2], [2]] : [[2], [2], [3]];
|
|
@@ -1994,6 +1996,8 @@ export {
|
|
|
1994
1996
|
getScaleFactoryList,
|
|
1995
1997
|
getTempoString,
|
|
1996
1998
|
getTuningStrings,
|
|
1999
|
+
isNoteLength,
|
|
2000
|
+
isTupletRatio,
|
|
1997
2001
|
validateGuitarNoteLabel,
|
|
1998
2002
|
validateHandedness,
|
|
1999
2003
|
validateIntervalQuality,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tspro/web-music-score",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"author": "PahkaSoft",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"package.json"
|
|
107
107
|
],
|
|
108
108
|
"dependencies": {
|
|
109
|
-
"@tspro/ts-utils-lib": "^1.
|
|
109
|
+
"@tspro/ts-utils-lib": "^2.1.0",
|
|
110
110
|
"tone": "^15.1.22"
|
|
111
111
|
},
|
|
112
112
|
"peerDependencies": {
|
|
@@ -128,8 +128,9 @@
|
|
|
128
128
|
"scripts": {
|
|
129
129
|
"build": "tsup",
|
|
130
130
|
"watch": "tsup --watch",
|
|
131
|
-
"build:
|
|
132
|
-
"
|
|
131
|
+
"build:all": "npm run build && npm run build:prod --workspaces --if-present",
|
|
132
|
+
"start:features-demo": "npm run start --workspace features-demo",
|
|
133
|
+
"start:guitar-app": "npm run start --workspace guitar-app",
|
|
133
134
|
"docs": "typedoc"
|
|
134
135
|
}
|
|
135
136
|
}
|