annotate widgets/PropertyBox.cpp @ 219:1fff998ae4a9

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