Skip to content

Commit 96b4a25

Browse files
committed
Fix possible out-of-sync between replayer pos and tracker pos
1 parent 844b088 commit 96b4a25

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/pt2_header.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "pt2_unicode.h"
1515
#include "pt2_palette.h"
1616

17-
#define PROG_VER_STR "1.43"
17+
#define PROG_VER_STR "1.44"
1818

1919
#ifdef _WIN32
2020
#define DIR_DELIMITER '\\'
@@ -210,7 +210,10 @@ enum
210210
TEXT_EDIT_HEX = 2
211211
};
212212

213-
int8_t *allocMemForAllSamples(void); // pt2_replayer.c
213+
// pt2_replayer.c
214+
int8_t *allocMemForAllSamples(void);
215+
void setReplayerPosToTrackerPos(void);
216+
// -------------------------
214217

215218
void restartSong(void);
216219
void resetSong(void);

src/pt2_replayer.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ static const uint8_t funkTable[16] = // EFx (FunkRepeat/InvertLoop)
3535
0x10, 0x13, 0x16, 0x1A, 0x20, 0x2B, 0x40, 0x80
3636
};
3737

38+
void setReplayerPosToTrackerPos(void)
39+
{
40+
modPattern = (int8_t)song->currPattern;
41+
modOrder = song->currOrder;
42+
song->row = song->currRow;
43+
song->tick = 0;
44+
}
45+
3846
int8_t *allocMemForAllSamples(void)
3947
{
4048
// allocate memory for all sample data blocks (+ 2 extra, for quirk + safety)
@@ -707,7 +715,7 @@ static void checkMoreEffects(moduleChannel_t *ch)
707715
switch (cmd)
708716
{
709717
case 0x9: sampleOffset(ch); return; // note the returns here, not breaks!
710-
case 0xB: positionJump(ch); return;
718+
case 0xB: positionJump(ch); return;
711719
case 0xD: patternBreak(ch); return;
712720
case 0xE: E_Commands(ch); return;
713721
case 0xF: setSpeed(ch); return;
@@ -1270,6 +1278,13 @@ void modStop(void)
12701278
posJumpAssert = false;
12711279
modRenderDone = true;
12721280

1281+
/* The replayer is one tick ahead (unfortunately), so if the user was to stop the mod at the previous tick
1282+
** before a position jump (pattern loop, pattern break, position jump, row 63->0 transition, etc),
1283+
** it would be possible for the replayer to be at another order/pattern than the tracker.
1284+
** Let's set the replayer state to the tracker state on mod stop, to fix possible confusion.
1285+
*/
1286+
setReplayerPosToTrackerPos();
1287+
12731288
doStopSong = false; // just in case this flag was stuck from command F00 (stop song)
12741289
}
12751290

@@ -1280,8 +1295,9 @@ void playPattern(int8_t startRow)
12801295

12811296
audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
12821297
song->currRow = song->row = startRow & 0x3F;
1283-
song->tick = song->speed;
1284-
ciaSetBPM = -1;
1298+
1299+
song->tick = song->speed-1;
1300+
ciaSetBPM = -1; // fix possibly stuck "set BPM" flag
12851301

12861302
editor.playMode = PLAY_MODE_PATTERN;
12871303
editor.currMode = MODE_PLAY;
@@ -1323,8 +1339,6 @@ void modPlay(int16_t patt, int16_t order, int8_t row)
13231339

13241340
doStopIt(false);
13251341
turnOffVoices();
1326-
audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
1327-
ciaSetBPM = -1;
13281342

13291343
if (row != -1)
13301344
{
@@ -1376,13 +1390,17 @@ void modPlay(int16_t patt, int16_t order, int8_t row)
13761390
editor.currMode = oldMode;
13771391

13781392
song->tick = song->speed-1;
1393+
ciaSetBPM = -1; // fix possibly stuck "set BPM" flag
1394+
13791395
modRenderDone = false;
13801396
editor.songPlaying = true;
13811397
editor.didQuantize = false;
13821398

13831399
if (editor.playMode != PLAY_MODE_PATTERN)
13841400
editor.musicTime64 = 0; // don't reset playback counter in "play/rec pattern" mode
13851401

1402+
audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
1403+
13861404
if (audioWasntLocked)
13871405
unlockAudio();
13881406

0 commit comments

Comments
 (0)