Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- JukeRock PathFlow processing sketch
- The sketch loads in the input file matrix from a text file and loads the sound accordingly. then it creates a matrix of buttons to simulate a climbing wall. Each button/grip is associated with a sound, horizontal levels the same, vertical levels changing in pitch/instrument. A sequencer periodically scans all the columns, playing activated button in the column at each step. This reflects the path followed by the climber in a melodic way.
- */
- //User definitions:
- int beat = 45;
- int unit = 60; // 60 pixels, 30 cm
- int VertItemCount = 12;
- int HorItemCount = 15;
- boolean SoundOn=true; // true: play mode; false: record mode
- boolean makeMovie = false;
- int fps=10;
- import ddf.minim.*;
- import processing.video.*;
- MovieMaker mm;
- //AudioSample sound, S;
- Minim minim;
- int counter = 0;
- int gripC=0;
- int c = 0;
- Coord topLeft, topRight, bottomLeft, bottomRight;
- int wWidth = unit*HorItemCount;
- int wHeight = unit*VertItemCount;
- float step = beat/HorItemCount;
- //Location arrays:
- Hold [][] HoldArray = new Hold [wWidth][wHeight];
- Coord [] Buffer = new Coord [16];
- // audio input from text file
- String[] noteMatrix;
- String[] row;
- String note;
- void setup () {
- size(wWidth, wHeight);
- frameRate(10);
- background(255);
- if(makeMovie)
- mm = new MovieMaker(this, width, height, "path_flow.mov",10, MovieMaker.ANIMATION, MovieMaker.HIGH);
- noteMatrix = loadStrings("fm7.txt");
- PImage r = loadImage("pressed_60.png");
- PImage y = loadImage("gray_60.png");
- PImage yr= loadImage("gray_roll_60.png");
- PImage p = loadImage("left_60.png");
- int w = r.width;
- int h = r.height;
- minim = new Minim(this);
- for (int j=0; j<(wHeight/unit);j++)
- {
- row = split(noteMatrix[j], '\t');
- for (int i=0; i<(wWidth/unit);i++)
- {
- note = row[i];
- HoldArray[i][j] = new Hold(i*unit,j*unit,i,j,w,h,y,yr,r,p,note);
- }
- }
- }
- void draw (){
- // procedure for updating and displaying grips:
- for (int i=0; i<wWidth/unit;i++)
- {
- for (int j=0;j<wHeight/unit;j++)
- {
- HoldArray[i][j].update();
- HoldArray[i][j].display();
- }
- }
- if (counter==beat)
- {
- counter=0;
- }
- else
- {
- for(int a =0; a<HorItemCount;a++)
- {
- if(counter==int(step)*a)
- {
- for (int i = 0; i<VertItemCount;i++)
- if(HoldArray[a][i].activated)
- {
- if(SoundOn)
- {
- HoldArray[a][i].S.trigger();
- }
- }
- }
- }
- counter++;
- }
- //println(c);
- fill(108,56,8,150);
- if(c==3)
- {
- triangle(Buffer[0].x+unit/2,Buffer[0].y+unit/2,Buffer[1].x+unit/2,Buffer[1].y+unit/2,Buffer[2].x+unit/2,Buffer[2].y+unit/2);
- }
- else if (c==4)
- {
- int indBot1=0, indBot2=0, indTop1=0, indTop2=0;
- int maxY;
- maxY=0;
- for(int k=0;k<4;k++)
- {
- if(maxY<Buffer[k].y)
- {
- maxY=Buffer[k].y;
- indBot1=k;
- }
- }
- maxY=0;
- for(int k=0;k<4;k++)
- {
- if(maxY<Buffer[k].y && k !=indBot1)
- {
- maxY=Buffer[k].y;
- indBot2=k;
- }
- }
- for(int k=0;k<4;k++)
- {
- if(k!=indBot1 && k!=indBot2)
- indTop1=k;
- }
- for(int k=0;k<4;k++)
- {
- if(k!=indBot1 && k!=indBot2 && k!=indTop1)
- indTop2=k;
- }
- if (Buffer[indBot1].x < Buffer[indBot2].x)
- {
- bottomLeft = Buffer[indBot1];
- bottomRight= Buffer[indBot2];
- }
- else
- {
- bottomLeft = Buffer[indBot2];
- bottomRight= Buffer[indBot1];
- }
- if (Buffer[indTop1].x < Buffer[indTop2].x)
- {
- topLeft = Buffer[indTop1];
- topRight= Buffer[indTop2];
- }
- else
- {
- topLeft = Buffer[indTop2];
- topRight= Buffer[indTop1];
- }
- quad(topLeft.x+unit/2,topLeft.y+unit/2,topRight.x+unit/2,topRight.y+unit/2,bottomRight.x+unit/2,bottomRight.y+unit/2,bottomLeft.x+unit/2,bottomLeft.y+unit/2);
- }
- if(makeMovie)
- {
- mm.addFrame();
- }
- }
- void stop() {
- // always close Minim audio classes when you are done with them
- if(makeMovie)
- mm.finish();
- minim.stop();
- super.stop();
- }
- class Coord
- {
- int x;
- int y;
- Coord (int ii, int ij) {
- x = ii;
- y = ij;
- }
- }
- // Hold Class File:
- boolean mReleased = false;
- float radius;
- void mouseReleased()
- {
- mReleased = true;
- }
- class Hold
- {
- PImage base; // image on screen
- PImage roll; // image when mouse is on
- PImage down; // image when clicked
- PImage currentimage;
- PImage p;
- int x, y; // coordinates of the holds
- int i,j; // place in the array, like HoldArray [i][j]
- int w, h; // width and height of the image
- int age = 0; // "age" of the hold. when clicked, it's born, and after 4 seconds, its "born" again, creating a sound
- String note; //name of the tone of each hold
- float [] rgb = new float [3];
- boolean over = false; // bool if mouse over
- boolean pressed = false; // bool if mouse clicked
- boolean activated = false; // bool if sound of the hold is activated
- boolean left = false;
- AudioSample S;
- Hold(int ix, int iy, int ii, int ij, int iw, int ih, PImage ibase, PImage iroll, PImage idown, PImage ip, String inote)
- {
- x = ix;
- y = iy;
- i=ii;
- j=ij;
- w = iw;
- h = ih;
- base = ibase;
- roll = iroll;
- down = idown;
- p = ip;
- currentimage = base;
- note=inote;
- for (int j=0;j<2;j++)
- rgb[j] = int(random(0,255));
- S = minim.loadSample(note, 2048);
- }
- void pressed()
- {
- if(over && mReleased && !activated)
- {
- pressed = !pressed;
- activated = !activated;
- if(SoundOn)
- {
- S.trigger();
- }
- // if (c==4)
- // {
- // for (int t=1;t<4;t++)
- // Buffer[t-1]=Buffer[t];
- // Buffer[3].x=x;
- // Buffer[3].y=y;
- //
- // }
- // else
- // {
- Buffer[c]= new Coord(x,y);
- c++;
- // }
- mReleased = false;
- } else if (over && mReleased && activated)
- {
- pressed = !pressed;
- //activated = !activated;
- left=!left;
- mReleased = false;
- for(int t=0;t<c;t++)
- {
- if (Buffer[t].x==x && Buffer[t].y == y)
- {
- int v=t;
- while((v+1)!=c)
- {
- Buffer[v]=Buffer[v+1];
- v++;
- }
- }
- }
- if(left)
- {
- c--;
- }
- else
- {
- Buffer[c]= new Coord(x,y);
- c++;
- }
- }
- }
- void over()
- {
- if (mouseX >= x && mouseX <= x+w &&
- mouseY >= y && mouseY <= y+h)
- {
- over = true;
- }
- else
- {
- over = false;
- }
- }
- void update()
- {
- over();
- pressed();
- if(pressed)
- {
- currentimage = down;
- }
- else if (left)
- {
- currentimage = p;
- }else
- {
- currentimage = base;
- }
- }
- void display()
- {
- fill(255,255,255);
- noStroke();
- rect(x,y,unit,unit);
- if (counter-i*step>=0)
- radius = counter -i*step;
- else
- radius = beat + counter -i*step;
- radius = radius/float(beat)*63;
- //rect:
- fill(0,0,255,radius);
- noStroke();
- rect(x,y,unit,unit); // draw rect
- // fill(255,255,255);
- // noStroke();
- // rect(x,y,unit,unit);
- image(currentimage, x, y);
- }
- }//end of class Hold
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement