66import type { ISbDmNoteEvent , ITiming , RealTime } from "../core/ScoreBookDataModel.js" ;
77import type { ITimeParamsBase } from "../core/types/general.js" ;
88import 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 }
0 commit comments