import net.beadsproject.beads.core.*; import net.beadsproject.beads.ugens.*; import net.beadsproject.beads.events.*; import net.beadsproject.beads.data.*; //import benito_beads_ext1.*; //import benito_beads_ext2.*; import com.benitomedia.processing.display.*; import com.benitomedia.beadsext.benito1.*; import com.benitomedia.benito_beads_ext2.*; AudioContext ac; Bead bration; Drum bassd; Gain brator, bratorwg, brationlevel, maingain; Function bratorlevel, mainlevel; WavePlayer bratorwave; Clock clock; Envelope pulseinterval; int notenum = 0; long notelen = 16000; int brationkey = 0; final int brationslen = 100; Envelope[] brations = new Envelope[brationslen]; int[] brationsnote = new int[brationslen]; float[][] notefreqs = new float[256][]; int[] notemap = new int[256]; int numbrations = 0; int maxbrations = 11; float[] brationsx = new float[brationslen]; float[] brationsy = new float[brationslen]; float[] brationsr = new float[brationslen]; //float[] brationsalpha = new float[brationslen]; float[] brationsrcum = new float[256]; PFont smallfont, bigfont; DisplayRegime maindisp; void setup() { size(800, 450); frameRate(24); smallfont = loadFont("Aharoni-Bold-24.vlw"); bigfont = loadFont("Aharoni-Bold-32.vlw"); maindisp = new DisplayRegime(this); int yoffs = -30; DisplayText dtitle = new DisplayText("The Brightness of Space", bigfont, CENTER, width * .5, height * .5 + yoffs, 180, 180, 180, 0); dtitle.cueCTrans(1, 180, 180, 180, 0); dtitle.cueCTrans(1, 180, 180, 180, 1); dtitle.cueCTrans(5.5, 180, 180, 180, 1); dtitle.cueCTrans(1, 180, 180, 180, 0, 1); yoffs = 30; DisplayText dauthor = new DisplayText("by Benito\nv1.0f", smallfont, CENTER, width * .5, height * .5 + yoffs, 180, 180, 180, 0); dauthor.cueCTrans(3, 180, 180, 180, 0); dauthor.cueCTrans(1, 180, 180, 180, 1); dauthor.cueCTrans(4, 180, 180, 180, 1); dauthor.cueCTrans(1, 180, 180, 180, 0, 1); yoffs = 0; String descrstr = "a journey through sonic light"; DisplayText ddesc = new DisplayText(descrstr, smallfont, CENTER, width * .5, height * .5 + yoffs, 180, 180, 180, 0); ddesc.cueCTrans(9, 180, 180, 180, 0); ddesc.cueCTrans(1, 180, 180, 180, 1); ddesc.cueCTrans(4, 180, 180, 180, 1); ddesc.cueCTrans(1, 180, 180, 180, 0, 1); yoffs = 0; String instrstr = "type to initiate soundpoints"; instrstr += ""; DisplayText dinstr = new DisplayText(instrstr, smallfont, CENTER, width * .5, height * .5 + yoffs, 180, 180, 180, 0); dinstr.cueCTrans(16, 180, 180, 180, 0); dinstr.cueCTrans(1, 180, 180, 180, 1); dinstr.cueCTrans(6, 180, 180, 180, 1); dinstr.cueCTrans(1, 180, 180, 180, 0, 1); maindisp.add(dtitle); maindisp.add(dauthor); maindisp.add(ddesc); maindisp.add(dinstr); String p = ""; for(int i = 0; i < 256; i++) { notefreqs[i] = calcfornotenum(i); int k = i; for(int j = 0; j < 57; j++) { k = (k * i) % 251; } notemap[i] = k; p += i + " (" + char(i) + "): " + k + "; \n"; } println(p); ac = new AudioContext(); brationlevel = new Gain(ac, 1); bratorlevel = new Function(brationlevel) { public float calculate() { float x0 = x[0] * .5; if(x0 < .5) { return 0; } else if (x0 < 2.5) { return (x0 - .5) * (x0 - .5) * .2; } else { return 1 - .2 / (x0 - 1.5); } } }; bratorwg = new Gain(ac, 1, bratorlevel); bratorwave = new WavePlayer(ac, 143, Buffer.SAW); bratorwg.addInput(bratorwave); brator = new Gain(ac, 1, 1); brator.addInput(bratorwg); brator.addInput(new Static(ac, 1)); Gain bkeeper = new Gain(ac, 1, 1); bkeeper.addInput(brator); mainlevel = new Function(brationlevel) { public float calculate() { float x0 = x[0]; if(x0 < 1.5) { return .5; } else { return 1.1 / (x0 * .2 + 1.8); } } }; maingain = new Gain(ac, 1, mainlevel); def_beads(); bassd = new BassDrum(ac); maingain.addInput(bassd); ac.out.addInput(maingain); ac.start(); } void draw() { background(0); textFont(smallfont); Arrays.fill(brationsr, 0); Arrays.fill(brationsrcum, 0); for (int i = brationslen - 1; i >= 0; i--) { synchronized(brations) { int i2 = (brationkey + i) % brationslen; if (brations[i2] != null) { int bn = brationsnote[i2]; brationsrcum[bn] += brations[i2].getValue(); brationsr[i2] = brationsrcum[bn]; } } } fill(128, 128, 256); smooth(); stroke(32, 16, 64, 256); strokeWeight(2); //noStroke(); ellipseMode(CENTER); for(int i = 0; i < brationslen; i++) { synchronized(brations) { int i2 = (brationkey + i) % brationslen; if(brations[i2] != null) { float rln = sqrt(brationsr[i2]) * 100; //fill(128, 128, 256, brationsalpha[i2] * 80); ellipse(brationsx[i2], brationsy[i2], rln, rln); } } } maindisp.update(); //text(minx + ", " + maxx + ", " + miny + ", " + maxy + ". brations: " + numbrations, 10, 430); } void keyPressed() { if(key == ESC) { key = 0; } if(keyCode == '1') { bassd.hit(1); } else { if(numbrations < maxbrations) { notenum = notemap[keyCode]; notelen = 16000; println(notenum); println(calcfornotenum(notenum)); bration.message(bration); } } } float[] calcfornotenum(float nn) { float nr = nn + 20; float f1 = pow(2, nr / 30) * 10; float f2 = (f1 * f1) % 2000.; return new float[] {f1, f2, (f1 + f2 + 1000)}; }