annotate widgets/PropertyBox.cpp @ 168:d4be66d61c04

* Make audio dial remember its more accurate mapped value as well as its display position * Add tool tip support to audio dial to show values
author Chris Cannam
date Tue, 17 Oct 2006 13:04:49 +0000
parents 53b9c7656798
children bdba24db0446
rev   line source
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@168 184 //!!! gainDial->setToolTip(tr("Playback Level"));
Chris@34 185 gainDial->setDefaultValue(0);
Chris@168 186 gainDial->setObjectName(tr("Playback Gain"));
Chris@167 187 gainDial->setRangeMapper(new LinearRangeMapper
Chris@167 188 (-50, 50, -25, 25, tr("dB")));
Chris@168 189 gainDial->setShowToolTip(true);
Chris@34 190 connect(gainDial, SIGNAL(valueChanged(int)),
Chris@34 191 this, SLOT(playGainDialChanged(int)));
Chris@34 192 connect(params, SIGNAL(playGainChanged(float)),
Chris@34 193 this, SLOT(playGainChanged(float)));
Chris@34 194 connect(this, SIGNAL(changePlayGain(float)),
Chris@34 195 params, SLOT(setPlayGain(float)));
Chris@34 196 connect(this, SIGNAL(changePlayGainDial(int)),
Chris@34 197 gainDial, SLOT(setValue(int)));
Chris@34 198 layout->setAlignment(gainDial, Qt::AlignVCenter);
Chris@34 199
Chris@34 200 AudioDial *panDial = new AudioDial;
Chris@34 201 layout->addWidget(panDial);
Chris@34 202 panDial->setMeterColor(Qt::darkGreen);
Chris@34 203 panDial->setMinimum(-50);
Chris@34 204 panDial->setMaximum(50);
Chris@34 205 panDial->setPageStep(1);
Chris@34 206 panDial->setFixedWidth(24);
Chris@34 207 panDial->setFixedHeight(24);
Chris@34 208 panDial->setNotchesVisible(false);
Chris@57 209 panDial->setToolTip(tr("Playback Pan / Balance"));
Chris@34 210 panDial->setDefaultValue(0);
Chris@168 211 panDial->setObjectName(tr("Playback Pan / Balance"));
Chris@168 212 panDial->setShowToolTip(true);
Chris@34 213 connect(panDial, SIGNAL(valueChanged(int)),
Chris@34 214 this, SLOT(playPanDialChanged(int)));
Chris@34 215 connect(params, SIGNAL(playPanChanged(float)),
Chris@34 216 this, SLOT(playPanChanged(float)));
Chris@34 217 connect(this, SIGNAL(changePlayPan(float)),
Chris@34 218 params, SLOT(setPlayPan(float)));
Chris@34 219 connect(this, SIGNAL(changePlayPanDial(int)),
Chris@34 220 panDial, SLOT(setValue(int)));
Chris@34 221 layout->setAlignment(panDial, Qt::AlignVCenter);
Chris@34 222
Chris@34 223 } else {
Chris@34 224
Chris@34 225 layout->insertStretch(-1, 10);
Chris@33 226 }
Chris@33 227 }
Chris@33 228
Chris@33 229 void
Chris@0 230 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
Chris@0 231 {
Chris@0 232 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 233 int row = m_layout->rowCount();
Chris@0 234
Chris@0 235 int min = 0, max = 0, value = 0;
Chris@0 236 value = m_container->getPropertyRangeAndValue(name, &min, &max);
Chris@0 237
Chris@0 238 bool have = (m_propertyControllers.find(name) !=
Chris@0 239 m_propertyControllers.end());
Chris@0 240
Chris@0 241 QString groupName = m_container->getPropertyGroupName(name);
Chris@87 242 QString propertyLabel = m_container->getPropertyLabel(name);
Chris@0 243
Chris@0 244 #ifdef DEBUG_PROPERTY_BOX
Chris@0 245 std::cerr << "PropertyBox[" << this
Chris@0 246 << "(\"" << m_container->getPropertyContainerName().toStdString()
Chris@0 247 << "\")]";
Chris@0 248 std::cerr << "::updatePropertyEditor(\"" << name.toStdString() << "\"):";
Chris@0 249 std::cerr << " value " << value << ", have " << have << ", group \""
Chris@0 250 << groupName.toStdString() << "\"" << std::endl;
Chris@0 251 #endif
Chris@0 252
Chris@0 253 bool inGroup = (groupName != QString());
Chris@0 254
Chris@0 255 if (!have) {
Chris@0 256 if (inGroup) {
Chris@0 257 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 258 #ifdef DEBUG_PROPERTY_BOX
Chris@0 259 std::cerr << "PropertyBox: adding label \"" << groupName.toStdString() << "\" and frame for group for \"" << name.toStdString() << "\"" << std::endl;
Chris@0 260 #endif
Chris@33 261 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 262 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 263 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@0 264 m_groupLayouts[groupName] = new QHBoxLayout;
Chris@0 265 m_groupLayouts[groupName]->setMargin(0);
Chris@0 266 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 267 }
Chris@0 268 } else {
Chris@0 269 #ifdef DEBUG_PROPERTY_BOX
Chris@87 270 std::cerr << "PropertyBox: adding label \"" << propertyLabel.toStdString() << "\"" << std::endl;
Chris@0 271 #endif
Chris@87 272 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
Chris@0 273 }
Chris@0 274 }
Chris@0 275
Chris@0 276 switch (type) {
Chris@0 277
Chris@0 278 case PropertyContainer::ToggleProperty:
Chris@0 279 {
Chris@0 280 QCheckBox *cb;
Chris@0 281
Chris@0 282 if (have) {
Chris@0 283 cb = dynamic_cast<QCheckBox *>(m_propertyControllers[name]);
Chris@0 284 assert(cb);
Chris@0 285 } else {
Chris@0 286 #ifdef DEBUG_PROPERTY_BOX
Chris@0 287 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
Chris@0 288 #endif
Chris@0 289 cb = new QCheckBox();
Chris@0 290 cb->setObjectName(name);
Chris@0 291 connect(cb, SIGNAL(stateChanged(int)),
Chris@0 292 this, SLOT(propertyControllerChanged(int)));
Chris@0 293 if (inGroup) {
Chris@108 294 cb->setToolTip(propertyLabel);
Chris@0 295 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 296 } else {
Chris@0 297 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 298 }
Chris@0 299 m_propertyControllers[name] = cb;
Chris@0 300 }
Chris@0 301
Chris@55 302 if (cb->isChecked() != (value > 0)) {
Chris@55 303 cb->blockSignals(true);
Chris@55 304 cb->setChecked(value > 0);
Chris@55 305 cb->blockSignals(false);
Chris@55 306 }
Chris@0 307 break;
Chris@0 308 }
Chris@0 309
Chris@0 310 case PropertyContainer::RangeProperty:
Chris@0 311 {
Chris@0 312 AudioDial *dial;
Chris@0 313
Chris@0 314 if (have) {
Chris@0 315 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 316 assert(dial);
Chris@0 317 } else {
Chris@0 318 #ifdef DEBUG_PROPERTY_BOX
Chris@0 319 std::cerr << "PropertyBox: creating new dial" << std::endl;
Chris@0 320 #endif
Chris@0 321 dial = new AudioDial();
Chris@0 322 dial->setObjectName(name);
Chris@0 323 dial->setMinimum(min);
Chris@0 324 dial->setMaximum(max);
Chris@0 325 dial->setPageStep(1);
Chris@34 326 dial->setNotchesVisible((max - min) <= 12);
Chris@34 327 dial->setDefaultValue(value);
Chris@167 328 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@168 329 dial->setShowToolTip(true);
Chris@0 330 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 331 this, SLOT(propertyControllerChanged(int)));
Chris@0 332
Chris@0 333 if (inGroup) {
Chris@0 334 dial->setFixedWidth(24);
Chris@0 335 dial->setFixedHeight(24);
Chris@168 336 //!!! dial->setToolTip(propertyLabel);
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@64 579
Chris@64 580
Chris@64 581
Chris@0 582 #ifdef INCLUDE_MOCFILES
Chris@0 583 #include "PropertyBox.moc.cpp"
Chris@0 584 #endif
Chris@0 585