@tspro/web-music-score 1.0.0 → 1.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0] - 2025-07-03
4
+ ### Added
5
+ - Preliminary support for rendering guitar tabs.
6
+
7
+ ### Fixed
8
+ - Ties/slurs were created multiple times.
9
+ - Beams in first measure (upbeat) were not created correctly.
10
+ - Quite much refactoring for better code.
11
+
3
12
  ## [1.0.0] - 2025-07-03
4
13
  ### Added
5
14
  - First release.
package/README.md CHANGED
@@ -8,7 +8,7 @@ later taking lessons in classical guitar. I've also studied music theory indepen
8
8
  This project has been a slow and steady effort over several years. It's now ready for
9
9
  public release — though please note that there may still be bugs or unexpected behavior.
10
10
 
11
- ## Install
11
+ ## Installation
12
12
 
13
13
  ```sh
14
14
  npm i @tspro/web-music-score
@@ -17,53 +17,30 @@ npm i @tspro/web-music-score
17
17
  npm i react
18
18
  ```
19
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
20
  ## Usage And API Documentation
49
21
 
50
- ### Import Methods
22
+ ### Usage
23
+
24
+ #### Import (ESM)
51
25
  ```js
52
26
  // Import named exports
53
27
  import * as Score from "@tspro/web-music-score";
54
28
 
55
- // Or import default export
29
+ // Import default export
56
30
  import Score from "@tspro/web-music-score";
31
+ ```
57
32
 
58
- // Or use require
33
+ #### Require (CommonJS)
34
+ ```js
35
+ // Use require
59
36
  const Score = require("@tspro/web-music-score");
60
37
  ```
61
38
 
39
+ #### Browser Script
40
+ Use in browser via unpkg CDN.
41
+ Browser version comes without React-components.
42
+
62
43
  ```html
63
- <!--
64
- Or use in browser via unpkg CDN.
65
- Browser version comes without React-components.
66
- -->
67
44
  <script src="https://unpkg.com/@tspro/web-music-score@1"></script>
68
45
 
69
46
  <canvas id="scoreCanvas"></canvas><br />
@@ -78,21 +55,32 @@ const Score = require("@tspro/web-music-score");
78
55
  ### Create Document
79
56
 
80
57
  ```js
81
- let doc = new Score.MDocument(Score.StaffKind.Treble, 4);
58
+ let doc = new Score.MDocument(Score.StaffKind.Treble, { measuresPerRow: 4 });
82
59
  ```
83
60
 
84
- First argument can be Treble, TrebleForGuitar, Bass or Grand. TrebleForGuitar is same as Treble but one octave lower.
61
+ First argument is `StaffKind`:
62
+ * `Treble`: Staff with treble (G-) clef.
63
+ * `Bass`: Staff with bass (F-) clef.
64
+ * `Grand`: Both treble and bas staves.
65
+ * `GuitarTreble`: `Treble` but one octave lower.
66
+ * `GuitarTab`: Guitar tab only.
67
+ * `GuitarTrebleAndTab`: Treble and tab for guitar.
85
68
 
86
- Second argument is number of measures per row, and can be omitted.
69
+ Second argument is optional `DocumentOptions`:
70
+ ```ts
71
+ DocumentOptions = { measuresPerRow?: number, tuning?: string }
72
+ ```
73
+
74
+ Default tuning is `"Standard"`. `TuningNameList` is array of available tuning names.
87
75
 
88
- ## Set Header
76
+ ### Set Header
89
77
 
90
78
  ```js
91
79
  doc.setHeader("Title", "Composer", "Arranger");
92
80
  doc.setHeader("Title");
93
81
  ```
94
82
 
95
- Any of title, composer and arranger can be omitted/set undefined.
83
+ Any of `title`, `composer` and `arranger` can be omitted/set undefined.
96
84
 
97
85
  ### Add Measure
98
86
 
@@ -116,14 +104,14 @@ m.setKeySignature("C", Score.ScaleType.Major);
116
104
 
117
105
  Firat argument is scale key note.
118
106
 
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.
107
+ Second argument is `ScaleType`, which can be `Major`, `NaturalMinor`, `HarmonicMinor`, `Ionian`, `Dorian`, `Phrygian`, `Lydian`, `Mixolydian`,
108
+ `Aeolian`, `Locrian`, `MajorPentatonic`, `MinorPentatonic`, `MajorHexatonicBlues`, `MinorHexatonicBlues` or `HeptatonicBlues`.
121
109
 
122
110
  ```js
123
111
  m.setTimeSignature("4/4");
124
112
  ```
125
113
 
126
- Time signature can be "2/4", "3/4", "4/4", "6/8" or "9/8".
114
+ Time signature can be `"2/4"`, `"3/4"`, `"4/4"`, `"6/8"` or `"9/8"`.
127
115
 
128
116
  ```js
