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