diff options
author | Chris Xiong <chirs241097@gmail.com> | 2020-01-11 23:26:03 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2020-01-11 23:26:03 +0800 |
commit | f7f2e9039cfd6c3d07a28137e321fa96b0267084 (patch) | |
tree | 1fd53d58a388b575881dce827520b3a8d6984fbb | |
parent | 12ad6495fa332ea499485082272f796c4b08c83c (diff) | |
download | QMidiPlayer-f7f2e9039cfd6c3d07a28137e321fa96b0267084.tar.xz |
Code refactoring for qmpChannelEditor.
Do not crash if preset selection dialog is closed with no preset selected.
More translatable strings in qmpChannelEditor.
-rw-r--r-- | core/qmpmidiplay.cpp | 2 | ||||
-rw-r--r-- | core/qmpmidiplay.hpp | 2 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpchanneleditor.cpp | 141 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpchanneleditor.hpp | 4 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmppresetselect.cpp | 1 | ||||
-rw-r--r-- | qmidiplayer-desktop/translations/qmp_zh_CN.ts | 85 |
6 files changed, 126 insertions, 109 deletions
diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp index c24b0c9..4cb5430 100644 --- a/core/qmpmidiplay.cpp +++ b/core/qmpmidiplay.cpp @@ -450,7 +450,7 @@ void CMidiPlayer::setSolo(int ch,bool s) {setBit(solo,ch,s?1:0);} bool CMidiPlayer::getChannelMask(int ch) {return((mute>>ch)&1)||(solo&&!((solo>>ch)&1));} -int CMidiPlayer::getCC(int ch,int id) +uint16_t CMidiPlayer::getCC(int ch,int id) { if(chstatus[ch][id]==0xff) return getChannelOutputDevice(ch)->getInitialCCValue(uint8_t(id),uint8_t(ch)); diff --git a/core/qmpmidiplay.hpp b/core/qmpmidiplay.hpp index c3833a5..2fd81a0 100644 --- a/core/qmpmidiplay.hpp +++ b/core/qmpmidiplay.hpp @@ -146,7 +146,7 @@ class CMidiPlayer void setMute(int ch,bool m); void setSolo(int ch,bool s); bool getChannelMask(int ch); - int getCC(int ch,int id); + uint16_t getCC(int ch,int id); void setCC(int ch,int id,int val); qmpMidiOutFluid* fluid(); diff --git a/qmidiplayer-desktop/qmpchanneleditor.cpp b/qmidiplayer-desktop/qmpchanneleditor.cpp index 103d612..445b68e 100644 --- a/qmidiplayer-desktop/qmpchanneleditor.cpp +++ b/qmidiplayer-desktop/qmpchanneleditor.cpp @@ -3,15 +3,15 @@ #include "ui_qmpchanneleditor.h" #include "qmpmainwindow.hpp" -qmpChannelEditor::qmpChannelEditor(QWidget *parent) : +qmpChannelEditor::qmpChannelEditor(QWidget *parent): QDialog(parent), ui(new Ui::qmpChannelEditor) { ui->setupUi(this);ch=0; styl=new QDialSkulptureStyle(); - QList<QDial*> dials=findChildren<QDial*>(); - for(int i=0;i<dials.count();++i) - dials.at(i)->setStyle(styl); + dials=findChildren<QDial*>(); + for(auto&d:dials) + d->setStyle(styl); } qmpChannelEditor::~qmpChannelEditor() @@ -36,27 +36,30 @@ void qmpChannelEditor::setupWindow(int chid) sprintf(str,"BK: %03d",b);ui->lbBank->setText(str); sprintf(str,"PC: %03d",p);ui->lbPreset->setText(str); ui->lbChannelNumber->setText(QString::number(ch+1)); -#define setupControl(ccid,lb,d,ccname)\ - b=player->getCC(ch,ccid);\ - sprintf(str,"%s %d",ccname,b);\ - ui->lb->setText(str);\ - ui->d->setValue(b); - setupControl(7,lbVol,dVol,"Vol."); - setupControl(91,lbReverb,dReverb,"Rev."); - setupControl(93,lbChorus,dChorus,"Chr."); - setupControl(71,lbReso,dReso,"Res."); - setupControl(74,lbCut,dCut,"Cut."); - setupControl(73,lbAttack,dAttack,"Atk."); - setupControl(75,lbDecay,dDecay,"Dec."); - setupControl(72,lbRelease,dRelease,"Rel."); - setupControl(76,lbRate,dRate,"Rate"); - setupControl(77,lbDepth,dDepth,"Dep."); - setupControl(78,lbDelay,dDelay,"Del."); - b=player->getCC(ch,10); - if(b==64)strcpy(str,"Pan. C"); - else if(b<64)sprintf(str,"Pan. L%d",64-b);else sprintf(str,"Pan. R%d",b-64); - ui->lbPan->setText(str); - ui->dPan->setValue(b); + auto setupControl=[this,player](int ccid,QLabel* lb,QDial* d,QString ccname,std::function<QString(uint16_t)> valconv) + { + uint16_t b=player->getCC(ch,ccid); + lb->setText(QString("%1 %2").arg(ccname).arg(valconv(b))); + d->setValue(b); + }; + auto defconv=std::bind(static_cast<QString(*)(uint,int)>(&QString::number),std::placeholders::_1,10); + auto panconv=[](uint v)->QString{ + if(v==64)return tr("C"); + else if(v<64)return tr("L%1").arg(64-v); + else return tr("R%1").arg(v-64); + }; + setupControl(7,ui->lbVol,ui->dVol,tr("Vol."),defconv); + setupControl(91,ui->lbReverb,ui->dReverb,tr("Rev."),defconv); + setupControl(93,ui->lbChorus,ui->dChorus,tr("Chr."),defconv); + setupControl(71,ui->lbReso,ui->dReso,tr("Res."),defconv); + setupControl(74,ui->lbCut,ui->dCut,tr("Cut."),defconv); + setupControl(73,ui->lbAttack,ui->dAttack,tr("Atk."),defconv); + setupControl(75,ui->lbDecay,ui->dDecay,tr("Dec."),defconv); + setupControl(72,ui->lbRelease,ui->dRelease,tr("Rel."),defconv); + setupControl(76,ui->lbRate,ui->dRate,tr("Rate"),defconv); + setupControl(77,ui->lbDepth,ui->dDepth,tr("Dep."),defconv); + setupControl(78,ui->lbDelay,ui->dDelay,tr("Del."),defconv); + setupControl(10,ui->lbPan,ui->dPan,tr("Pan."),panconv); } void qmpChannelEditor::sendCC() @@ -120,84 +123,20 @@ void qmpChannelEditor::commonChanged() void qmpChannelEditor::connectSlots() { - connect(ui->dCut,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dReso,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dReverb,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dChorus,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dVol,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dPan,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dAttack,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dDecay,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dRelease,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dRate,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dDepth,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - connect(ui->dDelay,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - - connect(ui->dCut,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dReso,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dReverb,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dChorus,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dVol,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dPan,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dAttack,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dDecay,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dRelease,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dRate,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dDepth,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - connect(ui->dDelay,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - - connect(ui->dCut,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dReso,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dReverb,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dChorus,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dVol,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dPan,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dAttack,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dDecay,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dRelease,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dRate,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dDepth,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - connect(ui->dDelay,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); + for(auto&d:dials) + { + connect(d,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); + connect(d,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); + connect(d,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); + } } void qmpChannelEditor::disconnectSlots() { - disconnect(ui->dCut,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dReso,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dReverb,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dChorus,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dVol,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dPan,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dAttack,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dDecay,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dRelease,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dRate,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dDepth,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - disconnect(ui->dDelay,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); - - disconnect(ui->dCut,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dReso,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dReverb,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dChorus,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dVol,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dPan,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dAttack,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dDecay,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dRelease,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dRate,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dDepth,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - disconnect(ui->dDelay,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); - - disconnect(ui->dCut,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dReso,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dReverb,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dChorus,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dVol,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dPan,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dAttack,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dDecay,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dRelease,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dRate,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dDepth,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); - disconnect(ui->dDelay,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); + for(auto&d:dials) + { + disconnect(d,&QDial::sliderPressed,this,&qmpChannelEditor::commonPressed); + disconnect(d,&QDial::sliderReleased,this,&qmpChannelEditor::commonReleased); + disconnect(d,&QDial::valueChanged,this,&qmpChannelEditor::commonChanged); + } } diff --git a/qmidiplayer-desktop/qmpchanneleditor.hpp b/qmidiplayer-desktop/qmpchanneleditor.hpp index 350db1e..c7ef028 100644 --- a/qmidiplayer-desktop/qmpchanneleditor.hpp +++ b/qmidiplayer-desktop/qmpchanneleditor.hpp @@ -10,12 +10,13 @@ namespace Ui { class qmpChannelEditor; } +class QDial; class qmpChannelEditor:public QDialog { Q_OBJECT public: - explicit qmpChannelEditor(QWidget *parent=0); + explicit qmpChannelEditor(QWidget *parent=nullptr); ~qmpChannelEditor(); protected: void showEvent(QShowEvent *e); @@ -36,6 +37,7 @@ class qmpChannelEditor:public QDialog void sendCC(); void connectSlots(); void disconnectSlots(); + QList<QDial*> dials; QMetaObject::Connection updconn; QCommonStyle* styl; }; diff --git a/qmidiplayer-desktop/qmppresetselect.cpp b/qmidiplayer-desktop/qmppresetselect.cpp index 85dc893..8286053 100644 --- a/qmidiplayer-desktop/qmppresetselect.cpp +++ b/qmidiplayer-desktop/qmppresetselect.cpp @@ -84,6 +84,7 @@ void qmpPresetSelector::on_pbOk_clicked() plyr->setChannelPreset(ch,(ui->spCustomMSB->value()<<7)|ui->spCustomLSB->value(),ui->spCustomPC->value()); else { + if(!ui->lwBankSelect->currentItem()||!ui->lwPresetSelect->currentItem())return (void)close(); int b=ui->lwBankSelect->currentItem()->text().split(' ').first().toInt(); int p=ui->lwPresetSelect->currentItem()->text().split(' ').first().toInt(); plyr->setChannelPreset(ch,b,p); diff --git a/qmidiplayer-desktop/translations/qmp_zh_CN.ts b/qmidiplayer-desktop/translations/qmp_zh_CN.ts index c9e0800..233129e 100644 --- a/qmidiplayer-desktop/translations/qmp_zh_CN.ts +++ b/qmidiplayer-desktop/translations/qmp_zh_CN.ts @@ -12,27 +12,27 @@ <context> <name>main</name> <message> - <location filename="../main.cpp" line="51"/> + <location filename="../main.cpp" line="59"/> <source>A cross-platform MIDI player.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../main.cpp" line="54"/> + <location filename="../main.cpp" line="62"/> <source>midi files to play (optional).</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../main.cpp" line="55"/> + <location filename="../main.cpp" line="63"/> <source>Load a plugin from <plugin library>.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../main.cpp" line="56"/> + <location filename="../main.cpp" line="64"/> <source>Load all files from the same folder.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../main.cpp" line="58"/> + <location filename="../main.cpp" line="66"/> <source>Keep console window open.</source> <translation type="unfinished"></translation> </message> @@ -164,6 +164,81 @@ <source>Channel Parameter Editor - Channel #%1</source> <translation type="unfinished">通道参数编辑器 通道#%1</translation> </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="47"/> + <source>C</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="48"/> + <source>L%1</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="49"/> + <source>R%1</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="51"/> + <source>Vol.</source> + <translation type="unfinished">音量</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="52"/> + <source>Rev.</source> + <translation type="unfinished">混响</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="53"/> + <source>Chr.</source> + <translation type="unfinished">合奏</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="54"/> + <source>Res.</source> + <translation type="unfinished">共鸣</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="55"/> + <source>Cut.</source> + <translation type="unfinished">截止</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="56"/> + <source>Atk.</source> + <translation type="unfinished">上升</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="57"/> + <source>Dec.</source> + <translation type="unfinished">衰减</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="58"/> + <source>Rel.</source> + <translation type="unfinished">余韵</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="59"/> + <source>Rate</source> + <translation type="unfinished">频率</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="60"/> + <source>Dep.</source> + <translation type="unfinished">振幅</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="61"/> + <source>Del.</source> + <translation type="unfinished">延迟</translation> + </message> + <message> + <location filename="../qmpchanneleditor.cpp" line="62"/> + <source>Pan.</source> + <translation type="unfinished">位置</translation> + </message> </context> <context> <name>qmpChannelsWindow</name> |