Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Wall_Piano 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, to mimic a 2D piano. Horizontal levels are mapped to the same pitch, vertical levels correspond to increasing pitch
- */
- import ddf.minim.*;
- import processing.video.*;
- MovieMaker mm;
- AudioSample S;
- Minim minim;
- int counter = 0;
- int c=0;
- int life = 60;
- // int beat = 100;
- // float step = beat/7;
- int unit = 60;
- int wWidth = unit*15;
- int wHeight = unit*12;
- String note;
- boolean SoundOn = true;
- boolean makeMovie;
- //Location arrays:
- Hold [][] HoldArray = new Hold [wWidth][wHeight];
- Coord [] Buffer = new Coord [32];
- Coord topLeft, topRight, bottomLeft, bottomRight;
- String[] noteMatrix;
- String[] row;
- void setup () {
- size(wWidth, wHeight);
- frameRate(10);
- if(makeMovie)
- mm = new MovieMaker(this, width, height, "tone_wall_vertical.mov", 10, MovieMaker.ANIMATION, MovieMaker.HIGH);
- background(255);
- noteMatrix = loadStrings("vertical_mp3.txt");
- // PImage r = loadImage("red.png");
- // PImage y = loadImage("yellow.png");
- // PImage yr= loadImage("yellow_roll.png");
- PImage pressed = loadImage("pressed_60.png");
- PImage gray = loadImage("gray_60.png");
- //PImage yr= loadImage("gray_60.png");
- int w = gray.width;
- int h = gray.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,gray,pressed,note);
- }
- }
- }
- void draw (){
- for (int i=0; i<wWidth/unit;i++)
- {
- for (int j=0;j<wHeight/unit;j++)
- {
- //background(255);
- HoldArray[i][j].update(); // the function which determines whether the mouse is on the hold or not, and loads the according image
- HoldArray[i][j].display(); // then the loaded image is displayed on screen
- }
- }
- fill(182,37,227,100);
- 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)
- {
- // make quad here
- 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
- //S.close();
- if(makeMovie)
- mm.finish();
- minim.stop();
- super.stop();
- }
- class Coord
- {
- int x;
- int y;
- Coord (int ii, int ij) {
- x = ii;
- y = ij;
- }
- }
- boolean mReleased = false;
- void mouseReleased()
- {
- mReleased = true;
- }
- class Hold
- {
- PImage base; // image on screen
- PImage down; // image when clicked
- PImage currentimage;
- 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];
- //AudioSample sound;
- boolean played = false;
- 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
- Hold(int ix, int iy, int ii, int ij, int iw, int ih, PImage ibase, PImage idown, String iNote)
- {
- x = ix;
- y = iy;
- i=ii;
- j=ij;
- w = iw;
- h = ih;
- base = ibase;
- down = idown;
- currentimage = base;
- note = iNote;
- for (int c=0;c<2;c++)
- rgb[c] = int(random(0,255));
- }
- void pressed()
- {
- if(over && mReleased && !activated)
- {
- pressed = !pressed;
- activated = !activated;
- if(SoundOn)
- {
- S = minim.loadSample(note, 2048);
- S.trigger();
- }
- Buffer[c]= new Coord(x,y);
- c++;
- age = 0;
- mReleased = false;
- }
- else if (over && mReleased && activated)
- {
- pressed = !pressed;
- activated = !activated;
- mReleased = false;
- played = false;
- age=0;
- if(c==4)
- for(int t=0;t<4;t++)
- {
- if (Buffer[t].x==x && Buffer[t].y == y)
- {
- int v=t;
- while((v+1)!=4)
- {
- Buffer[v]=Buffer[v+1];
- v++;
- }
- }
- }
- 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
- {
- currentimage = base;
- }
- }
- void display()
- {
- fill(255,255,255);
- noStroke();
- rect(x,y,unit,unit);
- image(currentimage, x, y);
- if (!played && activated)
- age=age+3;
- if (age == life)
- {
- age=0;
- played=true;
- }
- fill(rgb[0],rgb[1],rgb[2],100);
- ellipse(x+(w/2),y+(h/2),int((float(age)/float(life))*float(w)),int((float(age)/float(life))*float(w)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement