From 75e4b2f487d36b555d80d3d3689b779014b47d62 Mon Sep 17 00:00:00 2001 From: RJ Ryan Date: Sat, 4 Jan 2014 12:51:55 -0500 Subject: Fix WKnob / WDisplay active pixmap calculation to bias towards the lower of the two middle pixmaps when there are an even number. --- src/widget/wdisplay.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/widget/wdisplay.cpp') 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* pPixmaps, int iPos, } int WDisplay::getActivePixmapIndex() const { - return static_cast(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(m_value * numPixmaps() - 0.00001); } void WDisplay::paintEvent(QPaintEvent* ) { -- cgit v1.2.3