129
117
  m.setTempo(80, Score.NoteLength.Quarter, false);
@@ -134,118 +122,77 @@ First argument is beats per minute.
134
122
 
135
123
  Second argument is beat length. Third argument tells if beat length is dotted. Second and third arguments can be omitted.
136
124
 
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
125
+ ### Add Note Or Chord
163
126
 
164
127
  ```js
165
- m.addNote(0, "C3", Score.NoteLength.Quarter, { dotted: true });
166
- m.addRest(0, Score.NoteLength.Quarter, { dotted: true });
128
+ m.addNote(voiceId, note, noteLength, noteOptions?);
129
+ m.addChord(voiceId, notes, noteLength, noteOptions);
167
130
  ```
168
131
 
169
- #### Stem Direction
132
+ * `voiceId`: Voice track id `0`, `1`, `2` or `3`
133
+ * `note`: note `string | Note` (e.g. `"C3"`)
134
+ * `notes`: array of notes `(string | Note)[]` (e.g. `["C3", "E3"]`)
135
+ * `noteLength`: Note length (e.g. `NoteLength.Half`), see below
136
+ * `noteOptions`: Optional note otions, see below
170
137
 
138
+ Examples:
171
139
  ```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
140
  m.addNote(0, "C3", Score.NoteLength.Quarter);
141
+ m.addChord(1, ["C3", "E3", "G3", "C4"], Score.NoteLength.Half, { dotted: true });
202
142
  ```
203
-
204
- Adds a tie.
205
143
 
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
- ```
144
+ #### NoteLength
210
145
 
211
- Adds a slur.
146
+ * `NoteLength.Whole`
147
+ * `NoteLength.Half`
148
+ * `NoteLength.Quarter`
149
+ * `NoteLength.Eighth`
150
+ * `NoteLength.Sixteenth`
151
+ * `NoteLength.ThirtySecond`
152
+ * `NoteLength.SixtyFourth`
212
153
 
213
- ArcPos can be Auto, Above (above note head), Middle (next to note head), Below (below note head), StemTip.
154
+ #### NoteOptions
214
155
 
215
- #### Add Triplet
156
+ Optional object of note options (e.g. `{ stem: Stem.Up }`):
216
157
 
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
- ```
158
+ | Note option | Type | |
159
+ |-------------|-------------------------|--------------------|
160
+ | dotted | `boolean` | Create dotted note. |
161
+ | stem | `Stem` | Set stem direction (`Stem.Auto`/`Up`/`Down`) |
162
+ | arpeggio | `Arpeggio` | Play column in arpeggio `Arpeggio.Up`/`Down` |
163
+ | staccato | `boolean` | Play column in staccato. |
164
+ | diamond | `boolean` | Diamond shaped note head. |
165
+ | tieSpan | `number` \| `TieLength` | How many notes tied, or `TieLength.Short`/`ToMeasureEnd` |
166
+ | tiePos | `ArcPos` | Tie attach point: `Arc.Auto`/`Above`/`Middle`/`Below`/`StemTip` |
167
+ | slurSpan | `number` | How many notes slurred. |
168
+ | slurPos | `ArcPos` | Slur attach point: `Arc.Auto`/`Above`/`Middle`/`Below`/`StemTip` |
169
+ | triplet | `boolean` | Make this note part of triplet. |
170
+ | string | `number` \| `number[]` | What string does the note fret number belong to in guitar tab. Array of strings for chord. |
223
171
 
224
- Adds triplet between three notes or rest of equal length.
172
+ ### Add Rest
225
173
 
226
- ```js
227
- doc.addMeasure()
228
- .addNote(0, "C3", Score.NoteLength.Eight, { triplet: true })
229
- .addRest(0, Score.NoteLength.Quarter, { triplet: true });
174
+ ```js
175
+ m.addRest(voideId, restLength, restOptions?);
230
176
  ```
231
177
 
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
178
+ * `voiceId`: Voice track id `0`, `1`, `2` or `3`.
179
+ * `restLength`: Rest length using `NoteLength` (e.g. `NoteLength.Half`), see above.
180
+ * `restOptions`: Optional rest otions, see below.
235
181
 
182
+ Example:
236
183
  ```js
237
- m.addRest(0, Score.NoteLength.Quarter, { pitch: "C3" });
184
+ m.addRest(0, Score.NoteLength.Quarter);
238
185
  ```
239
186
 
240
- Positions rest at the pitch level of note "C3".
241
-
242
- #### Hide Rest
187
+ #### RestOptions
243
188
 
244
- ```js
245
- m.addRest(0, Score.NoteLength.Quarter, { hide: true });
246
- ```
247
-
248
- Creates invisible rest.
189
+ Optional object of rest options (e.g. `{ hide: true }`):
190
+ | Rest option | Type | |
191
+ |-------------|------------------------|--------------------|
192
+ | dotted | `boolean` | Create dotted rest |
193
+ | pitch | `string` \| `Note` | Positions rest at level of note (e.g. `"C3"`) |
194
+ | hide | `boolean` | Add invisible rest |
195
+ | triplet | `boolean` | Make this rest part of triplet |
249
196
 
250
197
  ### Add Fermata
251
198
 
@@ -272,25 +219,25 @@ Adds navigational element to measure.
272
219
 
273
220
  Available navigations are:
274
221
 
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
222
+ * `Navigation.DC_al_Fine`
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`
286
233
 
