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

Replace every use of the foreach macro with an iterator loop #2658

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions include/InstrumentPlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class EXPORT InstrumentPlayHandle : public PlayHandle
do
{
nphsLeft = false;
foreach( const NotePlayHandle * cnph, nphv )
for( ConstNotePlayHandleList::const_iterator it = nphv.constBegin(); it != nphv.constEnd(); ++it )
{
NotePlayHandle * nph = const_cast<NotePlayHandle *>( cnph );
NotePlayHandle * nph = const_cast<NotePlayHandle *>( *it );
if( nph->state() != ThreadableJob::Done && ! nph->isFinished() )
{
nphsLeft = true;
Expand Down
18 changes: 12 additions & 6 deletions plugins/MidiExport/MidiExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,35 @@ bool MidiExport::tryExport( const TrackContainer::TrackList &tracks, int tempo,
uint8_t buffer[BUFFER_SIZE];
uint32_t size;

foreach( Track* track, tracks ) if( track->type() == Track::InstrumentTrack ) nTracks++;
for( TrackContainer::TrackList::const_iterator it = tracks.constBegin(); it != tracks.constEnd(); ++it )
{
if( ( *it )->type() == Track::InstrumentTrack )
{
nTracks++;
}
}

// midi header
MidiFile::MIDIHeader header(nTracks);
size = header.writeToBuffer(buffer);
midiout.writeRawData((char *)buffer, size);

// midi tracks
foreach( Track* track, tracks )
for( TrackContainer::TrackList::const_iterator it = tracks.constBegin(); it != tracks.constEnd(); ++it )
{
DataFile dataFile( DataFile::SongProject );
MidiFile::MIDITrack<BUFFER_SIZE> mtrack;

if( track->type() != Track::InstrumentTrack ) continue;
if( ( *it )->type() != Track::InstrumentTrack ) continue;

//qDebug() << "exporting " << track->name();
//qDebug() << "exporting " << ( *it )->name();


mtrack.addName(track->name().toStdString(), 0);
mtrack.addName(( *it )->name().toStdString(), 0);
//mtrack.addProgramChange(0, 0);
mtrack.addTempo(tempo, 0);

instTrack = dynamic_cast<InstrumentTrack *>( track );
instTrack = dynamic_cast<InstrumentTrack *>( *it );
element = instTrack->saveState( dataFile, dataFile.content() );

// instrumentTrack
Expand Down
7 changes: 4 additions & 3 deletions plugins/zynaddsubfx/ZynAddSubFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ void ZynAddSubFxInstrument::loadSettings( const QDomElement & _this )
m_pluginMutex.unlock();

m_modifiedControllers.clear();
foreach( const QString & c, _this.attribute( "modifiedcontrollers" ).split( ',' ) )
QStringList modifiedControllers = _this.attribute( "modifiedcontrollers" ).split( ',' );
for( QStringList::const_iterator it = modifiedControllers.constBegin(); it != modifiedControllers.constEnd(); ++it )
{
if( !c.isEmpty() )
if( !( *it ).isEmpty() )
{
switch( c.toInt() )
switch( ( *it ).toInt() )
{
case C_portamento: updatePortamento(); break;
case C_filtercutoff: updateFilterFreq(); break;
Expand Down
4 changes: 2 additions & 2 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ void AutomatableModel::unlinkModels( AutomatableModel* model1, AutomatableModel*

void AutomatableModel::unlinkAllModels()
{
foreach( AutomatableModel* model, m_linkedModels )
for( AutoModelVector::const_iterator it = m_linkedModels.constBegin(); it != m_linkedModels.constEnd(); ++it )
{
unlinkModels( this, model );
unlinkModels( this, *it );
}

m_hasLinkedModels = false;
Expand Down
4 changes: 2 additions & 2 deletions src/core/ComboBoxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void ComboBoxModel::addItem( const QString& item, PixmapLoader* loader )
void ComboBoxModel::clear()
{
setRange( 0, 0 );
foreach( const Item& i, m_items )
for( QVector<Item>::const_iterator it = m_items.constBegin(); it != m_items.constEnd(); ++it )
{
delete i.second;
delete ( *it ).second;
}

m_items.clear();
Expand Down
50 changes: 25 additions & 25 deletions src/core/FxMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ FxChannel::~FxChannel()

inline void FxChannel::processed()
{
foreach( FxRoute * receiverRoute, m_sends )
for( FxRouteVector::const_iterator it = m_sends.constBegin(); it != m_sends.constEnd(); ++it )
{
if( receiverRoute->receiver()->m_muted == false )
if( ( *it )->receiver()->m_muted == false )
{
receiverRoute->receiver()->incrementDeps();
( *it )->receiver()->incrementDeps();
}
}
}
Expand Down Expand Up @@ -121,11 +121,11 @@ void FxChannel::doProcessing()

if( m_muted == false )
{
foreach( FxRoute * senderRoute, m_receives )
for( FxRouteVector::const_iterator it = m_receives.constBegin(); it != m_receives.constEnd(); ++it )
{
FxChannel * sender = senderRoute->sender();
FloatModel * sendModel = senderRoute->amount();
if( ! sendModel ) qFatal( "Error: no send model found from %d to %d", senderRoute->senderIndex(), m_channelIndex );
FxChannel * sender = ( *it )->sender();
FloatModel * sendModel = ( *it )->amount();
if( ! sendModel ) qFatal( "Error: no send model found from %d to %d", ( *it )->senderIndex(), m_channelIndex );

if( sender->m_hasInput || sender->m_stillRunning )
{
Expand Down Expand Up @@ -293,11 +293,11 @@ void FxMixer::deleteChannel( int index )
tracks += Engine::getSong()->tracks();
tracks += Engine::getBBTrackContainer()->tracks();

foreach( Track* t, tracks )
for( TrackContainer::TrackList::const_iterator it = tracks.constBegin(); it != tracks.constEnd(); ++it )
{
if( t->type() == Track::InstrumentTrack )
if( ( *it )->type() == Track::InstrumentTrack )
{
InstrumentTrack* inst = dynamic_cast<InstrumentTrack *>( t );
InstrumentTrack* inst = dynamic_cast<InstrumentTrack *>( *it );
int val = inst->effectChannelModel()->value(0);
if( val == index )
{
Expand Down Expand Up @@ -335,13 +335,13 @@ void FxMixer::deleteChannel( int index )
m_fxChannels[i]->m_channelIndex = i;

// now check all routes and update names of the send models
foreach( FxRoute * r, m_fxChannels[i]->m_sends )
for( FxRouteVector::const_iterator it = m_fxChannels[i]->m_sends.constBegin(); it != m_fxChannels[i]->m_sends.constEnd(); ++it )
{
r->updateName();
( *it )->updateName();
}
foreach( FxRoute * r, m_fxChannels[i]->m_receives )
for( FxRouteVector::const_iterator it = m_fxChannels[i]->m_receives.constBegin(); it != m_fxChannels[i]->m_receives.constEnd(); ++it )
{
r->updateName();
( *it )->updateName();
}
}
}
Expand Down Expand Up @@ -528,11 +528,11 @@ FloatModel * FxMixer::channelSendModel( fx_ch_t fromChannel, fx_ch_t toChannel )
const FxChannel * from = m_fxChannels[fromChannel];
const FxChannel * to = m_fxChannels[toChannel];

foreach( FxRoute * route, from->m_sends )
for( FxRouteVector::const_iterator it = from->m_sends.constBegin(); it != from->m_sends.constEnd(); ++it )
{
if( route->receiver() == to )
if( ( *it )->receiver() == to )
{
return route->amount();
return ( *it )->amount();
}
}

Expand Down Expand Up @@ -578,18 +578,18 @@ void FxMixer::masterMix( sampleFrame * _buf )
// also instantly add all muted channels as they don't need to care about their senders, and can just increment the deps of
// their recipients right away.
MixerWorkerThread::resetJobQueue( MixerWorkerThread::JobQueue::Dynamic );
foreach( FxChannel * ch, m_fxChannels )
for( QVector<FxChannel *>::const_iterator it = m_fxChannels.constBegin(); it != m_fxChannels.constEnd(); ++it )
{
ch->m_muted = ch->m_muteModel.value();
if( ch->m_muted ) // instantly "process" muted channels
( *it )->m_muted = ( *it )->m_muteModel.value();
if( ( *it )->m_muted ) // instantly "process" muted channels
{
ch->processed();
ch->done();
( *it )->processed();
( *it )->done();
}
else if( ch->m_receives.size() == 0 )
else if( ( *it )->m_receives.size() == 0 )
{
ch->m_queued = true;
MixerWorkerThread::addJob( ch );
( *it )->m_queued = true;
MixerWorkerThread::addJob( *it );
}
}
while( m_fxChannels[0]->state() != ThreadableJob::Done )
Expand Down
19 changes: 4 additions & 15 deletions src/core/NotePlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,6 @@ void NotePlayHandle::play( sampleFrame * _working_buffer )
}
}

// play sub-notes (e.g. chords)
// handled by mixer now
/* foreach( NotePlayHandle * n, m_subNotes )
{
n->play( _working_buffer );
if( n->isFinished() )
{
NotePlayHandleManager::release( n );
}
}*/

// update internal data
m_totalFramesPlayed += framesThisPeriod;
unlock();
Expand Down Expand Up @@ -369,11 +358,11 @@ void NotePlayHandle::noteOff( const f_cnt_t _s )
m_released = true;

// first note-off all sub-notes
foreach( NotePlayHandle * n, m_subNotes )
for( NotePlayHandleList::const_iterator it = m_subNotes.constBegin(); it != m_subNotes.constEnd(); ++it )
{
n->lock();
n->noteOff( _s );
n->unlock();
( *it )->lock();
( *it )->noteOff( _s );
( *it )->unlock();
}

// then set some variables indicating release-state
Expand Down
13 changes: 7 additions & 6 deletions src/core/audio/AudioPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ void AudioPort::doProcessing()
BufferManager::clear( m_portBuffer, fpp );

//qDebug( "Playhandles: %d", m_playHandles.size() );
foreach( PlayHandle * ph, m_playHandles ) // now we mix all playhandle buffers into the audioport buffer
// now we mix all playhandle buffers into the audioport buffer
for( PlayHandleList::const_iterator it = m_playHandles.constBegin(); it != m_playHandles.constEnd(); ++it )
{
if( ph->buffer() )
if( ( *it )->buffer() )
{
if( ph->usesBuffer() )
if( ( *it )->usesBuffer() )
{
m_bufferUsage = true;
MixHelpers::add( m_portBuffer, ph->buffer(), fpp );
MixHelpers::add( m_portBuffer, ( *it )->buffer(), fpp );
}
ph->releaseBuffer(); // gets rid of playhandle's buffer and sets
// pointer to null, so if it doesn't get re-acquired we know to skip it next time
( *it )->releaseBuffer(); // gets rid of playhandle's buffer and sets
// pointer to null, so if it doesn't get re-acquired we know to skip it next time
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/fft_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int compressbands(float *absspec_buffer, float *compressedband, int num_old, int

ratio=(float)usefromold/(float)num_new;

// foreach new subband
// for each new subband
Copy link
Member

Choose a reason for hiding this comment

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

-   // foreach new subband
+   // for each new subband

bahahaha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered if anyone would spot that one 😁. I really wanted grep -r foreach to be clean 😋

for ( i=0; i<num_new; i++ )
{
compressedband[i]=0;
Expand Down
7 changes: 4 additions & 3 deletions src/gui/EffectSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ void EffectSelectDialog::rowChanged( const QModelIndex & _idx,
subLayout->setSpacing( 0 );
m_currentSelection.desc->subPluginFeatures->
fillDescriptionWidget( subWidget, &m_currentSelection );
foreach( QWidget * w, subWidget->findChildren<QWidget *>() )
QList<QWidget *> subChildren = subWidget->findChildren<QWidget *>();
for( QList<QWidget *>::const_iterator it = subChildren.constBegin(); it != subChildren.constEnd(); ++it )
{
if( w->parent() == subWidget )
if( ( *it )->parent() == subWidget )
{
subLayout->addWidget( w );
subLayout->addWidget( *it );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/FxMixerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ void FxMixerView::deleteUnusedChannels()
{
// check if an instrument references to the current channel
bool empty=true;
foreach( Track* t, tracks )
for( TrackContainer::TrackList::const_iterator it = tracks.constBegin(); it != tracks.constEnd(); ++it )
{
if( t->type() == Track::InstrumentTrack )
if( ( *it )->type() == Track::InstrumentTrack )
{
InstrumentTrack* inst = dynamic_cast<InstrumentTrack *>( t );
InstrumentTrack* inst = dynamic_cast<InstrumentTrack *>( *it );
if( i == inst->effectChannelModel()->value(0) )
{
empty=false;
Expand Down
9 changes: 5 additions & 4 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ MainWindow::MainWindow() :

#if ! defined(LMMS_BUILD_APPLE)
QFileInfoList drives = QDir::drives();
foreach( const QFileInfo & drive, drives )
for( QFileInfoList::const_iterator it = drives.constBegin(); it != drives.constEnd(); ++it )
{
root_paths += drive.absolutePath();
root_paths += ( *it ).absolutePath();
}
#endif

Expand Down Expand Up @@ -602,9 +602,10 @@ void MainWindow::finalize()
gui->songEditor()->parentWidget()->show();

// reset window title every time we change the state of a subwindow to show the correct title
foreach( QMdiSubWindow * subWindow, workspace()->subWindowList() )
QList<QMdiSubWindow *> subWindowList = workspace()->subWindowList();
for( QList<QMdiSubWindow *>::const_iterator it = subWindowList.constBegin(); it != subWindowList.constEnd(); ++it )
{
connect( subWindow, SIGNAL( windowStateChanged(Qt::WindowStates,Qt::WindowStates) ), this, SLOT( resetWindowTitle() ) );
connect( *it, SIGNAL( windowStateChanged(Qt::WindowStates,Qt::WindowStates) ), this, SLOT( resetWindowTitle() ) );
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/gui/editors/BBEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ void BBTrackContainerView::addAutomationTrack()

void BBTrackContainerView::removeBBView(int bb)
{
foreach( TrackView* view, trackViews() )
QList<TrackView *> tvs = trackViews();
for( QList<TrackView *>::const_iterator it = tvs.constBegin(); it != tvs.constEnd(); ++it )
{
view->getTrackContentWidget()->removeTCOView( bb );
( *it )->getTrackContentWidget()->removeTCOView( bb );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/gui/widgets/AutomatableButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ void automatableButtonGroup::activateButton( AutomatableButton * _btn )
m_buttons.indexOf( _btn ) != -1 )
{
model()->setValue( m_buttons.indexOf( _btn ) );
foreach( AutomatableButton * btn, m_buttons )
for( QList<AutomatableButton *>::const_iterator it = m_buttons.constBegin(); it != m_buttons.constEnd(); ++it )
{
btn->update();
( *it )->update();
}
}
}
Expand All @@ -261,9 +261,9 @@ void automatableButtonGroup::updateButtons()
{
model()->setRange( 0, m_buttons.size() - 1 );
int i = 0;
foreach( AutomatableButton * btn, m_buttons )
for( QList<AutomatableButton *>::const_iterator it = m_buttons.constBegin(); it != m_buttons.constEnd(); ++it )
{
btn->model()->setValue( i == model()->value() );
( *it )->model()->setValue( i == model()->value() );
++i;
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/tracks/BBTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,5 @@ void BBTrackView::clickedTrackLabel()
{
Engine::getBBTrackContainer()->setCurrentBB( m_bbTrack->index() );
gui->getBBEditor()->show();
/* foreach( bbTrackView * tv,
trackContainerView()->findChildren<bbTrackView *>() )
{
tv->m_trackLabel->update();
}*/

}







9 changes: 4 additions & 5 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,13 +949,12 @@ InstrumentTrackView::~InstrumentTrackView()
InstrumentTrackWindow * InstrumentTrackView::topLevelInstrumentTrackWindow()
{
InstrumentTrackWindow * w = NULL;
foreach( QMdiSubWindow * sw,
gui->mainWindow()->workspace()->subWindowList(
QMdiArea::ActivationHistoryOrder ) )
QList<QMdiSubWindow *> subWindowList = gui->mainWindow()->workspace()->subWindowList( QMdiArea::ActivationHistoryOrder );
for( QList<QMdiSubWindow *>::const_iterator it = subWindowList.constBegin(); it != subWindowList.constEnd(); ++it )
{
if( sw->isVisible() && sw->widget()->inherits( "InstrumentTrackWindow" ) )
if( ( *it )->isVisible() && ( *it )->widget()->inherits( "InstrumentTrackWindow" ) )
{
w = qobject_cast<InstrumentTrackWindow *>( sw->widget() );
w = qobject_cast<InstrumentTrackWindow *>( ( *it )->widget() );
}
}

Expand Down