diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-01-03 17:17:26 -0500 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-01-03 17:17:26 -0500 |
commit | 6fcd283cd80a34747320340ecc9a17b9b4b9606a (patch) | |
tree | 1be642930460e2b47a5d4c1a8dc863ee1774883f /src/widget | |
parent | 28177a40eaf77683c402e18f08755fac2e02e1e4 (diff) |
Revert "Normalize potmeter widget values to [0.0, 1.0] instead of [0.0, 127.0]."
This reverts commit 328d5958483ceb33cee74def6c947111182b5af0.
Diffstat (limited to 'src/widget')
-rw-r--r-- | src/widget/knobeventhandler.h | 16 | ||||
-rw-r--r-- | src/widget/wdisplay.cpp | 3 | ||||
-rw-r--r-- | src/widget/wknob.cpp | 4 | ||||
-rw-r--r-- | src/widget/wknobcomposed.cpp | 4 | ||||
-rw-r--r-- | src/widget/woverview.cpp | 32 | ||||
-rw-r--r-- | src/widget/woverview.h | 10 | ||||
-rw-r--r-- | src/widget/wslidercomposed.cpp | 30 | ||||
-rw-r--r-- | src/widget/wvumeter.cpp | 9 | ||||
-rw-r--r-- | src/widget/wwaveformviewer.cpp | 15 |
9 files changed, 51 insertions, 72 deletions
diff --git a/src/widget/knobeventhandler.h b/src/widget/knobeventhandler.h index 61a11951be..f638f5a87e 100644 --- a/src/widget/knobeventhandler.h +++ b/src/widget/knobeventhandler.h @@ -31,12 +31,13 @@ class KnobEventHandler { } double value = pWidget->getValue(); - // For legacy (MIDI) reasons this is tuned to 127. - value += dist / 127.0; + value += dist; QCursor::setPos(m_startPos); - // Clamp to [0.0, 1.0] - value = math_max(0.0, math_min(1.0, value)); + if (value > 127.0) + value = 127.0; + else if (value < 0.0) + value = 0.0; pWidget->setValue(value); emit(pWidget->valueChangedLeftDown(value)); @@ -79,12 +80,11 @@ class KnobEventHandler { } void wheelEvent(T* pWidget, QWheelEvent* e) { - // For legacy (MIDI) reasons this is tuned to 127. - double wheelDirection = e->delta() / (120.0 * 127.0); + double wheelDirection = e->delta() / 120.; double newValue = pWidget->getValue() + wheelDirection; - // Clamp to [0.0, 1.0] - newValue = math_max(0.0, math_min(1.0, newValue)); + // Clamp to [0.0, 127.0] + newValue = math_max(0.0, math_min(127.0, newValue)); pWidget->updateValue(newValue); e->accept(); diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index 7c325e598a..0d8bbf9cb5 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -108,7 +108,8 @@ void WDisplay::setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos, } int WDisplay::getActivePixmapIndex() const { - return static_cast<int>(m_value * m_pixmaps.size()); + return static_cast<int>( + m_value * static_cast<double>(m_pixmaps.size()) / 128.0); } void WDisplay::paintEvent(QPaintEvent* ) { diff --git a/src/widget/wknob.cpp b/src/widget/wknob.cpp index d2b4f306ea..e379643f29 100644 --- a/src/widget/wknob.cpp +++ b/src/widget/wknob.cpp @@ -29,7 +29,9 @@ WKnob::~WKnob() { } int WKnob::getActivePixmapIndex() const { - return static_cast<int>(m_value * numPixmaps()); + // TODO(rryan): Ew. + int iNoPos = numPixmaps(); + return (int)(((m_value-64.)*(((float)iNoPos-1.)/127.))+((float)iNoPos/2.)); } void WKnob::mouseMoveEvent(QMouseEvent* e) { diff --git a/src/widget/wknobcomposed.cpp b/src/widget/wknobcomposed.cpp index 76b17e6892..e9654e7587 100644 --- a/src/widget/wknobcomposed.cpp +++ b/src/widget/wknobcomposed.cpp @@ -71,8 +71,8 @@ void WKnobComposed::paintEvent(QPaintEvent* e) { if (!m_pKnob.isNull() && !m_pKnob->isNull()) { p.translate(width() / 2.0, height() / 2.0); - // Value is in the range [0, 1]. - double value = getValue(); + // Value is now in the range [0, 1]. + double value = getValue() / 127.0; double angle = m_dMinAngle + (m_dMaxAngle - m_dMinAngle) * value; p.rotate(angle); diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index f17f607932..e7ae137379 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -120,14 +120,14 @@ void WOverview::setup(QDomNode node) { //qDebug() << "WOverview : m_markRanges" << m_markRanges.size(); } -void WOverview::setValue(double dValue) { +void WOverview::setValue(double fValue) { if (!m_bDrag) { // Calculate handle position - int iPos = valueToPosition(dValue); + int iPos = valueToPosition(fValue); if (iPos != m_iPos) { m_iPos = iPos; - //qDebug() << "WOverview::setValue" << dValue << ">>" << m_iPos; + //qDebug() << "WOverview::setValue" << fValue << ">>" << m_iPos; update(); } } @@ -247,14 +247,14 @@ void WOverview::mouseMoveEvent(QMouseEvent* e) { void WOverview::mouseReleaseEvent(QMouseEvent* e) { mouseMoveEvent(e); - double dValue = positionToValue(m_iPos); + float fValue = positionToValue(m_iPos); - //qDebug() << "WOverview::mouseReleaseEvent" << e->pos() << m_iPos << ">>" << dValue; + //qDebug() << "WOverview::mouseReleaseEvent" << e->pos() << m_iPos << ">>" << fValue; if (e->button() == Qt::RightButton) { - emit(valueChangedRightUp(dValue)); + emit(valueChangedRightUp(fValue)); } else { - emit(valueChangedLeftUp(dValue)); + emit(valueChangedLeftUp(fValue)); } m_bDrag = false; } @@ -466,21 +466,9 @@ void WOverview::paintText(const QString &text, QPainter *painter) { } void WOverview::resizeEvent(QResizeEvent *) { - // Play-position potmeters range from -0.14 to 1.14. This is to give VC and - // MIDI control access to the pre-roll area. - // TODO(rryan): get these limits from the CO itself. - const double kMaxPlayposRange = 1.14; - const double kMinPlayposRange = -0.14; - - // Values of zero and one in normalized space. - const double zero = (0.0 - kMinPlayposRange) / (kMaxPlayposRange - kMinPlayposRange); - const double one = (1.0 - kMinPlayposRange) / (kMaxPlayposRange - kMinPlayposRange); - - // These coeficients convert between widget space and normalized value - // space. - m_a = (width() - 1) / (one - zero); - m_b = zero * m_a; - + //Those coeficient map position from [0;width-1] to value [14;114] + m_a = (float)((width()-1))/( 114.f - 14.f); + m_b = 14.f * m_a; m_waveformImageScaled = QImage(); m_diffGain = 0; } diff --git a/src/widget/woverview.h b/src/widget/woverview.h index dd94276c44..e5ffd81798 100644 --- a/src/widget/woverview.h +++ b/src/widget/woverview.h @@ -84,11 +84,11 @@ class WOverview : public WWidget { // Append the waveform overview pixmap according to available data in waveform virtual bool drawNextPixmapPart() = 0; void paintText(const QString &text, QPainter *painter); - inline int valueToPosition(double value) const { - return static_cast<int>(m_a * value - m_b); + inline int valueToPosition(float value) const { + return static_cast<int>(m_a * value - m_b + 0.5); } inline double positionToValue(int position) const { - return (static_cast<double>(position) + m_b) / m_a; + return (static_cast<float>(position) + m_b) / m_a; } const QString m_group; @@ -116,8 +116,8 @@ class WOverview : public WWidget { std::vector<WaveformMarkRange> m_markRanges; // Coefficient value-position linear transposition - double m_a; - double m_b; + float m_a; + float m_b; double m_dAnalyserProgress; bool m_bAnalyserFinalizing; diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index ced64e0506..189aa3b426 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -101,19 +101,16 @@ void WSliderComposed::mouseMoveEvent(QMouseEvent * e) { int sliderLength = m_bHorizontal ? width() : height(); - // Clamp to the range [0, sliderLength - m_iHandleLength]. if (m_iPos > (sliderLength - m_iHandleLength)) { m_iPos = sliderLength - m_iHandleLength; } else if (m_iPos < 0) { m_iPos = 0; } - // Divide by (sliderLength - m_iHandleLength) to produce a normalized - // value in the range of [0.0, 1.0]. 1.0 - m_value = static_cast<double>(m_iPos) / - static_cast<double>(sliderLength - m_iHandleLength); + // value ranges from 0 to 127 + m_value = (double)m_iPos * (127. / (double)(sliderLength - m_iHandleLength)); if (!m_bHorizontal) { - m_value = 1.0 - m_value; + m_value = 127. - m_value; } // Emit valueChanged signal @@ -131,14 +128,9 @@ void WSliderComposed::mouseMoveEvent(QMouseEvent * e) { } void WSliderComposed::wheelEvent(QWheelEvent *e) { - // For legacy (MIDI) reasons this is tuned to 127. - double wheelDirection = ((QWheelEvent *)e)->delta() / (120.0 * 127.0); - double newValue = getValue() + wheelDirection; - - // Clamp to [0.0, 1.0] - newValue = math_max(0.0, math_min(1.0, newValue)); - - updateValue(newValue); + double wheelDirection = ((QWheelEvent *)e)->delta() / 120.; + double newValue = getValue() + (wheelDirection); + this->updateValue(newValue); e->accept(); @@ -200,18 +192,18 @@ void WSliderComposed::paintEvent(QPaintEvent *) { } } -void WSliderComposed::setValue(double dValue) { - if (!m_bDrag && m_value != dValue) { +void WSliderComposed::setValue(double fValue) { + if (!m_bDrag && m_value != fValue) { // Set value without emitting a valueChanged signal // and force display update - m_value = dValue; + m_value = fValue; // Calculate handle position if (!m_bHorizontal) { - dValue = 1.0 - dValue; + fValue = 127-fValue; } int sliderLength = m_bHorizontal ? width() : height(); - m_iPos = static_cast<int>(dValue * (sliderLength - m_iHandleLength)); + m_iPos = (int)((fValue / 127.) * (double)(sliderLength - m_iHandleLength)); if (m_iPos > (sliderLength - m_iHandleLength)) { m_iPos = sliderLength - m_iHandleLength; diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index e099343619..363f114005 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -103,8 +103,9 @@ void WVuMeter::setPixmaps(const QString &vuFilename, } } -void WVuMeter::setValue(double dValue) { - int idx = static_cast<int>(dValue * m_iNoPos); +void WVuMeter::setValue(double fValue) +{ + int idx = (int)(fValue * (float)(m_iNoPos)/128.); // Range check if (idx > m_iNoPos) idx = m_iNoPos; @@ -112,7 +113,7 @@ void WVuMeter::setValue(double dValue) { idx = 0; setPeak(idx); - m_value = dValue; + m_value = fValue; QTime currentTime = QTime::currentTime(); int msecsElapsed = m_lastUpdate.msecsTo(currentTime); @@ -159,7 +160,7 @@ void WVuMeter::paintEvent(QPaintEvent *) { } if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) { - int idx = static_cast<int>(m_value * m_iNoPos); + int idx = (int)(m_value*(float)(m_iNoPos)/128.); // Range check if (idx > m_iNoPos) diff --git a/src/widget/wwaveformviewer.cpp b/src/widget/wwaveformviewer.cpp index cf10c0a511..1c5b842215 100644 --- a/src/widget/wwaveformviewer.cpp +++ b/src/widget/wwaveformviewer.cpp @@ -100,16 +100,11 @@ void WWaveformViewer::mouseMoveEvent(QMouseEvent* event) { m_pScratchPosition->slotSet(targetPosition); } else if (m_bBending) { QPoint diff = event->pos() - m_mouseAnchor; - // Start at the middle of [0.0, 1.0], and emit values based on how far - // the mouse has traveled horizontally. Note, for legacy (MIDI) reasons, - // this is tuned to 127. - // NOTE(rryan): This is basically a direct connection to the "wheel" - // control since we manually connect it in LegacySkinParser regardless - // of whether the skin specifies it. See ControlTTRotaryBehavior to see - // where this value is handled. - double v = 0.5 + (diff.x() / 1270.0); - // clamp to [0.0, 1.0] - v = math_min(1.0, math_max(0.0, v)); + // start at the middle of 0-127, and emit values based on + // how far the mouse has traveled horizontally + double v = 64.0 + diff.x()/10.0f; + // clamp to [0, 127] + v = math_min(127.0, math_max(0.0, v)); emit(valueChangedRightDown(v)); } } |