using more than one pitch value

edited October 2014 in Library Questions

Hi, i'm working on a sketch where midi signals from ableton live change the scene within my processing sketch. The problem i can't seem to solve is finding away to use more than one pitch value to iterate the scene, currently i can only pick on value and not two or three.

the only solution ive come up with is putting all the incoming pitch values into an array and randomly selecting a value. This is counter intuitive as not every pitch value iterates the scene.

is there a way for me to listen for use multiple pitch values .

i hope that was concise.

import themidibus.*; 

MidiBus myBus;

int scene = 0, 
    shape = 0;

float centX, centY, lngth;

color[] clr = {/*color(38,43,54),*/  //creates list of colours
               color(145,121,96),
               color(214,207,199),
               color(199,179,113)};

color randCol = clr[ (int) random(clr.length)];
//int randCol = int(random(clr.length));
int [] fwd = {60,67,69,74};
//int fwdNotes = fwd[fwd.length-4];
int fwdNotes = fwd[ (int) random(fwd.length)];
//int [] bck = {74};
//int bckNotes = bck[ (int) random(bck.length)];



//colour palette
color c1 = color(38,43,54); //dark blue/grey
color c2 = color(145,121,96); //peachy colour
color c3 = color(214,207,199); // beige colour
color c4 = color(199,179,113); //yellowy colour


void setup(){
size(640, 360);
background(c1);
smooth(8);
noFill();
//strokeWeight(3);
centX=width/2;
centY=height/2;
lngth=25;
ellipseMode(CENTER);
rectMode(CENTER);

myBus = new MidiBus(this, "loopMIDI Port", -1);

}

void draw(){
  drawScene();
}

void noteOn(int channel, int pitch, int velocity) { // NoteOn function only runs when a Note On message is recieved
  //Receive a noteOn and trigger events

  //println();  // uncomment to see all the incoming messages
  //println("Note On:");
  //println("--------");
  //println("Channel:"+channel);
  println("Pitch:"+pitch);
  //println("Velocity:"+velocity);



  if((pitch==fwdNotes)){ // Move to the next scene
    scene++;
  }/*else if((channel==0)&&(pitch==bckNotes)){ // Move to the previouc scene
    scene--;
  }*/
scene%=4;
}

void mousePressed(){
  if (mouseButton == LEFT) {
  scene++;
} else if (mouseButton == RIGHT){
  scene--;
}
 randCol = clr[ (int) random(clr.length)];
  scene%=4; //makes it wrap around back to 0 when it hits 4, since you only have 4 scenes.
}



void drawScene(){
  background(c1);
  switch(scene){
    case 0:
      //background(c1);
      stroke(c3);
      ellipse(centX-160,centY,lngth,lngth);
      stroke(randCol);
      ellipse(centX,centY,lngth,lngth);
      stroke(c3);
      ellipse(centX+160,centY,lngth,lngth);
      break;
    case 1:
      background(c1);
      stroke(randCol);
      rect(centX-160,centY,lngth,lngth);
      stroke(randCol);
      ellipse(centX,centY,lngth,lngth);
      stroke(randCol);
      ellipse(centX+160,centY,lngth,lngth);
      break;
    case 2:
      background(c1);
      stroke(randCol);
      ellipse(centX-160,centY,lngth,lngth);
      stroke(c3);
      rect(centX,centY,lngth,lngth);
      stroke(c4);
      ellipse(centX+160,centY,lngth,lngth);
      break;
    case 3:
      background(c1);
      stroke(randCol);
      ellipse(centX-160,centY,lngth,lngth);
      stroke(c3);
      ellipse(centX,centY,lngth,lngth);
      stroke(c4);
      rect(centX+160,centY,lngth,lngth);
      break;
  }
}
Sign In or Register to comment.