summaryrefslogtreecommitdiff
path: root/sunkenfoal/sunkenfoal.pde
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-08-09 20:14:02 +0100
committerTim Redfern <tim@eclectronics.org>2012-08-09 20:14:02 +0100
commitb3548f90171f0be1ebfd7020f38f3d0acec65f8b (patch)
tree76698256f9cf4edb797f7996e36edc8e4bf92f83 /sunkenfoal/sunkenfoal.pde
initial commit
Diffstat (limited to 'sunkenfoal/sunkenfoal.pde')
-rw-r--r--sunkenfoal/sunkenfoal.pde240
1 files changed, 240 insertions, 0 deletions
diff --git a/sunkenfoal/sunkenfoal.pde b/sunkenfoal/sunkenfoal.pde
new file mode 100644
index 0000000..a7dbbb4
--- /dev/null
+++ b/sunkenfoal/sunkenfoal.pde
@@ -0,0 +1,240 @@
+import playApp.*;
+PlayApp app;
+//
+// pmlPlayer
+// Tim Redfern, September 09
+//
+
+import javax.sound.midi.*;
+import java.io.File;
+import ddf.minim.*;
+
+String midiFileName = "playhouse_midi_02.mid";
+String audioFileName = "a_way_in_playhouse01mast.mp3";
+Sequencer s;
+MetaListener metaListener;
+Note[] notes = new Note[30];
+int NOTE_LOW = 0, NOTE_HIGH = 29;
+
+Minim minim;
+AudioPlayer audioPlayer;
+
+int pw=10;int ph=10;
+PImage sc; //=createImage(width,height);
+
+//convolution matrix
+float[][] matrix = { { 0,.2, 0 },
+ {0, .59, 0 },
+ { 0, .2,0 } };
+
+//vary size and matrix over piece
+//matrix comes in slowly
+//
+//overall weighting of matrix is strongly determinant
+//functions that map the frequency of change
+//stepped by the notes will tend to maximise change where the music is busiest.
+//map the notes to cyclers- independently - no cant be done
+class FMcycler {
+ float cycleA;
+ float cycleB;
+ float offset;
+ float weight;
+ //takes a normalised coordinate and calculates a zeroed FM cycle
+ FMcycler(float _A, float _B) {
+ cycleA=_A;
+ cycleB=_B;
+ offset=0;
+ weight=1;
+ }
+ FMcycler(float _A, float _B,float _offs,float _wei) {
+ cycleA=_A;
+ cycleB=_B;
+ offset=_offs;
+ weight=_wei;
+ }
+ float map(float f) {
+ return offset+(weight*sin(cycleB*sin(cycleA*f*2*PI)*2*PI));
+ }
+}
+FMcycler off=new FMcycler(0,0,1.0,0);
+FMcycler[][] cyclematrix = { { off, new FMcycler(0.5,1.2,0,0), off },
+ { off, new FMcycler(0.5,1.2,1.0,0), off},
+ { off, new FMcycler(0.5,1.2,0,0), off } };
+FMcycler poscycler;
+FMcycler scalecycler;
+FMcycler vertcycler;
+void setup(){
+ poscycler=new FMcycler(0.5,1.7);
+ scalecycler=new FMcycler(0.5,3.1);
+ vertcycler=new FMcycler(0.5,0.9);
+ size(300, 110, P3D);
+ frameRate(15);
+ for(int i = NOTE_LOW; i < NOTE_HIGH; i++){
+ notes[i]=new Note();
+ }
+ //load audio file
+ minim = new Minim(this);
+ audioPlayer = minim.loadFile(audioFileName, 2048);
+ audioPlayer.play();
+ //audioPlayer.loop(9999999);
+ //audioPlayer is started when midi sequencer is started
+
+ startMidiFile();
+
+ sc=createImage(width,height,RGB);
+ background(0);
+ rectMode(CORNER);
+ noStroke();
+
+ colorMode(RGB, 255);
+
+ //app=new PlayApp(this,"localhost","Backing & Veering","Sunken Foal",153f);
+ swidth=width-2;
+ soffset=1;
+}
+int swidth;
+int soffset;
+float time=0;
+void draw(){
+ time+=(1f/(153f*25));
+
+ // for (int i=0;i<matrix.length;i++) {
+ // for (int j=0;j<matrix[0].length;j++) matrix[i][j]=cyclematrix[i][j].map(time);
+ //}
+
+ //matrix = { { 0, 0, 0 },{ 0, 1, 0 },{ 0, 0,0 } };
+
+ //println(time);
+ //scroll whole screen downwards how
+ //maybe copy the screen to the buffer offset a bit up, then draw in a blank rectangle and the new notes
+ //can the notes overlap?
+ loadPixels();
+ //sc=get(-1,0,width,height);
+ //sc=get(0,0,width,height);
+ //sc.filter(BLUR,1);
+ if (time>0.6) matrix[1][1]=0.6+(sin(((time-0.6)*0.25)*PI)*0.2);
+ sc=convolution(matrix,get(0,0,width,height));
+ background(0);
+ //image(sc,1,15,width,height);
+ image(sc,1,3.2+(vertcycler.map(time)*1.7),width-1,height);
+ //image(sc,soffset,5,swidth,height);
+ //image(sc,(int)(poscycler.map(time)*0)+1,5,width-2+(int)(scalecycler.map(time)*0),height);
+ //for (int i=15*width;i<height*width;i++) pixels[i]=color(255,255,255);
+ //image(sc,0,0,width,height);
+ updatePixels();
+
+
+ for(int i = NOTE_LOW; i < NOTE_HIGH; i++){
+ int v=notes[i].velocity;
+ if(v>0) {
+ //draw the note
+ colorMode(HSB, 255);
+ fill(200-v,255,255);
+ colorMode(RGB, 255);
+ rect(i*pw,0,pw,ph);
+ }
+ }
+
+
+ saveFrame("frames/img####.png");
+ if (!audioPlayer.isPlaying()) exit();
+}
+
+//change rate of drop?
+//veering??
+
+
+void startMidiFile(){
+ InputStream midiFileStream = createInput(midiFileName);
+
+ try {
+ s = MidiSystem.getSequencer(false);
+ s.setSequence(MidiSystem.getSequence(midiFileStream));
+
+ //Create a MidiReceiver that listens to NOTE ON and OFF events
+ Receiver midiReceiver = new MidiReceiver();
+ Transmitter midiTransmitter = s.getTransmitter();
+ midiTransmitter.setReceiver(midiReceiver);
+
+ //Create a MetaEventListener that listens to the END OF TRACK event
+ metaListener = new MetaListener();
+ s.addMetaEventListener(metaListener);
+ s.open();
+ s.setTickPosition(0L);
+ s.start();
+ }
+ catch(Exception e) {
+ println(e);
+ background(0, 100, 100); //red screen if erro
+ //stop();
+ }
+
+}
+
+
+void stop(){
+ s.stop();
+}
+
+
+PImage convolution(float[][] matrix, PImage img)
+{
+ //return img;
+
+ PImage newimg=createImage(img.width,img.height,RGB);
+ newimg.loadPixels();
+ int matrixsize = matrix[0].length;
+ int offset = matrixsize / 2;
+ for (int x=0;x<img.width;x++) {
+ for (int y=0;y<img.height;y++) {
+ float rtotal = 0.0;
+ float gtotal = 0.0;
+ float btotal = 0.0;
+ for (int i = 0; i < matrixsize; i++){
+ for (int j= 0; j < matrixsize; j++){
+ // What pixel are we testing
+ int xloc = x+i-offset;
+ int yloc = y+j-offset;
+ int loc = xloc + img.width*yloc;
+ // Make sure we haven't walked off our image, we could do better here
+ loc = constrain(loc,0,img.pixels.length-1);
+ // Calculate the convolution
+ rtotal += (red(img.pixels[loc]) * matrix[i][j]);
+ gtotal += (green(img.pixels[loc]) * matrix[i][j]);
+ btotal += (blue(img.pixels[loc]) * matrix[i][j]);
+ }
+ }
+ // Make sure RGB is within range
+ rtotal = constrain(rtotal,0,255);
+ gtotal = constrain(gtotal,0,255);
+ btotal = constrain(btotal,0,255);
+ //write a buffer
+ newimg.pixels[x+y*img.width]=color(rtotal,gtotal,btotal);
+ //newimg.pixels[x+y*img.width]=color(255,255,255);
+ }
+ }
+ //save the buffer
+ newimg.updatePixels();
+ return newimg;
+
+}
+
+void keyPressed() {
+ switch(key){
+ case 'q':
+ swidth-=1;
+ break;
+ case 'w':
+ swidth+=1;
+ break;
+ case 'e':
+ soffset-=1;
+ break;
+ case 'r':
+ soffset+=1;
+ break;
+ }
+}
+
+
+