@tspro/web-music-score 1.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +271 -224
  3. package/dist/audio/index.d.mts +22 -0
  4. package/dist/audio/index.d.ts +22 -0
  5. package/dist/audio/index.js +147 -0
  6. package/dist/audio/index.mjs +109 -0
  7. package/dist/audio-cg/index.d.mts +4 -0
  8. package/dist/audio-cg/index.d.ts +4 -0
  9. package/dist/audio-cg/index.js +124 -0
  10. package/dist/audio-cg/index.mjs +91 -0
  11. package/dist/chunk-2EPWQZKJ.mjs +9 -0
  12. package/dist/core/index.d.mts +21 -0
  13. package/dist/core/index.d.ts +21 -0
  14. package/dist/core/index.js +72 -0
  15. package/dist/core/index.mjs +45 -0
  16. package/dist/guitar-BIFwFT31.d.ts +24 -0
  17. package/dist/guitar-kbJYu3Am.d.mts +24 -0
  18. package/dist/iife/index.global.js +222 -0
  19. package/dist/note-B5ZtlHc8.d.ts +99 -0
  20. package/dist/note-CraqEy8x.d.mts +99 -0
  21. package/dist/pieces/index.d.mts +15 -0
  22. package/dist/pieces/index.d.ts +15 -0
  23. package/dist/pieces/index.js +104 -0
  24. package/dist/pieces/index.mjs +77 -0
  25. package/dist/react-ui/index.d.mts +169 -0
  26. package/dist/react-ui/index.d.ts +169 -0
  27. package/dist/react-ui/index.js +624 -0
  28. package/dist/react-ui/index.mjs +582 -0
  29. package/dist/score/index.d.mts +1558 -0
  30. package/dist/score/index.d.ts +1558 -0
  31. package/dist/score/index.js +6937 -0
  32. package/dist/score/index.mjs +6863 -0
  33. package/dist/tempo--588tdcv.d.ts +203 -0
  34. package/dist/tempo-BEJBHZ5I.d.mts +203 -0
  35. package/dist/theory/index.d.mts +47 -0
  36. package/dist/theory/index.d.ts +47 -0
  37. package/dist/theory/index.js +1783 -0
  38. package/dist/theory/index.mjs +1716 -0
  39. package/package.json +99 -56
  40. package/dist/index.cjs.js +0 -40708
  41. package/dist/index.d.ts +0 -1258
  42. package/dist/index.esm.mjs +0 -40699
  43. package/dist/index.umd.min.js +0 -9
package/README.md CHANGED
@@ -2,338 +2,361 @@
2
2
 
3
3
  This library allows you to view and play music scores (notation) in the browser.
4
4
 
5
- Note: I'm not a professional musician. I began learning classical guitar on my own,
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 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.
8
+ This is a work in progress project. Expect changes, bugs, or unexpected behavior.
10
9
 
11
- ## Install
10
+ ## Version 2 Update
12
11
 
13
- ```sh
14
- npm i @tspro/web-music-score
12
+ **Breaking:** Version 2 is major update and brought many changes.
15
13
 
16
- # React is required, it is peer dependency
17
- npm i react
18
- ```
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.
19
21
 
20
- ## Library Bundle
22
+ Enough changes until next major update!
21
23
 
22
- This library is bundled to ESM, CJS and UMD formats.
24
+ ## Installation
23
25
 
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.
26
+ ```sh
27
+ npm i @tspro/web-music-score
28
+ ```
28
29
 
29
- While designed for compatibility in mind, the library has not been explicitly tested against specific Node.js or browser versions.
30
+ ## Import
30
31
 
31
- ## Report a Bug
32
+ ```js
33
+ // Import core module, it does not contain much.
34
+ import * as Core from "@tspro/web-music-score/core";
32
35
 
33
- Found a bug or unexpected behavior?
36
+ // Import audio module, it can play notes.
37
+ import * as Audio from "@tspro/web-music-score/audio";
34
38
 
35
- [Please open a new issue.](https://github.com/pahkasoft/issues/issues/new)
39
+ // Import theory module, it contains all music theory stuff.
40
+ import * as Theory from "@tspro/web-music-score/theory";
36
41
 
37
- You can also suggest a feature or impovement.
42
+ // Import score module, it contains music score stuff.
43
+ import * as Score from "@tspro/web-music-score/score";
38
44
 
39
- Thanks for helping improve the project!
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";
40
48
 
41
- ## License
49
+ // Import pieces module, it contains demo songs.
50
+ import * as Pieces from "@tspro/web-music-score/pieces";
42
51
 
43
- This project is licensed under the [MIT License](https://mit-license.org/).
52
+ // You can also use require
53
+ const Core = require("@tspro/web-music-score/core");
44
54
 
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";
55
+ // etc.
56
+ ```
54
57
 
