annotate widgets/PropertyBox.cpp @ 33:651e4e868bcc

* Implement play mute, level and pan controls and a layer visibility control * Handle swapping the buffers in AudioCallbackPlaySource more gracefully, so that in many cases it can be done inaudibly. Still gets it wrong when playing in a noncontiguous selection. * Fix to SV file save for non-2d sparse models * Fixes to LED button drawing and AudioDial mouse functionality * Add progress bar for Ogg file import * Reshuffle PropertyContainer and its subclasses so it can be a QObject * Add layer dormancy (invisible layer permitted to free its cache space) * Optimisations to SpectrogramLayer, removing locks when reading/writing individual pixels in the cache (should be unnecessary there) -- there's still an issue here as we need a lock when reading from the model in case the model is replaced, and we don't currently have one * Several munlock() calls to make it harder to exhaust real memory if running in an RT mode with mlockall() active
author Chris Cannam
date Fri, 17 Feb 2006 18:04:26 +0000
parents 37b110168acf
children c43f2c4f66f2
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@5 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #include "PropertyBox.h"
Chris@0 11
Chris@0 12 #include "base/PropertyContainer.h"
Chris@33 13 #include "base/PlayParameters.h"
Chris@33 14 #include "base/Layer.h"
Chris@0 15
Chris@0 16 #include "AudioDial.h"
Chris@33 17 #include "LEDButton.h"
Chris@0 18
Chris@0 19 #include <QGridLayout>
Chris@0 20 #include <QHBoxLayout>
Chris@33 21 #include <QVBoxLayout>
Chris@0 22 #include <QCheckBox>
Chris@0 23 #include <QComboBox>
Chris@0 24 #include <QLabel>
Chris@33 25 #include <QFrame>
Chris@0 26
Chris@0 27 #include <cassert>
Chris@0 28 #include <iostream>
Chris@0 29
Chris@0 30 //#define DEBUG_PROPERTY_BOX 1
Chris@0 31
Chris@0 32 PropertyBox::PropertyBox(PropertyContainer *container) :
Chris@0 33 m_container(container)
Chris@0 34 {
Chris@0 35 #ifdef DEBUG_PROPERTY_BOX
Chris@0 36 std::cerr << "PropertyBox[" << this << "(\"" <<
Chris@0 37 container->getPropertyContainerName().toStdString() << "\")]::PropertyBox" << std::endl;
Chris@0 38 #endif
Chris@0 39
Chris@33 40 QVBoxLayout *vbox = new QVBoxLayout;
Chris@33 41 setLayout(vbox);
Chris@33 42
Chris@33 43 bool needViewPlayBox = false;
Chris@33 44
Chris@33 45 if (container->getPlayParameters() || dynamic_cast<Layer *>(container)) {
Chris@33 46 needViewPlayBox = true;
Chris@33 47 }
Chris@33 48
Chris@33 49 if (needViewPlayBox) {
Chris@33 50 #ifdef DEBUG_PROPERTY_BOX
Chris@33 51 std::cerr << "Adding view play box" << std::endl;
Chris@33 52 #endif
Chris@33 53 QFrame *frame = new QFrame;
Chris@33 54 frame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@33 55 QHBoxLayout *hbox = new QHBoxLayout;
Chris@33 56 frame->setLayout(hbox);
Chris@33 57 vbox->addWidget(frame);
Chris@33 58 populateViewPlayBox(container, hbox);
Chris@33 59 hbox->insertStretch(-1, 10);
Chris@33 60 }
Chris@33 61
Chris@33 62 m_mainWidget = new QWidget;
Chris@33 63 vbox->addWidget(m_mainWidget);
Chris@33 64
Chris@33 65 vbox->insertStretch(-1, 10);
Chris@33 66
Chris@0 67 m_layout = new QGridLayout;
Chris@33 68 m_mainWidget->setLayout(m_layout);
Chris@0 69
Chris@0 70 PropertyContainer::PropertyList properties = container->getProperties();
Chris@0 71
Chris@0 72 blockSignals(true);
Chris@0 73
Chris@0 74 size_t i;
Chris@0 75
Chris@0 76 for (i = 0; i < properties.size(); ++i) {
Chris@0 77 updatePropertyEditor(properties[i]);
Chris@0 78 }
Chris@0 79
Chris@0 80 blockSignals(false);
Chris@0 81
Chris@0 82 m_layout->setRowStretch(m_layout->rowCount(), 10);
Chris@0 83
Chris@0 84 #ifdef DEBUG_PROPERTY_BOX
Chris@0 85 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl;
Chris@0 86 #endif
Chris@0 87 }
Chris@0 88
Chris@0 89 PropertyBox::~PropertyBox()
Chris@0 90 {
Chris@0 91 #ifdef DEBUG_PROPERTY_BOX
Chris@33 92 std::cerr << "PropertyBox[" << this << "]::~PropertyBox" << std::endl;
Chris@0 93 #endif
Chris@0 94 }
Chris@0 95
Chris@0 96 void
Chris@33 97 PropertyBox::populateViewPlayBox(PropertyContainer *container, QLayout *layout)
Chris@33 98 {
Chris@33 99 Layer *layer = dynamic_cast<Layer *>(container);
Chris@33 100 PlayParameters *params = container->getPlayParameters();
Chris@33 101 if (!params && !layer) return;
Chris@33 102
Chris@33 103 std::cerr << "PropertyBox::populateViewPlayBox: container " << container << " (name " << container->getPropertyContainerName().toStdString() << ") params " << params << std::endl;
Chris@33 104
Chris@33 105 if (layer) {
Chris@33 106 LEDButton *showButton = new LEDButton(Qt::blue);
Chris@33 107 layout->addWidget(showButton);
Chris@33 108 connect(showButton, SIGNAL(stateChanged(bool)),
Chris@33 109 layer, SLOT(showLayer(bool)));
Chris@33 110 }
Chris@33 111
Chris@33 112 if (params) {
Chris@33 113 LEDButton *playButton = new LEDButton(Qt::darkGreen);
Chris@33 114 layout->addWidget(playButton);
Chris@33 115 connect(playButton, SIGNAL(stateChanged(bool)),
Chris@33 116 params, SLOT(setPlayAudible(bool)));
Chris@33 117 }
Chris@33 118 }
Chris@33 119
Chris@33 120 void
Chris@0 121 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
Chris@0 122 {
Chris@0 123 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 124 int row = m_layout->rowCount();
Chris@0 125
Chris@0 126 int min = 0, max = 0, value = 0;
Chris@0 127 value = m_container->getPropertyRangeAndValue(name, &min, &max);
Chris@0 128
Chris@0 129 bool have = (m_propertyControllers.find(name) !=
Chris@0 130 m_propertyControllers.end());
Chris@0 131
Chris@0 132 QString groupName = m_container->getPropertyGroupName(name);
Chris@0 133
Chris@0 134 #ifdef DEBUG_PROPERTY_BOX
Chris@0 135 std::cerr << "PropertyBox[" << this
Chris@0 136 << "(\"" << m_container->getPropertyContainerName().toStdString()
Chris@0 137 << "\")]";
Chris@0 138 std::cerr << "::updatePropertyEditor(\"" << name.toStdString() << "\"):";
Chris@0 139 std::cerr << " value " << value << ", have " << have << ", group \""
Chris@0 140 << groupName.toStdString() << "\"" << std::endl;
Chris@0 141 #endif
Chris@0 142
Chris@0 143 bool inGroup = (groupName != QString());
Chris@0 144
Chris@0 145 if (!have) {
Chris@0 146 if (inGroup) {
Chris@0 147 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 148 #ifdef DEBUG_PROPERTY_BOX
Chris@0 149 std::cerr << "PropertyBox: adding label \"" << groupName.toStdString() << "\" and frame for group for \"" << name.toStdString() << "\"" << std::endl;
Chris@0 150 #endif
Chris@33 151 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 152 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 153 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@0 154 m_groupLayouts[groupName] = new QHBoxLayout;
Chris@0 155 m_groupLayouts[groupName]->setMargin(0);
Chris@0 156 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 157 }
Chris@0 158 } else {
Chris@0 159 #ifdef DEBUG_PROPERTY_BOX
Chris@0 160 std::cerr << "PropertyBox: adding label \"" << name.toStdString() << "\"" << std::endl;
Chris@0 161 #endif
Chris@33 162 m_layout->addWidget(new QLabel(name, m_mainWidget), row, 0);
Chris@0 163 }
Chris@0 164 }
Chris@0 165
Chris@0 166 switch (type) {
Chris@0 167
Chris@0 168 case PropertyContainer::ToggleProperty:
Chris@0 169 {
Chris@0 170 QCheckBox *cb;
Chris@0 171
Chris@0 172 if (have) {
Chris@0 173 cb = dynamic_cast<QCheckBox *>(m_propertyControllers[name]);
Chris@0 174 assert(cb);
Chris@0 175 } else {
Chris@0 176 #ifdef DEBUG_PROPERTY_BOX
Chris@0 177 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
Chris@0 178 #endif
Chris@0 179 cb = new QCheckBox();
Chris@0 180 cb->setObjectName(name);
Chris@0 181 connect(cb, SIGNAL(stateChanged(int)),
Chris@0 182 this, SLOT(propertyControllerChanged(int)));
Chris@0 183 if (inGroup) {
Chris@0 184 cb->setToolTip(name);
Chris@0 185 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 186 } else {
Chris@0 187 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 188 }
Chris@0 189 m_propertyControllers[name] = cb;
Chris@0 190 }
Chris@0 191
Chris@0 192 if (cb->isChecked() != (value > 0)) cb->setChecked(value > 0);
Chris@0 193 break;
Chris@0 194 }
Chris@0 195
Chris@0 196 case PropertyContainer::RangeProperty:
Chris@0 197 {
Chris@0 198 AudioDial *dial;
Chris@0 199
Chris@0 200 if (have) {
Chris@0 201 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 202 assert(dial);
Chris@0 203 } else {
Chris@0 204 #ifdef DEBUG_PROPERTY_BOX
Chris@0 205 std::cerr << "PropertyBox: creating new dial" << std::endl;
Chris@0 206 #endif
Chris@0 207 dial = new AudioDial();
Chris@0 208 dial->setObjectName(name);
Chris@0 209 dial->setMinimum(min);
Chris@0 210 dial->setMaximum(max);
Chris@0 211 dial->setPageStep(1);
Chris@0 212 dial->setNotchesVisible(true);
Chris@0 213 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 214 this, SLOT(propertyControllerChanged(int)));
Chris@0 215
Chris@0 216 if (inGroup) {
Chris@0 217 dial->setFixedWidth(24);
Chris@0 218 dial->setFixedHeight(24);
Chris@0 219 dial->setToolTip(name);
Chris@0 220 m_groupLayouts[groupName]->addWidget(dial);
Chris@0 221 } else {
Chris@0 222 dial->setFixedWidth(32);
Chris@0 223 dial->setFixedHeight(32);
Chris@0 224 m_layout->addWidget(dial, row, 1);
Chris@33 225 QLabel *label = new QLabel(m_mainWidget);
Chris@0 226 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 227 label, SLOT(setNum(int)));
Chris@0 228 label->setNum(value);
Chris@0 229 m_layout->addWidget(label, row, 2);
Chris@0 230 }
Chris@0 231
Chris@0 232 m_propertyControllers[name] = dial;
Chris@0 233 }
Chris@0 234
Chris@0 235 if (dial->value() != value) dial->setValue(value);
Chris@0 236 break;
Chris@0 237 }
Chris@0 238
Chris@0 239 case PropertyContainer::ValueProperty:
Chris@0 240 {
Chris@0 241 QComboBox *cb;
Chris@0 242
Chris@0 243 if (have) {
Chris@0 244 cb = dynamic_cast<QComboBox *>(m_propertyControllers[name]);
Chris@0 245 assert(cb);
Chris@0 246 } else {
Chris@0 247 #ifdef DEBUG_PROPERTY_BOX
Chris@0 248 std::cerr << "PropertyBox: creating new combobox" << std::endl;
Chris@0 249 #endif
Chris@0 250
Chris@0 251 cb = new QComboBox();
Chris@0 252 cb->setObjectName(name);
Chris@0 253 for (int i = min; i <= max; ++i) {
Chris@0 254 cb->addItem(m_container->getPropertyValueLabel(name, i));
Chris@0 255 }
Chris@0 256 connect(cb, SIGNAL(activated(int)),
Chris@0 257 this, SLOT(propertyControllerChanged(int)));
Chris@0 258 if (inGroup) {
Chris@0 259 cb->setToolTip(name);
Chris@0 260 m_groupLayouts[groupName]->addWidget(cb);
Chris@0 261 } else {
Chris@0 262 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 263 }
Chris@0 264 m_propertyControllers[name] = cb;
Chris@0 265 }
Chris@0 266
Chris@0 267 if (cb->currentIndex() != value) cb->setCurrentIndex(value);
Chris@0 268
Chris@0 269 #ifdef Q_WS_MAC
Chris@0 270 // Crashes on startup without this, for some reason
Chris@0 271 cb->setMinimumSize(QSize(10, 10));
Chris@0 272 #endif
Chris@0 273
Chris@0 274 break;
Chris@0 275 }
Chris@0 276
Chris@0 277 default:
Chris@0 278 break;
Chris@0 279 }
Chris@0 280 }
Chris@0 281
Chris@0 282 void
Chris@0 283 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 284 {
Chris@0 285 if (pc != m_container) return;
Chris@0 286
Chris@0 287 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 288 size_t i;
Chris@0 289
Chris@0 290 blockSignals(true);
Chris@0 291
Chris@0 292 for (i = 0; i < properties.size(); ++i) {
Chris@0 293 updatePropertyEditor(properties[i]);
Chris@0 294 }
Chris@0 295
Chris@0 296 blockSignals(false);
Chris@0 297 }
Chris@0 298
Chris@0 299 void
Chris@0 300 PropertyBox::propertyControllerChanged(int value)
Chris@0 301 {
Chris@0 302 QObject *obj = sender();
Chris@0 303 QString name = obj->objectName();
Chris@0 304
Chris@33 305 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
Chris@33 306 << ", " << value << ")" << std::endl;
Chris@0 307
Chris@0 308 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 309
Chris@0 310 if (type != PropertyContainer::InvalidProperty) {
Chris@0 311 m_container->setProperty(name, value);
Chris@0 312 }
Chris@0 313
Chris@0 314 if (type == PropertyContainer::RangeProperty) {
Chris@0 315 AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 316 if (dial) {
Chris@0 317 dial->setToolTip(QString("%1: %2").arg(name).arg(value));
Chris@0 318 //!!! unfortunately this doesn't update an already-visible tooltip
Chris@0 319 }
Chris@0 320 }
Chris@0 321 }
Chris@0 322
Chris@0 323
Chris@0 324
Chris@0 325 #ifdef INCLUDE_MOCFILES
Chris@0 326 #include "PropertyBox.moc.cpp"
Chris@0 327 #endif
Chris@0 328