Skip to content

Commit 9d4522b

Browse files
committed
fix: off-by-one errors in playback
1 parent 18aadc1 commit 9d4522b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

internal/input/playback.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,19 @@ func AdvancePlayback(m *model.Model) {
154154
activeTrackCount++
155155
log.Printf("DEBUG_SONG: Processing active track %d, ticksLeft=%d", track, m.SongPlaybackTicksLeft[track])
156156

157-
// Decrement ticks for this track
157+
// Decrement ticks for this track if > 0
158158
if m.SongPlaybackTicksLeft[track] > 0 {
159159
m.SongPlaybackTicksLeft[track]--
160160
log.Printf("Song track %d: %d ticks remaining", track, m.SongPlaybackTicksLeft[track])
161161
}
162162

163-
// Only advance this track when its ticks reach 0
163+
// Only advance when ticks reach 0
164164
if m.SongPlaybackTicksLeft[track] > 0 {
165165
continue
166166
}
167167

168+
log.Printf("Song track %d: ticks exhausted, advancing", track)
169+
168170
// Now advance to next playable row for this track
169171
if !advanceToNextPlayableRowForTrack(m, track) {
170172
// Track finished, deactivate

internal/model/model.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,8 +2179,9 @@ func (m *Model) LoadTicksLeftForTrack(track int) {
21792179
if dtValue <= 0 {
21802180
m.SongPlaybackTicksLeft[track] = 0
21812181
} else {
2182-
// Set to dtValue - 1 because row was already emitted during initialization/advancement
2183-
m.SongPlaybackTicksLeft[track] = dtValue - 1
2182+
// Set to dtValue so the row plays for exactly DT ticks
2183+
// The playback logic will decrement on the LAST tick and then advance
2184+
m.SongPlaybackTicksLeft[track] = dtValue
21842185
}
21852186
}
21862187

0 commit comments

Comments
 (0)