abcjs 6.0.2 → 6.0.3

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.
@@ -5709,7 +5709,7 @@ var ParseHeader = function ParseHeader(tokenizer, warn, multilineVars, tune, tun
5709
5709
  return [e - i + 1 + ws];
5710
5710
 
5711
5711
  case "[K:":
5712
- var result = parseKeyVoice.parseKey(line.substring(i + 3, e));
5712
+ var result = parseKeyVoice.parseKey(line.substring(i + 3, e), true);
5713
5713
  if (result.foundClef && tuneBuilder.hasBeginMusic()) tuneBuilder.appendStartingElement('clef', startChar, endChar, multilineVars.clef);
5714
5714
  if (result.foundKey && tuneBuilder.hasBeginMusic()) tuneBuilder.appendStartingElement('key', startChar, endChar, parseKeyVoice.fixKey(multilineVars.clef, multilineVars.key));
5715
5715
  return [e - i + 1 + ws];
@@ -5774,7 +5774,7 @@ var ParseHeader = function ParseHeader(tokenizer, warn, multilineVars, tune, tun
5774
5774
  return [line.length];
5775
5775
 
5776
5776
  case "K:":
5777
- var result = parseKeyVoice.parseKey(line.substring(i + 2));
5777
+ var result = parseKeyVoice.parseKey(line.substring(i + 2), tuneBuilder.hasBeginMusic());
5778
5778
  if (result.foundClef && tuneBuilder.hasBeginMusic()) tuneBuilder.appendStartingElement('clef', multilineVars.iChar + i, multilineVars.iChar + line.length, multilineVars.clef);
5779
5779
  if (result.foundKey && tuneBuilder.hasBeginMusic()) tuneBuilder.appendStartingElement('key', multilineVars.iChar + i, multilineVars.iChar + line.length, parseKeyVoice.fixKey(multilineVars.clef, multilineVars.key));
5780
5780
  return [line.length];
@@ -5863,7 +5863,7 @@ var ParseHeader = function ParseHeader(tokenizer, warn, multilineVars, tune, tun
5863
5863
  case 'K':
5864
5864
  // since the key is the last thing that can happen in the header, we can resolve the tempo now
5865
5865
  this.resolveTempo();
5866
- var result = parseKeyVoice.parseKey(line.substring(2));
5866
+ var result = parseKeyVoice.parseKey(line.substring(2), false);
5867
5867
 
5868
5868
  if (!multilineVars.is_in_header && tuneBuilder.hasBeginMusic()) {
5869
5869
  if (result.foundClef) tuneBuilder.appendStartingElement('clef', startChar, endChar, multilineVars.clef);
@@ -6487,7 +6487,7 @@ var parseKeyVoice = {};
6487
6487
  }
6488
6488
  };
6489
6489
 
6490
- parseKeyVoice.parseKey = function (str) // (and clef)
6490
+ parseKeyVoice.parseKey = function (str, isInline) // (and clef)
6491
6491
  {
6492
6492
  // returns:
6493
6493
  // { foundClef: true, foundKey: true }
@@ -6605,8 +6605,12 @@ var parseKeyVoice = {};
6605
6605
 
6606
6606
  var oldKey = parseKeyVoice.deepCopyKey(multilineVars.key); //TODO-PER: HACK! To get the local transpose to work, the transposition is done for each line. This caused the global transposition variable to be factored in twice, so, instead of rewriting that right now, I'm just subtracting one of them here.
6607
6607
 
6608
- var keyCompensate = multilineVars.globalTranspose ? -multilineVars.globalTranspose : 0;
6608
+ var keyCompensate = !isInline && multilineVars.globalTranspose ? -multilineVars.globalTranspose : 0; //console.log("parse", JSON.stringify(multilineVars), isInline)
6609
+
6610
+ var savedOrigKey;
6611
+ if (isInline) savedOrigKey = multilineVars.globalTransposeOrigKeySig;
6609
6612
  multilineVars.key = parseKeyVoice.deepCopyKey(parseKeyVoice.standardKey(key, retPitch.token, acc, keyCompensate));
6613
+ if (isInline) multilineVars.globalTransposeOrigKeySig = savedOrigKey;
6610
6614
  multilineVars.key.mode = mode;
6611
6615
 
6612
6616
  if (oldKey) {
@@ -10039,6 +10043,12 @@ var Tokenizer = function Tokenizer(lines, multilineVars) {
10039
10043
  value: parseFloat(num)
10040
10044
  };
10041
10045
 
10046
+ case 'px':
10047
+ return {
10048
+ used: used + 1,
10049
+ value: parseFloat(num)
10050
+ };
10051
+
10042
10052
  case 'cm':
10043
10053
  return {
10044
10054
  used: used + 1,
@@ -10058,17 +10068,11 @@ var Tokenizer = function Tokenizer(lines, multilineVars) {
10058
10068
  value: parseFloat(num)
10059
10069
  };
10060
10070
  }
10061
-
10062
- return {
10063
- used: 0
10064
- };
10065
10071
  };
10066
10072
 
10067
10073
  var substInChord = function substInChord(str) {
10068
- while (str.indexOf("\\n") !== -1) {
10069
- str = str.replace("\\n", "\n");
10070
- }
10071
-
10074
+ str = str.replace(/\\n/g, "\n");
10075
+ str = str.replace(/\\"/g, '"');
10072
10076
  return str;
10073
10077
  };
10074
10078
 
@@ -10084,8 +10088,10 @@ var Tokenizer = function Tokenizer(lines, multilineVars) {
10084
10088
  var matchChar = _matchChar || line.charAt(i);
10085
10089
 
10086
10090
  var pos = i + 1;
10091
+ var esc = false;
10087
10092
 
10088
- while (pos < line.length && line.charAt(pos) !== matchChar) {
10093
+ while (pos < line.length && (esc || line[pos] !== matchChar)) {
10094
+ esc = line[pos] === '\\';
10089
10095
  ++pos;
10090
10096
  }
10091
10097
 
@@ -10124,9 +10130,11 @@ module.exports = Tokenizer;
10124
10130
  /*!************************************!*\
10125
10131
  !*** ./src/parse/abc_transpose.js ***!
10126
10132
  \************************************/
10127
- /***/ (function(module) {
10133
+ /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
10128
10134
 
10129
10135
  // abc_transpose.js: Handles the automatic transposition of key signatures, chord symbols, and notes.
10136
+ var allNotes = __webpack_require__(/*! ./all-notes */ "./src/parse/all-notes.js");
10137
+
10130
10138
  var transpose = {};
10131
10139
  var keyIndex = {
10132
10140
  'C': 0,
@@ -10346,19 +10354,42 @@ var accidentals2 = {
10346
10354
  "1": "sharp",
10347
10355
  "2": "dblsharp"
10348
10356
  };
10357
+ var accidentals3 = {
10358
+ "-2": "__",
10359
+ "-1": "_",
10360
+ "0": "=",
10361
+ "1": "^",
10362
+ "2": "^^"
10363
+ };
10364
+ var count = 0;
10349
10365
 
10350
10366
  transpose.note = function (multilineVars, el) {
10351
- // the "el" that is passed in has el.accidental, and el.pitch. "pitch" is the vertical position (0=middle C)
10367
+ // the "el" that is passed in has el.name, el.accidental, and el.pitch. "pitch" is the vertical position (0=middle C)
10352
10368
  // localTranspose is the number of half steps
10353
10369
  // localTransposeVerticalMovement is the vertical distance to move.
10370
+ //console.log(count++,multilineVars.localTranspose, el)
10354
10371
  if (!multilineVars.localTranspose || multilineVars.clef.type === "perc") return;
10355
10372
  var origPitch = el.pitch;
10356
- el.pitch = el.pitch + multilineVars.localTransposeVerticalMovement;
10373
+
10374
+ if (multilineVars.localTransposeVerticalMovement) {
10375
+ el.pitch = el.pitch + multilineVars.localTransposeVerticalMovement;
10376
+
10377
+ if (el.name) {
10378
+ var actual = el.accidental ? el.name.substring(1) : el.name;
10379
+ var acc = el.accidental ? el.name[0] : '';
10380
+ var p = allNotes.pitchIndex(actual);
10381
+ el.name = acc + allNotes.noteName(p + multilineVars.localTransposeVerticalMovement);
10382
+ }
10383
+ }
10357
10384
 
10358
10385
  if (el.accidental) {
10359
10386
  var ret = accidentalChange(origPitch, el.pitch, el.accidental, multilineVars.globalTransposeOrigKeySig, multilineVars.targetKey);
10360
10387
  el.pitch = ret[0];
10361
10388
  el.accidental = accidentals2[ret[1]];
10389
+
10390
+ if (el.name) {
10391
+ el.name = accidentals3[ret[1]] + el.name.replace(/[_^=]/g, '');
10392
+ }
10362
10393
  }
10363
10394
  };
10364
10395
 
@@ -10366,6 +10397,27 @@ module.exports = transpose;
10366
10397
 
10367
10398
  /***/ }),
10368
10399
 
10400
+ /***/ "./src/parse/all-notes.js":
10401
+ /*!********************************!*\
10402
+ !*** ./src/parse/all-notes.js ***!
10403
+ \********************************/
10404
+ /***/ (function(module) {
10405
+
10406
+ var allNotes = {};
10407
+ var allPitches = ['C,,,', 'D,,,', 'E,,,', 'F,,,', 'G,,,', 'A,,,', 'B,,,', 'C,,', 'D,,', 'E,,', 'F,,', 'G,,', 'A,,', 'B,,', 'C,', 'D,', 'E,', 'F,', 'G,', 'A,', 'B,', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'c', 'd', 'e', 'f', 'g', 'a', 'b', "c'", "d'", "e'", "f'", "g'", "a'", "b'", "c''", "d''", "e''", "f''", "g''", "a''", "b''", "c'''", "d'''", "e'''", "f'''", "g'''", "a'''", "b'''"];
10408
+
10409
+ allNotes.pitchIndex = function (noteName) {
10410
+ return allPitches.indexOf(noteName);
10411
+ };
10412
+
10413
+ allNotes.noteName = function (pitchIndex) {
10414
+ return allPitches[pitchIndex];
10415
+ };
10416
+
10417
+ module.exports = allNotes;
10418
+
10419
+ /***/ }),
10420
+
10369
10421
  /***/ "./src/parse/tune-builder.js":
10370
10422
  /*!***********************************!*\
10371
10423
  !*** ./src/parse/tune-builder.js ***!
@@ -16138,8 +16190,8 @@ function placeNote(outputAudioBuffer, sampleRate, sound, startArray, volumeMulti
16138
16190
  var fnResolve;
16139
16191
 
16140
16192
  offlineCtx.oncomplete = function (e) {
16141
- if (e.renderedBuffer) {
16142
- // If the system gets overloaded then this can start failing. Just drop the note if so.
16193
+ if (e.renderedBuffer && e.renderedBuffer.getChannelData) {
16194
+ // If the system gets overloaded or there are network problems then this can start failing. Just drop the note if so.
16143
16195
  for (var i = 0; i < startArray.length; i++) {
16144
16196
  //Math.floor(startArray[i] * sound.tempoMultiplier * sampleRate)
16145
16197
  var start = startArray[i] * sound.tempoMultiplier;
@@ -19861,6 +19913,7 @@ AbstractEngraver.prototype.addSlursAndTies = function (abselem, pitchelem, noteh
19861
19913
  for (var j = 0; j < this.ties.length; j++) {
19862
19914
  if (this.ties[j].anchor1 && this.ties[j].anchor1.pitch === notehead.pitch) {
19863
19915
  this.ties[j].setEndAnchor(notehead);
19916
+ voice.setRange(this.ties[j]);
19864
19917
  this.ties.splice(j, 1);
19865
19918
  found = true;
19866
19919
  break;
@@ -19869,6 +19922,7 @@ AbstractEngraver.prototype.addSlursAndTies = function (abselem, pitchelem, noteh
19869
19922
 
19870
19923
  if (!found) {
19871
19924
  this.ties[0].setEndAnchor(notehead);
19925
+ voice.setRange(this.ties[0]);
19872
19926
  this.ties.splice(0, 1);
19873
19927
  }
19874
19928
  }
@@ -19904,6 +19958,7 @@ AbstractEngraver.prototype.addSlursAndTies = function (abselem, pitchelem, noteh
19904
19958
  if (this.slurs[slurid]) {
19905
19959
  slur = this.slurs[slurid];
19906
19960
  slur.setEndAnchor(notehead);
19961
+ voice.setRange(slur);
19907
19962
  delete this.slurs[slurid];
19908
19963
  } else {
19909
19964
  slur = new TieElem({
@@ -22663,6 +22718,17 @@ TieElem.prototype.addInternalNote = function (note) {
22663
22718
  TieElem.prototype.setEndAnchor = function (anchor2) {
22664
22719
  // console.log("end", this.anchor1 ? this.anchor1.pitch : "N/A", anchor2 ? anchor2.pitch : "N/A", this.isTie, this.isGrace);
22665
22720
  this.anchor2 = anchor2; // must have a .x and a .pitch property or be null (means ends at the end of the line)
22721
+ // we don't really have enough info to know what the vertical extent is yet and we won't until drawing. This will just give it enough
22722
+ // room on either side (we don't even know if the slur will be above yet). We need to set this so that we can make sure the voice has
22723
+ // at least enough room that the line doesn't get cut off if the tie or slur is the lowest thing.
22724
+
22725
+ if (this.anchor1) {
22726
+ this.top = Math.max(this.anchor1.pitch, this.anchor2.pitch) + 4;
22727
+ this.bottom = Math.min(this.anchor1.pitch, this.anchor2.pitch) - 4;
22728
+ } else {
22729
+ this.top = this.anchor2.pitch + 4;
22730
+ this.bottom = this.anchor2.pitch - 4;
22731
+ }
22666
22732
  }; // If we encounter a repeat sign, then we don't want to extend either a tie or a slur past it, so these are called to be a limit.
22667
22733
 
22668
22734
 
@@ -25587,7 +25653,7 @@ function formatJazzChord(chordString) {
25587
25653
  for (var i = 0; i < lines.length; i++) {
25588
25654
  var chord = lines[i]; // If the chord isn't in a recognizable format then just skip the formatting.
25589
25655
 
25590
- var reg = chord.match(/^([ABCDEFG][♯♭]?)?([^\/]+)?(\/[ABCDEFG][#b]?)?/);
25656
+ var reg = chord.match(/^([ABCDEFG][♯♭]?)?([^\/]+)?(\/[ABCDEFG][#b♯♭]?)?/);
25591
25657
  if (reg) lines[i] = (reg[1] ? reg[1] : '') + "\x03" + (reg[2] ? reg[2] : '') + "\x03" + (reg[3] ? reg[3] : '');
25592
25658
  }
25593
25659
 
@@ -28187,7 +28253,7 @@ module.exports = unhighlight;
28187
28253
  \********************/
28188
28254
  /***/ (function(module) {
28189
28255
 
28190
- var version = '6.0.2';
28256
+ var version = '6.0.3';
28191
28257
  module.exports = version;
28192
28258
 
28193
28259
  /***/ })