瀏覽代碼

Initial work on C++ code generation

dds
PaulStoffregen 10 年之前
父節點
當前提交
7cb99cb9b9
共有 2 個檔案被更改,包括 64 行新增4 行删除
  1. +63
    -3
      gui/red/main.js
  2. +1
    -1
      gui/red/nodes.js

+ 63
- 3
gui/red/main.js 查看文件

@@ -45,7 +45,6 @@ var RED = (function() {
event.preventDefault();
});


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

@@ -76,13 +75,74 @@ var RED = (function() {
}
}
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").addClass('spinner');
RED.view.dirty(false);

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

+ 1
- 1
gui/red/nodes.js 查看文件

@@ -247,7 +247,7 @@ RED.nodes = (function() {
var wires = links.filter(function(d){return d.source === n;});
for (var j=0;j<wires.length;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;

Loading…
取消
儲存