Skip to content

Commit d0dc142

Browse files
committed
Fixed resume
1 parent 79ad792 commit d0dc142

2 files changed

Lines changed: 46 additions & 43 deletions

File tree

Applications/Sequencer/Sequence.cpp

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ void Sequence::Tick()
9595
// Initialize timing at this clock edge
9696
lastPulseTime = lastClockTime;
9797
currentPulse = UINT16_MAX; // next advance produces pulse 0
98-
currentStep = 0;
9998
pulseSinceStart = 0;
10099
}
101100
}
@@ -250,21 +249,22 @@ void Sequence::PlayClipForAllTracks(uint8_t clip)
250249

251250
void Sequence::Resume()
252251
{
253-
// Initialize timing if not already playing
254-
if (!playing) {
255-
playing = true;
256-
clocksTillStart = record ? 24 * 4 + 1 : 1;
257-
currentPulse = UINT16_MAX;
258-
currentStep = 0;
259-
pulseSinceStart = 0;
260-
currentRecordLayer = 0;
252+
if(CanResume() == false)
253+
{
254+
return;
261255
}
262256

257+
// Initialize timing if not already playing
258+
playing = true;
259+
currentPulse = UINT16_MAX;
260+
clocksTillStart = record ? 24 * 4 + 1 : 1; // Count-in for recording, immediate otherwise
261+
263262
// Resume only tracks that were playing before stop
264263
for (uint8_t track = 0; track < trackPlayback.size(); track++) {
265264
if (trackPlayback[track].canResume) {
266265
// Restore position from resumePosition
267266
trackPlayback[track].position = trackPlayback[track].resumePosition;
267+
trackPlayback[track].position.pulse = UINT16_MAX;
268268

269269
// Clear playback state
270270
trackPlayback[track].nextClip = 255;
@@ -1601,37 +1601,6 @@ void Sequence::ProcessTrack(uint8_t track)
16011601

16021602
SequencePosition& pos = trackPlayback[track].position;
16031603

1604-
// Advance to the pulse being processed
1605-
if (pos.pulse == UINT16_MAX) {
1606-
pos.pulse = 0;
1607-
}
1608-
else {
1609-
pos.pulse++;
1610-
if (pos.pulse >= pulsesPerStep) {
1611-
pos.pulse = 0;
1612-
pos.step++;
1613-
}
1614-
}
1615-
1616-
// Wrap step/pattern based on active pattern length
1617-
{
1618-
uint8_t clip = pos.clip;
1619-
uint8_t pattern = pos.pattern;
1620-
uint8_t patternSteps = data.patternLength;
1621-
if (ClipExists(track, clip) && pattern < GetPatternCount(track, clip)) {
1622-
if (SequencePattern* pat = GetPattern(track, clip, pattern)) {
1623-
patternSteps = pat->steps;
1624-
}
1625-
}
1626-
if (pos.step >= patternSteps) {
1627-
pos.step = 0;
1628-
pos.pattern++;
1629-
if (ClipExists(track, clip) && pos.pattern >= GetPatternCount(track, clip)) {
1630-
pos.pattern = 0;
1631-
}
1632-
}
1633-
}
1634-
16351604
// Check for queued clip change at bar boundary (currentStep == 0)
16361605
if (trackPlayback[track].nextClip != 255 && currentStep == 0) {
16371606
if (trackPlayback[track].nextClip == 254) {
@@ -1646,9 +1615,43 @@ void Sequence::ProcessTrack(uint8_t track)
16461615
trackPlayback[track].nextClip = 255;
16471616
trackPlayback[track].playing = true;
16481617
}
1618+
else
1619+
{
1620+
// Only process tracks that are currently playing
1621+
if (!trackPlayback[track].playing) return;
16491622

1650-
// Only process tracks that are currently playing
1651-
if (!trackPlayback[track].playing) return;
1623+
// Advance to the pulse being processed
1624+
if (pos.pulse == UINT16_MAX) {
1625+
pos.pulse = 0;
1626+
}
1627+
else {
1628+
pos.pulse++;
1629+
if (pos.pulse >= pulsesPerStep) {
1630+
pos.pulse = 0;
1631+
pos.step++;
1632+
}
1633+
}
1634+
1635+
// Wrap step/pattern based on active pattern length
1636+
{
1637+
uint8_t clip = pos.clip;
1638+
uint8_t pattern = pos.pattern;
1639+
uint8_t patternSteps = data.patternLength;
1640+
if (ClipExists(track, clip) && pattern < GetPatternCount(track, clip)) {
1641+
if (SequencePattern* pat = GetPattern(track, clip, pattern)) {
1642+
patternSteps = pat->steps;
1643+
}
1644+
}
1645+
if (pos.step >= patternSteps) {
1646+
pos.step = 0;
1647+
pos.pattern++;
1648+
1649+
if (ClipExists(track, clip) && pos.pattern >= GetPatternCount(track, clip)) {
1650+
pos.pattern = 0;
1651+
}
1652+
}
1653+
}
1654+
}
16521655

16531656
// 2. Fire events at current tick position
16541657
uint8_t clip = pos.clip;

Applications/Sequencer/Sequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Sequence
2626
bool clockOutput = false;
2727

2828
// Clip switching timing
29-
uint16_t barLength = 16; // Length of each bay in steps
29+
uint16_t barLength = 16; // Length of each bay in steps
3030

3131
// Internal sequencer timing (96 PPQN)
3232
uint32_t lastPulseTime = 0; // Last time the sequencer tick was processed (microseconds)

0 commit comments

Comments
 (0)