Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automation Editor point fine tuning with double click #5292

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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