abcjs 6.1.7 → 6.1.9

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.
@@ -1628,6 +1628,7 @@ var Tune = function Tune() {
1628
1628
  var height = bottom - top;
1629
1629
  var voices = group.voices;
1630
1630
  for (var v = 0; v < voices.length; v++) {
1631
+ if (voices[v].staff && voices[v].staff.isTabStaff) continue;
1631
1632
  var noteFound = false;
1632
1633
  if (!voicesArr[v]) voicesArr[v] = [];
1633
1634
  if (measureNumber[v] === undefined) measureNumber[v] = 0;
@@ -2542,8 +2543,14 @@ var create;
2542
2543
  case 'program':
2543
2544
  var pan = 0;
2544
2545
  if (options.pan && options.pan.length > i) pan = options.pan[i];
2545
- midi.setChannel(event.channel, pan);
2546
- midi.setInstrument(event.instrument);
2546
+ if (event.instrument === 128) {
2547
+ // If we're using the percussion voice, change to Channel 10
2548
+ midi.setChannel(9, pan);
2549
+ midi.setInstrument(0);
2550
+ } else {
2551
+ midi.setChannel(event.channel, pan);
2552
+ midi.setInstrument(event.instrument);
2553
+ }
2547
2554
  break;
2548
2555
  case 'note':
2549
2556
  var gapLengthInBeats = event.gap * beatsPerSecond;
@@ -2787,6 +2794,7 @@ var Parse = function Parse() {
2787
2794
  type: 'treble',
2788
2795
  verticalPos: 0
2789
2796
  };
2797
+ this.octave = 0;
2790
2798
  this.next_note_duration = 0;
2791
2799
  this.start_new_line = true;
2792
2800
  this.is_in_header = true;
@@ -5949,6 +5957,28 @@ var parseKeyVoice = {};
5949
5957
  multilineVars.clef.staffscale = tokens[0].floatt;
5950
5958
  tokens.shift();
5951
5959
  break;
5960
+ case "octave":
5961
+ tokens.shift();
5962
+ if (tokens.length === 0) {
5963
+ warn("Expected = after octave", str, 0);
5964
+ return ret;
5965
+ }
5966
+ token = tokens.shift();
5967
+ if (token.token !== "=") {
5968
+ warn("Expected = after octave", str, token.start);
5969
+ break;
5970
+ }
5971
+ if (tokens.length === 0) {
5972
+ warn("Expected parameter after octave=", str, 0);
5973
+ return ret;
5974
+ }
5975
+ if (tokens[0].type !== 'number') {
5976
+ warn("Expected number after octave", str, tokens[0].start);
5977
+ break;
5978
+ }
5979
+ multilineVars.octave = tokens[0].intt;
5980
+ tokens.shift();
5981
+ break;
5952
5982
  case "style":
5953
5983
  tokens.shift();
5954
5984
  if (tokens.length === 0) {
@@ -6250,7 +6280,6 @@ var parseKeyVoice = {};
6250
6280
  addNextTokenToVoiceInfo(id, 'staffscale', 'number');
6251
6281
  break;
6252
6282
  case 'octave':
6253
- // TODO-PER: This is accepted, but not implemented, yet.
6254
6283
  addNextTokenToVoiceInfo(id, 'octave', 'number');
6255
6284
  break;
6256
6285
  case 'volume':
@@ -6955,7 +6984,7 @@ function durationOfMeasure(multilineVars) {
6955
6984
  if (!meter.value || meter.value.length === 0) return 1;
6956
6985
  return parseInt(meter.value[0].num, 10) / parseInt(meter.value[0].den, 10);
6957
6986
  }
6958
- var legalAccents = ["trill", "lowermordent", "uppermordent", "mordent", "pralltriller", "accent", "fermata", "invertedfermata", "tenuto", "0", "1", "2", "3", "4", "5", "+", "wedge", "open", "thumb", "snap", "turn", "roll", "breath", "shortphrase", "mediumphrase", "longphrase", "segno", "coda", "D.S.", "D.C.", "fine", "beambr1", "beambr2", "slide", "marcato", "upbow", "downbow", "/", "//", "///", "////", "trem1", "trem2", "trem3", "trem4", "turnx", "invertedturn", "invertedturnx", "trill(", "trill)", "arpeggio", "xstem", "mark", "umarcato", "style=normal", "style=harmonic", "style=rhythm", "style=x", "style=triangle"];
6987
+ var legalAccents = ["trill", "lowermordent", "uppermordent", "mordent", "pralltriller", "accent", "fermata", "invertedfermata", "tenuto", "0", "1", "2", "3", "4", "5", "+", "wedge", "open", "thumb", "snap", "turn", "roll", "breath", "shortphrase", "mediumphrase", "longphrase", "segno", "coda", "D.S.", "D.C.", "fine", "beambr1", "beambr2", "slide", "marcato", "upbow", "downbow", "/", "//", "///", "////", "trem1", "trem2", "trem3", "trem4", "turnx", "invertedturn", "invertedturnx", "trill(", "trill)", "arpeggio", "xstem", "mark", "umarcato", "style=normal", "style=harmonic", "style=rhythm", "style=x", "style=triangle", "D.C.alcoda", "D.C.alfine", "D.S.alcoda", "D.S.alfine", "editorial", "courtesy"];
6959
6988
  var volumeDecorations = ["p", "pp", "f", "ff", "mf", "mp", "ppp", "pppp", "fff", "ffff", "sfz"];
6960
6989
  var dynamicDecorations = ["crescendo(", "crescendo)", "diminuendo(", "diminuendo)", "glissando(", "glissando)"];
6961
6990
  var accentPseudonyms = [["<", "accent"], [">", "accent"], ["tr", "trill"], ["plus", "+"], ["emphasis", "accent"], ["^", "umarcato"], ["marcato", "umarcato"]];
@@ -7352,6 +7381,7 @@ var getCoreNote = function getCoreNote(line, index, el, canHaveBrokenRhythm) {
7352
7381
  case 'g':
7353
7382
  if (state === 'startSlur' || state === 'sharp2' || state === 'flat2' || state === 'pitch') {
7354
7383
  el.pitch = pitches[line.charAt(index)];
7384
+ el.pitch += 7 * (multilineVars.currentVoice && multilineVars.currentVoice.octave !== undefined ? multilineVars.currentVoice.octave : multilineVars.octave);
7355
7385
  el.name = line.charAt(index);
7356
7386
  if (el.accidental) el.name = accMap[el.accidental] + el.name;
7357
7387
  transpose.note(multilineVars, el);
@@ -8908,7 +8938,15 @@ transpose.keySignature = function (multilineVars, keyName, root, acc, localTrans
8908
8938
  baseKey += keyName[1];
8909
8939
  keyName = keyName.substr(2);
8910
8940
  } else keyName = keyName.substr(1);
8911
- var index = keyIndex[baseKey] + multilineVars.localTranspose;
8941
+ var thisKeyIndex = keyIndex[baseKey];
8942
+ var recognized = thisKeyIndex !== undefined;
8943
+ if (!recognized) {
8944
+ // Either the key sig is "none" or we don't recognize it. Either way we don't change it, and we assume key of C for the purposes of this calculation.
8945
+ thisKeyIndex = 0;
8946
+ baseKey = "C";
8947
+ keyName = "";
8948
+ }
8949
+ var index = thisKeyIndex + multilineVars.localTranspose;
8912
8950
  while (index < 0) {
8913
8951
  index += 12;
8914
8952
  }
@@ -8935,10 +8973,14 @@ transpose.keySignature = function (multilineVars, keyName, root, acc, localTrans
8935
8973
  }
8936
8974
  }
8937
8975
  if (multilineVars.localTranspose > 0) multilineVars.localTransposeVerticalMovement = distance + Math.floor(multilineVars.localTranspose / 12) * 7;else multilineVars.localTransposeVerticalMovement = distance + Math.ceil(multilineVars.localTranspose / 12) * 7;
8938
- return {
8976
+ if (recognized) return {
8939
8977
  accidentals: newKeySig,
8940
8978
  root: newKeyName[0],
8941
8979
  acc: newKeyName.length > 1 ? newKeyName[1] : ""
8980
+ };else return {
8981
+ accidentals: [],
8982
+ root: root,
8983
+ acc: acc
8942
8984
  };
8943
8985
  };
8944
8986
  transpose.chordName = function (multilineVars, chord) {
@@ -8990,7 +9032,7 @@ var accidentals3 = {
8990
9032
  "1": "^",
8991
9033
  "2": "^^"
8992
9034
  };
8993
- var count = 0;
9035
+ //var count = 0
8994
9036
  transpose.note = function (multilineVars, el) {
8995
9037
  // the "el" that is passed in has el.name, el.accidental, and el.pitch. "pitch" is the vertical position (0=middle C)
8996
9038
  // localTranspose is the number of half steps
@@ -12668,7 +12710,7 @@ var parseCommon = __webpack_require__(/*! ../parse/abc_common */ "./src/parse/ab
12668
12710
  (function () {
12669
12711
  "use strict";
12670
12712
 
12671
- var measureLength;
12713
+ var measureLength = 1; // This should be set by the meter, but just in case that is missing, we'll take a guess.
12672
12714
  // The abc is provided to us line by line. It might have repeats in it. We want to re arrange the elements to
12673
12715
  // be an array of voices with all the repeats embedded, and no lines. Then it is trivial to go through the events
12674
12716
  // one at a time and turn it into midi.
@@ -14589,7 +14631,19 @@ var pitchMap = {
14589
14631
  f13: "_b",
14590
14632
  n13: "=b",
14591
14633
  s13: "^b",
14592
- x13: "b"
14634
+ x13: "b",
14635
+ f14: "_c'",
14636
+ n14: "=c'",
14637
+ s14: "^c'",
14638
+ x14: "c'",
14639
+ f15: "_d'",
14640
+ n15: "=d'",
14641
+ s15: "^d'",
14642
+ x15: "d'",
14643
+ f16: "_e'",
14644
+ n16: "=e'",
14645
+ s16: "^e'",
14646
+ x16: "e'"
14593
14647
  };
14594
14648
  function pitchesToPerc(pitchObj) {
14595
14649
  var pitch = (pitchObj.accidental ? pitchObj.accidental[0] : 'x') + pitchObj.verticalPos;
@@ -15330,7 +15384,7 @@ function handleChordNotes(self, notes) {
15330
15384
  }
15331
15385
  function noteToNumber(self, note, stringNumber, secondPosition, firstSize) {
15332
15386
  var strings = self.strings;
15333
- note.checkKeyAccidentals(self.accidentals);
15387
+ note.checkKeyAccidentals(self.accidentals, self.measureAccidentals);
15334
15388
  if (secondPosition) {
15335
15389
  strings = secondPosition;
15336
15390
  }
@@ -15357,6 +15411,15 @@ function noteToNumber(self, note, stringNumber, secondPosition, firstSize) {
15357
15411
  return null;
15358
15412
  }
15359
15413
  function toNumber(self, note) {
15414
+ if (note.isAltered || note.natural) {
15415
+ var acc;
15416
+ if (note.isFlat) {
15417
+ if (note.isDouble) acc = "__";else acc = "_";
15418
+ } else if (note.isSharp) {
15419
+ if (note.isDouble) acc = "^^";else acc = "^";
15420
+ } else if (note.natural) acc = "=";
15421
+ self.measureAccidentals[note.name.toUpperCase()] = acc;
15422
+ }
15360
15423
  var num = null;
15361
15424
  var str = 0;
15362
15425
  var lowestString = self.strings[self.strings.length - 1];
@@ -15475,6 +15538,7 @@ function StringPatterns(plugin) {
15475
15538
  // override default
15476
15539
  this.highestNote = highestNote;
15477
15540
  }
15541
+ this.measureAccidentals = {};
15478
15542
  this.capo = 0;
15479
15543
  if (capo) {
15480
15544
  this.capo = capo;
@@ -15668,7 +15732,27 @@ TabNote.prototype.isLowerThan = function (note) {
15668
15732
  if (noteComparator.indexOf(thisName) < noteComparator.indexOf(noteName)) return true;
15669
15733
  return false;
15670
15734
  };
15671
- TabNote.prototype.checkKeyAccidentals = function (accidentals) {
15735
+ TabNote.prototype.checkKeyAccidentals = function (accidentals, measureAccidentals) {
15736
+ if (this.isAltered || this.natural) return;
15737
+ if (measureAccidentals[this.name.toUpperCase()]) {
15738
+ switch (measureAccidentals[this.name.toUpperCase()]) {
15739
+ case "__":
15740
+ this.acc = -2;
15741
+ return;
15742
+ case "_":
15743
+ this.acc = -1;
15744
+ return;
15745
+ case "=":
15746
+ this.acc = 0;
15747
+ return;
15748
+ case "^":
15749
+ this.acc = 1;
15750
+ return;
15751
+ case "^^":
15752
+ this.acc = 2;
15753
+ return;
15754
+ }
15755
+ }
15672
15756
  if (accidentals) {
15673
15757
  var curNote = this.name;
15674
15758
  for (var iii = 0; iii < accidentals.length; iii++) {
@@ -16008,6 +16092,8 @@ function cloneAbsolute(absSrc) {
16008
16092
  cloneObject(returned.abcelem, absSrc.abcelem);
16009
16093
  if (returned.abcelem.el_type === "note") returned.abcelem.el_type = 'tabNumber';
16010
16094
  }
16095
+ // TODO-PER: This fixes the classes because the element isn't created at the right time.
16096
+ absSrc.cloned = returned;
16011
16097
  return returned;
16012
16098
  }
16013
16099
  function cloneAbsoluteAndRelatives(absSrc, plugin) {
@@ -16199,6 +16285,7 @@ TabAbsoluteElements.prototype.build = function (plugin, staffAbsolute, tabVoice,
16199
16285
  }
16200
16286
  break;
16201
16287
  case 'bar':
16288
+ plugin.semantics.strings.measureAccidentals = {};
16202
16289
  var lastBar = false;
16203
16290
  if (ii === source.children.length - 1) {
16204
16291
  // used for final line bar drawing
@@ -16552,6 +16639,7 @@ TabRenderer.prototype.doLayout = function () {
16552
16639
  for (var ii = 0; ii < nbVoices; ii++) {
16553
16640
  var tabVoice = new VoiceElement(0, 0);
16554
16641
  var nameHeight = buildTabName(this, tabVoice) / spacing.STEP;
16642
+ nameHeight = Math.max(nameHeight, 1); // If there is no label for the tab line, then there needs to be a little padding
16555
16643
  staffGroup.staffs[this.staffIndex].top += nameHeight;
16556
16644
  staffGroup.height += nameHeight * spacing.STEP;
16557
16645
  tabVoice.staff = staffGroupInfos;
@@ -18759,7 +18847,7 @@ var stackedDecoration = function stackedDecoration(decoration, width, abselem, y
18759
18847
  }
18760
18848
  return y;
18761
18849
  }
18762
- function textDecoration(text, placement) {
18850
+ function textDecoration(text, placement, anchor) {
18763
18851
  var y = getPlacement(placement);
18764
18852
  var textFudge = 2;
18765
18853
  var textHeight = 5;
@@ -18767,7 +18855,8 @@ var stackedDecoration = function stackedDecoration(decoration, width, abselem, y
18767
18855
  abselem.addFixedX(new RelativeElement(text, width / 2, 0, y + textFudge, {
18768
18856
  type: "decoration",
18769
18857
  klass: 'ornament',
18770
- thickness: 3
18858
+ thickness: 3,
18859
+ anchor: anchor
18771
18860
  }));
18772
18861
  incrementPlacement(placement, textHeight);
18773
18862
  }
@@ -18824,11 +18913,27 @@ var stackedDecoration = function stackedDecoration(decoration, width, abselem, y
18824
18913
  case "5":
18825
18914
  case "D.C.":
18826
18915
  case "D.S.":
18827
- textDecoration(decoration[i], positioning);
18916
+ textDecoration(decoration[i], positioning, 'middle');
18917
+ hasOne = true;
18918
+ break;
18919
+ case "D.C.alcoda":
18920
+ textDecoration("D.C. al coda", positioning, 'left');
18921
+ hasOne = true;
18922
+ break;
18923
+ case "D.C.alfine":
18924
+ textDecoration("D.C. al fine", positioning, 'left');
18925
+ hasOne = true;
18926
+ break;
18927
+ case "D.S.alcoda":
18928
+ textDecoration("D.S. al coda", positioning, 'left');
18929
+ hasOne = true;
18930
+ break;
18931
+ case "D.S.alfine":
18932
+ textDecoration("D.S. al fine", positioning, 'left');
18828
18933
  hasOne = true;
18829
18934
  break;
18830
18935
  case "fine":
18831
- textDecoration("FINE", positioning);
18936
+ textDecoration("FINE", positioning, 'middle');
18832
18937
  hasOne = true;
18833
18938
  break;
18834
18939
  case "+":
@@ -19979,6 +20084,7 @@ var RelativeElement = function RelativeElement(c, dx, w, pitch, opt) {
19979
20084
  this.pitch2 = opt.pitch2;
19980
20085
  this.linewidth = opt.linewidth;
19981
20086
  this.klass = opt.klass;
20087
+ this.anchor = opt.anchor ? opt.anchor : 'middle';
19982
20088
  this.top = pitch;
19983
20089
  if (this.pitch2 !== undefined && this.pitch2 > this.top) this.top = this.pitch2;
19984
20090
  this.bottom = pitch;
@@ -21118,6 +21224,10 @@ Classes.prototype.generate = function (c) {
21118
21224
  if (!this.shouldAddClasses) return "";
21119
21225
  var ret = [];
21120
21226
  if (c && c.length > 0) ret.push(c);
21227
+ if (c === "tab-number")
21228
+ // TODO-PER-HACK! straighten out the tablature
21229
+ return ret.join(' ');
21230
+ if (c === "text instrument-name") return "abcjs-text abcjs-instrument-name";
21121
21231
  if (this.lineNumber !== null) ret.push("l" + this.lineNumber);
21122
21232
  if (this.measureNumber !== null) ret.push("m" + this.measureNumber);
21123
21233
  if (this.measureNumber !== null) ret.push("mm" + this.measureTotal()); // measureNumber is null between measures so this is still the test for measureTotal
@@ -21178,6 +21288,14 @@ function drawAbsolute(renderer, params, bartop, selectables, staffPos) {
21178
21288
  }
21179
21289
  var g = elementGroup.endGroup(klass, params.type);
21180
21290
  if (g) {
21291
+ // TODO-PER-HACK! This corrects the classes because the tablature is not being created at the right time.
21292
+ if (params.cloned) {
21293
+ params.cloned.overrideClasses = g.className.baseVal;
21294
+ }
21295
+ if (params.overrideClasses) {
21296
+ var type = g.classList && g.classList.length > 0 ? g.classList[0] + ' ' : '';
21297
+ g.setAttribute("class", type + params.overrideClasses);
21298
+ }
21181
21299
  if (isTempo) {
21182
21300
  params.startChar = params.abcelem.startChar;
21183
21301
  params.endChar = params.abcelem.endChar;
@@ -22089,7 +22207,7 @@ function drawRelativeElement(renderer, params, bartop) {
22089
22207
  text: params.c,
22090
22208
  type: 'annotationfont',
22091
22209
  klass: renderer.controller.classes.generate("annotation"),
22092
- anchor: "middle",
22210
+ anchor: params.anchor,
22093
22211
  centerVertically: true,
22094
22212
  dim: params.dim
22095
22213
  }, false);
@@ -24484,9 +24602,15 @@ function setupSelection(engraver, svgs) {
24484
24602
  }
24485
24603
  }
24486
24604
  for (var i = 0; i < svgs.length; i++) {
24487
- svgs[i].addEventListener('touchstart', mouseDown.bind(engraver));
24488
- svgs[i].addEventListener('touchmove', mouseMove.bind(engraver));
24489
- svgs[i].addEventListener('touchend', mouseUp.bind(engraver));
24605
+ svgs[i].addEventListener('touchstart', mouseDown.bind(engraver), {
24606
+ passive: true
24607
+ });
24608
+ svgs[i].addEventListener('touchmove', mouseMove.bind(engraver), {
24609
+ passive: true
24610
+ });
24611
+ svgs[i].addEventListener('touchend', mouseUp.bind(engraver), {
24612
+ passive: true
24613
+ });
24490
24614
  svgs[i].addEventListener('mousedown', mouseDown.bind(engraver));
24491
24615
  svgs[i].addEventListener('mousemove', mouseMove.bind(engraver));
24492
24616
  svgs[i].addEventListener('mouseup', mouseUp.bind(engraver));
@@ -25448,7 +25572,7 @@ module.exports = unhighlight;
25448
25572
  \********************/
25449
25573
  /***/ (function(module) {
25450
25574
 
25451
- var version = '6.1.7';
25575
+ var version = '6.1.9';
25452
25576
  module.exports = version;
25453
25577
 
25454
25578
  /***/ })