fix some threading issues

This commit is contained in:
tildearrow 2023-08-21 14:14:09 -05:00
parent d0f498189c
commit 6ba8527cb6
3 changed files with 40 additions and 10 deletions

View File

@ -822,10 +822,6 @@ void DivEngine::runExportThread() {
size_t curFadeOutSample=0;
bool isFadingOut=false;
quitDispatch();
initDispatch(true);
renderSamples();
switch (exportMode) {
case DIV_EXPORT_MODE_ONE: {
SNDFILE* sf;
@ -838,9 +834,6 @@ void DivEngine::runExportThread() {
sf=sfWrap.doOpen(exportPath.c_str(),SFM_WRITE,&si);
if (sf==NULL) {
logE("could not open file for writing! (%s)",sf_strerror(NULL));
quitDispatch();
initDispatch(false);
renderSamples();
exporting=false;
return;
}
@ -1153,9 +1146,6 @@ void DivEngine::runExportThread() {
}
}
quitDispatch();
initDispatch(false);
renderSamples();
stopExport=false;
}
#else
@ -1163,6 +1153,11 @@ void DivEngine::runExportThread() {
}
#endif
bool DivEngine::shallSwitchCores() {
// TODO: detect whether we should
return true;
}
bool DivEngine::saveAudio(const char* path, int loops, DivAudioExportModes mode, double fadeOutTime) {
#ifndef HAVE_SNDFILE
logE("Furnace was not compiled with libsndfile. cannot export!");
@ -1192,6 +1187,20 @@ bool DivEngine::saveAudio(const char* path, int loops, DivAudioExportModes mode,
} else {
remainingLoops=-1;
}
if (shallSwitchCores()) {
bool isMutedBefore[DIV_MAX_CHANS];
memcpy(isMutedBefore,isMuted,DIV_MAX_CHANS*sizeof(bool));
quitDispatch();
initDispatch(true);
renderSamplesP();
for (int i=0; i<tchans; i++) {
if (isMutedBefore[i]) {
muteChannels(i,true);
}
}
}
exportLoopCount=loops;
exportThread=new std::thread(_runExportThread,this);
return true;
@ -1206,10 +1215,27 @@ void DivEngine::waitAudioFile() {
bool DivEngine::haltAudioFile() {
stopExport=true;
waitAudioFile();
stop();
finishAudioFile();
return true;
}
void DivEngine::finishAudioFile() {
if (shallSwitchCores()) {
bool isMutedBefore[DIV_MAX_CHANS];
memcpy(isMutedBefore,isMuted,DIV_MAX_CHANS*sizeof(bool));
quitDispatch();
initDispatch(false);
renderSamplesP();
for (int i=0; i<tchans; i++) {
if (isMutedBefore[i]) {
muteChannels(i,true);
}
}
}
}
void DivEngine::notifyInsChange(int ins) {
BUSY_BEGIN;
for (int i=0; i<song.systemLen; i++) {

View File

@ -497,6 +497,7 @@ class DivEngine {
void playSub(bool preserveDrift, int goalRow=0);
void runMidiClock(int totalCycles=1);
void runMidiTime(int totalCycles=1);
bool shallSwitchCores();
void testFunction();
@ -614,6 +615,8 @@ class DivEngine {
void waitAudioFile();
// stop audio file export
bool haltAudioFile();
// return back to playback cores if necessary
void finishAudioFile();
// notify instrument parameter change
void notifyInsChange(int ins);
// notify wavetable change

View File

@ -5262,6 +5262,7 @@ bool FurnaceGUI::loop() {
}
}
if (!e->isExporting()) {
e->finishAudioFile();
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();