private class Env { Step s => Envelope e => blackhole; // feed constant into env 1::second => e.duration; // set ramp time fun void target (float val) { e.target(val); } } public class Node { string id; Point pos; string inputIds[0]; Input inputs[0]; 0 => int output; Chubgraph ugen; //connect to the dac if output is on Gain graphOut; //should never be connected to the dac fun string tString() { return "id: " + id + " output: " + output + " pos: " +pos.tString()+ "\n"; } //initialize ugens outside fun void init(string nid, Point p, int op, Chubgraph u) { nid @=> id; p @=> pos; if(u != null) { u @=> ugen; ugen => graphOut; } if (op > 0) { doOutput(); } } fun void addEdge(DirectedEdge edge) { if (edge.inId == id) { //if the edge comes from this node graphOut => edge.edge; //connect our signal to the edge } if (edge.outId == id) { //if the edge goes to this node //store information about source location Input in; in.init(edge.inId, edge.edge, edge.inPos, pos); in @=> inputs[edge.inId]; inputIds << edge.inId; //connect in.inp => ugen; if(output > 0) doOutput(); } if (edge.inId != id && edge.outId != id) { cherr <= "adding an edge for no good reason. Node: " <= id <= " edge: " <= edge.tString() + "\n"; } } fun int hasInput(string id){ for (0 => int i; i < inputIds.cap(); i++){ if (inputIds[i] == id) { return i; } } return -1; } fun void removeEdge(DirectedEdge edge) { if (edge.inId == id) { //if the edge comes from this node graphOut =< edge.edge; //connect our signal to the edge } if (edge.outId == id) { //if the edge goes to this node //store information about source location hasInput(edge.inId) => int inputIndex; if(inputIndex > -1) { inputs[edge.inId].inp =< ugen; null @=> inputs[edge.inId].inp; //null @=> inputs[inputIndex]; should figure out how to delete an input "" => inputIds[inputIndex]; if(output > 0) doOutput(); } } if (edge.inId != id && edge.outId != id) { cherr <= "adding an edge for no good reason. Node: " <= id <= " edge: " <= edge.tString() + "\n"; } } fun void doOutput() { 1 => output; ugen => dac; for (0 => int i; i < inputIds.cap(); i++){ inputs[inputIds[i]].play(); } } fun void stopOutput(){ if (output == 1) { 0 => output; ugen =< dac; for (0 => int i; i < inputIds.cap(); i++){ inputs[inputIds[i]].stop(); } } } fun void sporkMove(Point po){ Env x; Env y; x.target(po.x); y.target(po.y); now + x.e.duration() + 1::ms => time later; while(now < later) { x.e.last() => pos.x; y.e.last() => pos.y; for (0 => int i; i < inputIds.cap(); i++){ inputs[inputIds[i]].containerMoved(pos); } 3::samp => now; } } fun void moveTo(Point nPos) { //nPos @=> pos; spork ~ sporkMove(nPos); } fun void sourceMoved(string sourceId, Point newPoint){ if (hasInput(sourceId) > -1) { inputs[sourceId].sourceMoved(newPoint); } } } private class Input { string id; DelEdge inp; Point absPos; Point relPos; DBAP4 output; fun void init(string tid, DelEdge edge, Point input, Point container) { input @=> absPos; edge @=> inp; tid => id; containerMoved(container); } fun void containerMoved(Point container) { absPos.x - container.x => relPos.x; absPos.y - container.y => relPos.y; output.setPosition(relPos.x, relPos.y); } fun void sourceMoved(Point newPoint){ newPoint.x => absPos.x; newPoint.y => absPos.y; } fun void play() { cherr <= tString() <= "playing"; inp => output; } fun void stop() { inp =< output; } fun string tString(){ return "Input distance: " +inp.dist+ "relative Position: ("+relPos.x+", "+relPos.y+")"; } } while(true) { 1::day => now; }