annotate widgets/PropertyBox.cpp @ 192:fcc043f75c41

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