GUI: fix audio export progress bar

issue #2454
This commit is contained in:
tildearrow 2025-10-30 14:59:48 -05:00
parent 0c8cddf356
commit 0ae9151b47
2 changed files with 16 additions and 32 deletions

View file

@ -2717,11 +2717,10 @@ int FurnaceGUI::loadStream(String path) {
void FurnaceGUI::exportAudio(String path, DivAudioExportModes mode) {
e->calcSongTimestamps();
DivSongTimestamps& ts=e->curSubSong->ts;
// TODO: fix!
songFadeoutSectionLength=0;
songHasSongEndCommand=!e->curSubSong->ts.isLoopable;
songLength=e->curSubSong->ts.totalRows;
songLength=ts.totalSeconds+(double)ts.totalMicros/1000000.0;
double loopLength=songLength-(ts.loopStartTime.seconds+(double)ts.loopStartTime.micros/1000000.0);
e->saveAudio(path.c_str(),audioExportOptions);
@ -2729,19 +2728,15 @@ void FurnaceGUI::exportAudio(String path, DivAudioExportModes mode) {
e->getTotalAudioFiles(totalFiles);
int totalLoops=0;
lengthOfOneFile=songLength;
if (!songHasSongEndCommand) {
if (ts.isLoopable) {
e->getTotalLoops(totalLoops);
lengthOfOneFile+=songLoopedSectionLength*totalLoops;
lengthOfOneFile+=songFadeoutSectionLength; // account for fadeout
songLength+=loopLength*totalLoops;
songLength+=audioExportOptions.fadeOut;
}
totalLength=lengthOfOneFile*totalFiles;
totalLength=songLength*totalFiles;
curProgress=0.0f;
displayExporting=true;
}
@ -6037,24 +6032,21 @@ bool FurnaceGUI::loop() {
if (audioExportOptions.mode!=DIV_EXPORT_MODE_MANY_CHAN) {
ImGui::Text(_("Please wait..."));
}
float* progressLambda=&curProgress;
int curPosInRows=0;
int* curPosInRowsLambda=&curPosInRows;
int curFile=0;
int* curFileLambda=&curFile;
if (e->isExporting()) {
e->lockEngine(
[this, progressLambda, curPosInRowsLambda, curFileLambda] () {
[this, curFileLambda] () {
*curFileLambda=0;
e->getCurFileIndex(*curFileLambda);
*progressLambda=(double)e->getTotalSeconds()/(double)MAX(1,e->curSubSong->ts.totalSeconds);
// TODO: fix
*curPosInRowsLambda=0;
curProgress=(((double)e->getTotalSeconds()+(double)e->getTotalTicks()/1000000.0)+(songLength*(*curFileLambda)))/totalLength;
}
);
}
ImGui::Text(_("Row %d of %d"),songLength,lengthOfOneFile);
if (curProgress<0.0f) curProgress=0.0f;
if (curProgress>1.0f) curProgress=1.0f;
if (audioExportOptions.mode==DIV_EXPORT_MODE_MANY_CHAN) ImGui::Text(_("Channel %d of %d"),curFile+1,totalFiles);
ImGui::ProgressBar(curProgress,ImVec2(320.0f*dpiScale,0),fmt::sprintf("%.2f%%",curProgress*100.0f).c_str());
@ -8727,12 +8719,8 @@ FurnaceGUI::FurnaceGUI():
patFont(NULL),
bigFont(NULL),
headFont(NULL),
songLength(0),
songLoopedSectionLength(0),
songFadeoutSectionLength(0),
songHasSongEndCommand(false),
lengthOfOneFile(0),
totalLength(0),
songLength(0.0),
totalLength(0.0),
curProgress(0.0f),
totalFiles(0),
localeRequiresJapanese(false),

View file

@ -1823,12 +1823,8 @@ class FurnaceGUI {
char emptyLabel[32];
char emptyLabel2[32];
int songLength; // length of all the song in rows
int songLoopedSectionLength; // length of looped part of the song
int songFadeoutSectionLength; // length of fading part of the song
bool songHasSongEndCommand; // song has "Song end" command (FFxx)
int lengthOfOneFile; // length of one rendering pass. song length times num of loops + fadeout
int totalLength; // total length of render (lengthOfOneFile times num of files for per-channel export)
double songLength; // length of the song in seconds
double totalLength; // total length of render (songLength times num of files for per-channel export)
float curProgress;
int totalFiles;