@goplayerjuggler/abc-tools 1.0.17 → 1.0.18

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.17",
3
+ "version": "1.0.18",
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": {
@@ -179,6 +179,7 @@ function toggleMeterDoubling(abc, smallMeter, largeMeter, currentMeter) {
179
179
 
180
180
  const parsed = parseAbc(abc);
181
181
  const { headerLines, barLines, musicText, bars, meter } = parsed;
182
+
182
183
  // throw if there's a change of meter or unit length in the tune
183
184
  if (barLines.find((bl) => bl.newMeter || bl.newUnitLength)) {
184
185
  throw new Error("change of meter or unit length not handled");
@@ -269,13 +270,6 @@ function toggleMeterDoubling(abc, smallMeter, largeMeter, currentMeter) {
269
270
  continue;
270
271
  }
271
272
 
272
- // If the current bar starts with a variant, keep its bar line
273
- const currentBarVariant = barStartsWithVariant.get(i);
274
- if (currentBarVariant) {
275
- barLineDecisions.set(i, { action: "keep" });
276
- continue;
277
- }
278
-
279
273
  // This is a complete bar - use its barNumber to decide
280
274
  // Without anacrucis: Remove complete bars with even barNumber (0, 2, 4, ...), keep odd ones (1, 3, 5, ...)
281
275
  // With anacrucis: the other way round!
@@ -287,6 +281,15 @@ function toggleMeterDoubling(abc, smallMeter, largeMeter, currentMeter) {
287
281
  ? barLine.barNumber % 2 !== 0
288
282
  : barLine.barNumber % 2 === 0;
289
283
  if (remove) {
284
+ // Check if current bar starts with variant
285
+ if (barStartsWithVariant.has(i)) {
286
+ const variantToken = barStartsWithVariant.get(i);
287
+ barLinesToConvert.set(variantToken.sourceIndex, {
288
+ oldLength: variantToken.sourceLength,
289
+ oldText: variantToken.token
290
+ });
291
+ }
292
+ // Also check if next bar starts with variant
290
293
  const nextBarIdx = i + 1;
291
294
  if (nextBarIdx < bars.length && barStartsWithVariant.has(nextBarIdx)) {
292
295
  const variantToken = barStartsWithVariant.get(nextBarIdx);
@@ -302,6 +305,26 @@ function toggleMeterDoubling(abc, smallMeter, largeMeter, currentMeter) {
302
305
  }
303
306
  }
304
307
 
308
+ // --- Debugging - may be helpful ----
309
+ // console.log(
310
+ // "Bar line decisions:",
311
+ // Array.from(barLineDecisions.entries()).map(([i, d]) => ({
312
+ // index: i,
313
+ // barLine: barLines[i]?.text,
314
+ // sourceIndex: barLines[i]?.sourceIndex,
315
+ // action: d.action
316
+ // }))
317
+ // );
318
+
319
+ // console.log(
320
+ // "Bar lines:",
321
+ // barLines.map((bl) => ({ text: bl.text, sourceIndex: bl.sourceIndex }))
322
+ // );
323
+ // console.log(
324
+ // "Bars starting with variants:",
325
+ // Array.from(barStartsWithVariant.entries())
326
+ // );
327
+
305
328
  // Reconstruct music
306
329
  let newMusic = "";
307
330
  let pos = 0;
@@ -383,10 +406,9 @@ function toggleMeter_4_4_to_4_2(abc, currentMeter) {
383
406
  }
384
407
 
385
408
  const defaultCommentForReelConversion =
386
- "*abc-tools: convert reel to M:4/4 & L:1/16*";
387
- const defaultCommentForHornpipeConversion =
388
- "*abc-tools: convert hornpipe to M:4/2*";
389
- const defaultCommentForJigConversion = "*abc-tools: convert jig to M:12/8*";
409
+ "*abc-tools: convert to M:4/4 & L:1/16*";
410
+ const defaultCommentForHornpipeConversion = "*abc-tools: convert to M:4/2*";
411
+ const defaultCommentForJigConversion = "*abc-tools: convert to M:12/8*";
390
412
  /**
391
413
  * Adjusts bar lengths and L, M fields - a
392
414
  * reel written in the normal way (M:4/4 L:1/8) is written
@@ -159,7 +159,7 @@ function getContour(
159
159
  avg -= 7;
160
160
  }
161
161
  else
162
- while (avg < -0.5) {
162
+ while (avg < -5) {
163
163
  sortKey.forEach((c, i) => (sortKey[i] = shiftChar(c, 1)));
164
164
  avg += 7;
165
165
  }