1 //
2 // C++ Implementation: ssplugingui
3 //
4 // Description:
5 //
6 //
7 // Author: Mathias Lundgren <lunar_shuttle@users.sf.net>, (C) 2004
8 //  Contributer: (C) Copyright 2011 Tim E. Real (terminator356 at users.sourceforge.net)
9 //
10 //  This program is free software; you can redistribute it and/or
11 //  modify it under the terms of the GNU General Public License
12 //  as published by the Free Software Foundation; version 2 of
13 //  the License, or (at your option) any later version.
14 //
15 //  This program is distributed in the hope that it will be useful,
16 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 //  GNU General Public License for more details.
19 //
20 //  You should have received a copy of the GNU General Public License
21 //  along with this program; if not, write to the Free Software
22 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 //
25 // Copyright: See COPYING file that comes with this distribution
26 //
27 //
28 #include "ssplugingui.h"
29 #include "simpledrumsgui.h"
30 
31 #define SS_PLUGINGUI_XOFF       300
32 #define SS_PLUGINGUI_YOFF       300
33 #define SS_PLUGINGUI_WIDTH      450
34 #define SS_PLUGINGUI_MAX_WIDTH  700
35 
36 #define SS_PLUGINFRONT_MINWIDTH SS_PLUGINGUI_WIDTH
37 #define SS_PLUGINFRONT_MINHEIGHT 70
38 #define SS_PLUGINFRONT_MARGIN    9
39 #define SS_PLUGINFRONT_INC_PARAM    30
40 #define SS_PLUGINFRONT_INC_PARAM_MIN 60
41 #define SS_PLUGINGUI_HEIGHT (SS_NR_OF_SENDEFFECTS * SS_PLUGINFRONT_MINHEIGHT)
42 
43 
44 /*!
45     \fn SS_PluginFront::SS_PluginFront(QWidget* parent, const char* name = 0)
46  */
SS_PluginFront(QWidget * parent,int in_fxid)47 SS_PluginFront::SS_PluginFront(QWidget* parent, int in_fxid)
48       : QGroupBox(parent), fxid (in_fxid)
49       {
50       SS_TRACE_IN
51       expanded = false;
52       pluginChooser = 0;
53       plugin = 0;
54       expGroup = 0;
55 
56 //TD      setLineWidth(3);
57       setFlat(false);
58 //TD      setFrameStyle( Q3Frame::Box | Q3Frame::Raised );
59 //TD      setFrameShape(QFrame::StyledPanel);
60 //      setFrameShadow(Qt::Sunken);
61       setFocusPolicy(Qt::NoFocus);
62       setMinimumSize(SS_PLUGINFRONT_MINWIDTH, SS_PLUGINFRONT_MINHEIGHT);
63       setMaximumSize(SS_PLUGINGUI_MAX_WIDTH, SS_PLUGINFRONT_MINHEIGHT);
64       //layout->setSpacing(1);
65       //layout->setMargin(1);
66 
67       QVBoxLayout* bigLayout = new QVBoxLayout(this);
68       bigLayout->setContentsMargins(SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN);
69       bigLayout->setAlignment(Qt::AlignTop);
70       bigLayout->setSpacing(1);
71       bigLayout->setMargin(1);
72 //TODO      bigLayout->setResizeMode(QLayout::SetNoConstraint);
73 
74       layout = new QHBoxLayout;
75       bigLayout->addLayout(layout);
76       layout->setAlignment(Qt::AlignVCenter);
77 //TODO      layout->setResizeMode(QLayout::SetNoConstraint);
78 
79 
80       QVBoxLayout* onOffLayout = new QVBoxLayout;
81       layout->addLayout(onOffLayout);
82       onOffLayout->setContentsMargins(SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN);
83       onOff = new QCheckBox(this);
84       onOffLayout->addWidget(new QLabel("On/Off", this));
85       onOffLayout->addWidget(onOff);
86       connect(onOff, SIGNAL(toggled(bool)), SLOT(onOffToggled(bool)));
87 
88       pluginName = new QLineEdit(this);
89       pluginName->setReadOnly(true);
90       layout->addWidget(pluginName);
91 
92       loadFxButton = new QPushButton("L", this);
93       QRect r = loadFxButton->geometry();
94       loadFxButton->setGeometry(r.x(), r.y(), 20, pluginName->geometry().height());
95       loadFxButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
96       loadFxButton->setMinimumSize(20,pluginName->geometry().height());
97       loadFxButton->setMaximumSize(30,pluginName->geometry().height());
98       connect(loadFxButton, SIGNAL(clicked()), SLOT(loadButton()));
99       layout->addWidget(loadFxButton);
100 
101       clearFxButton = new QPushButton("C", this);
102       r = clearFxButton->geometry();
103       clearFxButton->setGeometry(r.x(), r.y(), 20, pluginName->geometry().height());
104       clearFxButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
105       clearFxButton->setMinimumSize(20,pluginName->geometry().height());
106       clearFxButton->setMaximumSize(30,pluginName->geometry().height());
107       connect(clearFxButton, SIGNAL(clicked()), SLOT(clearButtonPressed()));
108       layout->addWidget(clearFxButton);
109 
110       layout->addSpacing(5);
111 
112       expandButton = new QPushButton("->", this);
113       r = loadFxButton->geometry();
114       expandButton->setGeometry(r.x(), r.y(), 20, pluginName->geometry().height());
115       expandButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
116       expandButton->setMinimumSize(20,pluginName->geometry().height());
117       expandButton->setMaximumSize(30,pluginName->geometry().height());
118       connect(expandButton, SIGNAL(clicked()), SLOT(expandButtonPressed()));
119       layout->addWidget(expandButton);
120 
121       layout->addSpacing(5);
122 
123       QVBoxLayout* gainSliderLayout = new QVBoxLayout;
124       layout->addLayout(gainSliderLayout);
125       gainSliderLayout->addWidget(new QLabel("Return level", this));
126       gainSliderLayout->setContentsMargins(SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN);
127       outGainSlider = new QSlider(Qt::Horizontal, this);
128       outGainSlider->setMinimumSize(100, pluginName->geometry().height());
129       outGainSlider->setMaximumSize(500, pluginName->geometry().height());
130       loadFxButton->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
131       outGainSlider->setRange(0, 127);
132       outGainSlider->setValue(75);
133       connect(outGainSlider, SIGNAL(valueChanged(int)), SLOT(returnSliderMoved(int)));
134       gainSliderLayout->addWidget(outGainSlider);
135       clearPluginDisplay();
136 
137       expLayout = new QVBoxLayout; // (bigLayout, 2);
138       bigLayout->addLayout(expLayout);
139 
140       clearFxButton->setToolTip(tr("Clear and unload effect"));
141       loadFxButton->setToolTip(tr("Load effect"));
142       expandButton->setToolTip(tr("Toggle display of effect parameters"));
143       onOff->setToolTip(tr("Turn effect on/off"));
144       SS_TRACE_OUT
145       }
146 
~SS_PluginFront()147 SS_PluginFront::~SS_PluginFront()
148       {
149       if (pluginChooser)
150             delete pluginChooser;
151       }
152 
153 /*!
154     \fn SS_PluginFront::clearPluginDisplay()
155  */
clearPluginDisplay()156 void SS_PluginFront::clearPluginDisplay()
157       {
158       SS_TRACE_IN
159       if (expanded)
160             expandButtonPressed();
161 
162       pluginName->setText("No plugin loaded");
163       pluginName->setEnabled(false);
164       onOff->setEnabled(false);
165       onOff->blockSignals(true);
166       onOff->setChecked(false);
167       onOff->blockSignals(false);
168 
169       clearFxButton->setEnabled(false);
170       expandButton->setEnabled(false);
171       outGainSlider->setEnabled(false);
172       SS_TRACE_OUT
173       }
174 
175 /*!
176     \fn SS_PluginFront::setPluginName(QString name)
177  */
setPluginName(QString name)178 void SS_PluginFront::setPluginName(QString name)
179       {
180       pluginName->setText(name);
181       }
182 
183 
184 /*!
185     \fn SS_PluginFront::loadButton()
186  */
loadButton()187 void SS_PluginFront::loadButton()
188       {
189       SS_TRACE_IN
190       if (!pluginChooser)
191             pluginChooser = new MusESimplePlugin::SimplerPluginChooser(this);
192 
193       pluginChooser->exec();
194       if ((pluginChooser->result() == QDialog::Accepted) && pluginChooser->getSelectedPlugin()) {
195             MusESimplePlugin::Plugin* p = pluginChooser->getSelectedPlugin();
196             //printf("Selected plugin: %s\n", pluginChooser->getSelectedPlugin()->name().toLatin1().constData());
197             emit loadPlugin(fxid, p->lib(), p->label());
198             }
199       SS_TRACE_OUT
200       }
201 
202 /*!
203     \fn SS_PluginFront::returnSliderMoved(int val)
204  */
returnSliderMoved(int val)205 void SS_PluginFront::returnSliderMoved(int val)
206       {
207       emit returnLevelChanged(fxid, val);
208       }
209 
210 /*!
211     \fn SS_PluginFront::updatePluginValue(PluginI* plugi)
212  */
updatePluginValue(MusESimplePlugin::PluginI * plugi)213 void SS_PluginFront::updatePluginValue(MusESimplePlugin::PluginI* plugi)
214       {
215       SS_TRACE_IN
216       // If parameters are shown - close them
217       if (expanded) {
218             expandButtonPressed();
219             }
220 
221       plugin = plugi;
222       setPluginName(plugin->label());
223       outGainSlider->setEnabled(true);
224       clearFxButton->setEnabled(true);
225       expandButton->setEnabled(true);
226       pluginName->setEnabled(true);
227       onOff->setEnabled(true);
228       ///onOff->setChecked(true);
229       SS_TRACE_OUT
230       }
231 
232 /*!
233     \fn SS_PluginFront::onOffToggled(bool state)
234  */
onOffToggled(bool state)235 void SS_PluginFront::onOffToggled(bool state)
236       {
237       emit fxToggled(fxid, state);
238       }
239 
240 /*!
241     \fn SS_PluginFront::sizeHint() const
242  */
sizeHint() const243 QSize SS_PluginFront::sizeHint() const
244       {
245       return QSize(SS_PLUGINFRONT_MINWIDTH, 50);
246       }
247 
248 /*!
249     \fn SS_PluginFront::sizePolicy() const
250  */
sizePolicy() const251 QSizePolicy SS_PluginFront::sizePolicy() const
252       {
253       return QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
254       }
255 
256 
257 /*!
258     \fn SS_PluginFront::clearButtonPressed()
259  */
clearButtonPressed()260 void SS_PluginFront::clearButtonPressed()
261       {
262       // If parameters are shown - close them
263       if (expanded) {
264             expandButtonPressed();
265             }
266       emit clearPlugin(fxid);
267       }
268 
269 /*!
270     \fn SS_PluginFront::setRetGain(int val)
271  */
setRetGain(int val)272 void SS_PluginFront::setRetGain(int val)
273       {
274       outGainSlider->blockSignals(true);
275       outGainSlider->setValue(val);
276       outGainSlider->blockSignals(false);
277       }
278 
279 /*!
280     \fn SS_PluginFront::setOnOff(bool val)
281  */
setOnOff(bool val)282 void SS_PluginFront::setOnOff(bool val)
283       {
284       onOff->blockSignals(true);
285       onOff->setChecked(val);
286       onOff->blockSignals(false);
287       }
288 /*!
289     \fn SS_PluginFront::expandButtonPressed()
290  */
expandButtonPressed()291 void SS_PluginFront::expandButtonPressed()
292       {
293       SS_TRACE_IN
294       int sizeIncrease = 0;
295       QRect pf = geometry();
296 
297       if (!expanded) {
298             plugin->parameters() == 1 ? sizeIncrease = SS_PLUGINFRONT_INC_PARAM_MIN : sizeIncrease = plugin->parameters() * SS_PLUGINFRONT_INC_PARAM;
299             pf.setHeight(pf.height() + sizeIncrease);
300             setMinimumSize(QSize(pf.width(), pf.height()));
301             setMaximumSize(QSize(SS_PLUGINGUI_MAX_WIDTH, pf.height()));
302             setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
303             setGeometry(pf);
304             emit sizeChanged(fxid, sizeIncrease);
305 
306             expanded = true;
307             expandButton->setText("<-");
308             createPluginParameters();
309             }
310       else {
311 //TODO            expLayout->remove(expGroup);
312             expGroup->hide();
313             expGroup->deleteLater();
314             paramWidgets.clear();
315             expGroup = 0;
316             plugin->parameters() == 1 ? sizeIncrease = (0-SS_PLUGINFRONT_INC_PARAM_MIN) : sizeIncrease = 0 - (plugin->parameters() * SS_PLUGINFRONT_INC_PARAM);
317             expandButton->setText("->");
318             expanded = false;
319             pf.setHeight(pf.height() + sizeIncrease);
320             pf.setTop(pf.top() + sizeIncrease);
321             pf.setBottom(pf.bottom() + sizeIncrease);
322             setGeometry(pf);
323             adjustSize();
324             layout->activate();
325             setMinimumSize(QSize(pf.width(), pf.height()));
326             setMaximumSize(QSize(SS_PLUGINGUI_MAX_WIDTH, pf.height()));
327             setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
328             emit sizeChanged(fxid, sizeIncrease);
329             }
330       SS_TRACE_OUT
331       }
332 
333 /*!
334     \fn SS_PluginFront::createPluginParameters()
335  */
createPluginParameters()336 void SS_PluginFront::createPluginParameters()
337       {
338       SS_TRACE_IN
339       expGroup = new QGroupBox(this);
340 
341       expGroup->setMinimumSize(QSize(50, 50));
342       expGroup->setMaximumSize(QSize(SS_PLUGINGUI_MAX_WIDTH, (plugin->parameters() * SS_PLUGINFRONT_INC_PARAM  - SS_PLUGINFRONT_MARGIN)));
343       expGroup->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
344       expLayout->addWidget(expGroup);
345       expGroup->show();
346       QVBoxLayout* expGroupLayout = new QVBoxLayout(expGroup); // , 1);
347       expGroupLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
348 //TD      expGroupLayout->setResizeMode(QLayout::FreeResize);
349       expGroupLayout->setContentsMargins(SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN, SS_PLUGINFRONT_MARGIN);
350 
351       for (unsigned long i=0; i < plugin->parameters(); i++) {
352             QHBoxLayout* paramStrip = new QHBoxLayout; // (expGroupLayout, 3);
353             expGroupLayout->addLayout(paramStrip);
354             paramStrip->setAlignment(Qt::AlignLeft);
355             QLabel* paramName = new QLabel(plugin->getParameterName(i), expGroup);
356             paramName->show();
357             paramName->setMinimumSize(QSize(150, 10));
358             paramName->setMaximumSize(QSize(300, SS_PLUGINFRONT_INC_PARAM));
359             paramName->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));
360 
361             paramStrip->addWidget(paramName);
362 
363             if (plugin->isBool(i)) {
364                   SS_ParameterCheckBox* paramCheckBox = new SS_ParameterCheckBox(expGroup, plugin, fxid, i);
365                   paramCheckBox->setEnabled(true);
366                   paramCheckBox->setParamValue((int) plugin->param(i));
367                   paramCheckBox->show();
368                   paramStrip->addWidget(paramCheckBox);
369                   connect(paramCheckBox, SIGNAL(valueChanged(int, int, int)), SLOT(parameterValueChanged(int, int, int)));
370                   }
371             else  {
372                   SS_ParameterSlider* paramSlider = new SS_ParameterSlider(expGroup, plugin, fxid, i);
373                   paramSlider->setEnabled(true);
374                   paramSlider->show();
375                   paramSlider->setRange(SS_PLUGIN_PARAM_MIN, SS_PLUGIN_PARAM_MAX);
376 
377                   float max, min;
378                   plugin->range(i, &min, &max);
379                   //int intval = 0;
380                   paramSlider->setParamValue(plugin->getGuiControlValue(i));
381                   connect(paramSlider, SIGNAL(valueChanged(int, int, int)), SLOT(parameterValueChanged(int, int, int)));
382                   paramStrip->addWidget(paramSlider);
383                   }
384             }
385       expLayout->activate();
386       SS_TRACE_OUT
387       }
388 
389 /*!
390     \fn SS_PluginFront::parameterValueChanged(int fxid, int parameter, int val)
391  */
parameterValueChanged(int fxid,int parameter,int val)392 void SS_PluginFront::parameterValueChanged(int fxid, int parameter, int val)
393       {
394       emit effectParameterChanged(fxid, parameter, val);
395       }
396 
397 /*!
398     \fn SS_PluginFront::setParameterValue(int param, float val)
399  */
setParameterValue(int param,int val)400 void SS_PluginFront::setParameterValue(int param, int val)
401       {
402       SS_TRACE_IN
403       int j=0;
404       for (SS_iParameterWidgetList i=paramWidgets.begin(); i != paramWidgets.end(); i++, j++) {
405             if (j == param) {
406                   (*i)->setParamValue(val);
407                   }
408             }
409       SS_TRACE_OUT
410       }
411 
SS_PluginGui(QWidget * parent)412 SS_PluginGui::SS_PluginGui(QWidget* parent)
413       : QDialog(parent)
414       {
415       setWindowTitle("SimpleDrums LADSPA sendeffects");
416       for (int i=0; i<SS_NR_OF_SENDEFFECTS; i++) {
417             pluginFronts[i] = 0;
418             }
419       layout = new QVBoxLayout(this);
420 
421       for (int i=0; i<SS_NR_OF_SENDEFFECTS; i++) {
422             pluginFronts[i] = new SS_PluginFront(this, i);
423             pluginFronts[i]->update();
424             layout->addWidget(pluginFronts[i]);
425             connect(pluginFronts[i], SIGNAL(loadPlugin(int, QString, QString)),
426                     parent, SLOT(loadEffectInvoked(int, QString, QString)));
427             connect(pluginFronts[i], SIGNAL(returnLevelChanged(int, int)),
428                     parent, SLOT(returnLevelChanged(int, int)));
429             connect(pluginFronts[i], SIGNAL(fxToggled(int, int)),
430                     parent, SLOT(toggleEffectOnOff(int, int)));
431             connect(pluginFronts[i], SIGNAL(clearPlugin(int)),
432                     parent, SLOT(clearPlugin(int)));
433             connect(pluginFronts[i], SIGNAL(sizeChanged(int, int)), SLOT(pluginFrontSizeChanged(int, int)));
434             connect(pluginFronts[i], SIGNAL(effectParameterChanged(int, int, int)),
435                     parent, SLOT(effectParameterChanged(int, int, int)));
436             }
437       }
438 
439 
440 /*!
441     \fn SS_PluginGui::pluginFrontSizeChanged(int fxid, int val)
442  */
pluginFrontSizeChanged(int,int val)443 void SS_PluginGui::pluginFrontSizeChanged(int /*fxid*/, int val)
444       {
445       QRect r = geometry();
446       r.setHeight(r.height() + val);
447       setMinimumSize(QSize(SS_PLUGINGUI_WIDTH, r.height()));
448       setMaximumSize(QSize(SS_PLUGINGUI_MAX_WIDTH, r.height()));
449       setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
450       setGeometry(r);
451       adjustSize();
452       }
453 
getPluginFront(unsigned i)454 SS_PluginFront* SS_PluginGui::getPluginFront(unsigned i)
455       {
456       SS_TRACE_IN
457       if (i<SS_NR_OF_SENDEFFECTS)
458       SS_TRACE_OUT
459       return pluginFronts[i];
460       }
461