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