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 for-iterator loops with for-each loops and algorithm functions under libs/ #949

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
10 changes: 5 additions & 5 deletions libs/ardour/analysis_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ AnalysisGraph::analyze_range (std::shared_ptr<Route> route, std::shared_ptr<Audi
}
const samplecnt_t n_samples = _max_chunksize - (_max_chunksize % n_audio);

for (std::list<TimelineRange>::const_iterator j = range.begin(); j != range.end(); ++j) {
for (const TimelineRange& j : range) {

interleaver.reset (new Interleaver<Sample> ());
interleaver->init (n_audio, _max_chunksize);

chunker.reset (new Chunker<Sample> (n_samples));
analyser.reset (new Analyser (
_session->nominal_sample_rate(),
n_audio, n_samples, (*j).length_samples()));
n_audio, n_samples, j.length_samples()));

interleaver->add_output(chunker);
chunker->add_output (analyser);

samplecnt_t x = 0;
const samplecnt_t rlen = j->length().samples();
const samplepos_t rpos = j->start().samples();
const samplecnt_t rlen = j.length().samples();
const samplepos_t rpos = j.start().samples();

while (x < rlen) {
samplecnt_t chunk = std::min (_max_chunksize, rlen - x);
Expand Down Expand Up @@ -175,7 +175,7 @@ AnalysisGraph::analyze_range (std::shared_ptr<Route> route, std::shared_ptr<Audi
_session->nominal_sample_rate(),
100, false),
Timecode::timecode_format_sampletime (
(*j).end().samples(),
j.end().samples(),
_session->nominal_sample_rate(),
100, false)
);
Expand Down
4 changes: 2 additions & 2 deletions libs/ardour/ardour/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ class LIBARDOUR_API Session : public PBD::HistoryOwner,
PBD::Signal<void()> route_groups_reordered;