55
- // Or import default export
56
- import Score from "@tspro/web-music-score";
58
+ ## Browser Script
57
59
 
58
- // Or use require
59
- const Score = require("@tspro/web-music-score");
60
- ```
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`).
61
63
 
62
64
  ```html
65
+ <script src="https://unpkg.com/@tspro/web-music-score@2.0.0"></script>
66
+
63
67
  <!--
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
+ 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.
68
70
 
69
- <canvas id="scoreCanvas"></canvas><br />
70
- <button id="playButton"></button>
71
+ TODO: Add direct link to bundle.
72
+ -->
71
73
 
72
74
  <script>
73
- const Score = window.WebMusicScore;
75
+ const { Core, Audio, Theory, Score, Pieces } = window.WebMusicScore;
74
76
  // ...
75
77
  </script>
76
78
  ```
77
79
 
78
- ### Create Document
79
-
80
- ```js
81
- let doc = new Score.MDocument(Score.StaffKind.Treble, 4);
82
- ```
80
+ ## API
83
81
 
84
- First argument can be Treble, TrebleForGuitar, Bass or Grand. TrebleForGuitar is same as Treble but one octave lower.
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.
85
84
 
86
- Second argument is number of measures per row, and can be omitted.
85
+ Following is the main interface explained.
87
86
 
88
- ## Set Header
87
+ ### Create Document
89
88
 
90
89
  ```js
91
- doc.setHeader("Title", "Composer", "Arranger");
92
- doc.setHeader("Title");
90
+ let doc = new Score.MDocument(staffPreset: Score.StaffPreset, options: Score.DocumentOptions);
93
91
  ```
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.
94
99
 
95
- Any of title, composer and arranger can be omitted/set undefined.
96
-
97
- ### Add Measure
98
-
99
- ```js
100
- let m = doc.addMeasure();
100
+ Second argument is optional `DocumentOptions`:
101
+ ```ts
102
+ DocumentOptions = { measuresPerRow?: number, tuning?: string }
101
103
  ```
102
104
 
103
- ### End Row
105
+ Default tuning is `"Standard"`. `Theory.TuningNameList` is array of available tuning names.
104
106
 
105
107
  ```js
106
- m.endRow();
108
+ // Example
109
+ let doc = new Score.MDocument(Score.StaffPreset.GuitarCombined, { tuning: "Drop D" });
107
110
  ```
108
111
 
109
- Manually induce row change. Next measure will be added to new row.
110
-
111
- ### Set Signature
112
+ ### Set Header
112
113
 
113
114
  ```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.
115
+ doc.setHeader(title?: string, composer?: string, arranger?: string);
121
116
 
122
- ```js
123
- m.setTimeSignature("4/4");
117
+ // Example
118
+ doc.setHeader("Demo Song");
124
119
  ```
125
120
 
126
- Time signature can be "2/4", "3/4", "4/4", "6/8" or "9/8".
121
+ ### Add Measure
127
122
 
128
123
  ```js
129
- m.setTempo(80, Score.NoteLength.Quarter, false);
130
- m.setTempo(80);
124
+ let m = doc.addMeasure();
131
125
  ```
132
126
 
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
127
+ ### End Row
138
128
 
139
129
  ```js
140
- m.addNote(0, "C3", Score.NoteLength.Quarter);
141
- m.addChord(1, ["C3", "E3", "G3", "C4"], Score.NoteLength.Whole);
130
+ m.endRow();
142
131
  ```
143
132
 
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.
133
+ Manually induce row change. Next measure that is added will start new row.
147
134
 
148
- Third argument is note length. Note length can be Whole, Half, Quarter, Eighth, Sixteenth, ThirdySecond or SixtyFourth.
135
+ ### Set Signature
149
136
 
