@tspro/web-music-score 4.2.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +63 -26
  3. package/dist/audio/index.d.mts +23 -27
  4. package/dist/audio/index.d.ts +23 -27
  5. package/dist/audio/index.js +63 -85
  6. package/dist/audio/index.mjs +53 -73
  7. package/dist/audio-cg/index.d.mts +18 -3
  8. package/dist/audio-cg/index.d.ts +18 -3
  9. package/dist/audio-cg/index.js +54 -51
  10. package/dist/audio-cg/index.mjs +49 -52
  11. package/dist/audio-synth/index.d.mts +15 -0
  12. package/dist/audio-synth/index.d.ts +15 -0
  13. package/dist/audio-synth/index.js +95 -0
  14. package/dist/audio-synth/index.mjs +58 -0
  15. package/dist/{chunk-64N22LCV.mjs → chunk-2EQHSQWO.mjs} +2 -2
  16. package/dist/{chunk-RQFFLRWF.mjs → chunk-QVYFIK3L.mjs} +5 -6
  17. package/dist/chunk-ROPTZBKD.mjs +11 -0
  18. package/dist/core/index.d.mts +2 -1
  19. package/dist/core/index.d.ts +2 -1
  20. package/dist/core/index.js +3 -2
  21. package/dist/core/index.mjs +4 -3
  22. package/dist/iife/audio-cg.global.js +220 -0
  23. package/dist/iife/index.global.js +11 -11
  24. package/dist/instrument-DYboobMW.d.mts +44 -0
  25. package/dist/instrument-DYboobMW.d.ts +44 -0
  26. package/dist/{music-objects-CI7IjsjE.d.ts → music-objects-CMdYZeC6.d.ts} +118 -36
  27. package/dist/{music-objects-3Hxlkxy6.d.mts → music-objects-DTDFSro0.d.mts} +118 -36
  28. package/dist/pieces/index.d.mts +1 -1
  29. package/dist/pieces/index.d.ts +1 -1
  30. package/dist/pieces/index.js +1 -1
  31. package/dist/pieces/index.mjs +2 -2
  32. package/dist/react-ui/index.d.mts +52 -33
  33. package/dist/react-ui/index.d.ts +52 -33
  34. package/dist/react-ui/index.js +41 -32
  35. package/dist/react-ui/index.mjs +42 -33
  36. package/dist/score/index.d.mts +8 -8
  37. package/dist/score/index.d.ts +8 -8
  38. package/dist/score/index.js +1998 -1626
  39. package/dist/score/index.mjs +1584 -1211
  40. package/dist/theory/index.js +3 -4
  41. package/dist/theory/index.mjs +3 -3
  42. package/package.json +13 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.1.0] - 2025-10-08
4
+ ## Added
5
+ - Audio functions: mute(), unmute() and isMuted().
6
+ - Added audio-synth as an own module.
7
+ - Added PlaybackButtons properties singlePlayStop, playStop and playPauseStop (deprecated buttonLayout).
8
+ - Added grandId property to staff config, deprecated isGrand property.
9
+ - Added tab signature (show tempo, measure number and time siganture).
10
+ - Draw rhythms above tab.
11
+
12
+ ## Fixed
13
+ - Documentation errors.
14
+ - Correctly apply NoteOptions.string for each note when using addNote with arrya of notes.
15
+ - Incorrect detection upbeat beams.
16
+ - Increase beam separation by angle.
17
+ - Better tempo position above staff.
18
+ - Distance between staff and tab.
19
+
20
+ ## [5.0.0] - 2025-10-05
21
+ Major update required to enable independent browser iife instrument modules.
22
+
23
+ ### **Breiking Changes**
24
+ - Converted audio instrument modules (currently only audio-cg) independant of main lib.
25
+ - Instead of using registerClassicalGuitar() => use import { ClassicalGuitar } and Audio.addInstrument(ClassicalGuitar).
26
+ - Renamed Audio.registerInstrument() => Audio.addInstrument().
27
+ - Renamed Audio.setInstrument() => Audio.useInstrument().
28
+
3
29
  ## [4.2.1] - 2025-10-04
4
30
  ## Fixed
5
31
  - Error was thrown with dotted rests.
package/README.md CHANGED
@@ -13,6 +13,19 @@ This is a work in progress project. Lately there has been improvements that requ
13
13
  version update. As the project matures there might be less major updates, and more minor
