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

Fixes createTCO method on some classes #5699

Merged
merged 11 commits into from
Nov 7, 2020
2 changes: 1 addition & 1 deletion include/AutomationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AutomationTrack : public Track
}

TrackView * createView( TrackContainerView* ) override;
TrackContentObject * createTCO( const MidiTime & _pos ) override;
TrackContentObject* createTCO(const MidiTime & pos) override;

virtual void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
Expand Down
2 changes: 1 addition & 1 deletion include/BBTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LMMS_EXPORT BBTrack : public Track
virtual bool play( const MidiTime & _start, const fpp_t _frames,
const f_cnt_t _frame_base, int _tco_num = -1 ) override;
TrackView * createView( TrackContainerView* tcv ) override;
TrackContentObject * createTCO( const MidiTime & _pos ) override;
TrackContentObject* createTCO(const MidiTime & pos) override;

virtual void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
Expand Down
2 changes: 1 addition & 1 deletion include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
TrackView * createView( TrackContainerView* tcv ) override;

// create new track-content-object = pattern
TrackContentObject * createTCO( const MidiTime & _pos ) override;
TrackContentObject* createTCO(const MidiTime & pos) override;


// called by track
Expand Down
2 changes: 1 addition & 1 deletion include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SampleTrack : public Track
virtual bool play( const MidiTime & _start, const fpp_t _frames,
const f_cnt_t _frame_base, int _tco_num = -1 ) override;
TrackView * createView( TrackContainerView* tcv ) override;
TrackContentObject * createTCO( const MidiTime & _pos ) override;
TrackContentObject* createTCO(const MidiTime & pos) override;


