@tspro/web-music-score 1.1.0 → 2.0.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 +10 -0
- package/README.md +247 -195
- package/dist/audio/index.d.mts +22 -0
- package/dist/audio/index.d.ts +22 -0
- package/dist/audio/index.js +147 -0
- package/dist/audio/index.mjs +109 -0
- package/dist/audio-cg/index.d.mts +4 -0
- package/dist/audio-cg/index.d.ts +4 -0
- package/dist/audio-cg/index.js +124 -0
- package/dist/audio-cg/index.mjs +91 -0
- package/dist/chunk-2EPWQZKJ.mjs +9 -0
- package/dist/core/index.d.mts +21 -0
- package/dist/core/index.d.ts +21 -0
- package/dist/core/index.js +72 -0
- package/dist/core/index.mjs +45 -0
- package/dist/guitar-BIFwFT31.d.ts +24 -0
- package/dist/guitar-kbJYu3Am.d.mts +24 -0
- package/dist/iife/index.global.js +222 -0
- package/dist/note-B5ZtlHc8.d.ts +99 -0
- package/dist/note-CraqEy8x.d.mts +99 -0
- package/dist/pieces/index.d.mts +15 -0
- package/dist/pieces/index.d.ts +15 -0
- package/dist/pieces/index.js +104 -0
- package/dist/pieces/index.mjs +77 -0
- package/dist/react-ui/index.d.mts +169 -0
- package/dist/react-ui/index.d.ts +169 -0
- package/dist/react-ui/index.js +624 -0
- package/dist/react-ui/index.mjs +582 -0
- package/dist/score/index.d.mts +1558 -0
- package/dist/score/index.d.ts +1558 -0
- package/dist/score/index.js +6937 -0
- package/dist/score/index.mjs +6863 -0
- package/dist/tempo--588tdcv.d.ts +203 -0
- package/dist/tempo-BEJBHZ5I.d.mts +203 -0
- package/dist/theory/index.d.mts +47 -0
- package/dist/theory/index.d.ts +47 -0
- package/dist/theory/index.js +1783 -0
- package/dist/theory/index.mjs +1716 -0
- package/package.json +98 -55
- package/dist/index.cjs.js +0 -41053
- package/dist/index.d.ts +0 -1281
- package/dist/index.esm.mjs +0 -41044
- package/dist/index.umd.min.js +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.0] - 2025-07-28
|
|
4
|
+
Major update and brought many changes.
|
|
5
|
+
### ** Breaking Changes **
|
|
6
|
+
- Use subpath modules. There is no main export.
|
|
7
|
+
- Refactored musical terms that were wrong (e.g. pitch => diatonicId, noteId => chromaticId).
|
|
8
|
+
- Score module stayed mostly same. Some changes (e.g. enum StaffKind => StaffPreset) but nothing major.
|
|
9
|
+
- Classical guitar audio was put into separate module (audio-cg) because it bundles over 1MB of audio
|
|
10
|
+
samples. Also improved default synthesizer audio.
|
|
11
|
+
- Numerous other unlisted changes/improvements/fixes.
|
|
12
|
+
|
|
3
13
|
## [1.1.0] - 2025-07-03
|
|
4
14
|
### Added
|
|
5
15
|
- Preliminary support for rendering guitar tabs.
|
package/README.md
CHANGED
|
@@ -2,85 +2,121 @@
|
|
|
2
2
|
|
|
3
3
|
This library allows you to view and play music scores (notation) in the browser.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
I'm not a professional musician. I began learning classical guitar on my own,
|
|
6
6
|
later taking lessons in classical guitar. I've also studied music theory independently.
|
|
7
7
|
|
|
8
|
-
This
|
|
9
|
-
|
|
8
|
+
This is a work in progress project. Expect changes, bugs, or unexpected behavior.
|
|
9
|
+
|
|
10
|
+
## Version 2 Update
|
|
11
|
+
|
|
12
|
+
**Breaking:** Version 2 is major update and brought many changes.
|
|
13
|
+
|
|
14
|
+
* Introduced subpath modules instead of one big main module. There is no main export.
|
|
15
|
+
* Theory module had big refactor that affected whole library. Renamed all musical terms that
|
|
16
|
+
were wrong (e.g. pitch => diatonicId, noteId => chromaticId).
|
|
17
|
+
* Score module stayed mostly same. Some changes (e.g. enum StaffKind => StaffPreset) but nothing major.
|
|
18
|
+
* Classical guitar audio was put into separate module (audio-cg) because it bundles over 1MB of audio
|
|
19
|
+
samples. Also improved default synthesizer audio.
|
|
20
|
+
* Numerous small changes/improvements.
|
|
21
|
+
|
|
22
|
+
Enough changes until next major update!
|
|
10
23
|
|
|
11
24
|
## Installation
|
|
12
25
|
|
|
13
26
|
```sh
|
|
14
27
|
npm i @tspro/web-music-score
|
|
15
|
-
|
|
16
|
-
# React is required, it is peer dependency
|
|
17
|
-
npm i react
|
|
18
28
|
```
|
|
19
29
|
|
|
20
|
-
##
|
|
30
|
+
## Import
|
|
21
31
|
|
|
22
|
-
### Usage
|
|
23
|
-
|
|
24
|
-
#### Import (ESM)
|
|
25
32
|
```js
|
|
26
|
-
// Import
|
|
27
|
-
import * as
|
|
33
|
+
// Import core module, it does not contain much.
|
|
34
|
+
import * as Core from "@tspro/web-music-score/core";
|
|
28
35
|
|
|
29
|
-
// Import
|
|
30
|
-
import
|
|
31
|
-
```
|
|
36
|
+
// Import audio module, it can play notes.
|
|
37
|
+
import * as Audio from "@tspro/web-music-score/audio";
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
// Import theory module, it contains all music theory stuff.
|
|
40
|
+
import * as Theory from "@tspro/web-music-score/theory";
|
|
41
|
+
|
|
42
|
+
// Import score module, it contains music score stuff.
|
|
43
|
+
import * as Score from "@tspro/web-music-score/score";
|
|
44
|
+
|
|
45
|
+
// Import react-ui module, it contains all react components.
|
|
46
|
+
// React is peer dependency "^18.0.0 || ^19.0.0".
|
|
47
|
+
import * as ScoreUI from "@tspro/web-music-score/react-ui";
|
|
48
|
+
|
|
49
|
+
// Import pieces module, it contains demo songs.
|
|
50
|
+
import * as Pieces from "@tspro/web-music-score/pieces";
|
|
51
|
+
|
|
52
|
+
// You can also use require
|
|
53
|
+
const Core = require("@tspro/web-music-score/core");
|
|
54
|
+
|
|
55
|
+
// etc.
|
|
37
56
|
```
|
|
38
57
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
## Browser Script
|
|
59
|
+
|
|
60
|
+
This is an experimental module that can be used in html page via unpkg CDN.
|
|
61
|
+
It declares global variable `WebMusicScore` that contains `Core`, `Audio`, `Theory`, `Score`,
|
|
62
|
+
and `Pieces` as corresponding subpath modules (excluding `react-ui` and `audio-cg`).
|
|
42
63
|
|
|
43
64
|
```html
|
|
44
|
-
<script src="https://unpkg.com/@tspro/web-music-score@
|
|
65
|
+
<script src="https://unpkg.com/@tspro/web-music-score@2.0.0"></script>
|
|
66
|
+
|
|
67
|
+
<!--
|
|
68
|
+
It is recommended to use version number (e.g. @2.0.0, at least use @2). This way
|
|
69
|
+
if there is breaking change between versions your code does not stop working.
|
|
45
70
|
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
TODO: Add direct link to bundle.
|
|
72
|
+
-->
|
|
48
73
|
|
|
49
74
|
<script>
|
|
50
|
-
const Score = window.WebMusicScore;
|
|
75
|
+
const { Core, Audio, Theory, Score, Pieces } = window.WebMusicScore;
|
|
51
76
|
// ...
|
|
52
77
|
</script>
|
|
53
78
|
```
|
|
54
79
|
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
Typedoc API reference is available [here](https://pahkasoft.github.io). It has no comments but
|
|
83
|
+
is mostly self explanatory and gives idea of full API.
|
|
84
|
+
|
|
85
|
+
Following is the main interface explained.
|
|
86
|
+
|
|
55
87
|
### Create Document
|
|
56
88
|
|
|
57
89
|
```js
|
|
58
|
-
let doc = new Score.MDocument(Score.
|
|
90
|
+
let doc = new Score.MDocument(staffPreset: Score.StaffPreset, options: Score.DocumentOptions);
|
|
59
91
|
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* `
|
|
63
|
-
* `
|
|
64
|
-
* `
|
|
65
|
-
* `
|
|
66
|
-
* `
|
|
67
|
-
* `GuitarTrebleAndTab`: Treble and tab for guitar.
|
|
92
|
+
`staffPreset` can be:
|
|
93
|
+
* `Score.StaffPreset.Treble`: Staff with treble (G-) clef.
|
|
94
|
+
* `Score.StaffPreset.Bass`: Staff with bass (F-) clef.
|
|
95
|
+
* `Score.StaffPreset.Grand`: Both treble and bas staves.
|
|
96
|
+
* `Score.StaffPreset.GuitarTreble`: `Treble` but one octave lower.
|
|
97
|
+
* `Score.StaffPreset.GuitarTab`: Guitar tab only.
|
|
98
|
+
* `Score.StaffPreset.GuitarCombined`: Treble and tab for guitar.
|
|
68
99
|
|
|
69
100
|
Second argument is optional `DocumentOptions`:
|
|
70
101
|
```ts
|
|
71
102
|
DocumentOptions = { measuresPerRow?: number, tuning?: string }
|
|
72
103
|
```
|
|
73
104
|
|
|
74
|
-
Default tuning is `"Standard"`. `TuningNameList` is array of available tuning names.
|
|
105
|
+
Default tuning is `"Standard"`. `Theory.TuningNameList` is array of available tuning names.
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
// Example
|
|
109
|
+
let doc = new Score.MDocument(Score.StaffPreset.GuitarCombined, { tuning: "Drop D" });
|
|
110
|
+
```
|
|
75
111
|
|
|
76
112
|
### Set Header
|
|
77
113
|
|
|
78
114
|
```js
|
|
79
|
-
doc.setHeader(
|
|
80
|
-
doc.setHeader("Title");
|
|
81
|
-
```
|
|
115
|
+
doc.setHeader(title?: string, composer?: string, arranger?: string);
|
|
82
116
|
|
|
83
|
-
|
|
117
|
+
// Example
|
|
118
|
+
doc.setHeader("Demo Song");
|
|
119
|
+
```
|
|
84
120
|
|
|
85
121
|
### Add Measure
|
|
86
122
|
|
|
@@ -94,244 +130,269 @@ let m = doc.addMeasure();
|
|
|
94
130
|
m.endRow();
|
|
95
131
|
```
|
|
96
132
|
|
|
97
|
-
Manually induce row change. Next measure
|
|
133
|
+
Manually induce row change. Next measure that is added will start new row.
|
|
98
134
|
|
|
99
135
|
### Set Signature
|
|
100
136
|
|
|
101
137
|
```js
|
|
102
|
-
m.setKeySignature(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`
|
|
138
|
+
m.setKeySignature(tonic: string, scaleType: Theory.ScaleType);
|
|
139
|
+
|
|
140
|
+
// Example: Am
|
|
141
|
+
m.setKeySignature("A", Theory.ScaleType.Aeolian);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`tonic` is scale tonic/root note, e.g. "C" (in "C Major").
|
|
145
|
+
|
|
146
|
+
`scaleType` can be
|
|
147
|
+
- `Theory.ScaleType.Major`
|
|
148
|
+
- `Theory.ScaleType.NaturalMinor`
|
|
149
|
+
- `Theory.ScaleType.HarmonicMinor`
|
|
150
|
+
- `Theory.ScaleType.Ionian`
|
|
151
|
+
- `Theory.ScaleType.Dorian`
|
|
152
|
+
- `Theory.ScaleType.Phrygian`
|
|
153
|
+
- `Theory.ScaleType.Lydian`
|
|
154
|
+
- `Theory.ScaleType.Mixolydian`
|
|
155
|
+
- `Theory.ScaleType.Aeolian`
|
|
156
|
+
- `Theory.ScaleType.Locrian`
|
|
157
|
+
- `Theory.ScaleType.MajorPentatonic`
|
|
158
|
+
- `Theory.ScaleType.MinorPentatonic`
|
|
159
|
+
- `Theory.ScaleType.MajorHexatonicBlues`
|
|
160
|
+
- `Theory.ScaleType.MinorHexatonicBlues`
|
|
161
|
+
- `Theory.ScaleType.HeptatonicBlues`
|
|
109
162
|
|
|
110
163
|
```js
|
|
111
|
-
m.setTimeSignature(
|
|
164
|
+
m.setTimeSignature(timeSignature: string);
|
|
165
|
+
|
|
166
|
+
// Example
|
|
167
|
+
m.setTimeSignature("3/4");
|
|
112
168
|
```
|
|
113
169
|
|
|
114
|
-
|
|
170
|
+
timeSignature can be:
|
|
171
|
+
- `"2/4"`
|
|
172
|
+
- `"3/4"`
|
|
173
|
+
- `"4/4"`
|
|
174
|
+
- `"6/8"`
|
|
175
|
+
- `"9/8"`
|
|
115
176
|
|
|
116
177
|
```js
|
|
117
|
-
m.setTempo(
|
|
118
|
-
|
|
178
|
+
m.setTempo(beatsPerMinute: number, beatLength?: Theory.NoteLength, dotted?: boolean);
|
|
179
|
+
|
|
180
|
+
// Example
|
|
181
|
+
m.setTempo(100, Theory.NoteLength.Quarter);
|
|
119
182
|
```
|
|
120
183
|
|
|
121
|
-
|
|
184
|
+
`beatsPerMinute` is self explanatory.
|
|
185
|
+
|
|
186
|
+
`beatLength` tells the length of each beat, e.g. Theory.NoteLength.Quarter.
|
|
122
187
|
|
|
123
|
-
|
|
188
|
+
`dotted` tells if `beatLength` is dotted.
|
|
124
189
|
|
|
125
190
|
### Add Note Or Chord
|
|
126
191
|
|
|
127
192
|
```js
|
|
128
|
-
m.addNote(voiceId, note, noteLength, noteOptions
|
|
129
|
-
m.addChord(voiceId, notes, noteLength, noteOptions);
|
|
130
|
-
```
|
|
193
|
+
m.addNote(voiceId: number, note: string, noteLength: Theory.NoteLength, noteOptions?: Score.NoteOptions);
|
|
194
|
+
m.addChord(voiceId: number, notes: string[], noteLength: Theory.NoteLength, noteOptions?: Score.NoteOptions);
|
|
131
195
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
* `noteLength`: Note length (e.g. `NoteLength.Half`), see below
|
|
136
|
-
* `noteOptions`: Optional note otions, see below
|
|
137
|
-
|
|
138
|
-
Examples:
|
|
139
|
-
```js
|
|
140
|
-
m.addNote(0, "C3", Score.NoteLength.Quarter);
|
|
141
|
-
m.addChord(1, ["C3", "E3", "G3", "C4"], Score.NoteLength.Half, { dotted: true });
|
|
196
|
+
// Examples
|
|
197
|
+
m.addNote(0, "C4", Theory.NoteLength.Half, { dotted: true });
|
|
198
|
+
m.addChord(1, ["C3", "E3", "G3"], Theory.NoteLength.Whole, { arpeggio: Score.Arpeggio.Down });
|
|
142
199
|
```
|
|
143
200
|
|
|
144
|
-
|
|
201
|
+
`voiceId` can be `0`, `1`, `2` or `3`.
|
|
145
202
|
|
|
146
|
-
|
|
147
|
-
* `NoteLength.Half`
|
|
148
|
-
* `NoteLength.Quarter`
|
|
149
|
-
* `NoteLength.Eighth`
|
|
150
|
-
* `NoteLength.Sixteenth`
|
|
151
|
-
* `NoteLength.ThirtySecond`
|
|
152
|
-
* `NoteLength.SixtyFourth`
|
|
203
|
+
`note` is note name, e.g. `"G#3"`, `"Db3"`.
|
|
153
204
|
|
|
154
|
-
|
|
205
|
+
`notes`: array of notes `string[]` (e.g. `["C3", "E3"]`)
|
|
155
206
|
|
|
156
|
-
|
|
207
|
+
`noteLength` can be:
|
|
208
|
+
* `Theory.NoteLength.Whole`
|
|
209
|
+
* `Theory.NoteLength.Half`
|
|
210
|
+
* `Theory.NoteLength.Quarter`
|
|
211
|
+
* `Theory.NoteLength.Eighth`
|
|
212
|
+
* `Theory.NoteLength.Sixteenth`
|
|
213
|
+
* `Theory.NoteLength.ThirtySecond`
|
|
214
|
+
* `Theory.NoteLength.SixtyFourth`
|
|
157
215
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
|
161
|
-
|
|
162
|
-
|
|
|
216
|
+
`noteOptions` is optional object of note options (e.g. `{ dotted: true }`):
|
|
217
|
+
|
|
218
|
+
| Note option | Type | |
|
|
219
|
+
|-------------|---------------------------|---------------------|
|
|
220
|
+
| dotted | `boolean` | Create dotted note. |
|
|
221
|
+
| stem | `Score.Stem.Auto/Up/Down` | Set stem direction. |
|
|
222
|
+
| arpeggio | `Score.Arpeggio.Up/Down` \| `boolean` | Play column in arpeggio. |
|
|
163
223
|
| staccato | `boolean` | Play column in staccato. |
|
|
164
224
|
| diamond | `boolean` | Diamond shaped note head. |
|
|
165
|
-
| tieSpan | `number` \| `
|
|
166
|
-
|
|
|
167
|
-
| slurSpan | `number` | How many notes
|
|
168
|
-
|
|
|
169
|
-
| triplet | `boolean` |
|
|
170
|
-
| string | `number` \| `number[]` |
|
|
225
|
+
| tieSpan | `number` \| `TieType.Stub/ToMeasureEnd` | How many notes this tie spans. |
|
|
226
|
+
| tieAnchor | `Score.NoteAnchor.Auto/Above/Center/Below/StemTip` | Tie attach point. |
|
|
227
|
+
| slurSpan | `number` | How many notes this slur spans. |
|
|
228
|
+
| slurAnchor | `Score.NoteAnchor.Auto/Above/Center/Below/StemTip` | Slur attach point. |
|
|
229
|
+
| triplet | `boolean` | Set this note part of triplet. |
|
|
230
|
+
| string | `number` \| `number[]` | String number for guitar tab. Array of string numbers for chord. |
|
|
171
231
|
|
|
172
232
|
### Add Rest
|
|
173
233
|
|
|
174
234
|
```js
|
|
175
|
-
m.addRest(voideId, restLength, restOptions
|
|
235
|
+
m.addRest(voideId: number, restLength: Theory.NoteLength, restOptions?: Score.RestOptions);
|
|
236
|
+
|
|
237
|
+
// Example
|
|
238
|
+
m.addRest(0, Theory.NoteLength.Sixteenth);
|
|
176
239
|
```
|
|
177
240
|
|
|
178
|
-
|
|
179
|
-
* `restLength`: Rest length using `NoteLength` (e.g. `NoteLength.Half`), see above.
|
|
180
|
-
* `restOptions`: Optional rest otions, see below.
|
|
241
|
+
`voiceId` can be `0`, `1`, `2` or `3`.
|
|
181
242
|
|
|
182
|
-
|
|
183
|
-
```js
|
|
184
|
-
m.addRest(0, Score.NoteLength.Quarter);
|
|
185
|
-
```
|
|
243
|
+
`restLength` is length of rest, similar as noteLength above.
|
|
186
244
|
|
|
187
|
-
|
|
245
|
+
`restOptions` is optional object of rest options (e.g. `{ hide: true }`):
|
|
188
246
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
| triplet | `boolean` | Make this rest part of triplet |
|
|
247
|
+
| Rest option | Type | |
|
|
248
|
+
|-------------|--------------|---------------------|
|
|
249
|
+
| dotted | `boolean` | Create dotted rest. |
|
|
250
|
+
| staffPos | `string` | Staff positions (e.g. `"C3"`). |
|
|
251
|
+
| hide | `boolean` | Add invisible rest. |
|
|
252
|
+
| triplet | `boolean` | Set this rest part of triplet. |
|
|
196
253
|
|
|
197
254
|
### Add Fermata
|
|
198
255
|
|
|
199
256
|
```js
|
|
200
|
-
m.
|
|
201
|
-
m.addRest(0, Score.NoteLength.Quarter).addFermata();
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
Adds fermata anchored to previously added note or rest.
|
|
257
|
+
m.addFermata(fermata?: Score.Fermata);
|
|
205
258
|
|
|
206
|
-
|
|
259
|
+
// Example
|
|
207
260
|
m.addFermata(Score.Fermata.AtMeasureEnd);
|
|
208
261
|
```
|
|
209
262
|
|
|
210
|
-
|
|
263
|
+
`fermata` is typeof `Score.Fermata` and can be:
|
|
264
|
+
- `Score.Fermata.AtNote`: Adds fermata anchored to previously added note, chord or rest.
|
|
265
|
+
- `Score.Fermata.AtMeasureEnd`: Adds fermata at the end of measure.
|
|
211
266
|
|
|
212
267
|
### Add Navigation
|
|
213
268
|
|
|
269
|
+
Add navigational element to measure.
|
|
270
|
+
|
|
214
271
|
```js
|
|
215
|
-
m.addNavigation(Score.Navigation
|
|
216
|
-
```
|
|
272
|
+
m.addNavigation(navigation: Score.Navigation, ...args?);
|
|
217
273
|
|
|
218
|
-
|
|
274
|
+
// Examples
|
|
275
|
+
m.addNavigation(Score.Navigation.StartRepeat);
|
|
276
|
+
m.addNavigation(Score.Navigation.EndRepeat, 3);
|
|
277
|
+
m.addNavigation(Score.Navigation.Ending, 1, 2);
|
|
278
|
+
```
|
|
219
279
|
|
|
220
|
-
|
|
280
|
+
`navigation` can be:
|
|
281
|
+
* `Score.Navigation.DC_al_Fine`
|
|
282
|
+
* `Score.Navigation.DC_al_Coda`
|
|
283
|
+
* `Score.Navigation.DS_al_Fine`
|
|
284
|
+
* `Score.Navigation.DS_al_Coda`
|
|
285
|
+
* `Score.Navigation.Coda`
|
|
286
|
+
* `Score.Navigation.toCoda`
|
|
287
|
+
* `Score.Navigation.Segno`
|
|
288
|
+
* `Score.Navigation.Fine`
|
|
289
|
+
* `Score.Navigation.StartRepeat`
|
|
290
|
+
* `Score.Navigation.EndRepeat`
|
|
291
|
+
* `Score.Navigation.Ending`
|
|
221
292
|
|
|
222
|
-
|
|
223
|
-
* `Navigation.DC_al_Coda`
|
|
224
|
-
* `Navigation.DS_al_Fine`
|
|
225
|
-
* `Navigation.DS_al_Coda`
|
|
226
|
-
* `Navigation.Coda`
|
|
227
|
-
* `Navigation.toCoda`
|
|
228
|
-
* `Navigation.Segno`
|
|
229
|
-
* `Navigation.Fine`
|
|
230
|
-
* `Navigation.StartRepeat`
|
|
231
|
-
* `Navigation.EndRepeat`
|
|
232
|
-
* `Navigation.Ending`
|
|
293
|
+
`Score.Navigation.EndRepeat` takes optional second arg which is number of times to repeat (once if omitted).
|
|
233
294
|
|
|
234
|
-
`Navigation.
|
|
295
|
+
`Score.Navigation.Ending` takes variable number of number args, each is a passage number.
|
|
235
296
|
|
|
236
|
-
|
|
237
|
-
m.addNavigation(Score.Navigation.EndRepeat, 2);
|
|
238
|
-
```
|
|
297
|
+
### Add Label
|
|
239
298
|
|
|
240
|
-
|
|
299
|
+
Add text label anchored to previously added note, chord or rest.
|
|
241
300
|
|
|
242
301
|
```js
|
|
243
|
-
m.
|
|
244
|
-
m.addNavigation(Score.Navigation.Ending, 3);
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
### Add Label
|
|
302
|
+
m.addLabel(label: Score.Label, text: string);
|
|
248
303
|
|
|
249
|
-
|
|
250
|
-
m.
|
|
304
|
+
// Example
|
|
305
|
+
m.addLabel(Score.Label.Chord, "Am);
|
|
251
306
|
```
|
|
252
307
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
* `Label.
|
|
256
|
-
* `Label.Chord` is used to label chords and is positioned on top.
|
|
308
|
+
`label` can be:
|
|
309
|
+
* `Score.Label.Note`: Used to label notes and is positioned below note.
|
|
310
|
+
* `Score.Label.Chord`: Used to label chords and is positioned on top.
|
|
257
311
|
|
|
258
312
|
### Add Annotation
|
|
259
313
|
|
|
260
|
-
|
|
261
|
-
m.addNote(0, "C3", Score.NoteLength.Quarter).addAnnotation(Score.Annotation.Dynamics, "fff");
|
|
262
|
-
```
|
|
314
|
+
Add annotation text anchored to previously added note, chord or rest.
|
|
263
315
|
|
|
264
|
-
|
|
316
|
+
```js
|
|
317
|
+
m.addAnnotation(annotation: Score.Annotation, text: string);
|
|
265
318
|
|
|
266
|
-
|
|
319
|
+
// Example
|
|
320
|
+
m.addAnnotation(Score.Annotation.Tempo, "accel.");
|
|
321
|
+
```
|
|
267
322
|
|
|
268
|
-
|
|
269
|
-
* `Annotation.
|
|
323
|
+
`annotation` can be:
|
|
324
|
+
* `Score.Annotation.Dynamics`: `text` could be for example `"fff"`, `"cresc."`, `"dim."`, etc.
|
|
325
|
+
* `Score.Annotation.Tempo`: `text` could be for example `"accel."`, `"rit."`, `"a tempo"`, etc.
|
|
270
326
|
|
|
271
327
|
### Add Extension
|
|
272
328
|
|
|
329
|
+
Adds extension line to element, for example to previously added annotation.
|
|
330
|
+
|
|
273
331
|
```js
|
|
274
|
-
m.
|
|
275
|
-
addAnnotation(Score.Annotation.Tempo, "accel.").
|
|
276
|
-
addExtension(Score.NoteLength.Whole * 2, true);
|
|
277
|
-
```
|
|
332
|
+
m.addExtension(extensionLength: number, visible?: boolean);
|
|
278
333
|
|
|
279
|
-
|
|
334
|
+
// Example
|
|
335
|
+
m.addAnnotation(Score.Annotation.Tempo, "accel.").addExtension(Theory.NoteLength.Whole * 2, true);
|
|
336
|
+
```
|
|
280
337
|
|
|
281
|
-
|
|
338
|
+
`extensionLength` is `number` but `Theory.NoteLength` values can be used as number and multiplied to set desired extension length.
|
|
282
339
|
|
|
283
|
-
|
|
340
|
+
`visible` sets visibility of extension line, visible by default (if omitted).
|
|
284
341
|
|
|
285
342
|
### Guitar Tab
|
|
286
343
|
|
|
287
|
-
|
|
288
|
-
Create document with `
|
|
344
|
+
This library has preliminary guitar tabs rendering.
|
|
345
|
+
Create document with `Score.StaffPreset.GuitarTab` or `Score.StaffPreset.GuitarCombined`, and specify tuning (defaults to `"Standard"` if omitted).
|
|
289
346
|
|
|
290
347
|
```js
|
|
291
|
-
let doc = new Score.MDocument(Score.
|
|
348
|
+
let doc = new Score.MDocument(Score.StaffPreset.GuitarCombined, { tuning: "Standard" });
|
|
292
349
|
```
|
|
293
350
|
|
|
294
|
-
Add notes with `string`
|
|
351
|
+
Add notes with `{ string: number | number[] }` to specify which string the fret number is rendered in guitar tab.
|
|
295
352
|
|
|
296
353
|
```js
|
|
297
354
|
// Single note
|
|
298
|
-
m.addNote(0, "G3",
|
|
355
|
+
m.addNote(0, "G3", Theory.NoteLength.Eighth, { string: 3 });
|
|
299
356
|
|
|
300
357
|
// Multi note
|
|
301
|
-
m.addChord(0, ["E4", "C3"],
|
|
358
|
+
m.addChord(0, ["E4", "C3"], Theory.NoteLength.Eighth, { string: [1, 5] });
|
|
302
359
|
```
|
|
303
360
|
|
|
304
|
-
|
|
305
361
|
### Queueing
|
|
306
362
|
|
|
307
363
|
Adding stuff to measures can be queued like this:
|
|
308
364
|
|
|
309
365
|
```js
|
|
310
366
|
doc.addMeasure()
|
|
311
|
-
.addNote(1, "C3",
|
|
312
|
-
.addChord(1, ["C3", "E3", "G3"],
|
|
313
|
-
.addRest(1,
|
|
367
|
+
.addNote(1, "C3", Theory.NoteLength.Quarter)
|
|
368
|
+
.addChord(1, ["C3", "E3", "G3"], Theory.NoteLength.Quarter).addLabel(Score.Label.Chord, "C")
|
|
369
|
+
.addRest(1, Theory.NoteLength.Quarter);
|
|
314
370
|
```
|
|
315
371
|
|
|
316
372
|
### Beams
|
|
317
373
|
|
|
318
374
|
Beams are detected and added automatically.
|
|
319
375
|
|
|
320
|
-
###
|
|
376
|
+
### Classical Guitar Audio Module
|
|
321
377
|
|
|
322
|
-
|
|
323
|
-
Score.Audio.setInstrument(Score.Audio.Instrument.ClassicalGuitar);
|
|
324
|
-
```
|
|
378
|
+
Default instrument is `Synthesizer`.
|
|
325
379
|
|
|
326
|
-
|
|
380
|
+
`Classical Guitar` is available via `audio-cg` module.
|
|
381
|
+
It was included as separate module because it contains over 1MB of audio samples bundled in it.
|
|
327
382
|
|
|
328
383
|
```js
|
|
329
|
-
|
|
384
|
+
import { registerClassicalGuitar } from "@tspro/web-music-score/audio-cg";
|
|
385
|
+
|
|
386
|
+
registerClassicalGuitar();
|
|
330
387
|
```
|
|
331
388
|
|
|
332
|
-
|
|
389
|
+
### Play Document
|
|
333
390
|
|
|
334
391
|
```js
|
|
392
|
+
// Simple play
|
|
393
|
+
doc.play();
|
|
394
|
+
|
|
395
|
+
// More playback options:
|
|
335
396
|
let player = new MPlayer(doc);
|
|
336
397
|
|
|
337
398
|
player.play();
|
|
@@ -341,21 +402,19 @@ player.stop();
|
|
|
341
402
|
MPlayer.stopAll();
|
|
342
403
|
```
|
|
343
404
|
|
|
344
|
-
More playback methods.
|
|
345
|
-
|
|
346
405
|
### Viewing Using React JSX/TSX
|
|
347
406
|
|
|
348
407
|
```js
|
|
349
408
|
// Draw document
|
|
350
|
-
<
|
|
409
|
+
<ScoreUI.MusicScoreView doc={doc} />
|
|
351
410
|
|
|
352
411
|
// Add playback buttons
|
|
353
|
-
<
|
|
354
|
-
<
|
|
355
|
-
<
|
|
412
|
+
<ScoreUI.PlaybackButtons doc={doc} buttonLayout={ScoreUI.PlaybackButtonsLayout.PlayStopSingle}/> // Single Play/Stopo button
|
|
413
|
+
<ScoreUI.PlaybackButtons doc={doc} buttonLayout={ScoreUI.PlaybackButtonsLayout.PlayStop}/> // Play and Stop buttons
|
|
414
|
+
<ScoreUI.PlaybackButtons doc={doc} buttonLayout={ScoreUI.PlaybackButtonsLayout.PlayPauseStop}/> // Play, Pause and Stop buttons
|
|
356
415
|
```
|
|
357
416
|
|
|
358
|
-
Bootstrap is used for better visual appearance but
|
|
417
|
+
Bootstrap is used for better visual appearance, but it needs to be installed and loaded.
|
|
359
418
|
|
|
360
419
|
### Viewing Using Plain JS/TS
|
|
361
420
|
|
|
@@ -394,29 +453,22 @@ p.setPlayStopButton("playStopButtonId")
|
|
|
394
453
|
p.setPlayButton(playButtonElement)
|
|
395
454
|
```
|
|
396
455
|
|
|
397
|
-
###
|
|
398
|
-
|
|
456
|
+
### MusicError
|
|
399
457
|
```js
|
|
400
458
|
try {
|
|
401
|
-
//
|
|
402
|
-
m.addNote(0, "C", Score.NoteLength.Quarter);
|
|
459
|
+
// Do your music stuff
|
|
403
460
|
}
|
|
404
|
-
catch(e) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
console.log(e);
|
|
461
|
+
catch (e) {
|
|
462
|
+
if(e instanceof Core.MusicError) {
|
|
463
|
+
// There was music error.
|
|
408
464
|
}
|
|
409
465
|
}
|
|
410
466
|
```
|
|
411
467
|
|
|
412
468
|
## Compatibility
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
* CJS and UMD bundles are transpiled with Babel for ES5/IE11 compatibility.
|
|
417
|
-
* ESM bundle targets modern environments (ES6+).
|
|
418
|
-
* Uses ES6 features like Map, etc.
|
|
419
|
-
* No polyfills are included.
|
|
469
|
+
- This library is bundled to ESM, CJS and IIFE formats.
|
|
470
|
+
- Target is to support ES6/ES2015.
|
|
471
|
+
- No polyfills are included.
|
|
420
472
|
|
|
421
473
|
While designed for compatibility in mind, the library has not been explicitly tested against specific Node.js or browser versions.
|
|
422
474
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { N as Note } from '../note-CraqEy8x.mjs';
|
|
2
|
+
|
|
3
|
+
/** @public */
|
|
4
|
+
interface Instrument {
|
|
5
|
+
getName(): string;
|
|
6
|
+
playNote(note: string, duration?: number, volume?: number): void;
|
|
7
|
+
stop(): void;
|
|
8
|
+
}
|
|
9
|
+
/** @public */
|
|
10
|
+
declare function getInstrumentList(): ReadonlyArray<string>;
|
|
11
|
+
/** @public */
|
|
12
|
+
declare function getCurrentInstrument(): string;
|
|
13
|
+
/** @public */
|
|
14
|
+
declare function registerInstrument(instr: Instrument): void;
|
|
15
|
+
/** @public */
|
|
16
|
+
declare function setInstrument(instrName: string): void;
|
|
17
|
+
/** @public */
|
|
18
|
+
declare function playNote(note: Note | string | number, duration?: number, linearVolume?: number): void;
|
|
19
|
+
/** @public */
|
|
20
|
+
declare function stop(): void;
|
|
21
|
+
|
|
22
|
+
export { type Instrument, getCurrentInstrument, getInstrumentList, playNote, registerInstrument, setInstrument, stop };
|