annotate widgets/PropertyBox.cpp @ 193:57c2350a8c40

* Add slice layers (so you can display a slice of a colour 3d plot as if it were a spectrum) * Make spectrum layer a subclass of slice layer
author Chris Cannam
date Fri, 26 Jan 2007 16:59:57 +0000
parents 53835534a9d3
children 6b023411087b
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@0 251 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
Chris@0 252 {
Chris@0 253 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 254 int row = m_layout->rowCount();
Chris@0 255
Chris@0 256 int min = 0, max = 0, value = 0;
Chris@0 257 value = m_container->getPropertyRangeAndValue(name, &min, &max);
Chris@0 258
Chris@0 259 bool have = (m_propertyControllers.find(name) !=
Chris@0 260 m_propertyControllers.end());
Chris@0 261
Chris@0 262 QString groupName = m_container->getPropertyGroupName(name);
Chris@87 263 QString propertyLabel = m_container->getPropertyLabel(name);
Chris@0 264
Chris@0 265 #ifdef DEBUG_PROPERTY_BOX
Chris@0 266 std::cerr << "PropertyBox[" << this
Chris@0 267 << "(\"" << m_container->getPropertyContainerName().toStdString()
Chris@0 268 << "\")]";
Chris@0 269 std::cerr << "::updatePropertyEditor(\"" << name.toStdString() << "\"):";
Chris@0 270 std::cerr << " value " << value << ", have " << have << ", group \""
Chris@0 271 << groupName.toStdString() << "\"" << std::endl;
Chris@0 272 #endif
Chris@0 273
Chris@0 274 bool inGroup = (groupName != QString());
Chris@0 275
Chris@0 276 if (!have) {
Chris@0 277 if (inGroup) {
Chris@0 278 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 279 #ifdef DEBUG_PROPERTY_BOX
Chris@0 280 std::cerr << "PropertyBox: adding label \"" << groupName.toStdString() << "\" and frame for group for \"" << name.toStdString() << "\"" << std::endl;
Chris@0 281 #endif
Chris@33 282 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 283 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 284 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@0 285 m_groupLayouts[groupName] = new QHBoxLayout;
Chris@0 286 m_groupLayouts[groupName]->setMargin(0);
Chris@0 287 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 288 }
Chris@0 289 } else {
Chris@0 290 #ifdef DEBUG_PROPERTY_BOX
Chris@87 291 std::cerr << "PropertyBox: adding label \"" << propertyLabel.toStdString() << "\"" << std::endl;
Chris@0 292 #endif
Chris@87 293 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
Chris@0 294 }
Chris@0 295 }
Chris@0 296
Chris@0 297 switch (type) {
Chris@0 298
Chris@0 299 case PropertyContainer::ToggleProperty:
Chris@0 300 {
Chris@189 301 NotifyingCheckBox *cb;
Chris@0 302
Chris@0 303 if (have) {
Chris@189 304 cb = dynamic_cast<NotifyingCheckBox *>(m_propertyControllers[name]);
Chris@0 305 assert(cb);
Chris@0 306 } else {
Chris@0 307 #ifdef DEBUG_PROPERTY_BOX
Chris@0 308 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
Chris@0 309 #endif
Chris@189 310 cb = new NotifyingCheckBox();
Chris@0 311 cb->setObjectName(name);
Chris@0 312 connect(cb, SIGNAL(stateChanged(int)),
Chris@0 313 this, SLOT(propertyControllerChanged(int)));
Chris@189 314 connect(cb, SIGNAL(mouseEntered()),
Chris@189 315 this, SLOT(mouseEnteredWidget()));
Chris@189 316 connect(cb, SIGNAL(mouseLeft()),
Chris@189 317 this, SLOT(mouseLeftWidget()));
Chris@0 318 if (inGroup) {
Chris@108 319 cb->setToolTip(propertyLabel);
Chris@0 320 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 321 } else {
Chris@0 322 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 323 }
Chris@0 324 m_propertyControllers[name] = cb;
Chris@0 325 }
Chris@0 326
Chris@55 327 if (cb->isChecked() != (value > 0)) {
Chris@55 328 cb->blockSignals(true);
Chris@55 329 cb->setChecked(value > 0);
Chris@55 330 cb->blockSignals(false);
Chris@55 331 }
Chris@0 332 break;
Chris@0 333 }
Chris@0 334
Chris@0 335 case PropertyContainer::RangeProperty:
Chris@0 336 {
Chris@0 337 AudioDial *dial;
Chris@0 338
Chris@0 339 if (have) {
Chris@0 340 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 341 assert(dial);
Chris@0 342 } else {
Chris@0 343 #ifdef DEBUG_PROPERTY_BOX
Chris@0 344 std::cerr << "PropertyBox: creating new dial" << std::endl;
Chris@0 345 #endif
Chris@0 346 dial = new AudioDial();
Chris@0 347 dial->setObjectName(name);
Chris@0 348 dial->setMinimum(min);
Chris@0 349 dial->setMaximum(max);
Chris@0 350 dial->setPageStep(1);
Chris@34 351 dial->setNotchesVisible((max - min) <= 12);
Chris@34 352 dial->setDefaultValue(value);
Chris@167 353 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@168 354 dial->setShowToolTip(true);
Chris@0 355 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 356 this, SLOT(propertyControllerChanged(int)));
Chris@189 357 connect(dial, SIGNAL(mouseEntered()),
Chris@189 358 this, SLOT(mouseEnteredWidget()));
Chris@189 359 connect(dial, SIGNAL(mouseLeft()),
Chris@189 360 this, SLOT(mouseLeftWidget()));
Chris@0 361
Chris@0 362 if (inGroup) {
Chris@0 363 dial->setFixedWidth(24);
Chris@0 364 dial->setFixedHeight(24);
Chris@0 365 m_groupLayouts[groupName]->addWidget(dial);
Chris@0 366 } else {
Chris@0 367 dial->setFixedWidth(32);
Chris@0 368 dial->setFixedHeight(32);
Chris@0 369 m_layout->addWidget(dial, row, 1);
Chris@33 370 QLabel *label = new QLabel(m_mainWidget);
Chris@0 371 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 372 label, SLOT(setNum(int)));
Chris@0 373 label->setNum(value);
Chris@0 374 m_layout->addWidget(label, row, 2);
Chris@0 375 }
Chris@0 376
Chris@0 377 m_propertyControllers[name] = dial;
Chris@0 378 }
Chris@0 379
Chris@55 380 if (dial->value() != value) {
Chris@55 381 dial->blockSignals(true);
Chris@55 382 dial->setValue(value);
Chris@55 383 dial->blockSignals(false);
Chris@55 384 }
Chris@0 385 break;
Chris@0 386 }
Chris@0 387
Chris@0 388 case PropertyContainer::ValueProperty:
Chris@100 389 case PropertyContainer::UnitsProperty:
Chris@0 390 {
Chris@189 391 NotifyingComboBox *cb;
Chris@0 392
Chris@0 393 if (have) {
Chris@189 394 cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]);
Chris@0 395 assert(cb);
Chris@0 396 } else {
Chris@0 397 #ifdef DEBUG_PROPERTY_BOX
Chris@0 398 std::cerr << "PropertyBox: creating new combobox" << std::endl;
Chris@0 399 #endif
Chris@0 400
Chris@189 401 cb = new NotifyingComboBox();
Chris@0 402 cb->setObjectName(name);
Chris@100 403 cb->setDuplicatesEnabled(false);
Chris@100 404
Chris@100 405 if (type == PropertyContainer::ValueProperty) {
Chris@100 406 for (int i = min; i <= max; ++i) {
Chris@100 407 cb->addItem(m_container->getPropertyValueLabel(name, i));
Chris@100 408 }
Chris@100 409 cb->setEditable(false);
Chris@100 410 } else {
Chris@100 411 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
Chris@100 412 for (int i = 0; i < units.size(); ++i) {
Chris@100 413 cb->addItem(units[i]);
Chris@100 414 }
Chris@100 415 cb->setEditable(true);
Chris@100 416 }
Chris@100 417
Chris@0 418 connect(cb, SIGNAL(activated(int)),
Chris@0 419 this, SLOT(propertyControllerChanged(int)));
Chris@189 420 connect(cb, SIGNAL(mouseEntered()),
Chris@189 421 this, SLOT(mouseEnteredWidget()));
Chris@189 422 connect(cb, SIGNAL(mouseLeft()),
Chris@189 423 this, SLOT(mouseLeftWidget()));
Chris@100 424
Chris@0 425 if (inGroup) {
Chris@108 426 cb->setToolTip(propertyLabel);
Chris@0 427 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 428 } else {
Chris@0 429 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 430 }
Chris@0 431 m_propertyControllers[name] = cb;
Chris@0 432 }
Chris@0 433
Chris@100 434 cb->blockSignals(true);
Chris@100 435 if (type == PropertyContainer::ValueProperty) {
Chris@100 436 if (cb->currentIndex() != value) {
Chris@100 437 cb->setCurrentIndex(value);
Chris@100 438 }
Chris@100 439 } else {
Chris@100 440 QString unit = UnitDatabase::getInstance()->getUnitById(value);
Chris@100 441 if (cb->currentText() != unit) {
Chris@100 442 for (int i = 0; i < cb->count(); ++i) {
Chris@100 443 if (cb->itemText(i) == unit) {
Chris@100 444 cb->setCurrentIndex(i);
Chris@100 445 break;
Chris@100 446 }
Chris@100 447 }
Chris@100 448 }
Chris@100 449 }
Chris@100 450 cb->blockSignals(false);
Chris@0 451
Chris@0 452 #ifdef Q_WS_MAC
Chris@0 453 // Crashes on startup without this, for some reason
Chris@0 454 cb->setMinimumSize(QSize(10, 10));
Chris@0 455 #endif
Chris@0 456
Chris@0 457 break;
Chris@0 458 }
Chris@0 459
Chris@0 460 default:
Chris@0 461 break;
Chris@0 462 }
Chris@0 463 }
Chris@0 464
Chris@0 465 void
Chris@0 466 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 467 {
Chris@0 468 if (pc != m_container) return;
Chris@0 469
Chris@55 470 #ifdef DEBUG_PROPERTY_BOX
Chris@55 471 std::cerr << "PropertyBox::propertyContainerPropertyChanged" << std::endl;
Chris@55 472 #endif
Chris@55 473
Chris@0 474 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 475 size_t i;
Chris@0 476
Chris@0 477 blockSignals(true);
Chris@0 478
Chris@0 479 for (i = 0; i < properties.size(); ++i) {
Chris@0 480 updatePropertyEditor(properties[i]);
Chris@0 481 }
Chris@0 482
Chris@0 483 blockSignals(false);
Chris@0 484 }
Chris@0 485
Chris@0 486 void
Chris@100 487 PropertyBox::unitDatabaseChanged()
Chris@100 488 {
Chris@100 489 blockSignals(true);
Chris@100 490
Chris@100 491 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@100 492 for (size_t i = 0; i < properties.size(); ++i) {
Chris@100 493 updatePropertyEditor(properties[i]);
Chris@100 494 }
Chris@100 495
Chris@100 496 blockSignals(false);
Chris@100 497 }
Chris@100 498
Chris@100 499 void
Chris@0 500 PropertyBox::propertyControllerChanged(int value)
Chris@0 501 {
Chris@0 502 QObject *obj = sender();
Chris@0 503 QString name = obj->objectName();
Chris@0 504
Chris@34 505 #ifdef DEBUG_PROPERTY_BOX
Chris@33 506 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
Chris@33 507 << ", " << value << ")" << std::endl;
Chris@34 508 #endif
Chris@0 509
Chris@0 510 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@100 511
Chris@100 512 if (type == PropertyContainer::UnitsProperty) {
Chris@189 513 NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj);
Chris@100 514 if (cb) {
Chris@100 515 QString unit = cb->currentText();
Chris@100 516 m_container->setPropertyWithCommand
Chris@100 517 (name, UnitDatabase::getInstance()->getUnitId(unit));
Chris@100 518 }
Chris@100 519 } else if (type != PropertyContainer::InvalidProperty) {
Chris@55 520 m_container->setPropertyWithCommand(name, value);
Chris@0 521 }
Chris@0 522 }
Chris@0 523
Chris@34 524 void
Chris@34 525 PropertyBox::playGainChanged(float gain)
Chris@34 526 {
Chris@34 527 int dialValue = lrint(log10(gain) * 20.0);
Chris@34 528 if (dialValue < -50) dialValue = -50;
Chris@34 529 if (dialValue > 50) dialValue = 50;
Chris@34 530 emit changePlayGainDial(dialValue);
Chris@34 531 }
Chris@34 532
Chris@34 533 void
Chris@34 534 PropertyBox::playGainDialChanged(int dialValue)
Chris@34 535 {
Chris@34 536 float gain = pow(10, float(dialValue) / 20.0);
Chris@34 537 emit changePlayGain(gain);
Chris@34 538 }
Chris@34 539
Chris@34 540 void
Chris@34 541 PropertyBox::playPanChanged(float pan)
Chris@34 542 {
Chris@34 543 int dialValue = lrint(pan * 50.0);
Chris@34 544 if (dialValue < -50) dialValue = -50;
Chris@34 545 if (dialValue > 50) dialValue = 50;
Chris@34 546 emit changePlayPanDial(dialValue);
Chris@34 547 }
Chris@34 548
Chris@34 549 void
Chris@34 550 PropertyBox::playPanDialChanged(int dialValue)
Chris@34 551 {
Chris@34 552 float pan = float(dialValue) / 50.0;
Chris@34 553 if (pan < -1.0) pan = -1.0;
Chris@34 554 if (pan > 1.0) pan = 1.0;
Chris@34 555 emit changePlayPan(pan);
Chris@34 556 }
Chris@0 557
Chris@63 558 void
Chris@63 559 PropertyBox::editPlugin()
Chris@63 560 {
Chris@63 561 //!!! should probably just emit and let something else do this
Chris@63 562
Chris@63 563 PlayParameters *params = m_container->getPlayParameters();
Chris@63 564 if (!params) return;
Chris@63 565
Chris@63 566 QString pluginId = params->getPlayPluginId();
Chris@63 567 QString configurationXml = params->getPlayPluginConfiguration();
Chris@63 568
Chris@63 569 RealTimePluginFactory *factory =
Chris@63 570 RealTimePluginFactory::instanceFor(pluginId);
Chris@63 571 if (!factory) return;
Chris@63 572
Chris@63 573 RealTimePluginInstance *instance =
Chris@63 574 factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1);
Chris@63 575 if (!instance) return;
Chris@63 576
Chris@71 577 PluginXml(instance).setParametersFromXml(configurationXml);
Chris@63 578
Chris@163 579 PluginParameterDialog *dialog = new PluginParameterDialog(instance);
Chris@64 580 connect(dialog, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 581 this, SLOT(pluginConfigurationChanged(QString)));
Chris@64 582
Chris@63 583 if (dialog->exec() == QDialog::Accepted) {
Chris@71 584 params->setPlayPluginConfiguration(PluginXml(instance).toXmlString());
Chris@64 585 } else {
Chris@64 586 // restore in case we mucked about with the configuration
Chris@64 587 // as a consequence of signals from the dialog
Chris@64 588 params->setPlayPluginConfiguration(configurationXml);
Chris@63 589 }
Chris@63 590
Chris@63 591 delete dialog;
Chris@63 592 delete instance;
Chris@63 593 }
Chris@63 594
Chris@64 595 void
Chris@64 596 PropertyBox::pluginConfigurationChanged(QString configurationXml)
Chris@64 597 {
Chris@64 598 PlayParameters *params = m_container->getPlayParameters();
Chris@64 599 if (!params) return;
Chris@64 600
Chris@64 601 params->setPlayPluginConfiguration(configurationXml);
Chris@64 602 }
Chris@185 603
Chris@185 604 void
Chris@185 605 PropertyBox::layerVisibilityChanged(bool visible)
Chris@185 606 {
Chris@185 607 if (m_showButton) m_showButton->setState(visible);
Chris@185 608 }
Chris@189 609
Chris@189 610 void
Chris@189 611 PropertyBox::mouseEnteredWidget()
Chris@189 612 {
Chris@189 613 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@189 614 if (!w) return;
Chris@64 615
Chris@189 616 if (!m_container) return;
Chris@190 617 QString cname = m_container->getPropertyContainerName();
Chris@189 618 if (cname == "") return;
Chris@189 619
Chris@189 620 QString wname = w->objectName();
Chris@189 621
Chris@189 622 if (w == m_showButton) {
Chris@190 623 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
Chris@189 624 } else if (w == m_playButton) {
Chris@190 625 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
Chris@189 626 } else if (wname == "") {
Chris@189 627 return;
Chris@189 628 } else if (dynamic_cast<NotifyingCheckBox *>(w)) {
Chris@190 629 emit contextHelpChanged(tr("Toggle %1 property of %2")
Chris@189 630 .arg(wname).arg(cname));
Chris@189 631 } else {
Chris@190 632 emit contextHelpChanged(tr("Adjust %1 property of %2")
Chris@189 633 .arg(wname).arg(cname));
Chris@189 634 }
Chris@189 635 }
Chris@189 636
Chris@189 637 void
Chris@189 638 PropertyBox::mouseLeftWidget()
Chris@189 639 {
Chris@189 640 emit contextHelpChanged("");
Chris@189 641 }
Chris@189 642
Chris@64 643
Chris@0 644 #ifdef INCLUDE_MOCFILES
Chris@0 645 #include "PropertyBox.moc.cpp"
Chris@0 646 #endif
Chris@0 647