287
- Navigation.EndRepeat takes optional second argument which is number of repeats. Defaults to 1 if omitted.
234
+ `Navigation.EndRepeat` Takes optional second argument which is number of repeats. Defaults to 1 if omitted.
288
235
 
289
236
  ```js
290
237
  m.addNavigation(Score.Navigation.EndRepeat, 2);
291
238
  ```
292
239
 
293
- Navigation.Ending takes variable number of arguments, each is a passage number.
240
+ `Navigation.Ending` takes variable number of arguments, each is a passage number.
294
241
 
295
242
  ```js
296
243
  m.addNavigation(Score.Navigation.Ending, 1, 2);
@@ -305,8 +252,8 @@ m.addChord(0, ["D3", "F3", "A3"], Score.NoteLength.Quarter).addLabel(Score.Label
305
252
 
306
253
  Available Label types are:
307
254
 
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.
255
+ * `Label.Note` is used to label notes and is positioned below note.
256
+ * `Label.Chord` is used to label chords and is positioned on top.
310
257
 
311
258
  ### Add Annotation
312
259
 
@@ -314,12 +261,12 @@ Available Label types are:
314
261
  m.addNote(0, "C3", Score.NoteLength.Quarter).addAnnotation(Score.Annotation.Dynamics, "fff");
315
262
  ```
316
263
 
317
- First argument is Annotation, second argument is the annotation text.
264
+ First argument is `Annotation`, second argument is the annotation text.
318
265
 
319
266
  Available annotations are:
320
267
 
321
- * Annotation.Dynamics could be for example "fff", "cresc.", "dim.", etc.
322
- * Annotation.Tempo could be for example "accel.", "rit.", "a tempo", etc.
268
+ * `Annotation.Dynamics` could be for example `"fff"`, `"cresc."`, `"dim."`, etc.
269
+ * `Annotation.Tempo` could be for example `"accel."`, `"rit."`, `"a tempo"`, etc.
323
270
 
324
271
  ### Add Extension
325
272
 
@@ -331,9 +278,29 @@ m.addNote(0, "C3", Score.NoteLength.Quarter).
331
278
 
332
279
  Adds extension line to element, annotation in this case.
333
280
 
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.
281
+ 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.
282
+
283
+ Second argument is `true`/`false` whether extension line is visible. This argument cvan be omitted, extension line is visible by default.
284
+
285
+ ### Guitar Tab
286
+
287
+ Has preliminary support for rendering guitar tabs.
288
+ Create document with `StaffKind.GuitarTab` or `StaffKind.GuitarTrebleAndTab`, and specify tuning (optional, defaults to Standard tuning):
289
+
290
+ ```js
291
+ let doc = new Score.MDocument(Score.StaffKind.GuitarTrebleAndTab, { tuning: "Standard" });
292
+ ```
293
+
294
+ Add notes with `string` option to specify which string the fret number is rendered in tab view.
295
+
296
+ ```js
297
+ // Single note
298
+ m.addNote(0, "G3", Score.NoteLength.Eighth, { string: 3 });
299
+
300
+ // Multi note
301
+ m.addChord(0, ["E4", "C3"], Score.NoteLength.Eighth, { string: [1, 5] });
302
+ ```
335
303
 
336
- Second argument is true/false whether extension line is visible. This argument cvan be omitted, extension line is visible by default.
337
304
 
338
305
  ### Queueing
339
306
 
@@ -441,3 +408,31 @@ catch(e) {
441
408
  }
442
409
  }
443
410
  ```
411
+
412
+ ## Compatibility
413
+
414
+ This library is bundled to ESM, CJS and UMD formats.
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.
420
+
421
+ While designed for compatibility in mind, the library has not been explicitly tested against specific Node.js or browser versions.
422
+
423
+ ## Report a Bug
424
+
425
+ Found a bug or unexpected behavior?
426
+
427
+ [Please open a new issue.](https://github.com/pahkasoft/issues/issues/new)
428
+
429
+ You can also suggest a feature or impovement.
430
+
431
+ Thanks for helping improve the project!
432
+
433
+ ## License
434
+
435
+ This project is licensed under the [MIT License](https://mit-license.org/).
436
+
437
+ It also bundles the [Tone.js](https://github.com/Tonejs/Tone.js) library,
438
+ which is licensed under the [MIT License](https://opensource.org/license/mit).