diff options
author | Chris Xiong <chirs241097@gmail.com> | 2020-05-12 00:58:40 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2020-05-12 00:58:40 +0800 |
commit | a7407edaf81c685d4a389785a405a53a5de4b148 (patch) | |
tree | e6e4f2d85f2172c94ac83a6e8f01e1e90a78ede9 /qmidiplayer-desktop/qmppresetselect.cpp | |
parent | 437b7b16c322a8e53ac55a5f831098494d9a7073 (diff) | |
download | QMidiPlayer-a7407edaf81c685d4a389785a405a53a5de4b148.tar.xz |
Format EVERYTHING.
Hopefully this will make the source code less horrendous and actually
readable.
The command used was:
```
astyle --suffix=none --style=allman --attach-extern-c --attach-closing-while --indent-switches --indent-after-parens --pad-oper --pad-header --unpad-paren --align-pointer=name --recursive './*.cpp,*.hpp'
```
Diffstat (limited to 'qmidiplayer-desktop/qmppresetselect.cpp')
-rw-r--r-- | qmidiplayer-desktop/qmppresetselect.cpp | 205 |
1 files changed, 113 insertions, 92 deletions
diff --git a/qmidiplayer-desktop/qmppresetselect.cpp b/qmidiplayer-desktop/qmppresetselect.cpp index 821eced..51bb7d4 100644 --- a/qmidiplayer-desktop/qmppresetselect.cpp +++ b/qmidiplayer-desktop/qmppresetselect.cpp @@ -4,132 +4,153 @@ #include "qmpmainwindow.hpp" qmpPresetSelector::qmpPresetSelector(QWidget *parent) : - QDialog(parent), - ui(new Ui::qmpPresetSelector) + QDialog(parent), + ui(new Ui::qmpPresetSelector) { - ui->setupUi(this); + ui->setupUi(this); } qmpPresetSelector::~qmpPresetSelector() { - delete ui; + delete ui; } void qmpPresetSelector::showEvent(QShowEvent *e) { - memset(presets,0,sizeof(presets)); - if(!qmpMainWindow::getInstance()->getFluid()->getSFCount())return e->ignore(); - ui->lwBankSelect->clear(); - ui->lwPresetSelect->clear(); - e->accept(); + memset(presets, 0, sizeof(presets)); + if (!qmpMainWindow::getInstance()->getFluid()->getSFCount()) + return e->ignore(); + ui->lwBankSelect->clear(); + ui->lwPresetSelect->clear(); + e->accept(); } void qmpPresetSelector::setupWindow(int chid) { - CMidiPlayer *plyr=qmpMainWindow::getInstance()->getPlayer(); - ch=chid;int r;char name[256]; - uint16_t b;uint8_t p; - std::string pstname; - 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(); - ui->lwBankSelect->blockSignals(false); - if(plyr->getChannelOutputDevice(ch)->getBankList().empty()){ - ui->lwPresetSelect->setEnabled(false); - ui->lwBankSelect->setEnabled(false); - ui->spCustomLSB->setEnabled(true); - ui->spCustomMSB->setEnabled(true); - ui->spCustomPC->setEnabled(true); - ui->spCustomMSB->setValue(plyr->getCC(chid,0)); - ui->spCustomLSB->setValue(plyr->getCC(chid,32)); - ui->spCustomPC->setValue(p); - } - else{ - ui->lwPresetSelect->setEnabled(true); - ui->lwBankSelect->setEnabled(true); - ui->spCustomLSB->setEnabled(false); - ui->spCustomMSB->setEnabled(false); - ui->spCustomPC->setEnabled(false); - ui->lwBankSelect->blockSignals(true); - for(auto&i:plyr->getChannelOutputDevice(ch)->getBankList()) - { - snprintf(name,256,"%03d %s",i.first,i.second.c_str()); - ui->lwBankSelect->addItem(name); - if(i.first==b)ui->lwBankSelect->setCurrentRow(ui->lwBankSelect->count()-1); - } - ui->lwBankSelect->blockSignals(false); - for(auto&i:plyr->getChannelOutputDevice(ch)->getPresets(b)) - { - snprintf(name,256,"%03d %s",i.first,i.second.c_str()); - ui->lwPresetSelect->addItem(name); - if(i.first==p)ui->lwPresetSelect->setCurrentRow(ui->lwPresetSelect->count()-1); - } - } + CMidiPlayer *plyr = qmpMainWindow::getInstance()->getPlayer(); + ch = chid; + int r; + char name[256]; + uint16_t b; + uint8_t p; + std::string pstname; + 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(); + ui->lwBankSelect->blockSignals(false); + if (plyr->getChannelOutputDevice(ch)->getBankList().empty()) + { + ui->lwPresetSelect->setEnabled(false); + ui->lwBankSelect->setEnabled(false); + ui->spCustomLSB->setEnabled(true); + ui->spCustomMSB->setEnabled(true); + ui->spCustomPC->setEnabled(true); + ui->spCustomMSB->setValue(plyr->getCC(chid, 0)); + ui->spCustomLSB->setValue(plyr->getCC(chid, 32)); + ui->spCustomPC->setValue(p); + } + else + { + ui->lwPresetSelect->setEnabled(true); + ui->lwBankSelect->setEnabled(true); + ui->spCustomLSB->setEnabled(false); + ui->spCustomMSB->setEnabled(false); + ui->spCustomPC->setEnabled(false); + ui->lwBankSelect->blockSignals(true); + for (auto &i : plyr->getChannelOutputDevice(ch)->getBankList()) + { + snprintf(name, 256, "%03d %s", i.first, i.second.c_str()); + ui->lwBankSelect->addItem(name); + if (i.first == b) + ui->lwBankSelect->setCurrentRow(ui->lwBankSelect->count() - 1); + } + ui->lwBankSelect->blockSignals(false); + for (auto &i : plyr->getChannelOutputDevice(ch)->getPresets(b)) + { + snprintf(name, 256, "%03d %s", i.first, i.second.c_str()); + ui->lwPresetSelect->addItem(name); + if (i.first == p) + ui->lwPresetSelect->setCurrentRow(ui->lwPresetSelect->count() - 1); + } + } } void qmpPresetSelector::on_pbCancel_clicked() { - close(); + close(); } 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 - { - 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); - } - } - else{ - if(!ui->lwBankSelect->currentItem()||!ui->lwPresetSelect->currentItem())return (void)close(); - int b,p; - b=ui->lwBankSelect->currentItem()->text().toInt(); - p=ui->lwPresetSelect->currentItem()->text().split(' ').first().toInt(); - std::string s=qmpMainWindow::getInstance()->getSettings()->getOptionEnumIntOptName("FluidSynth/BankSelect"); - if(s=="XG"){ - if(b==128)b=127<<7; - } - else if(s=="GS")b<<=7; - plyr->setChannelPreset(ch,b,p); - } - qmpMainWindow::getInstance()->invokeCallback("preset.set",nullptr); - close(); + 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 + { + 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); + } + } + else + { + if (!ui->lwBankSelect->currentItem() || !ui->lwPresetSelect->currentItem()) + return (void)close(); + int b, p; + b = ui->lwBankSelect->currentItem()->text().toInt(); + p = ui->lwPresetSelect->currentItem()->text().split(' ').first().toInt(); + std::string s = qmpMainWindow::getInstance()->getSettings()->getOptionEnumIntOptName("FluidSynth/BankSelect"); + if (s == "XG") + { + if (b == 128) + b = 127 << 7; + } + else if (s == "GS") + b <<= 7; + plyr->setChannelPreset(ch, b, p); + } + qmpMainWindow::getInstance()->invokeCallback("preset.set", nullptr); + close(); } void qmpPresetSelector::on_lwPresetSelect_itemDoubleClicked() { - on_pbOk_clicked(); + on_pbOk_clicked(); } void qmpPresetSelector::on_lwBankSelect_currentRowChanged() { - ui->lwPresetSelect->clear(); - if(!ui->lwBankSelect->currentItem())return; - char name[256];int b; - sscanf(ui->lwBankSelect->currentItem()->text().toStdString().c_str(),"%d",&b); - CMidiPlayer *plyr=qmpMainWindow::getInstance()->getPlayer(); - for(auto&i:plyr->getChannelOutputDevice(ch)->getPresets(b)) - { - snprintf(name,256,"%03d %s",i.first,i.second.c_str()); - ui->lwPresetSelect->addItem(name); - } + ui->lwPresetSelect->clear(); + if (!ui->lwBankSelect->currentItem()) + return; + char name[256]; + int b; + sscanf(ui->lwBankSelect->currentItem()->text().toStdString().c_str(), "%d", &b); + CMidiPlayer *plyr = qmpMainWindow::getInstance()->getPlayer(); + for (auto &i : plyr->getChannelOutputDevice(ch)->getPresets(b)) + { + snprintf(name, 256, "%03d %s", i.first, i.second.c_str()); + ui->lwPresetSelect->addItem(name); + } } void qmpPresetSelector::on_buttonBox_accepted() { - on_pbOk_clicked(); + on_pbOk_clicked(); } void qmpPresetSelector::on_buttonBox_rejected() { - on_pbCancel_clicked(); + on_pbCancel_clicked(); } |