20 #include "plugin/PluginXml.h" 21 #include "plugin/RealTimePluginInstance.h" 23 #include "base/RangeMapper.h" 25 #include <QDoubleSpinBox> 26 #include <QGridLayout> 41 m_programCombo(nullptr)
55 Vamp::PluginBase::ParameterList params =
m_plugin->getParameterDescriptors();
62 (
new QLabel(tr(
"This plugin has no adjustable parameters.")),
70 std::string currentProgram =
m_plugin->getCurrentProgram();
76 for (
int i = 0; in_range_for(
m_programs, i); ++i) {
83 m_layout->addWidget(
new QLabel(tr(
"Program")), 0, 0);
86 connect(
m_programCombo, SIGNAL(currentIndexChanged(
const QString &)),
92 for (
int i = 0; in_range_for(params, i); ++i) {
94 QString identifier = params[i].identifier.c_str();
95 QString name = params[i].name.c_str();
96 QString unit = params[i].unit.c_str();
98 float min = params[i].minValue;
99 float max = params[i].maxValue;
100 float deft = params[i].defaultValue;
101 float value =
m_plugin->getParameter(params[i].identifier);
103 int hint = PortHint::NoHint;
104 auto rtpi = std::dynamic_pointer_cast<RealTimePluginInstance>
107 hint = rtpi->getParameterDisplayHint(i);
111 if (params[i].isQuantized) qtz = params[i].quantizeStep;
116 std::vector<std::string> valueNames = params[i].valueNames;
120 int imin = 0, imax = 100;
122 if (!(hint & PortHint::Logarithmic)) {
124 imax = int(lrintf((max - min) / qtz));
127 qtz = (max - min) / 100.f;
130 qtz = (max - min) / 100.f;
137 QLabel *label =
new QLabel(name);
138 if (params[i].description !=
"") {
139 label->setToolTip(QString(
"<qt>%1</qt>")
140 .arg(params[i].description.c_str())
141 .replace(
"\n",
"<br>"));
143 m_layout->addWidget(label, i + offset, 0);
146 rec.
param = params[i];
152 if (params[i].isQuantized && !valueNames.empty()) {
154 QComboBox *combobox =
new QComboBox;
155 combobox->setObjectName(identifier);
156 for (
unsigned int j = 0; j < valueNames.size(); ++j) {
157 combobox->addItem(valueNames[j].c_str());
158 if ((
unsigned int)(lrintf(fabsf((value - min) / qtz))) == j) {
159 combobox->setCurrentIndex(j);
162 connect(combobox, SIGNAL(activated(
int)),
164 m_layout->addWidget(combobox, i + offset, 1, 1, 2);
165 rec.
combo = combobox;
167 }
else if (min == 0.0 && max == 1.0 && qtz == 1.0) {
169 QCheckBox *checkbox =
new QCheckBox;
170 checkbox->setObjectName(identifier);
171 checkbox->setCheckState(value < 0.5 ? Qt::Unchecked : Qt::Checked);
172 connect(checkbox, SIGNAL(stateChanged(
int)),
174 m_layout->addWidget(checkbox, i + offset, 2);
175 rec.
check = checkbox;
180 dial->setObjectName(name);
181 dial->setMinimum(imin);
182 dial->setMaximum(imax);
183 dial->setPageStep(1);
184 dial->setNotchesVisible((imax - imin) <= 12);
187 dial->setFixedWidth(32);
188 dial->setFixedHeight(32);
189 if (max == min || imax == imin) {
190 SVCERR <<
"WARNING: for parameter \"" << name
191 <<
"\" of plugin \"" <<
m_plugin->getName()
192 <<
"\": invalid range " << min <<
" -> " << max
193 <<
" with quantize step " << qtz << endl;
195 RangeMapper *rm =
nullptr;
196 if (hint & PortHint::Logarithmic) {
197 rm =
new LogRangeMapper(imin, imax, min, max, unit);
199 rm =
new LinearRangeMapper(imin, imax, min, max, unit);
203 dial->
setValue(rm->getPositionForValue(value));
206 connect(dial, SIGNAL(valueChanged(
int)),
208 m_layout->addWidget(dial, i + offset, 1);
210 QDoubleSpinBox *spinbox =
new QDoubleSpinBox;
211 spinbox->setObjectName(identifier);
212 spinbox->setMinimum(min);
213 spinbox->setMaximum(max);
214 spinbox->setSuffix(QString(
" %1").arg(unit));
215 if (qtz != 0) spinbox->setSingleStep(qtz);
216 spinbox->setValue(value);
217 spinbox->setDecimals(4);
218 connect(spinbox, SIGNAL(valueChanged(
double)),
220 m_layout->addWidget(spinbox, i + offset, 2);
233 QObject *obj = sender();
234 QString identifier = obj->objectName();
242 cerr <<
"WARNING: PluginParameterBox::dialChanged: Unknown parameter \"" << identifier <<
"\"" << endl;
246 Vamp::PluginBase::ParameterDescriptor params =
m_params[identifier].param;
248 float min = params.minValue;
249 float max = params.maxValue;
254 if (params.isQuantized) qtz = params.quantizeStep;
261 if (newValue < min) newValue = min;
262 if (newValue > max) newValue = max;
264 ival = int(lrintf((newValue - min) / qtz));
265 newValue = min + float(ival) * qtz;
270 qtz = (max - min) / 100.f;
272 newValue = min + float(ival) * qtz;
277 QDoubleSpinBox *spin =
m_params[identifier].spin;
279 spin->blockSignals(
true);
280 spin->setValue(newValue);
281 spin->blockSignals(
false);
286 m_plugin->setParameter(identifier.toStdString(), newValue);
296 QObject *obj = sender();
297 QString identifier = obj->objectName();
305 cerr <<
"WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << identifier <<
"\"" << endl;
309 Vamp::PluginBase::ParameterDescriptor params =
m_params[identifier].param;
311 if (state)
m_plugin->setParameter(identifier.toStdString(), 1.0);
312 else m_plugin->setParameter(identifier.toStdString(), 0.0);
322 QObject *obj = sender();
323 QString identifier = obj->objectName();
331 cerr <<
"WARNING: PluginParameterBox::spinBoxChanged: Unknown parameter \"" << identifier <<
"\"" << endl;
335 Vamp::PluginBase::ParameterDescriptor params =
m_params[identifier].param;
337 float min = params.minValue;
338 float max = params.maxValue;
341 if (params.isQuantized) qtz = params.quantizeStep;
344 int step = int(lrintf(
float(value - min) / qtz));
345 value = min + float(step) * qtz;
353 qtz = (max - min) / 100.f;
356 int ival = int(lrintf(
float(value - min) / qtz));
360 dial->blockSignals(
true);
366 dial->blockSignals(
false);
369 SVDEBUG <<
"setting plugin parameter \"" << identifier <<
"\" to value " << value << endl;
371 m_plugin->setParameter(identifier.toStdString(), float(value));
381 m_plugin->selectProgram(newProgram.toStdString());
383 for (std::map<QString, ParamRec>::iterator i =
m_params.begin();
386 Vamp::PluginBase::ParameterDescriptor ¶m = i->second.param;
387 float value =
m_plugin->getParameter(param.identifier);
389 if (i->second.spin) {
390 i->second.spin->blockSignals(
true);
391 i->second.spin->setValue(value);
392 i->second.spin->blockSignals(
false);
395 if (i->second.dial) {
397 float min = param.minValue;
398 float max = param.maxValue;
401 if (param.isQuantized) qtz = param.quantizeStep;
404 qtz = (max - min) / 100.f;
407 i->second.dial->blockSignals(
true);
408 i->second.dial->setValue(
int(lrintf(
float(value - min) / qtz)));
409 i->second.dial->blockSignals(
false);
412 if (i->second.combo) {
413 i->second.combo->blockSignals(
true);
414 i->second.combo->setCurrentIndex(
int(lrintf(value)));
415 i->second.combo->blockSignals(
false);
418 if (i->second.check) {
419 i->second.check->blockSignals(
true);
420 i->second.check->setCheckState(value < 0.5 ? Qt::Unchecked : Qt::Checked);
421 i->second.check->blockSignals(
false);
433 std::string currentProgram =
m_plugin->getCurrentProgram();
435 for (
int i = 0; in_range_for(
m_programs, i); ++i) {
void checkBoxChanged(int)
void setMappedValue(double mappedValue)
QComboBox * m_programCombo
void setDefaultValue(int defaultValue)
void spinBoxChanged(double)
void pluginConfigurationChanged(QString)
double mappedValue() const
std::map< QString, ParamRec > m_params
const RangeMapper * rangeMapper() const
std::map< QString, QString > m_nameMap
AudioDial is a nicer-looking QDial that by default reacts to mouse movement on horizontal and vertica...
void programComboChanged(const QString &)
Vamp::PluginBase::ProgramList m_programs
PluginParameterBox(std::shared_ptr< Vamp::PluginBase >, QWidget *parent=0)
std::shared_ptr< Vamp::PluginBase > m_plugin
Vamp::PluginBase::ParameterDescriptor param
void setRangeMapper(RangeMapper *mapper)
void updateProgramCombo()
void setShowToolTip(bool show)