@tspro/web-music-score 1.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 +5 -0
- package/LICENSE +57 -0
- package/README.md +443 -0
- package/dist/index.cjs.js +40708 -0
- package/dist/index.d.ts +1258 -0
- package/dist/index.esm.mjs +40699 -0
- package/dist/index.umd.min.js +9 -0
- package/package.json +77 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
This project is licensed under the terms of the MIT license.
|
|
3
|
+
See below for full license text and third-party licenses.
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2023 PahkaSoft
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included
|
|
16
|
+
in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
This project includes third-party code.
|
|
29
|
+
|
|
30
|
+
The following licenses apply to the bundled libraries, not to WebMusicScore itself.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
* Tone.js (https://github.com/Tonejs/Tone.js)
|
|
35
|
+
|
|
36
|
+
MIT License
|
|
37
|
+
|
|
38
|
+
Copyright (c) 2014-2020 Yotam Mann
|
|
39
|
+
|
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
41
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
42
|
+
in the Software without restriction, including without limitation the rights
|
|
43
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
44
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
45
|
+
furnished to do so, subject to the following conditions:
|
|
46
|
+
|
|
47
|
+
The above copyright notice and this permission notice shall be included in all
|
|
48
|
+
copies or substantial portions of the Software.
|
|
49
|
+
|
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
51
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
52
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
53
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
54
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
55
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
56
|
+
SOFTWARE.
|
|
57
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
# WebMusicScore
|
|
2
|
+
|
|
3
|
+
This library allows you to view and play music scores (notation) in the browser.
|
|
4
|
+
|
|
5
|
+
Note: I'm not a professional musician. I began learning classical guitar on my own,
|
|
6
|
+
later taking lessons in classical guitar. I've also studied music theory independently.
|
|
7
|
+
|
|
8
|
+
This project has been a slow and steady effort over several years. It's now ready for
|
|
9
|
+
public release — though please note that there may still be bugs or unexpected behavior.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i @tspro/web-music-score
|
|
15
|
+
|
|
16
|
+
# React is required, it is peer dependency
|
|
17
|
+
npm i react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Library Bundle
|
|
21
|
+
|
|
22
|
+
This library is bundled to ESM, CJS and UMD formats.
|
|
23
|
+
|
|
24
|
+
* CJS and UMD bundles are transpiled with Babel for ES5/IE11 compatibility.
|
|
25
|
+
* ESM bundle targets modern environments (ES6+).
|
|
26
|
+
* Uses ES6 features like Map, etc.
|
|
27
|
+
* No polyfills are included.
|
|
28
|
+
|
|
29
|
+
While designed for compatibility in mind, the library has not been explicitly tested against specific Node.js or browser versions.
|
|
30
|
+
|
|
31
|
+
## Report a Bug
|
|
32
|
+
|
|
33
|
+
Found a bug or unexpected behavior?
|
|
34
|
+
|
|
35
|
+
[Please open a new issue.](https://github.com/pahkasoft/issues/issues/new)
|
|
36
|
+
|
|
37
|
+
You can also suggest a feature or impovement.
|
|
38
|
+
|
|
39
|
+
Thanks for helping improve the project!
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
This project is licensed under the [MIT License](https://mit-license.org/).
|
|
44
|
+
|
|
45
|
+
It also bundles the [Tone.js](https://github.com/Tonejs/Tone.js) library,
|
|
46
|
+
which is licensed under the [MIT License](https://opensource.org/license/mit).
|
|
47
|
+
|
|
48
|
+
## Usage And API Documentation
|
|
49
|
+
|
|
50
|
+
### Import Methods
|
|
51
|
+
```js
|
|
52
|
+
// Import named exports
|
|
53
|
+
import * as Score from "@tspro/web-music-score";
|
|
54
|
+
|
|
55
|
+
// Or import default export
|
|
56
|
+
import Score from "@tspro/web-music-score";
|
|
57
|
+
|
|
58
|
+
// Or use require
|
|
59
|
+
const Score = require("@tspro/web-music-score");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<!--
|
|
64
|
+
Or use in browser via unpkg CDN.
|
|
65
|
+
Browser version comes without React-components.
|
|
66
|
+
-->
|
|
67
|
+
<script src="https://unpkg.com/@tspro/web-music-score@1"></script>
|
|
68
|
+
|
|
69
|
+
<canvas id="scoreCanvas"></canvas><br />
|
|
70
|
+
<button id="playButton"></button>
|
|
71
|
+
|
|
72
|
+
<script>
|
|
73
|
+
const Score = window.WebMusicScore;
|
|
74
|
+
// ...
|
|
75
|
+
</script>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Create Document
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
let doc = new Score.MDocument(Score.StaffKind.Treble, 4);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
First argument can be Treble, TrebleForGuitar, Bass or Grand. TrebleForGuitar is same as Treble but one octave lower.
|
|
85
|
+
|
|
86
|
+
Second argument is number of measures per row, and can be omitted.
|
|
87
|
+
|
|
88
|
+
## Set Header
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
doc.setHeader("Title", "Composer", "Arranger");
|
|
92
|
+
doc.setHeader("Title");
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Any of title, composer and arranger can be omitted/set undefined.
|
|
96
|
+
|
|
97
|
+
### Add Measure
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
let m = doc.addMeasure();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### End Row
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
m.endRow();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Manually induce row change. Next measure will be added to new row.
|
|
110
|
+
|
|
111
|
+
### Set Signature
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
m.setKeySignature("C", Score.ScaleType.Major);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Firat argument is scale key note.
|
|
118
|
+
|
|
119
|
+
Second argument is scale type, which can be Major, NaturalMinor, HarmonicMinor, Ionian, Dorian, Phrygian, Lydian, Mixolydian,
|
|
120
|
+
Aeolian, Locrian, MajorPentatonic, MinorPentatonic, MajorHexatonicBlues, MinorHexatonicBlues or HeptatonicBlues.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
m.setTimeSignature("4/4");
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Time signature can be "2/4", "3/4", "4/4", "6/8" or "9/8".
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
m.setTempo(80, Score.NoteLength.Quarter, false);
|
|
130
|
+
m.setTempo(80);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
First argument is beats per minute.
|
|
134
|
+
|
|
135
|
+
Second argument is beat length. Third argument tells if beat length is dotted. Second and third arguments can be omitted.
|
|
136
|
+
|
|
137
|
+
### Adding Notes and chords
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter);
|
|
141
|
+
m.addChord(1, ["C3", "E3", "G3", "C4"], Score.NoteLength.Whole);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
First argument is voice track id and can be 0, 1, 2 or 3.
|
|
145
|
+
|
|
146
|
+
Second argument is note or list of notes for chord.
|
|
147
|
+
|
|
148
|
+
Third argument is note length. Note length can be Whole, Half, Quarter, Eighth, Sixteenth, ThirdySecond or SixtyFourth.
|
|
149
|
+
|
|
150
|
+
### Add Rest
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
m.addRest(0, Score.NoteLength.Quarter);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
First argument is voice track id and can be 0, 1, 2 or 3.
|
|
157
|
+
|
|
158
|
+
Second argument is rest length. Rest length can be Whole, Half, Quarter, Eighth, Sixteenth, ThirdySecond or SixtyFourth.
|
|
159
|
+
|
|
160
|
+
### Note And Rest Options
|
|
161
|
+
|
|
162
|
+
#### Doted Note And Rest
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter, { dotted: true });
|
|
166
|
+
m.addRest(0, Score.NoteLength.Quarter, { dotted: true });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Stem Direction
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter, { stem: Stem.Up });
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Stem direction can be Auto, Up or Down
|
|
176
|
+
|
|
177
|
+
#### Arpeggio
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter, { arpeggio: Arpeggio.Down });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Play this column of notes in arpeggio. Arpeggio can be Up or Down.
|
|
184
|
+
|
|
185
|
+
#### Staccato
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter, { staccato: true });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Diamond Note Head
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter, { diamond: true });
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Add Ties And Slurs
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
m.addNote(0, "C3", Score.NoteLength.Half, { tieSpan: 2, tiePos: Score.ArcPos.Below })
|
|
201
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Adds a tie.
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
m.addNote(0, "C3", Score.NoteLength.Eight, { slurSpan: 2, slurPos: Score.ArcPos.Below })
|
|
208
|
+
m.addNote(0, "D3", Score.NoteLength.Eight);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Adds a slur.
|
|
212
|
+
|
|
213
|
+
ArcPos can be Auto, Above (above note head), Middle (next to note head), Below (below note head), StemTip.
|
|
214
|
+
|
|
215
|
+
#### Add Triplet
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
doc.addMeasure()
|
|
219
|
+
.addNote(0, "C3", Score.NoteLength.Eight, { triplet: true })
|
|
220
|
+
.addNote(0, "D3", Score.NoteLength.Eight, { triplet: true })
|
|
221
|
+
.addNote(0, "E3", Score.NoteLength.Eight, { triplet: true });
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Adds triplet between three notes or rest of equal length.
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
doc.addMeasure()
|
|
228
|
+
.addNote(0, "C3", Score.NoteLength.Eight, { triplet: true })
|
|
229
|
+
.addRest(0, Score.NoteLength.Quarter, { triplet: true });
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Triplet can also be added between two notes or rest. Other note or rest is double length of the other.
|
|
233
|
+
|
|
234
|
+
#### Rest Pitch
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
m.addRest(0, Score.NoteLength.Quarter, { pitch: "C3" });
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Positions rest at the pitch level of note "C3".
|
|
241
|
+
|
|
242
|
+
#### Hide Rest
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
m.addRest(0, Score.NoteLength.Quarter, { hide: true });
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Creates invisible rest.
|
|
249
|
+
|
|
250
|
+
### Add Fermata
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter).addFermata(Score.Fermata.AtNote);
|
|
254
|
+
m.addRest(0, Score.NoteLength.Quarter).addFermata();
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Adds fermata anchored to previously added note or rest.
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
m.addFermata(Score.Fermata.AtMeasureEnd);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Adds fermata at measure end.
|
|
264
|
+
|
|
265
|
+
### Add Navigation
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
m.addNavigation(Score.Navigation.DC_al_Fine);
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Adds navigational element to measure.
|
|
272
|
+
|
|
273
|
+
Available navigations are:
|
|
274
|
+
|
|
275
|
+
* Navigation.DC\_al\_Fine
|
|
276
|
+
* Navigation.DC\_al\_Coda
|
|
277
|
+
* Navigation.DS\_al\_Fine
|
|
278
|
+
* Navigation.DS\_al\_Coda
|
|
279
|
+
* Navigation.Coda
|
|
280
|
+
* Navigation.toCoda
|
|
281
|
+
* Navigation.Segno
|
|
282
|
+
* Navigation.Fine
|
|
283
|
+
* Navigation.StartRepeat
|
|
284
|
+
* Navigation.EndRepeat
|
|
285
|
+
* Navigation.Ending
|
|
286
|
+
|
|
287
|
+
Navigation.EndRepeat takes optional second argument which is number of repeats. Defaults to 1 if omitted.
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
m.addNavigation(Score.Navigation.EndRepeat, 2);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Navigation.Ending takes variable number of arguments, each is a passage number.
|
|
294
|
+
|
|
295
|
+
```js
|
|
296
|
+
m.addNavigation(Score.Navigation.Ending, 1, 2);
|
|
297
|
+
m.addNavigation(Score.Navigation.Ending, 3);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Add Label
|
|
301
|
+
|
|
302
|
+
```js
|
|
303
|
+
m.addChord(0, ["D3", "F3", "A3"], Score.NoteLength.Quarter).addLabel(Score.Label.Chord, "Dm");
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Available Label types are:
|
|
307
|
+
|
|
308
|
+
* Label.Note is used to label notes and is positioned below note.
|
|
309
|
+
* Label.Chord is used to label chords and is positioned on top.
|
|
310
|
+
|
|
311
|
+
### Add Annotation
|
|
312
|
+
|
|
313
|
+
```js
|
|
314
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter).addAnnotation(Score.Annotation.Dynamics, "fff");
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
First argument is Annotation, second argument is the annotation text.
|
|
318
|
+
|
|
319
|
+
Available annotations are:
|
|
320
|
+
|
|
321
|
+
* Annotation.Dynamics could be for example "fff", "cresc.", "dim.", etc.
|
|
322
|
+
* Annotation.Tempo could be for example "accel.", "rit.", "a tempo", etc.
|
|
323
|
+
|
|
324
|
+
### Add Extension
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
m.addNote(0, "C3", Score.NoteLength.Quarter).
|
|
328
|
+
addAnnotation(Score.Annotation.Tempo, "accel.").
|
|
329
|
+
addExtension(Score.NoteLength.Whole * 2, true);
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Adds extension line to element, annotation in this case.
|
|
333
|
+
|
|
334
|
+
First argument is extension length, of type number. NoteLength values can be used as number, and NoteLength values can be multiplied to set desired extension length.
|
|
335
|
+
|
|
336
|
+
Second argument is true/false whether extension line is visible. This argument cvan be omitted, extension line is visible by default.
|
|
337
|
+
|
|
338
|
+
### Queueing
|
|
339
|
+
|
|
340
|
+
Adding stuff to measures can be queued like this:
|
|
341
|
+
|
|
342
|
+
```js
|
|
343
|
+
doc.addMeasure()
|
|
344
|
+
.addNote(1, "C3", Score.NoteLength.Quarter)
|
|
345
|
+
.addChord(1, ["C3", "E3", "G3"], Score.NoteLength.Quarter).addLabel(Score.Label.Chord, "C")
|
|
346
|
+
.addRest(1, Score.NoteLength.Quarter);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Beams
|
|
350
|
+
|
|
351
|
+
Beams are detected and added automatically.
|
|
352
|
+
|
|
353
|
+
### Play Document
|
|
354
|
+
|
|
355
|
+
```js
|
|
356
|
+
Score.Audio.setInstrument(Score.Audio.Instrument.ClassicalGuitar);
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Sets instrument. Instrument can be ClassicalGuitar or Synth.
|
|
360
|
+
|
|
361
|
+
```js
|
|
362
|
+
doc.play();
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Plays the document.
|
|
366
|
+
|
|
367
|
+
```js
|
|
368
|
+
let player = new MPlayer(doc);
|
|
369
|
+
|
|
370
|
+
player.play();
|
|
371
|
+
player.pause();
|
|
372
|
+
player.stop();
|
|
373
|
+
|
|
374
|
+
MPlayer.stopAll();
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
More playback methods.
|
|
378
|
+
|
|
379
|
+
### Viewing Using React JSX/TSX
|
|
380
|
+
|
|
381
|
+
```js
|
|
382
|
+
// Draw document
|
|
383
|
+
<Score.MusicScoreView doc={doc} />
|
|
384
|
+
|
|
385
|
+
// Add playback buttons
|
|
386
|
+
<Score.PlaybackButtons doc={doc} buttonLayout={Score.PlaybackButtonsLayout.PlayStopSingle}/> // Single Play/Stopo button
|
|
387
|
+
<Score.PlaybackButtons doc={doc} buttonLayout={Score.PlaybackButtonsLayout.PlayStop}/> // Play and Stop buttons
|
|
388
|
+
<Score.PlaybackButtons doc={doc} buttonLayout={Score.PlaybackButtonsLayout.PlayPauseStop}/> // Play, Pause and Stop buttons
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Bootstrap is used for better visual appearance but you must load it.
|
|
392
|
+
|
|
393
|
+
### Viewing Using Plain JS/TS
|
|
394
|
+
|
|
395
|
+
```html
|
|
396
|
+
<!-- Add canvas -->
|
|
397
|
+
<canvas id="canvasId"></canvas>
|
|
398
|
+
|
|
399
|
+
<!-- Add play button -->
|
|
400
|
+
<button id="playButtonId"></button>
|
|
401
|
+
<!-- Add pause button -->
|
|
402
|
+
<button id="pauseButtonId"></button>
|
|
403
|
+
<!-- Add stop button -->
|
|
404
|
+
<button id="stopButtonId"></button>
|
|
405
|
+
<!-- Or add combined play/stop button -->
|
|
406
|
+
<button id="playStopButtonId"></button>
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
```js
|
|
410
|
+
// Draw document
|
|
411
|
+
let r = new Score.MRenderer().
|
|
412
|
+
setCanvas("canvasId").
|
|
413
|
+
setDocument(doc).
|
|
414
|
+
draw();
|
|
415
|
+
|
|
416
|
+
// Add playback buttons
|
|
417
|
+
let p = new Score.MPlaybackButtons().
|
|
418
|
+
setPlayButton("playButtonId").
|
|
419
|
+
setPauseButton("pauseButtonId").
|
|
420
|
+
setStopButton("stopButtonId").
|
|
421
|
+
setDocument(doc);
|
|
422
|
+
|
|
423
|
+
// You can also set combined play/stop button.
|
|
424
|
+
p.setPlayStopButton("playStopButtonId")
|
|
425
|
+
|
|
426
|
+
// You can also pass HTMLButtonElement instead of element id.
|
|
427
|
+
p.setPlayButton(playButtonElement)
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Error Handling
|
|
431
|
+
|
|
432
|
+
```js
|
|
433
|
+
try {
|
|
434
|
+
// Invalid note "C" without octave.
|
|
435
|
+
m.addNote(0, "C", Score.NoteLength.Quarter);
|
|
436
|
+
}
|
|
437
|
+
catch(e) {
|
|
438
|
+
// MusicError is raised on errors.
|
|
439
|
+
if(e instanceof Score.MusicError) {
|
|
440
|
+
console.log(e);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
```
|