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