diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-06-18 00:51:29 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-06-18 00:51:29 +0800 |
commit | 19c89fc7baa299e523e152a14066ebc8ce23af21 (patch) | |
tree | 893d2643b57cb03092ab520b64dabff753437bbc /qmidiplayer-desktop | |
parent | 795043d6851a355d70aa2341e2edfd526c24d041 (diff) | |
download | QMidiPlayer-19c89fc7baa299e523e152a14066ebc8ce23af21.tar.xz |
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.
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r-- | qmidiplayer-desktop/qmidiplayer-desktop.pro | 9 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpchannelswindow.cpp | 8 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpdevpropdialog.cpp | 96 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpdevpropdialog.hpp | 31 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpdevpropdialog.ui | 101 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpmainwindow.cpp | 7 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmppresetselect.cpp | 8 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmppresetselect.ui | 18 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpsettingswindow.cpp | 8 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpsettingswindow.hpp | 4 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpsettingswindow.ui | 36 |
11 files changed, 304 insertions, 22 deletions
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 <QComboBox> +#include <QHBoxLayout> +#include <QLabel> +#include <QFileDialog> +#include <QTableWidgetItem> +#include <QCheckBox> +#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;i<ui->twProps->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 <QDialog> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>qmpDevPropDialog</class> + <widget class="QDialog" name="qmpDevPropDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>566</width> + <height>388</height> + </rect> + </property> + <property name="windowTitle"> + <string>External Output Device Setup</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QTableWidget" name="twProps"> + <column> + <property name="text"> + <string>Device</string> + </property> + </column> + <column> + <property name="text"> + <string>Connected?</string> + </property> + </column> + <column> + <property name="text"> + <string>Device Initialization File</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="pbAdd"> + <property name="text"> + <string>+</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pbRemove"> + <property name="text"> + <string>-</string> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>qmpDevPropDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>qmpDevPropDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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<std::pair<qmpMidiOutRtMidi*,std::string>> 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 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>qmpPresetSelector</class> - <widget class="QDialog" name="qmpPresetSelector"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>404</width> - <height>300</height> - </rect> - </property> + <widget class="QDialog" name="qmpPresetSelector">\ <property name="minimumSize"> <size> - <width>404</width> + <width>480</width> <height>300</height> </size> </property> <property name="maximumSize"> <size> - <width>404</width> - <height>300</height> + <width>16777215</width> + <height>16777215</height> </size> </property> <property name="windowTitle"> @@ -47,7 +39,7 @@ </property> <property name="maximumSize"> <size> - <width>64</width> + <width>16777215</width> <height>16777215</height> </size> </property> 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 <QFormLayout> #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<std::string,QGridLayout*> 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 @@ <item> <widget class="QLabel" name="lbOutputDevice"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -48,7 +48,7 @@ <item> <widget class="QComboBox" name="cbOutputDevice"> <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -101,7 +101,7 @@ <item> <widget class="QLabel" name="lbEncoding"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -178,6 +178,36 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QLabel" name="lbExtDevSetup"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>External MIDI output device setup</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pbExtDevSetup"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> <widget class="QWidget" name="tab_2"> |