and finally, ref-ify all the range-fors

master
Zithia Satazaki 2022-03-28 17:45:13 -04:00
parent 042e13eefb
commit 5f1b9d03b4
7 changed files with 25 additions and 25 deletions

View File

@ -44,7 +44,7 @@ void Graph::saveData(QCborMap& m) const {
QCborArray c;
int idx = 0;
for (auto ch : children) {
for (auto& ch : children) {
if (!ch->plugin) continue;
indices[ch.get()] = idx++;
c << ch->toCbor();
@ -58,14 +58,14 @@ void Graph::saveData(QCborMap& m) const {
// array { oIdx, dataType, pIdx, iIdx, dataType, pIdx }
QCborArray cn;
for (auto ch : children) {
for (auto& ch : children) {
if (!ch->plugin) continue; // already skipped over
int idx = indices[ch.get()];
for (auto dt : ch->outputs) {
for (auto op : dt.second) {
for (auto& dt : ch->outputs) {
for (auto& op : dt.second) {
auto o = op.second;
o->cleanConnections(); // let's just do some groundskeeping here
for (auto iw : o->connections) {
for (auto& iw : o->connections) {
auto i = iw.lock();
QCborArray c;
c << idx;

View File

@ -48,7 +48,7 @@ bool Port::connect(std::shared_ptr<Port> p) {
// actual processing is always done on the input port, since that's where any limits are
if (type == Output) return p->type == Input && p->connect(shared_from_this());
if (!canConnectTo(p->dataType())) return false; // can't hook up to an incompatible data type
for (auto c : connections) if (c.lock() == p) return true; // I guess report success if already connected?
for (auto& c : connections) if (c.lock() == p) return true; // I guess report success if already connected?
if (singleInput() && connections.size() > 0) return false; // reject multiple connections on single-input ports
if (auto o = owner.lock(), po = p->owner.lock(); !o || !po || po->dependsOn(o)) return false; // no dependency loops!
// actually hook up
@ -118,7 +118,7 @@ QCborMap Node::multiToCbor(std::vector<std::shared_ptr<Node>>& v) {
{ /* nodes */ } {
QCborArray nm;
int idx = 0;
for (auto n : v) {
for (auto& n : v) {
if (n->isVolatile()) continue; // skip things with volatile locality (i/o ports etc.)
indices[n.get()] = idx++;
nm << n->toCbor();
@ -129,21 +129,21 @@ QCborMap Node::multiToCbor(std::vector<std::shared_ptr<Node>>& v) {
// exported samples
if (auto v = Sample::finishExport(); !v.empty()) {
QCborMap smp;
for (auto s : v) smp[QCborValue(s->uuid)] = s->toCbor();
for (auto& s : v) smp[QCborValue(s->uuid)] = s->toCbor();
m[qs("samples")] = smp;
}
{ /* connections */ } {
QCborArray cm;
for (auto n : v) {
for (auto& n : v) {
if (n->isVolatile()) continue; // already skipped
int idx = indices[n.get()];
for (auto dt : n->outputs) {
for (auto op : dt.second) {
for (auto& dt : n->outputs) {
for (auto& op : dt.second) {
auto o = op.second;
o->cleanConnections(); // let's just do some groundskeeping here
for (auto iw : o->connections) {
for (auto& iw : o->connections) {
auto i = iw.lock();
if (auto in = indices.find(i->owner.lock().get()); in != indices.end()) { // only connections within the collection
QCborArray c;
@ -166,7 +166,7 @@ QCborMap Node::multiToCbor(std::vector<std::shared_ptr<Node>>& v) {
{ /* center */ } {
int count = 0;
QPoint center;
for (auto n : v) {
for (auto& n : v) {
if (n->isVolatile()) continue;
center += QPoint(n->x, n->y);
count++;
@ -227,7 +227,7 @@ std::vector<std::shared_ptr<Node>> Node::multiFromCbor(const QCborMap& m, std::s
if (!cp.isNull()) { // offset and such
QPoint off = cp - center;
for (auto n : v) {
for (auto& n : v) {
n->x += off.x();
n->y += off.y();
}
@ -305,7 +305,7 @@ void Node::collapsePorts(Port::Type t, Port::DataType dt) {
if (mdt == m.end()) return; // nothing there
auto& mm = mdt->second;
uint8_t maxIdx = 0;
for (auto p : mm) maxIdx = std::max(maxIdx, p.first);
for (auto& p : mm) maxIdx = std::max(maxIdx, p.first);
uint8_t firstUnused = 255;
for (uint8_t i = 0; i <= maxIdx; i++) {
if (auto pi = mm.find(i); pi != mm.end()) {
@ -347,7 +347,7 @@ bool Node::try_process(bool checkDependencies) {
if (checkDependencies) { // check if dependencies are done
auto checkInput = Util::yCombinator([tick_this](auto checkInput, std::shared_ptr<Port> p) -> bool {
for (auto c : p->connections) { // check each connection; if node valid...
for (auto& c : p->connections) { // check each connection; if node valid...
if (auto cp = c.lock(); cp) {
if (auto n = cp->owner.lock(); n) {
if (n->tick_last != tick_this) return false; // if node itself not yet processed, check failed
@ -363,7 +363,7 @@ bool Node::try_process(bool checkDependencies) {
return true;
});
for (auto t : inputs) for (auto p : t.second) if (!checkInput(p.second)) return false;
for (auto& t : inputs) for (auto& p : t.second) if (!checkInput(p.second)) return false;
/*for (auto& t : inputs) {
for (auto& p : t.second) {

View File

@ -30,7 +30,7 @@ void AudioPort::pull() {
bufR = &bufL[ts]; // for some reason just adding the size wonks out
memset(bufL, 0, s*2); // clear buffers
for (auto c : connections) { // mix
for (auto& c : connections) { // mix
if (auto p = std::static_pointer_cast<AudioPort>(c.lock()); p && p->dataType() == Audio) {
p->pull();
for (size_t i = 0; i < ts; i++) {
@ -62,7 +62,7 @@ void CommandPort::pull() {
size = 0;
if (type == Input) {
for (auto c : connections) {
for (auto& c : connections) {
if (auto p = std::static_pointer_cast<CommandPort>(c.lock()); p && p->dataType() == Command) {
p->pull();
data = p->data; // just repoint to input's buffer

View File

@ -138,7 +138,7 @@ void SampleSelectorGadget::mousePressEvent(QGraphicsSceneMouseEvent* e) {
m->addAction("(no sample)", this, [this] { setSample(nullptr); });
m->addSeparator();
DirectoryNode root;
for (auto s : qAsConst(project->samples)) root.placeData(s->name, s->uuid);
for (auto& s : qAsConst(project->samples)) root.placeData(s->name, s->uuid);
root.sortTree();
buildSubmenu(&root, m);

View File

@ -57,7 +57,7 @@ void SelectorGadget::mousePressEvent(QGraphicsSceneMouseEvent* e) {
std::vector<Entry> v = fGetList ? fGetList() : std::vector<Entry>();
if (v.empty()) m->addAction("(no entries)")->setDisabled(true);
else {
for (auto e : v) {
for (auto& e : v) {
if (_entry.first == e.first) {
m->addAction(e.second)->setDisabled(true);
} else m->addAction(e.second, this, [this, e] {

View File

@ -115,7 +115,7 @@ PatchboardScene::PatchboardScene(QGraphicsView* parent, const std::shared_ptr<Xy
auto v = Node::multiFromCbor(QCborValue::fromCbor(data->data("xybrid-internal/x-graph-copy")), graph, center);
setSelectionArea(QPainterPath()); // deselect all
for (auto n : v) { // and select pasted objects
for (auto& n : v) { // and select pasted objects
auto o = new NodeObject(n);
addItem(o);
o->setSelected(true);
@ -225,7 +225,7 @@ void PatchboardScene::refresh() {
// build scene from graph
clear();
for (auto n : graph->children) {
for (auto& n : graph->children) {
auto* o = new NodeObject(n);
addItem(o);
}

View File

@ -99,7 +99,7 @@ void SampleListModel::refresh() {
root = std::make_shared<DirectoryNode>();
auto* project = window->getProject().get();
if (!project) return;
for (auto s : qAsConst(project->samples)) root->placeData(s->name, s->uuid);
for (auto& s : qAsConst(project->samples)) root->placeData(s->name, s->uuid);
root->sortTree();
view->setCurrentIndex(QModelIndex());
@ -237,7 +237,7 @@ bool SampleListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
QList<QUrl> urls = data->urls();
bool success = false;
for (auto u : urls) {
for (auto& u : urls) {
if (!u.isLocalFile()) continue;
auto smp = Sample::fromFile(u.toLocalFile());
if (smp) { // valid sample returned