From 11bfb3d5a87bc3290a9a2e2a4135824dd2763fe3 Mon Sep 17 00:00:00 2001 From: tecknixia Date: Thu, 7 Nov 2019 09:06:26 -0600 Subject: [PATCH] Automation Editor point fine tuning with wheel scroll --- include/AutomationEditor.h | 2 + src/gui/editors/AutomationEditor.cpp | 75 ++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index 60b894f1fbc..3f8d8d8d1a2 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -218,6 +218,8 @@ protected slots: Actions m_action; + float m_pointYLevel; + tick_t m_selectStartTick; tick_t m_selectedTick; float m_selectStartLevel; diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index bf56e303981..1389efc14d0 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -88,6 +88,7 @@ AutomationEditor::AutomationEditor() : m_topLevel( 0 ), m_currentPosition(), m_action( NONE ), + m_pointYLevel(0), m_moveStartLevel( 0 ), m_moveStartTick( 0 ), m_drawLastLevel( 0.0f ), @@ -732,6 +733,7 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent ) if( mouseEvent->y() > TOP_MARGIN ) { float level = getLevel( mouseEvent->y() ); + float maxLvlFraction = m_pattern->firstObject()->maxValue() * 0.05; int x = mouseEvent->x(); x -= VALUES_WIDTH; @@ -783,7 +785,7 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent ) removePoints( m_drawLastTick, pos_ticks ); Engine::getSong()->setModified(); } - else if( mouseEvent->buttons() & Qt::NoButton && m_editMode == DRAW ) + if (m_editMode == DRAW) { // set move- or resize-cursor @@ -797,17 +799,19 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent ) { // and check whether the cursor is over an // existing value - if( pos_ticks >= it.key() && - ( it+1==time_map.end() || - pos_ticks <= (it+1).key() ) && - level <= it.value() ) + if ((it + 1 == time_map.end() || pos_ticks <= (it + 1).key()) + && pos_ticks >= (it.key() - MidiTime::ticksPerBar() * 12 / m_ppb) + && pos_ticks <= (it.key() + MidiTime::ticksPerBar() * 12 / m_ppb) + && level > (it.value() - maxLvlFraction) + && level < (it.value() + maxLvlFraction)) { break; } } - // did it reach end of map because there's - // no value?? + // mouse over point, display it's Y level in tool tip + m_pointYLevel = roundf(it.value() * 1000) / 1000; + if( it != time_map.end() ) { if( QApplication::overrideCursor() ) @@ -838,6 +842,8 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent ) { QApplication::restoreOverrideCursor(); } + // sets drawCross tooltip back to mouse y position + if (it == time_map.end()) { m_pointYLevel = 0; } } } else if( mouseEvent->buttons() & Qt::LeftButton && @@ -1707,8 +1713,59 @@ void AutomationEditor::wheelEvent(QWheelEvent * we ) } else { - m_topBottomScroll->setValue( m_topBottomScroll->value() - - we->delta() / 30 ); + if (we->y() > TOP_MARGIN) + { + float level = getLevel(we->y()); + int x = we->x(); + + if (x >= VALUES_WIDTH) + { + x -= VALUES_WIDTH; + bool enableYScrolling = true; + float maxLvlFraction = m_pattern->firstObject()->maxValue() + * 0.05; + int pos_ticks = x * MidiTime::ticksPerTact() / m_ppt + + m_currentPosition; + timeMap & time_map = m_pattern->getTimeMap(); + timeMap::iterator it = time_map.begin(); + + for (; it != time_map.end(); ++it) + { + pos_ticks = (pos_ticks < 0) ? 0 : pos_ticks; + + if (pos_ticks >= it.key() - MidiTime::ticksPerBar() * 12 / m_ppb + && (it+1==time_map.end() || pos_ticks <= (it+1).key()) + && (pos_ticks<= it.key() + MidiTime::ticksPerBar() * 12 / m_ppb) + && (level > it.value() - maxLvlFraction) + && (level < it.value() + maxLvlFraction)) + { + enableYScrolling = false; + // mouse wheel up + if (we->delta() < 0) + { + level = roundf(it.value() * 1000) / 1000 - + m_pattern->firstObject()->step(); + } + // mouse wheel down + else if (we->delta() > 0) + { + level = roundf(it.value() * 1000) / 1000 + + m_pattern->firstObject()->step(); + } + m_pointYLevel = level; + // move point to new position + m_pattern->setDragValue(MidiTime(pos_ticks), level, true, false); + m_pattern->applyDragValue(); + break; + } + } + if (enableYScrolling) + { + m_topBottomScroll->setValue(m_topBottomScroll->value() - + we->delta() / 30); + } + } + } } }