prepare for DivSongTimestamps

this will replace walkSong and findSongLength while
offering more features
This commit is contained in:
tildearrow 2025-10-28 05:31:50 -05:00
parent 25cb78b306
commit d3c85ae748
3 changed files with 60 additions and 5 deletions

View file

@ -1666,6 +1666,19 @@ void DivEngine::setFilePlayerSync(bool doSync) {
filePlayerSync=doSync;
}
void DivEngine::syncFilePlayer() {
if (curFilePlayer==NULL) return;
int finalSeconds=totalSeconds+filePlayerCueSeconds;
int finalMicros=totalTicks+filePlayerCueMicros;
while (finalMicros>=1000000) {
finalMicros-=1000000;
finalSeconds++;
}
curFilePlayer->setPosSeconds(finalSeconds,finalMicros);
}
void DivEngine::playSub(bool preserveDrift, int goalRow) {
logV("playSub() called");
std::chrono::high_resolution_clock::time_point timeStart=std::chrono::high_resolution_clock::now();
@ -2020,7 +2033,7 @@ bool DivEngine::play() {
bool didItPlay=playing;
if (didItPlay) {
if (curFilePlayer && filePlayerSync) {
curFilePlayer->setPosSeconds(totalSeconds,totalTicks);
syncFilePlayer();
curFilePlayer->play();
}
}
@ -2042,7 +2055,7 @@ bool DivEngine::playToRow(int row) {
bool didItPlay=playing;
if (didItPlay) {
if (curFilePlayer && filePlayerSync) {
curFilePlayer->setPosSeconds(totalSeconds,totalTicks);
syncFilePlayer();
curFilePlayer->play();
}
}
@ -2055,6 +2068,9 @@ void DivEngine::stepOne(int row) {
BUSY_BEGIN_SOFT;
freelance=false;
playSub(false,row);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
}
for (int i=0; i<DIV_MAX_CHANS; i++) {
keyHit[i]=false;
}
@ -3136,6 +3152,10 @@ void DivEngine::addOrder(int pos, bool duplicate, bool where) {
prevOrder=curOrder;
if (playing && !freelance) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
curFilePlayer->play();
}
}
}
BUSY_END;
@ -3188,6 +3208,10 @@ void DivEngine::deepCloneOrder(int pos, bool where) {
if (pos<=curOrder) curOrder++;
if (playing && !freelance) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
curFilePlayer->play();
}
}
}
BUSY_END;
@ -3208,6 +3232,10 @@ void DivEngine::deleteOrder(int pos) {
if (curOrder>=curSubSong->ordersLen) curOrder=curSubSong->ordersLen-1;
if (playing && !freelance) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
curFilePlayer->play();
}
}
BUSY_END;
}
@ -3231,6 +3259,10 @@ void DivEngine::moveOrderUp(int& pos) {
pos--;
if (playing && !freelance) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
curFilePlayer->play();
}
}
BUSY_END;
}
@ -3254,6 +3286,10 @@ void DivEngine::moveOrderDown(int& pos) {
pos++;
if (playing && !freelance) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
curFilePlayer->play();
}
}
BUSY_END;
}
@ -3674,7 +3710,7 @@ void DivEngine::setOrder(unsigned char order) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
curFilePlayer->setPosSeconds(totalSeconds,totalTicks);
syncFilePlayer();
curFilePlayer->play();
}
}
@ -3697,6 +3733,10 @@ void DivEngine::updateSysFlags(int system, bool restart, bool render) {
if (restart) {
if (isPlaying()) {
playSub(false);
if (curFilePlayer && filePlayerSync) {
syncFilePlayer();
curFilePlayer->play();
}
} else if (freelance) {
reset();
}

View file

@ -603,13 +603,16 @@ class DivEngine {
DivFilePlayer* curFilePlayer;
bool filePlayerSync;
ssize_t filePlayerCueSeconds;
unsigned int filePlayerCueMillis;
unsigned int filePlayerCueMicros;
size_t totalProcessed;
unsigned int renderPoolThreads;
DivWorkPool* renderPool;
// song timestamps
DivSongTimestamps* songTimestamps;
// MIDI stuff
std::function<int(const TAMidiMessage&)> midiCallback=[](const TAMidiMessage&) -> int {return -3;};
@ -630,6 +633,8 @@ class DivEngine {
void runMidiTime(int totalCycles=1);
bool shallSwitchCores();
void syncFilePlayer();
void testFunction();
bool loadDMF(unsigned char* file, size_t len);
@ -874,6 +879,9 @@ class DivEngine {
// find song length in rows (up to specified loop point), and find length of every order
void findSongLength(int loopOrder, int loopRow, double fadeoutLen, int& rowsForFadeout, bool& hasFFxx, std::vector<int>& orders, int& length);
// calculate all song timestamps
void calcSongTimestamps();
// play (returns whether successful)
bool play();
@ -1573,7 +1581,7 @@ class DivEngine {
curFilePlayer(NULL),
filePlayerSync(true),
filePlayerCueSeconds(0),
filePlayerCueMillis(0),
filePlayerCueMicros(0),
totalProcessed(0),
renderPoolThreads(0),
renderPool(NULL),

View file

@ -245,6 +245,13 @@ struct DivEffectStorage {
storageLen(0) {}
};
struct DivSongTimestamps {
int totalSeconds;
int totalMicros;
// TODO
};
struct DivSong {
unsigned short version;
bool isDMF;