Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Piano Roll

$
0
0
Hello,

I have been working on this project to generate a way to read a jpeg version of a piano roll into sound. I have been using the Minim library. Eventually I would like to switch to midi bus but as this is for a course for now I have to stick to minim. I was wonder if something like this has been done. So far I also have come across some problems. These are one using a String array to call my .wav files and secondly my boolean test. My logic was that I could use a test for an intersection and one for a test colour. It seems the if (0) colour test doesn't work. Here is my code :

... I am pretty sure my code is messy and there might be a better way to do this.

//inport minim libary
import ddf.minim.*;

Pianola pianola;
Note[] notes = new Note[63] ;
Minim minim;
String[] myStrings = {"0_A1.wav","1_Bb1.wav","2_B1.wav","3_C2.wav","4_Db2.wav","5_D2.wav","6_Eb2.wav","7_E2.wav","8_F2.wav","9_Gb2.wav","10_G2.wav","11_Ab2.wav","12_A2.wav","13_Bb2.wav","14_B2.wav","15_C3.wav","16_Db3.wav","17_D3.wav","18_Eb3.wav","19_E3.wav","20_F3.wav","21_Gb3.wav","22_G3.wav","23_Ab3.wav","24_A3.wav","25_Bb3.wav","26_B3.wav","27_C4.wav","28_Db4.wav","29_D4.wav","30_Eb4.wav","31_E4.wav","32_F4.wav","33_Gb4.wav","34_G4.wav","35_Ab4.wav","36_A4.wav","37_Bb4.wav","38_B4.wav","39_C5.wav","40_Db5.wav","41_D5.wav","42_Eb5.wav","43_E5.wav","44_F5.wav","45_Gb5.wav","46_G5.wav","47_Ab5.wav","48_A5.wav","49_Bb5.wav","50_B5.wav","51_C6.wav","52_Db6.wav","53_D6.wav","54_Eb6.wav","55_E6.wav","56_F6.wav","57_Gb6.wav","58_G6.wav","59_Ab6.wav","60_A6.wav","61_Bb6.wav","62_B6.wav", "63_C7.wav"};


void setup()
  { 
  size(800,550); 
 //Piano roll image Hesitation Blues
 pianola = new Pianola(-15840,0,1.7); // ***The constructor Pianola is undefined
 minim = new Minim(this);
 
  for (int j = 0; j < notes.length; j++) {
  notes[j] = new Note (width/2,j*6, myStrings[j]);}
  
  
}

void draw(){
  background(255);
  pianola.move();
  pianola.render();
  notes[j].render();
 for (int j = 0; j < notes.length; j++) {
  notes[j] = new Note (width/2,j*6, myStrings[j]);
  if (notes[j].intersect(pianola) && note.hole(pianola)){
      println("hit me");
      note.hit();
}
}
 }



class Pianola {

//location and volocity
  float px;
  float py;
  float pv;
  float pw;
  PImage roll;
  
  Pianola (float Xtemp, float Ytemp, float Vtemp) {
       px = Xtemp;
       py = Ytemp;
       pv = Vtemp;
       pw = 15840;
       roll = loadImage("NC_HESITATE_B&W.jpg");
  }
  
  void move() {
 //moving image
  px += pv;
}

  
void render() {
  //display image
   image(roll, px, py, pw, 550);
  } 
   }


class Note {

  //Location of point
    float nx;
    float ny; 
    
   //An AudioSnippet object is used to store the sound.
  
    AudioSnippet player; 
   
   Note (float Xtemp, float Ytemp, String filename) {
     nx = Xtemp;
     ny = Ytemp;
   
   //load 63 waves
  player = minim.loadSnippet(filename);

 }
 
 void hit (){
// play .wav
   if (!player.isPlaying()){
       player.rewind(); 
       player.cue(-20);
       player.play();
    }
  } 
   
   boolean intersect(Pianola p) {
//calulate distance

float distance = dist(nx,ny,p.px,p.py);
if (distance < p.pw ) {
  return true;
} else{
    return false;
}
}

   boolean hole(Pianola p) {
//detects holes with a colour

int c = color(0,255);
if (c < 255){
  return true;
} else{
    return false;
}
}
 
        void render(){
    point(nx,ny);
}
}

Viewing all articles
Browse latest Browse all 1768

Trending Articles