150
- ### Add Rest
137
+ ```js
138
+ m.setKeySignature(tonic: string, scaleType: Theory.ScaleType);
151
139
 
152
- ```js
153
- m.addRest(0, Score.NoteLength.Quarter);
140
+ // Example: Am
141
+ m.setKeySignature("A", Theory.ScaleType.Aeolian);
154
142
  ```
155
143
 
156
- First argument is voice track id and can be 0, 1, 2 or 3.
144
+ `tonic` is scale tonic/root note, e.g. "C" (in "C Major").
157
145
 
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
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`
163
162
 
164
163
  ```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
164
+ m.setTimeSignature(timeSignature: string);
170
165
 
171
- ```js
172
- m.addNote(0, "C3", Score.NoteLength.Quarter, { stem: Stem.Up });
166
+ // Example
167
+ m.setTimeSignature("3/4");
173
168
  ```
174
169
 
175
- Stem direction can be Auto, Up or Down
176
-
177
- #### Arpeggio
170
+ timeSignature can be:
171
+ - `"2/4"`
172
+ - `"3/4"`
173
+ - `"4/4"`
174
+ - `"6/8"`
175
+ - `"9/8"`
178
176
 
179
177
  ```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.
178
+ m.setTempo(beatsPerMinute: number, beatLength?: Theory.NoteLength, dotted?: boolean);
184
179
 
185
- #### Staccato
186
-
187
- ```js
188
- m.addNote(0, "C3", Score.NoteLength.Quarter, { staccato: true });
180
+ // Example
181
+ m.setTempo(100, Theory.NoteLength.Quarter);
189
182
  ```
190
183
 
191
- #### Diamond Note Head
184
+ `beatsPerMinute` is self explanatory.
192
185
 
193
- ```js
194
- m.addNote(0, "C3", Score.NoteLength.Quarter, { diamond: true });
195
- ```
186
+ `beatLength` tells the length of each beat, e.g. Theory.NoteLength.Quarter.
196
187
 
197
- #### Add Ties And Slurs
188
+ `dotted` tells if `beatLength` is dotted.
198
189
 
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.
190
+ ### Add Note Or Chord
205
191
 
206
192
  ```js
207
- m.addNote(0, "C3", Score.NoteLength.Eight, { slurSpan: 2, slurPos: Score.ArcPos.Below })
208
- m.addNote(0, "D3", Score.NoteLength.Eight);
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);
195
+
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 });
209
199
  ```
210
200
 
211
- Adds a slur.
201
+ `voiceId` can be `0`, `1`, `2` or `3`.
212
202
 
213
- ArcPos can be Auto, Above (above note head), Middle (next to note head), Below (below note head), StemTip.
203
+ `note` is note name, e.g. `"G#3"`, `"Db3"`.
214
204
 
215
- #### Add Triplet
205
+ `notes`: array of notes `string[]` (e.g. `["C3", "E3"]`)
216
206
 
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
- ```
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`
223
215
 
224
- Adds triplet between three notes or rest of equal length.
216
+ `noteOptions` is optional object of note options (e.g. `{ dotted: true }`):
225
217
 
226
- ```js
227
- doc.addMeasure()
228
- .addNote(0, "C3", Score.NoteLength.Eight, { triplet: true })
229
- .addRest(0, Score.NoteLength.Quarter, { triplet: true });
230
- ```
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. |
223
+ | staccato | `boolean` | Play column in staccato. |
224
+ | diamond | `boolean` | Diamond shaped note head. |
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. |
231
231
 
232
- Triplet can also be added between two notes or rest. Other note or rest is double length of the other.
232
+ ### Add Rest
233
233
 
234
- #### Rest Pitch
234
+ ```js
235
+ m.addRest(voideId: number, restLength: Theory.NoteLength, restOptions?: Score.RestOptions);
235
236
 
236
- ```js
237
- m.addRest(0, Score.NoteLength.Quarter, { pitch: "C3" });
237
+ // Example
238
+ m.addRest(0, Theory.NoteLength.Sixteenth);
238
239
  ```
239
240
 
240
- Positions rest at the pitch level of note "C3".
241
+ `voiceId` can be `0`, `1`, `2` or `3`.
241
242
 
242
- #### Hide Rest
243
+ `restLength` is length of rest, similar as noteLength above.
243
244
 
244
- ```js
245
- m.addRest(0, Score.NoteLength.Quarter, { hide: true });
246
- ```
245
+ `restOptions` is optional object of rest options (e.g. `{ hide: true }`):
247
246
 
248
- Creates invisible rest.
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. |
249
253
 
250
254
  ### Add Fermata
251
255
 
252
256
  ```js
