Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "PropertyBox.h"
|
Chris@63
|
17 #include "PluginParameterDialog.h"
|
Chris@0
|
18
|
Chris@0
|
19 #include "base/PropertyContainer.h"
|
Chris@33
|
20 #include "base/PlayParameters.h"
|
Chris@128
|
21 #include "layer/Layer.h"
|
Chris@100
|
22 #include "base/UnitDatabase.h"
|
Chris@0
|
23
|
Chris@63
|
24 #include "plugin/RealTimePluginFactory.h"
|
Chris@63
|
25 #include "plugin/RealTimePluginInstance.h"
|
Chris@71
|
26 #include "plugin/PluginXml.h"
|
Chris@63
|
27
|
Chris@0
|
28 #include "AudioDial.h"
|
Chris@33
|
29 #include "LEDButton.h"
|
Chris@0
|
30
|
Chris@0
|
31 #include <QGridLayout>
|
Chris@0
|
32 #include <QHBoxLayout>
|
Chris@33
|
33 #include <QVBoxLayout>
|
Chris@0
|
34 #include <QCheckBox>
|
Chris@0
|
35 #include <QComboBox>
|
Chris@63
|
36 #include <QPushButton>
|
Chris@0
|
37 #include <QLabel>
|
Chris@33
|
38 #include <QFrame>
|
Chris@0
|
39
|
Chris@0
|
40 #include <cassert>
|
Chris@0
|
41 #include <iostream>
|
Martin@46
|
42 #include <cmath>
|
Chris@0
|
43
|
Chris@0
|
44 //#define DEBUG_PROPERTY_BOX 1
|
Chris@0
|
45
|
Chris@0
|
46 PropertyBox::PropertyBox(PropertyContainer *container) :
|
Chris@0
|
47 m_container(container)
|
Chris@0
|
48 {
|
Chris@0
|
49 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
50 std::cerr << "PropertyBox[" << this << "(\"" <<
|
Chris@0
|
51 container->getPropertyContainerName().toStdString() << "\")]::PropertyBox" << std::endl;
|
Chris@0
|
52 #endif
|
Chris@0
|
53
|
Chris@34
|
54 m_mainBox = new QVBoxLayout;
|
Chris@34
|
55 setLayout(m_mainBox);
|
Chris@33
|
56
|
Chris@107
|
57 // m_nameWidget = new QLabel;
|
Chris@107
|
58 // m_mainBox->addWidget(m_nameWidget);
|
Chris@107
|
59 // m_nameWidget->setText(container->objectName());
|
Chris@107
|
60
|
Chris@34
|
61 m_mainWidget = new QWidget;
|
Chris@34
|
62 m_mainBox->addWidget(m_mainWidget);
|
Chris@107
|
63 m_mainBox->insertStretch(2, 10);
|
Chris@33
|
64
|
Chris@34
|
65 m_viewPlayFrame = 0;
|
Chris@34
|
66 populateViewPlayFrame();
|
Chris@33
|
67
|
Chris@0
|
68 m_layout = new QGridLayout;
|
Chris@34
|
69 m_layout->setMargin(0);
|
Chris@33
|
70 m_mainWidget->setLayout(m_layout);
|
Chris@0
|
71
|
Chris@34
|
72 PropertyContainer::PropertyList properties = m_container->getProperties();
|
Chris@0
|
73
|
Chris@0
|
74 blockSignals(true);
|
Chris@0
|
75
|
Chris@0
|
76 size_t i;
|
Chris@0
|
77
|
Chris@0
|
78 for (i = 0; i < properties.size(); ++i) {
|
Chris@0
|
79 updatePropertyEditor(properties[i]);
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 blockSignals(false);
|
Chris@0
|
83
|
Chris@0
|
84 m_layout->setRowStretch(m_layout->rowCount(), 10);
|
Chris@0
|
85
|
Chris@100
|
86 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
|
Chris@100
|
87 this, SLOT(unitDatabaseChanged()));
|
Chris@100
|
88
|
Chris@0
|
89 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
90 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl;
|
Chris@0
|
91 #endif
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 PropertyBox::~PropertyBox()
|
Chris@0
|
95 {
|
Chris@0
|
96 #ifdef DEBUG_PROPERTY_BOX
|
Chris@33
|
97 std::cerr << "PropertyBox[" << this << "]::~PropertyBox" << std::endl;
|
Chris@0
|
98 #endif
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 void
|
Chris@34
|
102 PropertyBox::populateViewPlayFrame()
|
Chris@33
|
103 {
|
Chris@36
|
104 #ifdef DEBUG_PROPERTY_BOX
|
Chris@34
|
105 std::cerr << "PropertyBox(" << m_container << ")::populateViewPlayFrame" << std::endl;
|
Chris@36
|
106 #endif
|
Chris@34
|
107
|
Chris@34
|
108 if (m_viewPlayFrame) {
|
Chris@34
|
109 delete m_viewPlayFrame;
|
Chris@34
|
110 m_viewPlayFrame = 0;
|
Chris@34
|
111 }
|
Chris@34
|
112
|
Chris@34
|
113 if (!m_container) return;
|
Chris@34
|
114
|
Chris@34
|
115 Layer *layer = dynamic_cast<Layer *>(m_container);
|
Chris@34
|
116 if (layer) {
|
Chris@34
|
117 connect(layer, SIGNAL(modelReplaced()),
|
Chris@34
|
118 this, SLOT(populateViewPlayFrame()));
|
Chris@34
|
119 }
|
Chris@34
|
120
|
Chris@34
|
121 PlayParameters *params = m_container->getPlayParameters();
|
Chris@33
|
122 if (!params && !layer) return;
|
Chris@33
|
123
|
Chris@34
|
124 m_viewPlayFrame = new QFrame;
|
Chris@34
|
125 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
Chris@34
|
126 m_mainBox->addWidget(m_viewPlayFrame);
|
Chris@34
|
127
|
Chris@34
|
128 QHBoxLayout *layout = new QHBoxLayout;
|
Chris@34
|
129 m_viewPlayFrame->setLayout(layout);
|
Chris@34
|
130
|
Chris@34
|
131 layout->setMargin(layout->margin() / 2);
|
Chris@34
|
132
|
Chris@36
|
133 #ifdef DEBUG_PROPERTY_BOX
|
Chris@34
|
134 std::cerr << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName().toStdString() << ") params " << params << std::endl;
|
Chris@36
|
135 #endif
|
Chris@36
|
136
|
Chris@33
|
137 if (layer) {
|
Chris@34
|
138 QLabel *showLabel = new QLabel(tr("Show"));
|
Chris@34
|
139 layout->addWidget(showLabel);
|
Chris@34
|
140 layout->setAlignment(showLabel, Qt::AlignVCenter);
|
Chris@34
|
141
|
Chris@33
|
142 LEDButton *showButton = new LEDButton(Qt::blue);
|
Chris@33
|
143 layout->addWidget(showButton);
|
Chris@47
|
144 connect(showButton, SIGNAL(stateChanged(bool)),
|
Chris@47
|
145 this, SIGNAL(showLayer(bool)));
|
Chris@34
|
146 layout->setAlignment(showButton, Qt::AlignVCenter);
|
Chris@33
|
147 }
|
Chris@33
|
148
|
Chris@33
|
149 if (params) {
|
Chris@34
|
150
|
Chris@34
|
151 QLabel *playLabel = new QLabel(tr("Play"));
|
Chris@34
|
152 layout->addWidget(playLabel);
|
Chris@34
|
153 layout->setAlignment(playLabel, Qt::AlignVCenter);
|
Chris@34
|
154
|
Chris@33
|
155 LEDButton *playButton = new LEDButton(Qt::darkGreen);
|
Chris@33
|
156 layout->addWidget(playButton);
|
Chris@33
|
157 connect(playButton, SIGNAL(stateChanged(bool)),
|
Chris@33
|
158 params, SLOT(setPlayAudible(bool)));
|
Chris@34
|
159 connect(params, SIGNAL(playAudibleChanged(bool)),
|
Chris@34
|
160 playButton, SLOT(setState(bool)));
|
Chris@34
|
161 layout->setAlignment(playButton, Qt::AlignVCenter);
|
Chris@34
|
162
|
Chris@34
|
163 layout->insertStretch(-1, 10);
|
Chris@34
|
164
|
Chris@63
|
165 if (params->getPlayPluginId() != "") {
|
Chris@64
|
166 QPushButton *pluginButton = new QPushButton(QIcon(":icons/faders.png"), "");
|
Chris@64
|
167 pluginButton->setFixedWidth(24);
|
Chris@64
|
168 pluginButton->setFixedHeight(24);
|
Chris@63
|
169 layout->addWidget(pluginButton);
|
Chris@63
|
170 connect(pluginButton, SIGNAL(clicked()),
|
Chris@63
|
171 this, SLOT(editPlugin()));
|
Chris@63
|
172 }
|
Chris@63
|
173
|
Chris@34
|
174 AudioDial *gainDial = new AudioDial;
|
Chris@34
|
175 layout->addWidget(gainDial);
|
Chris@34
|
176 gainDial->setMeterColor(Qt::darkRed);
|
Chris@34
|
177 gainDial->setMinimum(-50);
|
Chris@34
|
178 gainDial->setMaximum(50);
|
Chris@34
|
179 gainDial->setPageStep(1);
|
Chris@34
|
180 gainDial->setFixedWidth(24);
|
Chris@34
|
181 gainDial->setFixedHeight(24);
|
Chris@34
|
182 gainDial->setNotchesVisible(false);
|
Chris@57
|
183 gainDial->setToolTip(tr("Playback Level"));
|
Chris@34
|
184 gainDial->setDefaultValue(0);
|
Chris@34
|
185 connect(gainDial, SIGNAL(valueChanged(int)),
|
Chris@34
|
186 this, SLOT(playGainDialChanged(int)));
|
Chris@34
|
187 connect(params, SIGNAL(playGainChanged(float)),
|
Chris@34
|
188 this, SLOT(playGainChanged(float)));
|
Chris@34
|
189 connect(this, SIGNAL(changePlayGain(float)),
|
Chris@34
|
190 params, SLOT(setPlayGain(float)));
|
Chris@34
|
191 connect(this, SIGNAL(changePlayGainDial(int)),
|
Chris@34
|
192 gainDial, SLOT(setValue(int)));
|
Chris@34
|
193 layout->setAlignment(gainDial, Qt::AlignVCenter);
|
Chris@34
|
194
|
Chris@34
|
195 AudioDial *panDial = new AudioDial;
|
Chris@34
|
196 layout->addWidget(panDial);
|
Chris@34
|
197 panDial->setMeterColor(Qt::darkGreen);
|
Chris@34
|
198 panDial->setMinimum(-50);
|
Chris@34
|
199 panDial->setMaximum(50);
|
Chris@34
|
200 panDial->setPageStep(1);
|
Chris@34
|
201 panDial->setFixedWidth(24);
|
Chris@34
|
202 panDial->setFixedHeight(24);
|
Chris@34
|
203 panDial->setNotchesVisible(false);
|
Chris@57
|
204 panDial->setToolTip(tr("Playback Pan / Balance"));
|
Chris@34
|
205 panDial->setDefaultValue(0);
|
Chris@34
|
206 connect(panDial, SIGNAL(valueChanged(int)),
|
Chris@34
|
207 this, SLOT(playPanDialChanged(int)));
|
Chris@34
|
208 connect(params, SIGNAL(playPanChanged(float)),
|
Chris@34
|
209 this, SLOT(playPanChanged(float)));
|
Chris@34
|
210 connect(this, SIGNAL(changePlayPan(float)),
|
Chris@34
|
211 params, SLOT(setPlayPan(float)));
|
Chris@34
|
212 connect(this, SIGNAL(changePlayPanDial(int)),
|
Chris@34
|
213 panDial, SLOT(setValue(int)));
|
Chris@34
|
214 layout->setAlignment(panDial, Qt::AlignVCenter);
|
Chris@34
|
215
|
Chris@34
|
216 } else {
|
Chris@34
|
217
|
Chris@34
|
218 layout->insertStretch(-1, 10);
|
Chris@33
|
219 }
|
Chris@33
|
220 }
|
Chris@33
|
221
|
Chris@33
|
222 void
|
Chris@0
|
223 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
|
Chris@0
|
224 {
|
Chris@0
|
225 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
|
Chris@0
|
226 int row = m_layout->rowCount();
|
Chris@0
|
227
|
Chris@0
|
228 int min = 0, max = 0, value = 0;
|
Chris@0
|
229 value = m_container->getPropertyRangeAndValue(name, &min, &max);
|
Chris@0
|
230
|
Chris@0
|
231 bool have = (m_propertyControllers.find(name) !=
|
Chris@0
|
232 m_propertyControllers.end());
|
Chris@0
|
233
|
Chris@0
|
234 QString groupName = m_container->getPropertyGroupName(name);
|
Chris@87
|
235 QString propertyLabel = m_container->getPropertyLabel(name);
|
Chris@0
|
236
|
Chris@0
|
237 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
238 std::cerr << "PropertyBox[" << this
|
Chris@0
|
239 << "(\"" << m_container->getPropertyContainerName().toStdString()
|
Chris@0
|
240 << "\")]";
|
Chris@0
|
241 std::cerr << "::updatePropertyEditor(\"" << name.toStdString() << "\"):";
|
Chris@0
|
242 std::cerr << " value " << value << ", have " << have << ", group \""
|
Chris@0
|
243 << groupName.toStdString() << "\"" << std::endl;
|
Chris@0
|
244 #endif
|
Chris@0
|
245
|
Chris@0
|
246 bool inGroup = (groupName != QString());
|
Chris@0
|
247
|
Chris@0
|
248 if (!have) {
|
Chris@0
|
249 if (inGroup) {
|
Chris@0
|
250 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
|
Chris@0
|
251 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
252 std::cerr << "PropertyBox: adding label \"" << groupName.toStdString() << "\" and frame for group for \"" << name.toStdString() << "\"" << std::endl;
|
Chris@0
|
253 #endif
|
Chris@33
|
254 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
|
Chris@33
|
255 QFrame *frame = new QFrame(m_mainWidget);
|
Chris@0
|
256 m_layout->addWidget(frame, row, 1, 1, 2);
|
Chris@0
|
257 m_groupLayouts[groupName] = new QHBoxLayout;
|
Chris@0
|
258 m_groupLayouts[groupName]->setMargin(0);
|
Chris@0
|
259 frame->setLayout(m_groupLayouts[groupName]);
|
Chris@0
|
260 }
|
Chris@0
|
261 } else {
|
Chris@0
|
262 #ifdef DEBUG_PROPERTY_BOX
|
Chris@87
|
263 std::cerr << "PropertyBox: adding label \"" << propertyLabel.toStdString() << "\"" << std::endl;
|
Chris@0
|
264 #endif
|
Chris@87
|
265 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
|
Chris@0
|
266 }
|
Chris@0
|
267 }
|
Chris@0
|
268
|
Chris@0
|
269 switch (type) {
|
Chris@0
|
270
|
Chris@0
|
271 case PropertyContainer::ToggleProperty:
|
Chris@0
|
272 {
|
Chris@0
|
273 QCheckBox *cb;
|
Chris@0
|
274
|
Chris@0
|
275 if (have) {
|
Chris@0
|
276 cb = dynamic_cast<QCheckBox *>(m_propertyControllers[name]);
|
Chris@0
|
277 assert(cb);
|
Chris@0
|
278 } else {
|
Chris@0
|
279 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
280 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
|
Chris@0
|
281 #endif
|
Chris@0
|
282 cb = new QCheckBox();
|
Chris@0
|
283 cb->setObjectName(name);
|
Chris@0
|
284 connect(cb, SIGNAL(stateChanged(int)),
|
Chris@0
|
285 this, SLOT(propertyControllerChanged(int)));
|
Chris@0
|
286 if (inGroup) {
|
Chris@108
|
287 cb->setToolTip(propertyLabel);
|
Chris@0
|
288 m_groupLayouts[groupName]->addWidget(cb);
|
Chris@0
|
289 } else {
|
Chris@0
|
290 m_layout->addWidget(cb, row, 1, 1, 2);
|
Chris@0
|
291 }
|
Chris@0
|
292 m_propertyControllers[name] = cb;
|
Chris@0
|
293 }
|
Chris@0
|
294
|
Chris@55
|
295 if (cb->isChecked() != (value > 0)) {
|
Chris@55
|
296 cb->blockSignals(true);
|
Chris@55
|
297 cb->setChecked(value > 0);
|
Chris@55
|
298 cb->blockSignals(false);
|
Chris@55
|
299 }
|
Chris@0
|
300 break;
|
Chris@0
|
301 }
|
Chris@0
|
302
|
Chris@0
|
303 case PropertyContainer::RangeProperty:
|
Chris@0
|
304 {
|
Chris@0
|
305 AudioDial *dial;
|
Chris@0
|
306
|
Chris@0
|
307 if (have) {
|
Chris@0
|
308 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
|
Chris@0
|
309 assert(dial);
|
Chris@0
|
310 } else {
|
Chris@0
|
311 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
312 std::cerr << "PropertyBox: creating new dial" << std::endl;
|
Chris@0
|
313 #endif
|
Chris@0
|
314 dial = new AudioDial();
|
Chris@0
|
315 dial->setObjectName(name);
|
Chris@0
|
316 dial->setMinimum(min);
|
Chris@0
|
317 dial->setMaximum(max);
|
Chris@0
|
318 dial->setPageStep(1);
|
Chris@34
|
319 dial->setNotchesVisible((max - min) <= 12);
|
Chris@34
|
320 dial->setDefaultValue(value);
|
Chris@0
|
321 connect(dial, SIGNAL(valueChanged(int)),
|
Chris@0
|
322 this, SLOT(propertyControllerChanged(int)));
|
Chris@0
|
323
|
Chris@0
|
324 if (inGroup) {
|
Chris@0
|
325 dial->setFixedWidth(24);
|
Chris@0
|
326 dial->setFixedHeight(24);
|
Chris@108
|
327 dial->setToolTip(propertyLabel);
|
Chris@0
|
328 m_groupLayouts[groupName]->addWidget(dial);
|
Chris@0
|
329 } else {
|
Chris@0
|
330 dial->setFixedWidth(32);
|
Chris@0
|
331 dial->setFixedHeight(32);
|
Chris@0
|
332 m_layout->addWidget(dial, row, 1);
|
Chris@33
|
333 QLabel *label = new QLabel(m_mainWidget);
|
Chris@0
|
334 connect(dial, SIGNAL(valueChanged(int)),
|
Chris@0
|
335 label, SLOT(setNum(int)));
|
Chris@0
|
336 label->setNum(value);
|
Chris@0
|
337 m_layout->addWidget(label, row, 2);
|
Chris@0
|
338 }
|
Chris@0
|
339
|
Chris@0
|
340 m_propertyControllers[name] = dial;
|
Chris@0
|
341 }
|
Chris@0
|
342
|
Chris@55
|
343 if (dial->value() != value) {
|
Chris@55
|
344 dial->blockSignals(true);
|
Chris@55
|
345 dial->setValue(value);
|
Chris@55
|
346 dial->blockSignals(false);
|
Chris@55
|
347 }
|
Chris@0
|
348 break;
|
Chris@0
|
349 }
|
Chris@0
|
350
|
Chris@0
|
351 case PropertyContainer::ValueProperty:
|
Chris@100
|
352 case PropertyContainer::UnitsProperty:
|
Chris@0
|
353 {
|
Chris@0
|
354 QComboBox *cb;
|
Chris@0
|
355
|
Chris@0
|
356 if (have) {
|
Chris@0
|
357 cb = dynamic_cast<QComboBox *>(m_propertyControllers[name]);
|
Chris@0
|
358 assert(cb);
|
Chris@0
|
359 } else {
|
Chris@0
|
360 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
361 std::cerr << "PropertyBox: creating new combobox" << std::endl;
|
Chris@0
|
362 #endif
|
Chris@0
|
363
|
Chris@0
|
364 cb = new QComboBox();
|
Chris@0
|
365 cb->setObjectName(name);
|
Chris@100
|
366 cb->setDuplicatesEnabled(false);
|
Chris@100
|
367
|
Chris@100
|
368 if (type == PropertyContainer::ValueProperty) {
|
Chris@100
|
369 for (int i = min; i <= max; ++i) {
|
Chris@100
|
370 cb->addItem(m_container->getPropertyValueLabel(name, i));
|
Chris@100
|
371 }
|
Chris@100
|
372 cb->setEditable(false);
|
Chris@100
|
373 } else {
|
Chris@100
|
374 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
|
Chris@100
|
375 for (int i = 0; i < units.size(); ++i) {
|
Chris@100
|
376 cb->addItem(units[i]);
|
Chris@100
|
377 }
|
Chris@100
|
378 cb->setEditable(true);
|
Chris@100
|
379 }
|
Chris@100
|
380
|
Chris@0
|
381 connect(cb, SIGNAL(activated(int)),
|
Chris@0
|
382 this, SLOT(propertyControllerChanged(int)));
|
Chris@100
|
383
|
Chris@0
|
384 if (inGroup) {
|
Chris@108
|
385 cb->setToolTip(propertyLabel);
|
Chris@0
|
386 m_groupLayouts[groupName]->addWidget(cb);
|
Chris@0
|
387 } else {
|
Chris@0
|
388 m_layout->addWidget(cb, row, 1, 1, 2);
|
Chris@0
|
389 }
|
Chris@0
|
390 m_propertyControllers[name] = cb;
|
Chris@0
|
391 }
|
Chris@0
|
392
|
Chris@100
|
393 cb->blockSignals(true);
|
Chris@100
|
394 if (type == PropertyContainer::ValueProperty) {
|
Chris@100
|
395 if (cb->currentIndex() != value) {
|
Chris@100
|
396 cb->setCurrentIndex(value);
|
Chris@100
|
397 }
|
Chris@100
|
398 } else {
|
Chris@100
|
399 QString unit = UnitDatabase::getInstance()->getUnitById(value);
|
Chris@100
|
400 if (cb->currentText() != unit) {
|
Chris@100
|
401 for (int i = 0; i < cb->count(); ++i) {
|
Chris@100
|
402 if (cb->itemText(i) == unit) {
|
Chris@100
|
403 cb->setCurrentIndex(i);
|
Chris@100
|
404 break;
|
Chris@100
|
405 }
|
Chris@100
|
406 }
|
Chris@100
|
407 }
|
Chris@100
|
408 }
|
Chris@100
|
409 cb->blockSignals(false);
|
Chris@0
|
410
|
Chris@0
|
411 #ifdef Q_WS_MAC
|
Chris@0
|
412 // Crashes on startup without this, for some reason
|
Chris@0
|
413 cb->setMinimumSize(QSize(10, 10));
|
Chris@0
|
414 #endif
|
Chris@0
|
415
|
Chris@0
|
416 break;
|
Chris@0
|
417 }
|
Chris@0
|
418
|
Chris@0
|
419 default:
|
Chris@0
|
420 break;
|
Chris@0
|
421 }
|
Chris@0
|
422 }
|
Chris@0
|
423
|
Chris@0
|
424 void
|
Chris@0
|
425 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
|
Chris@0
|
426 {
|
Chris@0
|
427 if (pc != m_container) return;
|
Chris@0
|
428
|
Chris@55
|
429 #ifdef DEBUG_PROPERTY_BOX
|
Chris@55
|
430 std::cerr << "PropertyBox::propertyContainerPropertyChanged" << std::endl;
|
Chris@55
|
431 #endif
|
Chris@55
|
432
|
Chris@0
|
433 PropertyContainer::PropertyList properties = m_container->getProperties();
|
Chris@0
|
434 size_t i;
|
Chris@0
|
435
|
Chris@0
|
436 blockSignals(true);
|
Chris@0
|
437
|
Chris@0
|
438 for (i = 0; i < properties.size(); ++i) {
|
Chris@0
|
439 updatePropertyEditor(properties[i]);
|
Chris@0
|
440 }
|
Chris@0
|
441
|
Chris@0
|
442 blockSignals(false);
|
Chris@0
|
443 }
|
Chris@0
|
444
|
Chris@0
|
445 void
|
Chris@100
|
446 PropertyBox::unitDatabaseChanged()
|
Chris@100
|
447 {
|
Chris@100
|
448 blockSignals(true);
|
Chris@100
|
449
|
Chris@100
|
450 PropertyContainer::PropertyList properties = m_container->getProperties();
|
Chris@100
|
451 for (size_t i = 0; i < properties.size(); ++i) {
|
Chris@100
|
452 updatePropertyEditor(properties[i]);
|
Chris@100
|
453 }
|
Chris@100
|
454
|
Chris@100
|
455 blockSignals(false);
|
Chris@100
|
456 }
|
Chris@100
|
457
|
Chris@100
|
458 void
|
Chris@0
|
459 PropertyBox::propertyControllerChanged(int value)
|
Chris@0
|
460 {
|
Chris@0
|
461 QObject *obj = sender();
|
Chris@0
|
462 QString name = obj->objectName();
|
Chris@0
|
463
|
Chris@34
|
464 #ifdef DEBUG_PROPERTY_BOX
|
Chris@33
|
465 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
|
Chris@33
|
466 << ", " << value << ")" << std::endl;
|
Chris@34
|
467 #endif
|
Chris@0
|
468
|
Chris@0
|
469 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
|
Chris@100
|
470
|
Chris@100
|
471 if (type == PropertyContainer::UnitsProperty) {
|
Chris@100
|
472 QComboBox *cb = dynamic_cast<QComboBox *>(obj);
|
Chris@100
|
473 if (cb) {
|
Chris@100
|
474 QString unit = cb->currentText();
|
Chris@100
|
475 m_container->setPropertyWithCommand
|
Chris@100
|
476 (name, UnitDatabase::getInstance()->getUnitId(unit));
|
Chris@100
|
477 }
|
Chris@100
|
478 } else if (type != PropertyContainer::InvalidProperty) {
|
Chris@55
|
479 m_container->setPropertyWithCommand(name, value);
|
Chris@0
|
480 }
|
Chris@0
|
481
|
Chris@0
|
482 if (type == PropertyContainer::RangeProperty) {
|
Chris@0
|
483 AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
|
Chris@0
|
484 if (dial) {
|
Chris@0
|
485 dial->setToolTip(QString("%1: %2").arg(name).arg(value));
|
Chris@0
|
486 //!!! unfortunately this doesn't update an already-visible tooltip
|
Chris@0
|
487 }
|
Chris@0
|
488 }
|
Chris@0
|
489 }
|
Chris@0
|
490
|
Chris@34
|
491 void
|
Chris@34
|
492 PropertyBox::playGainChanged(float gain)
|
Chris@34
|
493 {
|
Chris@34
|
494 int dialValue = lrint(log10(gain) * 20.0);
|
Chris@34
|
495 if (dialValue < -50) dialValue = -50;
|
Chris@34
|
496 if (dialValue > 50) dialValue = 50;
|
Chris@34
|
497 emit changePlayGainDial(dialValue);
|
Chris@34
|
498 }
|
Chris@34
|
499
|
Chris@34
|
500 void
|
Chris@34
|
501 PropertyBox::playGainDialChanged(int dialValue)
|
Chris@34
|
502 {
|
Chris@34
|
503 float gain = pow(10, float(dialValue) / 20.0);
|
Chris@34
|
504 emit changePlayGain(gain);
|
Chris@34
|
505 }
|
Chris@34
|
506
|
Chris@34
|
507 void
|
Chris@34
|
508 PropertyBox::playPanChanged(float pan)
|
Chris@34
|
509 {
|
Chris@34
|
510 int dialValue = lrint(pan * 50.0);
|
Chris@34
|
511 if (dialValue < -50) dialValue = -50;
|
Chris@34
|
512 if (dialValue > 50) dialValue = 50;
|
Chris@34
|
513 emit changePlayPanDial(dialValue);
|
Chris@34
|
514 }
|
Chris@34
|
515
|
Chris@34
|
516 void
|
Chris@34
|
517 PropertyBox::playPanDialChanged(int dialValue)
|
Chris@34
|
518 {
|
Chris@34
|
519 float pan = float(dialValue) / 50.0;
|
Chris@34
|
520 if (pan < -1.0) pan = -1.0;
|
Chris@34
|
521 if (pan > 1.0) pan = 1.0;
|
Chris@34
|
522 emit changePlayPan(pan);
|
Chris@34
|
523 }
|
Chris@0
|
524
|
Chris@63
|
525 void
|
Chris@63
|
526 PropertyBox::editPlugin()
|
Chris@63
|
527 {
|
Chris@63
|
528 //!!! should probably just emit and let something else do this
|
Chris@63
|
529
|
Chris@63
|
530 PlayParameters *params = m_container->getPlayParameters();
|
Chris@63
|
531 if (!params) return;
|
Chris@63
|
532
|
Chris@63
|
533 QString pluginId = params->getPlayPluginId();
|
Chris@63
|
534 QString configurationXml = params->getPlayPluginConfiguration();
|
Chris@63
|
535
|
Chris@63
|
536 RealTimePluginFactory *factory =
|
Chris@63
|
537 RealTimePluginFactory::instanceFor(pluginId);
|
Chris@63
|
538 if (!factory) return;
|
Chris@63
|
539
|
Chris@63
|
540 RealTimePluginInstance *instance =
|
Chris@63
|
541 factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1);
|
Chris@63
|
542 if (!instance) return;
|
Chris@63
|
543
|
Chris@71
|
544 PluginXml(instance).setParametersFromXml(configurationXml);
|
Chris@63
|
545
|
Chris@69
|
546 PluginParameterDialog *dialog = new PluginParameterDialog(instance, -1, -1, -1);
|
Chris@64
|
547 connect(dialog, SIGNAL(pluginConfigurationChanged(QString)),
|
Chris@64
|
548 this, SLOT(pluginConfigurationChanged(QString)));
|
Chris@64
|
549
|
Chris@63
|
550 if (dialog->exec() == QDialog::Accepted) {
|
Chris@71
|
551 params->setPlayPluginConfiguration(PluginXml(instance).toXmlString());
|
Chris@64
|
552 } else {
|
Chris@64
|
553 // restore in case we mucked about with the configuration
|
Chris@64
|
554 // as a consequence of signals from the dialog
|
Chris@64
|
555 params->setPlayPluginConfiguration(configurationXml);
|
Chris@63
|
556 }
|
Chris@63
|
557
|
Chris@63
|
558 delete dialog;
|
Chris@63
|
559 delete instance;
|
Chris@63
|
560 }
|
Chris@63
|
561
|
Chris@64
|
562 void
|
Chris@64
|
563 PropertyBox::pluginConfigurationChanged(QString configurationXml)
|
Chris@64
|
564 {
|
Chris@64
|
565 PlayParameters *params = m_container->getPlayParameters();
|
Chris@64
|
566 if (!params) return;
|
Chris@64
|
567
|
Chris@64
|
568 params->setPlayPluginConfiguration(configurationXml);
|
Chris@64
|
569 }
|
Chris@64
|
570
|
Chris@64
|
571
|
Chris@64
|
572
|
Chris@0
|
573 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
574 #include "PropertyBox.moc.cpp"
|
Chris@0
|
575 #endif
|
Chris@0
|
576
|