Mercurial > hg > svgui
diff widgets/PluginParameterBox.cpp @ 63:fb02fe13ff47
* Add editing for auralisation plugin parameters and programs
* Rename and reorganise the sample plugin sample set
author | Chris Cannam |
---|---|
date | Thu, 23 Mar 2006 15:49:41 +0000 |
parents | 50429a56680f |
children | 10bcd53ddc71 |
line wrap: on
line diff
--- a/widgets/PluginParameterBox.cpp Wed Mar 22 17:38:29 2006 +0000 +++ b/widgets/PluginParameterBox.cpp Thu Mar 23 15:49:41 2006 +0000 @@ -19,6 +19,8 @@ #include <QDoubleSpinBox> #include <QGridLayout> +#include <QComboBox> +#include <QCheckBox> #include <QLayout> #include <QLabel> @@ -42,15 +44,41 @@ PluginParameterBox::populate() { PluginInstance::ParameterList params = m_plugin->getParameterDescriptors(); + PluginInstance::ProgramList programs = m_plugin->getPrograms(); m_params.clear(); - if (params.empty()) { + if (params.empty() && programs.empty()) { m_layout->addWidget (new QLabel(tr("This plugin has no adjustable parameters.")), 0, 0); } + int offset = 0; + + if (!programs.empty()) { + + std::string currentProgram = m_plugin->getCurrentProgram(); + + QComboBox *programCombo = new QComboBox; + programCombo->setMaxVisibleItems(20); + + for (int i = 0; i < programs.size(); ++i) { + programCombo->addItem(programs[i].c_str()); + if (programs[i] == currentProgram) { + programCombo->setCurrentIndex(i); + } + } + + m_layout->addWidget(new QLabel(tr("Program")), 0, 0); + m_layout->addWidget(programCombo, 0, 1, 1, 2); + + connect(programCombo, SIGNAL(currentIndexChanged(const QString &)), + this, SLOT(programComboChanged(const QString &))); + + offset = 1; + } + for (size_t i = 0; i < params.size(); ++i) { QString name = params[i].name.c_str(); @@ -79,37 +107,54 @@ // an integer! QLabel *label = new QLabel(description); - m_layout->addWidget(label, i, 0); - - AudioDial *dial = new AudioDial; - dial->setObjectName(name); - dial->setMinimum(imin); - dial->setMaximum(imax); - dial->setPageStep(1); - dial->setNotchesVisible((imax - imin) <= 12); - dial->setDefaultValue(int((deft - min) / qtz)); - dial->setValue(int((value - min) / qtz)); - dial->setFixedWidth(32); - dial->setFixedHeight(32); - connect(dial, SIGNAL(valueChanged(int)), - this, SLOT(dialChanged(int))); - m_layout->addWidget(dial, i, 1); - - QDoubleSpinBox *spinbox = new QDoubleSpinBox; - spinbox->setObjectName(name); - spinbox->setMinimum(min); - spinbox->setMaximum(max); - spinbox->setSuffix(QString(" %1").arg(unit)); - spinbox->setSingleStep(qtz); - spinbox->setValue(value); - connect(spinbox, SIGNAL(valueChanged(double)), - this, SLOT(spinBoxChanged(double))); - m_layout->addWidget(spinbox, i, 2); + m_layout->addWidget(label, i + offset, 0); ParamRec rec; - rec.dial = dial; - rec.spin = spinbox; rec.param = params[i]; + rec.dial = 0; + rec.spin = 0; + rec.check = 0; + + if (min == 0.0 && max == 1.0 && qtz == 1.0) { + + QCheckBox *checkbox = new QCheckBox; + checkbox->setObjectName(name); + checkbox->setCheckState(value == 0.0 ? Qt::Unchecked : Qt::Checked); + connect(checkbox, SIGNAL(stateChanged(int)), + this, SLOT(checkBoxChanged(int))); + m_layout->addWidget(checkbox, i + offset, 2); + rec.check = checkbox; + + } else { + + AudioDial *dial = new AudioDial; + dial->setObjectName(name); + dial->setMinimum(imin); + dial->setMaximum(imax); + dial->setPageStep(1); + dial->setNotchesVisible((imax - imin) <= 12); + dial->setDefaultValue(int((deft - min) / qtz)); + dial->setValue(int((value - min) / qtz)); + dial->setFixedWidth(32); + dial->setFixedHeight(32); + connect(dial, SIGNAL(valueChanged(int)), + this, SLOT(dialChanged(int))); + m_layout->addWidget(dial, i + offset, 1); + + QDoubleSpinBox *spinbox = new QDoubleSpinBox; + spinbox->setObjectName(name); + spinbox->setMinimum(min); + spinbox->setMaximum(max); + spinbox->setSuffix(QString(" %1").arg(unit)); + spinbox->setSingleStep(qtz); + spinbox->setValue(value); + connect(spinbox, SIGNAL(valueChanged(double)), + this, SLOT(spinBoxChanged(double))); + m_layout->addWidget(spinbox, i + offset, 2); + rec.dial = dial; + rec.spin = spinbox; + } + m_params[name] = rec; } } @@ -140,14 +185,33 @@ float newValue = min + ival * qtz; QDoubleSpinBox *spin = m_params[name].spin; - spin->blockSignals(true); - spin->setValue(newValue); - spin->blockSignals(false); + if (spin) { + spin->blockSignals(true); + spin->setValue(newValue); + spin->blockSignals(false); + } m_plugin->setParameter(name.toStdString(), newValue); } void +PluginParameterBox::checkBoxChanged(int state) +{ + QObject *obj = sender(); + QString name = obj->objectName(); + + if (m_params.find(name) == m_params.end()) { + std::cerr << "WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl; + return; + } + + PluginInstance::ParameterDescriptor params = m_params[name].param; + + if (state) m_plugin->setParameter(name.toStdString(), 1.0); + else m_plugin->setParameter(name.toStdString(), 0.0); +} + +void PluginParameterBox::spinBoxChanged(double value) { QObject *obj = sender(); @@ -182,11 +246,48 @@ int ival = (value - min) / qtz; AudioDial *dial = m_params[name].dial; - dial->blockSignals(true); - dial->setValue(ival); - dial->blockSignals(false); + if (dial) { + dial->blockSignals(true); + dial->setValue(ival); + dial->blockSignals(false); + } m_plugin->setParameter(name.toStdString(), value); } +void +PluginParameterBox::programComboChanged(const QString &newProgram) +{ + m_plugin->selectProgram(newProgram.toStdString()); + for (std::map<QString, ParamRec>::iterator i = m_params.begin(); + i != m_params.end(); ++i) { + + PluginInstance::ParameterDescriptor ¶m = i->second.param; + float value = m_plugin->getParameter(param.name); + + if (i->second.spin) { + i->second.spin->blockSignals(true); + i->second.spin->setValue(value); + i->second.spin->blockSignals(false); + } + + if (i->second.dial) { + + float min = param.minValue; + float max = param.maxValue; + + float qtz = 0.0; + if (param.isQuantized) qtz = param.quantizeStep; + + if (qtz == 0.0) { + qtz = (max - min) / 100.0; + } + + i->second.dial->blockSignals(true); + i->second.dial->setValue(int((value - min) / qtz)); + i->second.dial->blockSignals(false); + } + } +} +