@goplayerjuggler/abc-tools 1.0.23 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goplayerjuggler/abc-tools",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "sorting algorithm and implementation for ABC tunes; plus other tools for parsing and manipulating ABC tunes",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/incipit.js CHANGED
@@ -296,12 +296,13 @@ function getIncipit(data) {
296
296
  (currentMeter[0] === 4 &&
297
297
  currentMeter[1] === 2 &&
298
298
  unitLength.den === 8) ||
299
- (currentMeter[0] === 12 && currentMeter[1] === 8)
300
- ) {
299
+ (currentMeter[0] === 12 && currentMeter[1] === 8) ||
300
+ (currentMeter[0] >= 12 && currentMeter[0] < 16)
301
+ )
301
302
  numBars = new Fraction(3, 2);
302
- } else if (currentMeter[0] === 3 && currentMeter[1] === 4) {
303
+ else if (currentMeter[0] === 3 && [4, 8].indexOf(currentMeter[1]) >= 0)
303
304
  numBars = 3;
304
- }
305
+ else if (currentMeter[0] >= 16) numBars = 1;
305
306
  }
306
307
  abc = sanitise(abc);
307
308
  return getFirstBars(abc, numBars, withAnacrucis, false, { all: true });
@@ -176,7 +176,7 @@ function hasAnacrucis(abc) {
176
176
  */
177
177
  function toggleMeterDoubling(abc, smallMeter, largeMeter, currentMeter) {
178
178
  //if no L: header at all: add one
179
- if (!/\nL:\s*1\/8/.test(abc)) abc = abc.replace("\nK:", "\nL:1/8\nK:");
179
+ if (!/\nL:\s*1\/\d+/.test(abc)) abc = abc.replace("\nK:", "\nL:1/8\nK:");
180
180
  if (!currentMeter) currentMeter = getMeter(abc);
181
181
 
182
182
  const isSmall =
@@ -725,6 +725,30 @@ function convertStandardHornpipe(
725
725
  }
726
726
  return result;
727
727
  }
728
+
729
+ /**
730
+ * Doubles the bar length of an ABC string when the
731
+ * ABC is eligible (as determined by canDoubleBarLength()).
732
+ * @param {string} abc
733
+ * @param {string} rhythm
734
+ * @returns {string}
735
+ */
736
+ function maybeConvertStandardTune(abc, rhythm) {
737
+ if (!canDoubleBarLength(abc, { rhythm })) return abc;
738
+ switch (rhythm) {
739
+ case "reel":
740
+ return convertStandardReel(abc);
741
+ case "jig":
742
+ return convertStandardJig(abc);
743
+ case "polka":
744
+ return convertStandardPolka(abc);
745
+ case "hornpipe":
746
+ return convertStandardHornpipe(abc);
747
+ default:
748
+ return abc;
749
+ }
750
+ }
751
+
728
752
  function doubleBarLength(abc, comment = null) {
729
753
  const meter = getMeter(abc);
730
754
  if (!Array.isArray(meter) || !meter) {
@@ -1061,10 +1085,12 @@ function getFirstBars(
1061
1085
  )}`;
1062
1086
  }
1063
1087
 
1064
- function canDoubleBarLength(abc) {
1065
- const meter = getMeter(abc),
1088
+ function canDoubleBarLength(abc, info = {}) {
1089
+ const {
1090
+ meter = getMeter(abc),
1066
1091
  l = getUnitLength(abc),
1067
- rhythm = getHeaderValue(abc, "R");
1092
+ rhythm = getHeaderValue(abc, "R")
1093
+ } = info;
1068
1094
  if (
1069
1095
  !rhythm ||
1070
1096
  ["reel", "hornpipe", "jig", "polka"].indexOf(rhythm.toLowerCase()) < 0
@@ -1125,6 +1151,7 @@ module.exports = {
1125
1151
  filterHeaders,
1126
1152
  getFirstBars,
1127
1153
  hasAnacrucis,
1154
+ maybeConvertStandardTune,
1128
1155
  normaliseKey,
1129
1156
  toggleMeter_4_4_to_4_2,
1130
1157
  toggleMeter_6_8_to_12_8,