253
- m.addNote(0, "C3", Score.NoteLength.Quarter).addFermata(Score.Fermata.AtNote);
254
- m.addRest(0, Score.NoteLength.Quarter).addFermata();
255
- ```
257
+ m.addFermata(fermata?: Score.Fermata);
256
258
 
257
- Adds fermata anchored to previously added note or rest.
258
-
259
- ```js
259
+ // Example
260
260
  m.addFermata(Score.Fermata.AtMeasureEnd);
261
261
  ```
262
262
 
263
- Adds fermata at measure end.
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.
264
266
 
265
267
  ### Add Navigation
266
268
 
269
+ Add navigational element to measure.
270
+
267
271
  ```js
268
- m.addNavigation(Score.Navigation.DC_al_Fine);
272
+ m.addNavigation(navigation: Score.Navigation, ...args?);
273
+
274
+ // Examples
275
+ m.addNavigation(Score.Navigation.StartRepeat);
276
+ m.addNavigation(Score.Navigation.EndRepeat, 3);
277
+ m.addNavigation(Score.Navigation.Ending, 1, 2);
269
278
  ```
270
279
 
271
- Adds navigational element to measure.
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`
292
+
293
+ `Score.Navigation.EndRepeat` takes optional second arg which is number of times to repeat (once if omitted).
272
294
 
273
- Available navigations are:
295
+ `Score.Navigation.Ending` takes variable number of number args, each is a passage number.
274
296
 
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
297
+ ### Add Label
286
298
 
287
- Navigation.EndRepeat takes optional second argument which is number of repeats. Defaults to 1 if omitted.
299
+ Add text label anchored to previously added note, chord or rest.
288
300
 
289
301
  ```js
290
- m.addNavigation(Score.Navigation.EndRepeat, 2);
302
+ m.addLabel(label: Score.Label, text: string);
303
+
304
+ // Example
305
+ m.addLabel(Score.Label.Chord, "Am);
291
306
  ```
292
307
 
293
- Navigation.Ending takes variable number of arguments, each is a passage number.
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.
294
311
 
295
- ```js
296
- m.addNavigation(Score.Navigation.Ending, 1, 2);
297
- m.addNavigation(Score.Navigation.Ending, 3);
298
- ```
312
+ ### Add Annotation
299
313
 
300
- ### Add Label
314
+ Add annotation text anchored to previously added note, chord or rest.
301
315
 
302
316
  ```js
303
- m.addChord(0, ["D3", "F3", "A3"], Score.NoteLength.Quarter).addLabel(Score.Label.Chord, "Dm");
317
+ m.addAnnotation(annotation: Score.Annotation, text: string);
318
+
319
+ // Example
320
+ m.addAnnotation(Score.Annotation.Tempo, "accel.");
304
321
  ```
305
322
 
306
- Available Label types are:
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.
307
326
 
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.
327
+ ### Add Extension
310
328
 
311
- ### Add Annotation
329
+ Adds extension line to element, for example to previously added annotation.
312
330
 
313
331
  ```js
314
- m.addNote(0, "C3", Score.NoteLength.Quarter).addAnnotation(Score.Annotation.Dynamics, "fff");
332
+ m.addExtension(extensionLength: number, visible?: boolean);
333
+
334
+ // Example
335
+ m.addAnnotation(Score.Annotation.Tempo, "accel.").addExtension(Theory.NoteLength.Whole * 2, true);
315
336
  ```
316
337
 
317
- First argument is Annotation, second argument is the annotation text.
338
+ `extensionLength` is `number` but `Theory.NoteLength` values can be used as number and multiplied to set desired extension length.
318
339
 
319
- Available annotations are:
340
+ `visible` sets visibility of extension line, visible by default (if omitted).
320
341
 
321
- * Annotation.Dynamics could be for example "fff", "cresc.", "dim.", etc.
322
- * Annotation.Tempo could be for example "accel.", "rit.", "a tempo", etc.
342
+ ### Guitar Tab
323
343
 
324
- ### Add Extension
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).
325
346
 
326
347
  ```js
327
- m.addNote(0, "C3", Score.NoteLength.Quarter).
328
- addAnnotation(Score.Annotation.Tempo, "accel.").
329
- addExtension(Score.NoteLength.Whole * 2, true);
348
+ let doc = new Score.MDocument(Score.StaffPreset.GuitarCombined, { tuning: "Standard" });
330
349
  ```
