xxxxxxxxxx
import javax.sound.midi.MidiMessage;
import javax.sound.midi.SysexMessage;
import javax.sound.midi.ShortMessage;
int keyNum, keyNum2;
float keyNumMap=200;
int keyNum0x0F;
int keyNum0x00;
int status = 128;
int lastKey;
int hue;
int numPoints = 7;
PVector[] points = new PVector[numPoints];
PVector[] targetPoints = new PVector[numPoints];
float ease = 0.7;
void setup(){
size(1280, 720);
points[0] = new PVector (640,360);
points[1] = new PVector (640,360);
points[2] = new PVector (640,360);
points[3] = new PVector (640,360);
points[4] = new PVector (640,360);
points[5] = new PVector (640,360);
points[6] = new PVector (640,360);
targetPoints[0] = new PVector (640,81);
targetPoints[1] = new PVector (881,498);
targetPoints[2] = new PVector (502,601);
targetPoints[3] = new PVector (880,220);
targetPoints[4] = new PVector (500,119);
targetPoints[5] = new PVector (362,362);
targetPoints[6] = new PVector (780,600);
/*
targetPoints[0] = new PVector (640,360);
targetPoints[1] = new PVector (640,360);
targetPoints[2] = new PVector (640,360);
targetPoints[3] = new PVector (640,360);
targetPoints[4] = new PVector (640,360);
targetPoints[5] = new PVector (640,360);
targetPoints[6] = new PVector (640,360);
for(int i = 0; i < numPoints; i++) {
points[i] = new PVector(random(width), random(height));
targetPoints[i] = new PVector(random(width), random(height));
}
*/
}
void draw()
{
smooth();
background(0);
noFill();
stroke(255);
int channel = 0;
int pitch = 64;
int velocity = 127;
for(int i = 0; i < numPoints; i++)
{
float xdist = targetPoints[i].x - points[i].x;
float ydist = targetPoints[i].y - points[i].y;
points[i].x += xdist * ease;
points[i].y += ydist * ease;
float distance = xdist*xdist + ydist*ydist;
if(distance <= 2)
{
points[i].x = targetPoints[i].x;
points[i].y = targetPoints[i].y;
//targetPoints[i].x = random(width);
//targetPoints[i].y = random(height);
}
ellipse(points[i].x, points[i].y, 5, 5);
ellipse(targetPoints[i].x, targetPoints[i].y, 5, 5);
}
for(int i = 0; i < numPoints - 1; i++)
{
for(int j = i + 1; j < numPoints; j++)
{
line(points[0].x, points[0].y, points[1].x, points[1].y);//c-e
line(points[1].x, points[1].y, points[2].x, points[2].y);//g-e
line(points[0].x, points[0].y, points[2].x, points[2].y);//c-g
line(points[0].x, points[0].y, points[5].x, points[5].y);//a-c
//line(points[0].x, points[0].y, points[1].x, points[1].y);//c-e
line(points[1].x, points[1].y, points[5].x, points[5].y);//a-c
line(points[2].x, points[2].y, points[3].x, points[3].y);//g-d
line(points[3].x, points[3].y, points[4].x, points[4].y);//d-b
line(points[4].x, points[4].y, points[2].x, points[2].y);//g-b
line(points[0].x, points[0].y, points[6].x, points[6].y);//c-f
line(points[5].x, points[5].y, points[6].x, points[6].y);//a-f
//line(points[0].x, points[0].y, points[5].x, points[5].y);//a-c
}
}
if (keyPressed) {
if (key == 'q') { //c
targetPoints[0].x=640;//c
targetPoints[0].y=81;
targetPoints[1].x=881;//e
targetPoints[1].y=498;
targetPoints[2].x=502;//g
targetPoints[2].y=601;
ellipse(640,81,50,50);}
if (key == 'w') { //c#
targetPoints[0].x=776;//c#
targetPoints[0].y=117;
targetPoints[1].x=881;//e
targetPoints[1].y=498;
targetPoints[2].x=399;//g#
targetPoints[2].y=500;
ellipse(776,117,50,50);}
if (key == 'e') { //d
targetPoints[2].x=880;//d
targetPoints[2].y=220;
targetPoints[4].x=638;//f#
targetPoints[4].y=638;
targetPoints[3].x=362;//a
targetPoints[3].y=361;
ellipse(880,220,50,50);}
if (key == 'r') { //d#
targetPoints[2].x=918;//d#
targetPoints[2].y=358;
targetPoints[4].x=502;//g
targetPoints[4].y=601;
targetPoints[3].x=398;//a#
targetPoints[3].y=221;
ellipse(918,358,50,50);}
if (key == 't') { //e
targetPoints[4].x=881;//e
targetPoints[4].y=498;
targetPoints[2].x=399;//g#
targetPoints[2].y=500;
targetPoints[3].x=500;//b
targetPoints[3].y=119;
ellipse(881,498,50,50);}
if (key == 'y') { //f
targetPoints[6].x=780;//f
targetPoints[6].y=600;
targetPoints[5].x=362;//a
targetPoints[5].y=361;
targetPoints[0].x=640;//c
targetPoints[0].y=81;
ellipse(780,600,50,50);}
if (key == 'u') { //f#
targetPoints[6].x=638;//f#
targetPoints[6].y=638;
targetPoints[5].x=398;//a#
targetPoints[5].y=221;
targetPoints[0].x=776;//c#
targetPoints[0].y=117;
ellipse(638,638,50,50);}
if (key == 'i') { //g
targetPoints[2].x=502;//g 2
targetPoints[2].y=601;
targetPoints[4].x=500;//b 0
targetPoints[4].y=119;
targetPoints[3].x=880;//d 1
targetPoints[3].y=220;
ellipse(502,601,50,50);}
if (key == 'o') { //g#
targetPoints[5].x=399;//g#
targetPoints[5].y=500;
targetPoints[0].x=640;//c
targetPoints[0].y=81;
targetPoints[1].x=918;//d#
targetPoints[1].y=358;
ellipse(399,500,50,50);}
if (key == 'p') { //a
targetPoints[5].x=362;//a
targetPoints[5].y=361;
targetPoints[0].x=776;//c#
targetPoints[0].y=117;
targetPoints[1].x=881;//e
targetPoints[1].y=498;
ellipse(362,361,50,50);}
if (key == '[') { //a#
targetPoints[1].x=398;//a#
targetPoints[1].y=221;
targetPoints[0].x=880;//d
targetPoints[0].y=220;
targetPoints[5].x=780;//f
targetPoints[5].y=600;
ellipse(398,221,50,50);}
if (key == ']') { //b
targetPoints[0].x=500;//b
targetPoints[0].y=119;
targetPoints[5].x=918;//d#
targetPoints[5].y=358;
targetPoints[6].x=638;//f#
targetPoints[6].y=638;
ellipse(500,119,50,50);}}
if (keyPressed) {
if (key == '0') {
targetPoints[0].x=640; //c
targetPoints[0].y=81;
targetPoints[1].x=881; //e
targetPoints[1].y=498;
targetPoints[2].x=502; //g
targetPoints[2].y=601;
targetPoints[3].x=880; //d
targetPoints[3].y=220;
targetPoints[4].x=500; //b
targetPoints[4].y=119;
targetPoints[5].x=362; //a
targetPoints[5].y=362;
targetPoints[6].x=780; //f
targetPoints[6].y=600;
ellipse(640,81,75,75);}
}}
void midiMessage(MidiMessage message) {
println();
println("MidiMessage Data:");
println("--------");
println("Status Byte/MIDI Command:"+message.getStatus());
status = message.getStatus();
for (int i = 1; i < message.getMessage().length; i++) {
println("Param "+(i+1)+": "+(int)(message.getMessage()[i] & 0xFF));
keyNum = (int)(message.getMessage()[1] & 0xFF);
keyNum0x0F = (int)(message.getMessage()[1] & 0x0F);
keyNum0x00 = (int)(message.getMessage()[1] & 0x00);
}
}