clang-tidy: Apply modernize-loop-convert everywhere (#6481)

Co-authored-by: allejok96 <allejok96@gmail.com>
Co-authored-by: Dominic Clark <mrdomclark@gmail.com>
This commit is contained in:
saker
2022-09-27 04:27:35 -04:00
committed by GitHub
parent e407e73e24
commit 2f7a6558a1
67 changed files with 441 additions and 598 deletions

View File

@@ -355,10 +355,9 @@ void GigInstrument::play( sampleFrame * _working_buffer )
it->state = PlayingKeyUp;
// Notify each sample that the key has been released
for( QList<GigSample>::iterator sample = it->samples.begin();
sample != it->samples.end(); ++sample )
for (auto& sample : it->samples)
{
sample->adsr.keyup();
sample.adsr.keyup();
}
// Add release samples if available
@@ -408,22 +407,17 @@ void GigInstrument::play( sampleFrame * _working_buffer )
}
// Fill buffer with portions of the note samples
for( QList<GigNote>::iterator it = m_notes.begin(); it != m_notes.end(); ++it )
for (auto& note : m_notes)
{
// Only process the notes if we're in a playing state
if( !( it->state == PlayingKeyDown ||
it->state == PlayingKeyUp ) )
if (!(note.state == PlayingKeyDown || note.state == PlayingKeyUp ))
{
continue;
}
for( QList<GigSample>::iterator sample = it->samples.begin();
sample != it->samples.end(); ++sample )
for (auto& sample : note.samples)
{
if( sample->sample == nullptr || sample->region == nullptr )
{
continue;
}
if (sample.sample == nullptr || sample.region == nullptr) { continue; }
// Will change if resampling
bool resample = false;
@@ -434,18 +428,15 @@ void GigInstrument::play( sampleFrame * _working_buffer )
// Resample to be the correct pitch when the sample provided isn't
// solely for this one note (e.g. one or two samples per octave) or
// we are processing at a different sample rate
if( sample->region->PitchTrack == true || rate != sample->sample->SamplesPerSecond )
if (sample.region->PitchTrack == true || rate != sample.sample->SamplesPerSecond)
{
resample = true;
// Factor just for resampling
freq_factor = 1.0 * rate / sample->sample->SamplesPerSecond;
freq_factor = 1.0 * rate / sample.sample->SamplesPerSecond;
// Factor for pitch shifting as well as resampling
if( sample->region->PitchTrack == true )
{
freq_factor *= sample->freqFactor;
}
if (sample.region->PitchTrack == true) { freq_factor *= sample.freqFactor; }
// We need a bit of margin so we don't get glitching
samples = frames / freq_factor + MARGIN[m_interpolation];
@@ -453,11 +444,11 @@ void GigInstrument::play( sampleFrame * _working_buffer )
// Load this note's data
sampleFrame sampleData[samples];
loadSample( *sample, sampleData, samples );
loadSample(sample, sampleData, samples);
// Apply ADSR using a copy so if we don't use these samples when
// resampling, the ADSR doesn't get messed up
ADSR copy = sample->adsr;
ADSR copy = sample.adsr;
for( f_cnt_t i = 0; i < samples; ++i )
{
@@ -472,8 +463,7 @@ void GigInstrument::play( sampleFrame * _working_buffer )
sampleFrame convertBuf[frames];
// Only output if resampling is successful (note that "used" is output)
if( sample->convertSampleRate( *sampleData, *convertBuf, samples, frames,
freq_factor, used ) )
if (sample.convertSampleRate(*sampleData, *convertBuf, samples, frames, freq_factor, used))
{
for( f_cnt_t i = 0; i < frames; ++i )
{
@@ -492,8 +482,8 @@ void GigInstrument::play( sampleFrame * _working_buffer )
}
// Update note position with how many samples we actually used
sample->pos += used;
sample->adsr.inc( used );
sample.pos += used;
sample.adsr.inc(used);
}
}
@@ -689,13 +679,12 @@ void GigInstrument::deleteNotePluginData( NotePlayHandle * _n )
// Mark the note as being released, but only if it was playing or was just
// pressed (i.e., not if the key was already released)
for( QList<GigNote>::iterator i = m_notes.begin(); i != m_notes.end(); ++i )
for (auto& note : m_notes)
{
// Find the note by matching pointers to the plugin data
if( i->handle == pluginData &&
( i->state == KeyDown || i->state == PlayingKeyDown ) )
if (note.handle == pluginData && (note.state == KeyDown || note.state == PlayingKeyDown))
{
i->state = KeyUp;
note.state = KeyUp;
}
}

View File

@@ -72,15 +72,13 @@ LadspaDescription::LadspaDescription( QWidget * _parent,
}
QList<QString> pluginNames;
for( l_sortable_plugin_t::iterator it = plugins.begin();
it != plugins.end(); ++it )
for (const auto& plugin : plugins)
{
if( _type != VALID ||
manager->getDescription( ( *it ).second )->inputChannels
<= Engine::audioEngine()->audioDev()->channels() )
{
pluginNames.push_back( ( *it ).first );
m_pluginKeys.push_back( ( *it ).second );
ch_cnt_t audioDeviceChannels = Engine::audioEngine()->audioDev()->channels();
if (_type != VALID || manager->getDescription(plugin.second)->inputChannels <= audioDeviceChannels)
{
pluginNames.push_back(plugin.first);
m_pluginKeys.push_back(plugin.second);
}
}

View File

@@ -69,11 +69,10 @@ LadspaControlDialog::LadspaControlDialog( LadspaControls * _ctl ) :
void LadspaControlDialog::updateEffectView( LadspaControls * _ctl )
{
QList<QGroupBox *> list = findChildren<QGroupBox *>();
for( QList<QGroupBox *>::iterator it = list.begin(); it != list.end();
++it )
QList<QGroupBox *> groupBoxes = findChildren<QGroupBox *>();
for (const auto& groupBox : groupBoxes)
{
delete *it;
delete groupBox;
}
m_effectControls = _ctl;
@@ -105,12 +104,11 @@ void LadspaControlDialog::updateEffectView( LadspaControls * _ctl )
grouper->setLayout( gl );
grouper->setAlignment( Qt::Vertical );
for( control_list_t::iterator it = controls.begin();
it != controls.end(); ++it )
for (const auto& control : controls)
{
if( (*it)->port()->proc == proc )
if (control->port()->proc == proc)
{
buffer_data_t this_port = (*it)->port()->data_type;
buffer_data_t this_port = control->port()->data_type;
if( last_port != NONE &&
( this_port == TOGGLED || this_port == ENUM ) &&
( last_port != TOGGLED && last_port != ENUM ) )
@@ -118,13 +116,13 @@ void LadspaControlDialog::updateEffectView( LadspaControls * _ctl )
++row;
col = 0;
}
gl->addWidget( new LadspaControlView( grouper, *it ), row, col );
gl->addWidget(new LadspaControlView(grouper, control), row, col);
if( ++col == cols )
{
++row;
col = 0;
}
last_port = (*it)->port()->data_type;
last_port = control->port()->data_type;
}
}

View File

@@ -53,20 +53,19 @@ LadspaControls::LadspaControls( LadspaEffect * _eff ) :
const bool linked_control = ( m_processors > 1 && proc == 0 );
for( multi_proc_t::Iterator it = controls.begin(); it != controls.end(); it++ )
for (const auto& control : controls)
{
if( (*it)->proc == proc )
if (control->proc == proc)
{
(*it)->control = new LadspaControl( this, *it,
linked_control );
control->control = new LadspaControl(this, control, linked_control);
p.append( (*it)->control );
p.append(control->control);
if( linked_control )
if (linked_control)
{
connect( (*it)->control, SIGNAL( linkChanged( int, bool ) ),
this, SLOT( linkPort( int, bool ) ),
Qt::DirectConnection );
connect(control->control, SIGNAL(linkChanged(int, bool)),
this, SLOT(linkPort(int, bool)),
Qt::DirectConnection);
}
}
}
@@ -77,12 +76,11 @@ LadspaControls::LadspaControls( LadspaEffect * _eff ) :
// now link all controls
if( m_processors > 1 )
{
for( multi_proc_t::Iterator it = controls.begin();
it != controls.end(); it++ )
for (const auto& control : controls)
{
if( (*it)->proc == 0 )
if (control->proc == 0)
{
linkPort( ( *it )->control_id, true );
linkPort(control->control_id, true);
}
}
}
@@ -112,12 +110,10 @@ void LadspaControls::saveSettings( QDomDocument & _doc, QDomElement & _this )
multi_proc_t controls = m_effect->getPortControls();
_this.setAttribute( "ports", controls.count() );
for( multi_proc_t::Iterator it = controls.begin();
it != controls.end(); it++ )
for (const auto& control : controls)
{
QString n = "port" + QString::number( (*it)->proc ) +
QString::number( (*it)->port_id );
(*it)->control->saveSettings( _doc, _this, n );
QString n = "port" + QString::number(control->proc) + QString::number(control->port_id);
control->control->saveSettings(_doc, _this, n);
}
}
@@ -132,12 +128,10 @@ void LadspaControls::loadSettings( const QDomElement & _this )
}
multi_proc_t controls = m_effect->getPortControls();
for( multi_proc_t::Iterator it = controls.begin();
it != controls.end(); it++ )
for (const auto& control : controls)
{
QString n = "port" + QString::number( (*it)->proc ) +
QString::number( (*it)->port_id );
(*it)->control->loadSettings( _this, n );
QString n = "port" + QString::number(control->proc) + QString::number(control->port_id);
control->control->loadSettings(_this, n);
}
}

View File

@@ -356,8 +356,9 @@ Lb302Synth::Lb302Synth( InstrumentTrack * _instrumentTrack ) :
Lb302Synth::~Lb302Synth()
{
for (int i=0; i<NUM_FILTERS; ++i) {
delete vcfs[i];
for (const auto& vcf : vcfs)
{
delete vcf;
}
}

View File

@@ -78,9 +78,6 @@ Lv2Instrument::Lv2Instrument(InstrumentTrack *instrumentTrackArg,
{
if (Lv2ControlBase::isValid())
{
#ifdef LV2_INSTRUMENT_USE_MIDI
for (int i = 0; i < NumKeys; ++i) { m_runningNotes[i] = 0; }
#endif
connect(instrumentTrack()->pitchRangeModel(), SIGNAL(dataChanged()),
this, SLOT(updatePitchRange()), Qt::DirectConnection);
connect(Engine::audioEngine(), &AudioEngine::sampleRateChanged,

View File

@@ -101,7 +101,7 @@ private:
void setNameFromFile(const QString &name) override;
#ifdef LV2_INSTRUMENT_USE_MIDI
int m_runningNotes[NumKeys];
std::array<int, NumKeys> m_runningNotes = {};
#endif
friend class gui::Lv2InsView;

View File

@@ -216,27 +216,28 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks,
int len = n.toElement().attribute("steps", "1").toInt() * 12;
// for each pattern clip of the current pattern track (in song editor)
for (auto it = plist.begin(); it != plist.end(); ++it)
for (const auto& position : plist)
{
while (!st.empty() && st.back().second <= it->first)
const auto& [start, end] = position;
while (!st.empty() && st.back().second <= start)
{
writePatternClip(midiClip, nv, len, st.back().first, pos, st.back().second);
pos = st.back().second;
st.pop_back();
}
if (!st.empty() && st.back().second <= it->second)
if (!st.empty() && st.back().second <= end)
{
writePatternClip(midiClip, nv, len, st.back().first, pos, it->first);
pos = it->first;
while (!st.empty() && st.back().second <= it->second)
writePatternClip(midiClip, nv, len, st.back().first, pos, start);
pos = start;
while (!st.empty() && st.back().second <= end)
{
st.pop_back();
}
}
st.push_back(*it);
pos = it->first;
st.push_back(position);
pos = start;
}
while (!st.empty())
@@ -286,9 +287,9 @@ void MidiExport::writeMidiClip(MidiNoteVector &midiClip, const QDomNode& n,
void MidiExport::writeMidiClipToTrack(MTrack &mtrack, MidiNoteVector &nv)
{
for (auto it = nv.begin(); it != nv.end(); ++it)
for (const auto& note : nv)
{
mtrack.addNote(it->pitch, it->volume, it->time / 48.0, it->duration / 48.0);
mtrack.addNote(note.pitch, note.volume, note.time / 48.0, note.duration / 48.0);
}
}
@@ -301,16 +302,15 @@ void MidiExport::writePatternClip(MidiNoteVector& src, MidiNoteVector& dst,
start -= base;
end -= base;
std::sort(src.begin(), src.end());
for (auto it = src.begin(); it != src.end(); ++it)
for (const auto& srcNote : src)
{
for (int time = it->time + ceil((start - it->time) / len)
* len; time < end; time += len)
for (int time = srcNote.time + ceil((start - srcNote.time) / len) * len; time < end; time += len)
{
MidiNote note;
note.duration = it->duration;
note.pitch = it->pitch;
note.duration = srcNote.duration;
note.pitch = srcNote.pitch;
note.time = base + time;
note.volume = it->volume;
note.volume = srcNote.volume;
dst.push_back(note);
}
}

View File

@@ -401,9 +401,9 @@ bool MidiImport::readSMF( TrackContainer* tc )
Alg_track_ptr trk = seq->track( t );
pd.setValue( t + preTrackSteps );
for( int c = 0; c < MIDI_CC_COUNT; c++ )
for (auto& cc : ccs)
{
ccs[c].clear();
cc.clear();
}
// Now look at events

View File

@@ -399,16 +399,16 @@ void PatmanInstrument::selectSample( NotePlayHandle * _n )
float min_dist = HUGE_VALF;
SampleBuffer* sample = nullptr;
for( QVector<SampleBuffer *>::iterator it = m_patchSamples.begin(); it != m_patchSamples.end(); ++it )
for (const auto& patchSample : m_patchSamples)
{
float patch_freq = ( *it )->frequency();
float patch_freq = patchSample->frequency();
float dist = freq >= patch_freq ? freq / patch_freq :
patch_freq / freq;
if( dist < min_dist )
{
min_dist = dist;
sample = *it;
sample = patchSample;
}
}

View File

@@ -115,10 +115,6 @@ Sf2Instrument::Sf2Instrument( InstrumentTrack * _instrument_track ) :
m_chorusSpeed( FLUID_CHORUS_DEFAULT_SPEED, 0.29, 5.0, 0.01, this, tr( "Chorus speed" ) ),
m_chorusDepth( FLUID_CHORUS_DEFAULT_DEPTH, 0, 46.0, 0.05, this, tr( "Chorus depth" ) )
{
for( int i = 0; i < 128; ++i )
{
m_notesRunning[i] = 0;
}
#if QT_VERSION_CHECK(FLUIDSYNTH_VERSION_MAJOR, FLUIDSYNTH_VERSION_MINOR, FLUIDSYNTH_VERSION_MICRO) >= QT_VERSION_CHECK(1,1,9)
@@ -1194,7 +1190,6 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main( Model *m, void * )
{
return new Sf2Instrument( static_cast<InstrumentTrack *>( m ) );
}
}

View File

@@ -135,7 +135,7 @@ private:
QMutex m_synthMutex;
QMutex m_loadMutex;
int m_notesRunning[128];
std::array<int, 128> m_notesRunning = {};
sample_rate_t m_internalSampleRate;
int m_lastMidiPitch;
int m_lastMidiPitchRange;

View File

@@ -140,11 +140,12 @@ void SfxrSynth::resetSample( bool restart )
if(s->m_phaserSweepModel.value()<0.0f) fdphase=-fdphase;
iphase=abs((int)fphase);
ipp=0;
for(int i=0;i<1024;i++)
phaser_buffer[i]=0.0f;
for(int i=0;i<32;i++)
noise_buffer[i]=frnd(2.0f)-1.0f;
phaser_buffer.fill(0.0f);
for (auto& noiseSample : noise_buffer)
{
noiseSample = frnd(2.0f) - 1.0f;
}
rep_time=0;
rep_limit=(int)(pow(1.0f-s->m_repeatSpeedModel.value(), 2.0f)*20000+32);
@@ -239,8 +240,10 @@ void SfxrSynth::update( sampleFrame * buffer, const int32_t frameNum )
// phase=0;
phase%=period;
if(s->m_waveFormModel.value()==3)
for(int i=0;i<32;i++)
noise_buffer[i]=frnd(2.0f)-1.0f;
for (auto& noiseSample : noise_buffer)
{
noiseSample = frnd(2.0f) - 1.0f;
}
}
// base waveform
float fp=(float)phase/period;

View File

@@ -105,7 +105,7 @@ private:
float fphase;
float fdphase;
int iphase;
float phaser_buffer[1024];
std::array<float, 1024> phaser_buffer;
int ipp;
float noise_buffer[32];
float fltp;

View File

@@ -227,10 +227,10 @@ f_cnt_t SidInstrument::desiredReleaseFrames() const
{
const float samplerate = Engine::audioEngine()->processingSampleRate();
int maxrel = 0;
for( int i = 0 ; i < 3 ; ++i )
for (const auto& voice : m_voice)
{
if( maxrel < m_voice[i]->m_releaseModel.value() )
maxrel = (int)m_voice[i]->m_releaseModel.value();
if( maxrel < voice->m_releaseModel.value() )
maxrel = (int)voice->m_releaseModel.value();
}
return f_cnt_t( float(relTime[maxrel])*samplerate/1000.0 );
@@ -320,9 +320,9 @@ void SidInstrument::playNote( NotePlayHandle * _n,
auto buf = reinterpret_cast<short*>(_working_buffer + offset);
unsigned char sidreg[NUMSIDREGS];
for (int c = 0; c < NUMSIDREGS; c++)
for (auto& reg : sidreg)
{
sidreg[c] = 0x00;
reg = 0x00;
}
if( (ChipModel)m_chipModel.value() == sidMOS6581 )
@@ -749,20 +749,14 @@ void SidInstrumentView::modelChanged()
&k->m_voice[i]->m_testModel );
}
for( int i = 0; i < 3; ++i )
for (const auto& voice : k->m_voice)
{
connect( &k->m_voice[i]->m_attackModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_decayModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_releaseModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_pulseWidthModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_sustainModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobToolTip() ) );
connect( &k->m_voice[i]->m_coarseModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobToolTip() ) );
connect(&voice->m_attackModel, SIGNAL(dataChanged()), this, SLOT(updateKnobHint()));
connect(&voice->m_decayModel, SIGNAL(dataChanged()), this, SLOT(updateKnobHint()));
connect(&voice->m_releaseModel, SIGNAL(dataChanged()), this, SLOT(updateKnobHint()));
connect(&voice->m_pulseWidthModel, SIGNAL(dataChanged()), this, SLOT(updateKnobHint()));
connect(&voice->m_sustainModel, SIGNAL(dataChanged()), this, SLOT(updateKnobToolTip()));
connect(&voice->m_coarseModel, SIGNAL(dataChanged()), this, SLOT(updateKnobToolTip()));
}
connect( &k->m_volumeModel, SIGNAL( dataChanged() ),

View File

@@ -409,10 +409,10 @@ gui::PluginView* TripleOscillator::instantiateView( QWidget * _parent )
void TripleOscillator::updateAllDetuning()
{
for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
for (const auto& osc : m_osc)
{
m_osc[i]->updateDetuningLeft();
m_osc[i]->updateDetuningRight();
osc->updateDetuningLeft();
osc->updateDetuningRight();
}
}

View File

@@ -375,15 +375,12 @@ void VstPlugin::setParameterDump( const QMap<QString, QString> & _pdump )
{
message m( IdVstSetParameterDump );
m.addInt( _pdump.size() );
for( QMap<QString, QString>::ConstIterator it = _pdump.begin();
it != _pdump.end(); ++it )
for (const auto& str : _pdump)
{
const VstParameterDumpItem item =
{
( *it ).section( ':', 0, 0 ).toInt(),
"",
LocaleHelper::toFloat((*it).section(':', 2, -1))
} ;
str.section(':', 0, 0).toInt(), "", LocaleHelper::toFloat(str.section(':', 2, -1))
};
m.addInt( item.index );
m.addString( item.shortLabel );
m.addFloat( item.value );

View File

@@ -377,13 +377,13 @@ public:
{}
~ExprFrontData()
{
for (int i = 0; i < m_cyclics.size() ; ++i)
for (const auto& cyclic : m_cyclics)
{
delete m_cyclics[i];
delete cyclic;
}
for (int i = 0; i < m_cyclics_interp.size() ; ++i)
for (const auto& cyclic : m_cyclics_interp)
{
delete m_cyclics_interp[i];
delete cyclic;
}
if (m_integ_func)
{

View File

@@ -51,11 +51,6 @@ LocalZynAddSubFx::LocalZynAddSubFx() :
m_master( nullptr ),
m_ioEngine( nullptr )
{
for( int i = 0; i < NumKeys; ++i )
{
m_runningNotes[i] = 0;
}
if( s_instanceCount == 0 )
{
#ifdef LMMS_BUILD_WIN32
@@ -182,14 +177,14 @@ void LocalZynAddSubFx::loadPreset( const std::string & _filename, int _part )
void LocalZynAddSubFx::setPresetDir( const std::string & _dir )
{
m_presetsDir = _dir;
for( int i = 0; i < MAX_BANK_ROOT_DIRS; ++i )
for (auto& bankRootDir : config.cfg.bankRootDirList)
{
if( config.cfg.bankRootDirList[i].empty() )
if (bankRootDir.empty())
{
config.cfg.bankRootDirList[i] = m_presetsDir;
bankRootDir = m_presetsDir;
break;
}
else if( config.cfg.bankRootDirList[i] == m_presetsDir )
else if (bankRootDir == m_presetsDir)
{
break;
}
@@ -214,9 +209,9 @@ void LocalZynAddSubFx::setLmmsWorkingDir( const std::string & _dir )
void LocalZynAddSubFx::setPitchWheelBendRange( int semitones )
{
for( int i = 0; i < NUM_MIDI_PARTS; ++i )
for (const auto& part : m_master->part)
{
m_master->part[i]->ctl.setpitchwheelbendrange( semitones * 100 );
part->ctl.setpitchwheelbendrange(semitones * 100);
}
}

View File

@@ -72,7 +72,7 @@ protected:
std::string m_presetsDir;
int m_runningNotes[NumKeys];
std::array<int, NumKeys> m_runningNotes = {};
Master * m_master;
NulEngine* m_ioEngine;