@tspro/web-music-score 5.3.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +6 -4
  3. package/dist/audio/index.d.mts +1 -1
  4. package/dist/audio/index.d.ts +1 -1
  5. package/dist/audio/index.js +3 -3
  6. package/dist/audio/index.mjs +6 -6
  7. package/dist/audio-cg/index.js +1 -1
  8. package/dist/audio-cg/index.mjs +3 -3
  9. package/dist/audio-synth/index.js +1 -1
  10. package/dist/audio-synth/index.mjs +3 -3
  11. package/dist/{chunk-C6UQDKWU.mjs → chunk-AUT4C6TY.mjs} +2 -2
  12. package/dist/{chunk-ZBA5XLYR.mjs → chunk-MHDBTCVG.mjs} +21 -21
  13. package/dist/{chunk-PMDIUO22.mjs → chunk-QGMOI7AP.mjs} +2 -2
  14. package/dist/chunk-ZWUBO5EW.mjs +37 -0
  15. package/dist/core/index.js +2 -2
  16. package/dist/core/index.mjs +6 -31
  17. package/dist/{guitar-BsSayRsH.d.ts → guitar-CarHGDAt.d.ts} +1 -1
  18. package/dist/{guitar-DdexKdN6.d.mts → guitar-DXlB-9vK.d.mts} +1 -1
  19. package/dist/iife/audio-cg.global.js +1 -1
  20. package/dist/iife/index.global.js +18 -11
  21. package/dist/{music-objects-Ih9vCl4p.d.ts → music-objects-3Esbz7ij.d.ts} +48 -243
  22. package/dist/{music-objects-BGiRQIXW.d.mts → music-objects-ONIuVUgs.d.mts} +48 -243
  23. package/dist/{note-CgCIBwvR.d.ts → note-CJuq5aBy.d.ts} +13 -1
  24. package/dist/{note-eA2xPPiG.d.mts → note-RVXvpfyV.d.mts} +13 -1
  25. package/dist/pieces/index.d.mts +3 -3
  26. package/dist/pieces/index.d.ts +3 -3
  27. package/dist/pieces/index.js +1 -1
  28. package/dist/pieces/index.mjs +2 -2
  29. package/dist/react-ui/index.d.mts +9 -9
  30. package/dist/react-ui/index.d.ts +9 -9
  31. package/dist/react-ui/index.js +12 -14
  32. package/dist/react-ui/index.mjs +14 -16
  33. package/dist/{scale-CBW4eTz7.d.ts → scale-C8gHC448.d.mts} +3 -3
  34. package/dist/{scale-DQP3b9Zx.d.mts → scale-DulPFco_.d.ts} +3 -3
  35. package/dist/score/index.d.mts +232 -6
  36. package/dist/score/index.d.ts +232 -6
  37. package/dist/score/index.js +981 -883
  38. package/dist/score/index.mjs +837 -769
  39. package/dist/{tempo-dkctPkCS.d.mts → tempo-BlCGZuYg.d.mts} +14 -2
  40. package/dist/{tempo-DMt3iwz9.d.ts → tempo-BnUjm25M.d.ts} +14 -2
  41. package/dist/theory/index.d.mts +6 -6
  42. package/dist/theory/index.d.ts +6 -6
  43. package/dist/theory/index.js +88 -86
  44. package/dist/theory/index.mjs +85 -81
  45. package/package.json +5 -4
@@ -1,10 +1,10 @@
1
- /* WebMusicScore v5.3.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
1
+ /* WebMusicScore v5.4.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
2
2
  import {
3
3
  __publicField
4
- } from "./chunk-C6UQDKWU.mjs";
4
+ } from "./chunk-AUT4C6TY.mjs";
5
5
 
6
6
  // src/theory/rhythm.ts
7
- import { Utils } from "@tspro/ts-utils-lib";
7
+ import { Guard, IndexArray, UniMap, Utils } from "@tspro/ts-utils-lib";
8
8
  import { MusicError, MusicErrorType } from "@tspro/web-music-score/core";
9
9
  var MaxTupletRatioValue = 12;
10
10
  var TicksMultiplier = 12 * 11 * 9 * 7 * 5;
@@ -47,8 +47,11 @@ var NoteLength = /* @__PURE__ */ ((NoteLength2) => {
47
47
  NoteLength2["SixtyFourthTriplet"] = "64t";
48
48
  return NoteLength2;
49
49
  })(NoteLength || {});
