@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.
- package/CHANGELOG.md +26 -0
- package/README.md +63 -26
- package/dist/audio/index.d.mts +23 -27
- package/dist/audio/index.d.ts +23 -27
- package/dist/audio/index.js +63 -85
- package/dist/audio/index.mjs +53 -73
- package/dist/audio-cg/index.d.mts +18 -3
- package/dist/audio-cg/index.d.ts +18 -3
- package/dist/audio-cg/index.js +54 -51
- package/dist/audio-cg/index.mjs +49 -52
- package/dist/audio-synth/index.d.mts +15 -0
- package/dist/audio-synth/index.d.ts +15 -0
- package/dist/audio-synth/index.js +95 -0
- package/dist/audio-synth/index.mjs +58 -0
- package/dist/{chunk-64N22LCV.mjs → chunk-2EQHSQWO.mjs} +2 -2
- package/dist/{chunk-RQFFLRWF.mjs → chunk-QVYFIK3L.mjs} +5 -6
- package/dist/chunk-ROPTZBKD.mjs +11 -0
- package/dist/core/index.d.mts +2 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +3 -2
- package/dist/core/index.mjs +4 -3
- package/dist/iife/audio-cg.global.js +220 -0
- package/dist/iife/index.global.js +11 -11
- package/dist/instrument-DYboobMW.d.mts +44 -0
- package/dist/instrument-DYboobMW.d.ts +44 -0
- package/dist/{music-objects-CI7IjsjE.d.ts → music-objects-CMdYZeC6.d.ts} +118 -36
- package/dist/{music-objects-3Hxlkxy6.d.mts → music-objects-DTDFSro0.d.mts} +118 -36
- package/dist/pieces/index.d.mts +1 -1
- package/dist/pieces/index.d.ts +1 -1
- package/dist/pieces/index.js +1 -1
- package/dist/pieces/index.mjs +2 -2
- package/dist/react-ui/index.d.mts +52 -33
- package/dist/react-ui/index.d.ts +52 -33
- package/dist/react-ui/index.js +41 -32
- package/dist/react-ui/index.mjs +42 -33
- package/dist/score/index.d.mts +8 -8
- package/dist/score/index.d.ts +8 -8
- package/dist/score/index.js +1998 -1626
- package/dist/score/index.mjs +1584 -1211
- package/dist/theory/index.js +3 -4
- package/dist/theory/index.mjs +3 -3
- package/package.json +13 -3
package/dist/audio/index.mjs
CHANGED
|
@@ -1,63 +1,14 @@
|
|
|
1
|
-
/* WebMusicScore
|
|
1
|
+
/* WebMusicScore v5.1.0 | (c) 2023 PahkaSoft | MIT License | Includes: Tone.js (MIT License) */
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "../chunk-
|
|
3
|
+
linearToDecibels
|
|
4
|
+
} from "../chunk-ROPTZBKD.mjs";
|
|
5
|
+
import "../chunk-2EQHSQWO.mjs";
|
|
5
6
|
|
|
6
7
|
// src/audio/index.ts
|
|
7
8
|
import { Note, PitchNotation, SymbolSet } from "@tspro/web-music-score/theory";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import * as Tone from "tone";
|
|
9
|
+
import { init as initCore, MusicError, MusicErrorType } from "@tspro/web-music-score/core";
|
|
10
|
+
import { Synthesizer } from "@tspro/web-music-score/audio-synth";
|
|
11
11
|
import { Utils } from "@tspro/ts-utils-lib";
|
|
12
|
-
var Synth2 = class {
|
|
13
|
-
constructor() {
|
|
14
|
-
__publicField(this, "audioSource");
|
|
15
|
-
try {
|
|
16
|
-
const reverb = new Tone.Reverb({ decay: 3, wet: 0.4 }).toDestination();
|
|
17
|
-
const filter = new Tone.Filter(800, "lowpass").connect(reverb);
|
|
18
|
-
this.audioSource = new Tone.PolySynth(Tone.Synth, {
|
|
19
|
-
oscillator: {
|
|
20
|
-
type: "triangle"
|
|
21
|
-
},
|
|
22
|
-
envelope: {
|
|
23
|
-
attack: 1e-3,
|
|
24
|
-
decay: 2,
|
|
25
|
-
sustain: 0.1,
|
|
26
|
-
release: 1.2
|
|
27
|
-
}
|
|
28
|
-
}).connect(filter);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
this.audioSource = void 0;
|
|
31
|
-
console.error(err);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
getName() {
|
|
35
|
-
return "Synthesizer";
|
|
36
|
-
}
|
|
37
|
-
playNote(note, duration, linearVolume) {
|
|
38
|
-
try {
|
|
39
|
-
if (this.audioSource) {
|
|
40
|
-
if (linearVolume !== void 0) {
|
|
41
|
-
this.audioSource.volume.value = Utils.Math.linearToDecibels(linearVolume);
|
|
42
|
-
}
|
|
43
|
-
this.audioSource.triggerAttackRelease(note, duration != null ? duration : "2n");
|
|
44
|
-
}
|
|
45
|
-
} catch (err) {
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
stop() {
|
|
49
|
-
try {
|
|
50
|
-
if (this.audioSource) {
|
|
51
|
-
this.audioSource.releaseAll();
|
|
52
|
-
}
|
|
53
|
-
} catch (err) {
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var Synthesizer = new Synth2();
|
|
58
|
-
|
|
59
|
-
// src/audio/index.ts
|
|
60
|
-
import { init as initCore } from "@tspro/web-music-score/core";
|
|
61
12
|
initCore();
|
|
62
13
|
function getNoteName(note) {
|
|
63
14
|
if (typeof note === "string") {
|
|
@@ -68,42 +19,71 @@ function getNoteName(note) {
|
|
|
68
19
|
return note.format(PitchNotation.Scientific, SymbolSet.Ascii);
|
|
69
20
|
}
|
|
70
21
|
var InstrumentList = [Synthesizer];
|
|
71
|
-
var
|
|
22
|
+
var currentInstrument = Synthesizer;
|
|
23
|
+
var DefaultDuration = (function calcDuration(noteSize, beatsPerMinute, timeTisgnature) {
|
|
24
|
+
var _a;
|
|
25
|
+
let beatSize = parseInt((_a = timeTisgnature.split("/")[1]) != null ? _a : "4");
|
|
26
|
+
return 60 * (1 / noteSize) / (beatsPerMinute * (1 / beatSize));
|
|
27
|
+
})(2, 80, "4/4");
|
|
28
|
+
var DefaultVolume = 1;
|
|
29
|
+
var mutePlayback = false;
|
|
72
30
|
function getInstrumentList() {
|
|
73
31
|
return InstrumentList.map((instr) => instr.getName());
|
|
74
32
|
}
|
|
75
33
|
function getCurrentInstrument() {
|
|
76
|
-
return
|
|
34
|
+
return currentInstrument.getName();
|
|
77
35
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
36
|
+
function addInstrument(instrument) {
|
|
37
|
+
(Utils.Is.isArray(instrument) ? instrument : [instrument]).forEach((instr) => {
|
|
38
|
+
if (!Utils.Obj.hasProperties(instr, ["getName", "playNote", "stop"]) || !Utils.Is.isFunction(instr.getName) || !Utils.Is.isFunction(instr.playNote) || !Utils.Is.isFunction(instr.stop)) {
|
|
39
|
+
throw new MusicError(MusicErrorType.Audio, "Invalid instrument object: " + instr);
|
|
40
|
+
}
|
|
41
|
+
if (InstrumentList.some((instr2) => instr2.getName() === instr.getName())) {
|
|
42
|
+
console.warn(`Instrument "${instr.getName()}" already registered!`);
|
|
43
|
+
} else {
|
|
44
|
+
InstrumentList.push(instr);
|
|
45
|
+
}
|
|
46
|
+
useInstrument(instr.getName());
|
|
47
|
+
});
|
|
84
48
|
}
|
|
85
|
-
function
|
|
86
|
-
if (
|
|
49
|
+
function useInstrument(instrumentName) {
|
|
50
|
+
if (instrumentName === currentInstrument.getName()) {
|
|
87
51
|
return;
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
let instr = InstrumentList.find((instr2) => instr2.getName() ===
|
|
53
|
+
currentInstrument.stop();
|
|
54
|
+
let instr = InstrumentList.find((instr2) => instr2.getName() === instrumentName);
|
|
91
55
|
if (instr) {
|
|
92
|
-
|
|
56
|
+
currentInstrument = instr;
|
|
93
57
|
}
|
|
94
58
|
}
|
|
95
59
|
function playNote(note, duration, linearVolume) {
|
|
96
|
-
|
|
60
|
+
if (!mutePlayback) {
|
|
61
|
+
currentInstrument.playNote(getNoteName(note), duration != null ? duration : DefaultDuration, linearVolume != null ? linearVolume : DefaultVolume);
|
|
62
|
+
}
|
|
97
63
|
}
|
|
98
64
|
function stop() {
|
|
99
|
-
|
|
65
|
+
currentInstrument.stop();
|
|
66
|
+
}
|
|
67
|
+
function mute() {
|
|
68
|
+
stop();
|
|
69
|
+
mutePlayback = true;
|
|
70
|
+
}
|
|
71
|
+
function unmute() {
|
|
72
|
+
mutePlayback = false;
|
|
73
|
+
}
|
|
74
|
+
function isMuted() {
|
|
75
|
+
return mutePlayback;
|
|
100
76
|
}
|
|
101
77
|
export {
|
|
78
|
+
addInstrument,
|
|
102
79
|
getCurrentInstrument,
|
|
103
80
|
getInstrumentList,
|
|
81
|
+
isMuted,
|
|
82
|
+
linearToDecibels,
|
|
83
|
+
mute,
|
|
104
84
|
playNote,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
85
|
+
stop,
|
|
86
|
+
unmute,
|
|
87
|
+
useInstrument
|
|
108
88
|
};
|
|
109
89
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import { I as Instrument } from '../instrument-DYboobMW.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Make this module "audio-cg" in typedoc instead of "audio-instruments/audio-cg".
|
|
5
|
+
* @module audio-cg
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
|
-
*
|
|
9
|
+
* Export classical guitar instrument object.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Usage
|
|
13
|
+
* import * as Audio from "@tspro/web-music-score/audio";
|
|
14
|
+
* import { ClassicalGuitar } from "@tspro/web-music-score/audio-cg";
|
|
15
|
+
*
|
|
16
|
+
* Audio.addInstrument(ClassicalGuitar);
|
|
17
|
+
* ```
|
|
3
18
|
*/
|
|
4
|
-
declare
|
|
19
|
+
declare const ClassicalGuitar: Instrument;
|
|
5
20
|
|
|
6
|
-
export {
|
|
21
|
+
export { ClassicalGuitar };
|
package/dist/audio-cg/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import { I as Instrument } from '../instrument-DYboobMW.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Make this module "audio-cg" in typedoc instead of "audio-instruments/audio-cg".
|
|
5
|
+
* @module audio-cg
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
|
-
*
|
|
9
|
+
* Export classical guitar instrument object.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Usage
|
|
13
|
+
* import * as Audio from "@tspro/web-music-score/audio";
|
|
14
|
+
* import { ClassicalGuitar } from "@tspro/web-music-score/audio-cg";
|
|
15
|
+
*
|
|
16
|
+
* Audio.addInstrument(ClassicalGuitar);
|
|
17
|
+
* ```
|
|
3
18
|
*/
|
|
4
|
-
declare
|
|
19
|
+
declare const ClassicalGuitar: Instrument;
|
|
5
20
|
|
|
6
|
-
export {
|
|
21
|
+
export { ClassicalGuitar };
|