some time refactors

no more weird totalTicks name
code looks better
This commit is contained in:
tildearrow 2025-10-30 20:35:14 -05:00
parent a2b56b5b64
commit 5ff81aef33
16 changed files with 256 additions and 211 deletions

View file

@ -104,10 +104,9 @@ void FurnaceGUI::drawClock() {
}
}
if (clockShowTime) {
int totalTicks=e->getTotalTicks();
int totalSeconds=e->getTotalSeconds();
String timeFormatted=e->getCurTime().toString(2,TA_TIME_FORMAT_MS_ZERO);
ImGui::PushFont(bigFont);
ImGui::Text("%.2d:%.2d.%.2d",(totalSeconds/60),totalSeconds%60,totalTicks/10000);
ImGui::TextUnformatted(timeFormatted.c_str());
ImGui::PopFont();
}
}

View file

@ -206,7 +206,8 @@ void FurnaceGUI::drawDebug() {
DivSongTimestamps& ts=e->curSubSong->ts;
ImGui::Text("song duration: %d.%06d (%d ticks; %d rows)",ts.totalSeconds,ts.totalMicros,ts.totalTicks,ts.totalRows);
String timeFormatted=ts.totalTime.toString(-1,TA_TIME_FORMAT_AUTO);
ImGui::Text("song duration: %s (%d ticks; %d rows)",timeFormatted.c_str(),ts.totalTicks,ts.totalRows);
if (ts.isLoopDefined) {
ImGui::Text("loop region is defined");
} else {
@ -219,7 +220,8 @@ void FurnaceGUI::drawDebug() {
}
ImGui::Text("loop region: %d:%d - %d:%d",ts.loopStart.order,ts.loopStart.row,ts.loopEnd.order,ts.loopEnd.row);
ImGui::Text("loop start time: %d.%06d",ts.loopStartTime.seconds,ts.loopStartTime.micros);
timeFormatted=ts.loopStartTime.toString(-1,TA_TIME_FORMAT_AUTO);
ImGui::Text("loop start time: %s",timeFormatted.c_str());
if (ImGui::TreeNode("Maximum rows")) {
for (int i=0; i<e->curSubSong->ordersLen; i++) {

View file

@ -2719,7 +2719,7 @@ void FurnaceGUI::exportAudio(String path, DivAudioExportModes mode) {
e->calcSongTimestamps();
DivSongTimestamps& ts=e->curSubSong->ts;
songLength=ts.totalSeconds+(double)ts.totalMicros/1000000.0;
songLength=ts.totalTime.toDouble();
double loopLength=songLength-(ts.loopStartTime.seconds+(double)ts.loopStartTime.micros/1000000.0);
e->saveAudio(path.c_str(),audioExportOptions);
@ -4843,8 +4843,7 @@ bool FurnaceGUI::loop() {
}
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PLAYBACK_STAT]);
if (e->isPlaying() && settings.playbackTime) {
int totalTicks=e->getTotalTicks();
int totalSeconds=e->getTotalSeconds();
TimeMicros totalTime=e->getCurTime();
String info;
@ -4873,32 +4872,10 @@ bool FurnaceGUI::loop() {
info+=_("| ");
if (totalSeconds==0x7fffffff) {
if (totalTime.seconds==0x7fffffff) {
info+=_("Don't you have anything better to do?");
} else {
if (totalSeconds>=86400) {
int totalDays=totalSeconds/86400;
int totalYears=totalDays/365;
totalDays%=365;
int totalMonths=totalDays/30;
totalDays%=30;
#ifdef HAVE_LOCALE
info+=fmt::sprintf(ngettext("%d year ","%d years ",totalYears),totalYears);
info+=fmt::sprintf(ngettext("%d month ","%d months ",totalMonths),totalMonths);
info+=fmt::sprintf(ngettext("%d day ","%d days ",totalDays),totalDays);
#else
info+=fmt::sprintf(_GN("%d year ","%d years ",totalYears),totalYears);
info+=fmt::sprintf(_GN("%d month ","%d months ",totalMonths),totalMonths);
info+=fmt::sprintf(_GN("%d day ","%d days ",totalDays),totalDays);
#endif
}
if (totalSeconds>=3600) {
info+=fmt::sprintf("%.2d:",(totalSeconds/3600)%24);
}
info+=fmt::sprintf("%.2d:%.2d.%.2d",(totalSeconds/60)%60,totalSeconds%60,totalTicks/10000);
info+=totalTime.toString(2,TA_TIME_FORMAT_AUTO_MS_ZERO);
}
ImGui::TextUnformatted(info.c_str());
@ -6039,7 +6016,7 @@ bool FurnaceGUI::loop() {
[this, curFileLambda] () {
*curFileLambda=0;
e->getCurFileIndex(*curFileLambda);
curProgress=(((double)e->getTotalSeconds()+(double)e->getTotalTicks()/1000000.0)+(songLength*(*curFileLambda)))/totalLength;
curProgress=(e->getCurTime().toDouble()+(songLength*(*curFileLambda)))/totalLength;
}
);
}
@ -7390,17 +7367,8 @@ bool FurnaceGUI::loop() {
if (!fp->isPlaying()) {
TimeMicros rowTS=e->curSubSong->ts.getTimes(cursor.order,cursor.y);
if (rowTS.seconds!=-1) {
int cueSeconds=0;
int cueMicros=0;
e->getFilePlayerCue(cueSeconds,cueMicros);
rowTS.seconds+=cueSeconds;
rowTS.micros+=cueMicros;
while (rowTS.micros>=1000000) {
rowTS.micros-=1000000;
rowTS.seconds++;
}
fp->setPosSeconds(rowTS.seconds,rowTS.micros);
TimeMicros cueTime=e->getFilePlayerCue();
fp->setPosSeconds(cueTime+rowTS);
}
}
}

View file

@ -90,30 +90,11 @@ void FurnaceGUI::drawMobileOrderSel() {
// time
if (e->isPlaying() && settings.playbackTime) {
int totalTicks=e->getTotalTicks();
int totalSeconds=e->getTotalSeconds();
String info="";
TimeMicros totalTime=e->getCurTime();
String info=totalTime.toString(2,TA_TIME_FORMAT_AUTO_MS_ZERO);
if (totalSeconds==0x7fffffff) {
if (totalTime.seconds==0x7fffffff) {
info="";
} else {
if (totalSeconds>=86400) {
int totalDays=totalSeconds/86400;
int totalYears=totalDays/365;
totalDays%=365;
int totalMonths=totalDays/30;
totalDays%=30;
info+=fmt::sprintf("%dy",totalYears);
info+=fmt::sprintf("%dm",totalMonths);
info+=fmt::sprintf("%dd",totalDays);
}
if (totalSeconds>=3600) {
info+=fmt::sprintf("%.2d:",(totalSeconds/3600)%24);
}
info+=fmt::sprintf("%.2d:%.2d.%.2d",(totalSeconds/60)%60,totalSeconds%60,totalTicks/10000);
}
ImVec2 textSize=ImGui::CalcTextSize(info.c_str());

View file

@ -412,7 +412,8 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
if (rowTS.seconds==-1) {
ImGui::Text("---");
} else {
ImGui::Text("%d.%06d",rowTS.seconds,rowTS.micros);
String timeFormatted=rowTS.toString(2,TA_TIME_FORMAT_AUTO_MS_ZERO);
ImGui::TextUnformatted(timeFormatted.c_str());
}
}
}

View file

@ -79,21 +79,15 @@ void FurnaceGUI::drawRefPlayer() {
}
if (fp->isPlaying()) {
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
int cueSeconds=0;
int cueMicros=0;
fp->stop();
e->getFilePlayerCue(cueSeconds,cueMicros);
fp->setPosSeconds(cueSeconds,cueMicros);
fp->setPosSeconds(e->getFilePlayerCue());
}
if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) {
fp->stop();
fp->setPos(0);
}
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
int cueSeconds=0;
int cueMicros=0;
e->getFilePlayerCue(cueSeconds,cueMicros);
fp->setPosSeconds(cueSeconds,cueMicros);
fp->setPosSeconds(e->getFilePlayerCue());
}
ImGui::SetItemTooltip(
_("left click: go to cue position\n"
@ -103,21 +97,12 @@ void FurnaceGUI::drawRefPlayer() {
} else {
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
// try setting cue pos
ssize_t curSeconds=0;
unsigned int curMicros=0;
fp->getPosSeconds(curSeconds,curMicros);
TimeMicros curPos=fp->getPosSeconds();
TimeMicros rowTS=e->curSubSong->ts.getTimes(curOrder,0);
if (rowTS.seconds==-1) {
showError(_("the first row of this order isn't going to play."));
} else {
// calculate difference and set cue pos
curSeconds-=rowTS.seconds;
int curMicrosI=curMicros-rowTS.micros;
while (curMicrosI<0) {
curMicrosI+=1000000;
curSeconds--;
}
e->setFilePlayerCue(curSeconds,curMicrosI);
e->setFilePlayerCue(curPos-rowTS);
}
}
if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) {
@ -125,25 +110,23 @@ void FurnaceGUI::drawRefPlayer() {
}
if (ImGui::BeginPopupContextItem("Edit Cue Position",ImGuiPopupFlags_MouseButtonRight)) {
ImGui::TextUnformatted(_("Set cue position at first order:"));
int cueSeconds=0;
int cueMicros=0;
TimeMicros cueTime=e->getFilePlayerCue();
bool altered=false;
e->getFilePlayerCue(cueSeconds,cueMicros);
// TODO: improve this...
ImGui::SetNextItemWidth(240.0f*dpiScale);
if (ImGui::InputInt(_("Seconds##CuePosS"),&cueSeconds)) {
if (cueSeconds<-3600) cueSeconds=-3600;
if (cueSeconds>3600) cueSeconds=3600;
if (ImGui::InputInt(_("Seconds##CuePosS"),&cueTime.seconds)) {
if (cueTime.seconds<-3600) cueTime.seconds=-3600;
if (cueTime.seconds>3600) cueTime.seconds=3600;
altered=true;
}
ImGui::SetNextItemWidth(240.0f*dpiScale);
if (ImGui::InputInt(_("Microseconds##CuePosM"),&cueMicros,1000,10000)) {
if (cueMicros<0) cueMicros=0;
if (cueMicros>999999) cueMicros=999999;
if (ImGui::InputInt(_("Microseconds##CuePosM"),&cueTime.micros,1000,10000)) {
if (cueTime.micros<0) cueTime.micros=0;
if (cueTime.micros>999999) cueTime.micros=999999;
altered=true;
}
if (altered) {
e->setFilePlayerCue(cueSeconds,cueMicros);
e->setFilePlayerCue(cueTime);
}
if (ImGui::Button(_("OK"))) {
ImGui::CloseCurrentPopup();
@ -165,21 +148,12 @@ void FurnaceGUI::drawRefPlayer() {
}
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
// try setting cue pos
ssize_t curSeconds=0;
unsigned int curMicros=0;
fp->getPosSeconds(curSeconds,curMicros);
TimeMicros curPos=fp->getPosSeconds();
TimeMicros rowTS=e->curSubSong->ts.getTimes(curOrder,0);
if (rowTS.seconds==-1) {
showError(_("the first row of this order isn't going to play."));
} else {
// calculate difference and set cue pos
curSeconds-=rowTS.seconds;
int curMicrosI=curMicros-rowTS.micros;
while (curMicrosI<0) {
curMicrosI+=1000000;
curSeconds--;
}
e->setFilePlayerCue(curSeconds,curMicrosI);
e->setFilePlayerCue(curPos-rowTS);
fp->stop();
}
}
@ -203,9 +177,7 @@ void FurnaceGUI::drawRefPlayer() {
} else {
rowTS=e->curSubSong->ts.getTimes(curOrder,0);
}
int cueSeconds=0;
int cueMicros=0;
e->getFilePlayerCue(cueSeconds,cueMicros);
TimeMicros cueTime=e->getFilePlayerCue();
if (rowTS.seconds==-1) {
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
showError(_("the row that the pattern cursor is at isn't going to play. try moving the cursor."));
@ -213,15 +185,7 @@ void FurnaceGUI::drawRefPlayer() {
showError(_("the first row of this order isn't going to play. try another order."));
}
} else {
int finalSeconds=rowTS.seconds+cueSeconds;
int finalMicros=rowTS.micros+cueMicros;
while (finalMicros>=1000000) {
finalMicros-=1000000;
finalSeconds++;
}
fp->setPosSeconds(finalSeconds,finalMicros);
fp->setPosSeconds(rowTS+cueTime);
fp->play();
}
}

View file

@ -1082,7 +1082,7 @@ void FurnaceGUI::drawTutorial() {
oneQuarter=(oneQuarter*e->curSubSong->virtualTempoN)/e->curSubSong->virtualTempoD;
oneQuarter/=e->curSubSong->hz;
oneQuarter/=4;
if (cv->playSongs && e->getTotalSeconds()>=oneQuarter) {
if (cv->playSongs && e->getCurTime().seconds>=oneQuarter) {
if (loadRandomDemoSong()) {
cv->loadInstruments();
e->changeSongP(0);