From 59db0247a95a1a650ab9540e62e8553ec4af0da0 Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Sun, 22 Oct 2017 18:07:49 +0200 Subject: [PATCH] Fix Automation Point delete radius --- include/AutomationEditor.h | 1 + src/gui/editors/AutomationEditor.cpp | 45 ++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index 5fc3ca03ac4..9705c5efa6a 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -132,6 +132,7 @@ public slots: void getSelectedValues(timeMap & selected_values ); void drawLine( int x0, float y0, int x1, float y1 ); + void removePoints( int x0, int x1 ); protected slots: void play(); diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index 1e94c1b50e7..12cfd93fb40 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -507,6 +507,7 @@ void AutomationEditor::mousePressEvent( QMouseEvent* mouseEvent ) // get tick in which the user clicked int pos_ticks = x * MidiTime::ticksPerTact() / m_ppt + m_currentPosition; + m_drawLastTick = pos_ticks; // get time map of current pattern timeMap & time_map = m_pattern->getTimeMap(); @@ -680,6 +681,39 @@ void AutomationEditor::mouseReleaseEvent(QMouseEvent * mouseEvent ) + +void AutomationEditor::removePoints( int x0, int x1 ) +{ + int deltax = qRound( qAbs( x1 - x0 ) ); + int x = x0; + int xstep; + + if( deltax < AutomationPattern::quantization() ) + { + return; + } + + deltax /= 1; + + if( x0 < x1) + { + xstep = 1; + } + else + { + xstep = -1; + } + + int i = 0; + while( i <= deltax ) + { + m_pattern->removeValue( MidiTime( x ) ); + x += xstep; + i += 1; + } +} + + void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent ) { QMutexLocker m( &m_patternMutex ); @@ -735,14 +769,13 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent ) ( mouseEvent->buttons() & Qt::LeftButton && m_editMode == ERASE ) ) { - // int resolution needed to improve the sensitivity of - // the erase manoeuvre with zoom levels < 100% - int zoom = m_zoomingXModel.value(); - int resolution = 1 + zoom * zoom; - for( int i = -resolution; i < resolution; ++i ) + // removing automation point + if( pos_ticks < 0 ) { - m_pattern->removeValue( MidiTime( pos_ticks + i ) ); + pos_ticks = 0; } + removePoints( m_drawLastTick, pos_ticks ); + Engine::getSong()->setModified(); } else if( mouseEvent->buttons() & Qt::NoButton && m_editMode == DRAW ) {