Hi guys, I'm currently working on editing a piece of code from
http://krazydad.com/processing_music/ I've managed to get it working roughly how I wanted, but there's a few gripes I'm thus far unable to get my head around.
This is what I'm struggling with;
1; I want the visual to draw in for however long I hold a note on my midi keyboard
2; I don't want the visual to disappear when I strike the note for a second time
Here's the code I'm working with, once again many thanks to Jim (KrazyDad) for the original code!
Copy code
- import rwmidi.*; //Import the library
- MidiOutput myOutput; // The MidiBus
- MidiInput myInput;
- boolean midiThru = false; // echo all received midi in messages to the midi out device
- int maxNotes = 128;
- class MNote {
- long startTime;
- float ax;
- float ay;
- float bx;
- float by;
- float cx;
- float cy;
- float dx;
- float dy;
- float ex;
- float ey;
- float fx;
- float fy;
- float gx;
- float gy;
- float hx;
- float hy;
- float initRad;
- float weight;
- float kMinVelocity = 10;
- float kMaxVelocity = 100;
- float a = 100;
- int pitch;
- int velocity;
- boolean isOn = false;
- MNote(int pitch) {
- this.pitch = pitch;
- }
- void init(int pitch, int velocity)
- {
- startTime = millis();
- int rotation = 50000;
- int currentTime = millis();
- float m = (currentTime%rotation)* PI*2 / rotation; //creates motion
- this.ax = (sin(m)*a+screen.width/2);
- this.ay = (cos(m)*a+screen.height/2);
- this.bx = (sin(m)*(a+40)+screen.width/2);
- this.by = (cos(m)*(a+40)+screen.height/2);
- this.cx = (sin(m)*(a+80)+screen.width/2);
- this.cy = (cos(m)*(a+80)+screen.height/2);
- this.dx = (sin(m)*(a+120)+screen.width/2);
- this.dy = (cos(m)*(a+120)+screen.height/2);
- this.ex = (sin(m)*(a+160)+screen.width/2);
- this.ey = (cos(m)*(a+160)+screen.height/2);
- this.fx = (sin(m)*(a+200)+screen.width/2);
- this.fy = (cos(m)*(a+200)+screen.height/2);
- this.gx = (sin(m)*(a+240)+screen.width/2);
- this.gy = (cos(m)*(a+240)+screen.height/2);
- this.hx = (sin(m)*(a+280)+screen.width/2);
- this.hy = (cos(m)*(a+280)+screen.height/2);
- this.pitch = pitch;
- this.velocity = velocity;
- this.isOn = true;
- }
- void render()
- {
- if (!isOn)
- return;
- float hueV = (this.pitch % 12) / 12.0;
- float lum = constrain(1+pow(4,2), .05, 1);
- float sat = lum;
- noStroke();
- fill(hueV,sat,lum,20);
- ellipse(ax,ay,40,40);
- fill(hueV,sat,lum,20);
- ellipse(bx,by,40,40);
- fill(hueV,sat,lum,20);
- ellipse(cx,cy,40,40);
- fill(hueV,sat,lum,20);
- ellipse(dx,dy,40,40);
- fill(hueV,sat,lum,20);
- ellipse(ex,ey,40,40);
- fill(hueV,sat,lum,20);
- ellipse(fx,fy,40,40);
- fill(hueV,sat,lum,20);
- ellipse(gx,gy,40,40);
- fill(hueV,sat,lum,20);
- ellipse(hx,hy,40,40);
- }
- }
1