@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.
- package/CHANGELOG.md +19 -0
- package/README.md +271 -224
- 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-2EPWQZKJ.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-kbJYu3Am.d.mts +24 -0
- package/dist/iife/index.global.js +222 -0
- package/dist/note-B5ZtlHc8.d.ts +99 -0
- package/dist/note-CraqEy8x.d.mts +99 -0
- package/dist/pieces/index.d.mts +15 -0
- package/dist/pieces/index.d.ts +15 -0
- package/dist/pieces/index.js +104 -0
- package/dist/pieces/index.mjs +77 -0
- package/dist/react-ui/index.d.mts +169 -0
- package/dist/react-ui/index.d.ts +169 -0
- package/dist/react-ui/index.js +624 -0
- package/dist/react-ui/index.mjs +582 -0
- package/dist/score/index.d.mts +1558 -0
- package/dist/score/index.d.ts +1558 -0
- package/dist/score/index.js +6937 -0
- package/dist/score/index.mjs +6863 -0
- package/dist/tempo--588tdcv.d.ts +203 -0
- package/dist/tempo-BEJBHZ5I.d.mts +203 -0
- package/dist/theory/index.d.mts +47 -0
- package/dist/theory/index.d.ts +47 -0
- package/dist/theory/index.js +1783 -0
- package/dist/theory/index.mjs +1716 -0
- package/package.json +99 -56
- package/dist/index.cjs.js +0 -40708
- package/dist/index.d.ts +0 -1258
- package/dist/index.esm.mjs +0 -40699
- 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
|
-
|
|
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
|
-
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
|
-
##
|
|
10
|
+
## Version 2 Update
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
npm i @tspro/web-music-score
|
|
12
|
+
**Breaking:** Version 2 is major update and brought many changes.
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
+
Enough changes until next major update!
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
## Installation
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* No polyfills are included.
|
|
26
|
+
```sh
|
|
27
|
+
npm i @tspro/web-music-score
|
|
28
|
+
```
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
## Import
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
```js
|
|
33
|
+
// Import core module, it does not contain much.
|
|
34
|
+
import * as Core from "@tspro/web-music-score/core";
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
// Import audio module, it can play notes.
|
|
37
|
+
import * as Audio from "@tspro/web-music-score/audio";
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
// Import theory module, it contains all music theory stuff.
|
|
40
|
+
import * as Theory from "@tspro/web-music-score/theory";
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
// Import score module, it contains music score stuff.
|
|
43
|
+
import * as Score from "@tspro/web-music-score/score";
|
|
38
44
|
|
|
39
|
-
|
|
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
|
-
|
|
49
|
+
// Import pieces module, it contains demo songs.
|
|
50
|
+
import * as Pieces from "@tspro/web-music-score/pieces";
|
|
42
51
|
|
|
43
|
-
|
|
52
|
+
// You can also use require
|
|
53
|
+
const Core = require("@tspro/web-music-score/core");
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
56
|
-
import Score from "@tspro/web-music-score";
|
|
58
|
+
## Browser Script
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
```js
|
|
81
|
-
let doc = new Score.MDocument(Score.StaffKind.Treble, 4);
|
|
82
|
-
```
|
|
80
|
+
## API
|
|
83
81
|
|
|
84
|
-
|
|
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
|
-
|
|
85
|
+
Following is the main interface explained.
|
|
87
86
|
|
|
88
|
-
|
|
87
|
+
### Create Document
|
|
89
88
|
|
|
90
89
|
```js
|
|
91
|
-
doc.
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
105
|
+
Default tuning is `"Standard"`. `Theory.TuningNameList` is array of available tuning names.
|
|
104
106
|
|
|
105
107
|
```js
|
|
106
|
-
|
|
108
|
+
// Example
|
|
109
|
+
let doc = new Score.MDocument(Score.StaffPreset.GuitarCombined, { tuning: "Drop D" });
|
|
107
110
|
```
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### Set Signature
|
|
112
|
+
### Set Header
|
|
112
113
|
|
|
113
114
|
```js
|
|
114
|
-
|
|
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
|
-
|
|
123
|
-
|
|
117
|
+
// Example
|
|
118
|
+
doc.setHeader("Demo Song");
|
|
124
119
|
```
|
|
125
120
|
|
|
126
|
-
|
|
121
|
+
### Add Measure
|
|
127
122
|
|
|
128
123
|
```js
|
|
129
|
-
m.
|
|
130
|
-
m.setTempo(80);
|
|
124
|
+
let m = doc.addMeasure();
|
|
131
125
|
```
|
|
132
126
|
|
|
133
|
-
|
|
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.
|
|
141
|
-
m.addChord(1, ["C3", "E3", "G3", "C4"], Score.NoteLength.Whole);
|
|
130
|
+
m.endRow();
|
|
142
131
|
```
|
|
143
132
|
|
|
144
|
-
|
|
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
|
-
|
|
135
|
+
### Set Signature
|
|
149
136
|
|
|
150
|
-
|
|
137
|
+
```js
|
|
138
|
+
m.setKeySignature(tonic: string, scaleType: Theory.ScaleType);
|
|
151
139
|
|
|
152
|
-
|
|
153
|
-
m.
|
|
140
|
+
// Example: Am
|
|
141
|
+
m.setKeySignature("A", Theory.ScaleType.Aeolian);
|
|
154
142
|
```
|
|
155
143
|
|
|
156
|
-
|
|
144
|
+
`tonic` is scale tonic/root note, e.g. "C" (in "C Major").
|
|
157
145
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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.
|
|
166
|
-
m.addRest(0, Score.NoteLength.Quarter, { dotted: true });
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
#### Stem Direction
|
|
164
|
+
m.setTimeSignature(timeSignature: string);
|
|
170
165
|
|
|
171
|
-
|
|
172
|
-
m.
|
|
166
|
+
// Example
|
|
167
|
+
m.setTimeSignature("3/4");
|
|
173
168
|
```
|
|
174
169
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
184
|
+
`beatsPerMinute` is self explanatory.
|
|
192
185
|
|
|
193
|
-
|
|
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
|
-
|
|
188
|
+
`dotted` tells if `beatLength` is dotted.
|
|
198
189
|
|
|
199
|
-
|
|
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(
|
|
208
|
-
m.
|
|
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
|
-
|
|
201
|
+
`voiceId` can be `0`, `1`, `2` or `3`.
|
|
212
202
|
|
|
213
|
-
|
|
203
|
+
`note` is note name, e.g. `"G#3"`, `"Db3"`.
|
|
214
204
|
|
|
215
|
-
|
|
205
|
+
`notes`: array of notes `string[]` (e.g. `["C3", "E3"]`)
|
|
216
206
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
216
|
+
`noteOptions` is optional object of note options (e.g. `{ dotted: true }`):
|
|
225
217
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
232
|
+
### Add Rest
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
```js
|
|
235
|
+
m.addRest(voideId: number, restLength: Theory.NoteLength, restOptions?: Score.RestOptions);
|
|
235
236
|
|
|
236
|
-
|
|
237
|
-
m.addRest(0,
|
|
237
|
+
// Example
|
|
238
|
+
m.addRest(0, Theory.NoteLength.Sixteenth);
|
|
238
239
|
```
|
|
239
240
|
|
|
240
|
-
|
|
241
|
+
`voiceId` can be `0`, `1`, `2` or `3`.
|
|
241
242
|
|
|
242
|
-
|
|
243
|
+
`restLength` is length of rest, similar as noteLength above.
|
|
243
244
|
|
|
244
|
-
|
|
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
|
-
|
|
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.
|
|
254
|
-
m.addRest(0, Score.NoteLength.Quarter).addFermata();
|
|
255
|
-
```
|
|
257
|
+
m.addFermata(fermata?: Score.Fermata);
|
|
256
258
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
```js
|
|
259
|
+
// Example
|
|
260
260
|
m.addFermata(Score.Fermata.AtMeasureEnd);
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
295
|
+
`Score.Navigation.Ending` takes variable number of number args, each is a passage number.
|
|
274
296
|
|
|
275
|
-
|
|
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
|
-
|
|
299
|
+
Add text label anchored to previously added note, chord or rest.
|
|
288
300
|
|
|
289
301
|
```js
|
|
290
|
-
m.
|
|
302
|
+
m.addLabel(label: Score.Label, text: string);
|
|
303
|
+
|
|
304
|
+
// Example
|
|
305
|
+
m.addLabel(Score.Label.Chord, "Am);
|
|
291
306
|
```
|
|
292
307
|
|
|
293
|
-
|
|
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
|
-
|
|
296
|
-
m.addNavigation(Score.Navigation.Ending, 1, 2);
|
|
297
|
-
m.addNavigation(Score.Navigation.Ending, 3);
|
|
298
|
-
```
|
|
312
|
+
### Add Annotation
|
|
299
313
|
|
|
300
|
-
|
|
314
|
+
Add annotation text anchored to previously added note, chord or rest.
|
|
301
315
|
|
|
302
316
|
```js
|
|
303
|
-
m.
|
|
317
|
+
m.addAnnotation(annotation: Score.Annotation, text: string);
|
|
318
|
+
|
|
319
|
+
// Example
|
|
320
|
+
m.addAnnotation(Score.Annotation.Tempo, "accel.");
|
|
304
321
|
```
|
|
305
322
|
|
|
306
|
-
|
|
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
|
-
|
|
309
|
-
* Label.Chord is used to label chords and is positioned on top.
|
|
327
|
+
### Add Extension
|
|
310
328
|
|
|
311
|
-
|
|
329
|
+
Adds extension line to element, for example to previously added annotation.
|
|
312
330
|
|
|
313
331
|
```js
|
|
314
|
-
m.
|
|
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
|
-
|
|
338
|
+
`extensionLength` is `number` but `Theory.NoteLength` values can be used as number and multiplied to set desired extension length.
|
|
318
339
|
|
|
319
|
-
|
|
340
|
+
`visible` sets visibility of extension line, visible by default (if omitted).
|
|
320
341
|
|
|
321
|
-
|
|
322
|
-
* Annotation.Tempo could be for example "accel.", "rit.", "a tempo", etc.
|
|
342
|
+
### Guitar Tab
|
|
323
343
|
|
|
324
|
-
|
|
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
|
-
|
|
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
|
-
|
|
351
|
+
Add notes with `{ string: number | number[] }` to specify which string the fret number is rendered in guitar tab.
|
|
333
352
|
|
|
334
|
-
|
|
353
|
+
```js
|
|
354
|
+
// Single note
|
|
355
|
+
m.addNote(0, "G3", Theory.NoteLength.Eighth, { string: 3 });
|
|
335
356
|
|
|
336
|
-
|
|
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",
|
|
345
|
-
.addChord(1, ["C3", "E3", "G3"],
|
|
346
|
-
.addRest(1,
|
|
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
|
-
###
|
|
376
|
+
### Classical Guitar Audio Module
|
|
354
377
|
|
|
355
|
-
|
|
356
|
-
Score.Audio.setInstrument(Score.Audio.Instrument.ClassicalGuitar);
|
|
357
|
-
```
|
|
378
|
+
Default instrument is `Synthesizer`.
|
|
358
379
|
|
|
359
|
-
|
|
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
|
-
|
|
384
|
+
import { registerClassicalGuitar } from "@tspro/web-music-score/audio-cg";
|
|
385
|
+
|
|
386
|
+
registerClassicalGuitar();
|
|
363
387
|
```
|
|
364
388
|
|
|
365
|
-
|
|
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
|
-
<
|
|
409
|
+
<ScoreUI.MusicScoreView doc={doc} />
|
|
384
410
|
|
|
385
411
|
// Add playback buttons
|
|
386
|
-
<
|
|
387
|
-
<
|
|
388
|
-
<
|
|
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
|
|
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
|
-
###
|
|
431
|
-
|
|
456
|
+
### MusicError
|
|
432
457
|
```js
|
|
433
458
|
try {
|
|
434
|
-
//
|
|
435
|
-
m.addNote(0, "C", Score.NoteLength.Quarter);
|
|
459
|
+
// Do your music stuff
|
|
436
460
|
}
|
|
437
|
-
catch(e) {
|
|
438
|
-
|
|
439
|
-
|
|
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).
|