I have been trying to create a bouncing ball that triggers midi notes when it hits the wall. I then want to continue and add more balls and get them to trigger notes when they hit each other. I already have a second sketch with the balls triggering off each other.
What I am having problems with is getting the note value to be selected from a group of values (that correspond to the D minor scale, ie "62", "64", "65", "67"(pitch values)). As you can see I kind of tried to create an array to hold the data and was hoping that i could get it to select one of the values at random on triggering(hitting edge). Instead what I have ended up with is 7 random values that trigger. (0-6 i think) (I +62 to make the notes higher, do not want that in there)
Another thing I would like is for the value chosen to depend on the x or y position of the ball. So far when trying to implement anything like this I get cannot convert float to int errors.
I do not know how much sense this makes :( I will try and clarify if you ask anything.
I am using the midi bus, and am totally confused now :(
import themidibus.*;
MidiBus myBus;
/**
* Bounce.
*
* When the shape hits the edge of the window, it reverses its direction.
*/
int size = 60; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 2.8; // Speed of the shape
float yspeed = 2.2; // Speed of the shape
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom
void setup()
{
MidiBus.list();
myBus = new MidiBus(this, -1, "Java Sound Synthesizer");
size(640, 400);
noStroke();
frameRate(30);
smooth();
// Set the starting position of the shape
xpos = width/2;
ypos = height/2;
}
void draw()
{
background(102);
// Update the position of the shape
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
// Test to see if the shape exceeds the boundaries of the screen
// If it does, reverse its direction by multiplying by -1
if (xpos > width-size || xpos < 0) {
xdirection *= -1;
}
if (ypos > height-size || ypos < 0) {
ydirection *= -1;
}
int Scale[] = {62, 64, 65, 67, 69, 70, 72};
int pitch = int(random(Scale.length+62));
//Attempt to get a single note on note offf sequence.