diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index 0a288f8af..481375969 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -209,6 +209,7 @@ private: float m_bottomLevel; float m_topLevel; + void centerTopBottomScroll(); void updateTopBottomLevels(); QScrollBar * m_leftRightScroll; diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index 8c281bf3e..221b01aca 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -320,7 +320,7 @@ void AutomationEditor::updateAfterPatternChange() m_minLevel = m_pattern->firstObject()->minValue(); m_maxLevel = m_pattern->firstObject()->maxValue(); m_step = m_pattern->firstObject()->step(); - m_scrollLevel = ( m_minLevel + m_maxLevel ) / 2; + centerTopBottomScroll(); m_tensionModel->setValue( m_pattern->getTension() ); @@ -1595,12 +1595,36 @@ void AutomationEditor::drawLevelTick(QPainter & p, int tick, float value) p.fillRect( x, y_start, rect_width, rect_height, currentColor ); } - +#ifdef LMMS_DEBUG else { printf("not in range\n"); } +#endif +} + + + +// center the vertical scroll position on the first object's value +void AutomationEditor::centerTopBottomScroll() +{ + // default to the m_scrollLevel position + int pos = static_cast(m_scrollLevel); + // If a pattern exists... + if (m_pattern) + { + // get time map of current pattern + timeMap & time_map = m_pattern->getTimeMap(); + // If time_map is not empty... + if (!time_map.empty()) + { + // set the position to the inverted value ((max + min) - value) + // If we set just (max - value), we're off by m_pattern's minimum + pos = m_pattern->getMax() + m_pattern->getMin() - static_cast(time_map.begin().value()); + } + } + m_topBottomScroll->setValue(pos); } @@ -1632,8 +1656,7 @@ void AutomationEditor::resizeEvent(QResizeEvent * re) m_topBottomScroll->setRange( (int) m_scrollLevel, (int) m_scrollLevel ); } - - m_topBottomScroll->setValue( (int) m_scrollLevel ); + centerTopBottomScroll(); if( Engine::getSong() ) {