abcjs 6.3.0 → 6.4.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/README.md +4 -0
- package/RELEASE.md +44 -0
- package/dist/abcjs-basic-min.js +2 -2
- package/dist/abcjs-basic.js +1028 -622
- package/dist/abcjs-basic.js.map +1 -1
- package/dist/abcjs-plugin-min.js +2 -2
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/api/tune-metrics.js +18 -0
- package/src/data/abc_tune.js +13 -2
- package/src/edit/abc_editarea.js +4 -1
- package/src/parse/abc_parse.js +2 -0
- package/src/parse/abc_parse_directive.js +6 -0
- package/src/synth/abc_midi_flattener.js +40 -462
- package/src/synth/abc_midi_sequencer.js +25 -10
- package/src/synth/chord-track.js +562 -0
- package/src/synth/create-note-map.js +2 -1
- package/src/synth/create-synth.js +91 -42
- package/src/test/abc_parser_lint.js +1 -0
- package/src/write/creation/abstract-engraver.js +4 -1
- package/src/write/creation/decoration.js +3 -2
- package/src/write/creation/elements/tie-element.js +23 -0
- package/src/write/draw/draw.js +1 -1
- package/src/write/engraver-controller.js +9 -5
- package/src/write/interactive/create-analysis.js +50 -0
- package/src/write/interactive/find-selectable-element.js +24 -0
- package/src/write/interactive/selection.js +5 -45
- package/src/write/layout/layout-in-grid.js +83 -0
- package/src/write/layout/layout.js +29 -24
- package/src/write/layout/set-upper-and-lower-elements.js +2 -0
- package/src/write/layout/staff-group.js +2 -2
- package/src/write/layout/voice-elements.js +1 -1
- package/src/write/layout/voice.js +1 -1
- package/src/write/renderer.js +3 -0
- package/temp.txt +1 -48
- package/types/index.d.ts +96 -32
- package/version.js +1 -1
- package/abc2xml_239/abc2xml.html +0 -769
- package/abc2xml_239/abc2xml.py +0 -2248
- package/abc2xml_239/abc2xml_changelog.html +0 -124
- package/abc2xml_239/lazy-river.abc +0 -26
- package/abc2xml_239/lazy-river.xml +0 -3698
- package/abc2xml_239/mean-to-me.abc +0 -22
- package/abc2xml_239/mean-to-me.xml +0 -2954
- package/abc2xml_239/pyparsing.py +0 -3672
- package/abc2xml_239/pyparsing.pyc +0 -0
|
@@ -28,6 +28,7 @@ var parseCommon = require("../parse/abc_common");
|
|
|
28
28
|
var drumBars = options.drumBars || 1;
|
|
29
29
|
var drumIntro = options.drumIntro || 0;
|
|
30
30
|
var drumOn = drumPattern !== "";
|
|
31
|
+
var drumOffAfterIntro = !!options.drumOff
|
|
31
32
|
var style = []; // The note head style for each voice.
|
|
32
33
|
var rhythmHeadThisBar = false; // Rhythm notation was detected.
|
|
33
34
|
var crescendoSize = 50; // how much to increase or decrease volume when crescendo/diminuendo is encountered.
|
|
@@ -368,10 +369,10 @@ var parseCommon = require("../parse/abc_common");
|
|
|
368
369
|
voices[voiceNumber].push({ el_type: 'transpose', transpose: elem.params[0] });
|
|
369
370
|
break;
|
|
370
371
|
case "gchordoff":
|
|
371
|
-
voices[voiceNumber].push({ el_type: '
|
|
372
|
+
voices[voiceNumber].push({ el_type: 'gchordOn', tacet: true });
|
|
372
373
|
break;
|
|
373
374
|
case "gchordon":
|
|
374
|
-
voices[voiceNumber].push({ el_type: '
|
|
375
|
+
voices[voiceNumber].push({ el_type: 'gchordOn', tacet: false });
|
|
375
376
|
break;
|
|
376
377
|
case "beat":
|
|
377
378
|
voices[voiceNumber].push({ el_type: 'beat', beats: elem.params });
|
|
@@ -383,10 +384,16 @@ var parseCommon = require("../parse/abc_common");
|
|
|
383
384
|
voices[voiceNumber].push({ el_type: 'beataccents', value: true });
|
|
384
385
|
break;
|
|
385
386
|
case "vol":
|
|
386
|
-
voices[voiceNumber].push({ el_type: 'vol', volume: elem.params[0] });
|
|
387
|
-
break;
|
|
388
387
|
case "volinc":
|
|
389
|
-
voices[voiceNumber].push({ el_type:
|
|
388
|
+
voices[voiceNumber].push({ el_type: elem.cmd, volume: elem.params[0] });
|
|
389
|
+
break;
|
|
390
|
+
case "swing":
|
|
391
|
+
case "gchord":
|
|
392
|
+
case "bassprog":
|
|
393
|
+
case "chordprog":
|
|
394
|
+
case "bassvol":
|
|
395
|
+
case "chordvol":
|
|
396
|
+
voices[voiceNumber].push({ el_type: elem.cmd, param: elem.params[0] });
|
|
390
397
|
break;
|
|
391
398
|
default:
|
|
392
399
|
console.log("MIDI seq: midi cmd not handled: ", elem.cmd, elem);
|
|
@@ -494,13 +501,21 @@ var parseCommon = require("../parse/abc_common");
|
|
|
494
501
|
if (voices[vv].length > insertPoint) {
|
|
495
502
|
for (var w = 0; w < drumIntro; w++) {
|
|
496
503
|
// If it is the last measure of intro, subtract the pickups.
|
|
497
|
-
if (pickups === 0 || w < drumIntro-1)
|
|
498
|
-
voices[vv].splice(insertPoint, 0,
|
|
499
|
-
{
|
|
500
|
-
|
|
501
|
-
|
|
504
|
+
if (pickups === 0 || w < drumIntro-1) {
|
|
505
|
+
voices[vv].splice(insertPoint, 0,
|
|
506
|
+
{el_type: "note", rest: {type: "rest"}, duration: measureLength},
|
|
507
|
+
{ el_type: "bar" }
|
|
508
|
+
);
|
|
509
|
+
insertPoint += 2
|
|
510
|
+
} else {
|
|
511
|
+
voices[vv].splice(insertPoint++, 0, {el_type: "note", rest: {type: "rest"}, duration: measureLength-pickups});
|
|
502
512
|
}
|
|
503
513
|
}
|
|
514
|
+
if (drumOffAfterIntro) {
|
|
515
|
+
drumOn = false
|
|
516
|
+
voices[vv].splice(insertPoint++, 0, {el_type: 'drum', params: { pattern: drumPattern, bars: drumBars, intro: drumIntro, on: drumOn}});
|
|
517
|
+
drumOffAfterIntro = false
|
|
518
|
+
}
|
|
504
519
|
}
|
|
505
520
|
}
|
|
506
521
|
}
|
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
//
|
|
2
|
+
// The algorithm for chords is:
|
|
3
|
+
// - The chords are done in a separate track.
|
|
4
|
+
// - If there are notes before the first chord, then put that much silence to start the track.
|
|
5
|
+
// - The pattern of chord expression depends on the meter, and how many chords are in a measure.
|
|
6
|
+
// - There is a possibility that a measure will have an incorrect number of beats, if that is the case, then
|
|
7
|
+
// start the pattern anew on the next measure number.
|
|
8
|
+
// - If a chord root is not A-G, then ignore it as if the chord wasn't there at all.
|
|
9
|
+
// - If a chord modification isn't in our supported list, change it to a major triad.
|
|
10
|
+
//
|
|
11
|
+
// - There is a standard pattern of boom-chick for each time sig, or it can be overridden.
|
|
12
|
+
// - For any unrecognized meter, play the full chord on each beat.
|
|
13
|
+
//
|
|
14
|
+
// - If there is a chord specified that is not on a beat, move it earlier to the previous beat, unless there is already a chord on that beat.
|
|
15
|
+
// - Otherwise, move it later, unless there is already a chord on that beat.
|
|
16
|
+
// - Otherwise, ignore it. (TODO-PER: expand this as more support is added.)
|
|
17
|
+
//
|
|
18
|
+
// If there is any note in the melody that has a rhythm head, then assume the melody controls the rhythm, so there is no chord added for that entire measure.
|
|
19
|
+
|
|
20
|
+
var parseCommon = require("../parse/abc_common");
|
|
21
|
+
|
|
22
|
+
var ChordTrack = function ChordTrack(numVoices, chordsOff, midiOptions, meter) {
|
|
23
|
+
this.chordTrack = [];
|
|
24
|
+
this.chordTrackFinished = false;
|
|
25
|
+
this.chordChannel = numVoices; // first free channel for chords
|
|
26
|
+
this.currentChords = [];
|
|
27
|
+
this.lastChord;
|
|
28
|
+
this.chordLastBar;
|
|
29
|
+
this.chordsOff = !!chordsOff
|
|
30
|
+
this.gChordTacet = this.chordsOff;
|
|
31
|
+
this.hasRhythmHead = false;
|
|
32
|
+
this.transpose = 0;
|
|
33
|
+
this.lastBarTime = 0;
|
|
34
|
+
this.meter = meter;
|
|
35
|
+
this.tempoChangeFactor = 1;
|
|
36
|
+
|
|
37
|
+
this.bassInstrument = midiOptions.bassprog && midiOptions.bassprog.length === 1 ? midiOptions.bassprog[0] : 0;
|
|
38
|
+
this.chordInstrument = midiOptions.chordprog && midiOptions.chordprog.length === 1 ? midiOptions.chordprog[0] : 0;
|
|
39
|
+
this.boomVolume = midiOptions.bassvol && midiOptions.bassvol.length === 1 ? midiOptions.bassvol[0] : 64;
|
|
40
|
+
this.chickVolume = midiOptions.chordvol && midiOptions.chordvol.length === 1 ? midiOptions.chordvol[0] : 48;
|
|
41
|
+
|
|
42
|
+
this.overridePattern = midiOptions.gchord ? parseGChord(midiOptions.gchord[0]) : undefined
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
ChordTrack.prototype.setMeter = function (meter) {
|
|
46
|
+
this.meter = meter
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
ChordTrack.prototype.setTempoChangeFactor = function (tempoChangeFactor) {
|
|
50
|
+
this.tempoChangeFactor = tempoChangeFactor
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
ChordTrack.prototype.setLastBarTime = function (lastBarTime) {
|
|
54
|
+
this.lastBarTime = lastBarTime
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
ChordTrack.prototype.setTranspose = function (transpose) {
|
|
58
|
+
this.transpose = transpose
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
ChordTrack.prototype.setRhythmHead = function (isRhythmHead, elem) {
|
|
62
|
+
this.hasRhythmHead = isRhythmHead
|
|
63
|
+
var ePitches = [];
|
|
64
|
+
if (isRhythmHead) {
|
|
65
|
+
if (this.lastChord && this.lastChord.chick) {
|
|
66
|
+
for (var i2 = 0; i2 < this.lastChord.chick.length; i2++) {
|
|
67
|
+
var note2 = parseCommon.clone(elem.pitches[0]);
|
|
68
|
+
note2.actualPitch = this.lastChord.chick[i2];
|
|
69
|
+
ePitches.push(note2);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return ePitches
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
ChordTrack.prototype.barEnd = function (element) {
|
|
77
|
+
if (this.chordTrack.length > 0 && !this.chordTrackFinished) {
|
|
78
|
+
this.resolveChords(this.lastBarTime, timeToRealTime(element.time));
|
|
79
|
+
this.currentChords = [];
|
|
80
|
+
}
|
|
81
|
+
this.chordLastBar = this.lastChord;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
ChordTrack.prototype.gChordOn = function (element) {
|
|
85
|
+
if (!this.chordsOff)
|
|
86
|
+
this.gChordTacet = element.tacet;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
ChordTrack.prototype.paramChange = function (element) {
|
|
90
|
+
switch (element.el_type) {
|
|
91
|
+
case "gchord":
|
|
92
|
+
this.overridePattern = parseGChord(element.param);
|
|
93
|
+
break;
|
|
94
|
+
case "bassprog":
|
|
95
|
+
this.bassInstrument = element.param;
|
|
96
|
+
break;
|
|
97
|
+
case "chordprog":
|
|
98
|
+
this.chordInstrument = element.param;
|
|
99
|
+
break;
|
|
100
|
+
case "bassvol":
|
|
101
|
+
this.boomVolume = element.param;
|
|
102
|
+
break;
|
|
103
|
+
case "chordvol":
|
|
104
|
+
this.chickVolume = element.param;
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
console.log("unhandled midi param", element)
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
ChordTrack.prototype.finish = function () {
|
|
112
|
+
if (!this.chordTrackEmpty()) // Don't do chords on more than one track, so turn off chord detection after we create it.
|
|
113
|
+
this.chordTrackFinished = true;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
ChordTrack.prototype.addTrack = function (tracks) {
|
|
117
|
+
if (!this.chordTrackEmpty())
|
|
118
|
+
tracks.push(this.chordTrack);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
ChordTrack.prototype.findChord = function (elem) {
|
|
122
|
+
if (this.gChordTacet)
|
|
123
|
+
return 'break';
|
|
124
|
+
|
|
125
|
+
// TODO-PER: Just using the first chord if there are more than one.
|
|
126
|
+
if (this.chordTrackFinished || !elem.chord || elem.chord.length === 0)
|
|
127
|
+
return null;
|
|
128
|
+
|
|
129
|
+
// Return the first annotation that is a regular chord: that is, it is in the default place or is a recognized "tacet" phrase.
|
|
130
|
+
for (var i = 0; i < elem.chord.length; i++) {
|
|
131
|
+
var ch = elem.chord[i];
|
|
132
|
+
if (ch.position === 'default')
|
|
133
|
+
return ch.name;
|
|
134
|
+
if (this.breakSynonyms.indexOf(ch.name.toLowerCase()) >= 0)
|
|
135
|
+
return 'break';
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ChordTrack.prototype.interpretChord = function (name) {
|
|
141
|
+
// chords have the format:
|
|
142
|
+
// [root][acc][modifier][/][bass][acc]
|
|
143
|
+
// (The chord might be surrounded by parens. Just ignore them.)
|
|
144
|
+
// root must be present and must be from A-G.
|
|
145
|
+
// acc is optional and can be # or b
|
|
146
|
+
// The modifier can be a wide variety of things, like "maj7". As they are discovered, more are supported here.
|
|
147
|
+
// If there is a slash, then there is a bass note, which can be from A-G, with an optional acc.
|
|
148
|
+
// If the root is unrecognized, then "undefined" is returned and there is no chord.
|
|
149
|
+
// If the modifier is unrecognized, a major triad is returned.
|
|
150
|
+
// If the bass notes is unrecognized, it is ignored.
|
|
151
|
+
if (name.length === 0)
|
|
152
|
+
return undefined;
|
|
153
|
+
if (name === 'break')
|
|
154
|
+
return { chick: [] };
|
|
155
|
+
var root = name.substring(0, 1);
|
|
156
|
+
if (root === '(') {
|
|
157
|
+
name = name.substring(1, name.length - 2);
|
|
158
|
+
if (name.length === 0)
|
|
159
|
+
return undefined;
|
|
160
|
+
root = name.substring(0, 1);
|
|
161
|
+
}
|
|
162
|
+
var bass = this.basses[root];
|
|
163
|
+
if (!bass) // If the bass note isn't listed, then this was an unknown root. Only A-G are accepted.
|
|
164
|
+
return undefined;
|
|
165
|
+
// Don't transpose the chords more than an octave.
|
|
166
|
+
var chordTranspose = this.transpose;
|
|
167
|
+
while (chordTranspose < -8)
|
|
168
|
+
chordTranspose += 12;
|
|
169
|
+
while (chordTranspose > 8)
|
|
170
|
+
chordTranspose -= 12;
|
|
171
|
+
bass += chordTranspose;
|
|
172
|
+
var bass2 = bass - 5; // The alternating bass is a 4th below
|
|
173
|
+
var chick;
|
|
174
|
+
if (name.length === 1)
|
|
175
|
+
chick = this.chordNotes(bass, '');
|
|
176
|
+
var remaining = name.substring(1);
|
|
177
|
+
var acc = remaining.substring(0, 1);
|
|
178
|
+
if (acc === 'b' || acc === '♭') {
|
|
179
|
+
bass--;
|
|
180
|
+
bass2--;
|
|
181
|
+
remaining = remaining.substring(1);
|
|
182
|
+
} else if (acc === '#' || acc === '♯') {
|
|
183
|
+
bass++;
|
|
184
|
+
bass2++;
|
|
185
|
+
remaining = remaining.substring(1);
|
|
186
|
+
}
|
|
187
|
+
var arr = remaining.split('/');
|
|
188
|
+
chick = this.chordNotes(bass, arr[0]);
|
|
189
|
+
// If the 5th is altered then the bass is altered. Normally the bass is 7 from the root, so adjust if it isn't.
|
|
190
|
+
if (chick.length >= 3) {
|
|
191
|
+
var fifth = chick[2] - chick[0];
|
|
192
|
+
bass2 = bass2 + fifth - 7;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (arr.length === 2) {
|
|
196
|
+
var explicitBass = this.basses[arr[1].substring(0, 1)];
|
|
197
|
+
if (explicitBass) {
|
|
198
|
+
var bassAcc = arr[1].substring(1);
|
|
199
|
+
var bassShift = { '#': 1, '♯': 1, 'b': -1, '♭': -1 }[bassAcc] || 0;
|
|
200
|
+
bass = this.basses[arr[1].substring(0, 1)] + bassShift + chordTranspose;
|
|
201
|
+
bass2 = bass;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { boom: bass, boom2: bass2, chick: chick };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
ChordTrack.prototype.chordNotes = function (bass, modifier) {
|
|
208
|
+
var intervals = this.chordIntervals[modifier];
|
|
209
|
+
if (!intervals) {
|
|
210
|
+
if (modifier.slice(0, 2).toLowerCase() === 'ma' || modifier[0] === 'M')
|
|
211
|
+
intervals = this.chordIntervals.M;
|
|
212
|
+
else if (modifier[0] === 'm' || modifier[0] === '-')
|
|
213
|
+
intervals = this.chordIntervals.m;
|
|
214
|
+
else
|
|
215
|
+
intervals = this.chordIntervals.M;
|
|
216
|
+
}
|
|
217
|
+
bass += 12; // the chord is an octave above the bass note.
|
|
218
|
+
var notes = [];
|
|
219
|
+
for (var i = 0; i < intervals.length; i++) {
|
|
220
|
+
notes.push(bass + intervals[i]);
|
|
221
|
+
}
|
|
222
|
+
return notes;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
ChordTrack.prototype.writeNote = function (note, beatLength, volume, beat, noteLength, instrument) {
|
|
226
|
+
// undefined means there is a stop time.
|
|
227
|
+
if (note !== undefined)
|
|
228
|
+
this.chordTrack.push({ cmd: 'note', pitch: note, volume: volume, start: this.lastBarTime + beat * durationRounded(beatLength, this.tempoChangeFactor), duration: durationRounded(noteLength, this.tempoChangeFactor), gap: 0, instrument: instrument });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
ChordTrack.prototype.chordTrackEmpty = function () {
|
|
232
|
+
var isEmpty = true;
|
|
233
|
+
for (var i = 0; i < this.chordTrack.length && isEmpty; i++) {
|
|
234
|
+
if (this.chordTrack[i].cmd === 'note')
|
|
235
|
+
isEmpty = false
|
|
236
|
+
}
|
|
237
|
+
return isEmpty;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
ChordTrack.prototype.resolveChords = function (startTime, endTime) {
|
|
241
|
+
// If there is a rhythm head anywhere in the measure then don't add a separate rhythm track
|
|
242
|
+
if (this.hasRhythmHead)
|
|
243
|
+
return
|
|
244
|
+
|
|
245
|
+
var num = this.meter.num;
|
|
246
|
+
var den = this.meter.den;
|
|
247
|
+
var beatLength = 1 / den;
|
|
248
|
+
var noteLength = beatLength / 2;
|
|
249
|
+
var thisMeasureLength = parseInt(num, 10) / parseInt(den, 10);
|
|
250
|
+
var portionOfAMeasure = thisMeasureLength - (endTime - startTime) / this.tempoChangeFactor;
|
|
251
|
+
if (Math.abs(portionOfAMeasure) < 0.00001)
|
|
252
|
+
portionOfAMeasure = 0;
|
|
253
|
+
|
|
254
|
+
// there wasn't a new chord this measure, so use the last chord declared.
|
|
255
|
+
// also the case where there is a chord declared in the measure, but not on its first beat.
|
|
256
|
+
if (this.currentChords.length === 0 || this.currentChords[0].beat !== 0) {
|
|
257
|
+
this.currentChords.unshift({ beat: 0, chord: this.chordLastBar });
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//console.log(this.currentChords)
|
|
261
|
+
var currentChordsExpanded = expandCurrentChords(this.currentChords, 8*num/den, beatLength)
|
|
262
|
+
//console.log(currentChordsExpanded)
|
|
263
|
+
var thisPattern = this.overridePattern ? this.overridePattern : this.rhythmPatterns[num + '/' + den]
|
|
264
|
+
if (portionOfAMeasure) {
|
|
265
|
+
thisPattern = [];
|
|
266
|
+
var beatsPresent = ((endTime - startTime) / this.tempoChangeFactor) * 8;
|
|
267
|
+
for (var p = 0; p < beatsPresent/2; p += 2) {
|
|
268
|
+
thisPattern.push("chick");
|
|
269
|
+
thisPattern.push("");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!thisPattern) {
|
|
273
|
+
thisPattern = []
|
|
274
|
+
for (var p = 0; p < (8*num/den)/2; p++) {
|
|
275
|
+
thisPattern.push('chick')
|
|
276
|
+
thisPattern.push("");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
var firstBoom = true
|
|
280
|
+
// If the pattern is overridden, it might be longer than the length of a measure. If so, then ignore the rest of it
|
|
281
|
+
var minLength = Math.min(thisPattern.length, currentChordsExpanded.length)
|
|
282
|
+
for (var p = 0; p < minLength; p++) {
|
|
283
|
+
if (p > 0 && currentChordsExpanded[p-1] && currentChordsExpanded[p] && currentChordsExpanded[p-1].boom !== currentChordsExpanded[p].boom)
|
|
284
|
+
firstBoom = true
|
|
285
|
+
var type = thisPattern[p]
|
|
286
|
+
var isBoom = type.indexOf('boom') >= 0
|
|
287
|
+
// If we changed chords at a time when we're not expecting a bass note, then add an extra bass note in.
|
|
288
|
+
var newBass = !isBoom && p !== 0 && (!currentChordsExpanded[p-1] || currentChordsExpanded[p-1].boom !== currentChordsExpanded[p].boom)
|
|
289
|
+
var pitches = resolvePitch(currentChordsExpanded[p], type, firstBoom, newBass)
|
|
290
|
+
if (isBoom)
|
|
291
|
+
firstBoom = false
|
|
292
|
+
for (var oo = 0; oo < pitches.length; oo++) {
|
|
293
|
+
this.writeNote(pitches[oo],
|
|
294
|
+
0.125,
|
|
295
|
+
isBoom || newBass ? this.boomVolume : this.chickVolume,
|
|
296
|
+
p,
|
|
297
|
+
noteLength,
|
|
298
|
+
isBoom || newBass ? this.bassInstrument : this.chordInstrument
|
|
299
|
+
)
|
|
300
|
+
if (newBass)
|
|
301
|
+
newBass = false
|
|
302
|
+
else
|
|
303
|
+
isBoom = false // only the first note in a chord is a bass note. This handles the case where bass and chord are played at the same time.
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
ChordTrack.prototype.processChord = function (elem) {
|
|
310
|
+
if (this.chordTrackFinished)
|
|
311
|
+
return
|
|
312
|
+
var chord = this.findChord(elem);
|
|
313
|
+
if (chord) {
|
|
314
|
+
var c = this.interpretChord(chord);
|
|
315
|
+
// If this isn't a recognized chord, just completely ignore it.
|
|
316
|
+
if (c) {
|
|
317
|
+
// If we ever have a chord in this voice, then we add the chord track.
|
|
318
|
+
// However, if there are chords on more than one voice, then just use the first voice.
|
|
319
|
+
if (this.chordTrack.length === 0) {
|
|
320
|
+
this.chordTrack.push({ cmd: 'program', channel: this.chordChannel, instrument: this.chordInstrument });
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
this.lastChord = c;
|
|
324
|
+
var barBeat = calcBeat(this.lastBarTime, timeToRealTime(elem.time));
|
|
325
|
+
this.currentChords.push({ chord: this.lastChord, beat: barBeat, start: timeToRealTime(elem.time) });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function resolvePitch(currentChord, type, firstBoom, newBass) {
|
|
331
|
+
var ret = []
|
|
332
|
+
if (!currentChord)
|
|
333
|
+
return ret
|
|
334
|
+
if (type.indexOf('boom') >= 0)
|
|
335
|
+
ret.push(firstBoom ? currentChord.boom : currentChord.boom2)
|
|
336
|
+
else if (newBass)
|
|
337
|
+
ret.push(currentChord.boom)
|
|
338
|
+
if (type.indexOf('chick') >= 0) {
|
|
339
|
+
for (var i = 0; i < currentChord.chick.length; i++)
|
|
340
|
+
ret.push(currentChord.chick[i])
|
|
341
|
+
}
|
|
342
|
+
switch (type) {
|
|
343
|
+
case 'DO': ret.push(currentChord.chick[0]); break;
|
|
344
|
+
case 'MI': ret.push(currentChord.chick[1]); break;
|
|
345
|
+
case 'SOL': ret.push(currentChord.chick[2]); break;
|
|
346
|
+
case 'TI': currentChord.chick.length > 3 ? ret.push(currentChord.chick[2]) : ret.push(currentChord.chick[0]+12); break;
|
|
347
|
+
case 'TOP': currentChord.chick.length > 4 ? ret.push(currentChord.chick[2]) : ret.push(currentChord.chick[1]+12); break;
|
|
348
|
+
case 'do': ret.push(currentChord.chick[0]+12); break;
|
|
349
|
+
case 'mi': ret.push(currentChord.chick[1]+12); break;
|
|
350
|
+
case 'sol': ret.push(currentChord.chick[2]+12); break;
|
|
351
|
+
case 'ti': currentChord.chick.length > 3 ? ret.push(currentChord.chick[2]+12) : ret.push(currentChord.chick[0]+24); break;
|
|
352
|
+
case 'top': currentChord.chick.length > 4 ? ret.push(currentChord.chick[2]+12) : ret.push(currentChord.chick[1]+24); break;
|
|
353
|
+
}
|
|
354
|
+
return ret
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function parseGChord(gchord) {
|
|
358
|
+
// TODO-PER: The spec is more complicated than this but for now this will not try to do anything with error cases like the wrong number of beats.
|
|
359
|
+
var pattern = []
|
|
360
|
+
for (var i = 0; i < gchord.length; i++) {
|
|
361
|
+
var ch = gchord[i]
|
|
362
|
+
switch(ch) {
|
|
363
|
+
case 'z' : pattern.push(''); break;
|
|
364
|
+
case '2' : pattern.push(''); break; // TODO-PER: This should extend the last note, but that's a small effect
|
|
365
|
+
case 'c' : pattern.push('chick'); break;
|
|
366
|
+
case 'b' : pattern.push('boom&chick'); break;
|
|
367
|
+
case 'f' : pattern.push('boom'); break;
|
|
368
|
+
case 'G' : pattern.push('DO'); break;
|
|
369
|
+
case 'H' : pattern.push('MI'); break;
|
|
370
|
+
case 'I' : pattern.push('SOL'); break;
|
|
371
|
+
case 'J' : pattern.push('TI'); break;
|
|
372
|
+
case 'K' : pattern.push('TOP'); break;
|
|
373
|
+
case 'g' : pattern.push('do'); break;
|
|
374
|
+
case 'h' : pattern.push('mi'); break;
|
|
375
|
+
case 'i' : pattern.push('sol'); break;
|
|
376
|
+
case 'j' : pattern.push('ti'); break;
|
|
377
|
+
case 'k' : pattern.push('top'); break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return pattern
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// This returns an array that has a chord for each 1/8th note position in the current measure
|
|
384
|
+
function expandCurrentChords(currentChords, num8thNotes, beatLength) {
|
|
385
|
+
beatLength = beatLength * 8 // this is expressed as a fraction, so that 0.25 is a quarter notes. We want it to be the number of 8th notes
|
|
386
|
+
var chords = []
|
|
387
|
+
if (currentChords.length === 0)
|
|
388
|
+
return chords
|
|
389
|
+
|
|
390
|
+
var currentChord = currentChords[0].chord
|
|
391
|
+
for (var i = 1; i < currentChords.length; i++) {
|
|
392
|
+
var current = currentChords[i]
|
|
393
|
+
while (chords.length < current.beat) {
|
|
394
|
+
chords.push(currentChord)
|
|
395
|
+
}
|
|
396
|
+
currentChord = current.chord
|
|
397
|
+
}
|
|
398
|
+
while (chords.length < num8thNotes)
|
|
399
|
+
chords.push(currentChord)
|
|
400
|
+
return chords
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function calcBeat(measureStart, currTime) {
|
|
404
|
+
var distanceFromStart = currTime - measureStart;
|
|
405
|
+
return distanceFromStart * 8;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
ChordTrack.prototype.breakSynonyms = ['break', '(break)', 'no chord', 'n.c.', 'tacet'];
|
|
409
|
+
|
|
410
|
+
ChordTrack.prototype.basses = {
|
|
411
|
+
'A': 33, 'B': 35, 'C': 36, 'D': 38, 'E': 40, 'F': 41, 'G': 43
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
ChordTrack.prototype.chordIntervals = {
|
|
415
|
+
// diminished (all flat 5 chords)
|
|
416
|
+
'dim': [0, 3, 6],
|
|
417
|
+
'°': [0, 3, 6],
|
|
418
|
+
'˚': [0, 3, 6],
|
|
419
|
+
|
|
420
|
+
'dim7': [0, 3, 6, 9],
|
|
421
|
+
'°7': [0, 3, 6, 9],
|
|
422
|
+
'˚7': [0, 3, 6, 9],
|
|
423
|
+
|
|
424
|
+
'ø7': [0, 3, 6, 10],
|
|
425
|
+
'm7(b5)': [0, 3, 6, 10],
|
|
426
|
+
'm7b5': [0, 3, 6, 10],
|
|
427
|
+
'm7♭5': [0, 3, 6, 10],
|
|
428
|
+
'-7(b5)': [0, 3, 6, 10],
|
|
429
|
+
'-7b5': [0, 3, 6, 10],
|
|
430
|
+
|
|
431
|
+
'7b5': [0, 4, 6, 10],
|
|
432
|
+
'7(b5)': [0, 4, 6, 10],
|
|
433
|
+
'7♭5': [0, 4, 6, 10],
|
|
434
|
+
|
|
435
|
+
'7(b9,b5)': [0, 4, 6, 10, 13],
|
|
436
|
+
'7b9,b5': [0, 4, 6, 10, 13],
|
|
437
|
+
'7(#9,b5)': [0, 4, 6, 10, 15],
|
|
438
|
+
'7#9b5': [0, 4, 6, 10, 15],
|
|
439
|
+
'maj7(b5)': [0, 4, 6, 11],
|
|
440
|
+
'maj7b5': [0, 4, 6, 11],
|
|
441
|
+
'13(b5)': [0, 4, 6, 10, 14, 21],
|
|
442
|
+
'13b5': [0, 4, 6, 10, 14, 21],
|
|
443
|
+
|
|
444
|
+
// minor (all normal 5, minor 3 chords)
|
|
445
|
+
'm': [0, 3, 7],
|
|
446
|
+
'-': [0, 3, 7],
|
|
447
|
+
'm6': [0, 3, 7, 9],
|
|
448
|
+
'-6': [0, 3, 7, 9],
|
|
449
|
+
'm7': [0, 3, 7, 10],
|
|
450
|
+
'-7': [0, 3, 7, 10],
|
|
451
|
+
|
|
452
|
+
'-(b6)': [0, 3, 7, 8],
|
|
453
|
+
'-b6': [0, 3, 7, 8],
|
|
454
|
+
'-6/9': [0, 3, 7, 9, 14],
|
|
455
|
+
'-7(b9)': [0, 3, 7, 10, 13],
|
|
456
|
+
'-7b9': [0, 3, 7, 10, 13],
|
|
457
|
+
'-maj7': [0, 3, 7, 11],
|
|
458
|
+
'-9+7': [0, 3, 7, 11, 13],
|
|
459
|
+
'-11': [0, 3, 7, 11, 14, 17],
|
|
460
|
+
'm11': [0, 3, 7, 11, 14, 17],
|
|
461
|
+
'-maj9': [0, 3, 7, 11, 14],
|
|
462
|
+
'-∆9': [0, 3, 7, 11, 14],
|
|
463
|
+
'mM9': [0, 3, 7, 11, 14],
|
|
464
|
+
|
|
465
|
+
// major (all normal 5, major 3 chords)
|
|
466
|
+
'M': [0, 4, 7],
|
|
467
|
+
'6': [0, 4, 7, 9],
|
|
468
|
+
'6/9': [0, 4, 7, 9, 14],
|
|
469
|
+
'6add9': [0, 4, 7, 9, 14],
|
|
470
|
+
'69': [0, 4, 7, 9, 14],
|
|
471
|
+
|
|
472
|
+
'7': [0, 4, 7, 10],
|
|
473
|
+
'9': [0, 4, 7, 10, 14],
|
|
474
|
+
'11': [0, 7, 10, 14, 17],
|
|
475
|
+
'13': [0, 4, 7, 10, 14, 21],
|
|
476
|
+
'7b9': [0, 4, 7, 10, 13],
|
|
477
|
+
'7♭9': [0, 4, 7, 10, 13],
|
|
478
|
+
'7(b9)': [0, 4, 7, 10, 13],
|
|
479
|
+
'7(#9)': [0, 4, 7, 10, 15],
|
|
480
|
+
'7#9': [0, 4, 7, 10, 15],
|
|
481
|
+
'(13)': [0, 4, 7, 10, 14, 21],
|
|
482
|
+
'7(9,13)': [0, 4, 7, 10, 14, 21],
|
|
483
|
+
'7(#9,b13)': [0, 4, 7, 10, 15, 20],
|
|
484
|
+
'7(#11)': [0, 4, 7, 10, 14, 18],
|
|
485
|
+
'7#11': [0, 4, 7, 10, 14, 18],
|
|
486
|
+
'7(b13)': [0, 4, 7, 10, 20],
|
|
487
|
+
'7b13': [0, 4, 7, 10, 20],
|
|
488
|
+
'9(#11)': [0, 4, 7, 10, 14, 18],
|
|
489
|
+
'9#11': [0, 4, 7, 10, 14, 18],
|
|
490
|
+
'13(#11)': [0, 4, 7, 10, 18, 21],
|
|
491
|
+
'13#11': [0, 4, 7, 10, 18, 21],
|
|
492
|
+
|
|
493
|
+
'maj7': [0, 4, 7, 11],
|
|
494
|
+
'∆7': [0, 4, 7, 11],
|
|
495
|
+
'Δ7': [0, 4, 7, 11],
|
|
496
|
+
'maj9': [0, 4, 7, 11, 14],
|
|
497
|
+
'maj7(9)': [0, 4, 7, 11, 14],
|
|
498
|
+
'maj7(11)': [0, 4, 7, 11, 17],
|
|
499
|
+
'maj7(#11)': [0, 4, 7, 11, 18],
|
|
500
|
+
'maj7(13)': [0, 4, 7, 14, 21],
|
|
501
|
+
'maj7(9,13)': [0, 4, 7, 11, 14, 21],
|
|
502
|
+
|
|
503
|
+
'7sus4': [0, 5, 7, 10],
|
|
504
|
+
'm7sus4': [0, 3, 7, 10, 17],
|
|
505
|
+
'sus4': [0, 5, 7],
|
|
506
|
+
'sus2': [0, 2, 7],
|
|
507
|
+
'7sus2': [0, 2, 7, 10],
|
|
508
|
+
'9sus4': [0, 5, 7, 10, 14],
|
|
509
|
+
'13sus4': [0, 5, 7, 10, 14, 21],
|
|
510
|
+
|
|
511
|
+
// augmented (all sharp 5 chords)
|
|
512
|
+
'aug7': [0, 4, 8, 10],
|
|
513
|
+
'+7': [0, 4, 8, 10],
|
|
514
|
+
'+': [0, 4, 8],
|
|
515
|
+
'7#5': [0, 4, 8, 10],
|
|
516
|
+
'7♯5': [0, 4, 8, 10],
|
|
517
|
+
'7+5': [0, 4, 8, 10],
|
|
518
|
+
'9#5': [0, 4, 8, 10, 14],
|
|
519
|
+
'9♯5': [0, 4, 8, 10, 14],
|
|
520
|
+
'9+5': [0, 4, 8, 10, 14],
|
|
521
|
+
'-7(#5)': [0, 3, 8, 10],
|
|
522
|
+
'-7#5': [0, 3, 8, 10],
|
|
523
|
+
'7(#5)': [0, 4, 8, 10],
|
|
524
|
+
'7(b9,#5)': [0, 4, 8, 10, 13],
|
|
525
|
+
'7b9#5': [0, 4, 8, 10, 13],
|
|
526
|
+
'maj7(#5)': [0, 4, 8, 11],
|
|
527
|
+
'maj7#5': [0, 4, 8, 11],
|
|
528
|
+
'maj7(#5,#11)': [0, 4, 8, 11, 18],
|
|
529
|
+
'maj7#5#11': [0, 4, 8, 11, 18],
|
|
530
|
+
'9(#5)': [0, 4, 8, 10, 14],
|
|
531
|
+
'13(#5)': [0, 4, 8, 10, 14, 21],
|
|
532
|
+
'13#5': [0, 4, 8, 10, 14, 21]
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
ChordTrack.prototype.rhythmPatterns = {
|
|
536
|
+
"2/2": ['boom', '', '', '', 'chick', '', '', ''],
|
|
537
|
+
"3/2": ['boom', '', '', '', 'chick', '', '', '', 'chick', '', '', ''],
|
|
538
|
+
"4/2": ['boom', '', '', '', 'chick', '', '', '', 'boom', '', '', '', 'chick', '', '', ''],
|
|
539
|
+
|
|
540
|
+
"2/4": ['boom', '', 'chick', ''],
|
|
541
|
+
"3/4": ['boom', '', 'chick', '', 'chick', ''],
|
|
542
|
+
"4/4": ['boom', '', 'chick', '', 'boom', '', 'chick', ''],
|
|
543
|
+
"5/4": ['boom', '', 'chick', '', 'chick', '', 'boom', '', 'chick', ''],
|
|
544
|
+
"6/4": ['boom', '', 'chick', '', 'boom', '', 'chick', '', 'boom', '', 'chick', ''],
|
|
545
|
+
|
|
546
|
+
"3/8": ['boom', '', 'chick'],
|
|
547
|
+
"6/8": ['boom', '', 'chick', 'boom', '', 'chick'],
|
|
548
|
+
"9/8": ['boom', '', 'chick', 'boom', '', 'chick', 'boom', '', 'chick'],
|
|
549
|
+
"12/8": ['boom', '', 'chick', 'boom', '', 'chick', 'boom', '', 'chick', 'boom', '', 'chick'],
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// TODO-PER: these are repeated in flattener. Can it be shared?
|
|
553
|
+
|
|
554
|
+
function timeToRealTime(time) {
|
|
555
|
+
return time / 1000000;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function durationRounded(duration, tempoChangeFactor) {
|
|
559
|
+
return Math.round(duration * tempoChangeFactor * 1000000) / 1000000;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
module.exports = ChordTrack;
|
|
@@ -18,13 +18,14 @@ var createNoteMap = function(sequence) {
|
|
|
18
18
|
// ev contains:
|
|
19
19
|
// {"cmd":"note","pitch":72,"volume":95,"start":0.125,"duration":0.25,"instrument":0,"gap":0}
|
|
20
20
|
// where start and duration are in whole notes, gap is in 1/1920 of a second (i.e. MIDI ticks)
|
|
21
|
+
var inst = ev.instrument !== undefined ? instrumentIndexToName[ev.instrument] : currentInstrument
|
|
21
22
|
if (ev.duration > 0) {
|
|
22
23
|
var gap = ev.gap ? ev.gap : 0;
|
|
23
24
|
var len = ev.duration;
|
|
24
25
|
gap = Math.min(gap, len * 2 / 3);
|
|
25
26
|
var obj = {
|
|
26
27
|
pitch: ev.pitch,
|
|
27
|
-
instrument:
|
|
28
|
+
instrument: inst,
|
|
28
29
|
start: Math.round((ev.start) * 1000000)/1000000,
|
|
29
30
|
end: Math.round((ev.start + len - gap) * 1000000)/1000000,
|
|
30
31
|
volume: ev.volume
|