Mercurial > hg > svgui
changeset 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 |
files | widgets/PluginParameterBox.cpp widgets/PluginParameterBox.h widgets/PluginParameterDialog.cpp widgets/PropertyBox.cpp widgets/PropertyBox.h |
diffstat | 5 files changed, 200 insertions(+), 43 deletions(-) [+] |
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); + } + } +} +
--- a/widgets/PluginParameterBox.h Wed Mar 22 17:38:29 2006 +0000 +++ b/widgets/PluginParameterBox.h Thu Mar 23 15:49:41 2006 +0000 @@ -23,6 +23,7 @@ class AudioDial; class QDoubleSpinBox; +class QCheckBox; class QGridLayout; class PluginParameterBox : public QFrame @@ -38,6 +39,8 @@ protected slots: void dialChanged(int); void spinBoxChanged(double); + void checkBoxChanged(int); + void programComboChanged(const QString &); protected: void populate(); @@ -48,6 +51,7 @@ struct ParamRec { AudioDial *dial; QDoubleSpinBox *spin; + QCheckBox *check; PluginInstance::ParameterDescriptor param; };
--- a/widgets/PluginParameterDialog.cpp Wed Mar 22 17:38:29 2006 +0000 +++ b/widgets/PluginParameterDialog.cpp Thu Mar 23 15:49:41 2006 +0000 @@ -39,6 +39,9 @@ QGridLayout *subgrid = new QGridLayout; pluginBox->setLayout(subgrid); + subgrid->setSpacing(0); + subgrid->setMargin(10); + QFont font(pluginBox->font()); font.setBold(true); @@ -55,17 +58,23 @@ QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str()); copyrightLabel->setFont(font); + QLabel *typeLabel = new QLabel(plugin->getType().c_str()); + typeLabel->setFont(font); + subgrid->addWidget(new QLabel(tr("Name:")), 0, 0); subgrid->addWidget(nameLabel, 0, 1); - subgrid->addWidget(new QLabel(tr("Maker:")), 1, 0); - subgrid->addWidget(makerLabel, 1, 1); + subgrid->addWidget(new QLabel(tr("Type:")), 1, 0); + subgrid->addWidget(typeLabel, 1, 1); - subgrid->addWidget(new QLabel(tr("Copyright:")), 2, 0); - subgrid->addWidget(copyrightLabel, 2, 1); + subgrid->addWidget(new QLabel(tr("Maker:")), 2, 0); + subgrid->addWidget(makerLabel, 2, 1); - subgrid->addWidget(new QLabel(tr("Version:")), 3, 0); - subgrid->addWidget(versionLabel, 3, 1); + subgrid->addWidget(new QLabel(tr("Copyright: ")), 3, 0); + subgrid->addWidget(copyrightLabel, 3, 1); + + subgrid->addWidget(new QLabel(tr("Version:")), 4, 0); + subgrid->addWidget(versionLabel, 4, 1); subgrid->setColumnStretch(1, 2); @@ -75,6 +84,7 @@ grid->setRowStretch(1, 10); QHBoxLayout *paramLayout = new QHBoxLayout; + paramLayout->setMargin(0); paramBox->setLayout(paramLayout); m_parameterBox = new PluginParameterBox(m_plugin);
--- a/widgets/PropertyBox.cpp Wed Mar 22 17:38:29 2006 +0000 +++ b/widgets/PropertyBox.cpp Thu Mar 23 15:49:41 2006 +0000 @@ -14,11 +14,15 @@ */ #include "PropertyBox.h" +#include "PluginParameterDialog.h" #include "base/PropertyContainer.h" #include "base/PlayParameters.h" #include "base/Layer.h" +#include "plugin/RealTimePluginFactory.h" +#include "plugin/RealTimePluginInstance.h" + #include "AudioDial.h" #include "LEDButton.h" @@ -27,6 +31,7 @@ #include <QVBoxLayout> #include <QCheckBox> #include <QComboBox> +#include <QPushButton> #include <QLabel> #include <QFrame> @@ -47,8 +52,6 @@ m_mainBox = new QVBoxLayout; setLayout(m_mainBox); - bool needViewPlayBox = false; - m_mainWidget = new QWidget; m_mainBox->addWidget(m_mainWidget); m_mainBox->insertStretch(1, 10); @@ -150,6 +153,13 @@ layout->insertStretch(-1, 10); + if (params->getPlayPluginId() != "") { + QPushButton *pluginButton = new QPushButton("E"); + layout->addWidget(pluginButton); + connect(pluginButton, SIGNAL(clicked()), + this, SLOT(editPlugin())); + } + AudioDial *gainDial = new AudioDial; layout->addWidget(gainDial); gainDial->setMeterColor(Qt::darkRed); @@ -454,6 +464,36 @@ emit changePlayPan(pan); } +void +PropertyBox::editPlugin() +{ + //!!! should probably just emit and let something else do this + + PlayParameters *params = m_container->getPlayParameters(); + if (!params) return; + + QString pluginId = params->getPlayPluginId(); + QString configurationXml = params->getPlayPluginConfiguration(); + + RealTimePluginFactory *factory = + RealTimePluginFactory::instanceFor(pluginId); + if (!factory) return; + + RealTimePluginInstance *instance = + factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1); + if (!instance) return; + + instance->setParametersFromXml(configurationXml); + + PluginParameterDialog *dialog = new PluginParameterDialog(instance); + if (dialog->exec() == QDialog::Accepted) { + params->setPlayPluginConfiguration(instance->toXmlString()); + } + + delete dialog; + delete instance; +} + #ifdef INCLUDE_MOCFILES #include "PropertyBox.moc.cpp" #endif