14
14
  updates and patches.
15
15
 
16
+ ## Version 5 Update
17
+
18
+ Version 5.0.0 updated audio interface, instrument bundles are no longer dependant of the main lib and can be loaded in browser environment as independent modules.
19
+
20
+ - How to add and use instrument, see sections [Instruments](#instruments)
21
+ - How to add and use instrument browser version, see sections [Browser Modules](#browser-modules)
22
+
23
+ ## Help Wanted
24
+
25
+ If someone has piano or keyboard and can record samples for me I'd be happy to add a new instrument.
26
+ About ten mp3 samples between C2 to C6 would be fine (named "E2.mp3", etc).
27
+ My email can be found on [GitHub](https://github.com/pahkasoft) (visible for signed in users).
28
+
16
29
  ## Installation
17
30
 
18
31
  ```sh
@@ -45,29 +58,35 @@ import * as Pieces from "@tspro/web-music-score/pieces";
45
58
  const Score = require("@tspro/web-music-score/score");
46
59
  ```
47
60
 
48
- ## Browser Script
61
+ ## Browser Modules
62
+
63
+ This lib can be used in browser via unpkg CDN using iife bundle. It declares
64
+ global name `WebMusicScore` that contains `Core`, `Audio`, `Theory`, `Score`,
65
+ and `Pieces` as corresponding subpath modules.
49
66
 
50
- This module that can be used in html page via unpkg CDN. It declares global variable
51
- `WebMusicScore` that contains `Core`, `Audio`, `Theory`, `Score`, and `Pieces` as
52
- corresponding subpath modules (`react-ui` and `audio-cg` are not included in this
53
- browser module).
67
+ React module `react-ui` is not included available for browser usage.
54
68
 
55
69
  ```html
56
70
  <!--
57
- It is recommended to use exact version number so that if something
58
- breaks between versions then your web site does not stop working.
71
+ It is recommended to use exact version number and direct link to the bundle so
72
+ that if something breaks between versions then your web site does not stop working.
59
73
  -->
60
- <script src="https://unpkg.com/@tspro/web-music-score@4.2.0"></script>
74
+ <script src="https://unpkg.com/@tspro/web-music-score@5.1.0/dist/iife/index.global.js"></script>
61
75
 
62
76
  <!--
63
- Or you can use direct link to the js bundle.
77
+ Classical guitar now also available for browser module.
64
78
  -->
65
- <script src="https://unpkg.com/@tspro/web-music-score@4.2.0/dist/iife/index.global.js"></script>
66
-
79
+ <script src="https://unpkg.com/@tspro/web-music-score@5.1.0/dist/iife/audio-cg.global.js"></script>
67
80
 
68
81
  <script>
82
+ // The lib is available via global name WebMusicScore.
69
83
  const { Core, Audio, Theory, Score, Pieces } = window.WebMusicScore;
70
- // ...
84
+
85
+ // Classical guitar audio is available via global name Audio_ClassicalGuitar.
86
+ const { ClassicalGuitar } = window.Audio_ClassicalGuitar;
87
+
88
+ // Add and use classical guitar instrument.
89
+ Audio.addInstrument(ClassicalGuitar);
71
90
  </script>
72
91
  ```
73
92
 
@@ -131,8 +150,8 @@ or corresponding string values (e.g. `"treble"`).
131
150
  voiceIds: [0, 1] // (optional) only present voices 0 and 1 in this staff
132
151
  })
133
152
  .setScoreConfiguration([
134
- { type: "staff", clef: "G", isGrand: true },
135
- { type: "staff", clef: "F", isGrand: true }
153
+ { type: "staff", clef: "G", grandId: "grand1" },
154
+ { type: "staff", clef: "F", grandId: "grand1" }
136
155
  ]) // Grand staff
137
156
  .setScoreConfiguration([
138
157
  { type: "staff", clef: "G", isOctaveDown: true },
@@ -400,17 +419,32 @@ These are the beam groupings for each time signature.
400
419
  How to set beam grouping for `5/8` and `7/8` time signatures,
401
420
  see [Set Time Signature](#set-time-signature) section above.
402
421
 
403
- ### Classical Guitar Audio Module
422
+ ### Instruments
404
423
 
405
- Default instrument is `Synthesizer`.
424
+ Default instrument `Synthesizer` is available out of the box.
425
+ Other instruments need to be registered manually.
406
426
 
407
427
  `Classical Guitar` is available via `audio-cg` module.
408
- It is included as separate module because it contains over 1MB of guitar audio samples bundled in it.
409
428
 
410
429
  ```js
411
- import { registerClassicalGuitar } from "@tspro/web-music-score/audio-cg";
430
+ // Import classical guitar instrument.
431
+ import { ClassicalGuitar } from "@tspro/web-music-score/audio-cg";
412
432
 
413
- registerClassicalGuitar(); // This registers classical guitar audio, and takes it into use.
433
+ // Add and use classical guitar instrument.
434
+ Audio.addInstrument(ClassicalGuitar);
435
+ ```
436
+
437
+ You can easily create and register your own instrument.
438
+ ```js
439
+ class MyCoolInstrument implements Audio.Instrument {
440
+ constructor() { }
441
+ getName() { return "My Cool Instrument"; }
442
+ playNote(note: string, duration: number, linearVolume: number) { }
443
+ stop() { }
444
+ }
445
+
446
+ // Add and use my cool instrument.
447
+ Audio.addInstrument(new MyCoolInstrument());
414
448
  ```
415
449
 
416
450
  ### Play Document
@@ -435,13 +469,16 @@ Score.MPlayer.stopAll();
435
469
  // Draw document
436
470
  <ScoreUI.MusicScoreView doc={doc} />
437
471
 
438
- // Add playback buttons
439
- <ScoreUI.PlaybackButtons doc={doc} buttonLayout={ScoreUI.PlaybackButtonsLayout.PlayStopSingle}/> // Single Play/Stopo button
440
- <ScoreUI.PlaybackButtons doc={doc} buttonLayout={ScoreUI.PlaybackButtonsLayout.PlayStop}/> // Play and Stop buttons
441
- <ScoreUI.PlaybackButtons doc={doc} buttonLayout={ScoreUI.PlaybackButtonsLayout.PlayPauseStop}/> // Play, Pause and Stop buttons
472
+ // Show playback buttons
473
+ <ScoreUI.PlaybackButtons doc={doc} singlePlayStop /> // Single play/stop button.
474
+ <ScoreUI.PlaybackButtons doc={doc} playStop /> // Play and stop buttons.
475
+ <ScoreUI.PlaybackButtons doc={doc} playPauseStop /> // Play, pause and Stop buttons.
476
+ <ScoreUI.PlaybackButtons doc={doc} /> // Default is play, pause and Stop buttons.
442
477
  ```
443
478
 
444
- Bootstrap is used for better visual appearance, but it needs to be installed and loaded.
479
+ Hint! Bootstrap is used for better visual appearance.
480
+ - Install bootstrap: `npm install bootstrap`
481
+ - Import in app entry: `import "bootstrap/dist/css/bootstrap.min.css";`
445
482
 
446
483
  ### Viewing Using Plain JS/TS
447
484
 
@@ -474,10 +511,10 @@ let p = new Score.MPlaybackButtons().
474
511
  setDocument(doc);
475
512
 
476
513
  // You can also set combined play/stop button.
477
- p.setPlayStopButton("playStopButtonId")
514
+ p.setPlayStopButton("playStopButtonId");
478
515
 
479
516
  // You can also pass HTMLButtonElement instead of element id.
480
- p.setPlayButton(playButtonElement)
517
+ p.setPlayButton(playButtonElement);
481
518
  ```
482
519
 
483
520
  ### MusicError
@@ -1,24 +1,7 @@
1
1
  import { N as Note } from '../note-eA2xPPiG.mjs';
2
+ import { I as Instrument } from '../instrument-DYboobMW.mjs';
3
+ export { l as linearToDecibels } from '../instrument-DYboobMW.mjs';
2
4
 
3
- /** Instrument interface. */
4
- interface Instrument {
5
- /**
6
- * Get instrument name.
7
- * @return - Instrument name.
8
- */
9
- getName(): string;
10
- /**
11
- * Play a note.
12
- * @param note - Note to play (e.g. "C4").
13
- * @param duration - Play duration in seconds.
14
- * @param volume - Linear volume in range [0, 1].
15
- */
16
- playNote(note: string, duration?: number, volume?: number): void;
17
- /**
18
- * Stop playback.
19
- */
20
- stop(): void;
21
- }
22
5
  /**
23
6
  * Get instrument name list.
24
7
  * @returns - Array of available instrument names.
@@ -30,15 +13,15 @@ declare function getInstrumentList(): ReadonlyArray<string>;
30
13
  */
31
14
  declare function getCurrentInstrument(): string;
32
15
  /**
33
- * Register new instrument.
34
- * @param instr - Instrument object implementing Instrument interface.
16
+ * Add and use instrument.
17
+ * @param instrument - Object that implements Instrument interface. Can be single instrument or array of instruments.
35
18
  */
36
- declare function registerInstrument(instr: Instrument): void;
19
+ declare function addInstrument(instrument: Instrument | Instrument[]): void;
37
20
  /**
38
- * Set current instrument to use in playback.
39
- * @param instrName - Instrument name.
21
+ * Set instrument to use in playback.
22
+ * @param instrumentName - Instrument name.
40
23
  */
41
- declare function setInstrument(instrName: string): void;
24
+ declare function useInstrument(instrumentName: string): void;
42
25
  /**
43
26
  * Play a note using current instrument.
44
27
  * @param note - Note instance of Note object, note name (e.g. "C4"), or midiNumber.
@@ -47,8 +30,21 @@ declare function setInstrument(instrName: string): void;
47
30
  */
48
31
  declare function playNote(note: Note | string | number, duration?: number, linearVolume?: number): void;
49
32
  /**
50
- * Stop playing on current instrument.
33
+ * Stop playback on current instrument.
51
34
  */
52
35
  declare function stop(): void;
36
+ /**
37
+ * Mute playback on current instrument.
38
+ */
39
+ declare function mute(): void;
40
+ /**
41
+ * Unmute playback on current instrument.
42
+ */
43
+ declare function unmute(): void;
44
+ /**
45
+ * Is playback muted?
46
+ * @returns True/false.
47
+ */
48
+ declare function isMuted(): boolean;
53
49
 
54
- export { type Instrument, getCurrentInstrument, getInstrumentList, playNote, registerInstrument, setInstrument, stop };
50
+ export { Instrument, addInstrument, getCurrentInstrument, getInstrumentList, isMuted, mute, playNote, stop, unmute, useInstrument };
@@ -1,24 +1,7 @@
1
1
  import { N as Note } from '../note-eA2xPPiG.js';
2
+ import { I as Instrument } from '../instrument-DYboobMW.js';
3
+ export { l as linearToDecibels } from '../instrument-DYboobMW.js';
2
4
 
3
- /** Instrument interface. */
4
- interface Instrument {
5
- /**
6
- * Get instrument name.
7
- * @return - Instrument name.
8
- */
9
- getName(): string;
10
- /**
11
- * Play a note.
12
- * @param note - Note to play (e.g. "C4").
13
- * @param duration - Play duration in seconds.
14
- * @param volume - Linear volume in range [0, 1].
15
- */
16
- playNote(note: string, duration?: number, volume?: number): void;
17
- /**
18
- * Stop playback.
19
- */
20
- stop(): void;
21
- }
22
5
  /**
23
6
  * Get instrument name list.
24
7
  * @returns - Array of available instrument names.
@@ -30,15 +13,15 @@ declare function getInstrumentList(): ReadonlyArray<string>;
30
13
  */
31
14
  declare function getCurrentInstrument(): string;
32
15
  /**
33
- * Register new instrument.
34
- * @param instr - Instrument object implementing Instrument interface.
16
+ * Add and use instrument.
17
+ * @param instrument - Object that implements Instrument interface. Can be single instrument or array of instruments.
35
18
  */
36
- declare function registerInstrument(instr: Instrument): void;
19
+ declare function addInstrument(instrument: Instrument | Instrument[]): void;
37
20
  /**
38
- * Set current instrument to use in playback.
39
- * @param instrName - Instrument name.
21
+ * Set instrument to use in playback.
22
+ * @param instrumentName - Instrument name.
40
23
  */
41
- declare function setInstrument(instrName: string): void;
24
+ declare function useInstrument(instrumentName: string): void;
42
25
  /**
43
26
  * Play a note using current instrument.
44
27
  * @param note - Note instance of Note object, note name (e.g. "C4"), or midiNumber.
@@ -47,8 +30,21 @@ declare function setInstrument(instrName: string): void;
47
30
  */
48
31
  declare function playNote(note: Note | string | number, duration?: number, linearVolume?: number): void;
49
32
  /**
50
- * Stop playing on current instrument.
33
+ * Stop playback on current instrument.
51
34
  */
52
35
  declare function stop(): void;
36
+ /**
37
+ * Mute playback on current instrument.
38
+ */
39
+ declare function mute(): void;
40
+ /**
41
+ * Unmute playback on current instrument.
42
+ */
43
+ declare function unmute(): void;
44
+ /**
45
+ * Is playback muted?
46
+ * @returns True/false.
47
+ */
48
+ declare function isMuted(): boolean;
53
49
 
54
- export { type Instrument, getCurrentInstrument, getInstrumentList, playNote, registerInstrument, setInstrument, stop };
50
+ export { Instrument, addInstrument, getCurrentInstrument, getInstrumentList, isMuted, mute, playNote, stop, unmute, useInstrument };
@@ -1,12 +1,9 @@
1
- /* WebMusicScore v4.2.1 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
1
+ /* WebMusicScore v5.1.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
2
2
  "use strict";
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
7
  var __export = (target, all) => {
11
8
  for (var name in all)
12
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -19,82 +16,34 @@ var __copyProps = (to, from, except, desc) => {
19
16
  }
20
17
  return to;
21
18
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
20
 
33
21
  // src/audio/index.ts
34
22
  var audio_exports = {};
35
23
  __export(audio_exports, {
24
+ addInstrument: () => addInstrument,
36
25
  getCurrentInstrument: () => getCurrentInstrument,
37
26
  getInstrumentList: () => getInstrumentList,
27
+ isMuted: () => isMuted,
28
+ linearToDecibels: () => linearToDecibels,
29
+ mute: () => mute,
38
30
  playNote: () => playNote,
39
- registerInstrument: () => registerInstrument,
40
- setInstrument: () => setInstrument,
41
- stop: () => stop
31
+ stop: () => stop,
32
+ unmute: () => unmute,
33
+ useInstrument: () => useInstrument
42
34
  });
43
35
  module.exports = __toCommonJS(audio_exports);
44
36
  var import_theory = require("@tspro/web-music-score/theory");
37
+ var import_core = require("@tspro/web-music-score/core");
38
+ var import_audio_synth = require("@tspro/web-music-score/audio-synth");
45
39
 
46
- // src/audio/synth.ts
47
- var Tone = __toESM(require("tone"));
48
- var import_ts_utils_lib = require("@tspro/ts-utils-lib");
49
- var Synth2 = class {
50
- constructor() {
51
- __publicField(this, "audioSource");
52
- try {
53
- const reverb = new Tone.Reverb({ decay: 3, wet: 0.4 }).toDestination();
54
- const filter = new Tone.Filter(800, "lowpass").connect(reverb);
55
- this.audioSource = new Tone.PolySynth(Tone.Synth, {
56
- oscillator: {
57
- type: "triangle"
58
- },
59
- envelope: {
60
- attack: 1e-3,
61
- decay: 2,
62
- sustain: 0.1,
63
- release: 1.2
64
- }
65
- }).connect(filter);
66
- } catch (err) {
67
- this.audioSource = void 0;
68
- console.error(err);
69
- }
70
- }
71
- getName() {
72
- return "Synthesizer";
73
- }
74
- playNote(note, duration, linearVolume) {
75
- try {
76
- if (this.audioSource) {
77
- if (linearVolume !== void 0) {
78
- this.audioSource.volume.value = import_ts_utils_lib.Utils.Math.linearToDecibels(linearVolume);
79
- }
80
- this.audioSource.triggerAttackRelease(note, duration != null ? duration : "2n");
81
- }
82
- } catch (err) {
83
- }
84
- }
85
- stop() {
86
- try {
87
- if (this.audioSource) {
88
- this.audioSource.releaseAll();
89
- }
90
- } catch (err) {
91
- }
92
- }
93
- };
94
- var Synthesizer = new Synth2();
40
+ // src/audio/instrument.ts
41
+ function linearToDecibels(linearVolume) {
42
+ return !isFinite(linearVolume) || linearVolume <= 0 ? -Infinity : 20 * Math.log10(linearVolume);
43
+ }
95
44
 
96
45
  // src/audio/index.ts
97
- var import_core = require("@tspro/web-music-score/core");
46
+ var import_ts_utils_lib = require("@tspro/ts-utils-lib");
98
47
  (0, import_core.init)();
99
48
  function getNoteName(note) {
100
49
  if (typeof note === "string") {
@@ -104,44 +53,73 @@ function getNoteName(note) {
104
53
  }
105
54
  return note.format(import_theory.PitchNotation.Scientific, import_theory.SymbolSet.Ascii);
106
55
  }
107
- var InstrumentList = [Synthesizer];
108
- var CurrentInstrument = Synthesizer;
56
+ var InstrumentList = [import_audio_synth.Synthesizer];
57
+ var currentInstrument = import_audio_synth.Synthesizer;
58
+ var DefaultDuration = (function calcDuration(noteSize, beatsPerMinute, timeTisgnature) {
59
+ var _a;
60
+ let beatSize = parseInt((_a = timeTisgnature.split("/")[1]) != null ? _a : "4");
61
+ return 60 * (1 / noteSize) / (beatsPerMinute * (1 / beatSize));
62
+ })(2, 80, "4/4");
63
+ var DefaultVolume = 1;
64
+ var mutePlayback = false;
109
65
  function getInstrumentList() {
110
66
  return InstrumentList.map((instr) => instr.getName());
111
67
  }
112
68
  function getCurrentInstrument() {
113
- return CurrentInstrument.getName();
69
+ return currentInstrument.getName();
114
70
  }
115
- function registerInstrument(instr) {
116
- if (InstrumentList.some((instr2) => instr2.getName() === instr.getName())) {
117
- return;
118
- }
119
- InstrumentList.push(instr);
120
- setInstrument(instr.getName());
71
+ function addInstrument(instrument) {
72
+ (import_ts_utils_lib.Utils.Is.isArray(instrument) ? instrument : [instrument]).forEach((instr) => {
73
+ if (!import_ts_utils_lib.Utils.Obj.hasProperties(instr, ["getName", "playNote", "stop"]) || !import_ts_utils_lib.Utils.Is.isFunction(instr.getName) || !import_ts_utils_lib.Utils.Is.isFunction(instr.playNote) || !import_ts_utils_lib.Utils.Is.isFunction(instr.stop)) {
74
+ throw new import_core.MusicError(import_core.MusicErrorType.Audio, "Invalid instrument object: " + instr);
75
+ }
76
+ if (InstrumentList.some((instr2) => instr2.getName() === instr.getName())) {
77
+ console.warn(`Instrument "${instr.getName()}" already registered!`);
78
+ } else {
79
+ InstrumentList.push(instr);
80
+ }
81
+ useInstrument(instr.getName());
82
+ });
121
83
  }
122
- function setInstrument(instrName) {
123
- if (instrName === CurrentInstrument.getName()) {
84
+ function useInstrument(instrumentName) {
85
+ if (instrumentName === currentInstrument.getName()) {
124
86
  return;
125
87
  }
126
- CurrentInstrument.stop();
127
- let instr = InstrumentList.find((instr2) => instr2.getName() === instrName);
88
+ currentInstrument.stop();
89
+ let instr = InstrumentList.find((instr2) => instr2.getName() === instrumentName);
128
90
  if (instr) {
129
- CurrentInstrument = instr;
91
+ currentInstrument = instr;
130
92
  }
131
93
  }
132
94
  function playNote(note, duration, linearVolume) {
133
- CurrentInstrument.playNote(getNoteName(note), duration, linearVolume);
95
+ if (!mutePlayback) {
96
+ currentInstrument.playNote(getNoteName(note), duration != null ? duration : DefaultDuration, linearVolume != null ? linearVolume : DefaultVolume);
97
+ }
134
98
  }
135
99
  function stop() {
136
- CurrentInstrument.stop();
100
+ currentInstrument.stop();
101
+ }
102
+ function mute() {
103
+ stop();
104
+ mutePlayback = true;
105
+ }
106
+ function unmute() {
107
+ mutePlayback = false;
108
+ }
109
+ function isMuted() {
110
+ return mutePlayback;
137
111
  }
138
112
  // Annotate the CommonJS export names for ESM import in node:
139
113
  0 && (module.exports = {
114
+ addInstrument,
140
115
  getCurrentInstrument,
141
116
  getInstrumentList,
117
+ isMuted,
118
+ linearToDecibels,
119
+ mute,
142
120
  playNote,
143
- registerInstrument,
144
- setInstrument,
145
- stop
121
+ stop,
122
+ unmute,
123
+ useInstrument
146
124
  });
147
125
  //# sourceMappingURL=index.js.map