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. --- 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 +++++++++- 11 files changed, 304 insertions(+), 22 deletions(-) create mode 100644 qmidiplayer-desktop/qmpdevpropdialog.cpp create mode 100644 qmidiplayer-desktop/qmpdevpropdialog.hpp create mode 100644 qmidiplayer-desktop/qmpdevpropdialog.ui (limited to 'qmidiplayer-desktop') 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