Skip to content

Commit

Permalink
Fix moving multiple tco's with mixed offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
zonkmachine committed Dec 10, 2017
1 parent 3c9e0d8 commit ef86ea3
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,21 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me )
}
else if( m_action == MoveSelection )
{
// find out if we have moved by testing the grabbed tco with the
// same algorithm as 'm_action == Move' from above
const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x();
MidiTime oldTime = m_tco->startPosition();
MidiTime newTime = qMax( 0, (int)
m_trackView->trackContainerView()->currentPosition()+
static_cast<int>( x * MidiTime::ticksPerTact() /
ppt ) );
if( oldTime.toNearestTact() == newTime.toNearestTact() )
{
// the grabbed tco didn't move so neither do the rest
return;
}

// calculate move
const int dx = me->x() - m_initialMousePos.x();
QVector<selectableObject *> so =
m_trackView->trackContainerView()->selectedObjects();
Expand All @@ -887,22 +902,25 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me )
static_cast<int>( dx *
MidiTime::ticksPerTact() / ppt ) );
}

// don't move any part ahead of song start
if( smallest_pos < 0 )
{
return;
}

for( QVector<TrackContentObject *>::iterator it = tcos.begin();
it != tcos.end(); ++it )
{
offset = ( *it )->startPosition() -
( *it )->startPosition().toNearestTact();
t = ( *it )->startPosition() +
static_cast<int>( dx *MidiTime::ticksPerTact() /
ppt )-smallest_pos;
MidiTime start = ( *it )->startPosition();
offset = start - start.toNearestTact();
t = start - smallest_pos;
// find directon with dx and add/subtract ticksPerTact()
t += dx > 0 ? MidiTime::ticksPerTact() : -MidiTime::ticksPerTact();
if( ! ( me->modifiers() & Qt::AltModifier )
&& me->button() == Qt::NoButton )
{
t = t.toNearestTact() + offset;
while( t < 0 )
{
t += MidiTime::ticksPerTact();
}
}
( *it )->movePosition( t );
}
Expand Down

0 comments on commit ef86ea3

Please sign in to comment.