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

Fix Automation Point delete radius and size #3902

Merged
merged 2 commits into from
Oct 24, 2017
Merged
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
1 change: 1 addition & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
47 changes: 40 additions & 7 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ void AutomationEditor::mousePressEvent( QMouseEvent* mouseEvent )
m_editMode == DRAW ) ||
m_editMode == ERASE )
{
m_drawLastTick = pos_ticks;
m_pattern->addJournalCheckPoint();
// erase single value
if( it != time_map.end() )
Expand Down Expand Up @@ -680,6 +681,39 @@ void AutomationEditor::mouseReleaseEvent(QMouseEvent * mouseEvent )




void AutomationEditor::removePoints( int x0, int x1 )
{
int deltax = qAbs( x1 - x0 );
int x = x0;
int xstep;

if( deltax < AutomationPattern::quantization() )
{
return;
}

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 );
Expand Down Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will mark the project as modified if no points are removed. It should be moved into removePoints().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove points without checking if there are any there. So if I add bool pointsRemoved = false; and lets the delete loop set it to true, it is still going to set the project to changed as soon as the mouse moves just a bit without really removing anything.

Copy link
Member Author

@zonkmachine zonkmachine Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour right now is, deleting points with right click sets the project to changed but deleting by dragging over points doesn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhysSong I don't know quite how to move Engine::getSong()->setModified(); to removePoints(). This is already an improvement from before when setModified() wasn't called at all. I suggest merging this 'as is', or I can have another look at it if someone can point me in the right direction but for now I think it's low priority.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Engine::getSong()->setModified(); is an UX problem. So I think it's out of scope a little bit. Since the point of this PR is on GUI part, merging as-is looks fine. Dropping that will be fine, too.
I can create a PR which fixes the UX issue later. I think it will be the best way. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right. I'll merge this tomorrow.

}
else if( mouseEvent->buttons() & Qt::NoButton && m_editMode == DRAW )
{
Expand Down Expand Up @@ -1067,7 +1100,7 @@ inline void AutomationEditor::drawAutomationPoint( QPainter & p, timeMap::iterat
{
int x = xCoordOfTick( it.key() );
int y = yCoordOfLevel( it.value() );
const int outerRadius = qBound( 2, ( m_ppt * AutomationPattern::quantization() ) / 576, 5 ); // man, getting this calculation right took forever
const int outerRadius = qBound( 3, ( m_ppt * AutomationPattern::quantization() ) / 576, 5 ); // man, getting this calculation right took forever
p.setPen( QPen( vertexColor().lighter( 200 ) ) );
p.setBrush( QBrush( vertexColor() ) );
p.drawEllipse( x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2 );
Expand Down