annotate widgets/PropertyBox.cpp @ 677:5e5ab4e8d64b imaf_enc

Fix from Jesus Corral Garcia (panel with gain only appears when IM AF loaded)
author Chris Cannam
date Mon, 04 Nov 2013 17:10:51 +0000
parents d3cbfb11b70a
children 97ea68f62c1f
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@377 21 #include "base/PlayParameterRepository.h"
Chris@128 22 #include "layer/Layer.h"
Chris@376 23 #include "layer/ColourDatabase.h"
Chris@100 24 #include "base/UnitDatabase.h"
Chris@167 25 #include "base/RangeMapper.h"
Chris@0 26
Chris@63 27 #include "plugin/RealTimePluginFactory.h"
Chris@63 28 #include "plugin/RealTimePluginInstance.h"
Chris@71 29 #include "plugin/PluginXml.h"
Chris@63 30
Chris@0 31 #include "AudioDial.h"
Chris@33 32 #include "LEDButton.h"
Chris@335 33 #include "IconLoader.h"
Chris@0 34
Chris@189 35 #include "NotifyingCheckBox.h"
Chris@189 36 #include "NotifyingComboBox.h"
Chris@335 37 #include "NotifyingPushButton.h"
Chris@285 38 #include "ColourNameDialog.h"
Chris@189 39
Chris@0 40 #include <QGridLayout>
Chris@0 41 #include <QHBoxLayout>
Chris@33 42 #include <QVBoxLayout>
Chris@63 43 #include <QPushButton>
Chris@0 44 #include <QLabel>
Chris@33 45 #include <QFrame>
Chris@218 46 #include <QApplication>
Chris@285 47 #include <QColorDialog>
Chris@285 48 #include <QInputDialog>
Chris@0 49
Chris@0 50 #include <cassert>
Chris@0 51 #include <iostream>
Martin@46 52 #include <cmath>
Chris@0 53
Chris@675 54 #include "Fader.h"
Chris@456 55 //#define DEBUG_PROPERTY_BOX 1
Chris@0 56
Chris@675 57 QHBoxLayout *layout1 = new QHBoxLayout;
Chris@675 58 int tracks=0;
Chris@677 59 extern bool isIMAF;
Chris@675 60 //#include "C:/Users/Paco/Desktop/SV mio/sonic-visualiser/main/imafdecoder.h"
Chris@0 61 PropertyBox::PropertyBox(PropertyContainer *container) :
Chris@185 62 m_container(container),
Chris@189 63 m_showButton(0),
Chris@189 64 m_playButton(0)
Chris@0 65 {
Chris@0 66 #ifdef DEBUG_PROPERTY_BOX
Chris@0 67 std::cerr << "PropertyBox[" << this << "(\"" <<
Chris@584 68 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << std::endl;
Chris@0 69 #endif
Chris@0 70
Chris@34 71 m_mainBox = new QVBoxLayout;
Chris@34 72 setLayout(m_mainBox);
Chris@33 73
Chris@107 74 // m_nameWidget = new QLabel;
Chris@107 75 // m_mainBox->addWidget(m_nameWidget);
Chris@107 76 // m_nameWidget->setText(container->objectName());
Chris@107 77
Chris@34 78 m_mainWidget = new QWidget;
Chris@34 79 m_mainBox->addWidget(m_mainWidget);
Chris@107 80 m_mainBox->insertStretch(2, 10);
Chris@33 81
Chris@34 82 m_viewPlayFrame = 0;
Chris@34 83 populateViewPlayFrame();
Chris@33 84
Chris@0 85 m_layout = new QGridLayout;
Chris@34 86 m_layout->setMargin(0);
Chris@33 87 m_mainWidget->setLayout(m_layout);
Chris@0 88
Chris@34 89 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 90
Chris@0 91 blockSignals(true);
Chris@0 92
Chris@0 93 size_t i;
Chris@0 94
Chris@0 95 for (i = 0; i < properties.size(); ++i) {
Chris@0 96 updatePropertyEditor(properties[i]);
Chris@0 97 }
Chris@0 98
Chris@0 99 blockSignals(false);
Chris@0 100
Chris@0 101 m_layout->setRowStretch(m_layout->rowCount(), 10);
Chris@0 102
Chris@100 103 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
Chris@100 104 this, SLOT(unitDatabaseChanged()));
Chris@100 105
Chris@285 106 connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()),
Chris@285 107 this, SLOT(colourDatabaseChanged()));
Chris@285 108
Chris@0 109 #ifdef DEBUG_PROPERTY_BOX
Chris@0 110 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl;
Chris@0 111 #endif
Chris@0 112 }
Chris@0 113
Chris@0 114 PropertyBox::~PropertyBox()
Chris@0 115 {
Chris@0 116 #ifdef DEBUG_PROPERTY_BOX
Chris@33 117 std::cerr << "PropertyBox[" << this << "]::~PropertyBox" << std::endl;
Chris@0 118 #endif
Chris@0 119 }
Chris@0 120
Chris@675 121
Chris@0 122 void
Chris@34 123 PropertyBox::populateViewPlayFrame()
Chris@33 124 {
Chris@36 125 #ifdef DEBUG_PROPERTY_BOX
Chris@34 126 std::cerr << "PropertyBox(" << m_container << ")::populateViewPlayFrame" << std::endl;
Chris@36 127 #endif
Chris@34 128
Chris@34 129 if (m_viewPlayFrame) {
Chris@34 130 delete m_viewPlayFrame;
Chris@34 131 m_viewPlayFrame = 0;
Chris@34 132 }
Chris@34 133
Chris@34 134 if (!m_container) return;
Chris@34 135
Chris@34 136 Layer *layer = dynamic_cast<Layer *>(m_container);
Chris@34 137 if (layer) {
Chris@193 138 disconnect(layer, SIGNAL(modelReplaced()),
Chris@193 139 this, SLOT(populateViewPlayFrame()));
Chris@34 140 connect(layer, SIGNAL(modelReplaced()),
Chris@34 141 this, SLOT(populateViewPlayFrame()));
Chris@34 142 }
Chris@34 143
Chris@34 144 PlayParameters *params = m_container->getPlayParameters();
Chris@33 145 if (!params && !layer) return;
Chris@33 146
Chris@34 147 m_viewPlayFrame = new QFrame;
Chris@34 148 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@34 149 m_mainBox->addWidget(m_viewPlayFrame);
Chris@34 150
Chris@34 151 QHBoxLayout *layout = new QHBoxLayout;
Chris@34 152 m_viewPlayFrame->setLayout(layout);
Chris@34 153
Chris@34 154 layout->setMargin(layout->margin() / 2);
Chris@34 155
Chris@36 156 #ifdef DEBUG_PROPERTY_BOX
Chris@587 157 SVDEBUG << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName() << ") params " << params << endl;
Chris@36 158 #endif
Chris@36 159
Chris@33 160 if (layer) {
Chris@34 161 QLabel *showLabel = new QLabel(tr("Show"));
Chris@34 162 layout->addWidget(showLabel);
Chris@34 163 layout->setAlignment(showLabel, Qt::AlignVCenter);
Chris@34 164
Chris@185 165 m_showButton = new LEDButton(Qt::blue);
Chris@185 166 layout->addWidget(m_showButton);
Chris@185 167 connect(m_showButton, SIGNAL(stateChanged(bool)),
Chris@47 168 this, SIGNAL(showLayer(bool)));
Chris@189 169 connect(m_showButton, SIGNAL(mouseEntered()),
Chris@189 170 this, SLOT(mouseEnteredWidget()));
Chris@189 171 connect(m_showButton, SIGNAL(mouseLeft()),
Chris@189 172 this, SLOT(mouseLeftWidget()));
Chris@185 173 layout->setAlignment(m_showButton, Qt::AlignVCenter);
Chris@33 174 }
Chris@33 175
Chris@33 176 if (params) {
Chris@34 177
Chris@34 178 QLabel *playLabel = new QLabel(tr("Play"));
Chris@34 179 layout->addWidget(playLabel);
Chris@34 180 layout->setAlignment(playLabel, Qt::AlignVCenter);
Chris@34 181
Chris@189 182 m_playButton = new LEDButton(Qt::darkGreen);
Chris@189 183 m_playButton->setState(!params->isPlayMuted());
Chris@189 184 layout->addWidget(m_playButton);
Chris@189 185 connect(m_playButton, SIGNAL(stateChanged(bool)),
Chris@377 186 this, SLOT(playAudibleButtonChanged(bool)));
Chris@189 187 connect(m_playButton, SIGNAL(mouseEntered()),
Chris@189 188 this, SLOT(mouseEnteredWidget()));
Chris@189 189 connect(m_playButton, SIGNAL(mouseLeft()),
Chris@189 190 this, SLOT(mouseLeftWidget()));
Chris@34 191 connect(params, SIGNAL(playAudibleChanged(bool)),
Chris@377 192 this, SLOT(playAudibleChanged(bool)));
Chris@189 193 layout->setAlignment(m_playButton, Qt::AlignVCenter);
Chris@34 194
Chris@34 195 layout->insertStretch(-1, 10);
Chris@34 196
Chris@63 197 if (params->getPlayPluginId() != "") {
Chris@64 198 QPushButton *pluginButton = new QPushButton(QIcon(":icons/faders.png"), "");
Chris@64 199 pluginButton->setFixedWidth(24);
Chris@64 200 pluginButton->setFixedHeight(24);
Chris@63 201 layout->addWidget(pluginButton);
Chris@63 202 connect(pluginButton, SIGNAL(clicked()),
Chris@63 203 this, SLOT(editPlugin()));
Chris@63 204 }
Chris@63 205
Chris@34 206 AudioDial *gainDial = new AudioDial;
Chris@675 207 layout->addWidget(gainDial);
Chris@34 208 gainDial->setMeterColor(Qt::darkRed);
Chris@34 209 gainDial->setMinimum(-50);
Chris@34 210 gainDial->setMaximum(50);
Chris@34 211 gainDial->setPageStep(1);
Chris@675 212 gainDial->setFixedWidth(24);
Chris@675 213 gainDial->setFixedHeight(24);
Chris@34 214 gainDial->setNotchesVisible(false);
Chris@34 215 gainDial->setDefaultValue(0);
Chris@168 216 gainDial->setObjectName(tr("Playback Gain"));
Chris@167 217 gainDial->setRangeMapper(new LinearRangeMapper
Chris@167 218 (-50, 50, -25, 25, tr("dB")));
Chris@168 219 gainDial->setShowToolTip(true);
Chris@34 220 connect(gainDial, SIGNAL(valueChanged(int)),
Chris@34 221 this, SLOT(playGainDialChanged(int)));
Chris@34 222 connect(params, SIGNAL(playGainChanged(float)),
Chris@34 223 this, SLOT(playGainChanged(float)));
Chris@34 224 connect(this, SIGNAL(changePlayGainDial(int)),
Chris@34 225 gainDial, SLOT(setValue(int)));
Chris@189 226 connect(gainDial, SIGNAL(mouseEntered()),
Chris@189 227 this, SLOT(mouseEnteredWidget()));
Chris@189 228 connect(gainDial, SIGNAL(mouseLeft()),
Chris@189 229 this, SLOT(mouseLeftWidget()));
Chris@377 230 playGainChanged(params->getPlayGain());
Chris@34 231 layout->setAlignment(gainDial, Qt::AlignVCenter);
Chris@34 232
Chris@675 233 //code added by Jesus
Chris@675 234
Chris@677 235 if (isIMAF){
Chris@675 236 QString property_container_name; // the name could be : Waveform, Time Instants, etc
Chris@675 237 property_container_name = layer->getPropertyContainerName();// obtain the name
Chris@676 238 bool isWaveform;
Chris@675 239
Chris@675 240 isWaveform = property_container_name.contains("Waveform", Qt::CaseInsensitive);//if QString contains "Waveform"
Chris@675 241
Chris@675 242 if (isWaveform == true){
Chris@675 243 tracks++;
Chris@675 244
Chris@675 245 AudioDial *gainDial1 = new AudioDial;
Chris@675 246 gainDial1->setMeterColor(Qt::darkRed);
Chris@675 247 gainDial1->setMinimum(-63);
Chris@675 248 gainDial1->setMaximum(10);
Chris@675 249 gainDial1->setPageStep(1);
Chris@675 250 gainDial1->setFixedWidth(60);
Chris@675 251 gainDial1->setFixedHeight(60);
Chris@675 252 gainDial1->setNotchesVisible(false);
Chris@675 253 gainDial1->setDefaultValue(0);
Chris@675 254 gainDial1->setObjectName(tr("Playback Gain"));
Chris@675 255 gainDial1->setRangeMapper(new LinearRangeMapper
Chris@675 256 (-50, 50, -25, 25, tr("dB")));
Chris@675 257 gainDial1->setShowToolTip(true);
Chris@675 258 connect(gainDial1, SIGNAL(valueChanged(int)),
Chris@675 259 this, SLOT(playGainDialChanged(int)));
Chris@675 260 connect(params, SIGNAL(playGainChanged(float)),
Chris@675 261 this, SLOT(playGainChanged(float)));
Chris@675 262 connect(this, SIGNAL(changePlayGainDial(int)),
Chris@675 263 gainDial1, SLOT(setValue(int)));
Chris@675 264 connect(gainDial1, SIGNAL(mouseEntered()),
Chris@675 265 this, SLOT(mouseEnteredWidget()));
Chris@675 266 connect(gainDial1, SIGNAL(mouseLeft()),
Chris@675 267 this, SLOT(mouseLeftWidget()));
Chris@675 268 playGainChanged(params->getPlayGain());
Chris@675 269 layout1->setAlignment(gainDial1, Qt::AlignVCenter);
Chris@675 270
Chris@675 271 QWidget *window = new QWidget;
Chris@675 272
Chris@675 273
Chris@675 274 // QLabel *showLabel1 = new QLabel(tr("Track"));
Chris@675 275 // layout1->addWidget(showLabel1);
Chris@675 276 // layout1->setAlignment(showLabel1, Qt::AlignVCenter);
Chris@675 277
Chris@675 278 layout1->addWidget(gainDial1);
Chris@675 279 if (tracks==3){
Chris@675 280 window->setLayout(layout1);
Chris@675 281 window ->showNormal();
Chris@675 282 }
Chris@677 283 } // end if isWaveform
Chris@677 284 } // end if isIMAF
Chris@675 285 // end code added by Jesus
Chris@675 286
Chris@34 287 AudioDial *panDial = new AudioDial;
Chris@34 288 layout->addWidget(panDial);
Chris@34 289 panDial->setMeterColor(Qt::darkGreen);
Chris@34 290 panDial->setMinimum(-50);
Chris@34 291 panDial->setMaximum(50);
Chris@34 292 panDial->setPageStep(1);
Chris@34 293 panDial->setFixedWidth(24);
Chris@34 294 panDial->setFixedHeight(24);
Chris@34 295 panDial->setNotchesVisible(false);
Chris@57 296 panDial->setToolTip(tr("Playback Pan / Balance"));
Chris@34 297 panDial->setDefaultValue(0);
Chris@168 298 panDial->setObjectName(tr("Playback Pan / Balance"));
Chris@168 299 panDial->setShowToolTip(true);
Chris@34 300 connect(panDial, SIGNAL(valueChanged(int)),
Chris@34 301 this, SLOT(playPanDialChanged(int)));
Chris@34 302 connect(params, SIGNAL(playPanChanged(float)),
Chris@34 303 this, SLOT(playPanChanged(float)));
Chris@34 304 connect(this, SIGNAL(changePlayPanDial(int)),
Chris@34 305 panDial, SLOT(setValue(int)));
Chris@189 306 connect(panDial, SIGNAL(mouseEntered()),
Chris@189 307 this, SLOT(mouseEnteredWidget()));
Chris@189 308 connect(panDial, SIGNAL(mouseLeft()),
Chris@189 309 this, SLOT(mouseLeftWidget()));
Chris@377 310 playPanChanged(params->getPlayPan());
Chris@34 311 layout->setAlignment(panDial, Qt::AlignVCenter);
Chris@34 312
Chris@34 313 } else {
Chris@34 314
Chris@34 315 layout->insertStretch(-1, 10);
Chris@33 316 }
Chris@33 317 }
Chris@33 318
Chris@33 319 void
Chris@197 320 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name,
Chris@197 321 bool rangeChanged)
Chris@0 322 {
Chris@0 323 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 324 int row = m_layout->rowCount();
Chris@0 325
Chris@216 326 int min = 0, max = 0, value = 0, deflt = 0;
Chris@216 327 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
Chris@0 328
Chris@0 329 bool have = (m_propertyControllers.find(name) !=
Chris@0 330 m_propertyControllers.end());
Chris@0 331
Chris@0 332 QString groupName = m_container->getPropertyGroupName(name);
Chris@87 333 QString propertyLabel = m_container->getPropertyLabel(name);
Chris@335 334 QString iconName = m_container->getPropertyIconName(name);
Chris@0 335
Chris@0 336 #ifdef DEBUG_PROPERTY_BOX
Chris@0 337 std::cerr << "PropertyBox[" << this
Chris@0 338 << "(\"" << m_container->getPropertyContainerName().toStdString()
Chris@0 339 << "\")]";
Chris@584 340 std::cerr << "::updatePropertyEditor(\"" << name << "\"):";
Chris@0 341 std::cerr << " value " << value << ", have " << have << ", group \""
Chris@584 342 << groupName << "\"" << std::endl;
Chris@0 343 #endif
Chris@0 344
Chris@0 345 bool inGroup = (groupName != QString());
Chris@0 346
Chris@0 347 if (!have) {
Chris@0 348 if (inGroup) {
Chris@0 349 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 350 #ifdef DEBUG_PROPERTY_BOX
Chris@584 351 std::cerr << "PropertyBox: adding label \"" << groupName << "\" and frame for group for \"" << name << "\"" << std::endl;
Chris@0 352 #endif
Chris@33 353 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 354 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 355 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@493 356 m_groupLayouts[groupName] = new QGridLayout;
Chris@0 357 m_groupLayouts[groupName]->setMargin(0);
Chris@0 358 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 359 }
Chris@0 360 } else {
Chris@0 361 #ifdef DEBUG_PROPERTY_BOX
Chris@584 362 std::cerr << "PropertyBox: adding label \"" << propertyLabel << "\"" << std::endl;
Chris@0 363 #endif
Chris@87 364 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
Chris@0 365 }
Chris@0 366 }
Chris@0 367
Chris@0 368 switch (type) {
Chris@0 369
Chris@0 370 case PropertyContainer::ToggleProperty:
Chris@0 371 {
Chris@335 372 QAbstractButton *button = 0;
Chris@0 373
Chris@0 374 if (have) {
Chris@335 375 button = dynamic_cast<QAbstractButton *>(m_propertyControllers[name]);
Chris@335 376 assert(button);
Chris@0 377 } else {
Chris@0 378 #ifdef DEBUG_PROPERTY_BOX
Chris@0 379 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
Chris@0 380 #endif
Chris@335 381 if (iconName != "") {
Chris@335 382 button = new NotifyingPushButton();
Chris@335 383 button->setCheckable(true);
Chris@335 384 QIcon icon(IconLoader().load(iconName));
Chris@335 385 button->setIcon(icon);
Chris@335 386 button->setObjectName(name);
Chris@335 387 button->setFixedSize(QSize(18, 18));
Chris@335 388 } else {
Chris@335 389 button = new NotifyingCheckBox();
Chris@335 390 button->setObjectName(name);
Chris@335 391 }
Chris@335 392 connect(button, SIGNAL(toggled(bool)),
Chris@335 393 this, SLOT(propertyControllerChanged(bool)));
Chris@335 394 connect(button, SIGNAL(mouseEntered()),
Chris@189 395 this, SLOT(mouseEnteredWidget()));
Chris@335 396 connect(button, SIGNAL(mouseLeft()),
Chris@189 397 this, SLOT(mouseLeftWidget()));
Chris@0 398 if (inGroup) {
Chris@335 399 button->setToolTip(propertyLabel);
Chris@493 400 m_groupLayouts[groupName]->addWidget
Chris@493 401 (button, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 402 } else {
Chris@335 403 m_layout->addWidget(button, row, 1, 1, 2);
Chris@0 404 }
Chris@335 405 m_propertyControllers[name] = button;
Chris@0 406 }
Chris@0 407
Chris@335 408 if (button->isChecked() != (value > 0)) {
Chris@335 409 button->blockSignals(true);
Chris@335 410 button->setChecked(value > 0);
Chris@335 411 button->blockSignals(false);
Chris@55 412 }
Chris@0 413 break;
Chris@0 414 }
Chris@0 415
Chris@0 416 case PropertyContainer::RangeProperty:
Chris@0 417 {
Chris@0 418 AudioDial *dial;
Chris@0 419
Chris@0 420 if (have) {
Chris@0 421 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 422 assert(dial);
Chris@197 423 if (rangeChanged) {
Chris@197 424 dial->blockSignals(true);
Chris@197 425 dial->setMinimum(min);
Chris@197 426 dial->setMaximum(max);
Chris@197 427 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@197 428 dial->blockSignals(false);
Chris@197 429 }
Chris@197 430
Chris@0 431 } else {
Chris@0 432 #ifdef DEBUG_PROPERTY_BOX
Chris@0 433 std::cerr << "PropertyBox: creating new dial" << std::endl;
Chris@0 434 #endif
Chris@0 435 dial = new AudioDial();
Chris@0 436 dial->setObjectName(name);
Chris@0 437 dial->setMinimum(min);
Chris@0 438 dial->setMaximum(max);
Chris@0 439 dial->setPageStep(1);
Chris@34 440 dial->setNotchesVisible((max - min) <= 12);
Chris@216 441 dial->setDefaultValue(deflt);
Chris@167 442 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@168 443 dial->setShowToolTip(true);
Chris@0 444 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 445 this, SLOT(propertyControllerChanged(int)));
Chris@189 446 connect(dial, SIGNAL(mouseEntered()),
Chris@189 447 this, SLOT(mouseEnteredWidget()));
Chris@189 448 connect(dial, SIGNAL(mouseLeft()),
Chris@189 449 this, SLOT(mouseLeftWidget()));
Chris@0 450
Chris@0 451 if (inGroup) {
Chris@0 452 dial->setFixedWidth(24);
Chris@0 453 dial->setFixedHeight(24);
Chris@493 454 m_groupLayouts[groupName]->addWidget
Chris@493 455 (dial, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 456 } else {
Chris@0 457 dial->setFixedWidth(32);
Chris@0 458 dial->setFixedHeight(32);
Chris@0 459 m_layout->addWidget(dial, row, 1);
Chris@33 460 QLabel *label = new QLabel(m_mainWidget);
Chris@0 461 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 462 label, SLOT(setNum(int)));
Chris@0 463 label->setNum(value);
Chris@0 464 m_layout->addWidget(label, row, 2);
Chris@0 465 }
Chris@0 466
Chris@0 467 m_propertyControllers[name] = dial;
Chris@0 468 }
Chris@0 469
Chris@55 470 if (dial->value() != value) {
Chris@55 471 dial->blockSignals(true);
Chris@55 472 dial->setValue(value);
Chris@55 473 dial->blockSignals(false);
Chris@55 474 }
Chris@0 475 break;
Chris@0 476 }
Chris@0 477
Chris@0 478 case PropertyContainer::ValueProperty:
Chris@100 479 case PropertyContainer::UnitsProperty:
Chris@285 480 case PropertyContainer::ColourProperty:
Chris@0 481 {
Chris@189 482 NotifyingComboBox *cb;
Chris@0 483
Chris@0 484 if (have) {
Chris@189 485 cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]);
Chris@0 486 assert(cb);
Chris@0 487 } else {
Chris@0 488 #ifdef DEBUG_PROPERTY_BOX
Chris@0 489 std::cerr << "PropertyBox: creating new combobox" << std::endl;
Chris@0 490 #endif
Chris@0 491
Chris@189 492 cb = new NotifyingComboBox();
Chris@0 493 cb->setObjectName(name);
Chris@100 494 cb->setDuplicatesEnabled(false);
Chris@197 495 }
Chris@100 496
Chris@197 497 if (!have || rangeChanged) {
Chris@285 498
Chris@197 499 cb->blockSignals(true);
Chris@197 500 cb->clear();
Chris@285 501 cb->setEditable(false);
Chris@285 502
Chris@100 503 if (type == PropertyContainer::ValueProperty) {
Chris@285 504
Chris@100 505 for (int i = min; i <= max; ++i) {
Chris@100 506 cb->addItem(m_container->getPropertyValueLabel(name, i));
Chris@100 507 }
Chris@285 508
Chris@285 509 } else if (type == PropertyContainer::UnitsProperty) {
Chris@285 510
Chris@100 511 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
Chris@100 512 for (int i = 0; i < units.size(); ++i) {
Chris@100 513 cb->addItem(units[i]);
Chris@100 514 }
Chris@285 515
Chris@100 516 cb->setEditable(true);
Chris@285 517
Chris@285 518 } else { // ColourProperty
Chris@290 519
Chris@290 520 //!!! should be a proper colour combobox class that
Chris@290 521 // manages its own Add New Colour entry...
Chris@285 522
Chris@285 523 ColourDatabase *db = ColourDatabase::getInstance();
Chris@285 524 for (size_t i = 0; i < db->getColourCount(); ++i) {
Chris@285 525 QString name = db->getColourName(i);
Chris@287 526 cb->addItem(db->getExamplePixmap(i, QSize(12, 12)), name);
Chris@285 527 }
Chris@285 528 cb->addItem(tr("Add New Colour..."));
Chris@285 529 }
Chris@285 530
Chris@197 531 cb->blockSignals(false);
Chris@280 532 if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) {
Chris@280 533 cb->setMaxVisibleItems(cb->count());
Chris@280 534 }
Chris@197 535 }
Chris@100 536
Chris@197 537 if (!have) {
Chris@0 538 connect(cb, SIGNAL(activated(int)),
Chris@0 539 this, SLOT(propertyControllerChanged(int)));
Chris@189 540 connect(cb, SIGNAL(mouseEntered()),
Chris@189 541 this, SLOT(mouseEnteredWidget()));
Chris@189 542 connect(cb, SIGNAL(mouseLeft()),
Chris@189 543 this, SLOT(mouseLeftWidget()));
Chris@100 544
Chris@0 545 if (inGroup) {
Chris@108 546 cb->setToolTip(propertyLabel);
Chris@493 547 m_groupLayouts[groupName]->addWidget
Chris@493 548 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 549 } else {
Chris@0 550 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 551 }
Chris@0 552 m_propertyControllers[name] = cb;
Chris@0 553 }
Chris@0 554
Chris@100 555 cb->blockSignals(true);
Chris@285 556 if (type == PropertyContainer::ValueProperty ||
Chris@285 557 type == PropertyContainer::ColourProperty) {
Chris@100 558 if (cb->currentIndex() != value) {
Chris@100 559 cb->setCurrentIndex(value);
Chris@100 560 }
Chris@100 561 } else {
Chris@100 562 QString unit = UnitDatabase::getInstance()->getUnitById(value);
Chris@100 563 if (cb->currentText() != unit) {
Chris@100 564 for (int i = 0; i < cb->count(); ++i) {
Chris@100 565 if (cb->itemText(i) == unit) {
Chris@100 566 cb->setCurrentIndex(i);
Chris@100 567 break;
Chris@100 568 }
Chris@100 569 }
Chris@100 570 }
Chris@100 571 }
Chris@100 572 cb->blockSignals(false);
Chris@0 573
Chris@0 574 #ifdef Q_WS_MAC
Chris@0 575 // Crashes on startup without this, for some reason
Chris@0 576 cb->setMinimumSize(QSize(10, 10));
Chris@0 577 #endif
Chris@0 578
Chris@0 579 break;
Chris@0 580 }
Chris@0 581
Chris@0 582 default:
Chris@0 583 break;
Chris@0 584 }
Chris@0 585 }
Chris@0 586
Chris@0 587 void
Chris@0 588 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 589 {
Chris@0 590 if (pc != m_container) return;
Chris@0 591
Chris@55 592 #ifdef DEBUG_PROPERTY_BOX
Chris@587 593 SVDEBUG << "PropertyBox::propertyContainerPropertyChanged" << endl;
Chris@55 594 #endif
Chris@55 595
Chris@0 596 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 597 size_t i;
Chris@0 598
Chris@0 599 blockSignals(true);
Chris@0 600
Chris@0 601 for (i = 0; i < properties.size(); ++i) {
Chris@0 602 updatePropertyEditor(properties[i]);
Chris@0 603 }
Chris@0 604
Chris@0 605 blockSignals(false);
Chris@0 606 }
Chris@0 607
Chris@0 608 void
Chris@249 609 PropertyBox::propertyContainerPropertyRangeChanged(PropertyContainer *)
Chris@197 610 {
Chris@197 611 blockSignals(true);
Chris@197 612
Chris@197 613 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@197 614 for (size_t i = 0; i < properties.size(); ++i) {
Chris@197 615 updatePropertyEditor(properties[i], true);
Chris@197 616 }
Chris@197 617
Chris@197 618 blockSignals(false);
Chris@197 619 }
Chris@197 620
Chris@197 621 void
Chris@100 622 PropertyBox::unitDatabaseChanged()
Chris@100 623 {
Chris@454 624 std::cerr << "PropertyBox[" << this << "]: unitDatabaseChanged" << std::endl;
Chris@100 625 blockSignals(true);
Chris@100 626
Chris@456 627 // std::cerr << "my container is " << m_container << std::endl;
Chris@456 628 // std::cerr << "my container's name is... " << std::endl;
Chris@584 629 // std::cerr << m_container->objectName() << std::endl;
Chris@456 630
Chris@100 631 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@100 632 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 633 if (m_container->getPropertyType(properties[i]) ==
Chris@285 634 PropertyContainer::UnitsProperty) {
Chris@285 635 updatePropertyEditor(properties[i]);
Chris@285 636 }
Chris@285 637 }
Chris@285 638
Chris@285 639 blockSignals(false);
Chris@285 640 }
Chris@285 641
Chris@285 642 void
Chris@285 643 PropertyBox::colourDatabaseChanged()
Chris@285 644 {
Chris@285 645 blockSignals(true);
Chris@285 646
Chris@285 647 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@285 648 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 649 if (m_container->getPropertyType(properties[i]) ==
Chris@285 650 PropertyContainer::ColourProperty) {
Chris@285 651 updatePropertyEditor(properties[i], true);
Chris@285 652 }
Chris@100 653 }
Chris@100 654
Chris@100 655 blockSignals(false);
Chris@100 656 }
Chris@100 657
Chris@100 658 void
Chris@335 659 PropertyBox::propertyControllerChanged(bool on)
Chris@335 660 {
Chris@335 661 propertyControllerChanged(on ? 1 : 0);
Chris@335 662 }
Chris@335 663
Chris@335 664 void
Chris@0 665 PropertyBox::propertyControllerChanged(int value)
Chris@0 666 {
Chris@0 667 QObject *obj = sender();
Chris@0 668 QString name = obj->objectName();
Chris@0 669
Chris@34 670 #ifdef DEBUG_PROPERTY_BOX
Chris@587 671 SVDEBUG << "PropertyBox::propertyControllerChanged(" << name << ", " << value << ")" << endl;
Chris@34 672 #endif
Chris@0 673
Chris@0 674 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@100 675
Chris@376 676 Command *c = 0;
Chris@376 677
Chris@100 678 if (type == PropertyContainer::UnitsProperty) {
Chris@285 679
Chris@189 680 NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj);
Chris@100 681 if (cb) {
Chris@100 682 QString unit = cb->currentText();
Chris@376 683 c = m_container->getSetPropertyCommand
Chris@100 684 (name, UnitDatabase::getInstance()->getUnitId(unit));
Chris@100 685 }
Chris@285 686
Chris@285 687 } else if (type == PropertyContainer::ColourProperty) {
Chris@285 688
Chris@285 689 if (value == int(ColourDatabase::getInstance()->getColourCount())) {
Chris@285 690 addNewColour();
Chris@285 691 if (value == int(ColourDatabase::getInstance()->getColourCount())) {
Chris@285 692 propertyContainerPropertyChanged(m_container);
Chris@285 693 return;
Chris@285 694 }
Chris@285 695 }
Chris@376 696 c = m_container->getSetPropertyCommand(name, value);
Chris@285 697
Chris@100 698 } else if (type != PropertyContainer::InvalidProperty) {
Chris@285 699
Chris@376 700 c = m_container->getSetPropertyCommand(name, value);
Chris@0 701 }
Chris@376 702
Chris@376 703 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
Chris@218 704
Chris@218 705 updateContextHelp(obj);
Chris@0 706 }
Chris@285 707
Chris@285 708 void
Chris@285 709 PropertyBox::addNewColour()
Chris@285 710 {
Chris@285 711 QColor newColour = QColorDialog::getColor();
Chris@285 712 if (!newColour.isValid()) return;
Chris@285 713
Chris@285 714 ColourNameDialog dialog(tr("Name New Colour"),
Chris@361 715 tr("Enter a name for the new colour:"),
Chris@361 716 newColour, newColour.name(), this);
Chris@285 717 dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour"));
Chris@285 718 if (dialog.exec() == QDialog::Accepted) {
Chris@285 719 //!!! command
Chris@285 720 ColourDatabase *db = ColourDatabase::getInstance();
Chris@285 721 int index = db->addColour(newColour, dialog.getColourName());
Chris@285 722 db->setUseDarkBackground(index, dialog.isDarkBackgroundChecked());
Chris@285 723 }
Chris@285 724 }
Chris@377 725
Chris@377 726 void
Chris@377 727 PropertyBox::playAudibleChanged(bool audible)
Chris@377 728 {
Chris@377 729 m_playButton->setState(audible);
Chris@377 730 }
Chris@377 731
Chris@377 732 void
Chris@377 733 PropertyBox::playAudibleButtonChanged(bool audible)
Chris@377 734 {
Chris@377 735 PlayParameters *params = m_container->getPlayParameters();
Chris@377 736 if (!params) return;
Chris@377 737
Chris@377 738 if (params->isPlayAudible() != audible) {
Chris@377 739 PlayParameterRepository::EditCommand *command =
Chris@377 740 new PlayParameterRepository::EditCommand(params);
Chris@377 741 command->setPlayAudible(audible);
Chris@377 742 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 743 }
Chris@377 744 }
Chris@0 745
Chris@34 746 void
Chris@34 747 PropertyBox::playGainChanged(float gain)
Chris@34 748 {
Chris@34 749 int dialValue = lrint(log10(gain) * 20.0);
Chris@34 750 if (dialValue < -50) dialValue = -50;
Chris@34 751 if (dialValue > 50) dialValue = 50;
Chris@34 752 emit changePlayGainDial(dialValue);
Chris@34 753 }
Chris@34 754
Chris@34 755 void
Chris@34 756 PropertyBox::playGainDialChanged(int dialValue)
Chris@34 757 {
Chris@218 758 QObject *obj = sender();
Chris@377 759
Chris@377 760 PlayParameters *params = m_container->getPlayParameters();
Chris@377 761 if (!params) return;
Chris@377 762
Chris@34 763 float gain = pow(10, float(dialValue) / 20.0);
Chris@377 764
Chris@377 765 if (params->getPlayGain() != gain) {
Chris@377 766 PlayParameterRepository::EditCommand *command =
Chris@377 767 new PlayParameterRepository::EditCommand(params);
Chris@377 768 command->setPlayGain(gain);
Chris@377 769 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 770 }
Chris@377 771
Chris@218 772 updateContextHelp(obj);
Chris@34 773 }
Chris@34 774
Chris@34 775 void
Chris@34 776 PropertyBox::playPanChanged(float pan)
Chris@34 777 {
Chris@34 778 int dialValue = lrint(pan * 50.0);
Chris@34 779 if (dialValue < -50) dialValue = -50;
Chris@34 780 if (dialValue > 50) dialValue = 50;
Chris@34 781 emit changePlayPanDial(dialValue);
Chris@34 782 }
Chris@34 783
Chris@34 784 void
Chris@34 785 PropertyBox::playPanDialChanged(int dialValue)
Chris@34 786 {
Chris@218 787 QObject *obj = sender();
Chris@377 788
Chris@377 789 PlayParameters *params = m_container->getPlayParameters();
Chris@377 790 if (!params) return;
Chris@377 791
Chris@34 792 float pan = float(dialValue) / 50.0;
Chris@34 793 if (pan < -1.0) pan = -1.0;
Chris@34 794 if (pan > 1.0) pan = 1.0;
Chris@377 795
Chris@377 796 if (params->getPlayPan() != pan) {
Chris@377 797 PlayParameterRepository::EditCommand *command =
Chris@377 798 new PlayParameterRepository::EditCommand(params);
Chris@377 799 command->setPlayPan(pan);
Chris@377 800 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 801 }
Chris@377 802
Chris@218 803 updateContextHelp(obj);
Chris@34 804 }
Chris@0 805
Chris@63 806 void
Chris@63 807 PropertyBox::editPlugin()
Chris@63 808 {
Chris@63 809 //!!! should probably just emit and let something else do this
Chris@63 810
Chris@63 811 PlayParameters *params = m_container->getPlayParameters();
Chris@63 812 if (!params) return;
Chris@63 813
Chris@63 814 QString pluginId = params->getPlayPluginId();
Chris@63 815 QString configurationXml = params->getPlayPluginConfiguration();
Chris@377 816
Chris@377 817 PlayParameterRepository::EditCommand *command =
Chris@377 818 new PlayParameterRepository::EditCommand(params);
Chris@63 819
Chris@63 820 RealTimePluginFactory *factory =
Chris@63 821 RealTimePluginFactory::instanceFor(pluginId);
Chris@63 822 if (!factory) return;
Chris@63 823
Chris@63 824 RealTimePluginInstance *instance =
Chris@63 825 factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1);
Chris@63 826 if (!instance) return;
Chris@63 827
Chris@71 828 PluginXml(instance).setParametersFromXml(configurationXml);
Chris@63 829
Chris@163 830 PluginParameterDialog *dialog = new PluginParameterDialog(instance);
Chris@64 831 connect(dialog, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 832 this, SLOT(pluginConfigurationChanged(QString)));
Chris@64 833
Chris@63 834 if (dialog->exec() == QDialog::Accepted) {
Chris@377 835 QString newConfiguration = PluginXml(instance).toXmlString();
Chris@377 836 command->setPlayPluginConfiguration(newConfiguration);
Chris@377 837 CommandHistory::getInstance()->addCommand(command, true);
Chris@64 838 } else {
Chris@377 839 delete command;
Chris@64 840 // restore in case we mucked about with the configuration
Chris@64 841 // as a consequence of signals from the dialog
Chris@64 842 params->setPlayPluginConfiguration(configurationXml);
Chris@63 843 }
Chris@63 844
Chris@63 845 delete dialog;
Chris@63 846 delete instance;
Chris@63 847 }
Chris@63 848
Chris@64 849 void
Chris@64 850 PropertyBox::pluginConfigurationChanged(QString configurationXml)
Chris@64 851 {
Chris@64 852 PlayParameters *params = m_container->getPlayParameters();
Chris@64 853 if (!params) return;
Chris@64 854
Chris@64 855 params->setPlayPluginConfiguration(configurationXml);
Chris@64 856 }
Chris@185 857
Chris@185 858 void
Chris@185 859 PropertyBox::layerVisibilityChanged(bool visible)
Chris@185 860 {
Chris@185 861 if (m_showButton) m_showButton->setState(visible);
Chris@185 862 }
Chris@189 863
Chris@189 864 void
Chris@189 865 PropertyBox::mouseEnteredWidget()
Chris@189 866 {
Chris@218 867 updateContextHelp(sender());
Chris@218 868 }
Chris@218 869
Chris@218 870 void
Chris@218 871 PropertyBox::updateContextHelp(QObject *o)
Chris@218 872 {
Chris@218 873 QWidget *w = dynamic_cast<QWidget *>(o);
Chris@189 874 if (!w) return;
Chris@218 875
Chris@189 876 if (!m_container) return;
Chris@190 877 QString cname = m_container->getPropertyContainerName();
Chris@189 878 if (cname == "") return;
Chris@189 879
Chris@189 880 QString wname = w->objectName();
Chris@189 881
Chris@218 882 QString extraText;
Chris@218 883 AudioDial *dial = dynamic_cast<AudioDial *>(w);
Chris@218 884 if (dial) {
Chris@218 885 float mv = dial->mappedValue();
Chris@218 886 QString unit = "";
Chris@218 887 if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
Chris@218 888 if (unit != "") {
Chris@218 889 extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
Chris@218 890 } else {
Chris@218 891 extraText = tr(" (current value: %1)").arg(mv);
Chris@218 892 }
Chris@218 893 }
Chris@218 894
Chris@189 895 if (w == m_showButton) {
Chris@190 896 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
Chris@189 897 } else if (w == m_playButton) {
Chris@190 898 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
Chris@189 899 } else if (wname == "") {
Chris@189 900 return;
Chris@335 901 } else if (dynamic_cast<QAbstractButton *>(w)) {
Chris@190 902 emit contextHelpChanged(tr("Toggle %1 property of %2")
Chris@189 903 .arg(wname).arg(cname));
Chris@189 904 } else {
Chris@218 905 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
Chris@218 906 .arg(wname).arg(cname).arg(extraText));
Chris@189 907 }
Chris@189 908 }
Chris@189 909
Chris@189 910 void
Chris@189 911 PropertyBox::mouseLeftWidget()
Chris@189 912 {
Chris@218 913 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
Chris@218 914 emit contextHelpChanged("");
Chris@218 915 }
Chris@189 916 }
Chris@189 917
Chris@64 918