From ae58704c3b12a255e4d4f74b7ff8d090dfe483a5 Mon Sep 17 00:00:00 2001 From: Joseph VanderStel Date: Sat, 20 Jul 2024 13:05:40 -0400 Subject: [PATCH 1/3] Fix beatGroups in 6/4, 9/4, and 12/4 meters --- src/meter.ts | 9 +-------- tests/moduleTests/meter.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/meter.ts b/src/meter.ts index c7a9e3bf..dd59c04d 100644 --- a/src/meter.ts +++ b/src/meter.ts @@ -186,14 +186,7 @@ export class TimeSignature extends base.Music21Object { computeBeatGroups(): number[][] { const tempBeatGroups = []; let numBeats = this.numerator; - let beatValue = this.denominator; - if (beatValue < 8 && numBeats >= 5) { - const beatsToEighthNoteRatio = 8 / beatValue; - // hopefully beatValue is an int -- right Brian Ferneyhough? - beatValue = 8; - numBeats *= beatsToEighthNoteRatio; - } - + const beatValue = this.denominator; if (beatValue >= 8) { if ([4, 2].includes(numBeats)) { // 4/8 and 2/8 should have eighth beats tempBeatGroups.push([1, beatValue]); diff --git a/tests/moduleTests/meter.ts b/tests/moduleTests/meter.ts index 6897dce9..00020017 100644 --- a/tests/moduleTests/meter.ts +++ b/tests/moduleTests/meter.ts @@ -240,4 +240,27 @@ export default function tests() { ); assert.equal(m.beatDuration.dots, 1, 'beatDuration has dot'); }); + + test('music21.meter.TimeSignature.beatGroups', assert => { + function assertBeatGroups(meterString: string, expectedBeatGroups: number[][]) { + const m = new music21.meter.TimeSignature(meterString); + assert.deepEqual( + m.beatGroups, + expectedBeatGroups, + `${meterString} should have beat groups: ${expectedBeatGroups}`, + ); + } + assertBeatGroups('2/8', [[1, 8]]); + assertBeatGroups('3/8', [[3, 8]]); + assertBeatGroups('4/8', [[1, 8]]); + assertBeatGroups('6/8', [[3, 8], [3, 8]]); + assertBeatGroups('9/8', [[3, 8], [3, 8], [3, 8]]); + assertBeatGroups('12/8', [[3, 8], [3, 8], [3, 8], [3, 8]]); + assertBeatGroups('2/4', [[2, 8]]); + assertBeatGroups('3/4', [[2, 8]]); + assertBeatGroups('4/4', [[2, 8]]); + assertBeatGroups('6/4', [[2, 8]]); + assertBeatGroups('9/4', [[2, 8]]); + assertBeatGroups('12/4', [[2, 8]]); + }); } From 3c708677496033bbfbdbe4056d0e328d9f64e4b6 Mon Sep 17 00:00:00 2001 From: Joseph VanderStel Date: Sat, 20 Jul 2024 13:17:32 -0400 Subject: [PATCH 2/3] add more meters to test --- tests/moduleTests/meter.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/moduleTests/meter.ts b/tests/moduleTests/meter.ts index 00020017..af2b72b2 100644 --- a/tests/moduleTests/meter.ts +++ b/tests/moduleTests/meter.ts @@ -250,17 +250,28 @@ export default function tests() { `${meterString} should have beat groups: ${expectedBeatGroups}`, ); } - assertBeatGroups('2/8', [[1, 8]]); - assertBeatGroups('3/8', [[3, 8]]); - assertBeatGroups('4/8', [[1, 8]]); - assertBeatGroups('6/8', [[3, 8], [3, 8]]); - assertBeatGroups('9/8', [[3, 8], [3, 8], [3, 8]]); - assertBeatGroups('12/8', [[3, 8], [3, 8], [3, 8], [3, 8]]); + assertBeatGroups('2/2', [[1, 2]]); + assertBeatGroups('3/2', [[1, 2]]); + assertBeatGroups('4/2', [[1, 2]]); assertBeatGroups('2/4', [[2, 8]]); assertBeatGroups('3/4', [[2, 8]]); assertBeatGroups('4/4', [[2, 8]]); + assertBeatGroups('5/4', [[2, 8]]); assertBeatGroups('6/4', [[2, 8]]); assertBeatGroups('9/4', [[2, 8]]); assertBeatGroups('12/4', [[2, 8]]); + assertBeatGroups('2/8', [[1, 8]]); + assertBeatGroups('3/8', [[3, 8]]); + assertBeatGroups('4/8', [[1, 8]]); + assertBeatGroups('5/8', [[3, 8], [2, 8]]); + assertBeatGroups('6/8', [[3, 8], [3, 8]]); + assertBeatGroups('9/8', [[3, 8], [3, 8], [3, 8]]); + assertBeatGroups('12/8', [[3, 8], [3, 8], [3, 8], [3, 8]]); + assertBeatGroups('3/16', [[3, 16]]); + assertBeatGroups('4/16', [[1, 16]]); + assertBeatGroups('5/16', [[3, 16], [2, 16]]); + assertBeatGroups('6/16', [[3, 16], [3, 16]]); + assertBeatGroups('9/16', [[3, 16], [3, 16], [3, 16]]); + assertBeatGroups('12/16', [[3, 16], [3, 16], [3, 16], [3, 16]]); }); } From 66346187f10f03abb9747d210f7c819154d602ad Mon Sep 17 00:00:00 2001 From: Joseph VanderStel Date: Sat, 20 Jul 2024 13:27:09 -0400 Subject: [PATCH 3/3] test 7/* too --- tests/moduleTests/meter.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/moduleTests/meter.ts b/tests/moduleTests/meter.ts index af2b72b2..aff02641 100644 --- a/tests/moduleTests/meter.ts +++ b/tests/moduleTests/meter.ts @@ -258,6 +258,7 @@ export default function tests() { assertBeatGroups('4/4', [[2, 8]]); assertBeatGroups('5/4', [[2, 8]]); assertBeatGroups('6/4', [[2, 8]]); + assertBeatGroups('7/4', [[2, 8]]); assertBeatGroups('9/4', [[2, 8]]); assertBeatGroups('12/4', [[2, 8]]); assertBeatGroups('2/8', [[1, 8]]); @@ -265,12 +266,14 @@ export default function tests() { assertBeatGroups('4/8', [[1, 8]]); assertBeatGroups('5/8', [[3, 8], [2, 8]]); assertBeatGroups('6/8', [[3, 8], [3, 8]]); + assertBeatGroups('7/8', [[3, 8], [2, 8], [2, 8]]); assertBeatGroups('9/8', [[3, 8], [3, 8], [3, 8]]); assertBeatGroups('12/8', [[3, 8], [3, 8], [3, 8], [3, 8]]); assertBeatGroups('3/16', [[3, 16]]); assertBeatGroups('4/16', [[1, 16]]); assertBeatGroups('5/16', [[3, 16], [2, 16]]); assertBeatGroups('6/16', [[3, 16], [3, 16]]); + assertBeatGroups('7/16', [[3, 16], [2, 16], [2, 16]]); assertBeatGroups('9/16', [[3, 16], [3, 16], [3, 16]]); assertBeatGroups('12/16', [[3, 16], [3, 16], [3, 16], [3, 16]]); });