diff options
Diffstat (limited to 'muse2/muse/widgets/arrangercolumns.cpp')
-rw-r--r-- | muse2/muse/widgets/arrangercolumns.cpp | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/muse2/muse/widgets/arrangercolumns.cpp b/muse2/muse/widgets/arrangercolumns.cpp new file mode 100644 index 00000000..883ba08c --- /dev/null +++ b/muse2/muse/widgets/arrangercolumns.cpp @@ -0,0 +1,168 @@ +//========================================================= +// MusE +// Linux Music Editor +// $Id: arrangercolumns.cpp, flo93 $ +// +// (C) Copyright 2012 Florian Jung (florian.a.jung@web.de) +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; version 2 of +// the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//========================================================= + +#include "arrangercolumns.h" +#include "midictrl.h" +#include "arranger.h" + +namespace MusEGui { + +ArrangerColumns::ArrangerColumns(QWidget* parent) : QDialog(parent) +{ + setupUi(this); + + initList(); + + connect(ctrlType,SIGNAL(activated(int)), SLOT(ctrlTypeChanged(int))); + // connect(ctrlType,SIGNAL(activated(int)), SLOT(somethingChanged())); // called by ctrlTypeChanged + connect(nameEdit,SIGNAL(textEdited(const QString&)), SLOT(somethingChanged())); + connect(spinBoxHCtrlNo,SIGNAL(valueChanged(int)), SLOT(somethingChanged())); + connect(spinBoxLCtrlNo,SIGNAL(valueChanged(int)), SLOT(somethingChanged())); + connect(listWidget,SIGNAL(currentRowChanged(int)), SLOT(itemSelected(int))); + connect(addBtn,SIGNAL(clicked()), SLOT(addEntry())); + connect(delBtn,SIGNAL(clicked()), SLOT(delEntry())); + + somethingChanged(); + ctrlTypeChanged(ctrlType->currentIndex()); +} + +void ArrangerColumns::ctrlTypeChanged(int idx) +{ + MusECore::MidiController::ControllerType t = (MusECore::MidiController::ControllerType)idx; + + switch (t) + { + case MusECore::MidiController::Controller7: + spinBoxHCtrlNo->setEnabled(false); + spinBoxLCtrlNo->setEnabled(true); + break; + + case MusECore::MidiController::RPN: + case MusECore::MidiController::NRPN: + case MusECore::MidiController::Controller14: + case MusECore::MidiController::RPN14: + case MusECore::MidiController::NRPN14: + spinBoxHCtrlNo->setEnabled(true); + spinBoxLCtrlNo->setEnabled(true); + break; + + default: + spinBoxHCtrlNo->setEnabled(false); + spinBoxLCtrlNo->setEnabled(false); + break; + } + + somethingChanged(); +} + +void ArrangerColumns::somethingChanged() +{ + int row=listWidget->currentRow(); + if (row!=-1) + { + int hnum = spinBoxHCtrlNo->value(); + int lnum = spinBoxLCtrlNo->value(); + MusECore::MidiController::ControllerType t = (MusECore::MidiController::ControllerType)ctrlType->currentIndex(); + int ctrl_number = MusECore::MidiController::genNum(t, hnum, lnum); + + Arranger::new_custom_columns[row].name=nameEdit->text(); + Arranger::new_custom_columns[row].ctrl=ctrl_number; + + listWidget->currentItem()->setText(getListEntryString(row)); + } +} + +QString ArrangerColumns::getListEntryString(int row) +{ + return "\""+Arranger::new_custom_columns[row].name+"\": "+MusECore::midiCtrlNumString(Arranger::new_custom_columns[row].ctrl, true); +} + +void ArrangerColumns::initList() +{ + listWidget->clear(); + + for (unsigned int i=0;i<Arranger::new_custom_columns.size(); i++) + listWidget->addItem(getListEntryString(i)); +} + +void ArrangerColumns::itemSelected(int i) +{ + if (i==-1) + { + frame->setEnabled(false); + delBtn->setEnabled(false); + } + else + { + frame->setEnabled(true); + delBtn->setEnabled(true); + + nameEdit->setText(Arranger::new_custom_columns[i].name); + int num=Arranger::new_custom_columns[i].ctrl; + ctrlType->setCurrentIndex(MusECore::midiControllerType(num)); + if (spinBoxHCtrlNo->isEnabled()) + spinBoxHCtrlNo->setValue((num & 0xFF00)>>8); + else + spinBoxHCtrlNo->setValue(0); + + if (spinBoxLCtrlNo->isEnabled()) + spinBoxLCtrlNo->setValue(num & 0xFF); + else + spinBoxLCtrlNo->setValue(0); + } +} + +void ArrangerColumns::addEntry() +{ + Arranger::new_custom_columns.push_back(Arranger::custom_col_t(0,QString("?"))); + listWidget->addItem(getListEntryString(listWidget->count())); + listWidget->setCurrentRow(listWidget->count()-1); +} + +void ArrangerColumns::delEntry() +{ + int row=listWidget->currentRow(); + + if (row!=-1) + { + std::vector<Arranger::custom_col_t>::iterator it=Arranger::new_custom_columns.begin(); + advance(it, row); + Arranger::new_custom_columns.erase(it); + + initList(); + + if (listWidget->count()>0) + { + if (listWidget->count()<=row) + row=listWidget->count()-1; + + listWidget->setCurrentRow(row); + itemSelected(row); + } + else + itemSelected(-1); + } +} + +} // namespace MusEGui + |