Vugdi Headhey
YaBB Newbies
Offline
Posts: 4
RWMidi - Midi Chords
Jul 19th , 2009, 8:19am
Hello, I'm a processing novice, however over the past few weeks I've been playing around with the Ruin & Wesen midi library and I've had some good results. In the past couple of days something has come up that I believe is down to my understanding of how the code is ordered overall, as opposed to something linked with the R&W library, in fact, I'm sure of it. That's why I'm posting this under 'Syntax Questions.' In the code below I'm using a midi controller keyboard to draw two squares, simple enough. However, it seems to be the case that it's either the red square or the green square that gets drawn at any one time, and if I play both notes together on the keyboard the code only selects one. I've tried using various 'for,' 'if,' and 'while' combinations, but no luck. It would be great if anyone could point out my lack of understanding! Many thanks. import rwmidi.*; MidiOutput midiOutput; MidiInput midiInput; static final int defaultInputDevice = 1; static final int defaultOutputDevice = 0; int pit; int vel; int xPos = 0; int yPos = 0; int AColor = color(255, 0, 0); int DColor = color(0, 255, 0); void setup(){ size(400, 400); background(0); frameRate(24); MidiInputDevice inDevices[] = RWMidi.getInputDevices(); for (int i = 0; i < inDevices.length; i++) { println("In " + i + ": " + inDevices[i].getName()); } MidiOutputDevice outDevices[] = RWMidi.getOutputDevices(); for (int i = 0; i < outDevices.length; i++) { println("Out " + i + ": " + outDevices[i].getName()); } midiInput = inDevices[defaultInputDevice].createInput(this); midiOutput = outDevices[defaultOutputDevice].createOutput(); } void noteOnReceived(Note note){ vel = note.getVelocity(); pit = note.getPitch(); println("noteOn, Velocity: " + vel + ", Pitch: " + pit); } void redSquare(int xPos, int yPos, int squareWidth, int squareHeight){ fill(AColor); noStroke(); rectMode(CENTER); translate(width/2, height/2); rect(xPos, yPos, squareWidth, squareWidth); } void greenSquare(int xPos, int yPos, int squareWidth, int squareHeight){ fill(DColor); noStroke(); rectMode(CENTER); translate(width/2, height/2); rect(xPos, yPos, squareWidth, squareWidth); } void noteChoice(){ int[] ANoteArray = {9, 21, 33, 45, 57, 69, 81, 93, 105, 117}; int[] DNoteArray = {2, 14, 26, 38, 50, 62, 74, 86, 98, 110, 122}; for(int i=0; i < ANoteArray.length; i++) { if(pit == ANoteArray[i] && vel > 0){ redSquare(xPos, yPos-50, vel, vel); } } for(int i=0; i < DNoteArray.length; i++) { if(pit == DNoteArray[i] && vel > 0){ greenSquare(xPos, yPos+50, vel, vel); } } } void draw(){ noStroke(); fill(0, 10); rectMode(CORNER); rect(0, 0, width, height); noteChoice(); smooth(); }