abcjs 6.0.0-beta.7 → 6.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/.github/workflows/tests.yml +29 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/CONTRIBUTING.md +1 -0
- package/LICENSE.md +1 -1
- package/README.md +92 -3
- package/RELEASE.md +957 -1
- package/abcjs-audio.css +14 -5
- package/dist/.gitignore +1 -2
- package/dist/abcjs-basic-min.js +3 -0
- package/dist/abcjs-basic-min.js.LICENSE +23 -0
- package/dist/abcjs-basic.js +28231 -0
- package/dist/abcjs-basic.js.map +1 -0
- package/dist/abcjs-plugin-min.js +3 -0
- package/dist/abcjs-plugin-min.js.LICENSE +23 -0
- package/dist/report-basic.html +37 -0
- package/dist/report-before-glyph-compress.html +37 -0
- package/dist/report-brown-ts-target-es5.html +37 -0
- package/dist/report-dev-orig-no-babel.html +37 -0
- package/dist/report-synth.html +37 -0
- package/docker-build.sh +1 -0
- package/glyphs.json +1 -0
- package/index.js +27 -2
- package/{static-wrappers/license.js → license.js} +1 -1
- package/package.json +26 -29
- package/{src/plugin/abc_plugin.js → plugin.js} +31 -19
- package/src/api/abc_animation.js +1 -17
- package/src/api/abc_tablatures.js +144 -0
- package/src/api/abc_timing_callbacks.js +234 -116
- package/src/api/abc_tunebook.js +18 -67
- package/src/api/abc_tunebook_svg.js +38 -46
- package/src/data/abc_tune.js +232 -972
- package/src/data/deline-tune.js +199 -0
- package/src/edit/abc_editarea.js +112 -0
- package/src/edit/abc_editor.js +95 -221
- package/src/midi/abc_midi_create.js +48 -50
- package/src/parse/abc_common.js +0 -14
- package/src/parse/abc_parse.js +167 -1321
- package/src/parse/abc_parse_book.js +62 -0
- package/src/parse/abc_parse_directive.js +164 -41
- package/src/parse/abc_parse_header.js +116 -145
- package/src/parse/abc_parse_key_voice.js +26 -20
- package/src/parse/abc_parse_music.js +1337 -0
- package/src/parse/abc_tokenizer.js +21 -15
- package/src/parse/abc_transpose.js +3 -15
- package/src/parse/tune-builder.js +896 -0
- package/src/parse/wrap_lines.js +205 -453
- package/src/synth/abc_midi_flattener.js +1292 -0
- package/src/{midi → synth}/abc_midi_renderer.js +44 -17
- package/src/synth/abc_midi_sequencer.js +648 -0
- package/src/synth/active-audio-context.js +3 -14
- package/src/synth/cents-to-factor.js +10 -0
- package/src/synth/create-note-map.js +21 -32
- package/src/synth/create-synth-control.js +20 -103
- package/src/synth/create-synth.js +185 -77
- package/src/synth/download-buffer.js +7 -21
- package/src/synth/get-midi-file.js +13 -20
- package/src/synth/images/{loading.svg → loading.svg.js} +4 -0
- package/src/synth/images/loop.svg.js +65 -0
- package/src/synth/images/pause.svg.js +10 -0
- package/src/synth/images/play.svg.js +9 -0
- package/src/synth/images/{reset.svg → reset.svg.js} +5 -1
- package/src/synth/instrument-index-to-name.js +1 -16
- package/src/synth/load-note.js +37 -76
- package/src/synth/pitch-to-note-name.js +0 -15
- package/src/synth/pitches-to-perc.js +64 -0
- package/src/synth/place-note.js +78 -68
- package/src/synth/play-event.js +17 -18
- package/src/synth/register-audio-context.js +11 -23
- package/src/synth/sounds-cache.js +0 -15
- package/src/synth/supports-audio.js +9 -23
- package/src/synth/synth-controller.js +80 -49
- package/src/synth/synth-sequence.js +20 -34
- package/src/tablatures/instruments/guitar/guitar-fonts.js +19 -0
- package/src/tablatures/instruments/guitar/guitar-patterns.js +23 -0
- package/src/tablatures/instruments/guitar/tab-guitar.js +50 -0
- package/src/tablatures/instruments/string-patterns.js +277 -0
- package/src/tablatures/instruments/string-tablature.js +56 -0
- package/src/tablatures/instruments/tab-note.js +282 -0
- package/src/tablatures/instruments/tab-notes.js +41 -0
- package/src/tablatures/instruments/violin/tab-violin.js +47 -0
- package/src/tablatures/instruments/violin/violin-fonts.js +19 -0
- package/src/tablatures/instruments/violin/violin-patterns.js +23 -0
- package/src/tablatures/tab-absolute-elements.js +310 -0
- package/src/tablatures/tab-common.js +29 -0
- package/src/tablatures/tab-renderer.js +243 -0
- package/src/tablatures/transposer.js +110 -0
- package/src/test/abc_midi_lint.js +5 -22
- package/src/test/abc_midi_sequencer_lint.js +11 -14
- package/src/test/abc_parser_lint.js +136 -32
- package/src/test/abc_vertical_lint.js +94 -32
- package/src/test/rendering-lint.js +38 -5
- package/src/write/abc_absolute_element.js +112 -120
- package/src/write/abc_abstract_engraver.js +102 -253
- package/src/write/abc_beam_element.js +30 -290
- package/src/write/abc_brace_element.js +12 -121
- package/src/write/abc_create_clef.js +21 -32
- package/src/write/abc_create_key_signature.js +8 -26
- package/src/write/abc_create_note_head.js +107 -0
- package/src/write/abc_create_time_signature.js +2 -21
- package/src/write/abc_crescendo_element.js +3 -50
- package/src/write/abc_decoration.js +7 -30
- package/src/write/abc_dynamic_decoration.js +3 -37
- package/src/write/abc_ending_element.js +1 -57
- package/src/write/abc_engraver_controller.js +111 -234
- package/src/write/abc_glyphs.js +9 -19
- package/src/write/abc_relative_element.js +57 -97
- package/src/write/abc_renderer.js +10 -832
- package/src/write/abc_spacing.js +0 -15
- package/src/write/abc_staff_group_element.js +14 -349
- package/src/write/abc_tempo_element.js +9 -117
- package/src/write/abc_tie_element.js +5 -68
- package/src/write/abc_triplet_element.js +6 -124
- package/src/write/abc_voice_element.js +7 -222
- package/src/write/add-chord.js +103 -0
- package/src/write/add-text-if.js +33 -0
- package/src/write/bottom-text.js +79 -0
- package/src/write/calcHeight.js +17 -0
- package/src/write/classes.js +100 -0
- package/src/write/draw/absolute.js +68 -0
- package/src/write/draw/beam.js +56 -0
- package/src/write/draw/brace.js +106 -0
- package/src/write/draw/crescendo.js +38 -0
- package/src/write/draw/debug-box.js +8 -0
- package/src/write/draw/draw.js +56 -0
- package/src/write/draw/dynamics.js +20 -0
- package/src/write/draw/ending.js +46 -0
- package/src/write/draw/group-elements.js +66 -0
- package/src/write/draw/horizontal-line.js +25 -0
- package/src/write/draw/non-music.js +50 -0
- package/src/write/draw/print-line.js +24 -0
- package/src/write/draw/print-path.js +7 -0
- package/src/write/draw/print-stem.js +30 -0
- package/src/write/draw/print-symbol.js +59 -0
- package/src/write/draw/print-vertical-line.js +18 -0
- package/src/write/draw/relative.js +77 -0
- package/src/write/draw/round-number.js +5 -0
- package/src/write/draw/selectables.js +59 -0
- package/src/write/draw/separator.js +16 -0
- package/src/write/draw/set-paper-size.js +45 -0
- package/src/write/{sprintf.js → draw/sprintf.js} +0 -0
- package/src/write/draw/staff-group.js +226 -0
- package/src/write/draw/staff-line.js +9 -0
- package/src/write/draw/staff.js +33 -0
- package/src/write/draw/tab-line.js +40 -0
- package/src/write/draw/tempo.js +45 -0
- package/src/write/draw/text.js +71 -0
- package/src/write/draw/tie.js +97 -0
- package/src/write/draw/triplet.js +46 -0
- package/src/write/draw/voice.js +102 -0
- package/src/write/format-jazz-chord.js +15 -0
- package/src/write/free-text.js +41 -0
- package/src/write/get-font-and-attr.js +37 -0
- package/src/write/get-text-size.js +56 -0
- package/src/write/highlight.js +11 -0
- package/src/write/layout/VoiceElements.js +121 -0
- package/src/write/layout/beam.js +213 -0
- package/src/write/layout/get-left-edge-of-staff.js +56 -0
- package/src/write/layout/getBarYAt.js +6 -0
- package/src/write/layout/layout.js +94 -0
- package/src/write/layout/setUpperAndLowerElements.js +232 -0
- package/src/write/layout/staffGroup.js +146 -0
- package/src/write/layout/triplet.js +75 -0
- package/src/write/layout/voice.js +137 -0
- package/src/write/selection.js +188 -70
- package/src/write/separator.js +10 -0
- package/src/write/set-class.js +21 -0
- package/src/write/subtitle.js +12 -0
- package/src/write/svg.js +95 -43
- package/src/write/top-text.js +54 -0
- package/src/write/unhighlight.js +11 -0
- package/temp.txt +17 -0
- package/test.js +27 -64
- package/types/index.d.ts +1095 -0
- package/version.js +1 -1
- package/.babelrc +0 -5
- package/.eslintrc +0 -3
- package/.gitmodules +0 -3
- package/abcjs-midi.css +0 -166
- package/build-utils/loadPresets.js +0 -14
- package/build-utils/presets/webpack.analyze.js +0 -6
- package/build-utils/presets/webpack.optimize.js +0 -30
- package/build-utils/webpack.development.js +0 -14
- package/build-utils/webpack.production.js +0 -35
- package/deploy-docs.sh +0 -25
- package/docs/README.md +0 -33
- package/fix-versions.sh +0 -23
- package/mei.js +0 -43
- package/midi.js +0 -62
- package/src/api/abc_tunebook_midi.js +0 -116
- package/src/midi/abc_midi_controls.js +0 -701
- package/src/midi/abc_midi_flattener.js +0 -1119
- package/src/midi/abc_midi_js_preparer.js +0 -243
- package/src/midi/abc_midi_sequencer.js +0 -401
- package/src/midi/abc_midi_ui_generator.js +0 -86
- package/src/plugin/abc_plugin_midi.js +0 -220
- package/src/synth/images/loop.svg +0 -61
- package/src/synth/images/pause.svg +0 -6
- package/src/synth/images/play.svg +0 -5
- package/src/transform/abc2abc_write.js +0 -395
- package/static-wrappers/basic.js +0 -2
- package/static-wrappers/midi.js +0 -2
- package/static-wrappers/plugin-midi.js +0 -6
- package/static-wrappers/plugin.js +0 -6
- package/webpack.config.js +0 -29
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
// abc_midi_js_preparer.js: Create the structure that MIDI.js expects.
|
|
2
|
-
// Copyright (C) 2010-2020 Gregory Dyke (gregdyke at gmail dot com) and Paul Rosen
|
|
3
|
-
//
|
|
4
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
5
|
-
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
6
|
-
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
7
|
-
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
-
//
|
|
9
|
-
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
-
//
|
|
11
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
12
|
-
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
13
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
14
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
15
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
16
|
-
|
|
17
|
-
var Preparer;
|
|
18
|
-
|
|
19
|
-
(function() {
|
|
20
|
-
"use strict";
|
|
21
|
-
|
|
22
|
-
Preparer = function() {
|
|
23
|
-
this.tempo = 0;
|
|
24
|
-
this.timeFactor = 0;
|
|
25
|
-
this.output = [];
|
|
26
|
-
this.currentChannel = 0;
|
|
27
|
-
this.currentInstrument = 0;
|
|
28
|
-
this.track = 0;
|
|
29
|
-
this.nextDuration = 0;
|
|
30
|
-
this.tracks = [ [] ];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
Preparer.prototype.setInstrument = function(instrument) {
|
|
34
|
-
this.currentInstrument = instrument;
|
|
35
|
-
|
|
36
|
-
var ev = [
|
|
37
|
-
{
|
|
38
|
-
ticksToEvent: 0,
|
|
39
|
-
track: this.track,
|
|
40
|
-
event: {
|
|
41
|
-
channel: this.currentChannel,
|
|
42
|
-
deltaTime: 0,
|
|
43
|
-
programNumber: this.currentInstrument,
|
|
44
|
-
subtype: 'programChange',
|
|
45
|
-
type: 'channel'
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
this.nextDuration * this.timeFactor
|
|
49
|
-
];
|
|
50
|
-
this.tracks[this.track].push(ev);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
Preparer.prototype.setChannel = function(channel) {
|
|
54
|
-
this.currentChannel = channel;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
Preparer.prototype.startTrack = function() {
|
|
58
|
-
this.track++;
|
|
59
|
-
this.tracks[this.track] = [];
|
|
60
|
-
this.nextDuration = 0;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
Preparer.prototype.setGlobalInfo = function(tempo, title) {
|
|
64
|
-
this.tempo = tempo;
|
|
65
|
-
var mspb = Math.round((1.0/tempo)*60000000);
|
|
66
|
-
this.timeFactor = mspb / 480000;
|
|
67
|
-
var ev = [
|
|
68
|
-
{
|
|
69
|
-
ticksToEvent: 0,
|
|
70
|
-
track: this.track,
|
|
71
|
-
event: {
|
|
72
|
-
deltaTime: 0,
|
|
73
|
-
microsecondsPerBeat: mspb,
|
|
74
|
-
subtype: 'setTempo',
|
|
75
|
-
type: 'meta'
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
this.nextDuration * this.timeFactor
|
|
79
|
-
];
|
|
80
|
-
// this.tracks[this.track].push(ev);
|
|
81
|
-
|
|
82
|
-
ev = [
|
|
83
|
-
{
|
|
84
|
-
ticksToEvent: 0,
|
|
85
|
-
track: this.track,
|
|
86
|
-
event: {
|
|
87
|
-
deltaTime: 0,
|
|
88
|
-
subtype: 'trackName',
|
|
89
|
-
text: title,
|
|
90
|
-
type: 'meta'
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
this.nextDuration * this.timeFactor
|
|
94
|
-
];
|
|
95
|
-
// this.tracks[this.track].push(ev);
|
|
96
|
-
|
|
97
|
-
ev = [
|
|
98
|
-
{
|
|
99
|
-
ticksToEvent: 0,
|
|
100
|
-
track: this.track,
|
|
101
|
-
event: {
|
|
102
|
-
deltaTime: 0,
|
|
103
|
-
subtype: 'endOfTrack',
|
|
104
|
-
type: 'meta'
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
this.nextDuration * this.timeFactor
|
|
108
|
-
];
|
|
109
|
-
// this.tracks[this.track].push(ev);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
Preparer.prototype.startNote = function(pitch, volume) {
|
|
113
|
-
var deltaTime = Math.floor(this.nextDuration / 5) * 5;
|
|
114
|
-
var ev = [
|
|
115
|
-
{
|
|
116
|
-
ticksToEvent: deltaTime,
|
|
117
|
-
track: this.track,
|
|
118
|
-
event: {
|
|
119
|
-
deltaTime: deltaTime,
|
|
120
|
-
channel: this.currentChannel,
|
|
121
|
-
type: "channel",
|
|
122
|
-
noteNumber: pitch,
|
|
123
|
-
velocity: volume,
|
|
124
|
-
subtype: "noteOn"
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
this.nextDuration * this.timeFactor
|
|
128
|
-
];
|
|
129
|
-
this.tracks[this.track].push(ev);
|
|
130
|
-
this.nextDuration = 0;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
Preparer.prototype.endNote = function(pitch) {
|
|
134
|
-
var deltaTime = Math.floor(this.nextDuration / 5) * 5;
|
|
135
|
-
var ev = [
|
|
136
|
-
{
|
|
137
|
-
ticksToEvent: deltaTime,
|
|
138
|
-
track: this.track,
|
|
139
|
-
event: {
|
|
140
|
-
deltaTime: deltaTime,
|
|
141
|
-
channel: this.currentChannel,
|
|
142
|
-
type: "channel",
|
|
143
|
-
noteNumber: pitch,
|
|
144
|
-
velocity: 0,
|
|
145
|
-
subtype: "noteOff"
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
this.nextDuration * this.timeFactor
|
|
149
|
-
];
|
|
150
|
-
this.tracks[this.track].push(ev);
|
|
151
|
-
this.nextDuration = 0;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
Preparer.prototype.addRest = function(duration) {
|
|
155
|
-
this.nextDuration += duration;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
Preparer.prototype.endTrack = function() {
|
|
159
|
-
var ev = [
|
|
160
|
-
{
|
|
161
|
-
ticksToEvent: 0,
|
|
162
|
-
track: this.track,
|
|
163
|
-
event: {
|
|
164
|
-
deltaTime: 0,
|
|
165
|
-
type: "meta",
|
|
166
|
-
subtype: "endOfTrack"
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
0
|
|
170
|
-
];
|
|
171
|
-
// this.tracks[this.track].push(ev);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
function addAbsoluteTime(tracks) {
|
|
175
|
-
for (var i = 0; i < tracks.length; i++) {
|
|
176
|
-
var absTime = 0;
|
|
177
|
-
for (var j = 0; j < tracks[i].length; j++) {
|
|
178
|
-
absTime += tracks[i][j][1];
|
|
179
|
-
tracks[i][j].absTime = absTime;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function combineTracks(tracks) {
|
|
185
|
-
var output = [];
|
|
186
|
-
for (var i = 0; i < tracks.length; i++) {
|
|
187
|
-
for (var j = 0; j < tracks[i].length; j++) {
|
|
188
|
-
output.push(tracks[i][j]);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return output;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function sortTracks(output) {
|
|
195
|
-
// First sort by time. If the time is the same, sort by channel, if the channel is the same, put the programChange first.
|
|
196
|
-
return output.sort(function(a,b) {
|
|
197
|
-
if (a.absTime > b.absTime) return 1;
|
|
198
|
-
if (a.absTime === b.absTime) {
|
|
199
|
-
if (a.length > 0 && b.length > 0 && a[0].event && b[0].event) { // I think that there will always be at least one event, but testing just in case.
|
|
200
|
-
var aChannel = a[0].event.channel;
|
|
201
|
-
var bChannel = b[0].event.channel;
|
|
202
|
-
if (aChannel > bChannel)
|
|
203
|
-
return 1;
|
|
204
|
-
else if (aChannel < bChannel)
|
|
205
|
-
return -1;
|
|
206
|
-
else {
|
|
207
|
-
var bIsPreferred = b[0].event.subtype === "programChange";
|
|
208
|
-
if (bIsPreferred)
|
|
209
|
-
return 1;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return -1;
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function adjustTime(output) {
|
|
218
|
-
var lastTime = 0;
|
|
219
|
-
for (var i = 0; i < output.length; i++) {
|
|
220
|
-
var thisTime = output[i].absTime;
|
|
221
|
-
output[i][1] = thisTime - lastTime;
|
|
222
|
-
lastTime = thisTime;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function weaveTracks(tracks) {
|
|
227
|
-
// Each track has a progression of delta times. To combine them, first assign an absolute time to each event,
|
|
228
|
-
// then make one large track of all the tracks, sort it by absolute time, then adjust the amount of time each
|
|
229
|
-
// event causes time to move. That is, the movement was figured out as the distance from the last note in the track,
|
|
230
|
-
// but now we want the distance from the last note on ANY track.
|
|
231
|
-
addAbsoluteTime(tracks);
|
|
232
|
-
var output = combineTracks(tracks);
|
|
233
|
-
output = sortTracks(output);
|
|
234
|
-
adjustTime(output);
|
|
235
|
-
return output;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
Preparer.prototype.getData = function() {
|
|
239
|
-
return weaveTracks(this.tracks);
|
|
240
|
-
};
|
|
241
|
-
})();
|
|
242
|
-
|
|
243
|
-
module.exports = Preparer;
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
// abc_midi_sequencer.js: Turn parsed abc into a linear series of events.
|
|
2
|
-
// Copyright (C) 2010-2020 Gregory Dyke (gregdyke at gmail dot com) and Paul Rosen
|
|
3
|
-
//
|
|
4
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
5
|
-
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
6
|
-
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
7
|
-
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
-
//
|
|
9
|
-
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
-
//
|
|
11
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
12
|
-
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
13
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
14
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
15
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
16
|
-
|
|
17
|
-
var sequence;
|
|
18
|
-
|
|
19
|
-
(function() {
|
|
20
|
-
"use strict";
|
|
21
|
-
|
|
22
|
-
var measureLength;
|
|
23
|
-
// The abc is provided to us line by line. It might have repeats in it. We want to re arrange the elements to
|
|
24
|
-
// be an array of voices with all the repeats embedded, and no lines. Then it is trivial to go through the events
|
|
25
|
-
// one at a time and turn it into midi.
|
|
26
|
-
|
|
27
|
-
var PERCUSSION_PROGRAM = 128;
|
|
28
|
-
|
|
29
|
-
sequence = function(abctune, options) {
|
|
30
|
-
// Global options
|
|
31
|
-
options = options || {};
|
|
32
|
-
var qpm = undefined;
|
|
33
|
-
var program = options.program || 0; // The program if there isn't a program specified.
|
|
34
|
-
var transpose = options.midiTranspose || 0;
|
|
35
|
-
var channel = options.channel || 0;
|
|
36
|
-
var channelExplicitlySet = false;
|
|
37
|
-
var drumPattern = options.drum || "";
|
|
38
|
-
var drumBars = options.drumBars || 1;
|
|
39
|
-
var drumIntro = options.drumIntro || 0;
|
|
40
|
-
var drumOn = drumPattern !== "";
|
|
41
|
-
|
|
42
|
-
// All of the above overrides need to be integers
|
|
43
|
-
program = parseInt(program, 10);
|
|
44
|
-
transpose = parseInt(transpose, 10);
|
|
45
|
-
channel = parseInt(channel, 10);
|
|
46
|
-
if (channel === 10)
|
|
47
|
-
program = PERCUSSION_PROGRAM;
|
|
48
|
-
drumPattern = drumPattern.split(" ");
|
|
49
|
-
drumBars = parseInt(drumBars, 10);
|
|
50
|
-
drumIntro = parseInt(drumIntro, 10);
|
|
51
|
-
|
|
52
|
-
var bagpipes = abctune.formatting.bagpipes; // If it is bagpipes, then the gracenotes are played on top of the main note.
|
|
53
|
-
if (bagpipes)
|
|
54
|
-
program = 71;
|
|
55
|
-
|
|
56
|
-
// %%MIDI fermatafixed
|
|
57
|
-
// %%MIDI fermataproportional
|
|
58
|
-
// %%MIDI deltaloudness n
|
|
59
|
-
// %%MIDI gracedivider b
|
|
60
|
-
// %%MIDI ratio n m
|
|
61
|
-
// %%MIDI beat a b c n
|
|
62
|
-
// %%MIDI grace a/b
|
|
63
|
-
// %%MIDI trim x/y
|
|
64
|
-
|
|
65
|
-
// %MIDI gchordon
|
|
66
|
-
// %MIDI gchordoff
|
|
67
|
-
// %%MIDI bassprog 45
|
|
68
|
-
// %%MIDI chordprog 24
|
|
69
|
-
// %%MIDI chordname name n1 n2 n3 n4 n5 n6
|
|
70
|
-
|
|
71
|
-
//%%MIDI beat ⟨int1⟩ ⟨int2⟩ ⟨int3⟩ ⟨int4⟩: controls the volumes of the notes in a measure. The first note in a bar has volume ⟨int1⟩; other ‘strong’ notes have volume ⟨int2⟩ and all the rest have volume ⟨int3⟩. These values must be in the range 0–127. The parameter ⟨int4⟩ determines which notes are ‘strong’. If the time signature is x/y, then each note is given a position number k = 0, 1, 2. . . x-1 within each bar. If k is a multiple of ⟨int4⟩, then the note is ‘strong’.
|
|
72
|
-
|
|
73
|
-
var startingMidi = [];
|
|
74
|
-
if (abctune.formatting.midi) {
|
|
75
|
-
//console.log("MIDI Formatting:", abctune.formatting.midi);
|
|
76
|
-
var globals = abctune.formatting.midi;
|
|
77
|
-
if (globals.program && globals.program.length > 0) {
|
|
78
|
-
program = globals.program[0];
|
|
79
|
-
if (globals.program.length > 1) {
|
|
80
|
-
program = globals.program[1];
|
|
81
|
-
channel = globals.program[0];
|
|
82
|
-
}
|
|
83
|
-
channelExplicitlySet = true;
|
|
84
|
-
}
|
|
85
|
-
if (globals.transpose)
|
|
86
|
-
transpose = globals.transpose[0];
|
|
87
|
-
if (globals.channel) {
|
|
88
|
-
channel = globals.channel[0];
|
|
89
|
-
channelExplicitlySet = true;
|
|
90
|
-
}
|
|
91
|
-
if (globals.drum)
|
|
92
|
-
drumPattern = globals.drum;
|
|
93
|
-
if (globals.drumbars)
|
|
94
|
-
drumBars = globals.drumbars[0];
|
|
95
|
-
if (globals.drumon)
|
|
96
|
-
drumOn = true;
|
|
97
|
-
if (channel === 10)
|
|
98
|
-
program = PERCUSSION_PROGRAM;
|
|
99
|
-
if (globals.beat)
|
|
100
|
-
startingMidi.push({ el_type: 'beat', beats: globals.beat })
|
|
101
|
-
if (globals.nobeataccents)
|
|
102
|
-
startingMidi.push({ el_type: 'beataccents', value: false });
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Specified options in abc string.
|
|
107
|
-
|
|
108
|
-
// If the tempo was passed in, use that.
|
|
109
|
-
// If the tempo is specified, use that.
|
|
110
|
-
// If there is a default, use that.
|
|
111
|
-
// Otherwise, use the default.
|
|
112
|
-
if (options.qpm)
|
|
113
|
-
qpm = parseInt(options.qpm, 10);
|
|
114
|
-
else if (abctune.metaText.tempo)
|
|
115
|
-
qpm = interpretTempo(abctune.metaText.tempo);
|
|
116
|
-
else if (options.defaultQpm)
|
|
117
|
-
qpm = options.defaultQpm;
|
|
118
|
-
else
|
|
119
|
-
qpm = 180; // The tempo if there isn't a tempo specified.
|
|
120
|
-
|
|
121
|
-
var startVoice = [];
|
|
122
|
-
if (bagpipes)
|
|
123
|
-
startVoice.push({ el_type: 'bagpipes' });
|
|
124
|
-
startVoice.push({ el_type: 'instrument', program: program });
|
|
125
|
-
if (channel)
|
|
126
|
-
startVoice.push({ el_type: 'channel', channel: channel });
|
|
127
|
-
if (transpose)
|
|
128
|
-
startVoice.push({ el_type: 'transpose', transpose: transpose });
|
|
129
|
-
startVoice.push({ el_type: 'tempo', qpm: qpm });
|
|
130
|
-
for (var ss = 0; ss < startingMidi.length;ss++)
|
|
131
|
-
startVoice.push(startingMidi[ss]);
|
|
132
|
-
|
|
133
|
-
// the relevant part of the input structure is:
|
|
134
|
-
// abctune
|
|
135
|
-
// array lines
|
|
136
|
-
// array staff
|
|
137
|
-
// object key
|
|
138
|
-
// object meter
|
|
139
|
-
// array voices
|
|
140
|
-
// array abcelem
|
|
141
|
-
|
|
142
|
-
// visit each voice completely in turn
|
|
143
|
-
var voices = [];
|
|
144
|
-
var startRepeatPlaceholder = []; // There is a place holder for each voice.
|
|
145
|
-
var skipEndingPlaceholder = []; // This is the place where the first ending starts.
|
|
146
|
-
var startingDrumSet = false;
|
|
147
|
-
for (var i = 0; i < abctune.lines.length; i++) {
|
|
148
|
-
// For each group of staff lines in the tune.
|
|
149
|
-
var line = abctune.lines[i];
|
|
150
|
-
if (line.staff) {
|
|
151
|
-
var staves = line.staff;
|
|
152
|
-
var voiceNumber = 0;
|
|
153
|
-
for (var j = 0; j < staves.length; j++) {
|
|
154
|
-
var staff = staves[j];
|
|
155
|
-
// For each staff line
|
|
156
|
-
for (var k = 0; k < staff.voices.length; k++) {
|
|
157
|
-
// For each voice in a staff line
|
|
158
|
-
var voice = staff.voices[k];
|
|
159
|
-
if (!voices[voiceNumber]) {
|
|
160
|
-
voices[voiceNumber] = [].concat(JSON.parse(JSON.stringify(startVoice)));
|
|
161
|
-
var voiceName = getTrackTitle(line.staffGroup, voiceNumber);
|
|
162
|
-
if (voiceName)
|
|
163
|
-
voices[voiceNumber].unshift({el_type: "name", trackName: voiceName});
|
|
164
|
-
}
|
|
165
|
-
if (staff.clef && staff.clef.type === 'perc' && !channelExplicitlySet) {
|
|
166
|
-
for (var cl = 0; cl < voices[voiceNumber].length; cl++) {
|
|
167
|
-
if (voices[voiceNumber][cl].el_type === 'instrument')
|
|
168
|
-
voices[voiceNumber][cl].program = PERCUSSION_PROGRAM;
|
|
169
|
-
}
|
|
170
|
-
} else if (staff.key) {
|
|
171
|
-
if (staff.key.root === 'HP')
|
|
172
|
-
voices[voiceNumber].push({el_type: 'key', accidentals: [{acc: 'natural', note: 'g'}, {acc: 'sharp', note: 'f'}, {acc: 'sharp', note: 'c'}]});
|
|
173
|
-
else
|
|
174
|
-
voices[voiceNumber].push({el_type: 'key', accidentals: staff.key.accidentals });
|
|
175
|
-
}
|
|
176
|
-
if (staff.meter) {
|
|
177
|
-
voices[voiceNumber].push(interpretMeter(staff.meter));
|
|
178
|
-
}
|
|
179
|
-
if (!startingDrumSet && drumOn) { // drum information is only needed once, so use the first line and track 0.
|
|
180
|
-
voices[voiceNumber].push({el_type: 'drum', params: {pattern: drumPattern, bars: drumBars, on: drumOn, intro: drumIntro}});
|
|
181
|
-
startingDrumSet = true;
|
|
182
|
-
}
|
|
183
|
-
if (staff.clef && staff.clef.transpose) {
|
|
184
|
-
staff.clef.el_type = 'clef';
|
|
185
|
-
voices[voiceNumber].push({ el_type: 'transpose', transpose: staff.clef.transpose });
|
|
186
|
-
}
|
|
187
|
-
if (abctune.formatting.midi && abctune.formatting.midi.drumoff) {
|
|
188
|
-
// If there is a drum off command right at the beginning it is put in the metaText instead of the stream,
|
|
189
|
-
// so we will just insert it here.
|
|
190
|
-
voices[voiceNumber].push({ el_type: 'bar' });
|
|
191
|
-
voices[voiceNumber].push({el_type: 'drum', params: {pattern: "", on: false }});
|
|
192
|
-
}
|
|
193
|
-
var noteEventsInBar = 0;
|
|
194
|
-
for (var v = 0; v < voice.length; v++) {
|
|
195
|
-
// For each element in a voice
|
|
196
|
-
var elem = voice[v];
|
|
197
|
-
switch (elem.el_type) {
|
|
198
|
-
case "note":
|
|
199
|
-
// regular items are just pushed.
|
|
200
|
-
if (!elem.rest || elem.rest.type !== 'spacer') {
|
|
201
|
-
if (elem.decoration) {
|
|
202
|
-
if (elem.decoration.indexOf('ppp') >= 0)
|
|
203
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [30, 20, 10, 1] });
|
|
204
|
-
else if (elem.decoration.indexOf('pp') >= 0)
|
|
205
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [45, 35, 20, 1] });
|
|
206
|
-
else if (elem.decoration.indexOf('p') >= 0)
|
|
207
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [60, 50, 35, 1] });
|
|
208
|
-
else if (elem.decoration.indexOf('mp') >= 0)
|
|
209
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [75, 65, 50, 1] });
|
|
210
|
-
else if (elem.decoration.indexOf('mf') >= 0)
|
|
211
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [90, 80, 65, 1] });
|
|
212
|
-
else if (elem.decoration.indexOf('f') >= 0)
|
|
213
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [105, 95, 80, 1] });
|
|
214
|
-
else if (elem.decoration.indexOf('ff') >= 0)
|
|
215
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [120, 110, 95, 1] });
|
|
216
|
-
else if (elem.decoration.indexOf('fff') >= 0)
|
|
217
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: [127, 125, 110, 1] });
|
|
218
|
-
}
|
|
219
|
-
voices[voiceNumber].push(elem);
|
|
220
|
-
noteEventsInBar++;
|
|
221
|
-
}
|
|
222
|
-
break;
|
|
223
|
-
case "key":
|
|
224
|
-
if (elem.root === 'HP')
|
|
225
|
-
voices[voiceNumber].push({el_type: 'key', accidentals: [{acc: 'natural', note: 'g'}, {acc: 'sharp', note: 'f'}, {acc: 'sharp', note: 'c'}]});
|
|
226
|
-
else
|
|
227
|
-
voices[voiceNumber].push({el_type: 'key', accidentals: elem.accidentals });
|
|
228
|
-
break;
|
|
229
|
-
case "meter":
|
|
230
|
-
voices[voiceNumber].push(interpretMeter(elem));
|
|
231
|
-
break;
|
|
232
|
-
case "clef": // need to keep this to catch the "transpose" element.
|
|
233
|
-
if (elem.transpose)
|
|
234
|
-
voices[voiceNumber].push({ el_type: 'transpose', transpose: elem.transpose });
|
|
235
|
-
break;
|
|
236
|
-
case "tempo":
|
|
237
|
-
qpm = interpretTempo(elem);
|
|
238
|
-
voices[voiceNumber].push({ el_type: 'tempo', qpm: qpm });
|
|
239
|
-
break;
|
|
240
|
-
case "bar":
|
|
241
|
-
if (noteEventsInBar > 0) // don't add two bars in a row.
|
|
242
|
-
voices[voiceNumber].push({ el_type: 'bar' }); // We need the bar marking to reset the accidentals.
|
|
243
|
-
noteEventsInBar = 0;
|
|
244
|
-
// figure out repeats and endings --
|
|
245
|
-
// The important part is where there is a start repeat, and end repeat, or a first ending.
|
|
246
|
-
var endRepeat = (elem.type === "bar_right_repeat" || elem.type === "bar_dbl_repeat");
|
|
247
|
-
var startEnding = (elem.startEnding === '1');
|
|
248
|
-
var startRepeat = (elem.type === "bar_left_repeat" || elem.type === "bar_dbl_repeat" || elem.type === "bar_right_repeat");
|
|
249
|
-
if (endRepeat) {
|
|
250
|
-
var s = startRepeatPlaceholder[voiceNumber];
|
|
251
|
-
if (!s) s = 0; // If there wasn't a left repeat, then we repeat from the beginning.
|
|
252
|
-
var e = skipEndingPlaceholder[voiceNumber];
|
|
253
|
-
if (!e) e = voices[voiceNumber].length; // If there wasn't a first ending marker, then we copy everything.
|
|
254
|
-
voices[voiceNumber] = voices[voiceNumber].concat(voices[voiceNumber].slice(s, e));
|
|
255
|
-
// reset these in case there is a second repeat later on.
|
|
256
|
-
skipEndingPlaceholder[voiceNumber] = undefined;
|
|
257
|
-
startRepeatPlaceholder[voiceNumber] = undefined;
|
|
258
|
-
}
|
|
259
|
-
if (startEnding)
|
|
260
|
-
skipEndingPlaceholder[voiceNumber] = voices[voiceNumber].length;
|
|
261
|
-
if (startRepeat)
|
|
262
|
-
startRepeatPlaceholder[voiceNumber] = voices[voiceNumber].length;
|
|
263
|
-
break;
|
|
264
|
-
case 'style':
|
|
265
|
-
// TODO-PER: If this is set to rhythm heads, then it should use the percussion channel.
|
|
266
|
-
break;
|
|
267
|
-
case 'part':
|
|
268
|
-
// TODO-PER: If there is a part section in the header, then this should probably affect the repeats.
|
|
269
|
-
break;
|
|
270
|
-
case 'stem':
|
|
271
|
-
case 'scale':
|
|
272
|
-
// These elements don't affect sound
|
|
273
|
-
break;
|
|
274
|
-
case 'midi':
|
|
275
|
-
//console.log("MIDI inline", elem); // TODO-PER: for debugging. Remove this.
|
|
276
|
-
var drumChange = false;
|
|
277
|
-
switch (elem.cmd) {
|
|
278
|
-
case "drumon": drumOn = true; drumChange = true; break;
|
|
279
|
-
case "drumoff": drumOn = false; drumChange = true; break;
|
|
280
|
-
case "drum": drumPattern = elem.params; drumChange = true; break;
|
|
281
|
-
case "drumbars": drumBars = elem.params[0]; drumChange = true; break;
|
|
282
|
-
case "drummap":
|
|
283
|
-
// This is handled before getting here so it can be ignored.
|
|
284
|
-
break;
|
|
285
|
-
case "program":
|
|
286
|
-
voices[voiceNumber].push({ el_type: 'instrument', program: elem.params[0] });
|
|
287
|
-
channelExplicitlySet = true;
|
|
288
|
-
break;
|
|
289
|
-
case "transpose":
|
|
290
|
-
voices[voiceNumber].push({ el_type: 'transpose', transpose: elem.params[0] });
|
|
291
|
-
break;
|
|
292
|
-
case "gchordoff":
|
|
293
|
-
voices[voiceNumber].push({ el_type: 'gchord', tacet: true });
|
|
294
|
-
break;
|
|
295
|
-
case "gchordon":
|
|
296
|
-
voices[voiceNumber].push({ el_type: 'gchord', tacet: false });
|
|
297
|
-
break;
|
|
298
|
-
case "beat":
|
|
299
|
-
voices[voiceNumber].push({ el_type: 'beat', beats: elem.params });
|
|
300
|
-
break;
|
|
301
|
-
case "nobeataccents":
|
|
302
|
-
voices[voiceNumber].push({ el_type: 'beataccents', value: false });
|
|
303
|
-
break;
|
|
304
|
-
case "beataccents":
|
|
305
|
-
voices[voiceNumber].push({ el_type: 'beataccents', value: true });
|
|
306
|
-
break;
|
|
307
|
-
case "vol":
|
|
308
|
-
voices[voiceNumber].push({ el_type: 'vol', volume: elem.params[0] });
|
|
309
|
-
break;
|
|
310
|
-
case "volinc":
|
|
311
|
-
voices[voiceNumber].push({ el_type: 'volinc', volume: elem.params[0] });
|
|
312
|
-
break;
|
|
313
|
-
default:
|
|
314
|
-
console.log("MIDI seq: midi cmd not handled: ", elem.cmd, elem);
|
|
315
|
-
}
|
|
316
|
-
if (drumChange) {
|
|
317
|
-
voices[0].push({el_type: 'drum', params: { pattern: drumPattern, bars: drumBars, intro: drumIntro, on: drumOn}});
|
|
318
|
-
startingDrumSet = true;
|
|
319
|
-
}
|
|
320
|
-
break;
|
|
321
|
-
default:
|
|
322
|
-
console.log("MIDI: element type " + elem.el_type + " not handled.");
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
voiceNumber++;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (drumIntro) {
|
|
331
|
-
var pickups = abctune.getPickupLength();
|
|
332
|
-
// add some measures of rests to the start of each track.
|
|
333
|
-
for (var vv = 0; vv < voices.length; vv++) {
|
|
334
|
-
var insertPoint = 0;
|
|
335
|
-
while (voices[vv][insertPoint].el_type !== "note" && voices[vv].length > insertPoint)
|
|
336
|
-
insertPoint++;
|
|
337
|
-
if (voices[vv].length > insertPoint) {
|
|
338
|
-
for (var w = 0; w < drumIntro; w++) {
|
|
339
|
-
// If it is the last measure of intro, subtract the pickups.
|
|
340
|
-
if (pickups === 0 || w < drumIntro-1)
|
|
341
|
-
voices[vv].splice(insertPoint, 0, {el_type: "note", rest: {type: "rest"}, duration: measureLength},
|
|
342
|
-
{ el_type: "bar" });
|
|
343
|
-
else {
|
|
344
|
-
voices[vv].splice(insertPoint, 0, {el_type: "note", rest: {type: "rest"}, duration: measureLength-pickups});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return voices;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
function getTrackTitle(staffGroup, voiceNumber) {
|
|
354
|
-
if (!staffGroup || !staffGroup.staffs)
|
|
355
|
-
return undefined;
|
|
356
|
-
for (var i = 0; i < staffGroup.staffs.length; i++) {
|
|
357
|
-
var staff = staffGroup.staffs[i];
|
|
358
|
-
for (var j = 0; j < staff.voices.length; j++) {
|
|
359
|
-
if (staff.voices[j] === voiceNumber)
|
|
360
|
-
return staffGroup.voices[staff.voices[j]].header;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function interpretTempo(element) {
|
|
366
|
-
var duration = 1/4;
|
|
367
|
-
if (element.duration) {
|
|
368
|
-
duration = element.duration[0];
|
|
369
|
-
}
|
|
370
|
-
var bpm = 60;
|
|
371
|
-
if (element.bpm) {
|
|
372
|
-
bpm = element.bpm;
|
|
373
|
-
}
|
|
374
|
-
// The tempo is defined with a beat of a 1/4 note, so we need to adjust it if the tempo is expressed with other than a quarter note.
|
|
375
|
-
// expressedDuration * expressedBeatsPerMinute / lengthOfQuarterNote = quarterNotesPerMinute
|
|
376
|
-
return duration * bpm / 0.25;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function interpretMeter(element) {
|
|
380
|
-
var meter;
|
|
381
|
-
switch (element.type) {
|
|
382
|
-
case "common_time":
|
|
383
|
-
meter = { el_type: 'meter', num: 4, den: 4 };
|
|
384
|
-
break;
|
|
385
|
-
case "cut_time":
|
|
386
|
-
meter = { el_type: 'meter', num: 2, den: 2 };
|
|
387
|
-
break;
|
|
388
|
-
case "specified":
|
|
389
|
-
// TODO-PER: only taking the first meter, so the complex meters are not handled.
|
|
390
|
-
meter = { el_type: 'meter', num: element.value[0].num, den: element.value[0].den };
|
|
391
|
-
break;
|
|
392
|
-
default:
|
|
393
|
-
// This should never happen.
|
|
394
|
-
meter = { el_type: 'meter' };
|
|
395
|
-
}
|
|
396
|
-
measureLength = meter.num/meter.den;
|
|
397
|
-
return meter;
|
|
398
|
-
}
|
|
399
|
-
})();
|
|
400
|
-
|
|
401
|
-
module.exports = sequence;
|