Skip to content

Commit 0399504

Browse files
committed
Fix misplaced pulse markers in grid view mode
Signed-off-by: Mike Lischke <mike@lischke-online.de>
1 parent 474b200 commit 0399504

7 files changed

Lines changed: 36 additions & 12 deletions

File tree

src/core/serialisation/migration/ArrangementMigrator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
IArrangementSnapshot, IMeasureStep, ISubdivision, ITrackMeasureSnapshot, ITrackSnapshot
1414
} from "../../types/general.js";
1515
import { greatestCommonDivisor } from "../numeric-functions.js";
16-
import { createBeatGroups, primeFactors } from "../../utils.js";
16+
import { primeFactors } from "../../utils.js";
1717
import { tryParsePackedArrangement } from "../snapshot-packing.js";
1818
import { arrangementSnapshotVersion } from "../snapshots.js";
1919
import { BananaDrumUrlImporter, LegacyArrangement, LegacyNote, LegacyTrack } from "./BananaDrumUrlImporter.js";
@@ -253,9 +253,7 @@ export class ArrangementMigrator {
253253
beats: metrics.beatsPerBar,
254254
beatUnits: metrics.beatUnit,
255255
stepResolution: stepsPerBar,
256-
beatGroups: createBeatGroups(
257-
metrics.beatsPerBar, metrics.beatUnit, stepsPerBar,
258-
),
256+
beatGroups: metrics.beatGroups,
259257
},
260258
steps,
261259
subdivisions,

src/player/TimeCoordinator.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import type { ISbDmNoteEvent, ITiming, RealTime } from "../core/ScoreBookDataModel.js";
77
import type { ITimeParamsBase } from "../core/types/general.js";
88
import type { IRealtimeProvider } from "../ui/AnimationEngine.js";
9+
import { createBeatGroups } from "../core/utils.js";
910

1011
/**
1112
* Timing details about the score, such as how long a bar is, or how many pulses there are in a bar.
@@ -32,13 +33,24 @@ export interface IScoreMetrics {
3233
/** What note value represents one beat? (e.g. 4 for 4/4, 8 for 6/8 etc.) */
3334
beatUnit: number,
3435

35-
/** How many pulses are in a bar? */
36+
/** How many pulses are in a bar? (= beatGroups.length) */
3637
pulsesPerBar: number,
3738

3839
/** How many steps are in a bar? */
3940
stepsPerBar: number,
4041

41-
/** How many steps are in a pulse? */
42+
/**
43+
* Beat group sizes in steps, summing to {@link stepsPerBar}.
44+
* E.g. `[4, 4, 4, 4]` for 4/4 or `[3, 2, 2]` for 7/8. Irregular meters have
45+
* varying group sizes; this array captures the exact pulse boundaries.
46+
*/
47+
beatGroups: number[],
48+
49+
/**
50+
* How many steps are in a pulse, when beat groups are uniform.
51+
* For irregular meters this is the average (may be fractional);
52+
* prefer {@link beatGroups} for precise pulse-boundary work.
53+
*/
4254
stepsPerPulse: number,
4355
}
4456

@@ -143,16 +155,18 @@ export class TimeCoordinator {
143155
// And produce our actually useful values.
144156
const secondsPerStep = secondsPerPulse / stepsPerPulse;
145157
const secondsPerBar = secondsPerStep * stepsPerBar;
158+
const beatGroups = createBeatGroups(beatsPerBar, beatUnit, stepsPerBar);
146159

147160
return {
148161
realTimeLength: secondsPerBar * this.timeParams.length,
149162
secondsPerBar,
150163
secondsPerStep,
151164
bars: this.timeParams.length,
152-
pulsesPerBar: stepsPerBar / stepsPerPulse,
165+
pulsesPerBar: beatGroups.length,
153166
beatsPerBar,
154167
beatUnit,
155168
stepsPerBar,
169+
beatGroups,
156170
stepsPerPulse,
157171
};
158172
}

tests/e2e/polyrhythm-bananadrum-import.spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ test.describe("BananaDrum polyrhythm import", () => {
6262
return null;
6363
}
6464

65-
const directChildren = Array.from(row.children);
65+
const directChildren = Array.from(row.children)
66+
.filter((c) => { return !c.classList.contains("grid-beat-overlay"); });
6667

6768
return directChildren.map((child) => {
6869
const isSubdivision = child.classList.contains("subdivision");
@@ -166,7 +167,9 @@ test.describe("BananaDrum polyrhythm import", () => {
166167
return null;
167168
}
168169

169-
return Array.from(row.children).map((child) => {
170+
return Array.from(row.children)
171+
.filter((c) => { return !c.classList.contains("grid-beat-overlay"); })
172+
.map((child) => {
170173
if (child.classList.contains("subdivision")) {
171174
return {
172175
type: "subdivision",
@@ -199,7 +202,9 @@ test.describe("BananaDrum polyrhythm import", () => {
199202
return null;
200203
}
201204

202-
return Array.from(row.children).map((child) => {
205+
return Array.from(row.children)
206+
.filter((c) => { return !c.classList.contains("grid-beat-overlay"); })
207+
.map((child) => {
203208
if (child.classList.contains("subdivision")) {
204209
return {
205210
type: "subdivision",
@@ -230,7 +235,9 @@ test.describe("BananaDrum polyrhythm import", () => {
230235
return null;
231236
}
232237

233-
return Array.from(row.children).map((child) => {
238+
return Array.from(row.children)
239+
.filter((c) => { return !c.classList.contains("grid-beat-overlay"); })
240+
.map((child) => {
234241
if (child.classList.contains("subdivision")) {
235242
return {
236243
type: "subdivision",

tests/e2e/structure-checks.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ test.describe("Beija Flor I-Break: Agogô DOM structure", () => {
4040
return null;
4141
}
4242

43-
return Array.from(row.children).map((child) => {
43+
return Array.from(row.children)
44+
.filter((c) => { return !c.classList.contains("grid-beat-overlay"); })
45+
.map((child) => {
4446
if (child.classList.contains("subdivision")) {
4547
return {
4648
type: "subdivision",

tests/player/ArrangementPlayer.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ vi.mock("../../src/player/TimeCoordinator.js", () => {
5959
beatUnit: 4,
6060
pulsesPerBar: 4,
6161
stepsPerBar: 16,
62+
beatGroups: [4, 4, 4, 4],
6263
stepsPerPulse: 4,
6364
};
6465
}

tests/player/TrackPlayer.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const makeTimeCoordinator = (realTimeLength: RealTime = 4): TimeCoordinator => {
2828
bars: 1,
2929
beatsPerBar: 4,
3030
stepsPerBar: 16,
31+
beatGroups: [2, 2, 2, 2, 2, 2, 2, 2],
3132
stepsPerPulse: 2,
3233
beatUnit: 4,
3334
pulsesPerBar: 8,

tests/ui/Minimap.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ const makeScoreMetrics = (): IScoreMetrics => {
180180
beatUnit: 4,
181181
pulsesPerBar: 4,
182182
stepsPerBar: 8,
183+
beatGroups: [2, 2, 2, 2],
183184
stepsPerPulse: 2,
184185
};
185186
};

0 commit comments

Comments
 (0)