From fcd13f9b227d80e066775f75b09bc6ec9337bfc8 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 14 Dec 2020 01:14:20 +0800 Subject: 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. --- include/qmpcorepublic.hpp | 9 +++++++++ qmidiplayer-desktop/qmpmainwindow.cpp | 22 +++++++++++++++++----- qmidiplayer-desktop/qmpmainwindow.hpp | 1 + qmidiplayer-desktop/qmpplugin.cpp | 5 +++++ qmidiplayer-desktop/qmpplugin.hpp | 1 + visualization/renderer/qmppluginapistub.cpp | 5 +++++ visualization/renderer/qmppluginapistub.hpp | 1 + 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/qmpcorepublic.hpp b/include/qmpcorepublic.hpp index 8376af8..242ca58 100644 --- a/include/qmpcorepublic.hpp +++ b/include/qmpcorepublic.hpp @@ -70,6 +70,14 @@ public: if (copyright)delete[] copyright; } }; +struct PlaybackStatus +{ + bool paused; + uint64_t curtime_ms; + uint64_t maxtime_ms; + uint64_t curtick; + uint64_t maxtick; +}; //Generic callback function that can be used for hooking the core. //"userdata" is set when you register the callback function. //Deprecated. Removing in 0.9.x. @@ -160,6 +168,7 @@ extern "C" { virtual uint32_t getMaxPolyphone() = 0; virtual uint32_t getCurrentTimeStamp() = 0; virtual uint32_t getCurrentPlaybackPercentage() = 0; + virtual PlaybackStatus getPlaybackStatus() = 0; virtual int getChannelCC(int ch, int cc) = 0; virtual int getChannelPreset(int ch) = 0; virtual void playerSeek(uint32_t percentage) = 0; 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 elapsed = + std::chrono::duration_cast>(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() diff --git a/qmidiplayer-desktop/qmpmainwindow.hpp b/qmidiplayer-desktop/qmpmainwindow.hpp index 47a29f6..eb36ba8 100644 --- a/qmidiplayer-desktop/qmpmainwindow.hpp +++ b/qmidiplayer-desktop/qmpmainwindow.hpp @@ -228,6 +228,7 @@ public: std::wstring getWTitle(); uint32_t getPlaybackPercentage(); void playerSeek(uint32_t percentage); + PlaybackStatus getPlaybackStatus(); int parseArgs(); void registerFunctionality(qmpFuncBaseIntf *i, std::string name, std::string desc, const char *icon, int iconlen, bool checkable); void unregisterFunctionality(std::string name); diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp index ca851ee..c52f486 100644 --- a/qmidiplayer-desktop/qmpplugin.cpp +++ b/qmidiplayer-desktop/qmpplugin.cpp @@ -213,6 +213,11 @@ uint32_t qmpPluginAPIImpl::getCurrentPlaybackPercentage() { return qmw ? qmw->getPlaybackPercentage() : 0; } + +PlaybackStatus qmpPluginAPIImpl::getPlaybackStatus() +{ + return qmw ? qmw->getPlaybackStatus() : PlaybackStatus{false, 0, 0, 0, 0}; +} int qmpPluginAPIImpl::getChannelCC(int ch, int cc) { return qmw && qmw->getPlayer() ? qmw->getPlayer()->getCC(ch, cc) : 0; diff --git a/qmidiplayer-desktop/qmpplugin.hpp b/qmidiplayer-desktop/qmpplugin.hpp index 778f90f..b7a5e06 100644 --- a/qmidiplayer-desktop/qmpplugin.hpp +++ b/qmidiplayer-desktop/qmpplugin.hpp @@ -37,6 +37,7 @@ public: uint32_t getMaxPolyphone(); uint32_t getCurrentTimeStamp(); uint32_t getCurrentPlaybackPercentage(); + PlaybackStatus getPlaybackStatus(); int getChannelCC(int ch, int cc); int getChannelPreset(int ch); void playerSeek(uint32_t percentage); diff --git a/visualization/renderer/qmppluginapistub.cpp b/visualization/renderer/qmppluginapistub.cpp index b84a2b6..ae424b4 100644 --- a/visualization/renderer/qmppluginapistub.cpp +++ b/visualization/renderer/qmppluginapistub.cpp @@ -59,6 +59,11 @@ uint32_t qmpPluginAPIStub::getCurrentPlaybackPercentage() { return 0; } + +PlaybackStatus qmpPluginAPIStub::getPlaybackStatus() +{ + return {false, 0, 0, 0, 0}; +} int qmpPluginAPIStub::getChannelCC(int ch, int cc) { return 0; diff --git a/visualization/renderer/qmppluginapistub.hpp b/visualization/renderer/qmppluginapistub.hpp index 4a9024d..ede08d3 100644 --- a/visualization/renderer/qmppluginapistub.hpp +++ b/visualization/renderer/qmppluginapistub.hpp @@ -20,6 +20,7 @@ public: uint32_t getMaxPolyphone(); uint32_t getCurrentTimeStamp(); uint32_t getCurrentPlaybackPercentage(); + PlaybackStatus getPlaybackStatus(); int getChannelCC(int ch, int cc); int getChannelPreset(int ch); void playerSeek(uint32_t percentage); -- cgit v1.2.3