Skip to content

Commit

Permalink
Automation Editor point fine tuning with wheel scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
tecknixia committed Nov 7, 2019
1 parent b4459be commit fedff3e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
2 changes: 2 additions & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ protected slots:

Actions m_action;

float m_pointYLevel;

tick_t m_selectStartTick;
tick_t m_selectedTick;
float m_selectStartLevel;
Expand Down
84 changes: 74 additions & 10 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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<float>() * 0.05;
int x = mouseEvent->x();

x -= VALUES_WIDTH;
Expand Down Expand Up @@ -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

Expand All @@ -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() )
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -1105,7 +1111,14 @@ inline void AutomationEditor::drawCross( QPainter & p )
mouse_pos.y() >= 0 &&
mouse_pos.y() <= height() - SCROLLBAR_SIZE )
{
QToolTip::showText( tt_pos, QString::number( scaledLevel ), this );
if (m_pointYLevel == 0)
{
QToolTip::showText(tt_pos, QString::number(scaledLevel), this);
}
else if (m_pointYLevel != 0)
{
QToolTip::showText(tt_pos, QString::number(m_pointYLevel), this);
}
}
}

Expand Down Expand Up @@ -1707,8 +1720,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<float>() * 0.05;
int pos_ticks = x * MidiTime::ticksPerBar() / m_ppb
+ 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<float>();
}
// mouse wheel down
else if (we->delta() > 0)
{
level = roundf(it.value() * 1000) / 1000 +
m_pattern->firstObject()->step<float>();
}
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);
}
}
}
}
}

Expand Down

0 comments on commit fedff3e

Please sign in to comment.