add code
This commit is contained in:
parent
bf115de9cd
commit
24f309fb8b
|
@ -0,0 +1,75 @@
|
|||
import themidibus.*;
|
||||
|
||||
MidiBus myBus;
|
||||
ArrayList<PVector> squares;
|
||||
ArrayList<Integer> velocities;
|
||||
color[] pitchColors;
|
||||
|
||||
void setup() {
|
||||
size(400, 400);
|
||||
squares = new ArrayList<PVector>();
|
||||
velocities = new ArrayList<Integer>();
|
||||
MidiBus.list();
|
||||
myBus = new MidiBus(this, 2, 3);
|
||||
|
||||
pitchColors = new color[128];
|
||||
for (int pitch = 0; pitch < 128; pitch++) {
|
||||
if (pitch == 36){
|
||||
pitchColors[pitch] = color(255, 255, 255);
|
||||
}
|
||||
if (pitch == 38){
|
||||
pitchColors[pitch] = color(255, 0, 0);
|
||||
}
|
||||
if (pitch == 48){
|
||||
pitchColors[pitch] = color(0, 0, 255);
|
||||
}
|
||||
if (pitch == 45){
|
||||
pitchColors[pitch] = color(0, 255, 0);
|
||||
}
|
||||
if (pitch == 46){
|
||||
pitchColors[pitch] = color(205, 85, 0);
|
||||
}
|
||||
if (pitch == 49){
|
||||
pitchColors[pitch] = color(255, 255, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
for (int i = 0; i < squares.size(); i++) {
|
||||
PVector square = squares.get(i);
|
||||
int pitch = (int) square.z;
|
||||
int velocity = velocities.get(i);
|
||||
fill(pitchColors[pitch]);
|
||||
rect(square.x, square.y, velocity, velocity);
|
||||
}
|
||||
}
|
||||
|
||||
void noteOn(int channel, int pitch, int velocity) {
|
||||
println("--------");
|
||||
println("Channel: "+channel, "Pitch: "+pitch, "Velocity: "+velocity);
|
||||
if (pitch == 36 || pitch == 38 || pitch == 48 || pitch == 45 || pitch == 46 || pitch == 49) {
|
||||
squares.add(new PVector(random(width), random(height), pitch));
|
||||
velocities.add(velocity);
|
||||
}
|
||||
}
|
||||
|
||||
void noteOff(int channel, int pitch, int velocity) {
|
||||
println("--------");
|
||||
println("Channel: "+channel, "Pitch: "+pitch, "Velocity: "+velocity);
|
||||
if (pitch == 36 || pitch == 38 || pitch == 48 || pitch == 45 || pitch == 46 || pitch == 49) {
|
||||
for (int i = squares.size() - 1; i >= 0; i--) {
|
||||
if (squares.get(i).z == pitch) {
|
||||
squares.remove(i);
|
||||
velocities.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void controllerChange(int channel, int number, int value) {
|
||||
println("--------");
|
||||
println("Channel: "+channel, "Number: "+number, "Value: "+value);
|
||||
}
|
Loading…
Reference in New Issue