void foreach_route_group (std::function<void(RouteGroup*)> f) {
for (std::list<RouteGroup *>::iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) {
f (*i);
for (RouteGroup *& i : _route_groups) {
f (i);
}
}

Expand Down
9 changes: 4 additions & 5 deletions libs/ardour/audio_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ AudioLibrary::set_tags (string member, vector<string> tags)

lrdf_remove_uri_matches (file_uri.c_str());

for (vector<string>::iterator i = tags.begin(); i != tags.end(); ++i) {
lrdf_add_triple (src.c_str(), file_uri.c_str(), TAG, (*i).c_str(), lrdf_literal);
for (string& i : tags) {
lrdf_add_triple (src.c_str(), file_uri.c_str(), TAG, i.c_str(), lrdf_literal);
}
#endif
}
Expand Down Expand Up @@ -153,12 +153,11 @@ AudioLibrary::search_members_and (vector<string>& members, const vector<string>&
lrdf_statement* old = 0;
head = &pattern;

vector<string>::const_iterator i;
for (i = tags.begin(); i != tags.end(); ++i){
for (const string& i : tags) {
pattern = new lrdf_statement;
pattern->subject = const_cast<char*>("?");
pattern->predicate = const_cast<char*>(TAG);
pattern->object = strdup((*i).c_str());
pattern->object = strdup(i.c_str());
pattern->next = old;

old = pattern;
Expand Down
14 changes: 7 additions & 7 deletions libs/ardour/audio_region_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ AudioRegionImporter::prepare_region ()
prepare_sources();

// Create source list
for (std::list<string>::iterator it = filenames.begin(); it != filenames.end(); ++it) {
source_list.push_back (handler.get_source (*it));
for (string& it : filenames) {
source_list.push_back (handler.get_source (it));
}

// create region and update XML
Expand Down Expand Up @@ -344,9 +344,9 @@ AudioRegionImporter::prepare_sources ()
status.import_markers = false;

// Get sources that still need to be imported
for (std::list<string>::iterator it = filenames.begin(); it != filenames.end(); ++it) {
if (!handler.check_source (*it)) {
status.paths.push_back (*it);
for (string& it : filenames) {
if (!handler.check_source (it)) {
status.paths.push_back (it);
status.total++;
}
}
Expand Down Expand Up @@ -383,8 +383,8 @@ AudioRegionImporter::add_sources_to_session ()
return;
}

for (std::list<string>::iterator it = filenames.begin(); it != filenames.end(); ++it) {
session.add_source (handler.get_source (*it));
for (string& it : filenames) {
session.add_source (handler.get_source (it));
}
}

Expand Down
20 changes: 10 additions & 10 deletions libs/ardour/audio_track.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ AudioTrack::state (bool save_template) const
freeze_node->set_property ("playlist-id", _freeze_record.playlist->id().to_s ());
freeze_node->set_property ("state", _freeze_record.state);

for (vector<FreezeRecordProcessorInfo*>::const_iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
for (FreezeRecordProcessorInfo* const& i : _freeze_record.processor_info) {
inode = new XMLNode (X_("processor"));
inode->set_property (X_ ("id"), (*i)->id.to_s ());
inode->add_child_copy ((*i)->state);
inode->set_property (X_ ("id"), i->id.to_s ());
inode->add_child_copy (i->state);

freeze_node->add_child_nocopy (*inode);
}
Expand Down Expand Up @@ -145,8 +145,8 @@ AudioTrack::set_state_part_two ()

_freeze_record.state = Frozen;

for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
delete *i;
for (FreezeRecordProcessorInfo*& i : _freeze_record.processor_info) {
delete i;
}
_freeze_record.processor_info.clear ();

Expand Down Expand Up @@ -435,9 +435,9 @@ AudioTrack::unfreeze ()
{
Glib::Threads::RWLock::ReaderLock lm (_processor_lock); // should this be a write lock? jlc
for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
for (vector<FreezeRecordProcessorInfo*>::iterator ii = _freeze_record.processor_info.begin(); ii != _freeze_record.processor_info.end(); ++ii) {
if ((*ii)->id == (*i)->id()) {
(*i)->set_state (((*ii)->state), Stateful::current_state_version);
for (FreezeRecordProcessorInfo*& ii : _freeze_record.processor_info) {
if (ii->id == (*i)->id()) {
(*i)->set_state ((ii->state), Stateful::current_state_version);
break;
}
}
Expand All @@ -448,8 +448,8 @@ AudioTrack::unfreeze ()
/* XXX need to use _main_outs _panner->set_automation_state (_freeze_record.pan_automation_state); */
}

for (vector<FreezeRecordProcessorInfo*>::iterator ii = _freeze_record.processor_info.begin(); ii != _freeze_record.processor_info.end(); ++ii) {
delete *ii;
for (FreezeRecordProcessorInfo*& ii : _freeze_record.processor_info) {
delete ii;
}
_freeze_record.processor_info.clear ();

Expand Down
28 changes: 14 additions & 14 deletions libs/ardour/audio_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ AUPlugin::match_variable_io (ChanCount& in, ChanCount& aux_in, ChanCount& out)
if (DEBUG_ENABLED(DEBUG::AudioUnitConfig)) {
DEBUG_STR_DECL(a);
DEBUG_STR_APPEND(a, string_compose ("AU Initial I/O Config list for %1 n_cfg: %2, in-bus %4 out-bus: %5\n", name(), io_configs.size(), input_elements, output_elements));
for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
DEBUG_STR_APPEND(a, string_compose (" - I/O %1 / %2\n", i->first, i->second));
for (pair<int,int> & i : io_configs) {
DEBUG_STR_APPEND(a, string_compose (" - I/O %1 / %2\n", i.first, i.second));
}
DEBUG_TRACE (DEBUG::AudioUnitConfig, DEBUG_STR(a).str());
}
Expand All @@ -1161,9 +1161,9 @@ AUPlugin::match_variable_io (ChanCount& in, ChanCount& aux_in, ChanCount& out)
#endif
if (output_elements > 1) {
const vector<pair<int,int> >& ioc (pinfo->io_configs);
for (vector<pair<int,int> >::const_iterator i = ioc.begin(); i != ioc.end(); ++i) {
int32_t possible_in = i->first;
int32_t possible_out = i->second;
for (const pair<int,int> & i : ioc) {
int32_t possible_in = i.first;
int32_t possible_out = i.second;
if (possible_out < 0) {
continue;
}
Expand Down Expand Up @@ -1191,8 +1191,8 @@ AUPlugin::match_variable_io (ChanCount& in, ChanCount& aux_in, ChanCount& out)
if (DEBUG_ENABLED(DEBUG::AudioUnitConfig) && outs_added) {
DEBUG_STR_DECL(a);
DEBUG_STR_APPEND(a, string_compose ("AU Final I/O Config list for %1 n_cfg: %2\n", name(), io_configs.size()));
for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
DEBUG_STR_APPEND(a, string_compose (" - I/O %1 / %2\n", i->first, i->second));
for (pair<int,int> & i : io_configs) {
DEBUG_STR_APPEND(a, string_compose (" - I/O %1 / %2\n", i.first, i.second));
}
DEBUG_TRACE (DEBUG::AudioUnitConfig, DEBUG_STR(a).str());
}
Expand Down Expand Up @@ -1267,10 +1267,10 @@ AUPlugin::match_variable_io (ChanCount& in, ChanCount& aux_in, ChanCount& out)
} \
}

for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
for (pair<int,int> & i : io_configs) {

int32_t possible_in = i->first;
int32_t possible_out = i->second;
int32_t possible_in = i.first;
int32_t possible_out = i.second;

DEBUG_TRACE (DEBUG::AudioUnitConfig, string_compose ("\tpossible in %1 possible out %2\n", possible_in, possible_out));

Expand Down Expand Up @@ -2318,9 +2318,9 @@ AUPlugin::find_presets ()
DEBUG_TRACE (DEBUG::AudioUnitConfig, "AU No Preset Files found for given plugin.\n");
}

for (vector<string>::iterator x = preset_files.begin(); x != preset_files.end(); ++x) {
for (string& x : preset_files) {

string path = *x;
string path = x;
string preset_name;

/* make an initial guess at the preset name using the path */
Expand Down Expand Up @@ -2434,8 +2434,8 @@ AUPluginInfo::get_presets (bool user_only) const
vector<string> preset_files;
find_files_matching_filter (preset_files, preset_search_path, au_preset_filter, const_cast<AUPluginInfo*>(this), true, true, true);

for (vector<string>::iterator x = preset_files.begin(); x != preset_files.end(); ++x) {
string path = *x;
for (string& x : preset_files) {
string path = x;
string preset_name;
preset_name = Glib::path_get_basename (path);
preset_name = preset_name.substr (0, preset_name.find_last_of ('.'));
Expand Down
6 changes: 3 additions & 3 deletions libs/ardour/audioengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,13 +899,13 @@ AudioEngine::discover_backends ()

DEBUG_TRACE (DEBUG::AudioEngine, string_compose ("looking for backends in %1\n", backend_search_path().to_string()));

for (vector<std::string>::iterator i = backend_modules.begin(); i != backend_modules.end(); ++i) {
for (std::string& i : backend_modules) {

AudioBackendInfo* info;

DEBUG_TRACE (DEBUG::AudioEngine, string_compose ("Checking possible backend in %1\n", *i));
DEBUG_TRACE (DEBUG::AudioEngine, string_compose ("Checking possible backend in %1\n", i));

if ((info = backend_discover (*i)) != 0) {
if ((info = backend_discover (i)) != 0) {
_backends.insert (make_pair (info->name, info));
}
}
Expand Down
16 changes: 8 additions & 8 deletions libs/ardour/auv2_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ auv2_plugin_info (AudioComponent& comp, CAComponentDescription& desc, std::vecto
*/

const vector<pair<int,int> >& ioc (info.io_configs);
for (vector<pair<int,int> >::const_iterator i = ioc.begin(); i != ioc.end(); ++i) {
int32_t possible_out = i->second;
for (const pair<int,int> & i : ioc) {
int32_t possible_out = i.second;
if (possible_out < 0) {
continue;
} else if (possible_out > info.max_outputs) {
Expand Down Expand Up @@ -460,9 +460,9 @@ ARDOUR::auv2_scan_and_cache (CAComponentDescription& desc, std::function<void (C
delete root;
return false;
}
for (std::vector<AUv2Info>::const_iterator i = nfo.begin(); i != nfo.end(); ++i) {
cb (desc, *i);
root->add_child_nocopy (i->state ());
for (const AUv2Info& i : nfo) {
cb (desc, i);
root->add_child_nocopy (i.state ());
}
} catch (...) {
cerr << "Cannot load AudioUnit plugin: '" << auv2_stringify_descriptor (desc) << "'\n";
Expand Down Expand Up @@ -613,10 +613,10 @@ AUv2Info::state () const
node->set_property ("n_midi_outputs", n_midi_outputs);
node->set_property ("max_outputs", max_outputs);

for (vector<pair<int, int> >::const_iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
for (const pair<int, int> & i : io_configs) {
XMLNode* child = new XMLNode (X_("io_config"));
child->set_property (X_("in"), i->first);
child->set_property (X_("out"), i->second);
child->set_property (X_("in"), i.first);
child->set_property (X_("out"), i.second);
node->add_child_nocopy (*child);
}
return *node;
Expand Down
10 changes: 5 additions & 5 deletions libs/ardour/buffer_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ void
BufferSet::clear()
{
if (!_is_mirror) {
for (std::vector<BufferVec>::iterator i = _buffers.begin(); i != _buffers.end(); ++i) {
for (BufferVec::iterator j = (*i).begin(); j != (*i).end(); ++j) {
for (BufferVec& i : _buffers) {
for (BufferVec::iterator j = i.begin(); j != i.end(); ++j) {
delete *j;
}
(*i).clear();
i.clear();
}
}
_buffers.clear();
Expand Down Expand Up @@ -485,8 +485,8 @@ BufferSet::merge_from (const BufferSet& in, samplecnt_t nframes)
void
BufferSet::silence (samplecnt_t nframes, samplecnt_t offset)
{
for (std::vector<BufferVec>::iterator i = _buffers.begin(); i != _buffers.end(); ++i) {
for (BufferVec::iterator b = i->begin(); b != i->end(); ++b) {
for (BufferVec& i : _buffers) {
for (BufferVec::iterator b = i.begin(); b != i.end(); ++b) {
(*b)->silence (nframes, offset);
}
}
Expand Down
12 changes: 6 additions & 6 deletions libs/ardour/bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ Bundle::nchannels () const
Glib::Threads::Mutex::Lock lm (_channel_mutex);

ChanCount c;
for (vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
c.set (i->type, c.get (i->type) + 1);
for (const Channel& i : _channel) {
c.set (i.type, c.get (i.type) + 1);
}

return c;
Expand Down Expand Up @@ -240,8 +240,8 @@ Bundle::offers_port (std::string p) const
{
Glib::Threads::Mutex::Lock lm (_channel_mutex);

for (std::vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
for (PortList::const_iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
for (const Channel& i : _channel) {
for (PortList::const_iterator j = i.ports.begin(); j != i.ports.end(); ++j) {
if (*j == p) {
return true;
}
Expand All @@ -259,8 +259,8 @@ Bundle::offers_port_alone (std::string p) const
{
Glib::Threads::Mutex::Lock lm (_channel_mutex);

for (std::vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
if (i->ports.size() == 1 && i->ports[0] == p) {
for (const Channel& i : _channel) {
if (i.ports.size() == 1 && i.ports[0] == p) {
return true;
}
}
Expand Down
Loading