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@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
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@34
|
184 gainDial->setDefaultValue(0);
|
Chris@168
|
185 gainDial->setObjectName(tr("Playback Gain"));
|
Chris@167
|
186 gainDial->setRangeMapper(new LinearRangeMapper
|
Chris@167
|
187 (-50, 50, -25, 25, tr("dB")));
|
Chris@168
|
188 gainDial->setShowToolTip(true);
|
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@168
|
210 panDial->setObjectName(tr("Playback Pan / Balance"));
|
Chris@168
|
211 panDial->setShowToolTip(true);
|
Chris@34
|
212 connect(panDial, SIGNAL(valueChanged(int)),
|
Chris@34
|
213 this, SLOT(playPanDialChanged(int)));
|
Chris@34
|
214 connect(params, SIGNAL(playPanChanged(float)),
|
Chris@34
|
215 this, SLOT(playPanChanged(float)));
|
Chris@34
|
216 connect(this, SIGNAL(changePlayPan(float)),
|
Chris@34
|
217 params, SLOT(setPlayPan(float)));
|
Chris@34
|
218 connect(this, SIGNAL(changePlayPanDial(int)),
|
Chris@34
|
219 panDial, SLOT(setValue(int)));
|
Chris@34
|
220 layout->setAlignment(panDial, Qt::AlignVCenter);
|
Chris@34
|
221
|
Chris@34
|
222 } else {
|
Chris@34
|
223
|
Chris@34
|
224 layout->insertStretch(-1, 10);
|
Chris@33
|
225 }
|
Chris@33
|
226 }
|
Chris@33
|
227
|
Chris@33
|
228 void
|
Chris@0
|
229 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
|
Chris@0
|
230 {
|
Chris@0
|
231 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
|
Chris@0
|
232 int row = m_layout->rowCount();
|
Chris@0
|
233
|
Chris@0
|
234 int min = 0, max = 0, value = 0;
|
Chris@0
|
235 value = m_container->getPropertyRangeAndValue(name, &min, &max);
|
Chris@0
|
236
|
Chris@0
|
237 bool have = (m_propertyControllers.find(name) !=
|
Chris@0
|
238 m_propertyControllers.end());
|
Chris@0
|
239
|
Chris@0
|
240 QString groupName = m_container->getPropertyGroupName(name);
|
Chris@87
|
241 QString propertyLabel = m_container->getPropertyLabel(name);
|
Chris@0
|
242
|
Chris@0
|
243 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
244 std::cerr << "PropertyBox[" << this
|
Chris@0
|
245 << "(\"" << m_container->getPropertyContainerName().toStdString()
|
Chris@0
|
246 << "\")]";
|
Chris@0
|
247 std::cerr << "::updatePropertyEditor(\"" << name.toStdString() << "\"):";
|
Chris@0
|
248 std::cerr << " value " << value << ", have " << have << ", group \""
|
Chris@0
|
249 << groupName.toStdString() << "\"" << std::endl;
|
Chris@0
|
250 #endif
|
Chris@0
|
251
|
Chris@0
|
252 bool inGroup = (groupName != QString());
|
Chris@0
|
253
|
Chris@0
|
254 if (!have) {
|
Chris@0
|
255 if (inGroup) {
|
Chris@0
|
256 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
|
Chris@0
|
257 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
258 std::cerr << "PropertyBox: adding label \"" << groupName.toStdString() << "\" and frame for group for \"" << name.toStdString() << "\"" << std::endl;
|
Chris@0
|
259 #endif
|
Chris@33
|
260 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
|
Chris@33
|
261 QFrame *frame = new QFrame(m_mainWidget);
|
Chris@0
|
262 m_layout->addWidget(frame, row, 1, 1, 2);
|
Chris@0
|
263 m_groupLayouts[groupName] = new QHBoxLayout;
|
Chris@0
|
264 m_groupLayouts[groupName]->setMargin(0);
|
Chris@0
|
265 frame->setLayout(m_groupLayouts[groupName]);
|
Chris@0
|
266 }
|
Chris@0
|
267 } else {
|
Chris@0
|
268 #ifdef DEBUG_PROPERTY_BOX
|
Chris@87
|
269 std::cerr << "PropertyBox: adding label \"" << propertyLabel.toStdString() << "\"" << std::endl;
|
Chris@0
|
270 #endif
|
Chris@87
|
271 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
|
Chris@0
|
272 }
|
Chris@0
|
273 }
|
Chris@0
|
274
|
Chris@0
|
275 switch (type) {
|
Chris@0
|
276
|
Chris@0
|
277 case PropertyContainer::ToggleProperty:
|
Chris@0
|
278 {
|
Chris@0
|
279 QCheckBox *cb;
|
Chris@0
|
280
|
Chris@0
|
281 if (have) {
|
Chris@0
|
282 cb = dynamic_cast<QCheckBox *>(m_propertyControllers[name]);
|
Chris@0
|
283 assert(cb);
|
Chris@0
|
284 } else {
|
Chris@0
|
285 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
286 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
|
Chris@0
|
287 #endif
|
Chris@0
|
288 cb = new QCheckBox();
|
Chris@0
|
289 cb->setObjectName(name);
|
Chris@0
|
290 connect(cb, SIGNAL(stateChanged(int)),
|
Chris@0
|
291 this, SLOT(propertyControllerChanged(int)));
|
Chris@0
|
292 if (inGroup) {
|
Chris@108
|
293 cb->setToolTip(propertyLabel);
|
Chris@0
|
294 m_groupLayouts[groupName]->addWidget(cb);
|
Chris@0
|
295 } else {
|
Chris@0
|
296 m_layout->addWidget(cb, row, 1, 1, 2);
|
Chris@0
|
297 }
|
Chris@0
|
298 m_propertyControllers[name] = cb;
|
Chris@0
|
299 }
|
Chris@0
|
300
|
Chris@55
|
301 if (cb->isChecked() != (value > 0)) {
|
Chris@55
|
302 cb->blockSignals(true);
|
Chris@55
|
303 cb->setChecked(value > 0);
|
Chris@55
|
304 cb->blockSignals(false);
|
Chris@55
|
305 }
|
Chris@0
|
306 break;
|
Chris@0
|
307 }
|
Chris@0
|
308
|
Chris@0
|
309 case PropertyContainer::RangeProperty:
|
Chris@0
|
310 {
|
Chris@0
|
311 AudioDial *dial;
|
Chris@0
|
312
|
Chris@0
|
313 if (have) {
|
Chris@0
|
314 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
|
Chris@0
|
315 assert(dial);
|
Chris@0
|
316 } else {
|
Chris@0
|
317 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
318 std::cerr << "PropertyBox: creating new dial" << std::endl;
|
Chris@0
|
319 #endif
|
Chris@0
|
320 dial = new AudioDial();
|
Chris@0
|
321 dial->setObjectName(name);
|
Chris@0
|
322 dial->setMinimum(min);
|
Chris@0
|
323 dial->setMaximum(max);
|
Chris@0
|
324 dial->setPageStep(1);
|
Chris@34
|
325 dial->setNotchesVisible((max - min) <= 12);
|
Chris@34
|
326 dial->setDefaultValue(value);
|
Chris@167
|
327 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
|
Chris@168
|
328 dial->setShowToolTip(true);
|
Chris@0
|
329 connect(dial, SIGNAL(valueChanged(int)),
|
Chris@0
|
330 this, SLOT(propertyControllerChanged(int)));
|
Chris@0
|
331
|
Chris@0
|
332 if (inGroup) {
|
Chris@0
|
333 dial->setFixedWidth(24);
|
Chris@0
|
334 dial->setFixedHeight(24);
|
Chris@0
|
335 m_groupLayouts[groupName]->addWidget(dial);
|
Chris@0
|
336 } else {
|
Chris@0
|
337 dial->setFixedWidth(32);
|
Chris@0
|
338 dial->setFixedHeight(32);
|
Chris@0
|
339 m_layout->addWidget(dial, row, 1);
|
Chris@33
|
340 QLabel *label = new QLabel(m_mainWidget);
|
Chris@0
|
341 connect(dial, SIGNAL(valueChanged(int)),
|
Chris@0
|
342 label, SLOT(setNum(int)));
|
Chris@0
|
343 label->setNum(value);
|
Chris@0
|
344 m_layout->addWidget(label, row, 2);
|
Chris@0
|
345 }
|
Chris@0
|
346
|
Chris@0
|
347 m_propertyControllers[name] = dial;
|
Chris@0
|
348 }
|
Chris@0
|
349
|
Chris@55
|
350 if (dial->value() != value) {
|
Chris@55
|
351 dial->blockSignals(true);
|
Chris@55
|
352 dial->setValue(value);
|
Chris@55
|
353 dial->blockSignals(false);
|
Chris@55
|
354 }
|
Chris@0
|
355 break;
|
Chris@0
|
356 }
|
Chris@0
|
357
|
Chris@0
|
358 case PropertyContainer::ValueProperty:
|
Chris@100
|
359 case PropertyContainer::UnitsProperty:
|
Chris@0
|
360 {
|
Chris@0
|
361 QComboBox *cb;
|
Chris@0
|
362
|
Chris@0
|
363 if (have) {
|
Chris@0
|
364 cb = dynamic_cast<QComboBox *>(m_propertyControllers[name]);
|
Chris@0
|
365 assert(cb);
|
Chris@0
|
366 } else {
|
Chris@0
|
367 #ifdef DEBUG_PROPERTY_BOX
|
Chris@0
|
368 std::cerr << "PropertyBox: creating new combobox" << std::endl;
|
Chris@0
|
369 #endif
|
Chris@0
|
370
|
Chris@0
|
371 cb = new QComboBox();
|
Chris@0
|
372 cb->setObjectName(name);
|
Chris@100
|
373 cb->setDuplicatesEnabled(false);
|
Chris@100
|
374
|
Chris@100
|
375 if (type == PropertyContainer::ValueProperty) {
|
Chris@100
|
376 for (int i = min; i <= max; ++i) {
|
Chris@100
|
377 cb->addItem(m_container->getPropertyValueLabel(name, i));
|
Chris@100
|
378 }
|
Chris@100
|
379 cb->setEditable(false);
|
Chris@100
|
380 } else {
|
Chris@100
|
381 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
|
Chris@100
|
382 for (int i = 0; i < units.size(); ++i) {
|
Chris@100
|
383 cb->addItem(units[i]);
|
Chris@100
|
384 }
|
Chris@100
|
385 cb->setEditable(true);
|
Chris@100
|
386 }
|
Chris@100
|
387
|
Chris@0
|
388 connect(cb, SIGNAL(activated(int)),
|
Chris@0
|
389 this, SLOT(propertyControllerChanged(int)));
|
Chris@100
|
390
|
Chris@0
|
391 if (inGroup) {
|
Chris@108
|
392 cb->setToolTip(propertyLabel);
|
Chris@0
|
393 m_groupLayouts[groupName]->addWidget(cb);
|
Chris@0
|
394 } else {
|
Chris@0
|
395 m_layout->addWidget(cb, row, 1, 1, 2);
|
Chris@0
|
396 }
|
Chris@0
|
397 m_propertyControllers[name] = cb;
|
Chris@0
|
398 }
|
Chris@0
|
399
|
Chris@100
|
400 cb->blockSignals(true);
|
Chris@100
|
401 if (type == PropertyContainer::ValueProperty) {
|
Chris@100
|
402 if (cb->currentIndex() != value) {
|
Chris@100
|
403 cb->setCurrentIndex(value);
|
Chris@100
|
404 }
|
Chris@100
|
405 } else {
|
Chris@100
|
406 QString unit = UnitDatabase::getInstance()->getUnitById(value);
|
Chris@100
|
407 if (cb->currentText() != unit) {
|
Chris@100
|
408 for (int i = 0; i < cb->count(); ++i) {
|
Chris@100
|
409 if (cb->itemText(i) == unit) {
|
Chris@100
|
410 cb->setCurrentIndex(i);
|
Chris@100
|
411 break;
|
Chris@100
|
412 }
|
Chris@100
|
413 }
|
Chris@100
|
414 }
|
Chris@100
|
415 }
|
Chris@100
|
416 cb->blockSignals(false);
|
Chris@0
|
417
|
Chris@0
|
418 #ifdef Q_WS_MAC
|
Chris@0
|
419 // Crashes on startup without this, for some reason
|
Chris@0
|
420 cb->setMinimumSize(QSize(10, 10));
|
Chris@0
|
421 #endif
|
Chris@0
|
422
|
Chris@0
|
423 break;
|
Chris@0
|
424 }
|
Chris@0
|
425
|
Chris@0
|
426 default:
|
Chris@0
|
427 break;
|
Chris@0
|
428 }
|
Chris@0
|
429 }
|
Chris@0
|
430
|
Chris@0
|
431 void
|
Chris@0
|
432 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
|
Chris@0
|
433 {
|
Chris@0
|
434 if (pc != m_container) return;
|
Chris@0
|
435
|
Chris@55
|
436 #ifdef DEBUG_PROPERTY_BOX
|
Chris@55
|
437 std::cerr << "PropertyBox::propertyContainerPropertyChanged" << std::endl;
|
Chris@55
|
438 #endif
|
Chris@55
|
439
|
Chris@0
|
440 PropertyContainer::PropertyList properties = m_container->getProperties();
|
Chris@0
|
441 size_t i;
|
Chris@0
|
442
|
Chris@0
|
443 blockSignals(true);
|
Chris@0
|
444
|
Chris@0
|
445 for (i = 0; i < properties.size(); ++i) {
|
Chris@0
|
446 updatePropertyEditor(properties[i]);
|
Chris@0
|
447 }
|
Chris@0
|
448
|
Chris@0
|
449 blockSignals(false);
|
Chris@0
|
450 }
|
Chris@0
|
451
|
Chris@0
|
452 void
|
Chris@100
|
453 PropertyBox::unitDatabaseChanged()
|
Chris@100
|
454 {
|
Chris@100
|
455 blockSignals(true);
|
Chris@100
|
456
|
Chris@100
|
457 PropertyContainer::PropertyList properties = m_container->getProperties();
|
Chris@100
|
458 for (size_t i = 0; i < properties.size(); ++i) {
|
Chris@100
|
459 updatePropertyEditor(properties[i]);
|
Chris@100
|
460 }
|
Chris@100
|
461
|
Chris@100
|
462 blockSignals(false);
|
Chris@100
|
463 }
|
Chris@100
|
464
|
Chris@100
|
465 void
|
Chris@0
|
466 PropertyBox::propertyControllerChanged(int value)
|
Chris@0
|
467 {
|
Chris@0
|
468 QObject *obj = sender();
|
Chris@0
|
469 QString name = obj->objectName();
|
Chris@0
|
470
|
Chris@34
|
471 #ifdef DEBUG_PROPERTY_BOX
|
Chris@33
|
472 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
|
Chris@33
|
473 << ", " << value << ")" << std::endl;
|
Chris@34
|
474 #endif
|
Chris@0
|
475
|
Chris@0
|
476 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
|
Chris@100
|
477
|
Chris@100
|
478 if (type == PropertyContainer::UnitsProperty) {
|
Chris@100
|
479 QComboBox *cb = dynamic_cast<QComboBox *>(obj);
|
Chris@100
|
480 if (cb) {
|
Chris@100
|
481 QString unit = cb->currentText();
|
Chris@100
|
482 m_container->setPropertyWithCommand
|
Chris@100
|
483 (name, UnitDatabase::getInstance()->getUnitId(unit));
|
Chris@100
|
484 }
|
Chris@100
|
485 } else if (type != PropertyContainer::InvalidProperty) {
|
Chris@55
|
486 m_container->setPropertyWithCommand(name, value);
|
Chris@0
|
487 }
|
Chris@0
|
488
|
Chris@168
|
489 // if (type == PropertyContainer::RangeProperty) {
|
Chris@168
|
490 // AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
|
Chris@168
|
491 //!!! if (dial) {
|
Chris@168
|
492 // dial->setToolTip(QString("%1: %2").arg(name).arg(value));
|
Chris@168
|
493 // //!!! unfortunately this doesn't update an already-visible tooltip
|
Chris@168
|
494 // }
|
Chris@168
|
495 // }
|
Chris@0
|
496 }
|
Chris@0
|
497
|
Chris@34
|
498 void
|
Chris@34
|
499 PropertyBox::playGainChanged(float gain)
|
Chris@34
|
500 {
|
Chris@34
|
501 int dialValue = lrint(log10(gain) * 20.0);
|
Chris@34
|
502 if (dialValue < -50) dialValue = -50;
|
Chris@34
|
503 if (dialValue > 50) dialValue = 50;
|
Chris@34
|
504 emit changePlayGainDial(dialValue);
|
Chris@34
|
505 }
|
Chris@34
|
506
|
Chris@34
|
507 void
|
Chris@34
|
508 PropertyBox::playGainDialChanged(int dialValue)
|
Chris@34
|
509 {
|
Chris@34
|
510 float gain = pow(10, float(dialValue) / 20.0);
|
Chris@34
|
511 emit changePlayGain(gain);
|
Chris@34
|
512 }
|
Chris@34
|
513
|
Chris@34
|
514 void
|
Chris@34
|
515 PropertyBox::playPanChanged(float pan)
|
Chris@34
|
516 {
|
Chris@34
|
517 int dialValue = lrint(pan * 50.0);
|
Chris@34
|
518 if (dialValue < -50) dialValue = -50;
|
Chris@34
|
519 if (dialValue > 50) dialValue = 50;
|
Chris@34
|
520 emit changePlayPanDial(dialValue);
|
Chris@34
|
521 }
|
Chris@34
|
522
|
Chris@34
|
523 void
|
Chris@34
|
524 PropertyBox::playPanDialChanged(int dialValue)
|
Chris@34
|
525 {
|
Chris@34
|
526 float pan = float(dialValue) / 50.0;
|
Chris@34
|
527 if (pan < -1.0) pan = -1.0;
|
Chris@34
|
528 if (pan > 1.0) pan = 1.0;
|
Chris@34
|
529 emit changePlayPan(pan);
|
Chris@34
|
530 }
|
Chris@0
|
531
|
Chris@63
|
532 void
|
Chris@63
|
533 PropertyBox::editPlugin()
|
Chris@63
|
534 {
|
Chris@63
|
535 //!!! should probably just emit and let something else do this
|
Chris@63
|
536
|
Chris@63
|
537 PlayParameters *params = m_container->getPlayParameters();
|
Chris@63
|
538 if (!params) return;
|
Chris@63
|
539
|
Chris@63
|
540 QString pluginId = params->getPlayPluginId();
|
Chris@63
|
541 QString configurationXml = params->getPlayPluginConfiguration();
|
Chris@63
|
542
|
Chris@63
|
543 RealTimePluginFactory *factory =
|
Chris@63
|
544 RealTimePluginFactory::instanceFor(pluginId);
|
Chris@63
|
545 if (!factory) return;
|
Chris@63
|
546
|
Chris@63
|
547 RealTimePluginInstance *instance =
|
Chris@63
|
548 factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1);
|
Chris@63
|
549 if (!instance) return;
|
Chris@63
|
550
|
Chris@71
|
551 PluginXml(instance).setParametersFromXml(configurationXml);
|
Chris@63
|
552
|
Chris@163
|
553 PluginParameterDialog *dialog = new PluginParameterDialog(instance);
|
Chris@64
|
554 connect(dialog, SIGNAL(pluginConfigurationChanged(QString)),
|
Chris@64
|
555 this, SLOT(pluginConfigurationChanged(QString)));
|
Chris@64
|
556
|
Chris@63
|
557 if (dialog->exec() == QDialog::Accepted) {
|
Chris@71
|
558 params->setPlayPluginConfiguration(PluginXml(instance).toXmlString());
|
Chris@64
|
559 } else {
|
Chris@64
|
560 // restore in case we mucked about with the configuration
|
Chris@64
|
561 // as a consequence of signals from the dialog
|
Chris@64
|
562 params->setPlayPluginConfiguration(configurationXml);
|
Chris@63
|
563 }
|
Chris@63
|
564
|
Chris@63
|
565 delete dialog;
|
Chris@63
|
566 delete instance;
|
Chris@63
|
567 }
|
Chris@63
|
568
|
Chris@64
|
569 void
|
Chris@64
|
570 PropertyBox::pluginConfigurationChanged(QString configurationXml)
|
Chris@64
|
571 {
|
Chris@64
|
572 PlayParameters *params = m_container->getPlayParameters();
|
Chris@64
|
573 if (!params) return;
|
Chris@64
|
574
|
Chris@64
|
575 params->setPlayPluginConfiguration(configurationXml);
|
Chris@64
|
576 }
|
Chris@64
|
577
|
Chris@64
|
578
|
Chris@64
|
579
|
Chris@0
|
580 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
581 #include "PropertyBox.moc.cpp"
|
Chris@0
|
582 #endif
|
Chris@0
|
583
|