Skip to content

Commit

Permalink
Automation Editor point fine tuning with double click
Browse files Browse the repository at this point in the history
  • Loading branch information
tecknixia committed Nov 7, 2019
1 parent b4459be commit cf50b86
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public slots:
void paintEvent(QPaintEvent * pe) override;
void resizeEvent(QResizeEvent * re) override;
void wheelEvent(QWheelEvent * we) override;
void mouseDoubleClickEvent(QMouseEvent * mouseEvent) override;

float getLevel( int y );
int xCoordOfTick( int tick );
Expand Down Expand Up @@ -218,6 +219,8 @@ protected slots:

Actions m_action;

float m_pointYLevel;

tick_t m_selectStartTick;
tick_t m_selectedTick;
float m_selectStartLevel;
Expand Down
69 changes: 63 additions & 6 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,10 +799,11 @@ 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;
}
Expand Down Expand Up @@ -838,6 +841,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 +1110,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 @@ -1715,6 +1727,51 @@ void AutomationEditor::wheelEvent(QWheelEvent * we )



void AutomationEditor::mouseDoubleClickEvent(QMouseEvent * mouseEvent)
{
int x = mouseEvent->x();

if (x >= VALUES_WIDTH)
{
x -= VALUES_WIDTH;
float mouseLevel = getLevel(mouseEvent->y());
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();

while (it != time_map.end())
{
// and check whether the cursor is over an
// existing 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)
&& (mouseLevel > it.value() - maxLvlFraction)
&& (mouseLevel < it.value() + maxLvlFraction))
{
// end of map or the cursor is on a point
break;
}
it++;
}

bool ok;
double d = QInputDialog::getDouble(this, tr("Edit Point"),
tr("New Y Value:"), m_pointYLevel, 0, m_pattern->firstObject()->maxValue<float>(), 3, &ok);

if (ok)
{
// move point to new position
m_pattern->setDragValue(MidiTime(pos_ticks), d, true, false);
m_pattern->applyDragValue();
}
}
}




float AutomationEditor::getLevel(int y )
{
int level_line_y = height() - SCROLLBAR_SIZE - 1;
Expand Down

0 comments on commit cf50b86

Please sign in to comment.