summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2014-01-03 17:17:26 -0500
committerRJ Ryan <rryan@mixxx.org>2014-01-03 17:17:26 -0500
commit6fcd283cd80a34747320340ecc9a17b9b4b9606a (patch)
tree1be642930460e2b47a5d4c1a8dc863ee1774883f
parent28177a40eaf77683c402e18f08755fac2e02e1e4 (diff)
Revert "Normalize potmeter widget values to [0.0, 1.0] instead of [0.0, 127.0]."
-rw-r--r--src/control/controlbehavior.cpp52
-rw-r--r--src/control/controlbehavior.h5
-rw-r--r--src/controllinpotmeter.cpp4
-rw-r--r--src/controllogpotmeter.cpp12
-rw-r--r--src/engine/enginebuffer.cpp4
-rw-r--r--src/widget/knobeventhandler.h16
-rw-r--r--src/widget/wdisplay.cpp3
-rw-r--r--src/widget/wknob.cpp4
-rw-r--r--src/widget/wknobcomposed.cpp4
-rw-r--r--src/widget/woverview.cpp32
-rw-r--r--src/widget/woverview.h10
-rw-r--r--src/widget/wslidercomposed.cpp30
-rw-r--r--src/widget/wvumeter.cpp9
-rw-r--r--src/widget/wwaveformviewer.cpp15
14 files changed, 88 insertions, 112 deletions
diff --git a/src/control/controlbehavior.cpp b/src/control/controlbehavior.cpp
index b07c783f3f..34ff4fa9a0 100644
--- a/src/control/controlbehavior.cpp
+++ b/src/control/controlbehavior.cpp
@@ -54,42 +54,35 @@ double ControlPotmeterBehavior::valueToWidgetParameter(double dValue) {
} else if (dValue < m_dMinValue) {
dValue = m_dMinValue;
}
- if (m_dValueRange == 0.0) {
- return 0;
- }
- return (dValue - m_dMinValue) / m_dValueRange;
+ double dNorm = (dValue - m_dMinValue) / m_dValueRange;
+ return dNorm < 0.5 ? dNorm * 128.0 : dNorm * 126.0 + 1.0;
}
double ControlPotmeterBehavior::widgetParameterToValue(double dParam) {
- return m_dMinValue + dParam * m_dValueRange;
+ double dNorm = dParam < 64 ? dParam / 128.0 : (dParam - 1.0) / 126.0;
+ return m_dMinValue + dNorm * m_dValueRange;
}
double ControlPotmeterBehavior::valueToMidiParameter(double dValue) {
- // 7-bit MIDI has 128 values [0, 127]. This means there is no such thing as
- // center. The industry convention is that 64 is center. We fake things a
- // little bit here to make that the case. This piece-wise function is linear
- // from 0 to 64 with slope 128 and from 64 to 127 with slope 126.
- double dNorm = valueToWidgetParameter(dValue);
- return dNorm < 0.5 ? dNorm * 128.0 : dNorm * 126.0 + 1.0;
+ return valueToWidgetParameter(dValue);
}
void ControlPotmeterBehavior::setValueFromMidiParameter(MidiOpCode o, double dParam,
ControlDoublePrivate* pControl) {
Q_UNUSED(o);
- double dNorm = dParam < 64 ? dParam / 128.0 : (dParam - 1.0) / 126.0;
- pControl->set(widgetParameterToValue(dNorm), NULL);
+ pControl->set(widgetParameterToValue(dParam), NULL);
}
-#define maxPosition 1.0
-#define minPosition 0.0
-#define middlePosition ((maxPosition-minPosition)/2.0)
+#define maxPosition 127
+#define minPosition 0
+#define middlePosition ((maxPosition-minPosition)/2)
#define positionrange (maxPosition-minPosition)
ControlLogpotmeterBehavior::ControlLogpotmeterBehavior(double dMaxValue)
: ControlPotmeterBehavior(0, dMaxValue) {
if (dMaxValue == 1.0) {
m_bTwoState = false;
- m_dB1 = log10(2.0) / maxPosition;
+ m_dB1 = log10(2.0)/maxPosition;
} else {
m_bTwoState = true;
m_dB1 = log10(2.0) / middlePosition;
@@ -141,29 +134,26 @@ ControlLinPotmeterBehavior::ControlLinPotmeterBehavior(double dMinValue, double
ControlLinPotmeterBehavior::~ControlLinPotmeterBehavior() {
}
-double ControlLinPotmeterBehavior::valueToMidiParameter(double dValue) {
- // 7-bit MIDI has 128 values [0, 127]. This means there is no such thing as
- // center. The industry convention is that 64 is center. We fake things a
- // little bit here to make that the case. This function is linear from [0,
- // 127.0/128.0] with slope 128 and then cuts off at 127 from 127.0/128.0 to
- // 1.0. from 0 to 64 with slope 128 and from 64 to 127 with slope 126.
- double dNorm = valueToWidgetParameter(dValue);
- return math_max(127.0, dNorm * 128.0);
+double ControlLinPotmeterBehavior::valueToWidgetParameter(double dValue) {
+ if (dValue > m_dMaxValue) {
+ dValue = m_dMaxValue;
+ } else if (dValue < m_dMinValue) {
+ dValue = m_dMinValue;
+ }
+ double dNorm = (dValue - m_dMinValue) / m_dValueRange;
+ return math_min(dNorm * 128, 127);
}
-void ControlLinPotmeterBehavior::setValueFromMidiParameter(MidiOpCode o, double dParam,
- ControlDoublePrivate* pControl) {
- Q_UNUSED(o);
+double ControlLinPotmeterBehavior::widgetParameterToValue(double dParam) {
double dNorm = dParam / 128.0;
- pControl->set(widgetParameterToValue(dNorm), NULL);
+ return m_dMinValue + dNorm * m_dValueRange;
}
double ControlTTRotaryBehavior::valueToWidgetParameter(double dValue) {
- return (dValue * 200.0 + 64) / 127.0;
+ return dValue * 200.0 + 64;
}
double ControlTTRotaryBehavior::widgetParameterToValue(double dParam) {
- dParam *= 127.0;
// Non-linear scaling
double temp = ((dParam - 64.0) * (dParam - 64.0)) / 64.0;
if (dParam - 64 < 0) {
diff --git a/src/control/controlbehavior.h b/src/control/controlbehavior.h
index 5f7322a14b..8b7cdc1ff2 100644
--- a/src/control/controlbehavior.h
+++ b/src/control/controlbehavior.h
@@ -65,9 +65,8 @@ class ControlLinPotmeterBehavior : public ControlPotmeterBehavior {
ControlLinPotmeterBehavior(double dMinValue, double dMaxValue);
virtual ~ControlLinPotmeterBehavior();
- virtual double valueToMidiParameter(double dValue);
- virtual void setValueFromMidiParameter(MidiOpCode o, double dParam,
- ControlDoublePrivate* pControl);
+ virtual double valueToWidgetParameter(double dValue);
+ virtual double widgetParameterToValue(double dParam);
};
class ControlTTRotaryBehavior : public ControlNumericBehavior {
diff --git a/src/controllinpotmeter.cpp b/src/controllinpotmeter.cpp
index 0f302b028f..7b9b15ff37 100644
--- a/src/controllinpotmeter.cpp
+++ b/src/controllinpotmeter.cpp
@@ -1,6 +1,8 @@
#include "controllinpotmeter.h"
#include "defs.h"
+// This control has a linear link between the m_dValue and the Midi Value
+// limitation: m_dMaxValue represents the midi value of 128 and is never reached
ControlLinPotmeter::ControlLinPotmeter(ConfigKey key, double dMinValue, double dMaxValue) :
ControlPotmeter(key, dMinValue, dMaxValue) {
if (m_pControl) {
@@ -8,3 +10,5 @@ ControlLinPotmeter::ControlLinPotmeter(ConfigKey key, double dMinValue, double d
new ControlLinPotmeterBehavior(dMinValue, dMaxValue));
}
}
+
+
diff --git a/src/controllogpotmeter.cpp b/src/controllogpotmeter.cpp
index f44685037f..fad510f29a 100644
--- a/src/controllogpotmeter.cpp
+++ b/src/controllogpotmeter.cpp
@@ -21,13 +21,16 @@
Purpose: Creates a new logarithmic potmeter, where the value is
given by:
- value = 10^(b*parameter) - 1
+ value = 10^(b*midibyte) - 1
- The lower value is 0, for parameter=0.5 the value is 1 and the upper
+ The lower value is 0, for midibyte=64 the value is 1 and the upper
value is set by maxvalue.
- If the maxvalue is 1, the potmeter operates with only one
- logarithmic scale between 0 (for parameter 0) and 1 (parameter 1.0).
+ If the maxvalue is set to 1, the potmeter operates with only
+ one logarithmid scale between 0 (for midi 0) and 1 (midivalue 128).
+ Input: n - name
+ midino - number of the midi controller.
+ midicontroller - pointer to the midi controller.
-------- ------------------------------------------------------ */
ControlLogpotmeter::ControlLogpotmeter(ConfigKey key, double dMaxValue)
: ControlPotmeter(key, 0, dMaxValue) {
@@ -40,3 +43,4 @@ ControlLogpotmeter::ControlLogpotmeter(ConfigKey key, double dMaxValue)
new ControlLogpotmeterBehavior(dMaxValue));
}
}
+
diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp
index b304f9b9dd..5eb0db8220 100644
--- a/src/engine/enginebuffer.cpp
+++ b/src/engine/enginebuffer.cpp
@@ -180,8 +180,8 @@ EngineBuffer::EngineBuffer(const char* _group, ConfigObject<ConfigValue>* _confi
m_visualBpm = new ControlObject(ConfigKey(m_group, "visual_bpm"));
m_visualKey = new ControlObject(ConfigKey(m_group, "visual_key"));
- // Slider to show and change song position. kMinPlayposRange and
- // kMaxPlayposRange map conveniently to the 0-127 range of 7-bit MIDI.
+ // Slider to show and change song position
+ //these bizarre choices map conveniently to the 0-127 range of midi
m_playposSlider = new ControlLinPotmeter(
ConfigKey(m_group, "playposition"), kMinPlayposRange, kMaxPlayposRange);
connect(m_playposSlider, SIGNAL(valueChanged(double)),
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));
}
}