annotate widgets/PropertyBox.cpp @ 62:50429a56680f

* Add plugin parameter dialog, and use it to set up parameters for feature extraction plugins via a semi-opaque (translucent?) configurationXml string which is associated with a given transform instance. This is not yet saved to and restored from the SV file properly. * Remove no-longer-relevant BeatDetect and BeatDetectionFunction transforms (replaced a long time ago with the beat detector plugin).
author Chris Cannam
date Wed, 22 Mar 2006 17:38:29 +0000
parents 705f05ab42e3
children fb02fe13ff47
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@59 7 This file copyright 2006 Chris Cannam.
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@0 17
Chris@0 18 #include "base/PropertyContainer.h"
Chris@33 19 #include "base/PlayParameters.h"
Chris@33 20 #include "base/Layer.h"
Chris@0 21
Chris@0 22 #include "AudioDial.h"
Chris@33 23 #include "LEDButton.h"
Chris@0 24
Chris@0 25 #include <QGridLayout>
Chris@0 26 #include <QHBoxLayout>
Chris@33 27 #include <QVBoxLayout>
Chris@0 28 #include <QCheckBox>
Chris@0 29 #include <QComboBox>
Chris@0 30 #include <QLabel>
Chris@33 31 #include <QFrame>
Chris@0 32
Chris@0 33 #include <cassert>
Chris@0 34 #include <iostream>
Martin@46 35 #include <cmath>
Chris@0 36
Chris@0 37 //#define DEBUG_PROPERTY_BOX 1
Chris@0 38
Chris@0 39 PropertyBox::PropertyBox(PropertyContainer *container) :
Chris@0 40 m_container(container)
Chris@0 41 {
Chris@0 42 #ifdef DEBUG_PROPERTY_BOX
Chris@0 43 std::cerr << "PropertyBox[" << this << "(\"" <<
Chris@0 44 container->getPropertyContainerName().toStdString() << "\")]::PropertyBox" << std::endl;
Chris@0 45 #endif
Chris@0 46
Chris@34 47 m_mainBox = new QVBoxLayout;
Chris@34 48 setLayout(m_mainBox);
Chris@33 49
Chris@33 50 bool needViewPlayBox = false;
Chris@33 51
Chris@34 52 m_mainWidget = new QWidget;
Chris@34 53 m_mainBox->addWidget(m_mainWidget);
Chris@34 54 m_mainBox->insertStretch(1, 10);
Chris@33 55
Chris@34 56 m_viewPlayFrame = 0;
Chris@34 57 populateViewPlayFrame();
Chris@33 58
Chris@0 59 m_layout = new QGridLayout;
Chris@34 60 m_layout->setMargin(0);
Chris@33 61 m_mainWidget->setLayout(m_layout);
Chris@0 62
Chris@34 63 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 64
Chris@0 65 blockSignals(true);
Chris@0 66
Chris@0 67 size_t i;
Chris@0 68
Chris@0 69 for (i = 0; i < properties.size(); ++i) {
Chris@0 70 updatePropertyEditor(properties[i]);
Chris@0 71 }
Chris@0 72
Chris@0 73 blockSignals(false);
Chris@0 74
Chris@0 75 m_layout->setRowStretch(m_layout->rowCount(), 10);
Chris@0 76
Chris@0 77 #ifdef DEBUG_PROPERTY_BOX
Chris@0 78 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl;
Chris@0 79 #endif
Chris@0 80 }
Chris@0 81
Chris@0 82 PropertyBox::~PropertyBox()
Chris@0 83 {
Chris@0 84 #ifdef DEBUG_PROPERTY_BOX
Chris@33 85 std::cerr << "PropertyBox[" << this << "]::~PropertyBox" << std::endl;
Chris@0 86 #endif
Chris@0 87 }
Chris@0 88
Chris@0 89 void
Chris@34 90 PropertyBox::populateViewPlayFrame()
Chris@33 91 {
Chris@36 92 #ifdef DEBUG_PROPERTY_BOX
Chris@34 93 std::cerr << "PropertyBox(" << m_container << ")::populateViewPlayFrame" << std::endl;
Chris@36 94 #endif
Chris@34 95
Chris@34 96 if (m_viewPlayFrame) {
Chris@34 97 delete m_viewPlayFrame;
Chris@34 98 m_viewPlayFrame = 0;
Chris@34 99 }
Chris@34 100
Chris@34 101 if (!m_container) return;
Chris@34 102
Chris@34 103 Layer *layer = dynamic_cast<Layer *>(m_container);
Chris@34 104 if (layer) {
Chris@34 105 connect(layer, SIGNAL(modelReplaced()),
Chris@34 106 this, SLOT(populateViewPlayFrame()));
Chris@34 107 }
Chris@34 108
Chris@34 109 PlayParameters *params = m_container->getPlayParameters();
Chris@33 110 if (!params && !layer) return;
Chris@33 111
Chris@34 112 m_viewPlayFrame = new QFrame;
Chris@34 113 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@34 114 m_mainBox->addWidget(m_viewPlayFrame);
Chris@34 115
Chris@34 116 QHBoxLayout *layout = new QHBoxLayout;
Chris@34 117 m_viewPlayFrame->setLayout(layout);
Chris@34 118
Chris@34 119 layout->setMargin(layout->margin() / 2);
Chris@34 120
Chris@36 121 #ifdef DEBUG_PROPERTY_BOX
Chris@34 122 std::cerr << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName().toStdString() << ") params " << params << std::endl;
Chris@36 123 #endif
Chris@36 124
Chris@33 125 if (layer) {
Chris@34 126 QLabel *showLabel = new QLabel(tr("Show"));
Chris@34 127 layout->addWidget(showLabel);
Chris@34 128 layout->setAlignment(showLabel, Qt::AlignVCenter);
Chris@34 129
Chris@33 130 LEDButton *showButton = new LEDButton(Qt::blue);
Chris@33 131 layout->addWidget(showButton);
Chris@47 132 connect(showButton, SIGNAL(stateChanged(bool)),
Chris@47 133 this, SIGNAL(showLayer(bool)));
Chris@34 134 layout->setAlignment(showButton, Qt::AlignVCenter);
Chris@33 135 }
Chris@33 136
Chris@33 137 if (params) {
Chris@34 138
Chris@34 139 QLabel *playLabel = new QLabel(tr("Play"));
Chris@34 140 layout->addWidget(playLabel);
Chris@34 141 layout->setAlignment(playLabel, Qt::AlignVCenter);
Chris@34 142
Chris@33 143 LEDButton *playButton = new LEDButton(Qt::darkGreen);
Chris@33 144 layout->addWidget(playButton);
Chris@33 145 connect(playButton, SIGNAL(stateChanged(bool)),
Chris@33 146 params, SLOT(setPlayAudible(bool)));
Chris@34 147 connect(params, SIGNAL(playAudibleChanged(bool)),
Chris@34 148 playButton, SLOT(setState(bool)));
Chris@34 149 layout->setAlignment(playButton, Qt::AlignVCenter);
Chris@34 150
Chris@34 151 layout->insertStretch(-1, 10);
Chris@34 152
Chris@34 153 AudioDial *gainDial = new AudioDial;
Chris@34 154 layout->addWidget(gainDial);
Chris@34 155 gainDial->setMeterColor(Qt::darkRed);
Chris@34 156 gainDial->setMinimum(-50);
Chris@34 157 gainDial->setMaximum(50);
Chris@34 158 gainDial->setPageStep(1);
Chris@34 159 gainDial->setFixedWidth(24);
Chris@34 160 gainDial->setFixedHeight(24);
Chris@34 161 gainDial->setNotchesVisible(false);
Chris@57 162 gainDial->setToolTip(tr("Playback Level"));
Chris@34 163 gainDial->setDefaultValue(0);
Chris@34 164 connect(gainDial, SIGNAL(valueChanged(int)),
Chris@34 165 this, SLOT(playGainDialChanged(int)));
Chris@34 166 connect(params, SIGNAL(playGainChanged(float)),
Chris@34 167 this, SLOT(playGainChanged(float)));
Chris@34 168 connect(this, SIGNAL(changePlayGain(float)),
Chris@34 169 params, SLOT(setPlayGain(float)));
Chris@34 170 connect(this, SIGNAL(changePlayGainDial(int)),
Chris@34 171 gainDial, SLOT(setValue(int)));
Chris@34 172 layout->setAlignment(gainDial, Qt::AlignVCenter);
Chris@34 173
Chris@34 174 AudioDial *panDial = new AudioDial;
Chris@34 175 layout->addWidget(panDial);
Chris@34 176 panDial->setMeterColor(Qt::darkGreen);
Chris@34 177 panDial->setMinimum(-50);
Chris@34 178 panDial->setMaximum(50);
Chris@34 179 panDial->setPageStep(1);
Chris@34 180 panDial->setFixedWidth(24);
Chris@34 181 panDial->setFixedHeight(24);
Chris@34 182 panDial->setNotchesVisible(false);
Chris@57 183 panDial->setToolTip(tr("Playback Pan / Balance"));
Chris@34 184 panDial->setDefaultValue(0);
Chris@34 185 connect(panDial, SIGNAL(valueChanged(int)),
Chris@34 186 this, SLOT(playPanDialChanged(int)));
Chris@34 187 connect(params, SIGNAL(playPanChanged(float)),
Chris@34 188 this, SLOT(playPanChanged(float)));
Chris@34 189 connect(this, SIGNAL(changePlayPan(float)),
Chris@34 190 params, SLOT(setPlayPan(float)));
Chris@34 191 connect(this, SIGNAL(changePlayPanDial(int)),
Chris@34 192 panDial, SLOT(setValue(int)));
Chris@34 193 layout->setAlignment(panDial, Qt::AlignVCenter);
Chris@34 194
Chris@34 195 } else {
Chris@34 196
Chris@34 197 layout->insertStretch(-1, 10);
Chris@33 198 }
Chris@33 199 }
Chris@33 200
Chris@33 201 void
Chris@0 202 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
Chris@0 203 {
Chris@0 204 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 205 int row = m_layout->rowCount();
Chris@0 206
Chris@0 207 int min = 0, max = 0, value = 0;
Chris@0 208 value = m_container->getPropertyRangeAndValue(name, &min, &max);
Chris@0 209
Chris@0 210 bool have = (m_propertyControllers.find(name) !=
Chris@0 211 m_propertyControllers.end());
Chris@0 212
Chris@0 213 QString groupName = m_container->getPropertyGroupName(name);
Chris@0 214
Chris@0 215 #ifdef DEBUG_PROPERTY_BOX
Chris@0 216 std::cerr << "PropertyBox[" << this
Chris@0 217 << "(\"" << m_container->getPropertyContainerName().toStdString()
Chris@0 218 << "\")]";
Chris@0 219 std::cerr << "::updatePropertyEditor(\"" << name.toStdString() << "\"):";
Chris@0 220 std::cerr << " value " << value << ", have " << have << ", group \""
Chris@0 221 << groupName.toStdString() << "\"" << std::endl;
Chris@0 222 #endif
Chris@0 223
Chris@0 224 bool inGroup = (groupName != QString());
Chris@0 225
Chris@0 226 if (!have) {
Chris@0 227 if (inGroup) {
Chris@0 228 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 229 #ifdef DEBUG_PROPERTY_BOX
Chris@0 230 std::cerr << "PropertyBox: adding label \"" << groupName.toStdString() << "\" and frame for group for \"" << name.toStdString() << "\"" << std::endl;
Chris@0 231 #endif
Chris@33 232 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 233 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 234 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@0 235 m_groupLayouts[groupName] = new QHBoxLayout;
Chris@0 236 m_groupLayouts[groupName]->setMargin(0);
Chris@0 237 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 238 }
Chris@0 239 } else {
Chris@0 240 #ifdef DEBUG_PROPERTY_BOX
Chris@0 241 std::cerr << "PropertyBox: adding label \"" << name.toStdString() << "\"" << std::endl;
Chris@0 242 #endif
Chris@33 243 m_layout->addWidget(new QLabel(name, m_mainWidget), row, 0);
Chris@0 244 }
Chris@0 245 }
Chris@0 246
Chris@0 247 switch (type) {
Chris@0 248
Chris@0 249 case PropertyContainer::ToggleProperty:
Chris@0 250 {
Chris@0 251 QCheckBox *cb;
Chris@0 252
Chris@0 253 if (have) {
Chris@0 254 cb = dynamic_cast<QCheckBox *>(m_propertyControllers[name]);
Chris@0 255 assert(cb);
Chris@0 256 } else {
Chris@0 257 #ifdef DEBUG_PROPERTY_BOX
Chris@0 258 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
Chris@0 259 #endif
Chris@0 260 cb = new QCheckBox();
Chris@0 261 cb->setObjectName(name);
Chris@0 262 connect(cb, SIGNAL(stateChanged(int)),
Chris@0 263 this, SLOT(propertyControllerChanged(int)));
Chris@0 264 if (inGroup) {
Chris@0 265 cb->setToolTip(name);
Chris@0 266 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 267 } else {
Chris@0 268 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 269 }
Chris@0 270 m_propertyControllers[name] = cb;
Chris@0 271 }
Chris@0 272
Chris@55 273 if (cb->isChecked() != (value > 0)) {
Chris@55 274 cb->blockSignals(true);
Chris@55 275 cb->setChecked(value > 0);
Chris@55 276 cb->blockSignals(false);
Chris@55 277 }
Chris@0 278 break;
Chris@0 279 }
Chris@0 280
Chris@0 281 case PropertyContainer::RangeProperty:
Chris@0 282 {
Chris@0 283 AudioDial *dial;
Chris@0 284
Chris@0 285 if (have) {
Chris@0 286 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 287 assert(dial);
Chris@0 288 } else {
Chris@0 289 #ifdef DEBUG_PROPERTY_BOX
Chris@0 290 std::cerr << "PropertyBox: creating new dial" << std::endl;
Chris@0 291 #endif
Chris@0 292 dial = new AudioDial();
Chris@0 293 dial->setObjectName(name);
Chris@0 294 dial->setMinimum(min);
Chris@0 295 dial->setMaximum(max);
Chris@0 296 dial->setPageStep(1);
Chris@34 297 dial->setNotchesVisible((max - min) <= 12);
Chris@34 298 dial->setDefaultValue(value);
Chris@0 299 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 300 this, SLOT(propertyControllerChanged(int)));
Chris@0 301
Chris@0 302 if (inGroup) {
Chris@0 303 dial->setFixedWidth(24);
Chris@0 304 dial->setFixedHeight(24);
Chris@0 305 dial->setToolTip(name);
Chris@0 306 m_groupLayouts[groupName]->addWidget(dial);
Chris@0 307 } else {
Chris@0 308 dial->setFixedWidth(32);
Chris@0 309 dial->setFixedHeight(32);
Chris@0 310 m_layout->addWidget(dial, row, 1);
Chris@33 311 QLabel *label = new QLabel(m_mainWidget);
Chris@0 312 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 313 label, SLOT(setNum(int)));
Chris@0 314 label->setNum(value);
Chris@0 315 m_layout->addWidget(label, row, 2);
Chris@0 316 }
Chris@0 317
Chris@0 318 m_propertyControllers[name] = dial;
Chris@0 319 }
Chris@0 320
Chris@55 321 if (dial->value() != value) {
Chris@55 322 dial->blockSignals(true);
Chris@55 323 dial->setValue(value);
Chris@55 324 dial->blockSignals(false);
Chris@55 325 }
Chris@0 326 break;
Chris@0 327 }
Chris@0 328
Chris@0 329 case PropertyContainer::ValueProperty:
Chris@0 330 {
Chris@0 331 QComboBox *cb;
Chris@0 332
Chris@0 333 if (have) {
Chris@0 334 cb = dynamic_cast<QComboBox *>(m_propertyControllers[name]);
Chris@0 335 assert(cb);
Chris@0 336 } else {
Chris@0 337 #ifdef DEBUG_PROPERTY_BOX
Chris@0 338 std::cerr << "PropertyBox: creating new combobox" << std::endl;
Chris@0 339 #endif
Chris@0 340
Chris@0 341 cb = new QComboBox();
Chris@0 342 cb->setObjectName(name);
Chris@0 343 for (int i = min; i <= max; ++i) {
Chris@0 344 cb->addItem(m_container->getPropertyValueLabel(name, i));
Chris@0 345 }
Chris@0 346 connect(cb, SIGNAL(activated(int)),
Chris@0 347 this, SLOT(propertyControllerChanged(int)));
Chris@0 348 if (inGroup) {
Chris@0 349 cb->setToolTip(name);
Chris@0 350 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 351 } else {
Chris@0 352 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 353 }
Chris@0 354 m_propertyControllers[name] = cb;
Chris@0 355 }
Chris@0 356
Chris@55 357 if (cb->currentIndex() != value) {
Chris@55 358 cb->blockSignals(true);
Chris@55 359 cb->setCurrentIndex(value);
Chris@55 360 cb->blockSignals(false);
Chris@55 361 }
Chris@0 362
Chris@0 363 #ifdef Q_WS_MAC
Chris@0 364 // Crashes on startup without this, for some reason
Chris@0 365 cb->setMinimumSize(QSize(10, 10));
Chris@0 366 #endif
Chris@0 367
Chris@0 368 break;
Chris@0 369 }
Chris@0 370
Chris@0 371 default:
Chris@0 372 break;
Chris@0 373 }
Chris@0 374 }
Chris@0 375
Chris@0 376 void
Chris@0 377 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 378 {
Chris@0 379 if (pc != m_container) return;
Chris@0 380
Chris@55 381 #ifdef DEBUG_PROPERTY_BOX
Chris@55 382 std::cerr << "PropertyBox::propertyContainerPropertyChanged" << std::endl;
Chris@55 383 #endif
Chris@55 384
Chris@0 385 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 386 size_t i;
Chris@0 387
Chris@0 388 blockSignals(true);
Chris@0 389
Chris@0 390 for (i = 0; i < properties.size(); ++i) {
Chris@0 391 updatePropertyEditor(properties[i]);
Chris@0 392 }
Chris@0 393
Chris@0 394 blockSignals(false);
Chris@0 395 }
Chris@0 396
Chris@0 397 void
Chris@0 398 PropertyBox::propertyControllerChanged(int value)
Chris@0 399 {
Chris@0 400 QObject *obj = sender();
Chris@0 401 QString name = obj->objectName();
Chris@0 402
Chris@34 403 #ifdef DEBUG_PROPERTY_BOX
Chris@33 404 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
Chris@33 405 << ", " << value << ")" << std::endl;
Chris@34 406 #endif
Chris@0 407
Chris@0 408 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 409
Chris@0 410 if (type != PropertyContainer::InvalidProperty) {
Chris@55 411 m_container->setPropertyWithCommand(name, value);
Chris@0 412 }
Chris@0 413
Chris@0 414 if (type == PropertyContainer::RangeProperty) {
Chris@0 415 AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 416 if (dial) {
Chris@0 417 dial->setToolTip(QString("%1: %2").arg(name).arg(value));
Chris@0 418 //!!! unfortunately this doesn't update an already-visible tooltip
Chris@0 419 }
Chris@0 420 }
Chris@0 421 }
Chris@0 422
Chris@34 423 void
Chris@34 424 PropertyBox::playGainChanged(float gain)
Chris@34 425 {
Chris@34 426 int dialValue = lrint(log10(gain) * 20.0);
Chris@34 427 if (dialValue < -50) dialValue = -50;
Chris@34 428 if (dialValue > 50) dialValue = 50;
Chris@34 429 emit changePlayGainDial(dialValue);
Chris@34 430 }
Chris@34 431
Chris@34 432 void
Chris@34 433 PropertyBox::playGainDialChanged(int dialValue)
Chris@34 434 {
Chris@34 435 float gain = pow(10, float(dialValue) / 20.0);
Chris@34 436 emit changePlayGain(gain);
Chris@34 437 }
Chris@34 438
Chris@34 439 void
Chris@34 440 PropertyBox::playPanChanged(float pan)
Chris@34 441 {
Chris@34 442 int dialValue = lrint(pan * 50.0);
Chris@34 443 if (dialValue < -50) dialValue = -50;
Chris@34 444 if (dialValue > 50) dialValue = 50;
Chris@34 445 emit changePlayPanDial(dialValue);
Chris@34 446 }
Chris@34 447
Chris@34 448 void
Chris@34 449 PropertyBox::playPanDialChanged(int dialValue)
Chris@34 450 {
Chris@34 451 float pan = float(dialValue) / 50.0;
Chris@34 452 if (pan < -1.0) pan = -1.0;
Chris@34 453 if (pan > 1.0) pan = 1.0;
Chris@34 454 emit changePlayPan(pan);
Chris@34 455 }
Chris@0 456
Chris@0 457 #ifdef INCLUDE_MOCFILES
Chris@0 458 #include "PropertyBox.moc.cpp"
Chris@0 459 #endif
Chris@0 460