aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2020-04-29 11:25:58 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2020-04-29 11:25:58 +0800
commit65a8bde4e4beca860a13491e94631dc16b5e71af (patch)
treed92df4a6538af18c4231dca015a6f504d8c65cd2 /qmidiplayer-desktop
parent73020aae5bf0b7dd49c78880e2768deb19181b81 (diff)
downloadQMidiPlayer-65a8bde4e4beca860a13491e94631dc16b5e71af.tar.xz
Decouple CMidiPlayer and qmpMidiOutFluid.
Visualization renderer should no longer depend on the fluidsynth library. Reworked the "wait voice" option: now it only takes effect if an automatic track switch happens. Actually process events while waiting for async operation to finish.
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r--qmidiplayer-desktop/CMakeLists.txt1
-rw-r--r--qmidiplayer-desktop/qmpefxwindow.cpp2
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.cpp88
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.hpp7
-rw-r--r--qmidiplayer-desktop/qmpplugin.cpp4
-rw-r--r--qmidiplayer-desktop/qmppresetselect.cpp3
6 files changed, 74 insertions, 31 deletions
diff --git a/qmidiplayer-desktop/CMakeLists.txt b/qmidiplayer-desktop/CMakeLists.txt
index c34f258..419bb05 100644
--- a/qmidiplayer-desktop/CMakeLists.txt
+++ b/qmidiplayer-desktop/CMakeLists.txt
@@ -58,6 +58,7 @@ set(CMAKE_AUTOUIC ON)
include_directories(${fluidsynth_INCLUDE_DIRS})
include_directories(${rtmidi_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include/)
+include_directories(${PROJECT_SOURCE_DIR}/core/)
cmake_host_system_information(RESULT build_host QUERY HOSTNAME)
add_definitions(-DBUILD_MACHINE=${build_host})
diff --git a/qmidiplayer-desktop/qmpefxwindow.cpp b/qmidiplayer-desktop/qmpefxwindow.cpp
index f8731ba..7691756 100644
--- a/qmidiplayer-desktop/qmpefxwindow.cpp
+++ b/qmidiplayer-desktop/qmpefxwindow.cpp
@@ -103,7 +103,7 @@ void qmpEfxWindow::sendEfxChange(void *_fs)
cfb=ui->sbFeedBack->value();cl=ui->sbLevelC->value()/100.;
cr=ui->sbRate->value();cd=ui->sbDepth->value();
IFluidSettings* fs=(IFluidSettings*)_fs;
- if(!_fs)fs=qmpMainWindow::getInstance()->getPlayer()->fluid();
+ if(!_fs)fs=qmpMainWindow::getInstance()->getFluid();
fs->setReverbPara(ui->cbEnabledR->isChecked()?1:0,rr,rd,rw,rl);
fs->setChorusPara(ui->cbEnabledC->isChecked()?1:0,cfb,cl,cr,cd,ct);
diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp
index 50c92b4..ea90493 100644
--- a/qmidiplayer-desktop/qmpmainwindow.cpp
+++ b/qmidiplayer-desktop/qmpmainwindow.cpp
@@ -67,6 +67,8 @@ qmpMainWindow::~qmpMainWindow()
delete renderf;renderf=nullptr;
delete reloadsynf;reloadsynf=nullptr;
if(player)delete player;
+ internalfluid->deviceDeinit();
+ delete internalfluid;
delete ui;
}
@@ -82,17 +84,24 @@ void qmpMainWindow::init()
[this]
{
player=new CMidiPlayer();
+ internalfluid=new qmpMidiOutFluid();
+ player->registerMidiOutDevice(internalfluid,"Internal FluidSynth");
reloadsynf=new qmpReloadSynthFunc(this);
- player->registerFluidOptions(pmgr->pluginAPI);
- playerSetup(player->fluid());
- player->fluid()->deviceInit();
- loadSoundFont(player->fluid());
+
+ internalfluid->registerOptions(pmgr->pluginAPI);
+ playerSetup(internalfluid);
+ internalfluid->deviceInit();
+ loadSoundFont(internalfluid);
+ for(int i=0;i<16;++i)
+ player->setChannelOutput(i,0);
+
auto rtdev=qmpRtMidiManager::getDevices();
for(auto &i:rtdev)
player->registerMidiOutDevice(i.first,i.second);
}
);
- while(f.wait_for(std::chrono::milliseconds(100))==std::future_status::timeout);
+ while(f.wait_for(std::chrono::milliseconds(100))==std::future_status::timeout)
+ QApplication::processEvents();
ui->centralWidget->setEnabled(true);
settingsw->registerSoundFontOption();
@@ -231,7 +240,14 @@ void qmpMainWindow::updateWidgets()
timer->stop();stopped=true;playing=false;
invokeCallback("main.stop",nullptr);
setFuncEnabled("Render",stopped);setFuncEnabled("ReloadSynth",stopped);
- player->playerDeinit();playerTh->join();
+ player->playerDeinit();
+ auto f=std::async([this]{playerTh->join();});
+ while(f.wait_for(std::chrono::milliseconds(100))==std::future_status::timeout)
+ {
+ QApplication::processEvents();
+ ui->lbCurPoly->setText(QString("%1").arg(internalfluid->getPolyphone(),5,10,QChar('0')));
+ ui->lbMaxPoly->setText(QString("%1").arg(internalfluid->getMaxPolyphone(),5,10,QChar('0')));
+ }
delete playerTh;playerTh=nullptr;
player->playerPanic(true);
chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
@@ -241,7 +257,7 @@ void qmpMainWindow::updateWidgets()
ui->lbCurTime->setText("00:00");
}
else
- switchTrack(plistw->getNextItem());
+ switchTrack(plistw->getNextItem(),false);
}
if(renderTh)
{
@@ -264,20 +280,35 @@ void qmpMainWindow::updateWidgets()
char ts[100];
sprintf(ts,"%02d:%02d",(int)(elapsed.count()+offset)/60,(int)(elapsed.count()+offset)%60);
ui->lbCurTime->setText(ts);
- ui->lbCurPoly->setText(QString("%1").arg(player->fluid()->getPolyphone(),5,10,QChar('0')));
- ui->lbMaxPoly->setText(QString("%1").arg(player->fluid()->getMaxPolyphone(),5,10,QChar('0')));
+ ui->lbCurPoly->setText(QString("%1").arg(internalfluid->getPolyphone(),5,10,QChar('0')));
+ ui->lbMaxPoly->setText(QString("%1").arg(internalfluid->getMaxPolyphone(),5,10,QChar('0')));
}
}
QString qmpMainWindow::getFileName(){return ui->lbFileName->text();}
-void qmpMainWindow::switchTrack(QString s)
+void qmpMainWindow::switchTrack(QString s,bool interrupt)
{
stopped=false;playing=true;
setFuncEnabled("Render",stopped);setFuncEnabled("ReloadSynth",stopped);
ui->pbPlayPause->setIcon(QIcon(getThemedIcon(":/img/pause.svg")));
- timer->stop();player->playerDeinit();
+ if(interrupt)
+ {
+ player->playerDeinit();
+ player->playerPanic();
+ }
invokeCallback("main.stop",nullptr);
- if(playerTh){playerTh->join();delete playerTh;playerTh=nullptr;}
+ if(playerTh)
+ {
+ auto f=std::async([this]{playerTh->join();});
+ while(f.wait_for(std::chrono::milliseconds(100))==std::future_status::timeout)
+ {
+ QApplication::processEvents();
+ ui->lbCurPoly->setText(QString("%1").arg(internalfluid->getPolyphone(),5,10,QChar('0')));
+ ui->lbMaxPoly->setText(QString("%1").arg(internalfluid->getMaxPolyphone(),5,10,QChar('0')));
+ }
+ delete playerTh;playerTh=nullptr;
+ }
+ timer->stop();
player->playerPanic(true);
ui->hsTimer->setValue(0);
chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
@@ -290,9 +321,13 @@ void qmpMainWindow::switchTrack(QString s)
ui->lbFinTime->setText(ts);
player->playerInit();
invokeCallback("main.start",nullptr);
- player->fluid()->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
- player->setWaitVoice(settings->getOptionBool("Midi/WaitVoice"));
- playerTh=new std::thread(&CMidiPlayer::playerThread,player);
+ internalfluid->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
+ playerTh=new std::thread([this]{
+ player->playerThread();
+ if(settings->getOptionBool("Midi/WaitVoice")&&player->isFinished())
+ while(internalfluid->getPolyphone()>0)
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ });
#ifdef _WIN32
SetThreadPriority((void*)playerTh->native_handle(),THREAD_PRIORITY_TIME_CRITICAL);
#endif
@@ -415,9 +450,13 @@ void qmpMainWindow::on_pbPlayPause_clicked()
ui->lbFinTime->setText(ts);
player->playerInit();
invokeCallback("main.start",nullptr);
- player->fluid()->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
- player->setWaitVoice(settings->getOptionBool("Midi/WaitVoice"));
- playerTh=new std::thread(&CMidiPlayer::playerThread,player);
+ internalfluid->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
+ playerTh=new std::thread([this]{
+ player->playerThread();
+ if(settings->getOptionBool("Midi/WaitVoice")&&player->isFinished())
+ while(internalfluid->getPolyphone()>0)
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ });
#ifdef _WIN32
SetThreadPriority((void*)playerTh->native_handle(),THREAD_PRIORITY_TIME_CRITICAL);
#endif
@@ -498,7 +537,7 @@ void qmpMainWindow::playerSeek(uint32_t percentage)
void qmpMainWindow::on_vsMasterVol_valueChanged()
{
- if(!stopped)player->fluid()->setGain(ui->vsMasterVol->value()/250.);
+ if(!stopped)internalfluid->setGain(ui->vsMasterVol->value()/250.);
settings->setOptionRaw("FluidSynth/Gain",ui->vsMasterVol->value());
}
@@ -642,13 +681,14 @@ void qmpMainWindow::reloadSynth()
std::future<void> f=std::async(std::launch::async,
[this]
{
- player->fluid()->deviceDeinit(true);
- playerSetup(player->fluid());
- player->fluid()->deviceInit();
- loadSoundFont(player->fluid());
+ internalfluid->deviceDeinit(true);
+ playerSetup(internalfluid);
+ internalfluid->deviceInit();
+ loadSoundFont(internalfluid);
}
);
- while(f.wait_for(std::chrono::milliseconds(100))==std::future_status::timeout);
+ while(f.wait_for(std::chrono::milliseconds(100))==std::future_status::timeout)
+ QApplication::processEvents();
ui->centralWidget->setEnabled(true);
}
diff --git a/qmidiplayer-desktop/qmpmainwindow.hpp b/qmidiplayer-desktop/qmpmainwindow.hpp
index 700b501..d98029d 100644
--- a/qmidiplayer-desktop/qmpmainwindow.hpp
+++ b/qmidiplayer-desktop/qmpmainwindow.hpp
@@ -20,7 +20,8 @@
#include <future>
#include <map>
#include <unordered_map>
-#include "../core/qmpmidiplay.hpp"
+#include "qmpmidioutfluid.hpp"
+#include "qmpmidiplay.hpp"
#include "qmpplugin.hpp"
#include "qmpplistwindow.hpp"
#include "qmpchannelswindow.hpp"
@@ -141,11 +142,12 @@ class qmpMainWindow:public QMainWindow
void dragEnterEvent(QDragEnterEvent *event);
~qmpMainWindow();
CMidiPlayer* getPlayer(){return player;}
+ qmpMidiOutFluid* getFluid(){return internalfluid;}
qmpSettings* getSettings(){return settings.get();}
QTimer* getTimer(){return timer;}
bool isFinalizing(){return fin;}
QString getFileName();
- void switchTrack(QString s);
+ void switchTrack(QString s,bool interrupt=true);
std::string getTitle();
std::wstring getWTitle();
uint32_t getPlaybackPercentage();
@@ -193,6 +195,7 @@ class qmpMainWindow:public QMainWindow
std::chrono::steady_clock::time_point st;
double offset;
CMidiPlayer *player;
+ qmpMidiOutFluid *internalfluid;
qmpFileRendererFluid *fluidrenderer;
qmpPluginManager *pmgr;
QPointer<qmpPlistWindow> plistw;
diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp
index 8a156ba..6e53302 100644
--- a/qmidiplayer-desktop/qmpplugin.cpp
+++ b/qmidiplayer-desktop/qmpplugin.cpp
@@ -144,9 +144,9 @@ uint32_t qmpPluginAPI::getNoteCount()
uint32_t qmpPluginAPI::getMaxTick()
{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getMaxTick():0;}
uint32_t qmpPluginAPI::getCurrentPolyphone()
-{return qmw&&qmw->getPlayer()?qmw->getPlayer()->fluid()->getPolyphone():0;}
+{return qmw&&qmw->getPlayer()?qmw->getFluid()->getPolyphone():0;}
uint32_t qmpPluginAPI::getMaxPolyphone()
-{return qmw&&qmw->getPlayer()?qmw->getPlayer()->fluid()->getMaxPolyphone():0;}
+{return qmw&&qmw->getPlayer()?qmw->getFluid()->getMaxPolyphone():0;}
uint32_t qmpPluginAPI::getCurrentTimeStamp()
{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getTick():0;}
uint32_t qmpPluginAPI::getCurrentPlaybackPercentage()
diff --git a/qmidiplayer-desktop/qmppresetselect.cpp b/qmidiplayer-desktop/qmppresetselect.cpp
index 52b0b66..821eced 100644
--- a/qmidiplayer-desktop/qmppresetselect.cpp
+++ b/qmidiplayer-desktop/qmppresetselect.cpp
@@ -18,8 +18,7 @@ qmpPresetSelector::~qmpPresetSelector()
void qmpPresetSelector::showEvent(QShowEvent *e)
{
memset(presets,0,sizeof(presets));
- CMidiPlayer *plyr=qmpMainWindow::getInstance()->getPlayer();
- if(!plyr->fluid()->getSFCount())return e->ignore();
+ if(!qmpMainWindow::getInstance()->getFluid()->getSFCount())return e->ignore();
ui->lwBankSelect->clear();
ui->lwPresetSelect->clear();
e->accept();