From 19c89fc7baa299e523e152a14066ebc8ce23af21 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 18 Jun 2019 00:51:29 +0800 Subject: Device initialization file implementation (part 1). Added UI for external device configuration. Instrument mapping portion of the device intialization file is now working. Fixed a few spots where return value of getChannelPreset() is ignored. Fixed layout of the preset selection dialog. --- ChangeLog | 8 +++ core/qmpmidioutfluid.cpp | 3 +- core/qmpmidioutfluid.hpp | 2 +- core/qmpmidioutrtmidi.cpp | 52 +++++++++++++- core/qmpmidioutrtmidi.hpp | 5 +- include/qmpcorepublic.hpp | 2 +- qmidiplayer-desktop/qmidiplayer-desktop.pro | 9 ++- qmidiplayer-desktop/qmpchannelswindow.cpp | 8 ++- qmidiplayer-desktop/qmpdevpropdialog.cpp | 96 ++++++++++++++++++++++++++ qmidiplayer-desktop/qmpdevpropdialog.hpp | 31 +++++++++ qmidiplayer-desktop/qmpdevpropdialog.ui | 101 ++++++++++++++++++++++++++++ qmidiplayer-desktop/qmpmainwindow.cpp | 7 +- qmidiplayer-desktop/qmppresetselect.cpp | 8 +++ qmidiplayer-desktop/qmppresetselect.ui | 18 ++--- qmidiplayer-desktop/qmpsettingswindow.cpp | 8 ++- qmidiplayer-desktop/qmpsettingswindow.hpp | 4 ++ qmidiplayer-desktop/qmpsettingswindow.ui | 36 +++++++++- 17 files changed, 371 insertions(+), 27 deletions(-) create mode 100644 qmidiplayer-desktop/qmpdevpropdialog.cpp create mode 100644 qmidiplayer-desktop/qmpdevpropdialog.hpp create mode 100644 qmidiplayer-desktop/qmpdevpropdialog.ui diff --git a/ChangeLog b/ChangeLog index 9c656ed..cd993dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-06-17 0.8.7 indev +Device initialization file implementation (part 1). + +Added UI for external device configuration. +Instrument mapping portion of the device intialization file is now working. +Fixed a few spots where return value of getChannelPreset() is ignored. +Fixed layout of the preset selection dialog. + 2019-06-16 0.8.7 indev Inital implementation of the device properties API. diff --git a/core/qmpmidioutfluid.cpp b/core/qmpmidioutfluid.cpp index 414cb3a..ac6523f 100644 --- a/core/qmpmidioutfluid.cpp +++ b/core/qmpmidioutfluid.cpp @@ -123,7 +123,7 @@ std::vector> qmpMidiOutFluid::getBankList() { return bnk; } -std::vector> qmpMidiOutFluid::getPresets(int bank) +std::vector> qmpMidiOutFluid::getPresets(uint16_t bank) { std::vector> ret; if(pst.find(bank)==pst.end())return ret; @@ -137,6 +137,7 @@ std::vector> qmpMidiOutFluid::getPresets(int bank std::string qmpMidiOutFluid::getPresetName(uint16_t bank,uint8_t preset) { if(pst.find(bank)==pst.end())return ""; + //should consult fluidsynth instead? (4 bank mapping methods) return pst[bank][preset]; } bool qmpMidiOutFluid::getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname) diff --git a/core/qmpmidioutfluid.hpp b/core/qmpmidioutfluid.hpp index 72197e7..d6a62c9 100644 --- a/core/qmpmidioutfluid.hpp +++ b/core/qmpmidioutfluid.hpp @@ -41,7 +41,7 @@ class qmpMidiOutFluid:public qmpMidiOutDevice,public IFluidSettings void onMapped(uint8_t ch,int refcnt); void onUnmapped(uint8_t ch,int refcnt); std::vector> getBankList(); - std::vector> getPresets(int bank); + std::vector> getPresets(uint16_t bank); std::string getPresetName(uint16_t bank,uint8_t preset); bool getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname); uint8_t getInitialCCValue(uint8_t cc); diff --git a/core/qmpmidioutrtmidi.cpp b/core/qmpmidioutrtmidi.cpp index 0ff2c86..2cc9d5b 100644 --- a/core/qmpmidioutrtmidi.cpp +++ b/core/qmpmidioutrtmidi.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include RT_MIDI_H @@ -132,6 +133,27 @@ qmpDeviceInitializer* qmpDeviceInitializer::parse(const char* path) } } } + else if(st_inmapping) + { + if(b.front()=='['&&b.back()==']') + { + b=b.substr(1,b.length()-2); + split(b,':',tok); + if(tok.size()<3)err("invalid bank") + cmsb=strtol(tok[0].c_str(),nullptr,10); + clsb=strtol(tok[1].c_str(),nullptr,10); + ret->banks[cmsb<<7|clsb]=BankStore{{},tok[2]}; + } + else if(b.find('=')!=std::string::npos) + { + if(!~cmsb||!~clsb)err("inst outside a bank") + split(b,'=',tok); + if(tok.size()<2)err("invalid inst") + int p=strtol(tok[0].c_str(),nullptr,10); + ret->banks[cmsb<<7|clsb].presets[p]=tok[1]; + } + else err("invalid mapping line") + } } #undef err @@ -143,10 +165,12 @@ qmpMidiOutRtMidi::qmpMidiOutRtMidi(unsigned _portid) { portid=_portid; outport=nullptr; + devinit=nullptr; } qmpMidiOutRtMidi::~qmpMidiOutRtMidi() { if(!outport)return; + if(devinit){delete devinit;devinit=nullptr;} if(outport->isPortOpen())outport->closePort(); delete outport;outport=nullptr; } @@ -229,18 +253,44 @@ void qmpMidiOutRtMidi::onUnmapped(uint8_t ch,int refcnt) } std::vector> qmpMidiOutRtMidi::getBankList() { + if(!devinit)return{}; + std::vector> ret; + for(auto&i:devinit->banks) + ret.push_back({i.first,i.second.bankname}); + std::sort(ret.begin(),ret.end(),[](std::pair&a,std::pair&b){return a.first> qmpMidiOutRtMidi::getPresets(int bank) +std::vector> qmpMidiOutRtMidi::getPresets(uint16_t bank) { + if(!devinit)return{}; + if(devinit->banks.find(bank)==devinit->banks.end())return{}; + std::vector> ret; + for(auto&i:devinit->banks[bank].presets) + ret.push_back({i.first,i.second}); + std::sort(ret.begin(),ret.end(),[](std::pair&a,std::pair&b){return a.firstbanks.find(bank)!=devinit->banks.end()) + if(devinit->banks[bank].presets.find(preset)!=devinit->banks[bank].presets.end()) + return devinit->banks[bank].presets[preset]; + return""; } bool qmpMidiOutRtMidi::getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname) { + //This ain't a state-tracking device + return false; } uint8_t qmpMidiOutRtMidi::getInitialCCValue(uint8_t cc) { + if(!devinit)return 0;//Nope! +} +void qmpMidiOutRtMidi::setInitializerFile(const char* path) +{ + if(devinit)delete devinit; + devinit=qmpDeviceInitializer::parse(path); } RtMidiOut* qmpRtMidiManager::dummy=nullptr; diff --git a/core/qmpmidioutrtmidi.hpp b/core/qmpmidioutrtmidi.hpp index 23adec6..0c1843c 100644 --- a/core/qmpmidioutrtmidi.hpp +++ b/core/qmpmidioutrtmidi.hpp @@ -23,6 +23,7 @@ class qmpMidiOutRtMidi:public qmpMidiOutDevice private: unsigned portid; RtMidiOut* outport; + qmpDeviceInitializer* devinit; public: qmpMidiOutRtMidi(unsigned _portid); ~qmpMidiOutRtMidi(); @@ -37,10 +38,12 @@ public: void onMapped(uint8_t ch,int refcnt); void onUnmapped(uint8_t ch,int refcnt); std::vector> getBankList(); - std::vector> getPresets(int bank); + std::vector> getPresets(uint16_t bank); std::string getPresetName(uint16_t bank,uint8_t preset); bool getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname); uint8_t getInitialCCValue(uint8_t cc); + + void setInitializerFile(const char* path); }; class qmpRtMidiManager { diff --git a/include/qmpcorepublic.hpp b/include/qmpcorepublic.hpp index 34e4ea6..178fa19 100644 --- a/include/qmpcorepublic.hpp +++ b/include/qmpcorepublic.hpp @@ -95,7 +95,7 @@ class qmpMidiOutDevice virtual void onMapped(uint8_t ch,int refcnt)=0; virtual void onUnmapped(uint8_t ch,int refcnt)=0; virtual std::vector> getBankList()=0; - virtual std::vector> getPresets(int bank)=0; + virtual std::vector> getPresets(uint16_t bank)=0; virtual std::string getPresetName(uint16_t bank,uint8_t preset)=0; virtual bool getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname)=0; virtual uint8_t getInitialCCValue(uint8_t cc)=0; diff --git a/qmidiplayer-desktop/qmidiplayer-desktop.pro b/qmidiplayer-desktop/qmidiplayer-desktop.pro index d942f23..3d127bb 100644 --- a/qmidiplayer-desktop/qmidiplayer-desktop.pro +++ b/qmidiplayer-desktop/qmidiplayer-desktop.pro @@ -29,7 +29,8 @@ SOURCES += main.cpp\ qmpplugin.cpp \ qmpcustomizewindow.cpp \ ../core/qmpmidioutrtmidi.cpp \ - ../core/qmpmidioutfluid.cpp + ../core/qmpmidioutfluid.cpp \ + qmpdevpropdialog.cpp HEADERS += qmpmainwindow.hpp \ ../core/qmpmidiplay.hpp \ @@ -46,7 +47,8 @@ HEADERS += qmpmainwindow.hpp \ qmpplugin.hpp \ qmpcustomizewindow.hpp \ ../core/qmpmidioutrtmidi.hpp \ - ../core/qmpmidioutfluid.hpp + ../core/qmpmidioutfluid.hpp \ + qmpdevpropdialog.hpp FORMS += qmpmainwindow.ui \ qmpplistwindow.ui \ @@ -57,7 +59,8 @@ FORMS += qmpmainwindow.ui \ qmpinfowindow.ui \ qmpsettingswindow.ui \ qmphelpwindow.ui \ - qmpcustomizewindow.ui + qmpcustomizewindow.ui \ + qmpdevpropdialog.ui TRANSLATIONS += translations/qmp_zh_CN.ts DEFINES += BUILD_MACHINE=$${QMAKE_HOST.name} diff --git a/qmidiplayer-desktop/qmpchannelswindow.cpp b/qmidiplayer-desktop/qmpchannelswindow.cpp index 5a6a2de..b029e3e 100644 --- a/qmidiplayer-desktop/qmpchannelswindow.cpp +++ b/qmidiplayer-desktop/qmpchannelswindow.cpp @@ -156,8 +156,14 @@ void qmpChannelsWindow::channelWindowsUpdate() char data[128]; std::string nm; uint16_t b;uint8_t p; - qmpMainWindow::getInstance()->getPlayer()->getChannelOutputDevice(i)->getChannelPreset(i,&b,&p,nm); + CMidiPlayer *plyr=qmpMainWindow::getInstance()->getPlayer(); + bool r=plyr->getChannelOutputDevice(i)->getChannelPreset(i,&b,&p,nm); sprintf(data,"%03d:%03d %s",b,p,nm.c_str()); + if(!r) + { + nm=plyr->getChannelOutputDevice(i)->getPresetName(plyr->getCC(i,0)<<7|plyr->getCC(i,32),plyr->getCC(i,128)); + sprintf(data,"%03d:%03d:%03d %s",plyr->getCC(i,0),plyr->getCC(i,32),plyr->getCC(i,128),nm.c_str()); + } if(fused) { if(strcmp((ui->twChannels->item(i,4))-> diff --git a/qmidiplayer-desktop/qmpdevpropdialog.cpp b/qmidiplayer-desktop/qmpdevpropdialog.cpp new file mode 100644 index 0000000..0159a63 --- /dev/null +++ b/qmidiplayer-desktop/qmpdevpropdialog.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include "qmpdevpropdialog.hpp" +#include "qmpmainwindow.hpp" +#include "qmpsettingswindow.hpp" +#include "ui_qmpdevpropdialog.h" + +qmpDevPropDialog::qmpDevPropDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::qmpDevPropDialog) +{ + ui->setupUi(this); +} + +qmpDevPropDialog::~qmpDevPropDialog() +{ + delete ui; +} + +void qmpDevPropDialog::launch() +{ + QSettings *s=qmpSettingsWindow::getSettingsIntf(); + ui->twProps->clearContents(); + ui->twProps->setRowCount(0); + s->beginGroup("DevInit"); + for(auto&k:s->allKeys()) + setupRow(k,s->value(k).toString()); + s->endGroup(); + show(); +} + +void qmpDevPropDialog::on_pbAdd_clicked() +{ + setupRow(); +} + +void qmpDevPropDialog::on_pbRemove_clicked() +{ + ui->twProps->removeRow(ui->twProps->currentRow()); +} + +void qmpDevPropDialog::setupRow(const QString&dn,const QString&din) +{ + int r; + ui->twProps->insertRow(r=ui->twProps->rowCount()); + ui->twProps->setRowHeight(r,32); + QComboBox *cb; + ui->twProps->setCellWidget(r,0,cb=new QComboBox); + for(auto&s:qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices()) + if(s!="Internal FluidSynth")cb->addItem(QString::fromStdString(s)); + QWidget *fw=new QWidget; + QLabel *lb;QPushButton *pb; + fw->setLayout(new QHBoxLayout); + fw->layout()->addWidget(lb=new QLabel); + lb->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); + if(din.length()){lb->setText(din);fw->setProperty("fn",din);} + fw->layout()->addWidget(pb=new QPushButton); + pb->setText("..."); + pb->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); + QCheckBox *cbx; + ui->twProps->setCellWidget(r,1,cbx=new QCheckBox); + cbx->setEnabled(false); + cbx->setChecked(false); + ui->twProps->setCellWidget(r,2,fw); + ui->twProps->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents); + connect(cb,&QComboBox::currentTextChanged,this,[this,r](const QString&s){ + bool conn=false; + for(auto&ds:qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices()) + if(s==QString::fromStdString(ds)){conn=true;break;} + ((QCheckBox*)ui->twProps->cellWidget(r,1))->setChecked(conn); + }); + if(dn.length())cb->setCurrentText(dn); + emit cb->currentTextChanged(cb->currentText()); + connect(pb,&QPushButton::clicked,this,[this,lb,fw]{ + lb->setText(QFileDialog::getOpenFileUrl(this,"Select Device Initialization File",QUrl()).path()); + fw->setProperty("fn",lb->text()); + }); +} + +void qmpDevPropDialog::on_buttonBox_accepted() +{ + QSettings *s=qmpSettingsWindow::getSettingsIntf(); + s->beginGroup("DevInit"); + s->remove(""); + for(int i=0;itwProps->rowCount();++i) + { + s->setValue(((QComboBox*)ui->twProps->cellWidget(i,0))->currentText(), + ui->twProps->cellWidget(i,2)->property("fn").toString()); + } + s->endGroup(); + s->sync(); +} diff --git a/qmidiplayer-desktop/qmpdevpropdialog.hpp b/qmidiplayer-desktop/qmpdevpropdialog.hpp new file mode 100644 index 0000000..cd0d150 --- /dev/null +++ b/qmidiplayer-desktop/qmpdevpropdialog.hpp @@ -0,0 +1,31 @@ +#ifndef QMPDEVPROPDIALOG_HPP +#define QMPDEVPROPDIALOG_HPP + +#include + +namespace Ui { +class qmpDevPropDialog; +} + +class qmpDevPropDialog : public QDialog +{ + Q_OBJECT + + public: + explicit qmpDevPropDialog(QWidget *parent = nullptr); + void launch(); + ~qmpDevPropDialog(); + + private slots: + void on_pbAdd_clicked(); + + void on_pbRemove_clicked(); + + void on_buttonBox_accepted(); + + private: + Ui::qmpDevPropDialog *ui; + void setupRow(const QString &dn="",const QString &din=""); +}; + +#endif // QMPDEVPROPDIALOG_HPP diff --git a/qmidiplayer-desktop/qmpdevpropdialog.ui b/qmidiplayer-desktop/qmpdevpropdialog.ui new file mode 100644 index 0000000..6cea5c0 --- /dev/null +++ b/qmidiplayer-desktop/qmpdevpropdialog.ui @@ -0,0 +1,101 @@ + + + qmpDevPropDialog + + + + 0 + 0 + 566 + 388 + + + + External Output Device Setup + + + + + + + Device + + + + + Connected? + + + + + Device Initialization File + + + + + + + + + + + + + + + + + + - + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + qmpDevPropDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + qmpDevPropDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp index cd00b2e..cc8b80d 100644 --- a/qmidiplayer-desktop/qmpmainwindow.cpp +++ b/qmidiplayer-desktop/qmpmainwindow.cpp @@ -85,7 +85,12 @@ void qmpMainWindow::init() rtmididev=new qmpRtMidiManager(); rtmididev->createDevices(); std::vector> rtdev=rtmididev->getDevices(); - for(auto &i:rtdev)player->registerMidiOutDevice(i.first,i.second); + for(auto &i:rtdev) + { + player->registerMidiOutDevice(i.first,i.second); + QString di=qmpSettingsWindow::getSettingsIntf()->value(QString("DevInit/%1").arg(QString::fromStdString(i.second)),"").toString(); + if(di.length())i.first->setInitializerFile(di.toUtf8().data()); + } reloadsynf=new qmpReloadSynthFunc(this); playerSetup(player->fluid());player->fluid()->deviceInit(); loadSoundFont(player->fluid()); diff --git a/qmidiplayer-desktop/qmppresetselect.cpp b/qmidiplayer-desktop/qmppresetselect.cpp index a32aa99..6683e49 100644 --- a/qmidiplayer-desktop/qmppresetselect.cpp +++ b/qmidiplayer-desktop/qmppresetselect.cpp @@ -34,6 +34,7 @@ void qmpPresetSelector::setupWindow(int chid) sprintf(name,"Preset Selection - Channel #%d",ch+1); setWindowTitle(name); r=plyr->getChannelOutputDevice(ch)->getChannelPreset(ch,&b,&p,pstname); + if(!r){b=plyr->getCC(ch,0)<<7|plyr->getCC(ch,32);p=plyr->getCC(ch,128);} ui->lwBankSelect->blockSignals(true); ui->lwBankSelect->clear(); ui->lwPresetSelect->clear(); @@ -80,7 +81,14 @@ void qmpPresetSelector::on_pbOk_clicked() { CMidiPlayer *plyr=qmpMainWindow::getInstance()->getPlayer(); if(plyr->getChannelOutput(ch)){ + if(ui->spCustomMSB->isEnabled()) plyr->setChannelPreset(ch,(ui->spCustomMSB->value()<<7)|ui->spCustomLSB->value(),ui->spCustomPC->value()); + else + { + int b=ui->lwBankSelect->currentItem()->text().split(' ').first().toInt(); + int p=ui->lwPresetSelect->currentItem()->text().split(' ').first().toInt(); + plyr->setChannelPreset(ch,b,p); + } } else{ if(!ui->lwBankSelect->currentItem()||!ui->lwPresetSelect->currentItem())return (void)close(); diff --git a/qmidiplayer-desktop/qmppresetselect.ui b/qmidiplayer-desktop/qmppresetselect.ui index a52b97b..0168d19 100644 --- a/qmidiplayer-desktop/qmppresetselect.ui +++ b/qmidiplayer-desktop/qmppresetselect.ui @@ -1,25 +1,17 @@ qmpPresetSelector - - - - 0 - 0 - 404 - 300 - - + \ - 404 + 480 300 - 404 - 300 + 16777215 + 16777215 @@ -47,7 +39,7 @@ - 64 + 16777215 16777215 diff --git a/qmidiplayer-desktop/qmpsettingswindow.cpp b/qmidiplayer-desktop/qmpsettingswindow.cpp index b14ff4d..08a76fd 100644 --- a/qmidiplayer-desktop/qmpsettingswindow.cpp +++ b/qmidiplayer-desktop/qmpsettingswindow.cpp @@ -30,11 +30,12 @@ qmpSettingsWindow::qmpSettingsWindow(QWidget *parent) : ui->pbDown->setIcon(QIcon(getThemedIcon(":/img/down.svg"))); ui->pbUp->setIcon(QIcon(getThemedIcon(":/img/up.svg"))); cw=new qmpCustomizeWindow(this); + dps=new qmpDevPropDialog(this); } qmpSettingsWindow::~qmpSettingsWindow() { - delete cw; + delete cw;delete dps; delete settings;settings=nullptr; delete ui; } @@ -740,3 +741,8 @@ void QFileEdit::chooseFile() QString s=QFileDialog::getOpenFileName(nullptr,tr("Select a file"),QFileInfo(text()).dir().absolutePath()); if(s.length())setText(s); } + +void qmpSettingsWindow::on_pbExtDevSetup_clicked() +{ + dps->launch(); +} diff --git a/qmidiplayer-desktop/qmpsettingswindow.hpp b/qmidiplayer-desktop/qmpsettingswindow.hpp index f186969..72b0aa1 100644 --- a/qmidiplayer-desktop/qmpsettingswindow.hpp +++ b/qmidiplayer-desktop/qmpsettingswindow.hpp @@ -14,6 +14,7 @@ #include #include "qmpplugin.hpp" #include "qmpcustomizewindow.hpp" +#include "qmpdevpropdialog.hpp" namespace Ui { class qmpSettingsWindow; @@ -130,6 +131,8 @@ class qmpSettingsWindow:public QDialog void on_pbCustomizeAct_clicked(); + void on_pbExtDevSetup_clicked(); + private: Ui::qmpSettingsWindow *ui; void settingsUpdate(); @@ -137,6 +140,7 @@ class qmpSettingsWindow:public QDialog std::map customOptPages; void updateCustomOptions(); qmpCustomizeWindow *cw; + qmpDevPropDialog *dps; static QSettings *settings; static QComboBox* outwidget; public: diff --git a/qmidiplayer-desktop/qmpsettingswindow.ui b/qmidiplayer-desktop/qmpsettingswindow.ui index dc9a8b0..a2400c5 100644 --- a/qmidiplayer-desktop/qmpsettingswindow.ui +++ b/qmidiplayer-desktop/qmpsettingswindow.ui @@ -35,7 +35,7 @@ - + 0 0 @@ -48,7 +48,7 @@ - + 0 0 @@ -101,7 +101,7 @@ - + 0 0 @@ -178,6 +178,36 @@ + + + + + + + 0 + 0 + + + + External MIDI output device setup + + + + + + + + 0 + 0 + + + + ... + + + + + -- cgit v1.2.3