331
350
 
332
- Adds extension line to element, annotation in this case.
351
+ Add notes with `{ string: number | number[] }` to specify which string the fret number is rendered in guitar tab.
333
352
 
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.
353
+ ```js
354
+ // Single note
355
+ m.addNote(0, "G3", Theory.NoteLength.Eighth, { string: 3 });
335
356
 
336
- Second argument is true/false whether extension line is visible. This argument cvan be omitted, extension line is visible by default.
357
+ // Multi note
358
+ m.addChord(0, ["E4", "C3"], Theory.NoteLength.Eighth, { string: [1, 5] });
359
+ ```
337
360
 
338
361
  ### Queueing
339
362
 
@@ -341,30 +364,35 @@ Adding stuff to measures can be queued like this:
341
364
 
342
365
  ```js
343
366
  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);
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);
347
370
  ```
348
371
 
349
372
  ### Beams
350
373
 
351
374
  Beams are detected and added automatically.
352
375
 
353
- ### Play Document
376
+ ### Classical Guitar Audio Module
354
377
 
355
- ```js
356
- Score.Audio.setInstrument(Score.Audio.Instrument.ClassicalGuitar);
357
- ```
378
+ Default instrument is `Synthesizer`.
358
379
 
359
- Sets instrument. Instrument can be ClassicalGuitar or Synth.
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.
360
382
 
361
383
  ```js
362
- doc.play();
384
+ import { registerClassicalGuitar } from "@tspro/web-music-score/audio-cg";
385
+
386
+ registerClassicalGuitar();
363
387
  ```
364
388
 
365
- Plays the document.
389
+ ### Play Document
366
390
 
367
391
  ```js
392
+ // Simple play
393
+ doc.play();
394
+
395
+ // More playback options:
368
396
  let player = new MPlayer(doc);
369
397
 
370
398
  player.play();
@@ -374,21 +402,19 @@ player.stop();
374
402
  MPlayer.stopAll();
375
403
  ```
376
404
 
377
- More playback methods.
378
-
379
405
  ### Viewing Using React JSX/TSX
380
406
 
381
407
  ```js
382
408
  // Draw document
383
- <Score.MusicScoreView doc={doc} />
409
+ <ScoreUI.MusicScoreView doc={doc} />
384
410
 
385
411
  // 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
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
389
415
  ```
390
416
 
391
- Bootstrap is used for better visual appearance but you must load it.
417
+ Bootstrap is used for better visual appearance, but it needs to be installed and loaded.
392
418
 
393
419
  ### Viewing Using Plain JS/TS
394
420
 
@@ -427,17 +453,38 @@ p.setPlayStopButton("playStopButtonId")
427
453
  p.setPlayButton(playButtonElement)
428
454
  ```
429
455
 
430
- ### Error Handling
431
-
456
+ ### MusicError
432
457
  ```js
433
458
  try {
434
- // Invalid note "C" without octave.
435
- m.addNote(0, "C", Score.NoteLength.Quarter);
459
+ // Do your music stuff
436
460
  }
437
- catch(e) {
438
- // MusicError is raised on errors.
439
- if(e instanceof Score.MusicError) {
440
- console.log(e);
461
+ catch (e) {
462
+ if(e instanceof Core.MusicError) {
463
+ // There was music error.
441
464
  }
442
465
  }
443
466
  ```
467
+
468
+ ## Compatibility
469
+ - This library is bundled to ESM, CJS and IIFE formats.
470
+ - Target is to support ES6/ES2015.
471
+ - No polyfills are included.
472
+
473
+ While designed for compatibility in mind, the library has not been explicitly tested against specific Node.js or browser versions.
474
+
475
+ ## Report a Bug
476
+
477
+ Found a bug or unexpected behavior?
478
+
479
+ [Please open a new issue.](https://github.com/pahkasoft/issues/issues/new)
480
+
481
+ You can also suggest a feature or impovement.
482
+
483
+ Thanks for helping improve the project!
484
+
485
+ ## License
486
+
487
+ This project is licensed under the [MIT License](https://mit-license.org/).
488
+
489
+ It also bundles the [Tone.js](https://github.com/Tonejs/Tone.js) library,
490
+ which is licensed under the [MIT License](https://opensource.org/license/mit).