# HG changeset patch # User Chris Cannam # Date 1161090289 0 # Node ID d4be66d61c045c40e9421c8277164d2f422cd7db # Parent 53b9c7656798a9c555e3416651be9a48421ecdcb * Make audio dial remember its more accurate mapped value as well as its display position * Add tool tip support to audio dial to show values diff -r 53b9c7656798 -r d4be66d61c04 widgets/AudioDial.cpp --- a/widgets/AudioDial.cpp Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/AudioDial.cpp Tue Oct 17 13:04:49 2006 +0000 @@ -25,7 +25,7 @@ * * Ported to Qt4 by Chris Cannam. * - * This file copyright 2003-2005 Chris Cannam, copyright 2005 Pedro + * This file copyright 2003-2006 Chris Cannam, copyright 2005 Pedro * Lopez-Cabanillas. * * This program is free software; you can redistribute it and/or @@ -71,6 +71,9 @@ QDial(parent), m_knobColor(Qt::black), m_meterColor(Qt::white), m_defaultValue(0), + m_mappedValue(0), + m_noMappedUpdate(false), + m_showTooltip(false), m_rangeMapper(0) { m_mouseDial = false; @@ -87,8 +90,13 @@ void AudioDial::setRangeMapper(RangeMapper *mapper) { + if (!m_rangeMapper) { + connect(this, SIGNAL(valueChanged(int)), + this, SLOT(updateMappedValue(int))); + } delete m_rangeMapper; m_rangeMapper = mapper; + m_mappedValue = m_rangeMapper->getValueForPosition(value()); } @@ -317,10 +325,45 @@ } +void AudioDial::setShowToolTip(bool show) +{ + m_showTooltip = show; + m_noMappedUpdate = true; + updateMappedValue(value()); + m_noMappedUpdate = false; +} + + float AudioDial::mappedValue() const { - if (m_rangeMapper) return m_rangeMapper->getValueForPosition(value()); - else return value(); + if (m_rangeMapper) { + std::cerr << "AudioDial::mappedValue(): value = " << value() << ", mappedValue = " << m_mappedValue << std::endl; + return m_mappedValue; + } + return value(); +} + + +void AudioDial::updateMappedValue(int value) +{ + if (m_rangeMapper) { + if (!m_noMappedUpdate) { + m_mappedValue = m_rangeMapper->getValueForPosition(value); + } + } + + if (m_showTooltip) { + QString name = objectName(); + QString unit = ""; + QString text; + if (m_rangeMapper) unit = m_rangeMapper->getUnit(); + if (name != "") { + text = tr("%1: %2%3").arg(name).arg(m_mappedValue).arg(unit); + } else { + text = tr("%2%3").arg(m_mappedValue).arg(unit); + } + setToolTip(text); + } } @@ -381,15 +424,24 @@ (this, tr("Enter new value"), text, - m_rangeMapper->getValueForPosition(value()), + m_mappedValue, min, max, - 5, + 4, &ok); - //!!! need to avoid this rounding by storing the float value + newPosition = m_rangeMapper->getPositionForValue(newValue); - newPosition = m_rangeMapper->getPositionForValue(newValue); + if (ok) { + m_mappedValue = newValue; + m_noMappedUpdate = true; + if (newPosition != value()) { + setValue(newPosition); + } else { + emit valueChanged(newPosition); + } + m_noMappedUpdate = false; + } } else { @@ -399,24 +451,11 @@ tr("Enter a new value from %1 to %2:") .arg(minimum()).arg(maximum()), value(), minimum(), maximum(), pageStep(), &ok); + + if (ok) { + setValue(newPosition); + } } - - if (ok) { - setValue(newPosition); - } - - -/*!!! - int newValue = QInputDialog::getInteger - (this, - tr("Enter new value"), - tr("Select a new value in the range %1 to %2:") - .arg(minimum()).arg(maximum()), - value(), minimum(), maximum(), pageStep(), &ok); - if (ok) { - setValue(newValue); - } -*/ } } diff -r 53b9c7656798 -r d4be66d61c04 widgets/AudioDial.h --- a/widgets/AudioDial.h Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/AudioDial.h Tue Oct 17 13:04:49 2006 +0000 @@ -72,8 +72,10 @@ bool getMouseDial() const { return m_mouseDial; } void setRangeMapper(RangeMapper *mapper); // I take ownership, will delete + const RangeMapper *rangeMapper() const { return m_rangeMapper; } + float mappedValue() const; - float mappedValue() const; + void setShowToolTip(bool show); public slots: /** @@ -107,17 +109,24 @@ virtual void mouseReleaseEvent(QMouseEvent *pMouseEvent); virtual void mouseDoubleClickEvent(QMouseEvent *pMouseEvent); +protected slots: + void updateMappedValue(int value); + private: QColor m_knobColor; QColor m_meterColor; int m_defaultValue; + float m_mappedValue; + bool m_noMappedUpdate; // Alternate mouse behavior tracking. bool m_mouseDial; bool m_mousePressed; QPoint m_posMouse; + bool m_showTooltip; + RangeMapper *m_rangeMapper; }; diff -r 53b9c7656798 -r d4be66d61c04 widgets/PluginParameterBox.cpp --- a/widgets/PluginParameterBox.cpp Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/PluginParameterBox.cpp Tue Oct 17 13:04:49 2006 +0000 @@ -163,6 +163,7 @@ dial->setFixedHeight(32); dial->setRangeMapper(new LinearRangeMapper (imin, imax, min, max, unit)); + dial->setShowToolTip(true); connect(dial, SIGNAL(valueChanged(int)), this, SLOT(dialChanged(int))); m_layout->addWidget(dial, i + offset, 1); @@ -208,15 +209,30 @@ float min = params.minValue; float max = params.maxValue; + float newValue; + float qtz = 0.0; if (params.isQuantized) qtz = params.quantizeStep; + + AudioDial *ad = dynamic_cast(obj); - if (qtz == 0.0) { - qtz = (max - min) / 100.0; + if (ad && ad->rangeMapper()) { + + newValue = ad->mappedValue(); + if (newValue < min) newValue = min; + if (newValue > max) newValue = max; + if (qtz != 0.0) { + ival = lrintf((newValue - min) / qtz); + newValue = min + ival * qtz; + } + + } else { + if (qtz == 0.0) { + qtz = (max - min) / 100.0; + } + newValue = min + ival * qtz; } - float newValue = min + ival * qtz; - QDoubleSpinBox *spin = m_params[name].spin; if (spin) { spin->blockSignals(true); diff -r 53b9c7656798 -r d4be66d61c04 widgets/PropertyBox.cpp --- a/widgets/PropertyBox.cpp Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/PropertyBox.cpp Tue Oct 17 13:04:49 2006 +0000 @@ -181,11 +181,12 @@ gainDial->setFixedWidth(24); gainDial->setFixedHeight(24); gainDial->setNotchesVisible(false); - gainDial->setToolTip(tr("Playback Level")); +//!!! gainDial->setToolTip(tr("Playback Level")); gainDial->setDefaultValue(0); - gainDial->setObjectName(tr("Playback Level")); + gainDial->setObjectName(tr("Playback Gain")); gainDial->setRangeMapper(new LinearRangeMapper (-50, 50, -25, 25, tr("dB"))); + gainDial->setShowToolTip(true); connect(gainDial, SIGNAL(valueChanged(int)), this, SLOT(playGainDialChanged(int))); connect(params, SIGNAL(playGainChanged(float)), @@ -207,7 +208,8 @@ panDial->setNotchesVisible(false); panDial->setToolTip(tr("Playback Pan / Balance")); panDial->setDefaultValue(0); - gainDial->setObjectName(tr("Playback Pan / Balance")); + panDial->setObjectName(tr("Playback Pan / Balance")); + panDial->setShowToolTip(true); connect(panDial, SIGNAL(valueChanged(int)), this, SLOT(playPanDialChanged(int))); connect(params, SIGNAL(playPanChanged(float)), @@ -324,13 +326,14 @@ dial->setNotchesVisible((max - min) <= 12); dial->setDefaultValue(value); dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name)); + dial->setShowToolTip(true); connect(dial, SIGNAL(valueChanged(int)), this, SLOT(propertyControllerChanged(int))); if (inGroup) { dial->setFixedWidth(24); dial->setFixedHeight(24); - dial->setToolTip(propertyLabel); +//!!! dial->setToolTip(propertyLabel); m_groupLayouts[groupName]->addWidget(dial); } else { dial->setFixedWidth(32); @@ -485,13 +488,13 @@ m_container->setPropertyWithCommand(name, value); } - if (type == PropertyContainer::RangeProperty) { - AudioDial *dial = dynamic_cast(m_propertyControllers[name]); - if (dial) { - dial->setToolTip(QString("%1: %2").arg(name).arg(value)); - //!!! unfortunately this doesn't update an already-visible tooltip - } - } +// if (type == PropertyContainer::RangeProperty) { +// AudioDial *dial = dynamic_cast(m_propertyControllers[name]); +//!!! if (dial) { +// dial->setToolTip(QString("%1: %2").arg(name).arg(value)); +// //!!! unfortunately this doesn't update an already-visible tooltip +// } +// } } void