Skip to content

Commit

Permalink
Revert "Replace iterator where possible"
Browse files Browse the repository at this point in the history
This reverts commit 0cc50b7.
  • Loading branch information
Spekular committed Aug 11, 2020
1 parent 0cc50b7 commit 5f24aab
Showing 1 changed file with 152 additions and 107 deletions.
259 changes: 152 additions & 107 deletions src/core/AutomationPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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())
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 )
{
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;
}
}
Expand Down Expand Up @@ -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<tick_t>(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<tick_t>((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);
}


Expand Down Expand Up @@ -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 );
}
}
}
Expand Down Expand Up @@ -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<const AutomationPattern *>(tco);
if (a && a->hasAutomation())
const AutomationPattern * a = dynamic_cast<const AutomationPattern *>( *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;
}
}
}
}
Expand All @@ -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 *> AutomationPattern::patternsForModel(const AutomatableModel* _m)
QVector<AutomationPattern *> AutomationPattern::patternsForModel( const AutomatableModel * _m )
{
QVector<AutomationPattern*> patterns;
TrackContainer::TrackList trackList;
trackList += Engine::getSong()->tracks();
trackList += Engine::getBBTrackContainer()->tracks();
trackList += Engine::getSong()->globalAutomationTrack();
QVector<AutomationPattern *> 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<AutomationPattern*>(tco);
AutomationPattern * a = dynamic_cast<AutomationPattern *>( *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; }
}
}
}
Expand All @@ -701,24 +716,29 @@ QVector<AutomationPattern *> 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<AutomationPattern*>(tco);
if (a)
AutomationPattern * a = dynamic_cast<AutomationPattern *>( *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;
}

Expand All @@ -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<AutomationPattern *>(tco);
if (a)
AutomationPattern * a = dynamic_cast<AutomationPattern *>( *j );
if( a )
{
for (const jo_id_t id: a->m_idsToResolve)
for( QVector<jo_id_t>::Iterator k = a->m_idsToResolve.begin();
k != a->m_idsToResolve.end(); ++k )
{
JournallingObject* o = Engine::projectJournal()->
journallingObject(id);
AutomatableModel* am = dynamic_cast<AutomatableModel*>(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<AutomatableModel *>( o ) )
{
a->addObject( dynamic_cast<AutomatableModel *>( 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<AutomatableModel *>( o ) )
{
a->addObject( dynamic_cast<AutomatableModel *>( 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<AutomatableModel *>( o ) )
{
a->addObject( dynamic_cast<AutomatableModel *>( o ), false );
}
}
}
}
a->m_idsToResolve.clear();
a->dataChanged();
Expand Down Expand Up @@ -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 );
}
}
}

Expand Down Expand Up @@ -858,3 +898,8 @@ void AutomationPattern::generateTangents( timeMap::const_iterator it,
it++;
}
}





0 comments on commit 5f24aab

Please sign in to comment.