summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widget/wdisplay.cpp38
-rw-r--r--src/widget/wdisplay.h3
-rw-r--r--src/widget/wknob.cpp4
-rw-r--r--src/widget/wknob.h2
4 files changed, 38 insertions, 9 deletions
diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp
index 7c325e598a..a77ba70ba0 100644
--- a/src/widget/wdisplay.cpp
+++ b/src/widget/wdisplay.cpp
@@ -108,7 +108,43 @@ void WDisplay::setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos,
}
int WDisplay::getActivePixmapIndex() const {
- return static_cast<int>(m_value * m_pixmaps.size());
+ // When there are an even number of pixmaps by convention we want a value of
+ // 0.5 to align to the lower of the two middle pixmaps. In Mixxx < 1.12.0 we
+ // accomplished this by the below formula:
+ // index = (m_value - 64.0/127.0) * (numPixmaps() - 1) + numPixmaps() / 2.0;
+
+ // But it's just as good to use m_value * numPixmaps() - epsilon. Using
+ // numPixmaps() instead of numPixmaps() - 1 ensures that every pixmap shares
+ // an equal slice of the value. Using m_value * (numPixmaps() - 1) gives an
+ // unequal slice of the value to the last pixmaps.
+
+ // Example:
+ // 3 pixmaps
+ // m_value * numPixmaps()
+ // idx: 0 1 2 3
+ // val: 0.0 ... 0.3 ... 0.6 ... 1.0
+ // Even distribution of value range, value 1 is out of bounds (3).
+
+ // m_value * (numPixmaps() - 1)
+ // idx: 0 1 2
+ // val: 0.0 ... 0.5 ... 1.0
+ // Pixmap 2 is only shown at value 1.
+
+ // floor(m_value * (numPixmaps() - 1) + 0.5)
+ // idx: 0 1 2
+ // val: 0.0 ... 0.25 ... 0.75 ... 1.0
+ // Pixmap 0 and Pixmap 2 only shown for 0.25 of value range
+
+ // 4 pixmaps
+ // m_value * numPixmaps()
+ // idx: 0 1 2 3 4
+ // val: 0.0 ... 0.25 ... 0.5 ... 0.75 ... 1.0
+ // Even distribution of value range, value 1 is out of bounds (4).
+
+ // Subtracting an epsilon prevents out of bound values at the end of the
+ // range and biases the middle value towards the lower of the 2 center
+ // pixmaps when there are an even number of pixmaps.
+ return static_cast<int>(m_value * numPixmaps() - 0.00001);
}
void WDisplay::paintEvent(QPaintEvent* ) {
diff --git a/src/widget/wdisplay.h b/src/widget/wdisplay.h
index e7e647532f..ca0e07e67f 100644
--- a/src/widget/wdisplay.h
+++ b/src/widget/wdisplay.h
@@ -42,7 +42,6 @@ class WDisplay : public WWidget {
}
private:
-
void setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos,
const QString& filename);
@@ -50,7 +49,7 @@ class WDisplay : public WWidget {
void setPositions(int iNoPos);
- virtual int getActivePixmapIndex() const;
+ int getActivePixmapIndex() const;
// Free existing pixmaps.
void resetPositions();
diff --git a/src/widget/wknob.cpp b/src/widget/wknob.cpp
index d2b4f306ea..6bcd401f37 100644
--- a/src/widget/wknob.cpp
+++ b/src/widget/wknob.cpp
@@ -28,10 +28,6 @@ WKnob::WKnob(QWidget* pParent)
WKnob::~WKnob() {
}
-int WKnob::getActivePixmapIndex() const {
- return static_cast<int>(m_value * numPixmaps());
-}
-
void WKnob::mouseMoveEvent(QMouseEvent* e) {
m_handler.mouseMoveEvent(this, e);
}
diff --git a/src/widget/wknob.h b/src/widget/wknob.h
index d95d9b0247..8f57fb6d6f 100644
--- a/src/widget/wknob.h
+++ b/src/widget/wknob.h
@@ -40,8 +40,6 @@ class WKnob : public WDisplay {
void mouseReleaseEvent(QMouseEvent *e);
private:
- int getActivePixmapIndex() const;
-
KnobEventHandler<WKnob> m_handler;
friend class KnobEventHandler<WKnob>;
};