@tspro/web-music-score 3.2.0 → 4.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 +26 -10
- package/README.md +189 -331
- package/dist/audio/index.d.ts +1 -1
- package/dist/audio/index.js +1 -1
- package/dist/audio/index.mjs +2 -2
- package/dist/audio-cg/index.js +1 -1
- package/dist/audio-cg/index.mjs +2 -2
- package/dist/{chunk-LCTM7BID.mjs → chunk-D643HZHM.mjs} +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/index.mjs +3 -3
- package/dist/{guitar-C2Cp71NZ.d.ts → guitar-cNmE-EvH.d.ts} +1 -1
- package/dist/iife/index.global.js +11 -11
- package/dist/{interface-BlNl69uT.d.ts → interface-7k8qGG44.d.ts} +89 -81
- package/dist/{interface-Bn5HFt_U.d.mts → interface-XoKiryoV.d.mts} +88 -80
- package/dist/{note-BFa43I86.d.ts → note-CcVdUFqS.d.ts} +1 -1
- package/dist/pieces/index.d.mts +2 -2
- package/dist/pieces/index.d.ts +3 -3
- package/dist/pieces/index.js +4 -7
- package/dist/pieces/index.mjs +8 -11
- package/dist/react-ui/index.d.mts +3 -3
- package/dist/react-ui/index.d.ts +5 -5
- package/dist/react-ui/index.js +1 -1
- package/dist/react-ui/index.mjs +2 -2
- package/dist/{scale-DRR-t4Kr.d.mts → scale-C2pCNxdE.d.mts} +4 -3
- package/dist/{scale-ebJm37q1.d.ts → scale-CvPbJvfN.d.ts} +5 -4
- package/dist/score/index.d.mts +98 -31
- package/dist/score/index.d.ts +99 -32
- package/dist/score/index.js +748 -567
- package/dist/score/index.mjs +755 -574
- package/dist/tempo-BAYoZ_Li.d.mts +187 -0
- package/dist/tempo-r2sb6Ku2.d.ts +187 -0
- package/dist/theory/index.d.mts +3 -3
- package/dist/theory/index.d.ts +6 -6
- package/dist/theory/index.js +221 -78
- package/dist/theory/index.mjs +218 -76
- package/package.json +2 -2
- package/dist/tempo-B4h5Ktob.d.mts +0 -104
- package/dist/tempo-DgqDEsn0.d.ts +0 -104
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# WebMusicScore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The API Reference, Examples and Demos can be found [here](https://pahkasoft.github.io). The API Reference is very little commented but gives idea of the full API.
|
|
4
4
|
|
|
5
5
|
## About
|
|
6
6
|
|
|
@@ -9,30 +9,11 @@ This library allows you to view and play music scores (notation) in the browser.
|
|
|
9
9
|
I'm not a professional musician. I began learning classical guitar on my own,
|
|
10
10
|
later taking lessons in classical guitar. I've also studied music theory independently.
|
|
11
11
|
|
|
12
|
-
This is a work in progress project.
|
|
12
|
+
This is a work in progress project. Lately there has been improvements that required major
|
|
13
|
+
version update. As the project matures there might be less major updates, and more minor
|
|
14
|
+
updates and patches.
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
**Breaking:** Version 2 is major update and brought many changes.
|
|
17
|
-
|
|
18
|
-
* Introduced subpath modules instead of one big main module. There is no main export.
|
|
19
|
-
* Theory module had big refactor that affected whole library. Renamed all musical terms that
|
|
20
|
-
were wrong (e.g. pitch => diatonicId, noteId => chromaticId).
|
|
21
|
-
* Score module stayed mostly same. Some changes (e.g. enum StaffKind => StaffPreset) but nothing major.
|
|
22
|
-
* Classical guitar audio was put into separate module (audio-cg) because it bundles over 1MB of audio
|
|
23
|
-
samples. Also improved default synthesizer audio.
|
|
24
|
-
* Numerous small changes/improvements.
|
|
25
|
-
|
|
26
|
-
Enough changes until next major update!
|
|
27
|
-
|
|
28
|
-
## Version 3 Update
|
|
29
|
-
|
|
30
|
-
**Breaking:** Version 3 is another major update and brought some important changes.
|
|
31
|
-
|
|
32
|
-
* Support score configuration with multiple notation lines (combination of staves and tabs).
|
|
33
|
-
* Introduced DocumentBuilder to create scores, removed old way.
|
|
34
|
-
* DocumentOptions functionality is replaced using functions addScoreConfiguration() and setMeasuresPerRow() in DocumentBuilder.
|
|
35
|
-
* Add ties, slurs and slides using addConnective() in DocumentBuilder. Tie and span options removed from NoteOptions.
|
|
16
|
+
This version (4.0.0) added support for string arguments in addition to typescript enums (e.g. NoteLength.Quarter => "4n", just to name one).
|
|
36
17
|
|
|
37
18
|
## Installation
|
|
38
19
|
|
|
@@ -63,25 +44,24 @@ import * as ScoreUI from "@tspro/web-music-score/react-ui";
|
|
|
63
44
|
import * as Pieces from "@tspro/web-music-score/pieces";
|
|
64
45
|
|
|
65
46
|
// You can also use require
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
// etc.
|
|
47
|
+
const Score = require("@tspro/web-music-score/score");
|
|
69
48
|
```
|
|
70
49
|
|
|
71
50
|
## Browser Script
|
|
72
51
|
|
|
73
|
-
This
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
This module that can be used in html page via unpkg CDN. It declares global variable
|
|
53
|
+
`WebMusicScore` that contains `Core`, `Audio`, `Theory`, `Score`, and `Pieces` as
|
|
54
|
+
corresponding subpath modules (`react-ui` and `audio-cg` are not included in this
|
|
55
|
+
browser module).
|
|
76
56
|
|
|
77
57
|
```html
|
|
78
|
-
<script src="https://unpkg.com/@tspro/web-music-score@
|
|
79
|
-
<script src="https://unpkg.com/@tspro/web-music-score@
|
|
80
|
-
<script src="https://unpkg.com/@tspro/web-music-score@
|
|
58
|
+
<script src="https://unpkg.com/@tspro/web-music-score@4"></script>
|
|
59
|
+
<script src="https://unpkg.com/@tspro/web-music-score@4.0.0"></script>
|
|
60
|
+
<script src="https://unpkg.com/@tspro/web-music-score@4.0.0/dist/iife/index.global.js"></script>
|
|
81
61
|
|
|
82
62
|
<!--
|
|
83
|
-
Use one of above. It is recommended to use version number (e.g. @
|
|
84
|
-
This way if
|
|
63
|
+
Use one of above. It is recommended to use version number (e.g. @4.0.0 or at least @4).
|
|
64
|
+
This way if something breaks between versions then your web site does not stop working.
|
|
85
65
|
-->
|
|
86
66
|
|
|
87
67
|
<script>
|
|
@@ -92,406 +72,284 @@ and `Pieces` as corresponding subpath modules (excluding `react-ui` and `audio-c
|
|
|
92
72
|
|
|
93
73
|
## API
|
|
94
74
|
|
|
95
|
-
Following is the main interface
|
|
75
|
+
Following is introduction to the main interface with the help of simple examples.
|
|
96
76
|
|
|
97
|
-
###
|
|
77
|
+
### Using `DocumentBuilder`
|
|
98
78
|
|
|
99
|
-
|
|
79
|
+
```js
|
|
80
|
+
let doc = new Score.DocumentBuilder()
|
|
81
|
+
.addScoreConfiguration({ type: "staff", clef: "G", isOctavewDown: true })
|
|
82
|
+
.setMeasuresPerRow(4)
|
|
83
|
+
.addMeasure()
|
|
84
|
+
.addNote(1, "C3", "4n")
|
|
85
|
+
.addChord(1, ["C3", "E3", "G3"], "4n").addLabel("chord", "C")
|
|
86
|
+
.addRest(1, "4n")
|
|
87
|
+
// etc.
|
|
88
|
+
.getDEocument();
|
|
89
|
+
```
|
|
100
90
|
|
|
91
|
+
**Hint:**
|
|
101
92
|
```js
|
|
102
|
-
|
|
93
|
+
// In following examples this:
|
|
94
|
+
.addNote(...)
|
|
103
95
|
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
.addMEasure()
|
|
107
|
-
.addNote(0, "C3", Theory.NoteLength.Quarter)
|
|
108
|
-
// etc.
|
|
96
|
+
// means call to the DocumentBuilder object:
|
|
97
|
+
documentBuilder.addNote(...)
|
|
109
98
|
|
|
110
|
-
//
|
|
111
|
-
let doc = builder.getDocument();
|
|
99
|
+
// It is just shortened for simplicity.
|
|
112
100
|
```
|
|
113
101
|
|
|
114
102
|
### Set Score Configuration
|
|
115
|
-
|
|
103
|
+
New score configuration takes place in the first measure of next row.
|
|
116
104
|
|
|
117
105
|
#### Using preset values
|
|
118
|
-
```js
|
|
119
|
-
builder.setScoreConfiguration(staffPreset: Score.StaffPreset);
|
|
120
|
-
```
|
|
121
106
|
|
|
122
|
-
`
|
|
123
|
-
|
|
124
|
-
* `Score.StaffPreset.Bass`: Staff with bass (F-) clef.
|
|
125
|
-
* `Score.StaffPreset.Grand`: Both treble and bas staves.
|
|
126
|
-
* `Score.StaffPreset.GuitarTreble`: Same as `Treble` but one octave down.
|
|
127
|
-
* `Score.StaffPreset.GuitarTab`: Guitar tab only.
|
|
128
|
-
* `Score.StaffPreset.GuitarCombined`: Treble and tab for guitar.
|
|
107
|
+
For staff presets you can use `Score.StaffPreset` enum values (e.g. `Score.StaffPreset.Treble`)
|
|
108
|
+
or corresponding string values (e.g. `"treble"`).
|
|
129
109
|
|
|
130
110
|
```js
|
|
131
|
-
//
|
|
132
|
-
|
|
111
|
+
.setScoreConfiguration("treble") // Staff with treble G-clef.
|
|
112
|
+
.setScoreConfiguration("bass") // Staff with bass F-clef.
|
|
113
|
+
.setScoreConfiguration("grand") // Both treble and bas staves.
|
|
114
|
+
.setScoreConfiguration("guitarTreble") // Same as `Treble` but one octave down.
|
|
115
|
+
.setScoreConfiguration("guitarTab") // Guitar tab only.
|
|
116
|
+
.setScoreConfiguration("guitarCombined") // Treble and tab for guitar.
|
|
133
117
|
```
|
|
134
118
|
|
|
135
119
|
#### Using configuration objects
|
|
136
120
|
```js
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* `type`: "tab"
|
|
155
|
-
* `name`: tab name.
|
|
156
|
-
* `tuning`: string | string[] (optional), tuning name or array of 6 note names for tuning.
|
|
157
|
-
* `voiceIds`: number[] (optional), array of voice ids are visible on this tab.
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
// Example: Staff and tab for guitar
|
|
161
|
-
builder.setScoreConfiguration([
|
|
162
|
-
{ type: "staff", clef: Score.Clef.G, isOctaveDown: true },
|
|
121
|
+
.setScoreConfiguration({ type: "staff", clef: "G"}) // Staff with treble G-clef.
|
|
122
|
+
.setScoreConfiguration({ type: "staff", clef: "F"}) // Staff with bass F-clef.
|
|
123
|
+
.setScoreConfiguration({
|
|
124
|
+
type: "staff",
|
|
125
|
+
clef: "G", // G-clef
|
|
126
|
+
isOctaveDown: false, // (optional) octave down
|
|
127
|
+
name: "staff1", // (optional) staff name
|
|
128
|
+
minNote: "C2", // (optional) min allowed note
|
|
129
|
+
maxNote: "C6", // (optional) max allowed note
|
|
130
|
+
voiceIds: [0, 1] // (optional) only present voices 0 and 1 in this staff
|
|
131
|
+
})
|
|
132
|
+
.setScoreConfiguration([
|
|
133
|
+
{ type: "staff", clef: "G", isGrand: true },
|
|
134
|
+
{ type: "staff", clef: "F", isGrand: true }
|
|
135
|
+
]) // Grand staff
|
|
136
|
+
.setScoreConfiguration([
|
|
137
|
+
{ type: "staff", clef: "G", isOctaveDown: true },
|
|
163
138
|
{ type: "tab", tuning: "Drop D" }
|
|
164
|
-
])
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
139
|
+
]) // Staff and tab for guitar, tab with Drop D tuning.
|
|
140
|
+
.setScoreConfiguration(
|
|
141
|
+
{
|
|
142
|
+
type: "tab",
|
|
143
|
+
name: "tab1",
|
|
144
|
+
tuning: ["E2", "A2", "D3", "G3", "B3", "E4"],
|
|
145
|
+
voiceIds: 4
|
|
146
|
+
}) // Tab with guitar tuning, present only voiceId 4 in this tab.
|
|
171
147
|
```
|
|
172
148
|
|
|
173
149
|
### Set Automatic Measures Per Row
|
|
174
150
|
```ts
|
|
175
|
-
|
|
151
|
+
.setMesuresPerRow(4) // Set 4 measures per row
|
|
152
|
+
.setMesuresPerRow(Infinity) // Turn off auto row change (default)
|
|
176
153
|
```
|
|
177
154
|
|
|
178
|
-
`measuresPerRow` can be integer >= 1, or Infinity (default).
|
|
179
|
-
|
|
180
155
|
### Set Header
|
|
181
156
|
```js
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// Example
|
|
185
|
-
builder.setHeader("Demo Song");
|
|
157
|
+
.setHeader("Title", "Composer", "Arranger") // Set title, composer and arranger
|
|
158
|
+
.setHeader("Title") // Set title only
|
|
186
159
|
```
|
|
187
160
|
|
|
188
161
|
### Add Measure
|
|
189
162
|
```js
|
|
190
|
-
|
|
163
|
+
.addMeasure() // Add new measure
|
|
191
164
|
```
|
|
192
165
|
|
|
193
166
|
### End Row
|
|
194
167
|
```js
|
|
195
|
-
|
|
168
|
+
.endRow() // Manually induce row change. Next measure that is added will begin new row.
|
|
196
169
|
```
|
|
197
170
|
|
|
198
|
-
Manually induce row change. Next measure that is added will begin new row.
|
|
199
|
-
|
|
200
171
|
### Set Key Signature
|
|
172
|
+
For scale type you can use `Theory.ScaleType` enum values (e.g. `Theory.ScaleType.Major`)
|
|
173
|
+
or corresponding string values (e.g. `"Major"`).
|
|
201
174
|
|
|
202
175
|
```js
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
`tonic` is scale tonic/root note, e.g. "C" (in "C Major").
|
|
210
|
-
|
|
211
|
-
`scaleType` can be
|
|
212
|
-
- `Theory.ScaleType.Major`
|
|
213
|
-
- `Theory.ScaleType.NaturalMinor`
|
|
214
|
-
- `Theory.ScaleType.HarmonicMinor`
|
|
215
|
-
- `Theory.ScaleType.Ionian`
|
|
216
|
-
- `Theory.ScaleType.Dorian`
|
|
217
|
-
- `Theory.ScaleType.Phrygian`
|
|
218
|
-
- `Theory.ScaleType.Lydian`
|
|
219
|
-
- `Theory.ScaleType.Mixolydian`
|
|
220
|
-
- `Theory.ScaleType.Aeolian`
|
|
221
|
-
- `Theory.ScaleType.Locrian`
|
|
222
|
-
- `Theory.ScaleType.MajorPentatonic`
|
|
223
|
-
- `Theory.ScaleType.MinorPentatonic`
|
|
224
|
-
- `Theory.ScaleType.MajorHexatonicBlues`
|
|
225
|
-
- `Theory.ScaleType.MinorHexatonicBlues`
|
|
226
|
-
- `Theory.ScaleType.HeptatonicBlues`
|
|
176
|
+
.setKeySignature("C Major") // Create C Major scale.
|
|
177
|
+
.setKeySignature("D", "Major") // Create D Major scale.
|
|
178
|
+
.setKeySignature("A", "Natural Minor") // Create A natural minor scale.
|
|
179
|
+
```
|
|
227
180
|
|
|
228
181
|
### Set Time Signature
|
|
229
182
|
```js
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
//
|
|
233
|
-
|
|
183
|
+
.setTimeSignature("2/4") // Set time signature of 2/4
|
|
184
|
+
.setTimeSignature("3/4") // Set time signature of 3/4
|
|
185
|
+
.setTimeSignature("4/4") // Set time signature of 4/4
|
|
186
|
+
.setTimeSignature("6/8") // Set time signature of 6/8
|
|
187
|
+
.setTimeSignature("9/8") // Set time signature of 9/8
|
|
234
188
|
```
|
|
235
189
|
|
|
236
|
-
timeSignature can be:
|
|
237
|
-
- `"2/4"`
|
|
238
|
-
- `"3/4"`
|
|
239
|
-
- `"4/4"`
|
|
240
|
-
- `"6/8"`
|
|
241
|
-
- `"9/8"`
|
|
242
|
-
|
|
243
190
|
### Set Tempo
|
|
244
191
|
```js
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// Example
|
|
248
|
-
builder.setTempo(100, Theory.NoteLength.Quarter);
|
|
192
|
+
.setTempo(100, "4n") // 100 beats per minute, beat length is quarter note.
|
|
193
|
+
.setTempo(80, "4..") // 100 beats per minute, beat length is double dotted quarter note.
|
|
249
194
|
```
|
|
250
195
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
`beatLength` tells the length of each beat, e.g. Theory.NoteLength.Quarter.
|
|
254
|
-
|
|
255
|
-
`dotted` tells if `beatLength` is dotted.
|
|
256
|
-
|
|
257
|
-
### Add Note Or Chord
|
|
258
|
-
|
|
196
|
+
### Add Note
|
|
259
197
|
```js
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
builder.addChord(1, ["C3", "E3", "G3"], Theory.NoteLength.Whole, { arpeggio: Score.Arpeggio.Down });
|
|
198
|
+
.addNote(0, "C4", "1n") // Create whole note "C4"
|
|
199
|
+
.addNote(0, "Bb4", "2..") // Create double dotted half note "Bb4"
|
|
200
|
+
.addNote(0, "C4", "4n", { stem: "up" }) // Stem direction Up (could be also Down)
|
|
201
|
+
.addNote(0, "C4", "4n", { staccate: true }) // Show staccato dot and play in short
|
|
202
|
+
.addNote(0, "C4", "4n", { diamond: true }) // Show diamond shaped note head
|
|
266
203
|
```
|
|
267
204
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
`notes`: array of notes `string[]` (e.g. `["C3", "E3"]`)
|
|
273
|
-
|
|
274
|
-
`noteLength` can be:
|
|
275
|
-
* `Theory.NoteLength.Whole`
|
|
276
|
-
* `Theory.NoteLength.Half`
|
|
277
|
-
* `Theory.NoteLength.Quarter`
|
|
278
|
-
* `Theory.NoteLength.Eighth`
|
|
279
|
-
* `Theory.NoteLength.Sixteenth`
|
|
280
|
-
* `Theory.NoteLength.ThirtySecond`
|
|
281
|
-
* `Theory.NoteLength.SixtyFourth`
|
|
282
|
-
|
|
283
|
-
`noteOptions` is optional object of note options (e.g. `{ dotted: true }`):
|
|
284
|
-
|
|
285
|
-
| Note option | Type | |
|
|
286
|
-
|-------------|---------------------------|---------------------|
|
|
287
|
-
| dotted | `boolean` | Create dotted note. |
|
|
288
|
-
| stem | `Score.Stem.Auto/Up/Down` | Set stem direction. |
|
|
289
|
-
| arpeggio | `Score.Arpeggio.Up/Down` \| `boolean` | Play column in arpeggio. |
|
|
290
|
-
| staccato | `boolean` | Play column in staccato. |
|
|
291
|
-
| diamond | `boolean` | Diamond shaped note head. |
|
|
292
|
-
| triplet | `boolean` | Set this note part of triplet. |
|
|
293
|
-
| string | `number` \| `number[]` | String number for guitar tab. Array of string numbers for chord. |
|
|
205
|
+
### Add Chord
|
|
206
|
+
```js
|
|
207
|
+
.addChord(1, ["C3", "E3", "G3"], "1n", { arpeggio: "down" }) // Create whole note chord of three notes, played in arpeggio.
|
|
208
|
+
```
|
|
294
209
|
|
|
295
210
|
### Add Rest
|
|
296
211
|
|
|
297
212
|
```js
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
//
|
|
301
|
-
|
|
213
|
+
.addRest(0, "16n") // Add sixteenth rest
|
|
214
|
+
.addRest(0, "4.") // Add dotted quarter rest
|
|
215
|
+
.addRest(0, "4n", { staffPos: "D3" }) // Draw this quarter rest at level of "D3" note.
|
|
216
|
+
.addRest(0, "4n", { hide: true }) // Invisible rest affects playing
|
|
302
217
|
```
|
|
303
218
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
`restLength` is length of rest, similar as noteLength above.
|
|
307
|
-
|
|
308
|
-
`restOptions` is optional object of rest options (e.g. `{ hide: true }`):
|
|
309
|
-
|
|
310
|
-
| Rest option | Type | |
|
|
311
|
-
|-------------|--------------|---------------------|
|
|
312
|
-
| dotted | `boolean` | Create dotted rest. |
|
|
313
|
-
| staffPos | `string` | Staff positions (e.g. `"C3"`). |
|
|
314
|
-
| hide | `boolean` | Add invisible rest. |
|
|
315
|
-
| triplet | `boolean` | Set this rest part of triplet. |
|
|
316
|
-
|
|
317
|
-
### Add Fermata
|
|
318
|
-
|
|
219
|
+
### Add Tuplet
|
|
220
|
+
This works for any tuplet:
|
|
319
221
|
```js
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
222
|
+
// Example: add triplet
|
|
223
|
+
.addTuplet(0, { parts: 3, inTimeOf: 2 }, notes => {
|
|
224
|
+
notes.addNote("G3", "8n")
|
|
225
|
+
notes.addNote("B3", "8n")
|
|
226
|
+
notes.addNote("D4", "8n")
|
|
227
|
+
})
|
|
324
228
|
```
|
|
325
229
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
230
|
+
Triplets can also be created using note length (e.g. NoteLength.EighthTriplet or "8t").
|
|
231
|
+
```js
|
|
232
|
+
// Example: add triplet using triplet note length.
|
|
233
|
+
.addNote(0, "G3", "8t")
|
|
234
|
+
.addNote(0, "B3", "8t")
|
|
235
|
+
.addNote(0, "D4", "8t")
|
|
236
|
+
```
|
|
329
237
|
|
|
330
|
-
### Add
|
|
238
|
+
### Add Fermata
|
|
331
239
|
|
|
332
|
-
|
|
240
|
+
For fermata you can use `Score.Fermata` enum values (e.g. `Scoore.Fermata.AtNote`)
|
|
241
|
+
or corresponding string values (e.g. `"atNote"`).
|
|
333
242
|
|
|
334
243
|
```js
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
// Examples
|
|
338
|
-
builder.addNavigation(Score.Navigation.StartRepeat);
|
|
339
|
-
builder.addNavigation(Score.Navigation.EndRepeat, 3);
|
|
340
|
-
builder.addNavigation(Score.Navigation.Ending, 1, 2);
|
|
244
|
+
.addNote(0, "C3", "2n").addFermata("atNote") // Add fermata at note.
|
|
245
|
+
.addFermata("atMeasureEnd") // Add fermata at measure end.
|
|
341
246
|
```
|
|
342
247
|
|
|
343
|
-
|
|
344
|
-
* `Score.Navigation.DC_al_Fine`
|
|
345
|
-
* `Score.Navigation.DC_al_Coda`
|
|
346
|
-
* `Score.Navigation.DS_al_Fine`
|
|
347
|
-
* `Score.Navigation.DS_al_Coda`
|
|
348
|
-
* `Score.Navigation.Coda`
|
|
349
|
-
* `Score.Navigation.toCoda`
|
|
350
|
-
* `Score.Navigation.Segno`
|
|
351
|
-
* `Score.Navigation.Fine`
|
|
352
|
-
* `Score.Navigation.StartRepeat`
|
|
353
|
-
* `Score.Navigation.EndRepeat`
|
|
354
|
-
* `Score.Navigation.Ending`
|
|
355
|
-
|
|
356
|
-
`Score.Navigation.EndRepeat` takes optional second arg which is number of times to repeat (once if omitted).
|
|
357
|
-
|
|
358
|
-
`Score.Navigation.Ending` takes variable number of number args, each is a passage number.
|
|
248
|
+
### Add Navigation
|
|
359
249
|
|
|
360
|
-
|
|
250
|
+
Add navigation element to measure.
|
|
361
251
|
|
|
362
|
-
|
|
252
|
+
For navigation you can use `Score.Navigation` enum values (e.g. `Score.Navigation.DC_al_Fine`)
|
|
253
|
+
or corresponding string values (e.g. `"D.C. al Fine"`).
|
|
363
254
|
|
|
364
255
|
```js
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
//
|
|
368
|
-
|
|
256
|
+
.addNavigation("D.C. al Fine") // Add "D.C. al Fine"
|
|
257
|
+
.addNavigation("D.C. al Coda") // Add "D.C. al Coda"
|
|
258
|
+
.addNavigation("D.S. al Fine") // Add "D.S. al Fine"
|
|
259
|
+
.addNavigation("D.S. al Coda") // Add "D.S. al Coda"
|
|
260
|
+
.addNavigation("Coda") // Add "Coda"
|
|
261
|
+
.addNavigation("toCoda") // Ass "toCoda"
|
|
262
|
+
.addNavigation("Segno") // Add "Segno" symbol
|
|
263
|
+
.addNavigation("Fine") // Add "Fine"
|
|
264
|
+
.addNavigation("startRepeat") // Add repeat sections start position
|
|
265
|
+
.addNavigation("endRepeat", 3) // Add repeat sections end position, repeat sectionplayed 3 times
|
|
266
|
+
.addNavigation("ending", 1, 2) // Add ending, played on 1st and 2nd run
|
|
369
267
|
```
|
|
370
268
|
|
|
371
|
-
`label` can be:
|
|
372
|
-
* `Score.Label.Note`: Used to label notes and is positioned below note.
|
|
373
|
-
* `Score.Label.Chord`: Used to label chords and is positioned on top.
|
|
374
|
-
|
|
375
269
|
### Add Annotation
|
|
376
270
|
|
|
377
271
|
Add annotation text anchored to previously added note, chord or rest.
|
|
378
272
|
|
|
379
|
-
|
|
380
|
-
|
|
273
|
+
For annotation you can use `Score.Annotation` enum values (e.g. `Score.Annotation.Tempo`)
|
|
274
|
+
or corresponding string values (e.g. `"tempo"`).
|
|
381
275
|
|
|
382
|
-
|
|
383
|
-
|
|
276
|
+
```js
|
|
277
|
+
.addAnnotation("dynamics", "ff") // Add dynamics annotation text.
|
|
278
|
+
.addAnnotation("tempo", "accel.") // Add tempo annotation text.
|
|
279
|
+
.addAnnotation("ppp") // Add annotation text, detect annotation type automatically (incomplete list of annotations supported).
|
|
384
280
|
```
|
|
385
281
|
|
|
386
|
-
|
|
387
|
-
* `Score.Annotation.Dynamics`: `text` could be for example `"fff"`, `"cresc."`, `"dim."`, etc.
|
|
388
|
-
* `Score.Annotation.Tempo`: `text` could be for example `"accel."`, `"rit."`, `"a tempo"`, etc.
|
|
389
|
-
|
|
390
|
-
### Add Elements To Certain Staff Or Tab
|
|
391
|
-
|
|
392
|
-
There are alternatives to these functions:
|
|
393
|
-
- `addFermata` => `addFermataTo`
|
|
394
|
-
- `addNavigation` => `addNavigationTo`
|
|
395
|
-
- `addAnnotation` => `addAnnotationTo`
|
|
396
|
-
- `addLabel` => `addLabelTo`.
|
|
397
|
-
|
|
398
|
-
First argument of these alterate functions is:
|
|
282
|
+
### Add Label
|
|
399
283
|
|
|
400
|
-
|
|
284
|
+
Add text label anchored to previously added note, chord or rest.
|
|
401
285
|
|
|
402
|
-
`
|
|
403
|
-
|
|
404
|
-
- `string`: staff/tab name.
|
|
405
|
-
- `string`: staff group name.
|
|
406
|
-
- `(number | string)[]`: an array of staff/tab indices, names or group names.
|
|
286
|
+
For label you can use `Score.Label` enum values (e.g. `Score.Label.Chord`)
|
|
287
|
+
or corresponding string values (e.g. `"chord"`).
|
|
407
288
|
|
|
408
289
|
```js
|
|
409
|
-
//
|
|
410
|
-
|
|
290
|
+
.addLabel("chord", "Am") // Add chord label, positioned above staff by default.
|
|
291
|
+
.addLabel("note", "C#5") // Add note label, positioned below staff by default.
|
|
411
292
|
```
|
|
412
293
|
|
|
413
|
-
|
|
414
|
-
```js
|
|
415
|
-
builder.addStaffGroup(groupName: string, staffsTabsAndGroups: number | string | (number | string)[], verticalPosition: Score.VerticalPosition);
|
|
416
|
-
```
|
|
294
|
+
### Positioning Elements
|
|
417
295
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
- `staffsTabsAndGroups`: single value or an array of staves, tabs and groups (index or name).
|
|
421
|
-
- `verticalPosition` (optional): Can be `Score.VerticalPosition.Above`/`Below`/`Both`/`Auto` (default).
|
|
296
|
+
`addFermata`, `addNavigation`, `addAnnotation` and `addLabel` functions have alternate versions
|
|
297
|
+
`addFermataTo`, `addNavigationTo`, `addAnnotationTo` and `addLabelTo` that contain extra first argument.
|
|
422
298
|
|
|
423
299
|
```js
|
|
424
|
-
|
|
425
|
-
// Add
|
|
426
|
-
|
|
427
|
-
//
|
|
428
|
-
|
|
300
|
+
.addLabelTo(0, "chord", "Am") // Add label to top (id 0) staff/tab.
|
|
301
|
+
.addLabelTo([0, 1], "chord", "Am") // Add label to top two (id 0 and 1) staves/tabs.
|
|
302
|
+
.addLabelTo("staff1", "chord", "Am") // Add label to staff/tab/group named "staff1".
|
|
303
|
+
.addLabelTo("grp1", "chord", "Am") // Add label to staff/tab/group named "grp1".
|
|
304
|
+
|
|
305
|
+
// Create staff groups
|
|
306
|
+
.addStaffGroup("grp1", 0, "above") // This staff group layouts elements above top staff/tab.
|
|
307
|
+
.addStaffGroup("grp2", [1], "below") // This staff group layouts elements below second staff/tab from top.
|
|
308
|
+
.addStaffGroup("grp3", "tab1", "both") // This staff group layouts elements above and below tab named "tab1".
|
|
309
|
+
.addStaffGroup("grp4", ["staff1", "tab1"], "auto") // This staff group layouts elements to their default locations in "staff1" and "tab1".
|
|
429
310
|
```
|
|
430
311
|
|
|
431
312
|
### Add Extension
|
|
432
313
|
|
|
433
|
-
Adds extension line to
|
|
314
|
+
Adds extension line to previously added label or annotation.
|
|
434
315
|
|
|
435
316
|
```js
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
//
|
|
439
|
-
|
|
317
|
+
.addExtension(ext => ext.notes("1n", 2)) // Add extension line, length is 2 whole notes
|
|
318
|
+
.addExtension(ext => ext.measures(3).hide()) // Add extension line, length is 3 measures, hidden
|
|
319
|
+
.addExtension(ext => ext.measures(1).notes("8n")) // Add extension line, length is 1 measure + 1 eigth note
|
|
320
|
+
.addExtension(ext => ext.infinity()) // Add extension line, length is as long as possible
|
|
321
|
+
.addExtension() // Add extension line, length is as long as possible
|
|
440
322
|
```
|
|
441
323
|
|
|
442
|
-
`extensionLength` is `number` but `Theory.NoteLength` values can be used as number and multiplied to set desired extension length.
|
|
443
|
-
|
|
444
|
-
`visible` sets visibility of extension line, visible by default (if omitted).
|
|
445
|
-
|
|
446
324
|
### Add Connective (tie, slur, slide)
|
|
447
325
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
builder.addConnective(connective: Score.Connetive.Tie, span?: Score.ConnectiveSpan, noteAnchor?: Score.NoteAnchor);
|
|
451
|
-
|
|
452
|
-
// Add slur
|
|
453
|
-
builder.addConnective(connective: Score.Connetive.Slur, span?: Score.ConnectiveSpan, noteAnchor?: Score.NoteAnchor);
|
|
454
|
-
|
|
455
|
-
// Add slide
|
|
456
|
-
builder.addConnective(connective: Score.Connetive.Slide, noteAnchor?: Score.NoteAnchor);
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
- `span` describes how many notes the connective is across.
|
|
460
|
-
It is integer >= 2 (for tie it can be also `Score.TieType.Stub|ToMeasureEnd`).
|
|
461
|
-
Default value is 2.
|
|
462
|
-
- `noteAnchor` describes the attach point of connective to note.
|
|
463
|
-
It can be `Score.NoteAnchor.Auto|Above|Center|Below|StemTip`.
|
|
464
|
-
Default value is `Score.NoteAnchor.Auto`.
|
|
465
|
-
|
|
466
|
-
### Guitar Tab
|
|
326
|
+
For connective you can use `Score.Connective` enum values (e.g. `Score.Connective.Tie`)
|
|
327
|
+
or corresponding string values (e.g. `"tie"`).
|
|
467
328
|
|
|
468
|
-
|
|
469
|
-
|
|
329
|
+
For note anchor you can use `Score.NoteAnchor` enum values (e.g. `Score.NoteAnchor.Above`)
|
|
330
|
+
or corresponding string values (e.g. `"above"`).
|
|
470
331
|
|
|
471
|
-
Add notes with `{ string: number | number[] }` to specify which string the fret number is rendered in guitar tab.
|
|
472
332
|
|
|
473
333
|
```js
|
|
474
|
-
//
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
//
|
|
478
|
-
|
|
334
|
+
.addConnective("tie") // Add tie
|
|
335
|
+
.addConnective("slur") // Add slur
|
|
336
|
+
.addConnective("slide") // Add slide
|
|
337
|
+
.addConnective("tie", 3) // Add tie with span value (describes how many notes the connective is across).
|
|
338
|
+
.addConnective("slur", 2, "above") // Add slur connected above note.
|
|
339
|
+
.addConnective("slur", 2, "below") // Add slur connected below note.
|
|
340
|
+
.addConnective("slur", 2, "center") // Add slur connected next to note.
|
|
341
|
+
.addConnective("slur", 2, "stemTip") // Add slur connected at stem tip.
|
|
479
342
|
```
|
|
480
343
|
|
|
481
|
-
###
|
|
344
|
+
### Guitar Tab
|
|
345
|
+
|
|
346
|
+
This library has simple guitar tab rendering.
|
|
482
347
|
|
|
483
|
-
`
|
|
348
|
+
Add notes with `string` property to specify at what string the fret number is rendered in the tab.
|
|
484
349
|
|
|
485
350
|
```js
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
.setMeasuresPerRow(4)
|
|
489
|
-
.addMeasure()
|
|
490
|
-
.addNote(1, "C3", Theory.NoteLength.Quarter)
|
|
491
|
-
.addChord(1, ["C3", "E3", "G3"], Theory.NoteLength.Quarter).addLabel(Score.Label.Chord, "C")
|
|
492
|
-
.addRest(1, Theory.NoteLength.Quarter)
|
|
493
|
-
// etc.
|
|
494
|
-
.getDEocument();
|
|
351
|
+
.addNote(0, "G3", "8n", { string: 3 })
|
|
352
|
+
.addChord(0, ["E4", "C3"], "8n", { string: [1, 5] })
|
|
495
353
|
```
|
|
496
354
|
|
|
497
355
|
### Beams
|
|
@@ -503,12 +361,12 @@ Beams are detected and added automatically.
|
|
|
503
361
|
Default instrument is `Synthesizer`.
|
|
504
362
|
|
|
505
363
|
`Classical Guitar` is available via `audio-cg` module.
|
|
506
|
-
It
|
|
364
|
+
It is included as separate module because it contains over 1MB of guitar audio samples bundled in it.
|
|
507
365
|
|
|
508
366
|
```js
|
|
509
367
|
import { registerClassicalGuitar } from "@tspro/web-music-score/audio-cg";
|
|
510
368
|
|
|
511
|
-
registerClassicalGuitar();
|
|
369
|
+
registerClassicalGuitar(); // This registers classical guitar audio, and takes it into use.
|
|
512
370
|
```
|
|
513
371
|
|
|
514
372
|
### Play Document
|
|
@@ -518,13 +376,13 @@ registerClassicalGuitar();
|
|
|
518
376
|
doc.play();
|
|
519
377
|
|
|
520
378
|
// More playback options:
|
|
521
|
-
let player = new MPlayer(doc);
|
|
379
|
+
let player = new Score.MPlayer(doc);
|
|
522
380
|
|
|
523
381
|
player.play();
|
|
524
382
|
player.pause();
|
|
525
383
|
player.stop();
|
|
526
384
|
|
|
527
|
-
MPlayer.stopAll();
|
|
385
|
+
Score.MPlayer.stopAll();
|
|
528
386
|
```
|
|
529
387
|
|
|
530
388
|
### Viewing Using React JSX/TSX
|