import rwmidi.*; MidiOutput output; //El array "scale" no es necesario pero s’ es œtil porque tiene notas v‡lidas; cambiar la escala es una manera de variar la sonoridad. int scale[] = new int[] {12, 10, 8, 7, 5, 3, 2, 0 }; //int scale[] = new int[] {0, 2, 3, 5, 7, 8, 10, 12 }; int prevPitch = 0; //the bouncing ball example //DS //Max number of balls int MAX = 150; //set up some global variables as arrays now int[] xspeed = new int[MAX]; int[] yspeed = new int[MAX]; int[] x = new int[MAX]; int[] y = new int[MAX]; float[] r = new float[MAX]; //color []elColor = new color [MAX]; int[] color1 = new int [MAX]; int[] color2 = new int [MAX]; int[] color3 = new int [MAX]; //our setup function void setup() { size(800,600); //define size //initialize all arrays for (int i = 0; i < MAX; i++) { random(i); xspeed[i] = int(random(-5,5)); yspeed[i] = int(random(-5,5)); x[i] = width/2; y[i] = height/2; r[i] = 10; color1[i]= 255; color2[i]= 255; color3[i]= 255; } MidiOutputDevice devices[] = RWMidi.getOutputDevices(); //Aqu’ usamos el Device 0 (el que usa el IAC driver). el Device 2 es el Java Synthesizer output = RWMidi.getOutputDevices()[0].createOutput(); //ESTE FOR ES PARA QUE APAGUE AL PRINCIPIO CUALQUIER NOTA QUE QUEDE SONANDO for(int i=0; i<=127; i++){ notoutput(i); } } ///////////////// void draw() { background(50); //first we draw the background ellipseMode(CENTER); //set our ellipse mode noStroke(); for (int i = 0; i < MAX; i++) { fill(random (color1[i]),random (color2[i]),random (color3[i])); //set ellipse color ellipse(x[i],y[i],r[i],r[i]); //draw ellipse //radius always decreases back to 10 if it's bigger output (color1[i]/10); output (color2[i]/5); output (color3[i]/2); if (r[i] > 10) { r[i]--; } //adjust x,y based on speed x[i] = x[i] + xspeed[i]; y[i] = y[i] + yspeed[i]; //acount for bouncing off edges if ((x[i] > width) || (x[i] < 0)) { xspeed[i] = xspeed[i] * -1; r[i] = random(10,100); //adjust radius when bouncing } if ((y[i] > height) || (y[i] < 0)) { yspeed[i] = yspeed[i] * -1; r[i] = random(10,100); } notoutput(prevPitch); if(i%4 == 0){ //if(0 < ypos && ypos< height){ //if(0 < xpos && xpos < width){ int posPitch = floor(map(i, 0, MAX, 0, 7)); int pitch = scale[posPitch]; // println(pitch); output(pitch); prevPitch=pitch; // } //} } } } /////////////////////////////////////////// /* int tono(int x, int y) { return scale [(x + y) % 3 * 12 + 40]; } */ void output(int tono) { output.sendNoteOn(0, tono, 100); } void notoutput(int tono) { output.sendNoteOff(0, tono, 100); }