virtual void saveTrackSpecificSettings( QDomDocument & _doc,
Expand Down
4 changes: 1 addition & 3 deletions plugins/HydrogenImport/HydrogenImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,8 @@ bool HydrogenImport::readSong()

int i = pattern_id[patId]+song_num_tracks;
Track *t = ( BBTrack * ) s->tracks().at( i );
TrackContentObject *tco = t->createTCO( pos );
tco->movePosition( pos );
t->createTCO(pos);


if ( pattern_length[patId] > best_length )
{
best_length = pattern_length[patId];
Expand Down
6 changes: 2 additions & 4 deletions plugins/MidiImport/MidiImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ class smfMidiCC
{
MidiTime pPos = MidiTime( time.getBar(), 0 );
ap = dynamic_cast<AutomationPattern*>(
at->createTCO(0) );
ap->movePosition( pPos );
at->createTCO(pPos));
ap->addObject( objModel );
}

Expand Down Expand Up @@ -287,8 +286,7 @@ class smfMidiChannel
if (!newPattern || n->pos() > lastEnd + DefaultTicksPerBar)
{
MidiTime pPos = MidiTime(n->pos().getBar(), 0);
newPattern = dynamic_cast<Pattern*>(it->createTCO(0));
newPattern->movePosition(pPos);
newPattern = dynamic_cast<Pattern*>(it->createTCO(pPos));
}
lastEnd = n->pos() + n->length();

Expand Down
41 changes: 24 additions & 17 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ TrackContentObject::~TrackContentObject()
*/
void TrackContentObject::movePosition( const MidiTime & pos )
{
if( m_startPosition != pos )
MidiTime newPos = qMax(0, pos.getTicks());
if (m_startPosition != newPos)
{
Engine::mixer()->requestChangeInModel();
m_startPosition = pos;
m_startPosition = newPos;
Engine::mixer()->doneChangeInModel();
Engine::getSong()->updateLength();
emit positionChanged();
Expand Down Expand Up @@ -955,9 +956,8 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me )
{
MidiTime newPos = draggedTCOPos( me );

// Don't go left of bar zero
newPos = max( 0, newPos.getTicks() );
m_tco->movePosition( newPos );
m_tco->movePosition(newPos);
newPos = m_tco->startPosition(); // Get the real position the TCO was dragged to for the label
m_trackView->getTrackContentWidget()->changePosition();
s_textFloat->setText( QString( "%1:%2" ).
arg( newPos.getBar() + 1 ).
Expand Down Expand Up @@ -1073,7 +1073,6 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me )
if( m_tco->length() + ( oldPos - t ) >= 1 )
{
m_tco->movePosition( t );
m_trackView->getTrackContentWidget()->changePosition();
m_tco->changeLength( m_tco->length() + ( oldPos - t ) );
sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) );
}
Expand Down Expand Up @@ -1896,6 +1895,22 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, const QMimeData * md,
// The offset is quantized (rather than the positions) to preserve fine adjustments
offset = offset.quantize(snapSize);

// Get the leftmost TCO and fix the offset if it reaches below bar 0
MidiTime leftmostPos = grabbedTCOPos;
for(int i = 0; i < tcoNodes.length(); ++i)
{
QDomElement outerTCOElement = tcoNodes.item(i).toElement();
QDomElement tcoElement = outerTCOElement.firstChildElement();

MidiTime pos = tcoElement.attributeNode("pos").value().toInt();

if(pos < leftmostPos) { leftmostPos = pos; }
}
if((leftmostPos + offset) < 0)
{
offset = -leftmostPos;
}

Spekular marked this conversation as resolved.
Show resolved Hide resolved
for( int i = 0; i<tcoNodes.length(); i++ )
{
QDomElement outerTCOElement = tcoNodes.item( i ).toElement();
Expand All @@ -1913,7 +1928,7 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, const QMimeData * md,

TrackContentObject * tco = t->createTCO( pos );
tco->restoreState( tcoElement );
tco->movePosition( pos );
tco->movePosition(pos); // Because we restored the state, we need to move the TCO again.
ryuukumar marked this conversation as resolved.
Show resolved Hide resolved
if( wasSelection )
{
tco->selectViewOnCreate( true );
Expand Down Expand Up @@ -1967,11 +1982,7 @@ void TrackContentWidget::mousePressEvent( QMouseEvent * me )
getTrack()->addJournalCheckPoint();
const MidiTime pos = getPosition( me->x() ).getBar() *
MidiTime::ticksPerBar();
TrackContentObject * tco = getTrack()->createTCO( pos );

tco->saveJournallingState( false );
tco->movePosition( pos );
tco->restoreJournallingState();
getTrack()->createTCO(pos);
ryuukumar marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -2697,8 +2708,6 @@ void Track::loadSettings( const QDomElement & element )
TrackContentObject * tco = createTCO(
MidiTime( 0 ) );
tco->restoreState( node.toElement() );
saveJournallingState( false );
restoreJournallingState();
}
}
node = node.nextSibling();
Expand Down Expand Up @@ -2886,7 +2895,6 @@ void Track::createTCOsForBB( int bb )
{
MidiTime position = MidiTime( numOfTCOs(), 0 );
TrackContentObject * tco = createTCO( position );
tco->movePosition( position );
tco->changeLength( MidiTime( 1, 0 ) );
}
}
Expand Down Expand Up @@ -2932,8 +2940,7 @@ void Track::removeBar( const MidiTime & pos )
{
if( ( *it )->startPosition() >= pos )
{
( *it )->movePosition( qMax( ( *it )->startPosition() -
MidiTime::ticksPerBar(), 0 ) );
(*it)->movePosition((*it)->startPosition() - MidiTime::ticksPerBar());
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/tracks/AutomationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ TrackView * AutomationTrack::createView( TrackContainerView* tcv )



TrackContentObject * AutomationTrack::createTCO( const MidiTime & )
TrackContentObject* AutomationTrack::createTCO(const MidiTime & pos)
{
return new AutomationPattern( this );
AutomationPattern* p = new AutomationPattern(this);
p->movePosition(pos);
return p;
}


Expand Down Expand Up @@ -133,7 +135,6 @@ void AutomationTrackView::dropEvent( QDropEvent * _de )
TrackContentObject * tco = getTrack()->createTCO( pos );
AutomationPattern * pat = dynamic_cast<AutomationPattern *>( tco );
pat->addObject( mod );
pat->movePosition( pos );
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/tracks/BBTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ TrackView * BBTrack::createView( TrackContainerView* tcv )



TrackContentObject * BBTrack::createTCO( const MidiTime & _pos )
TrackContentObject* BBTrack::createTCO(const MidiTime & pos)
{
BBTCO * bbtco = new BBTCO( this );
BBTCO* bbtco = new BBTCO(this);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
bbtco->movePosition(pos);
return bbtco;
}

Expand Down
6 changes: 4 additions & 2 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,11 @@ bool InstrumentTrack::play( const MidiTime & _start, const fpp_t _frames,



TrackContentObject * InstrumentTrack::createTCO( const MidiTime & )
TrackContentObject* InstrumentTrack::createTCO(const MidiTime & pos)
{
return new Pattern( this );
Pattern* p = new Pattern(this);
p->movePosition(pos);
return p;
}


Expand Down