annotate widgets/PropertyBox.cpp @ 675:3437e0fad7ae imaf_enc

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