From 139e492b1786bf1214e54b029f3c99b8bf609df3 Mon Sep 17 00:00:00 2001 From: Spekular Date: Tue, 11 Aug 2020 14:58:54 +0200 Subject: [PATCH] Revert "Replace iterator where possible" This reverts commit 2fe06c8f3c849a0d8ce56910e66a1c9b85d3a460. --- src/core/AutomationPattern.cpp | 257 +++++++++++++++++++-------------- 1 file changed, 151 insertions(+), 106 deletions(-) diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 3098123aa..2fd1cea12 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -72,30 +72,29 @@ AutomationPattern::AutomationPattern( AutomationTrack * _auto_track ) : -AutomationPattern::AutomationPattern(const AutomationPattern& _pat_to_copy) : - TrackContentObject(_pat_to_copy.m_autoTrack), - m_autoTrack(_pat_to_copy.m_autoTrack), - m_objects(_pat_to_copy.m_objects), - m_tension(_pat_to_copy.m_tension), - m_progressionType(_pat_to_copy.m_progressionType) +AutomationPattern::AutomationPattern( const AutomationPattern & _pat_to_copy ) : + TrackContentObject( _pat_to_copy.m_autoTrack ), + m_autoTrack( _pat_to_copy.m_autoTrack ), + m_objects( _pat_to_copy.m_objects ), + m_tension( _pat_to_copy.m_tension ), + m_progressionType( _pat_to_copy.m_progressionType ) { - m_timeMap = timeMap(_pat_to_copy.m_timeMap); - m_tangents = timeMap(_pat_to_copy.m_tangents); - // Force a deep copy, because the previous implementation did this manually. - // TODO: Do we really need to do this? - m_timeMap.detach(); - m_tangents.detach(); - - switch (getTrack()->trackContainer()->type()) + for( timeMap::const_iterator it = _pat_to_copy.m_timeMap.begin(); + it != _pat_to_copy.m_timeMap.end(); ++it ) + { + m_timeMap[it.key()] = it.value(); + m_tangents[it.key()] = _pat_to_copy.m_tangents[it.key()]; + } + switch( getTrack()->trackContainer()->type() ) { case TrackContainer::BBContainer: - setAutoResize(true); + setAutoResize( true ); break; case TrackContainer::SongContainer: // move down default: - setAutoResize(false); + setAutoResize( false ); break; } } @@ -179,10 +178,16 @@ const AutomationPattern::objectVector& AutomationPattern::objects() const MidiTime AutomationPattern::timeMapLength() const { - // Find the time of the last point in the timemap, defaulting to 0 if it's empty - tick_t lastTick = static_cast(m_timeMap.isEmpty() ? 0 : m_timeMap.lastKey()); - // Return one bar if the pattern is empty, or only contains a point at time zero - return (lastTick == 0) ? MidiTime(1, 0) : MidiTime(lastTick); + MidiTime one_bar = MidiTime(1, 0); + if (m_timeMap.isEmpty()) { return one_bar; } + + timeMap::const_iterator it = m_timeMap.end(); + tick_t last_tick = static_cast((it-1).key()); + // if last_tick is 0 (single item at tick 0) + // return length as a whole bar to prevent disappearing TCO + if (last_tick == 0) { return one_bar; } + + return MidiTime(last_tick); } @@ -525,30 +530,33 @@ void AutomationPattern::flipX( int length ) -void AutomationPattern::saveSettings(QDomDocument & _doc, QDomElement & _this) +void AutomationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this ) { - _this.setAttribute("pos", startPosition()); - _this.setAttribute("len", length()); - _this.setAttribute("name", name()); - _this.setAttribute("prog", QString::number(progressionType())); - _this.setAttribute("tens", QString::number(getTension())); - _this.setAttribute("mute", QString::number(isMuted())); + _this.setAttribute( "pos", startPosition() ); + _this.setAttribute( "len", length() ); + _this.setAttribute( "name", name() ); + _this.setAttribute( "prog", QString::number( progressionType() ) ); + _this.setAttribute( "tens", QString::number( getTension() ) ); + _this.setAttribute( "mute", QString::number( isMuted() ) ); - for (timeMap::const_iterator it = m_timeMap.begin(); it != m_timeMap.end(); ++it) + for( timeMap::const_iterator it = m_timeMap.begin(); + it != m_timeMap.end(); ++it ) { - QDomElement element = _doc.createElement("time"); - element.setAttribute("pos", it.key()); - element.setAttribute("value", it.value()); - _this.appendChild(element); + QDomElement element = _doc.createElement( "time" ); + element.setAttribute( "pos", it.key() ); + element.setAttribute( "value", it.value() ); + _this.appendChild( element ); } - for (const auto model: m_objects) + for( objectVector::const_iterator it = m_objects.begin(); + it != m_objects.end(); ++it ) { - if (!model.isNull()) + if( *it ) { - QDomElement element = _doc.createElement("object"); - element.setAttribute("id", ProjectJournal::idToSave(model->id())); - _this.appendChild(element); + QDomElement element = _doc.createElement( "object" ); + element.setAttribute( "id", + ProjectJournal::idToSave( ( *it )->id() ) ); + _this.appendChild( element ); } } } @@ -627,26 +635,30 @@ TrackContentObjectView * AutomationPattern::createView( TrackView * _tv ) -bool AutomationPattern::isAutomated(const AutomatableModel* _m) +bool AutomationPattern::isAutomated( const AutomatableModel * _m ) { - TrackContainer::TrackList trackList; - trackList += Engine::getSong()->tracks(); - trackList += Engine::getBBTrackContainer()->tracks(); - trackList += Engine::getSong()->globalAutomationTrack(); + TrackContainer::TrackList l; + l += Engine::getSong()->tracks(); + l += Engine::getBBTrackContainer()->tracks(); + l += Engine::getSong()->globalAutomationTrack(); - for (const Track* track: trackList) + for( TrackContainer::TrackList::ConstIterator it = l.begin(); it != l.end(); ++it ) { - if (track->type() == Track::AutomationTrack || - track->type() == Track::HiddenAutomationTrack) + if( ( *it )->type() == Track::AutomationTrack || + ( *it )->type() == Track::HiddenAutomationTrack ) { - const Track::tcoVector& tcoVector = track->getTCOs(); - for (const TrackContentObject* tco: tcoVector) + const Track::tcoVector & v = ( *it )->getTCOs(); + for( Track::tcoVector::ConstIterator j = v.begin(); j != v.end(); ++j ) { - const AutomationPattern * a = dynamic_cast(tco); - if (a && a->hasAutomation()) + const AutomationPattern * a = dynamic_cast( *j ); + if( a && a->hasAutomation() ) { - for (const auto model: a->m_objects) { - if(model == _m) { return true; } + for( objectVector::const_iterator k = a->m_objects.begin(); k != a->m_objects.end(); ++k ) + { + if( *k == _m ) + { + return true; + } } } } @@ -659,39 +671,42 @@ bool AutomationPattern::isAutomated(const AutomatableModel* _m) /*! \brief returns a list of all the automation patterns everywhere that are connected to a specific model * \param _m the model we want to look for */ -QVector AutomationPattern::patternsForModel(const AutomatableModel* _m) +QVector AutomationPattern::patternsForModel( const AutomatableModel * _m ) { - QVector patterns; - TrackContainer::TrackList trackList; - trackList += Engine::getSong()->tracks(); - trackList += Engine::getBBTrackContainer()->tracks(); - trackList += Engine::getSong()->globalAutomationTrack(); + QVector patterns; + TrackContainer::TrackList l; + l += Engine::getSong()->tracks(); + l += Engine::getBBTrackContainer()->tracks(); + l += Engine::getSong()->globalAutomationTrack(); // go through all tracks... - for (const Track* track: trackList) + for( TrackContainer::TrackList::ConstIterator it = l.begin(); it != l.end(); ++it ) { // we want only automation tracks... - if (track->type() == Track::AutomationTrack || - track->type() == Track::HiddenAutomationTrack ) + if( ( *it )->type() == Track::AutomationTrack || + ( *it )->type() == Track::HiddenAutomationTrack ) { // get patterns in those tracks.... - const Track::tcoVector& tcoVector = track->getTCOs(); + const Track::tcoVector & v = ( *it )->getTCOs(); // go through all the patterns... - for (TrackContentObject* tco: tcoVector) + for( Track::tcoVector::ConstIterator j = v.begin(); j != v.end(); ++j ) { - auto a = dynamic_cast(tco); + AutomationPattern * a = dynamic_cast( *j ); // check that the pattern has automation - if (a && a->hasAutomation()) + if( a && a->hasAutomation() ) { // now check is the pattern is connected to the model we want by going through all the connections // of the pattern bool has_object = false; - for (const auto model: a->m_objects) + for( objectVector::const_iterator k = a->m_objects.begin(); k != a->m_objects.end(); ++k ) { - if (model == _m) { has_object = true; } + if( *k == _m ) + { + has_object = true; + } } // if the patterns is connected to the model, add it to the list - if (has_object) { patterns += a; } + if( has_object ) { patterns += a; } } } } @@ -701,24 +716,29 @@ QVector AutomationPattern::patternsForModel(const Automatab -AutomationPattern* AutomationPattern::globalAutomationPattern(AutomatableModel* _m) +AutomationPattern * AutomationPattern::globalAutomationPattern( + AutomatableModel * _m ) { - AutomationTrack* track = Engine::getSong()->globalAutomationTrack(); - Track::tcoVector tcoVector = track->getTCOs(); - for (TrackContentObject* tco: tcoVector) + AutomationTrack * t = Engine::getSong()->globalAutomationTrack(); + Track::tcoVector v = t->getTCOs(); + for( Track::tcoVector::const_iterator j = v.begin(); j != v.end(); ++j ) { - auto a = dynamic_cast(tco); - if (a) + AutomationPattern * a = dynamic_cast( *j ); + if( a ) { - for (const auto model: a->m_objects) + for( objectVector::const_iterator k = a->m_objects.begin(); + k != a->m_objects.end(); ++k ) { - if (model == _m) { return a; } + if( *k == _m ) + { + return a; + } } } } - AutomationPattern* a = new AutomationPattern(track); - a->addObject(_m, false); + AutomationPattern * a = new AutomationPattern( t ); + a->addObject( _m, false ); return a; } @@ -727,37 +747,51 @@ AutomationPattern* AutomationPattern::globalAutomationPattern(AutomatableModel* void AutomationPattern::resolveAllIDs() { - TrackContainer::TrackList trackList = Engine::getSong()->tracks(); - trackList += Engine::getBBTrackContainer()->tracks(); - trackList += Engine::getSong()->globalAutomationTrack(); - - for (const Track* track: trackList) + TrackContainer::TrackList l = Engine::getSong()->tracks() + + Engine::getBBTrackContainer()->tracks(); + l += Engine::getSong()->globalAutomationTrack(); + for( TrackContainer::TrackList::iterator it = l.begin(); + it != l.end(); ++it ) { - if (track->type() == Track::AutomationTrack || - track->type() == Track::HiddenAutomationTrack) + if( ( *it )->type() == Track::AutomationTrack || + ( *it )->type() == Track::HiddenAutomationTrack ) { - Track::tcoVector tcoVector = track->getTCOs(); - for (TrackContentObject* tco: tcoVector) + Track::tcoVector v = ( *it )->getTCOs(); + for( Track::tcoVector::iterator j = v.begin(); + j != v.end(); ++j ) { - AutomationPattern* a = dynamic_cast(tco); - if (a) + AutomationPattern * a = dynamic_cast( *j ); + if( a ) { - for (const jo_id_t id: a->m_idsToResolve) + for( QVector::Iterator k = a->m_idsToResolve.begin(); + k != a->m_idsToResolve.end(); ++k ) { - JournallingObject* o = Engine::projectJournal()-> - journallingObject(id); - AutomatableModel* am = dynamic_cast(o); - if (o && am) { a->addObject(am, false); continue; } - - // FIXME: Remove this block once the automation system gets fixed - // This is a temporary fix for https://github.com/LMMS/lmms/issues/3781 - o = Engine::projectJournal()->journallingObject(ProjectJournal::idFromSave(id)); - if (o && am) { a->addObject(am, false); continue; } - - // FIXME: Remove this block once the automation system gets fixed - // This is a temporary fix for https://github.com/LMMS/lmms/issues/4781 - o = Engine::projectJournal()->journallingObject(ProjectJournal::idToSave(id)); - if (o && am) { a->addObject(am, false); } + JournallingObject * o = Engine::projectJournal()-> + journallingObject( *k ); + if( o && dynamic_cast( o ) ) + { + a->addObject( dynamic_cast( o ), false ); + } + else + { + // FIXME: Remove this block once the automation system gets fixed + // This is a temporary fix for https://github.com/LMMS/lmms/issues/3781 + o = Engine::projectJournal()->journallingObject(ProjectJournal::idFromSave(*k)); + if( o && dynamic_cast( o ) ) + { + a->addObject( dynamic_cast( o ), false ); + } + else + { + // FIXME: Remove this block once the automation system gets fixed + // This is a temporary fix for https://github.com/LMMS/lmms/issues/4781 + o = Engine::projectJournal()->journallingObject(ProjectJournal::idToSave(*k)); + if( o && dynamic_cast( o ) ) + { + a->addObject( dynamic_cast( o ), false ); + } + } + } } a->m_idsToResolve.clear(); a->dataChanged(); @@ -809,10 +843,16 @@ void AutomationPattern::objectDestroyed( jo_id_t _id ) void AutomationPattern::cleanObjects() { - for (objectVector::iterator it = m_objects.begin(); it != m_objects.end();) + for( objectVector::iterator it = m_objects.begin(); it != m_objects.end(); ) { - if (*it) { ++it; } - else { it = m_objects.erase(it); } + if( *it ) + { + ++it; + } + else + { + it = m_objects.erase( it ); + } } } @@ -858,3 +898,8 @@ void AutomationPattern::generateTangents( timeMap::const_iterator it, it++; } } + + + + +