Anna Tracy's “pink sound” algorithmic composition sketch. MIDI note values are generated and sent to a Pure Data patch to be realized using OSC.
Scroll down for the patch.
//Anna Tracy //CS 444 //Advent 2010 //Sends 1/f midi values to Pd //And plays through variations sequentially. import oscP5.*; import netP5.*; String ipAddress="127.0.0.1"; int port = 9001; OscP5 oscP5; NetAddress ip; //length of tune int lngth=10; //1/f values int[] val; int[] vals; void setup() { oscP5=new OscP5(this, port); ip=new NetAddress(ipAddress, port); val=pnkMd(lngth); val=fixer(val); noLoop(); } void draw() { OscBundle bundle=new OscBundle(); //Sequentially play through variations. for (int j=0;j<6;j++) { switch(j) { case 0: vals=val; println("regular"); break; case 1: vals=invert(val); println("inverted"); break; case 2: vals=rep(val); println("repeat"); break; case 3: vals=scl(val, 2); println("scaled"); break; case 4: vals=transpose(val); println("transposed"); break; case 5: vals=reverse(val); println("reversed"); break; } pushMatrix(); OscMessage onf =new OscMessage("/onf"); onf.add(0.6); bundle.add(onf); oscP5.send(bundle, ip); //Play (send) current variation. for (int i=0;i<lngth;i++) { OscMessage note =new OscMessage("/note"); note.add(vals[i]); bundle.add(note); oscP5.send(bundle, ip); //Pause before sending next note (gives note length) try { Thread.sleep(400); } catch(InterruptedException ie) { System.out.println(ie.getMessage()); } } //Pause after sending last note of variation (makes last note longer). try { Thread.sleep(400); } catch(InterruptedException ie) { System.out.println(ie.getMessage()); } //Send message to PD to stop playing. onf =new OscMessage("/onf"); onf.add(0); bundle.add(onf); oscP5.send(bundle, ip); //If not on last variation, pause, and then //send message to PD to start playing next variation. if (j!=5) { try { Thread.sleep(800); } catch(InterruptedException ie) { System.out.println(ie.getMessage()); } onf =new OscMessage("/onf"); onf.add(0.6); bundle.add(onf); oscP5.send(bundle, ip); } } popMatrix(); println("finished"); }