aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop/qmpmainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2020-12-14 01:14:20 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2020-12-14 01:14:20 +0800
commitfcd13f9b227d80e066775f75b09bc6ec9337bfc8 (patch)
tree5d673da6cd88275cc03d771c13fa508de9c595be /qmidiplayer-desktop/qmpmainwindow.cpp
parent8ea9ca158e8a113f38c22fbfa93ad99277b51d26 (diff)
downloadQMidiPlayer-fcd13f9b227d80e066775f75b09bc6ec9337bfc8.tar.xz
Add unified interface for retrieving playback status.
This should make several methods obsolete, however I'm too lazy to migrate them right now. So one more item on the todo list I guess.
Diffstat (limited to 'qmidiplayer-desktop/qmpmainwindow.cpp')
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp
index 69a0ba9..05b7ec3 100644
--- a/qmidiplayer-desktop/qmpmainwindow.cpp
+++ b/qmidiplayer-desktop/qmpmainwindow.cpp
@@ -371,7 +371,8 @@ void qmpMainWindow::switchTrack(QString s, bool interrupt)
sprintf(ts, "%02d:%02d", (int)player->getFtime() / 60, (int)player->getFtime() % 60);
ui->lbFinTime->setText(ts);
player->playerInit();
- invokeCallback("main.start", nullptr);
+ PlaybackStatus ps = getPlaybackStatus();
+ invokeCallback("main.start", &ps);
internalfluid->setGain(ui->vsMasterVol->value() / 250.);
efxw->sendEfxChange();
playerTh = new std::thread([this]
@@ -525,7 +526,8 @@ void qmpMainWindow::on_pbPlayPause_clicked()
sprintf(ts, "%02d:%02d", (int)player->getFtime() / 60, (int)player->getFtime() % 60);
ui->lbFinTime->setText(ts);
player->playerInit();
- invokeCallback("main.start", nullptr);
+ PlaybackStatus ps = getPlaybackStatus();
+ invokeCallback("main.start", &ps);
internalfluid->setGain(ui->vsMasterVol->value() / 250.);
efxw->sendEfxChange();
playerTh = new std::thread([this]
@@ -556,7 +558,8 @@ void qmpMainWindow::on_pbPlayPause_clicked()
player->setResumed();
}
player->setTCpaused(!playing);
- invokeCallback("main.pause", nullptr);
+ PlaybackStatus ps = getPlaybackStatus();
+ invokeCallback("main.pause", &ps);
}
ui->pbPlayPause->setIcon(QIcon(getThemedIcon(playing ? ":/img/pause.svg" : ":/img/play.svg")));
}
@@ -594,7 +597,8 @@ void qmpMainWindow::on_hsTimer_sliderReleased()
sprintf(ts, "%02d:%02d", (int)(offset) / 60, (int)(offset) % 60);
ui->lbCurTime->setText(ts);
}
- invokeCallback("main.seek", nullptr);
+ PlaybackStatus ps = getPlaybackStatus();
+ invokeCallback("main.seek", &ps);
}
uint32_t qmpMainWindow::getPlaybackPercentage()
@@ -607,7 +611,6 @@ void qmpMainWindow::playerSeek(uint32_t percentage)
percentage = 100;
if (percentage < 0)
percentage = 0;
- invokeCallback("main.seek", nullptr);
if (playing)
{
if (percentage == 100)
@@ -635,6 +638,15 @@ void qmpMainWindow::playerSeek(uint32_t percentage)
sprintf(ts, "%02d:%02d", (int)(offset) / 60, (int)(offset) % 60);
ui->lbCurTime->setText(ts);
}
+ PlaybackStatus ps = getPlaybackStatus();
+ invokeCallback("main.seek", &ps);
+}
+
+PlaybackStatus qmpMainWindow::getPlaybackStatus()
+{
+ std::chrono::duration<double> elapsed =
+ std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - st);
+ return {!playing, uint64_t((elapsed.count() + offset) * 1000), uint64_t(player->getFtime() * 1000), player->getTick(), player->getMaxTick()};
}
void qmpMainWindow::on_vsMasterVol_valueChanged()