annotate widgets/PropertyBox.cpp @ 205:6969f21da18a

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