aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-04-26 23:16:46 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-04-26 23:16:46 +0800
commitdfcc193d4070c99bf217ac74a492160968dba766 (patch)
tree444132b8cf98ef3d8bc7b346f6e5bf515e662f1b /qmidiplayer-desktop
parent4ffde0ad55d041229793ca4457123bcbcbf8e0c0 (diff)
downloadQMidiPlayer-dfcc193d4070c99bf217ac74a492160968dba766.tar.xz
The visualization plugin is usable now...
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.cpp42
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.hpp7
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.ui3
-rw-r--r--qmidiplayer-desktop/qmpplugin.cpp29
4 files changed, 67 insertions, 14 deletions
diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp
index 9d73626..53a2031 100644
--- a/qmidiplayer-desktop/qmpmainwindow.cpp
+++ b/qmidiplayer-desktop/qmpmainwindow.cpp
@@ -27,6 +27,7 @@ char* wcsto8bit(const wchar_t* s)
}
#define LOAD_FILE \
{\
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->reset();\
char* c=wcsto8bit(fns.toStdWString().c_str());\
if(!player->playerLoadFile(c)){free(c);QMessageBox::critical(this,tr("Error"),tr("%1 is not a valid midi file.").arg(fns));return;}\
free(c);\
@@ -35,7 +36,10 @@ char* wcsto8bit(const wchar_t* s)
#define LOAD_SOUNDFONT \
player->pushSoundFont(settingsw->getSFWidget()->item(i)->text().toStdString().c_str())
#define LOAD_FILE \
- if(!player->playerLoadFile(fns.toStdString().c_str())){QMessageBox::critical(this,tr("Error"),tr("%1 is not a valid midi file.").arg(fns));return;}
+ {\
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->reset();\
+ if(!player->playerLoadFile(fns.toStdString().c_str())){QMessageBox::critical(this,tr("Error"),tr("%1 is not a valid midi file.").arg(fns));return;}\
+ }
#endif
#define UPDATE_INTERVAL 66
@@ -48,7 +52,7 @@ qmpMainWindow::qmpMainWindow(QWidget *parent) :
ui->setupUi(this);
ui->lnPolyphone->display("00000-00000");
ui->lbFileName->setText("");ref=this;
- playing=false;stopped=true;dragging=false;
+ playing=false;stopped=true;dragging=false;memset(VIs,0,sizeof(VIs));
settingsw=new qmpSettingsWindow(this);pmgr=new qmpPluginManager();
plistw=new qmpPlistWindow(this);player=NULL;timer=NULL;
singleFS=qmpSettingsWindow::getSettingsIntf()->value("Behavior/SingleInstance",0).toInt();
@@ -217,6 +221,7 @@ void qmpMainWindow::updateWidgets()
if(!plistw->getRepeat())
{
timer->stop();stopped=true;playing=false;
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->stop();
fnA2->setEnabled(stopped);chnlw->resetAcitivity();
player->playerDeinit();playerTh->join();
delete playerTh;playerTh=NULL;
@@ -232,6 +237,7 @@ void qmpMainWindow::updateWidgets()
timer->stop();player->playerDeinit();playerTh->join();
delete playerTh;playerTh=NULL;
ui->hsTimer->setValue(0);
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->stop();
if(singleFS)player->playerPanic(true);
chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
QString fns=plistw->getNextItem();
@@ -244,6 +250,7 @@ void qmpMainWindow::updateWidgets()
player->playerInit();if(!singleFS){playerSetup();player->fluidInitialize();
for(int i=settingsw->getSFWidget()->count()-1;i>=0;--i)
LOAD_SOUNDFONT;}
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->start();
player->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -346,6 +353,7 @@ void qmpMainWindow::on_pbPlayPause_clicked()
player->playerInit();if(!singleFS){playerSetup();player->fluidInitialize();
for(int i=settingsw->getSFWidget()->count()-1;i>=0;--i)
LOAD_SOUNDFONT;}
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->start();
player->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -369,6 +377,7 @@ void qmpMainWindow::on_pbPlayPause_clicked()
player->setResumed();
}
player->setTCpaused(!playing);
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->pause();
}
ui->pbPlayPause->setIcon(QIcon(playing?":/img/pause.png":":/img/play.png"));
}
@@ -410,6 +419,7 @@ void qmpMainWindow::on_pbStop_clicked()
if(!stopped)
{
timer->stop();stopped=true;playing=false;
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->stop();
player->playerDeinit();fnA2->setEnabled(stopped);
if(singleFS)player->playerPanic(true);chnlw->resetAcitivity();
if(playerTh){playerTh->join();delete playerTh;playerTh=NULL;}
@@ -460,6 +470,7 @@ void qmpMainWindow::on_pbPrev_clicked()
timer->stop();player->playerDeinit();
if(playerTh){playerTh->join();delete playerTh;playerTh=NULL;}
if(singleFS)player->playerPanic(true);
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->stop();
ui->hsTimer->setValue(0);chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
QString fns=plistw->getPrevItem();if(fns.length()==0)return on_pbStop_clicked();
ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName().left(QUrl::fromLocalFile(fns).fileName().lastIndexOf('.')));
@@ -471,6 +482,7 @@ void qmpMainWindow::on_pbPrev_clicked()
player->playerInit();if(!singleFS){playerSetup();player->fluidInitialize();
for(int i=settingsw->getSFWidget()->count()-1;i>=0;--i)
LOAD_SOUNDFONT;}
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->start();
player->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -486,6 +498,7 @@ void qmpMainWindow::on_pbNext_clicked()
timer->stop();player->playerDeinit();
if(playerTh){playerTh->join();delete playerTh;playerTh=NULL;}
if(singleFS)player->playerPanic(true);
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->stop();
ui->hsTimer->setValue(0);chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
QString fns=plistw->getNextItem();if(fns.length()==0)return on_pbStop_clicked();
ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName().left(QUrl::fromLocalFile(fns).fileName().lastIndexOf('.')));
@@ -497,6 +510,7 @@ void qmpMainWindow::on_pbNext_clicked()
player->playerInit();if(!singleFS){playerSetup();player->fluidInitialize();
for(int i=settingsw->getSFWidget()->count()-1;i>=0;--i)
LOAD_SOUNDFONT;}
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->start();
player->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -512,6 +526,7 @@ void qmpMainWindow::selectionChanged()
stopped=false;playing=true;
ui->pbPlayPause->setIcon(QIcon(":/img/pause.png"));
timer->stop();player->playerDeinit();
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->stop();
if(playerTh){playerTh->join();delete playerTh;playerTh=NULL;}
if(singleFS)player->playerPanic(true);
ui->hsTimer->setValue(0);
@@ -526,6 +541,7 @@ void qmpMainWindow::selectionChanged()
player->playerInit();if(!singleFS){playerSetup();player->fluidInitialize();
for(int i=settingsw->getSFWidget()->count()-1;i>=0;--i)
LOAD_SOUNDFONT;}
+ for(int i=0;i<16;++i)if(VIs[i])VIs[i]->start();
player->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -570,6 +586,20 @@ void qmpMainWindow::onfnChanged()
ui->lbFileName->setFont(f);
}
+int qmpMainWindow::registerVisualizationIntf(qmpVisualizationIntf* intf)
+{
+ for(int i=0;i<16;++i)
+ {
+ if(VIs[i]==intf)return i;
+ if(VIs[i]==NULL){VIs[i]=intf;return i;}
+ }
+ return -1;
+}
+void qmpMainWindow::unregisterVisualizationIntf(int handle)
+{
+ VIs[handle]=NULL;
+}
+
void qmpMainWindow::onfnA1()
{
infow->show();
@@ -609,3 +639,11 @@ void qmpMainWindow::on_pushButton_clicked()
{
helpw->show();
}
+
+void qmpMainWindow::on_pbVisualization_clicked()
+{
+ if(ui->pbVisualization->isChecked())
+ {for(int i=0;i<16;++i)if(VIs[i])VIs[i]->show();}
+ else
+ {for(int i=0;i<16;++i)if(VIs[i])VIs[i]->close();}
+}
diff --git a/qmidiplayer-desktop/qmpmainwindow.hpp b/qmidiplayer-desktop/qmpmainwindow.hpp
index b88169b..a981559 100644
--- a/qmidiplayer-desktop/qmpmainwindow.hpp
+++ b/qmidiplayer-desktop/qmpmainwindow.hpp
@@ -63,6 +63,8 @@ class qmpMainWindow:public QMainWindow
bool isFinalizing(){return fin;}
QString getFileName();
int pharseArgs();
+ int registerVisualizationIntf(qmpVisualizationIntf* intf);
+ void unregisterVisualizationIntf(int handle);
private slots:
void on_pbPlayPause_clicked();
@@ -84,7 +86,9 @@ class qmpMainWindow:public QMainWindow
void on_pushButton_clicked();
- public slots:
+ void on_pbVisualization_clicked();
+
+ public slots:
void dialogClosed();
void selectionChanged();
@@ -104,6 +108,7 @@ class qmpMainWindow:public QMainWindow
qmpInfoWindow *infow;
qmpSettingsWindow *settingsw;
qmpHelpWindow *helpw;
+ qmpVisualizationIntf* VIs[16];
QAction *fnA1,*fnA2,*fnA3;
void onfnChanged();
diff --git a/qmidiplayer-desktop/qmpmainwindow.ui b/qmidiplayer-desktop/qmpmainwindow.ui
index 2a9a420..69a3496 100644
--- a/qmidiplayer-desktop/qmpmainwindow.ui
+++ b/qmidiplayer-desktop/qmpmainwindow.ui
@@ -492,6 +492,9 @@
<height>32</height>
</size>
</property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</layout>
diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp
index aea01da..a71b869 100644
--- a/qmidiplayer-desktop/qmpplugin.cpp
+++ b/qmidiplayer-desktop/qmpplugin.cpp
@@ -62,25 +62,30 @@ void qmpPluginManager::initPlugins()
plugins[i].interface->init();
}
}
+void qmpPluginManager::deinitPlugins()
+{
+ for(unsigned i=0;i<plugins.size();++i)
+ plugins[i].interface->deinit();
+}
uint32_t qmpPluginAPI::getDivision()
-{return qmw->getPlayer()->getDivision();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getDivision():0;}
uint32_t qmpPluginAPI::getRawTempo()
-{return qmw->getPlayer()->getRawTempo();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getRawTempo():0;}
double qmpPluginAPI::getRealTempo()
-{return qmw->getPlayer()->getTempo();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getTempo():0;}
uint32_t qmpPluginAPI::getTimeSig()
-{int n,d=0,t;qmw->getPlayer()->getCurrentTimeSignature(&n,&t);for(;t>>=1;++d);return n<<8|d;}
+{int n,d=0,t;qmw&&qmw->getPlayer()?qmw->getPlayer()->getCurrentTimeSignature(&n,&t):void(0);for(;t>>=1;++d);return n<<8|d;}
int qmpPluginAPI::getKeySig()
-{return qmw->getPlayer()->getCurrentKeySignature();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getCurrentKeySignature():0;}
uint32_t qmpPluginAPI::getNoteCount()
-{return qmw->getPlayer()->getFileNoteCount();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getFileNoteCount():0;}
uint32_t qmpPluginAPI::getCurrentPolyphone()
-{return qmw->getPlayer()->getPolyphone();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getPolyphone():0;}
uint32_t qmpPluginAPI::getMaxPolyphone()
-{return qmw->getPlayer()->getMaxPolyphone();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getMaxPolyphone():0;}
uint32_t qmpPluginAPI::getCurrentTimeStamp()
-{return qmw->getPlayer()->getTCeptr();}
+{return qmw&&qmw->getPlayer()?qmw->getPlayer()->getTick():0;}
int qmpPluginAPI::registerEventHandlerIntf(IMidiCallBack *cb,void *userdata)
{return qmw->getPlayer()->setEventHandlerCB(cb,userdata);}
void qmpPluginAPI::unregisterEventHandlerIntf(int intfhandle)
@@ -89,8 +94,10 @@ int qmpPluginAPI::registerEventReaderIntf(IMidiCallBack *cb,void *userdata)
{return qmw->getPlayer()->setEventReaderCB(cb,userdata);}
void qmpPluginAPI::unregisterEventReaderIntf(int intfhandle)
{qmw->getPlayer()->unsetEventReaderCB(intfhandle);}
-int qmpPluginAPI::registerVisualizationIntf(qmpVisualizationIntf*){return 0;}
-void qmpPluginAPI::unregisterVisualizationIntf(int){}
+int qmpPluginAPI::registerVisualizationIntf(qmpVisualizationIntf* intf)
+{return qmw->registerVisualizationIntf(intf);}
+void qmpPluginAPI::unregisterVisualizationIntf(int intfhandle)
+{qmw->unregisterVisualizationIntf(intfhandle);}
void qmpPluginAPI::registerOptionInt(std::string,std::string,int){}
int qmpPluginAPI::getOptionInt(std::string){return 0;}
void qmpPluginAPI::registerOptionDouble(std::string,std::string,double){}