50
+ function isNoteLength(noteLength) {
51
+ return Guard.isEnumValue(noteLength, NoteLength);
52
+ }
50
53
  function validateNoteLength(noteLength) {
51
- if (Utils.Is.isEnumValue(noteLength, NoteLength)) {
54
+ if (isNoteLength(noteLength)) {
52
55
  return noteLength;
53
56
  } else {
54
57
  throw new MusicError(MusicErrorType.InvalidArg, `Invalid noteLength: ${noteLength}`);
@@ -95,11 +98,7 @@ var _NoteLengthProps = class _NoteLengthProps {
95
98
  * @returns - Note length props.
96
99
  */
97
100
  static get(noteLength) {
98
- let p = this.cache.get(noteLength);
99
- if (!p) {
100
- this.cache.set(noteLength, p = new _NoteLengthProps(noteLength));
101
- }
102
- return p;
101
+ return this.cache.getOrCreate(noteLength, () => new _NoteLengthProps(noteLength));
103
102
  }
104
103
  /**
105
104
  * Create note length props.
@@ -109,7 +108,7 @@ var _NoteLengthProps = class _NoteLengthProps {
109
108
  */
110
109
  static create(noteLength, dotCount = 0) {
111
110
  let noteSize = typeof noteLength === "number" ? noteLength : this.get(noteLength).noteSize;
112
- return this.get(noteSize + (Utils.Is.isIntegerGte(dotCount, 1) ? ".".repeat(dotCount) : "n"));
111
+ return this.get(noteSize + (Guard.isIntegerGte(dotCount, 1) ? ".".repeat(dotCount) : "n"));
113
112
  }
114
113
  /**
115
114
  * Compare note lengths/sizes. Whole (1) > half (2) > quarter (4), etc.
@@ -140,10 +139,13 @@ var _NoteLengthProps = class _NoteLengthProps {
140
139
  __publicField(_NoteLengthProps, "LongestNoteSize", Math.min(...Utils.Enum.getEnumValues(NoteLength).map((noteLength) => parseInt(noteLength))));
141
140
  /** Shortest note size (e.g. 64 = sixtyfourth note). */
142
141
  __publicField(_NoteLengthProps, "ShortestNoteSize", Math.max(...Utils.Enum.getEnumValues(NoteLength).map((noteLength) => parseInt(noteLength))));
143
- __publicField(_NoteLengthProps, "cache", /* @__PURE__ */ new Map());
142
+ __publicField(_NoteLengthProps, "cache", new UniMap());
144
143
  var NoteLengthProps = _NoteLengthProps;
144
+ function isTupletRatio(tupletRatio) {
145
+ return Guard.isObject(tupletRatio) && Guard.isIntegerBetween(tupletRatio.parts, 2, MaxTupletRatioValue) && Guard.isIntegerBetween(tupletRatio.inTimeOf, 2, MaxTupletRatioValue);
146
+ }
145
147
  function validateTupletRatio(tupletRatio) {
146
- if (Utils.Is.isObject(tupletRatio) && Utils.Is.isIntegerBetween(tupletRatio.parts, 2, MaxTupletRatioValue) && Utils.Is.isIntegerBetween(tupletRatio.inTimeOf, 2, MaxTupletRatioValue)) {
148
+ if (isTupletRatio(tupletRatio)) {
147
149
  return tupletRatio;
148
150
  } else {
149
151
  throw new MusicError(MusicErrorType.Note, `Invalid tupletRatio ${JSON.stringify(tupletRatio)}`);
@@ -183,7 +185,7 @@ var _RhythmProps = class _RhythmProps {
183
185
  this.dotCount = dotCount != null ? dotCount : p.dotCount;
184
186
  this.hasStem = p.hasStem;
185
187
  this.isSolidNoteHead = p.isSolid;
186
- if (Utils.Is.isObject(tupletRatio)) {
188
+ if (Guard.isObject(tupletRatio)) {
187
189
  this.tupletRatio = validateTupletRatio(tupletRatio);
188
190
  } else if (p.isTriplet) {
189
191
  this.tupletRatio = Tuplet.Triplet;
@@ -222,11 +224,7 @@ var _RhythmProps = class _RhythmProps {
222
224
  if (dotCount !== void 0 || tupletRatio !== void 0) {
223
225
  return new _RhythmProps(noteLength, dotCount, tupletRatio);
224
226
  } else {
225
- let rhythmProps = this.cache.get(noteLength);
226
- if (!rhythmProps) {
227
- this.cache.set(noteLength, rhythmProps = new _RhythmProps(noteLength));
228
- }
229
- return rhythmProps;
227
+ return this.cache.getOrCreate(noteLength, () => new _RhythmProps(noteLength));
230
228
  }
231
229
  }
232
230
  /**
@@ -248,16 +246,18 @@ var _RhythmProps = class _RhythmProps {
248
246
  return a.ticks === b.ticks;
249
247
  }
250
248
  };
251
- __publicField(_RhythmProps, "NoteSymbolMap", /* @__PURE__ */ new Map([[1, "\u{1D15D}"], [2, "\u{1D15E}"], [4, "\u{1D15F}"], [8, "\u{1D160}"], [16, "\u{1D161}"], [32, "\u{1D162}"], [64, "\u{1D163}"], [128, "\u{1D164}"]]));
252
- __publicField(_RhythmProps, "cache", /* @__PURE__ */ new Map());
249
+ __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}"]]));
250
+ __publicField(_RhythmProps, "cache", new UniMap());
253
251
  var RhythmProps = _RhythmProps;
254
252
 
255
253
  export {
256
254
  NoteLength,
255
+ isNoteLength,
257
256
  validateNoteLength,
258
257
  NoteLengthProps,
258
+ isTupletRatio,
259
259
  validateTupletRatio,
260
260
  Tuplet,
261
261
  RhythmProps
262
262
  };
263
- //# sourceMappingURL=chunk-ZBA5XLYR.mjs.map
263
+ //# sourceMappingURL=chunk-MHDBTCVG.mjs.map
@@ -1,4 +1,4 @@
1
- /* WebMusicScore v5.3.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
1
+ /* WebMusicScore v5.4.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
2
2
 
3
3
  // src/audio/instrument.ts
4
4
  function linearToDecibels(linearVolume) {
@@ -8,4 +8,4 @@ function linearToDecibels(linearVolume) {
8
8
  export {
9
9
  linearToDecibels
10
10
  };
11
- //# sourceMappingURL=chunk-PMDIUO22.mjs.map
11
+ //# sourceMappingURL=chunk-QGMOI7AP.mjs.map
@@ -0,0 +1,37 @@
1
+ /* WebMusicScore v5.4.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
2
+ import {
3
+ __publicField
4
+ } from "./chunk-AUT4C6TY.mjs";
5
+
6
+ // src/core/error.ts
7
+ var MusicErrorType = /* @__PURE__ */ ((MusicErrorType2) => {
8
+ MusicErrorType2[MusicErrorType2["Unknown"] = 0] = "Unknown";
9
+ MusicErrorType2[MusicErrorType2["InvalidArg"] = 1] = "InvalidArg";
10
+ MusicErrorType2[MusicErrorType2["Note"] = 2] = "Note";
11
+ MusicErrorType2[MusicErrorType2["Scale"] = 3] = "Scale";
12
+ MusicErrorType2[MusicErrorType2["KeySignature"] = 4] = "KeySignature";
13
+ MusicErrorType2[MusicErrorType2["Timesignature"] = 5] = "Timesignature";
14
+ MusicErrorType2[MusicErrorType2["Score"] = 6] = "Score";
15
+ MusicErrorType2[MusicErrorType2["Audio"] = 7] = "Audio";
16
+ return MusicErrorType2;
17
+ })(MusicErrorType || {});
18
+ function formatType(type) {
19
+ return type === void 0 ? "" : `[${MusicErrorType[type]}] `;
20
+ }
21
+ var MusicError = class extends Error {
22
+ constructor(...args) {
23
+ const [type, msg] = args.length === 1 ? [0 /* Unknown */, args[0]] : args;
24
+ super(formatType(type) + msg);
25
+ /** Music error type. */
26
+ __publicField(this, "type");
27
+ Object.setPrototypeOf(this, new.target.prototype);
28
+ this.name = "MusicError";
29
+ this.type = type;
30
+ }
31
+ };
32
+
33
+ export {
34
+ MusicErrorType,
35
+ MusicError
36
+ };
37
+ //# sourceMappingURL=chunk-ZWUBO5EW.mjs.map
@@ -1,4 +1,4 @@
1
- /* WebMusicScore v5.3.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
1
+ /* WebMusicScore v5.4.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -63,7 +63,7 @@ function init() {
63
63
  return;
64
64
  }
65
65
  initialized = true;
66
- console.log("%cWebMusicScore v5.3.0 (cjs) initialized.", "background: black; color: white; padding: 2px;");
66
+ console.log("%cWebMusicScore v5.4.0 (cjs) initialized.", "background: black; color: white; padding: 2px;");
67
67
  }
68
68
  // Annotate the CommonJS export names for ESM import in node:
69
69
  0 && (module.exports = {
@@ -1,34 +1,9 @@
1
- /* WebMusicScore v5.3.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
1
+ /* WebMusicScore v5.4.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
2
2
  import {
3
- __publicField
4
- } from "../chunk-C6UQDKWU.mjs";
5
-
6
- // src/core/error.ts
7
- var MusicErrorType = /* @__PURE__ */ ((MusicErrorType2) => {
8
- MusicErrorType2[MusicErrorType2["Unknown"] = 0] = "Unknown";
9
- MusicErrorType2[MusicErrorType2["InvalidArg"] = 1] = "InvalidArg";
10
- MusicErrorType2[MusicErrorType2["Note"] = 2] = "Note";
11
- MusicErrorType2[MusicErrorType2["Scale"] = 3] = "Scale";
12
- MusicErrorType2[MusicErrorType2["KeySignature"] = 4] = "KeySignature";
13
- MusicErrorType2[MusicErrorType2["Timesignature"] = 5] = "Timesignature";
14
- MusicErrorType2[MusicErrorType2["Score"] = 6] = "Score";
15
- MusicErrorType2[MusicErrorType2["Audio"] = 7] = "Audio";
16
- return MusicErrorType2;
17
- })(MusicErrorType || {});
18
- function formatType(type) {
19
- return type === void 0 ? "" : `[${MusicErrorType[type]}] `;
20
- }
21
- var MusicError = class extends Error {
22
- constructor(...args) {
23
- const [type, msg] = args.length === 1 ? [0 /* Unknown */, args[0]] : args;
24
- super(formatType(type) + msg);
25
- /** Music error type. */
26
- __publicField(this, "type");
27
- Object.setPrototypeOf(this, new.target.prototype);
28
- this.name = "MusicError";
29
- this.type = type;
30
- }
31
- };
3
+ MusicError,
4
+ MusicErrorType
5
+ } from "../chunk-ZWUBO5EW.mjs";
6
+ import "../chunk-AUT4C6TY.mjs";
32
7
 
33
8
  // src/core/index.ts
34
9
  var initialized = false;
@@ -37,7 +12,7 @@ function init() {
37
12
  return;
38
13
  }
39
14
  initialized = true;
40
- console.log("%cWebMusicScore v5.3.0 (esm) initialized.", "background: black; color: white; padding: 2px;");
15
+ console.log("%cWebMusicScore v5.4.0 (esm) initialized.", "background: black; color: white; padding: 2px;");
41
16
  }
42
17
  export {
43
18
  MusicError,
@@ -1,4 +1,4 @@
1
- import { N as Note } from './note-CgCIBwvR.js';
1
+ import { N as Note } from './note-CJuq5aBy.js';
2
2
 
3
3
  /** Guitar handedness enum. */
4
4
  declare enum Handedness {
@@ -1,4 +1,4 @@
1
- import { N as Note } from './note-eA2xPPiG.mjs';
1
+ import { N as Note } from './note-RVXvpfyV.mjs';
2
2
 
3
3
  /** Guitar handedness enum. */
4
4
  declare enum Handedness {