Selaa lähdekoodia

Initial work on C++ code generation

dds
PaulStoffregen 10 vuotta sitten
vanhempi
commit
7cb99cb9b9
2 muutettua tiedostoa jossa 64 lisäystä ja 4 poistoa
  1. +63
    -3
      gui/red/main.js
  2. +1
    -1
      gui/red/nodes.js

+ 63
- 3
gui/red/main.js Näytä tiedosto

event.preventDefault(); event.preventDefault();
}); });



function save(force) { function save(force) {
if (RED.view.dirty()) { if (RED.view.dirty()) {


} }
} }
var nns = RED.nodes.createCompleteNodeSet(); var nns = RED.nodes.createCompleteNodeSet();
// sort by horizontal position, plus slight vertical position,
// for well defined update order that follows signal flow
nns.sort(function(a,b){ return (a.x + a.y/250) - (b.x + b.y/250); });
console.log(JSON.stringify(nns));


var cpp = "";
// generate code for all audio processing nodes
for (var i=0; i<nns.length; i++) {
var n = nns[i];
var node = RED.nodes.node(n.id);
if (node && (node.outputs > 0 || node._def.inputs > 0)) {
cpp += n.type + " ";
for (var j=n.type.length; j<24; j++) cpp += " ";
cpp += n.id + "; ";
for (var j=n.id.length; j<14; j++) cpp += " ";
cpp += "//xy=" + n.x + "," + n.y + "\n";
}
//console.log("save: node " + n.id + " " + node.outputs);
}
// generate code for all connections (aka wires or links)
var cordcount = 1;
for (var i=0; i<nns.length; i++) {
var n = nns[i];
if (n.wires) {
for (var j=0; j<n.wires.length; j++) {
var wires = n.wires[j];
if (!wires) continue;
for (var k=0; k<wires.length; k++) {
var wire = n.wires[j][k];
if (wire) {
var parts = wire.split(":");
if (parts.length == 2) {
//console.log("save: wire " + n.id + ":" + j + " " + parts[0] + "-" + parts[1]);
cpp += "AudioConnection patchCord" + cordcount + "(";
var src = RED.nodes.node(n.id);
var dst = RED.nodes.node(parts[0]);
//console.log("save: src.outputs=" + src.outputs + ", dst._def.inputs=" + dst._def.inputs);
if (j == 0 && parts[1] == 0 && src && src.outputs == 1 && dst && dst._def.inputs == 1) {
cpp += n.id + ", " + parts[0];
} else {
cpp += n.id + ", " + j + ", " + parts[0] + ", " + parts[1];
}
cpp += ");\n";
cordcount++;
}
}
}
}
}
}
// generate code for all control nodes (no inputs or outputs)
for (var i=0; i<nns.length; i++) {
var n = nns[i];
var node = RED.nodes.node(n.id);
if (node && node.outputs == 0 && node._def.inputs == 0) {
cpp += n.type + " ";
for (var j=n.type.length; j<24; j++) cpp += " ";
cpp += n.id + "; ";
for (var j=n.id.length; j<14; j++) cpp += " ";
cpp += "//xy=" + n.x + "," + n.y + "\n";
}
}

console.log(cpp);
$("#btn-icn-deploy").removeClass('icon-upload'); $("#btn-icn-deploy").removeClass('icon-upload');
$("#btn-icn-deploy").addClass('spinner'); $("#btn-icn-deploy").addClass('spinner');
RED.view.dirty(false); RED.view.dirty(false);

console.log(JSON.stringify(nns));
$.ajax({ $.ajax({
url:"flows", url:"flows",

+ 1
- 1
gui/red/nodes.js Näytä tiedosto

var wires = links.filter(function(d){return d.source === n;}); var wires = links.filter(function(d){return d.source === n;});
for (var j=0;j<wires.length;j++) { for (var j=0;j<wires.length;j++) {
var w = wires[j]; var w = wires[j];
node.wires[w.sourcePort].push(w.target.id);
node.wires[w.sourcePort].push(w.target.id + ":" + w.targetPort);
} }
} }
return node; return node;

Loading…
Peruuta
Tallenna