web-music-score 0.0.1 → 6.0.0-pre.1
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 +200 -0
- package/LICENSE +62 -1
- package/README.md +46 -2
- package/dist/audio/index.d.ts +50 -0
- package/dist/audio/index.js +1858 -0
- package/dist/audio/index.mjs +92 -0
- package/dist/audio-cg/index.d.ts +21 -0
- package/dist/audio-cg/index.js +17568 -0
- package/dist/audio-cg/index.mjs +90 -0
- package/dist/audio-synth/index.d.ts +15 -0
- package/dist/audio-synth/index.js +18497 -0
- package/dist/audio-synth/index.mjs +63 -0
- package/dist/chunk-A7C2G7OG.mjs +101 -0
- package/dist/chunk-GNT3ECDB.mjs +267 -0
- package/dist/chunk-LO4NI4AU.mjs +18381 -0
- package/dist/chunk-PW2SO6EZ.mjs +37 -0
- package/dist/chunk-VHB57TXT.mjs +11 -0
- package/dist/chunk-X7BMJX7E.mjs +3867 -0
- package/dist/core/index.d.ts +31 -0
- package/dist/core/index.js +74 -0
- package/dist/core/index.mjs +22 -0
- package/dist/iife/audio-cg.global.js +220 -0
- package/dist/iife/index.global.js +228 -0
- package/dist/instrument-DS-9C6_8.d.ts +44 -0
- package/dist/music-objects-DLmp5uL6.d.ts +2398 -0
- package/dist/note-RVXvpfyV.d.ts +306 -0
- package/dist/pieces/index.d.ts +46 -0
- package/dist/pieces/index.js +79 -0
- package/dist/pieces/index.mjs +50 -0
- package/dist/react-ui/index.d.ts +86 -0
- package/dist/react-ui/index.js +132 -0
- package/dist/react-ui/index.mjs +96 -0
- package/dist/scale-B1M10_fu.d.ts +230 -0
- package/dist/score/index.d.ts +466 -0
- package/dist/score/index.js +13964 -0
- package/dist/score/index.mjs +10092 -0
- package/dist/tempo-D-JF-8b_.d.ts +409 -0
- package/dist/theory/index.d.ts +78 -0
- package/dist/theory/index.js +4842 -0
- package/dist/theory/index.mjs +1986 -0
- package/package.json +131 -3
- package/workspace.code-workspace +0 -9
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* WebMusicScore v6.0.0-pre.1 | (c) 2023-2025 Stefan Brockmann | MIT License | Includes: Tone.js (MIT License), Color Name to Code (MIT License) */
|
|
2
|
+
import {
|
|
3
|
+
Filter,
|
|
4
|
+
PolySynth,
|
|
5
|
+
Reverb,
|
|
6
|
+
Synth
|
|
7
|
+
} from "../chunk-LO4NI4AU.mjs";
|
|
8
|
+
import {
|
|
9
|
+
linearToDecibels
|
|
10
|
+
} from "../chunk-VHB57TXT.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__publicField
|
|
13
|
+
} from "../chunk-A7C2G7OG.mjs";
|
|
14
|
+
|
|
15
|
+
// src/audio-instruments/audio-synth/index.ts
|
|
16
|
+
var SynthesizerInstr = class {
|
|
17
|
+
constructor() {
|
|
18
|
+
__publicField(this, "audioSource");
|
|
19
|
+
try {
|
|
20
|
+
const reverb = new Reverb({ decay: 3, wet: 0.4 }).toDestination();
|
|
21
|
+
const filter = new Filter(800, "lowpass").connect(reverb);
|
|
22
|
+
this.audioSource = new PolySynth(Synth, {
|
|
23
|
+
oscillator: {
|
|
24
|
+
type: "triangle"
|
|
25
|
+
},
|
|
26
|
+
envelope: {
|
|
27
|
+
attack: 1e-3,
|
|
28
|
+
decay: 2,
|
|
29
|
+
sustain: 0.1,
|
|
30
|
+
release: 1.2
|
|
31
|
+
}
|
|
32
|
+
}).connect(filter);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
this.audioSource = void 0;
|
|
35
|
+
console.error(err);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getName() {
|
|
39
|
+
return "Synthesizer";
|
|
40
|
+
}
|
|
41
|
+
playNote(note, duration, linearVolume) {
|
|
42
|
+
try {
|
|
43
|
+
if (this.audioSource) {
|
|
44
|
+
this.audioSource.volume.value = linearToDecibels(linearVolume);
|
|
45
|
+
this.audioSource.triggerAttackRelease(note, duration);
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
stop() {
|
|
51
|
+
try {
|
|
52
|
+
if (this.audioSource) {
|
|
53
|
+
this.audioSource.releaseAll();
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var Synthesizer = new SynthesizerInstr();
|
|
60
|
+
export {
|
|
61
|
+
Synthesizer
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* WebMusicScore v6.0.0-pre.1 | (c) 2023-2025 Stefan Brockmann | MIT License | Includes: Tone.js (MIT License), Color Name to Code (MIT License) */
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
9
|
+
var __typeError = (msg) => {
|
|
10
|
+
throw TypeError(msg);
|
|
11
|
+
};
|
|
12
|
+
var __pow = Math.pow;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __objRest = (source, exclude) => {
|
|
27
|
+
var target = {};
|
|
28
|
+
for (var prop in source)
|
|
29
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
+
target[prop] = source[prop];
|
|
31
|
+
if (source != null && __getOwnPropSymbols)
|
|
32
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
39
|
+
var __async = (__this, __arguments, generator) => {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
var fulfilled = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.next(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var rejected = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
step(generator.throw(value));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
56
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
var __await = function(promise, isYieldStar) {
|
|
60
|
+
this[0] = promise;
|
|
61
|
+
this[1] = isYieldStar;
|
|
62
|
+
};
|
|
63
|
+
var __yieldStar = (value) => {
|
|
64
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
65
|
+
if (obj == null) {
|
|
66
|
+
obj = value[__knownSymbol("iterator")]();
|
|
67
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
68
|
+
} else {
|
|
69
|
+
obj = obj.call(value);
|
|
70
|
+
method = (k) => it[k] = (v) => {
|
|
71
|
+
if (isAwait) {
|
|
72
|
+
isAwait = false;
|
|
73
|
+
if (k === "throw") throw v;
|
|
74
|
+
return v;
|
|
75
|
+
}
|
|
76
|
+
isAwait = true;
|
|
77
|
+
return {
|
|
78
|
+
done: false,
|
|
79
|
+
value: new __await(new Promise((resolve) => {
|
|
80
|
+
var x = obj[k](v);
|
|
81
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
82
|
+
resolve(x);
|
|
83
|
+
}), 1)
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
88
|
+
throw x;
|
|
89
|
+
}, "return" in obj && method("return"), it;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
__pow,
|
|
94
|
+
__spreadValues,
|
|
95
|
+
__spreadProps,
|
|
96
|
+
__objRest,
|
|
97
|
+
__publicField,
|
|
98
|
+
__async,
|
|
99
|
+
__yieldStar
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=chunk-A7C2G7OG.mjs.map
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/* WebMusicScore v6.0.0-pre.1 | (c) 2023-2025 Stefan Brockmann | MIT License | Includes: Tone.js (MIT License), Color Name to Code (MIT License) */
|
|
2
|
+
import {
|
|
3
|
+
IndexArray,
|
|
4
|
+
UniMap,
|
|
5
|
+
guard_exports,
|
|
6
|
+
utils_exports
|
|
7
|
+
} from "./chunk-X7BMJX7E.mjs";
|
|
8
|
+
import {
|
|
9
|
+
__publicField
|
|
10
|
+
} from "./chunk-A7C2G7OG.mjs";
|
|
11
|
+
|
|
12
|
+
// src/theory/rhythm.ts
|
|
13
|
+
import { MusicError, MusicErrorType } from "web-music-score/core";
|
|
14
|
+
var MaxTupletRatioValue = 12;
|
|
15
|
+
var TicksMultiplier = 12 * 11 * 9 * 7 * 5;
|
|
16
|
+
var NoteLength = /* @__PURE__ */ ((NoteLength2) => {
|
|
17
|
+
NoteLength2["Whole"] = "1n";
|
|
18
|
+
NoteLength2["WholeTriplet"] = "1t";
|
|
19
|
+
NoteLength2["WholeDot"] = "1.";
|
|
20
|
+
NoteLength2["Whole2Dots"] = "1..";
|
|
21
|
+
NoteLength2["Whole3Dots"] = "1...";
|
|
22
|
+
NoteLength2["Whole4Dots"] = "1....";
|
|
23
|
+
NoteLength2["Whole5Dots"] = "1.....";
|
|
24
|
+
NoteLength2["Whole6Dots"] = "1......";
|
|
25
|
+
NoteLength2["Half"] = "2n";
|
|
26
|
+
NoteLength2["HalfTriplet"] = "2t";
|
|
27
|
+
NoteLength2["HalfDot"] = "2.";
|
|
28
|
+
NoteLength2["Half2Dots"] = "2..";
|
|
29
|
+
NoteLength2["Half3Dots"] = "2...";
|
|
30
|
+
NoteLength2["Half4Dots"] = "2....";
|
|
31
|
+
NoteLength2["Half5Dots"] = "2.....";
|
|
32
|
+
NoteLength2["Quarter"] = "4n";
|
|
33
|
+
NoteLength2["QuarterTriplet"] = "4t";
|
|
34
|
+
NoteLength2["QuarterDot"] = "4.";
|
|
35
|
+
NoteLength2["Quarter2Dots"] = "4..";
|
|
36
|
+
NoteLength2["Quarter3Dots"] = "4...";
|
|
37
|
+
NoteLength2["Quarter4Dots"] = "4....";
|
|
38
|
+
NoteLength2["Eighth"] = "8n";
|
|
39
|
+
NoteLength2["EighthTriplet"] = "8t";
|
|
40
|
+
NoteLength2["EighthDot"] = "8.";
|
|
41
|
+
NoteLength2["Eighth2Dots"] = "8..";
|
|
42
|
+
NoteLength2["Eighth3Dots"] = "8...";
|
|
43
|
+
NoteLength2["Sixteenth"] = "16n";
|
|
44
|
+
NoteLength2["SixteenthTriplet"] = "16t";
|
|
45
|
+
NoteLength2["SixteenthDot"] = "16.";
|
|
46
|
+
NoteLength2["Sixteenth2Dots"] = "16..";
|
|
47
|
+
NoteLength2["ThirtySecond"] = "32n";
|
|
48
|
+
NoteLength2["ThirtySecondTriplet"] = "32t";
|
|
49
|
+
NoteLength2["ThirtySecondDot"] = "32.";
|
|
50
|
+
NoteLength2["SixtyFourth"] = "64n";
|
|
51
|
+
NoteLength2["SixtyFourthTriplet"] = "64t";
|
|
52
|
+
return NoteLength2;
|
|
53
|
+
})(NoteLength || {});
|
|
54
|
+
function isNoteLength(noteLength) {
|
|
55
|
+
return guard_exports.isEnumValue(noteLength, NoteLength);
|
|
56
|
+
}
|
|
57
|
+
function validateNoteLength(noteLength) {
|
|
58
|
+
if (isNoteLength(noteLength)) {
|
|
59
|
+
return noteLength;
|
|
60
|
+
} else {
|
|
61
|
+
throw new MusicError(MusicErrorType.InvalidArg, `Invalid noteLength: ${noteLength}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var _NoteLengthProps = class _NoteLengthProps {
|
|
65
|
+
constructor(noteLength) {
|
|
66
|
+
/** Note length. */
|
|
67
|
+
__publicField(this, "noteLength");
|
|
68
|
+
/** Note size (whole=1, half=2, quarter=4, ...). */
|
|
69
|
+
__publicField(this, "noteSize");
|
|
70
|
+
/** Number of ticks (not altered by isTriplet). */
|
|
71
|
+
__publicField(this, "ticks");
|
|
72
|
+
/** Flag count. */
|
|
73
|
+
__publicField(this, "flagCount");
|
|
74
|
+
/** Dot count. */
|
|
75
|
+
__publicField(this, "dotCount");
|
|
76
|
+
/** Max dot count. */
|
|
77
|
+
__publicField(this, "maxDotCount");
|
|
78
|
+
/** Is triplet? */
|
|
79
|
+
__publicField(this, "isTriplet");
|
|
80
|
+
/** Has note stem. */
|
|
81
|
+
__publicField(this, "hasStem");
|
|
82
|
+
/** Is note head solid (black)? */
|
|
83
|
+
__publicField(this, "isSolid");
|
|
84
|
+
this.noteLength = validateNoteLength(noteLength);
|
|
85
|
+
this.noteSize = parseInt(noteLength);
|
|
86
|
+
this.isTriplet = noteLength.endsWith("t");
|
|
87
|
+
this.maxDotCount = this.isTriplet ? 0 : Math.floor(Math.log2(_NoteLengthProps.ShortestNoteSize / this.noteSize));
|
|
88
|
+
this.dotCount = utils_exports.Str.charCount(noteLength, ".");
|
|
89
|
+
this.flagCount = this.noteSize > 4 ? Math.floor(Math.log2(this.noteSize / 4)) : 0;
|
|
90
|
+
this.ticks = TicksMultiplier * _NoteLengthProps.ShortestNoteSize / this.noteSize;
|
|
91
|
+
this.hasStem = this.noteSize > 1;
|
|
92
|
+
this.isSolid = this.noteSize > 2;
|
|
93
|
+
if (this.dotCount > this.maxDotCount) {
|
|
94
|
+
throw new MusicError(MusicErrorType.Note, `dotCount ${this.dotCount} > maxDotCount ${this.maxDotCount}, for noteLength "${this.noteLength}".`);
|
|
95
|
+
} else if (this.isTriplet && this.dotCount > 0) {
|
|
96
|
+
throw new MusicError(MusicErrorType.Note, `noteLength "${this.noteLength}" is both triplet and dotted!`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get note length props.
|
|
101
|
+
* @param noteLength - Note length.
|
|
102
|
+
* @returns - Note length props.
|
|
103
|
+
*/
|
|
104
|
+
static get(noteLength) {
|
|
105
|
+
return this.cache.getOrCreate(noteLength, () => new _NoteLengthProps(noteLength));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create note length props.
|
|
109
|
+
* @param noteLength - Note length or note size.
|
|
110
|
+
* @param dotCount - Dot count.
|
|
111
|
+
* @returns - Note length props.
|
|
112
|
+
*/
|
|
113
|
+
static create(noteLength, dotCount = 0) {
|
|
114
|
+
let noteSize = typeof noteLength === "number" ? noteLength : this.get(noteLength).noteSize;
|
|
115
|
+
return this.get(noteSize + (guard_exports.isIntegerGte(dotCount, 1) ? ".".repeat(dotCount) : "n"));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Compare note lengths/sizes. Whole (1) > half (2) > quarter (4), etc.
|
|
119
|
+
* Ignores possible triplet property of note length.
|
|
120
|
+
* @param a - NoteLengthProps, NoteLength/Str or noteSize
|
|
121
|
+
* @param b - NoteLengthProps, NoteLength/Str or noteSize
|
|
122
|
+
* @returns - -1: a < b, 0: a === b, +1: a > b (note length/size comparisons)
|
|
123
|
+
*/
|
|
124
|
+
static cmp(a, b) {
|
|
125
|
+
let aNoteSize = a instanceof _NoteLengthProps ? a.noteSize : typeof a === "number" ? a : _NoteLengthProps.get(a).noteSize;
|
|
126
|
+
let bNoteSize = b instanceof _NoteLengthProps ? b.noteSize : typeof b === "number" ? b : _NoteLengthProps.get(b).noteSize;
|
|
127
|
+
return utils_exports.Math.cmp(bNoteSize, aNoteSize);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Compare note lengths/sizes for equality.
|
|
131
|
+
* Ignores possible triplet property of note length.
|
|
132
|
+
* @param a - NoteLengthProps, NoteLength/Str or noteSize
|
|
133
|
+
* @param b - NoteLengthProps, NoteLength/Str or noteSize
|
|
134
|
+
* @returns - true: a === b, false: a !== b (note length/size comparisons)
|
|
135
|
+
*/
|
|
136
|
+
static equals(a, b) {
|
|
137
|
+
let aNoteSize = a instanceof _NoteLengthProps ? a.noteSize : typeof a === "number" ? a : _NoteLengthProps.get(a).noteSize;
|
|
138
|
+
let bNoteSize = b instanceof _NoteLengthProps ? b.noteSize : typeof b === "number" ? b : _NoteLengthProps.get(b).noteSize;
|
|
139
|
+
return aNoteSize === bNoteSize;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
/** Longest note size (e.g. 1 = whole note). */
|
|
143
|
+
__publicField(_NoteLengthProps, "LongestNoteSize", Math.min(...utils_exports.Enum.getEnumValues(NoteLength).map((noteLength) => parseInt(noteLength))));
|
|
144
|
+
/** Shortest note size (e.g. 64 = sixtyfourth note). */
|
|
145
|
+
__publicField(_NoteLengthProps, "ShortestNoteSize", Math.max(...utils_exports.Enum.getEnumValues(NoteLength).map((noteLength) => parseInt(noteLength))));
|
|
146
|
+
__publicField(_NoteLengthProps, "cache", new UniMap());
|
|
147
|
+
var NoteLengthProps = _NoteLengthProps;
|
|
148
|
+
function isTupletRatio(tupletRatio) {
|
|
149
|
+
return guard_exports.isObject(tupletRatio) && guard_exports.isIntegerBetween(tupletRatio.parts, 2, MaxTupletRatioValue) && guard_exports.isIntegerBetween(tupletRatio.inTimeOf, 2, MaxTupletRatioValue);
|
|
150
|
+
}
|
|
151
|
+
function validateTupletRatio(tupletRatio) {
|
|
152
|
+
if (isTupletRatio(tupletRatio)) {
|
|
153
|
+
return tupletRatio;
|
|
154
|
+
} else {
|
|
155
|
+
throw new MusicError(MusicErrorType.Note, `Invalid tupletRatio ${JSON.stringify(tupletRatio)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
var Tuplet = {
|
|
159
|
+
/** Duplet: 2 in the time of 3 */
|
|
160
|
+
Duplet: { parts: 2, inTimeOf: 3 },
|
|
161
|
+
/** Triplet: 3 in the time of 2 */
|
|
162
|
+
Triplet: { parts: 3, inTimeOf: 2 },
|
|
163
|
+
/** Quadruplet: 4 in the time of 3 */
|
|
164
|
+
Quadruplet: { parts: 4, inTimeOf: 3 }
|
|
165
|
+
};
|
|
166
|
+
var _RhythmProps = class _RhythmProps {
|
|
167
|
+
constructor(noteLength, dotCount, tupletRatio) {
|
|
168
|
+
/** Note length. */
|
|
169
|
+
__publicField(this, "noteLength");
|
|
170
|
+
/** Note size (whole=1, half=2, quarter=4, ...). */
|
|
171
|
+
__publicField(this, "noteSize");
|
|
172
|
+
/** Dot count. */
|
|
173
|
+
__publicField(this, "dotCount");
|
|
174
|
+
/** Tuplet ratio. */
|
|
175
|
+
__publicField(this, "tupletRatio");
|
|
176
|
+
/** Number of ticks. */
|
|
177
|
+
__publicField(this, "ticks");
|
|
178
|
+
/** Flag count. */
|
|
179
|
+
__publicField(this, "flagCount");
|
|
180
|
+
/** Has note stem. */
|
|
181
|
+
__publicField(this, "hasStem");
|
|
182
|
+
/** Is note head solid (black)? */
|
|
183
|
+
__publicField(this, "isSolidNoteHead");
|
|
184
|
+
this.noteLength = validateNoteLength(noteLength);
|
|
185
|
+
let p = NoteLengthProps.get(noteLength);
|
|
186
|
+
this.noteSize = p.noteSize;
|
|
187
|
+
this.ticks = p.ticks;
|
|
188
|
+
this.flagCount = p.flagCount;
|
|
189
|
+
this.dotCount = dotCount != null ? dotCount : p.dotCount;
|
|
190
|
+
this.hasStem = p.hasStem;
|
|
191
|
+
this.isSolidNoteHead = p.isSolid;
|
|
192
|
+
if (guard_exports.isObject(tupletRatio)) {
|
|
193
|
+
this.tupletRatio = validateTupletRatio(tupletRatio);
|
|
194
|
+
} else if (p.isTriplet) {
|
|
195
|
+
this.tupletRatio = Tuplet.Triplet;
|
|
196
|
+
} else {
|
|
197
|
+
this.tupletRatio = void 0;
|
|
198
|
+
}
|
|
199
|
+
if (this.dotCount > 0 && this.tupletRatio !== void 0) {
|
|
200
|
+
throw new MusicError(MusicErrorType.Note, `Note cannot be both dotted and tuplet!`);
|
|
201
|
+
} else if (this.dotCount > p.maxDotCount) {
|
|
202
|
+
throw new MusicError(MusicErrorType.Note, `Too big dot count ${this.dotCount} for note length ${this.noteLength}.`);
|
|
203
|
+
}
|
|
204
|
+
for (let add = this.ticks / 2, i = 1; i <= this.dotCount; i++, add /= 2) {
|
|
205
|
+
this.ticks += add;
|
|
206
|
+
}
|
|
207
|
+
if (this.tupletRatio) {
|
|
208
|
+
this.ticks *= this.tupletRatio.inTimeOf / this.tupletRatio.parts;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get string presentation of rhythm props.
|
|
213
|
+
* @returns - String presentation.
|
|
214
|
+
*/
|
|
215
|
+
toString() {
|
|
216
|
+
let sym = _RhythmProps.NoteSymbolMap.get(this.noteSize);
|
|
217
|
+
let dots = ".".repeat(this.dotCount);
|
|
218
|
+
return sym ? sym + dots : "" + this.noteSize + (dots.length > 0 ? dots : "n");
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get rhythm props with given arguments.
|
|
222
|
+
* @param noteLength - Note length.
|
|
223
|
+
* @param dotCount - Dot count.
|
|
224
|
+
* @param tupletRatio - Tuplet ratio.
|
|
225
|
+
* @returns - Rhythm props.
|
|
226
|
+
*/
|
|
227
|
+
static get(noteLength, dotCount, tupletRatio) {
|
|
228
|
+
if (dotCount !== void 0 || tupletRatio !== void 0) {
|
|
229
|
+
return new _RhythmProps(noteLength, dotCount, tupletRatio);
|
|
230
|
+
} else {
|
|
231
|
+
return this.cache.getOrCreate(noteLength, () => new _RhythmProps(noteLength));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Compare duration of rhythm props.
|
|
236
|
+
* @param a - RhythmProps
|
|
237
|
+
* @param b - RhythmProps
|
|
238
|
+
* @returns - -1: a < b, 0: a === b, +1: a > b (duration comparisons)
|
|
239
|
+
*/
|
|
240
|
+
static cmp(a, b) {
|
|
241
|
+
return utils_exports.Math.cmp(a.ticks, b.ticks);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Compare duration equality of rhythm props.
|
|
245
|
+
* @param a - RhythmProps
|
|
246
|
+
* @param b - RhythmProps
|
|
247
|
+
* @returns - true: a === b, false: a !== b (duration comparisons)
|
|
248
|
+
*/
|
|
249
|
+
static equals(a, b) {
|
|
250
|
+
return a.ticks === b.ticks;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
__publicField(_RhythmProps, "NoteSymbolMap", new IndexArray([[1, "\u{1D15D}"], [2, "\u{1D15E}"], [4, "\u{1D15F}"], [8, "\u{1D160}"], [16, "\u{1D161}"], [32, "\u{1D162}"], [64, "\u{1D163}"], [128, "\u{1D164}"]]));
|
|
254
|
+
__publicField(_RhythmProps, "cache", new UniMap());
|
|
255
|
+
var RhythmProps = _RhythmProps;
|
|
256
|
+
|
|
257
|
+
export {
|
|
258
|
+
NoteLength,
|
|
259
|
+
isNoteLength,
|
|
260
|
+
validateNoteLength,
|
|
261
|
+
NoteLengthProps,
|
|
262
|
+
isTupletRatio,
|
|
263
|
+
validateTupletRatio,
|
|
264
|
+
Tuplet,
|
|
265
|
+
RhythmProps
|
|
266
|
+
};
|
|
267
|
+
//# sourceMappingURL=chunk-GNT3ECDB.mjs.map
|