Add files via upload
parent
cb85c56866
commit
7451954867
Binary file not shown.
@ -0,0 +1,135 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:bfe399c4bdb7ac4ba9372d224adaf9ea707649999c1740acf1e4006f2c9b7207"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
"worksheets": [
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"from music21 import *\n",
|
||||
"import random\n",
|
||||
"from scipy.stats import rv_discrete\n",
|
||||
"from OSC import OSCClient, OSCMessage"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# set up OSC client\n",
|
||||
"client = OSCClient()\n",
|
||||
"client.connect(('127.0.0.1', 57120))\n",
|
||||
"\n",
|
||||
"def play_sc(stream, streamName, durScale):\n",
|
||||
" pBinds = []\n",
|
||||
" for p in range(len(stream)):\n",
|
||||
" part = stream[p].getElementsByClass(note.Note).flat.elements\n",
|
||||
" freqs = [0] + [e.pitch.frequency for e in part]\n",
|
||||
" durs = [stream[p].getElementsByClass(note.Note).flat[0].offset] + [e.duration.quarterLength * durScale for e in part]\n",
|
||||
" pBinds.append('PBind'+str(p))\n",
|
||||
" client.send( OSCMessage('/ins', [pBinds[p],'instrument','difference']))\n",
|
||||
" client.send( OSCMessage('/bind', [pBinds[p],'freq',freqs]))\n",
|
||||
" client.send( OSCMessage('/bind', [pBinds[p],'dur',durs]))\n",
|
||||
" client.send( OSCMessage('/playPPar', [streamName, pBinds]))\n",
|
||||
" \n",
|
||||
"def stop_sc(streamName):\n",
|
||||
" client.send( OSCMessage('/stopPPar', streamName))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"tune = corpus.parse('bach/bwv40.8')\n",
|
||||
"tune.parts"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 4,
|
||||
"text": [
|
||||
"<music21.stream.Stream 140075135751376>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 4
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"s = stream.Stream()\n",
|
||||
"l = tune.duration.quarterLength\n",
|
||||
"t = 0\n",
|
||||
"mult = 0\n",
|
||||
"for part in tune.parts:\n",
|
||||
" p1 = stream.Part()\n",
|
||||
" p2 = stream.Part()\n",
|
||||
" for n in part.flat.notes:\n",
|
||||
" r1 = pitch.Pitch()\n",
|
||||
" r2 = pitch.Pitch()\n",
|
||||
" f = n.pitch.frequency\n",
|
||||
" #print f\n",
|
||||
" r1.frequency = 3000\n",
|
||||
" r2.frequency = r1.frequency - f\n",
|
||||
" d = n.quarterLength\n",
|
||||
" if n.isRest:\n",
|
||||
" p1.append(note.Rest(quarterLength = d))\n",
|
||||
" p2.append(note.Rest(quarterLength = d))\n",
|
||||
" else:\n",
|
||||
" p1.append(note.Note(r1, quarterLength = d))\n",
|
||||
" p2.append(note.Note(r2, quarterLength = d))\n",
|
||||
" t += d\n",
|
||||
" s.append(p1)\n",
|
||||
" s.append(p2)\n",
|
||||
" mult = mult + 1"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 5
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"play_sc(s[:], \"s\", 1)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"stop_sc(\"s\")"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 7
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
(
|
||||
~oscListeners.do({ arg item, i; ~oscListeners[i].free});
|
||||
~oscListeners = List.new;
|
||||
|
||||
~streams.do({ arg item, i; ~oscListeners[i].stop});
|
||||
~streams = Dictionary.new;
|
||||
|
||||
~oscListeners.add(
|
||||
OSCFunc({ |msg, time, addr |
|
||||
msg.postln;
|
||||
Pbindef(msg[1].asSymbol, msg[2].asSymbol,Pseq(msg[3..]));
|
||||
Pbindef('PBind0','\bufnum',e.bufnum);
|
||||
}, '/bind' );
|
||||
);
|
||||
~oscListeners.add(
|
||||
OSCFunc({ |msg, time, addr |
|
||||
msg.postln;
|
||||
Pbindef(msg[1].asSymbol,'instrument',msg[3].asSymbol);
|
||||
Pbindef(msg[1].asSymbol,'\bufnum',e.bufnum);
|
||||
}, '/ins' );
|
||||
);
|
||||
~oscListeners.add(
|
||||
OSCFunc({ |msg, time, addr |
|
||||
msg.postln;
|
||||
Pbindef(msg[1].asSymbol).playOnce;
|
||||
}, '/playPBind' );
|
||||
);
|
||||
~oscListeners.add(
|
||||
OSCFunc({ |msg, time, addr |
|
||||
msg.postln;
|
||||
(all {: m.asSymbol, m <- msg[2..] }).postln;
|
||||
~streams.put(msg[1], Ppar(all {: Pdef(m.asSymbol), m <- msg[2..] }).play);
|
||||
}, '/playPPar' );
|
||||
);
|
||||
~oscListeners.add(
|
||||
OSCFunc({ |msg, time, addr |
|
||||
msg.postln;
|
||||
~streams.at(msg[1]).stop;
|
||||
}, '/stopPPar' );
|
||||
);
|
||||
)
|
||||
|
||||
(
|
||||
e = Buffer.alloc(s, 512, 1);
|
||||
e.sine1(1.0, true, true, true);
|
||||
|
||||
SynthDef(\difference, { |dur = 1, outbus = 0, bufnum = 0, freq = 440, amp = 1, gate = 1|
|
||||
var out;
|
||||
out = EnvGen.ar(Env.adsr(sustainLevel:1), gate, doneAction: 2) * amp * Osc.ar(e.bufnum, freq, 0, 1, 0);
|
||||
Out.ar(outbus, out ! 2);
|
||||
}).add;
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
(
|
||||
a = Buffer.read(s, "/home/mwinter/room_ambience.wav"); //buffer of recording of the ambient noise; replace accordingly
|
||||
)
|
||||
|
||||
|
||||
(
|
||||
SynthDef("help-Select",{ arg out=0;
|
||||
Out.ar([0,1], Clip.ar(PlayBuf.ar(1, a, 1) * pow(Line.ar(0,1, 60 * 3.5, doneAction: 2), 3) * 2000, 0, 1));
|
||||
}).play;
|
||||
)
|
@ -0,0 +1,132 @@
|
||||
/*The field recordings are hardcoded such that buffers a and b are the drone and c and d are the birds.
|
||||
This should eventually change to pointing to folders but that would require a rework of the GUI.
|
||||
Also, I have been performing the fade manually hence the code for the automated fade being commented out.
|
||||
*/
|
||||
(
|
||||
a = Buffer.read(s, "/home/mwinter/Portfolio/fade_and_aviary/harmonium_fifth_final_norm_mono.wav");
|
||||
b = Buffer.read(s, "/home/mwinter/Portfolio/fade_and_aviary/gong_final_norm_mono.wav");
|
||||
c = Buffer.read(s, "/home/mwinter/Portfolio/fade_and_aviary/birds_wulf_norm_mono.wav");
|
||||
d = Buffer.read(s, "/home/mwinter/Portfolio/fade_and_aviary/birds_norm_mono.wav");
|
||||
)
|
||||
(
|
||||
w = 100;
|
||||
l = 30;
|
||||
m = 5;
|
||||
f = Array.fill(l, { arg i; (i + 1) * w });
|
||||
q = w/f;
|
||||
SynthDef("switch", {
|
||||
arg out=0, soundBufnum1=0, soundBufnum2 = 1, soundBufnum3 = 2, soundBufnum4 = 3, att = 0.1, rel = 0.01, dust = 0.5, prob = 0.7,
|
||||
ctlin = #[0,0,0,0,0,0,0,0,0,0];
|
||||
var fadeOut, fadeIn,
|
||||
soundInA, soundInB,
|
||||
inA, inB, inC, inD,
|
||||
filtA, filtB,
|
||||
trig, res,
|
||||
gTrigA, gTrigB,
|
||||
grainA, grainB,
|
||||
imp, delimp;
|
||||
|
||||
fadeOut = Line.ar(1, 0, m * 60);
|
||||
fadeIn = Line.ar(0, 0.75, 10);
|
||||
Poll.ar(Impulse.ar(1), fadeOut, \fade);
|
||||
Poll.ar(Impulse.ar(1), BufFrames.ir(soundBufnum3) - (BufSampleRate.ir(soundBufnum3) * 60 * m), \start);
|
||||
|
||||
//inA = PlayBuf.ar(1, soundBufnum1, BufRateScale.kr(soundBufnum1), loop: 1) * fadeOut;
|
||||
gTrigA = Dust.kr(2);
|
||||
grainA = GrainBuf.ar(1, gTrigA, TRand.kr(4, 8, gTrigA), soundBufnum1) /** fadeOut*/;
|
||||
soundInA = SoundIn.ar(0);
|
||||
|
||||
//inB = PlayBuf.ar(1, soundBufnum2, BufRateScale.kr(soundBufnum2), loop: 1) * fadeOut;
|
||||
gTrigB = Dust.kr(2);
|
||||
grainB = GrainBuf.ar(1, gTrigB, TRand.kr(4, 8, gTrigB), soundBufnum2) /** fadeOut*/;
|
||||
soundInB = SoundIn.ar(1);
|
||||
|
||||
inA = (grainA * ctlin[0]) + (soundInA * ctlin[2]);
|
||||
inB = (grainB * ctlin[1]) + (soundInB * ctlin[3]);
|
||||
inC = PlayBuf.ar(1, soundBufnum3, BufRateScale.kr(soundBufnum3),
|
||||
startPos: BufFrames.kr(soundBufnum3) - (BufSampleRate.kr(soundBufnum3) * 60 * (m + 1.5)), loop: 1) * ctlin[4] * fadeIn * 10;
|
||||
inD = PlayBuf.ar(1, soundBufnum4, BufRateScale.kr(soundBufnum3)) * ctlin[4] * fadeIn * 8;
|
||||
|
||||
filtA = BPF.ar(inA, f, q);
|
||||
filtB = BPF.ar(inB, f, q);
|
||||
|
||||
trig = { Dust.ar(dust) } ! l;
|
||||
res = {|i| Lag.ar(LeakDC.ar(Select.ar(TRand.ar(0, 1, trig[i]) > prob, [Normalizer.ar(filtA[i], Amplitude.ar(inA), 0.1), filtB[i]]), 1), 0.001)} ! l;
|
||||
res = Mix.new(res);
|
||||
res = Lag.ar(LeakDC.ar(Select.ar((Amplitude.ar(inC, att, rel) < Amplitude.ar(res, att, rel)), [(inC + inD) * 2, Normalizer.ar(res, 0.5, 0.1)])), 0.001);
|
||||
|
||||
Out.ar([0, 1],
|
||||
(
|
||||
(grainA * ctlin[5]) +
|
||||
(grainB * ctlin[6]) +
|
||||
|
||||
(soundInA * ctlin[7]) +
|
||||
(soundInB * ctlin[8]) +
|
||||
|
||||
(res * ctlin[9])
|
||||
) * fadeIn
|
||||
);
|
||||
|
||||
|
||||
imp = Impulse.kr(10);
|
||||
delimp = Delay1.kr(imp);
|
||||
|
||||
SendReply.kr(imp,
|
||||
'/levels',
|
||||
values: [
|
||||
//ins
|
||||
|
||||
[Amplitude.kr(grainA * ctlin[0]), K2A.ar(Peak.ar(grainA * ctlin[0], delimp).lag(0, 3))],
|
||||
[Amplitude.kr(grainB * ctlin[1]), K2A.ar(Peak.ar(grainB * ctlin[1], delimp).lag(0, 3))],
|
||||
|
||||
[Amplitude.kr(soundInA * ctlin[2]), K2A.ar(Peak.ar(soundInA * ctlin[2], delimp).lag(0, 3))],
|
||||
[Amplitude.kr(soundInB * ctlin[3]), K2A.ar(Peak.ar(soundInB * ctlin[3], delimp).lag(0, 3))],
|
||||
|
||||
[Amplitude.kr(inC), K2A.ar(Peak.ar(inC, delimp).lag(0, 3))],
|
||||
|
||||
//outs
|
||||
[Amplitude.kr(grainA * ctlin[5]), K2A.ar(Peak.ar(grainA * ctlin[5], delimp).lag(0, 3))],
|
||||
[Amplitude.kr(grainB * ctlin[6]), K2A.ar(Peak.ar(grainB * ctlin[6], delimp).lag(0, 3))],
|
||||
|
||||
[Amplitude.kr(soundInA * ctlin[7]), K2A.ar(Peak.ar(soundInA * ctlin[7], delimp).lag(0, 3))],
|
||||
[Amplitude.kr(soundInB * ctlin[8]), K2A.ar(Peak.ar(soundInB * ctlin[8], delimp).lag(0, 3))],
|
||||
|
||||
[Amplitude.kr(res * ctlin[9]), K2A.ar(Peak.ar(res * ctlin[9], delimp).lag(0, 3))]
|
||||
],
|
||||
replyID: [1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909]
|
||||
);
|
||||
|
||||
}).add;
|
||||
)
|
||||
(
|
||||
var synth, win,
|
||||
levels, levelIndicators,
|
||||
grainAInLevels, grainBInLevels, soundInALevels, soundInBLevels,
|
||||
grainAOutLevels, grainBOutLevels, soundOutALevels, soundOutBLevels, resOutLevels;
|
||||
synth = Synth("switch", [\soundBufnum1, a.bufnum, \soundBufnum2, b.bufnum, \soundBufnum3, c.bufnum, \soundBufnum4, d.bufnum]);
|
||||
|
||||
win = Window.new("fade and aviary", Rect(128, 64, 350, 600));
|
||||
win.view.decorator = FlowLayout(win.view.bounds);
|
||||
win.view.decorator.gap=2@2;
|
||||
|
||||
levels = [0,0,0,0,0,0,0,0,0,0];
|
||||
levelIndicators = {|i|
|
||||
var lI;
|
||||
EZSlider(win, 40 @ 250, "", ControlSpec(0, 1, \lin, 0, 0),
|
||||
{|v| levels[i] = v.value; synth.set("ctlin", levels )}, layout: 'vert');
|
||||
lI = LevelIndicator(win, Rect(10, 10, 20, 250));
|
||||
lI} ! 10;
|
||||
|
||||
EZSlider(win, 350 @ 40, "dust freq ", ControlSpec(0.5, 3, \lin, 0, 0.5), {|v| synth.set("dust", v.value )});
|
||||
EZSlider(win, 350 @ 40, "spec prob ", ControlSpec(0.1, 0.7, \lin, 0, 0.7), {|v| synth.set("prob", v.value )});
|
||||
|
||||
o = OSCFunc({arg msg;
|
||||
{
|
||||
levelIndicators[msg[2]-1900].value = msg[3].ampdb.linlin(-40, 0, 0, 1);
|
||||
levelIndicators[msg[2]-1900].peakLevel = msg[4].ampdb.linlin(-40, 0, 0, 1);
|
||||
}.defer;
|
||||
}, '/levels', s.addr);
|
||||
|
||||
|
||||
win.front;
|
||||
)
|
@ -0,0 +1,34 @@
|
||||
class Allocator
|
||||
{
|
||||
|
||||
ArrayList<Integer> indices = new ArrayList<Integer>();
|
||||
int initIndex = 0;
|
||||
|
||||
Allocator(int initIndex){
|
||||
this.initIndex = initIndex;
|
||||
for(int i = 0; i < 2056; i++){
|
||||
indices.add(-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int getNextAvailableIndex(){
|
||||
println("here");
|
||||
int i = initIndex;
|
||||
while(indices.get(i - initIndex) != -1){
|
||||
i++;
|
||||
}
|
||||
// println("-**-");
|
||||
// println("----");
|
||||
println(i);
|
||||
// println("----");
|
||||
// println("-**-");
|
||||
indices.set(i - initIndex, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
void freeIndex(int i){
|
||||
println("free " + i );
|
||||
indices.set(i - initIndex, -1);
|
||||
}
|
||||
}
|
@ -0,0 +1,472 @@
|
||||
import processing.opengl.*;
|
||||
import supercollider.*;
|
||||
import oscP5.*;
|
||||
import netP5.*;
|
||||
|
||||
// does removing this input fucking anything else up?
|
||||
//import java.awt.event.*;
|
||||
|
||||
ArrayList<Edge> edges = new ArrayList<Edge>();
|
||||
ArrayList<Vertex> vertices = new ArrayList<Vertex>();
|
||||
ArrayList<Vertex> path = new ArrayList<Vertex>();
|
||||
String data = "";
|
||||
ArrayList<String> synthDefNames = new ArrayList<String>();
|
||||
Group feedbackGroup;
|
||||
Group sourceGroup;
|
||||
Group inputGroup;
|
||||
Group edgeGroup;
|
||||
Group outputGroup;
|
||||
//int windowX = 1280;
|
||||
//int windowY = 720;
|
||||
int windowX = 1050;
|
||||
int windowY = 1050;
|
||||
String tool = "edit";
|
||||
int delayControlMult = 1;
|
||||
|
||||
OscP5 queryTreeOsc;
|
||||
|
||||
Allocator busAllocator = new Allocator(64);
|
||||
Allocator bufferAllocator = new Allocator(0);
|
||||
|
||||
void setup() {
|
||||
|
||||
// needed for old mousewheel version
|
||||
// addMouseWheelListener(new MouseWheelListener() {
|
||||
// public void mouseWheelMoved(MouseWheelEvent mwe) {
|
||||
// mouseWheel(mwe.getWheelRotation());
|
||||
// }});
|
||||
|
||||
Server.local.default_group.freeAll();
|
||||
|
||||
feedbackGroup = new Group();
|
||||
sourceGroup = new Group();
|
||||
inputGroup = new Group();
|
||||
edgeGroup = new Group();
|
||||
outputGroup = new Group();
|
||||
|
||||
feedbackGroup.addToTail();
|
||||
sourceGroup.addToTail();
|
||||
inputGroup.addToTail();
|
||||
edgeGroup.addToTail();
|
||||
outputGroup.addToTail();
|
||||
|
||||
size(windowX, windowY, OPENGL);
|
||||
|
||||
queryTreeOsc = new OscP5(this, 57151);
|
||||
queryTreeOsc.properties().setSRSP(OscProperties.ON);
|
||||
|
||||
synthDefNames.add("none");
|
||||
|
||||
}
|
||||
|
||||
void exit(){
|
||||
Server.local.default_group.freeAll();
|
||||
}
|
||||
|
||||
void oscEvent(OscMessage msg) {
|
||||
for(int i = 0; i < msg.typetag().length(); i++){
|
||||
String val = msg.get(i).stringValue();
|
||||
synthDefNames.add(val);
|
||||
println(val);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
background(0);
|
||||
noStroke();
|
||||
|
||||
fill(0, 51, 102);
|
||||
ambientLight(102, 102, 102);
|
||||
lightSpecular(204, 204, 204);
|
||||
directionalLight(102, 102, 102, 0, 0, -1);
|
||||
specular(255, 255, 255);
|
||||
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
vertices.get(i).display();
|
||||
}
|
||||
|
||||
for (int i = 0; i < edges.size(); i++) {
|
||||
edges.get(i).display();
|
||||
}
|
||||
|
||||
updateDataDisplay();
|
||||
//text(data, 15, 30);
|
||||
|
||||
//text((synthDefNames), windowX - 115, 30);
|
||||
textSize(20);
|
||||
text(data, 15, 200);
|
||||
text(getFormattedSynthDefNames(synthDefNames), windowX - 200, 200);
|
||||
|
||||
if(mouseX < 50) {
|
||||
cursor(CROSS);
|
||||
} else {
|
||||
cursor(HAND);
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
|
||||
Vertex mouseOverVertex = getMouseOverVertex();
|
||||
|
||||
if(mouseOverVertex == null && keyCode == SHIFT && keyPressed && tool == "edit"){
|
||||
Vertex vertex = new Vertex(mouseX, mouseY, busAllocator);
|
||||
vertex.startFeedbackSynth(feedbackGroup);
|
||||
vertex.setSelected(true);
|
||||
vertices.add(vertex);
|
||||
} else if(mouseOverVertex != null && keyCode == SHIFT && keyPressed && tool == "edit"){
|
||||
removeVertex(mouseOverVertex);
|
||||
} else if(mouseOverVertex != null){
|
||||
if(mouseOverVertex.isSelected()){
|
||||
mouseOverVertex.setSelected(false);
|
||||
} else {
|
||||
mouseOverVertex.setSelected(true);
|
||||
}
|
||||
} else if(tool == "path"){
|
||||
for(int i = 0; i < vertices.size(); i++) {
|
||||
vertices.get(i).setSelected(false);
|
||||
}
|
||||
path = new ArrayList<Vertex>();
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
if(tool == "path" && keyCode != SHIFT){
|
||||
for(int i = 0; i < vertices.size(); i++) {
|
||||
vertices.get(i).setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mouseMoved() {
|
||||
}
|
||||
|
||||
void mouseDragged(){
|
||||
Vertex mouseOverVertex = getMouseOverVertex();
|
||||
if(tool == "move"){
|
||||
ArrayList<Vertex> selectedVertices = getSelectedVertices();
|
||||
for(int i = 0; i < selectedVertices.size(); i++){
|
||||
PVector mouseVector = new PVector(mouseX, mouseY);
|
||||
PVector lastMouseVector = new PVector(pmouseX, pmouseY);
|
||||
selectedVertices.get(i).add(PVector.sub(mouseVector, lastMouseVector));
|
||||
}
|
||||
} else if(tool == "path" && !keyPressed){
|
||||
if(path.size() == 0 && mouseOverVertex != null){
|
||||
mouseOverVertex.setSelected(true);
|
||||
path.add(mouseOverVertex);
|
||||
} else if (mouseOverVertex != null) {
|
||||
mouseOverVertex.setSelected(true);
|
||||
path.add(mouseOverVertex);
|
||||
Vertex outVertex = path.get(path.size()-2);
|
||||
Vertex inVertex = path.get(path.size()-1);
|
||||
Edge edge = new Edge(outVertex, inVertex, bufferAllocator);
|
||||
if(outVertex != inVertex && !edges.contains(edge)){
|
||||
edge.startSynth(edgeGroup);
|
||||
edges.add(edge);
|
||||
}
|
||||
}
|
||||
} else if(tool == "path" && keyPressed && key == CODED && keyCode == SHIFT){
|
||||
if(path.size() == 0 && mouseOverVertex != null){
|
||||
mouseOverVertex.setSelected(true);
|
||||
path.add(mouseOverVertex);
|
||||
} else if (mouseOverVertex != null){
|
||||
mouseOverVertex.setSelected(true);
|
||||
path.add(mouseOverVertex);
|
||||
Vertex outVertex = path.get(path.size()-2);
|
||||
Vertex inVertex = path.get(path.size()-1);
|
||||
Edge edge = new Edge(outVertex, inVertex, bufferAllocator);
|
||||
if(outVertex != inVertex && edges.contains(edge)){
|
||||
edge = edges.get(edges.indexOf(edge));
|
||||
edge.stopSynth();
|
||||
edges.remove(edge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed(){
|
||||
|
||||
Vertex mouseOverVertex = getMouseOverVertex();
|
||||
ArrayList<Vertex> selectedVertices = getSelectedVertices();
|
||||
|
||||
if (key == 'p'){
|
||||
tool = "path";
|
||||
} else if (key == 'e'){
|
||||
tool = "edit";
|
||||
} else if (key == 'm'){
|
||||
tool = "move";
|
||||
} else if (key == 'g'){
|
||||
tool = "global";
|
||||
} else if (key == 'c'){
|
||||
for(int i = 0; i < selectedVertices.size(); i++) {
|
||||
for(int j = 0; j < selectedVertices.size(); j++) {
|
||||
Edge edge = new Edge(selectedVertices.get(i), selectedVertices.get(j), bufferAllocator);
|
||||
if(i != j && !edges.contains(edge)){
|
||||
edge.startSynth(edgeGroup);
|
||||
edges.add(edge);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(key == 'd'){
|
||||
for(int i = 0; i < vertices.size(); i++) {
|
||||
vertices.get(i).setSelected(false);
|
||||
}
|
||||
} else if(key == 'a'){
|
||||
for(int i = 0; i < vertices.size(); i++) {
|
||||
vertices.get(i).setSelected(true);
|
||||
}
|
||||
} else if(key == '-'){
|
||||
delayControlMult = constrain(delayControlMult - 1, 1, 10);
|
||||
} else if(key == '='){
|
||||
delayControlMult = constrain(delayControlMult + 1, 1, 10);
|
||||
} else if(key == 'i'){
|
||||
saveFrame("/home/mwinter/delayGraphImages/delayGraph-######.png");
|
||||
} else if(keyCode == BACKSPACE){
|
||||
for(int i = 0; i < selectedVertices.size(); i++){
|
||||
removeVertex(selectedVertices.get(i));
|
||||
}
|
||||
} else if(mouseOverVertex != null && isInteger(key)){
|
||||
int i = Character.getNumericValue(key);
|
||||
if(mouseOverVertex.x > mouseX){
|
||||
if(i == 0){
|
||||
mouseOverVertex.stopSourceAndInputSynths();
|
||||
} else {
|
||||
println(synthDefNames.get(i));
|
||||
mouseOverVertex.startSourceAndInputSynths(synthDefNames.get(i), sourceGroup, inputGroup);
|
||||
}
|
||||
} else{
|
||||
if(i == 0){
|
||||
mouseOverVertex.stopOutputSynth();
|
||||
} else {
|
||||
mouseOverVertex.startOutputSynth(i - 1, outputGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeVertex(Vertex v){
|
||||
int i = 0;
|
||||
while(i < edges.size()){
|
||||
Edge edge = edges.get(i);
|
||||
if(edge.getInVertex() == v || edge.getOutVertex() == v){
|
||||
edge.stopSynth();
|
||||
edges.remove(edge);
|
||||
} else{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
v.stopAllSynths();
|
||||
vertices.remove(v);
|
||||
}
|
||||
|
||||
Edge getMouseOverEdge(){
|
||||
Edge mouseOverEdge = null;
|
||||
for(int i = 0; i < edges.size(); i++) {
|
||||
if(edges.get(i).isMouseOver()){
|
||||
mouseOverEdge = edges.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mouseOverEdge;
|
||||
}
|
||||
|
||||
Vertex getMouseOverVertex(){
|
||||
Vertex mouseOverVertex = null;
|
||||
for(int i = 0; i < vertices.size(); i++) {
|
||||
if(vertices.get(i).isMouseOver()){
|
||||
mouseOverVertex = vertices.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mouseOverVertex;
|
||||
}
|
||||
|
||||
ArrayList<Vertex> getSelectedVertices(){
|
||||
ArrayList<Vertex> selectedVertices = new ArrayList<Vertex>();
|
||||
for(int i = 0; i < vertices.size(); i++) {
|
||||
if(vertices.get(i).isSelected()){
|
||||
selectedVertices.add(vertices.get(i));
|
||||
}
|
||||
}
|
||||
return selectedVertices;
|
||||
}
|
||||
|
||||
public boolean isInteger( char i ) {
|
||||
try {
|
||||
Integer.parseInt( String.valueOf(i) );
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void updateDataDisplay(){
|
||||
Vertex mouseOverVertex = getMouseOverVertex();
|
||||
Edge mouseOverEdge = getMouseOverEdge();
|
||||
if(mouseOverVertex != null){
|
||||
String outputString;
|
||||
if(mouseOverVertex.getOutputBusIndex() == -1){
|
||||
outputString = "none";
|
||||
} else {
|
||||
outputString = (mouseOverVertex.getOutputBusIndex() + 1) + "";
|
||||
}
|
||||
data = "input: " + mouseOverVertex.getInput() + "\nouput: " + outputString +
|
||||
"\ninput mod: " + mouseOverVertex.getInputMod() + "\noutput mod: " + mouseOverVertex.getOutputMod();
|
||||
} else if(mouseOverEdge != null){
|
||||
String mouseOverEdgeDir = "";
|
||||
if(mouseOverEdge.getOutVertex().x < mouseOverEdge.getInVertex().x){
|
||||
mouseOverEdgeDir = "->";
|
||||
} else {
|
||||
mouseOverEdgeDir = "<-";
|
||||
}
|
||||
String data1 = mouseOverEdgeDir + "\ndelay time: " + mouseOverEdge.getDelayTime() + "\nmod: " + mouseOverEdge.getMod();
|
||||
String data2 = "";
|
||||
|
||||
Edge sharedEdge = getSharedEdge(edges, mouseOverEdge);
|
||||
if(sharedEdge != null){
|
||||
String sharedEdgeDir = "";
|
||||
if(sharedEdge.getOutVertex().x < sharedEdge.getInVertex().x){
|
||||
sharedEdgeDir = "->";
|
||||
} else {
|
||||
sharedEdgeDir = "<-";
|
||||
}
|
||||
data2 = sharedEdgeDir + "\ndelay time: " + sharedEdge.getDelayTime() + "\nmod: " + sharedEdge.getMod();
|
||||
}
|
||||
data = data1 + "\n" + data2;
|
||||
} else {
|
||||
data = "";
|
||||
}
|
||||
}
|
||||
|
||||
String getFormattedSynthDefNames(ArrayList<String> s){
|
||||
String res = "synth definitions:\n";
|
||||
for(int i = 0; i < s.size(); i++){
|
||||
res = res + i + ") " + s.get(i) + "\n";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Edge getSharedEdge(ArrayList<Edge> e, Edge edge){
|
||||
if(edge == null || e == null || e.size() < 1){
|
||||
return null;
|
||||
}
|
||||
|
||||
for(int i = 0; i < e.size(); i++) {
|
||||
if(edge.getOutVertex() == e.get(i).getInVertex() && edge.getInVertex() == e.get(i).getOutVertex()){
|
||||
return e.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void mouseWheel(MouseEvent me) {
|
||||
Vertex mouseOverVertex = getMouseOverVertex();
|
||||
Edge mouseOverEdge = getMouseOverEdge();
|
||||
Edge sharedEdge = getSharedEdge(edges, mouseOverEdge);
|
||||
int delta = (int) me.getAmount();
|
||||
if(tool == "edit" && mouseOverVertex != null){
|
||||
if(mouseOverVertex.x > mouseX){
|
||||
mouseOverVertex.setInputMod(constrain(mouseOverVertex.getInputMod() - delta, 1, 64));
|
||||
} else{
|
||||
mouseOverVertex.setOutputMod(constrain(mouseOverVertex.getOutputMod() - delta, 1, 64));
|
||||
}
|
||||
} else if(tool == "edit" && mouseOverEdge != null && mouseOverEdge.isMouseOverMod()){
|
||||
mouseOverEdge.setMod(constrain(mouseOverEdge.getMod() - delta, 1, 64));
|
||||
} else if(tool == "edit" && mouseOverEdge != null && mouseOverEdge.isMouseOverDelayTime()){
|
||||
mouseOverEdge.setDelayTime(constrain(mouseOverEdge.getDelayTime() - delta/pow(10.,delayControlMult), 0, mouseOverEdge.getMaxDelayTime()));
|
||||
} else if(tool == "edit" && sharedEdge != null && sharedEdge.isMouseOverMod()){
|
||||
sharedEdge.setMod(constrain(sharedEdge.getMod() - delta, 1, 64));
|
||||
} else if(tool == "edit" && sharedEdge != null && sharedEdge.isMouseOverDelayTime()){
|
||||
sharedEdge.setDelayTime(constrain(sharedEdge.getDelayTime() - delta/pow(10.,delayControlMult), 0, mouseOverEdge.getMaxDelayTime()));
|
||||
} else if(tool == "global"){
|
||||
if(windowX/2 > mouseX){
|
||||
for(int i = 0; i < edges.size(); i++){
|
||||
edges.get(i).setMod(constrain(edges.get(i).getMod() - delta, 1, 64));
|
||||
}
|
||||
} else{
|
||||
for(int i = 0; i < edges.size(); i++){
|
||||
edges.get(i).setDelayTime(constrain(edges.get(i).getDelayTime() - delta/pow(10.,delayControlMult) , 0, 11.8886));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//old mousewheel version
|
||||
//void mouseWheel(MouseEvent me) {
|
||||
// Vertex mouseOverVertex = getMouseOverVertex();
|
||||
// Edge mouseOverEdge = getMouseOverEdge();
|
||||
// Edge sharedEdge = getSharedEdge(edges, mouseOverEdge);
|
||||
// int delta = (int) me.getAmount();
|
||||
// if(tool == "edit" && mouseOverVertex != null){
|
||||
// if(mouseOverVertex.x > mouseX){
|
||||
// mouseOverVertex.setInputMod(constrain(mouseOverVertex.getInputMod() - delta/2, 1, 64));
|
||||
// } else{
|
||||
// mouseOverVertex.setOutputMod(constrain(mouseOverVertex.getOutputMod() - delta/2, 1, 64));
|
||||
// }
|
||||
// } else if(tool == "edit" && mouseOverEdge != null && mouseOverEdge.isMouseOverMod()){
|
||||
// mouseOverEdge.setMod(constrain(mouseOverEdge.getMod() - delta/2, 1, 64));
|
||||
// } else if(tool == "edit" && mouseOverEdge != null && mouseOverEdge.isMouseOverDelayTime()){
|
||||
// mouseOverEdge.setDelayTime(constrain(mouseOverEdge.getDelayTime() - delta/1000., 0, mouseOverEdge.getMaxDelayTime()));
|
||||
// } else if(tool == "edit" && sharedEdge != null && sharedEdge.isMouseOverMod()){
|
||||
// sharedEdge.setMod(constrain(sharedEdge.getMod() - delta/2, 1, 64));
|
||||
// } else if(tool == "edit" && sharedEdge != null && sharedEdge.isMouseOverDelayTime()){
|
||||
// sharedEdge.setDelayTime(constrain(sharedEdge.getDelayTime() - delta/1000., 0, mouseOverEdge.getMaxDelayTime()));
|
||||
// } else if(tool == "global"){
|
||||
// if(windowX/2 > mouseX){
|
||||
// for(int i = 0; i < edges.size(); i++){
|
||||
// edges.get(i).setMod(constrain(edges.get(i).getMod() - delta/2, 1, 64));
|
||||
// }
|
||||
// } else{
|
||||
// for(int i = 0; i < edges.size(); i++){
|
||||
// edges.get(i).setDelayTime(constrain(edges.get(i).getDelayTime() - delta/1000., 0, 11.8886));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//Vertex getNearestVertex(ArrayList<Vertex> v, float x, float y){
|
||||
// if(v.size() == 0){
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Vertex nearestVertex = v.get(0);
|
||||
// float distanceToNearestVertex = dist(nearestVertex.x, nearestVertex.y, x, y);
|
||||
// for(int i = 1; i < v.size(); i++) {
|
||||
// Vertex curVertex = v.get(i);
|
||||
// float curDistance = dist(curVertex.x, curVertex.y, x, y);
|
||||
//// println("i = " + i + ", curD = " + curDistance + ", x = " + x + ", y = " + y);
|
||||
// if(curDistance < distanceToNearestVertex){
|
||||
// nearestVertex = curVertex;
|
||||
// distanceToNearestVertex = curDistance;
|
||||
// }
|
||||
// }
|
||||
// return nearestVertex;
|
||||
//}
|
||||
//
|
||||
//float edgeDist(Edge e, float x, float y){
|
||||
// float distance = dist(e.getOutVertex().x, e.getOutVertex().y, x, y) +
|
||||
// dist(x, y, e.getInVertex().x, e.getInVertex().y) -
|
||||
// dist(e.getOutVertex().x, e.getOutVertex().y, e.getInVertex().x, e.getInVertex().y);
|
||||
// return distance;
|
||||
//}
|
||||
//
|
||||
//Edge getNearestEdge(ArrayList<Edge> e, float x, float y){
|
||||
// if(e.size() == 0){
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Edge nearestEdge = e.get(0);
|
||||
// float distanceToNearestEdge = edgeDist(nearestEdge, x, y);
|
||||
// for(int i = 1; i < e.size(); i++) {
|
||||
// Edge curEdge = e.get(i);
|
||||
// float curDistance = edgeDist(curEdge, x, y);
|
||||
//// println("i = " + i + ", curD = " + curDistance + ", x = " + x + ", y = " + y);
|
||||
// if(curDistance < distanceToNearestEdge){
|
||||
// nearestEdge = curEdge;
|
||||
// distanceToNearestEdge = curDistance;
|
||||
// }
|
||||
// }
|
||||
// return nearestEdge;
|
||||
//}
|
@ -0,0 +1,253 @@
|
||||
class Edge
|
||||
{
|
||||
private Vertex inVertex;
|
||||
private Vertex outVertex;
|
||||
private float velocity;
|
||||
private float distance;
|
||||
private float delayTime;
|
||||
private float maxDelayTime = 11.8886;
|
||||
private int mod;
|
||||
private Synth edgeSynth;
|
||||
private int bufferIndex;
|
||||
Allocator bufferAllocator;
|
||||
|
||||
Edge(Vertex outVertex, Vertex inVertex, Allocator b){
|
||||
this.inVertex = inVertex;
|
||||
this.outVertex = outVertex;
|
||||
bufferAllocator = b;
|
||||
distance = 0;
|
||||
mod = floor(random(0, 1) * 64);
|
||||
delayTime = random(.01, maxDelayTime);
|
||||
}
|
||||
|
||||
void display() {
|
||||
|
||||
PVector dir = PVector.sub(outVertex, inVertex);
|
||||
float r = sqrt(dir.x*dir.x+dir.y*dir.y+dir.z*dir.z);
|
||||
float theta = atan2(dir.y,dir.x);
|
||||
float phi = acos(dir.z/r);
|
||||
float angle = atan2(outVertex.y-inVertex.y, outVertex.x-inVertex.x);
|
||||
|
||||
float vDist = PVector.dist(inVertex, outVertex);
|
||||
|
||||
distance += abs(delayTime - 1) * 1/60. + 1/60.;
|
||||
dir.mult(distance);
|
||||
PVector location = PVector.sub(outVertex, dir);
|
||||
|
||||
if(distance + abs(delayTime-1) * 1/60. + 1/60. > 1) {
|
||||
distance = 0;
|
||||
}
|
||||
|
||||
pushMatrix();
|
||||
|
||||
shininess(10.0);
|
||||
|
||||
translate(location.x, location.y, 0);
|
||||
sphere(5);
|
||||
translate(-location.x, -location.y, 0);
|
||||
|
||||
translate(outVertex.x, outVertex.y, outVertex.z);
|
||||
rotateZ(theta);
|
||||
rotateY(phi);
|
||||
rotateX(-HALF_PI);
|
||||
cylinder(1, vDist, 10);
|
||||
translate(-outVertex.x, -outVertex.y, -outVertex.z);
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
public boolean isMouseOver(){
|
||||
if(edgeDist(this, mouseX, mouseY) <= 4){
|
||||
return true;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMouseOverMod(){
|
||||
if(modDist(this, mouseX, mouseY) <= 4){
|
||||
return true;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMouseOverDelayTime(){
|
||||
if(delayTimeDist(this, mouseX, mouseY) <= 4){
|
||||
return true;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
float edgeDist(Edge e, float x, float y){
|
||||
float distance = dist(e.getOutVertex().x, e.getOutVertex().y, x, y) +
|
||||
dist(x, y, e.getInVertex().x, e.getInVertex().y) -
|
||||
dist(e.getOutVertex().x, e.getOutVertex().y, e.getInVertex().x, e.getInVertex().y);
|
||||
return distance;
|
||||
}
|
||||
|
||||
float modDist(Edge e, float x, float y){
|
||||
float midMidPointX=e.getOutVertex().x+((e.getInVertex().x-e.getOutVertex().x)/4.0);
|
||||
float midMidPointY=e.getOutVertex().y+((e.getInVertex().y-e.getOutVertex().y)/4.0);
|
||||
float distance = dist(e.getOutVertex().x, e.getOutVertex().y, x, y) +
|
||||
dist(x, y, midMidPointX, midMidPointY) -
|
||||
dist(e.getOutVertex().x, e.getOutVertex().y, midMidPointX, midMidPointY);
|
||||
return distance;
|
||||
}
|
||||
|
||||
float delayTimeDist(Edge e, float x, float y){
|
||||
float midPointX=e.getOutVertex().x+((e.getInVertex().x-e.getOutVertex().x)/2.0);
|
||||
float midPointY=e.getOutVertex().y+((e.getInVertex().y-e.getOutVertex().y)/2.0);
|
||||
float midMidPointX=e.getOutVertex().x+((e.getInVertex().x-e.getOutVertex().x)/4.0);
|
||||
float midMidPointY=e.getOutVertex().y+((e.getInVertex().y-e.getOutVertex().y)/4.0);
|
||||
float distance = dist(midMidPointX, midMidPointY, x, y) +
|
||||
dist(x, y, midPointX, midPointY) -
|
||||
dist(midPointX, midPointY, midMidPointX, midMidPointY);
|
||||
return distance;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
if(this.getInVertex() == ((Edge) obj).getInVertex() && this.outVertex == ((Edge) obj).getOutVertex()){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void setInVertex(Vertex inVertex){
|
||||
this.inVertex = inVertex;
|
||||
}
|
||||
|
||||
void setOutVertex(Vertex outVertex){
|
||||
this.outVertex = outVertex;
|
||||
}
|
||||
|
||||
Vertex getInVertex(){
|
||||
return inVertex;
|
||||
}
|
||||
|
||||
Vertex getOutVertex(){
|
||||
return outVertex;
|
||||
}
|
||||
|
||||
void setMod(int m){
|
||||
if(edgeSynth != null){
|
||||
edgeSynth.set("mod", pow(2,m));
|
||||
}
|
||||
mod = m;
|
||||
}
|
||||
|
||||
int getMod(){
|
||||
return mod;
|
||||
}
|
||||
|
||||
void setDelayTime(float d){
|
||||
if(edgeSynth != null){
|
||||
edgeSynth.set("delayTime", d);
|
||||
}
|
||||
delayTime = d;
|
||||
}
|
||||
|
||||
float getDelayTime(){
|
||||
return delayTime;
|
||||
}
|
||||
|
||||
void setMaxDelayTime(float d){
|
||||
if(edgeSynth != null){
|
||||
edgeSynth.set("maxDelayTime", d);
|
||||
}
|
||||
maxDelayTime = d;
|
||||
}
|
||||
|
||||
float getMaxDelayTime(){
|
||||
return maxDelayTime;
|
||||
}
|
||||
|
||||
void startSynth(Group g){
|
||||
edgeSynth = new Synth("edge");
|
||||
|
||||
allocBuffer();
|
||||
edgeSynth.set("buffer", bufferIndex);
|
||||
|
||||
edgeSynth.set("busIn", outVertex.getFeedbackOutBusIndex());
|
||||
edgeSynth.set("busOut", inVertex.getFeedbackInBusIndex());
|
||||
edgeSynth.set("mod", getMod());
|
||||
edgeSynth.set("maxDelayTime", getMaxDelayTime());
|
||||
edgeSynth.set("delayTime", delayTime);
|
||||
edgeSynth.addToTail(g);
|
||||
}
|
||||
|
||||
void stopSynth(){
|
||||
edgeSynth.free();
|
||||
freeBuffer();
|
||||
}
|
||||
|
||||
void allocBuffer(){
|
||||
bufferIndex = bufferAllocator.getNextAvailableIndex();
|
||||
int frames = 524288;
|
||||
int channels = 1;
|
||||
OscMessage msg = new OscMessage("/b_alloc");
|
||||
msg.add(bufferIndex);
|
||||
msg.add(frames);
|
||||
msg.add(channels);
|
||||
Server.osc.send(msg, Server.local.addr);
|
||||
}
|
||||
|
||||
void freeBuffer(){
|
||||
bufferAllocator.freeIndex(bufferIndex);
|
||||
OscMessage msg = new OscMessage("/b_free");
|
||||
msg.add(bufferIndex);
|
||||
Server.osc.send(msg, Server.local.addr);
|
||||
}
|
||||
|
||||
/**
|
||||
cylinder taken from http://wiki.processing.org/index.php/Cylinder
|
||||
@author matt ditton
|
||||
*/
|
||||
|
||||
void cylinder(float w, float h, int sides){
|
||||
float angle;
|
||||
float[] x = new float[sides+1];
|
||||
float[] z = new float[sides+1];
|
||||
|
||||
//get the x and z position on a circle for all the sides
|
||||
for(int i=0; i < x.length; i++){
|
||||
angle = TWO_PI / (sides) * i;
|
||||
x[i] = sin(angle) * w;
|
||||
z[i] = cos(angle) * w;
|
||||
}
|
||||
|
||||
//draw the top of the cylinder
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
vertex(0, 0, 0);
|
||||
|
||||
for(int i=0; i < x.length; i++){
|
||||
vertex(x[i], 0, z[i]);
|
||||
}
|
||||
|
||||
endShape();
|
||||
|
||||
//draw the center of the cylinder
|
||||
beginShape(QUAD_STRIP);
|
||||
|
||||
for(int i=0; i < x.length; i++){
|
||||
vertex(x[i], 0, z[i]);
|
||||
vertex(x[i], h, z[i]);
|
||||
}
|
||||
|
||||
endShape();
|
||||
|
||||
//draw the bottom of the cylinder
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
vertex(0, h, 0);
|
||||
|
||||
for(int i=0; i < x.length; i++){
|
||||
vertex(x[i], h, z[i]);
|
||||
}
|
||||
|
||||
endShape();
|
||||
}
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
class Vertex extends PVector
|
||||
{
|
||||
private boolean selectFlag = false;
|
||||
private PVector mouseVector;
|
||||
|
||||
private String input = "none";
|
||||
private int outputBusIndex = -1;
|
||||
|
||||
private int inputMod;
|
||||
private int outputMod;
|
||||
|
||||
Synth sourceSynth;
|
||||
Synth inputSynth;
|
||||
Synth feedbackSynth;
|
||||
Synth outputSynth;
|
||||
|
||||
// private Bus sourceBus;
|
||||
// private Bus feedbackInBus;
|
||||
// private Bus feedbackOutBus;
|
||||
|
||||
private int sourceBusIndex;
|
||||
private int feedbackInBusIndex;
|
||||
private int feedbackOutBusIndex;
|
||||
|
||||
Allocator busAllocator;
|
||||
|
||||
Vertex(float x, float y, Allocator b){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.busAllocator = b;
|
||||
inputMod = floor(random(0, 1) * 64);
|
||||
outputMod = floor(random(0, 1) * 64);
|
||||
// println("source bus: " + sourceBus.index);
|
||||
// println("feedback out bus: " + feedbackOutBus.index);
|
||||
// input = (int) random(-1,8);
|
||||
// output =(int) random(-1,8);
|
||||
}
|
||||
|
||||
void display() {
|
||||
pushMatrix();
|
||||
translate(x, y, 0);
|
||||
if(isSelected()){
|
||||
shininess(1.0);
|
||||
} else {
|
||||
shininess(10.0);
|
||||
}
|
||||
sphere(10);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
public boolean isMouseOver(){
|
||||
PVector mousePos = new PVector(mouseX, mouseY);
|
||||
if( PVector.dist(this, mousePos) <= 10){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void setSelected(boolean b){
|
||||
selectFlag = b;
|
||||
}
|
||||
|
||||
boolean isSelected(){
|
||||
return selectFlag;
|
||||
}
|
||||
|
||||
void setMouseVector(PVector v){
|
||||
mouseVector = v;
|
||||
}
|
||||
|
||||
PVector getMouseVector(){
|
||||
return mouseVector;
|
||||
}
|
||||
|
||||
void setInput(String i){
|
||||
input = i;
|
||||
}
|
||||
|
||||
String getInput(){
|
||||
return input;
|
||||
}
|
||||
|
||||
void setInputMod(int m){
|
||||
if(inputSynth != null){
|
||||
inputSynth.set("mod", pow(2,m));
|
||||
}
|
||||
inputMod = m;
|
||||
}
|
||||
|
||||
int getInputMod(){
|
||||
return inputMod;
|
||||
}
|
||||
|
||||
void setOutputMod(int m){
|
||||
if(outputSynth != null){
|
||||
outputSynth.set("mod", pow(2,m));
|
||||
}
|
||||
outputMod = m;
|
||||
}
|
||||
|
||||
int getOutputMod(){
|
||||
return outputMod;
|
||||
}
|
||||
|
||||
int getSourceBusIndex(){
|
||||
// return sourceBus.index;
|
||||
return sourceBusIndex;
|
||||
}
|
||||
|
||||
|
||||
int getFeedbackInBusIndex(){
|
||||
// return feedbackInBus.index;
|
||||
return feedbackInBusIndex;
|
||||
}
|
||||
|
||||
int getFeedbackOutBusIndex(){
|
||||
// return feedbackOutBus.index;
|
||||
return feedbackOutBusIndex;
|
||||
}
|
||||
|
||||
void setSourceBusIndex(int i){
|
||||
sourceBusIndex = i;
|
||||
}
|
||||
|
||||
void setFeedbackInBusIndex(int i){
|
||||
feedbackInBusIndex = i;
|
||||
}
|
||||
|
||||
void setFeedbackOutBusIndex(int i){
|
||||
feedbackOutBusIndex = i;
|
||||
}
|
||||
|
||||
int getOutputBusIndex(){
|
||||
return outputBusIndex;
|
||||
}
|
||||
|
||||
void setOutputBusIndex(int i){
|
||||
outputBusIndex = i;
|
||||
}
|
||||
|
||||
void startFeedbackSynth(Group feedbackGroup){
|
||||
stopFeedbackSynth();
|
||||
|
||||
// feedbackInBus = new Bus();
|
||||
setFeedbackInBusIndex(busAllocator.getNextAvailableIndex());
|
||||
// println(getFeedbackInBusIndex());
|
||||
// feedbackOutBus = new Bus();
|
||||
setFeedbackOutBusIndex(busAllocator.getNextAvailableIndex());
|
||||
|
||||
feedbackSynth = new Synth("feedback");
|
||||
feedbackSynth.set("busIn", getFeedbackInBusIndex());
|
||||
feedbackSynth.set("busOut", getFeedbackOutBusIndex());
|
||||
feedbackSynth.addToTail(feedbackGroup);
|
||||
}
|
||||
|
||||
void startSourceAndInputSynths(String syhthDefName, Group sourceGroup, Group inputGroup){
|
||||
stopSourceAndInputSynths();
|
||||
// sourceBus = new Bus();
|
||||
setSourceBusIndex(busAllocator.getNextAvailableIndex());
|
||||
|
||||
// println(getSourceBusIndex());
|
||||
startSourceSynth(syhthDefName, sourceGroup);
|
||||
startInputSynth(inputGroup);
|
||||
}
|
||||
|
||||
void startSourceSynth(String syhthDefName, Group sourceGroup){
|
||||
stopSourceSynth();
|
||||
input = syhthDefName;
|
||||
sourceSynth = new Synth(syhthDefName);
|
||||
sourceSynth.set("busOut", getSourceBusIndex());
|
||||
sourceSynth.addToTail(sourceGroup);
|
||||
}
|
||||
|
||||
void startInputSynth(Group inputGroup){
|
||||
stopInputSynth();
|
||||
inputSynth = new Synth("input");
|
||||
inputSynth.set("busIn", getSourceBusIndex());
|
||||
inputSynth.set("busOut", getFeedbackInBusIndex());
|
||||
inputSynth.set("mod", inputMod);
|
||||
inputSynth.addToTail(inputGroup);
|
||||
}
|
||||
|
||||
void startOutputSynth(int i, Group outputGroup){
|
||||
stopOutputSynth();
|
||||
setOutputBusIndex(i);
|
||||
outputSynth = new Synth("output");
|
||||
outputSynth.set("busIn", getFeedbackOutBusIndex());
|
||||
outputSynth.set("busOut", getOutputBusIndex());
|
||||
outputSynth.set("mod", outputMod);
|
||||
outputSynth.addToTail(outputGroup);
|
||||
}
|
||||
|
||||
void stopSourceAndInputSynths(){
|
||||
stopSourceSynth();
|
||||
stopInputSynth();
|
||||
}
|
||||
|
||||
void stopSourceSynth(){
|
||||
if(sourceSynth != null){
|
||||
input = "none";
|
||||
sourceSynth.free();
|
||||
// sourceBus.free();
|
||||
busAllocator.freeIndex(getSourceBusIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void stopInputSynth(){
|
||||
if(inputSynth != null){
|
||||
inputSynth.free();
|
||||
}
|
||||
}
|
||||
|
||||
void stopFeedbackSynth(){
|
||||
if(feedbackSynth != null){
|
||||
feedbackSynth.free();
|
||||
// feedbackInBus.free();
|
||||
// feedbackOutBus.free();
|
||||
busAllocator.freeIndex(getFeedbackInBusIndex());
|
||||
busAllocator.freeIndex(getFeedbackOutBusIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void stopOutputSynth(){
|
||||
if(outputSynth != null){
|
||||
setOutputBusIndex(-1);
|
||||
outputSynth.free();
|
||||
}
|
||||
}
|
||||
|
||||
void stopAllSynths(){
|
||||
stopSourceSynth();
|
||||
stopInputSynth();
|
||||
stopFeedbackSynth();
|
||||
stopOutputSynth();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
(
|
||||
SynthDef("sine_20", {
|
||||
arg freq = 20, busOut = 1;
|
||||
Out.ar(busOut, SinOsc.ar(freq, 0, 1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("sine_30", {
|
||||
arg freq = 30, busOut = 1;
|
||||
Out.ar(busOut, SinOsc.ar(freq, 0, 1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("sine_40", {
|
||||
arg freq = 40, busOut = 1;
|
||||
Out.ar(busOut, SinOsc.ar(freq, 0, 1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("sine_50", {
|
||||
arg freq = 50, busOut = 1;
|
||||
Out.ar(busOut, SinOsc.ar(freq, 0, 1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("sine_60", {
|
||||
arg freq = 60, busOut = 1;
|
||||
Out.ar(busOut, SinOsc.ar(freq, 0, 1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("click", {
|
||||
arg busOut = 1;
|
||||
Out.ar(busOut,Impulse.ar(1,0,1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("dust_1", {
|
||||
arg busOut = 1;
|
||||
Out.ar(busOut,Dust.ar(1));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("dust_5", {
|
||||
arg busOut = 1;
|
||||
Out.ar(busOut,Dust.ar(5));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("dust_10", {
|
||||
arg busOut = 1;
|
||||
Out.ar(busOut,Dust.ar(10));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("feedback", {
|
||||
arg busIn, busOut;
|
||||
Out.ar(busOut, InFeedback.ar(busIn));
|
||||
}).send(s);
|
||||
|
||||
SynthDef("edge", {
|
||||
arg buffer, busIn, busOut, maxDelayTime = 1, delayTime = 0.5, mod = 4;
|
||||
var offset, in, out;
|
||||
in = In.ar(busIn);
|
||||
out = BufDelayN.ar(buffer, in % mod, delayTime, 1, 0);
|
||||
Out.ar(busOut, out);
|
||||
}).send(s);
|
||||
|
||||
SynthDef("input", {
|
||||
arg busIn, busOut, mod = 4;
|
||||
var offset, in, out;
|
||||
in = In.ar(busIn);
|
||||
out = ((in / 2.0 + 0.5) * mod).floor % mod;
|
||||
Out.ar(busOut, out);
|
||||
}).send(s);
|
||||
|
||||
SynthDef("output", {
|
||||
arg busIn, busOut, mod = 2;
|
||||
var offset, in, out;
|
||||
offset = 10;
|
||||
in = In.ar(busIn);
|
||||
out = ((in % mod) / (mod-1.0) - 0.5) * 2;
|
||||
Out.ar(busOut, out);
|
||||
}).send(s);
|
||||
|
||||
n = NetAddr("127.0.0.1", 57151);
|
||||
n.sendMsg("/addSynthDefs",
|
||||
"sine_20",
|
||||
"sine_30",
|
||||
"sine_40",
|
||||
"sine_50",
|
||||
"sine_60",
|
||||
"click",
|
||||
"dust_1",
|
||||
"dust_5",
|
||||
"dust_10",
|
||||
);
|
||||
)
|
Loading…
Reference in New Issue