We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › MIDI-Albeton-MidiYoke-Processing-Arduino-HELP!
Page Index Toggle Pages: 1
MIDI-Albeton-MidiYoke-Processing-Arduino-HELP! (Read 716 times)
MIDI-Albeton-MidiYoke-Processing-Arduino-HELP!
Mar 6th, 2010, 9:27am
 
Hi!
I am totally new to processing and any kind of programming so am on a bit of a steep learning curve!

I am trying to control 13 digital output pins on my arduino using a MIDI file.

I have managed to get Processing to read MIDI in from Albeton Live via MIDIYoke, and have tested this is working using the proMIDI example 'reflection'.  I get a pattern being drawn. So thats good!

With a bit of help from a friend (a lot of help actually - he wrote it!) I have a file that should convert the MIDI to digital pin HIGH with a duration on the arduino with Firmata uploaded to it.

But it's not working!!!...

If anyone has experience in doing this I would really appreciate some help!
:)

This is the file:

-----------------------

import promidi.*;
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
MidiIO midiIO;

int numOfpins = 13;
Anote[] theNotes = new Anote[numOfpins]; //index of array == the pin num

void setup() {
 //size(400,400);
 background(50);
 
 println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[2], 57600);
 
  midiIO = MidiIO.getInstance(this);
  println("printPorts of midiIO");
  midiIO.printDevices();
  midiIO.openInput(1,0);
 
  for (int i = 0; i < numOfpins; i++){
    arduino.pinMode(i, Arduino.OUTPUT);
  }
 
  for (int i = 0; i < numOfpins; i++){
    theNotes[i] = new Anote(0,0);
  }

}



void draw() {
 //doRandomNote();
 
 int currentTime = millis();
 println("time: " + currentTime);
 for(int i=0;i < numOfpins;i++){    
   if((currentTime > theNotes[i].start) && (currentTime < theNotes[i].stop)){
     arduino.digitalWrite(i, Arduino.HIGH);
     println("set pin "+ i +" high" + " @ "+ theNotes[i].start + "millis");
   }else{
     arduino.digitalWrite(i, Arduino.LOW);
     println("set pin "+ i +" low"+ " @ "+ theNotes[i].start + "millis");
   }
 }
 
}


void noteOn(Note note, int deviceNumber, int midiChannel){
 int vel = note.getVelocity();
 //if(vel < 60) vel = 60;
 int pit = note.getPitch();
 //convert pitch to pin
 int mypin = pit - 60; //A above middle C == 69 midi and C is on pin 0
 //convert velocity to duration on pin
 int mydur = (int)map(vel,0,127,50,150);  //max duration = 30 milleseconds
 theNotes[mypin].start = millis();
 theNotes[mypin].stop = theNotes[mypin].start + mydur;
}

/*
void doRandomNote(){
 if (millis()%1000 <= 100){
   println("set note");
   //int i = int(random(12));
   int i = 13;
   theNotes[i].start = millis();
   theNotes[i].stop = theNotes[i].start + 500;
 }
}
*/

class Anote{
 int stop; //millis
 int start;  //millis
 Anote(int stTime, int durMill){
   start = stTime;
   stop = durMill + start;
 }
}

-----------------------

and this is the message I get:





Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
[0] "COM3"
[1] "COM4"
[2] "COM5"
printPorts of midiIO
<< inputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
input 0 : In From MIDI Yoke:  1
input 1 : In From MIDI Yoke:  2
<< outputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
output 0 : Microsoft MIDI Mapper
output 1 : Microsoft GS Wavetable Synth
output 2 : Out To MIDI Yoke:  1
output 3 : Out To MIDI Yoke:  2
output 4 : Java Sound Synthesizer
<<>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

[color=#ff0000][color=#ff0000]Disabling noteOn() for panel0 because of an error.
java.lang.reflect.InvocationTargetException
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at promidi.MidiIn.sendNoteOn(MidiIn.java:168)
     at promidi.MidiInDevice.send(MidiInDevice.java:112)
     at com.sun.media.sound.AbstractMidiDevice$TransmitterList.sendMessage(AbstractMidiD
evice.java:675)
     at com.sun.media.sound.MidiInDevice.callbackShortMessage(MidiInDevice.java:158)
     at com.sun.media.sound.MidiInDevice.nGetMessages(Native Method)
     at com.sun.media.sound.MidiInDevice.run(MidiInDevice.java:126)
     at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
     at midiArduino2.noteOn(midiArduino2.java:81)
     ... 11 more
time: 5001
set pin 0 low @ 0millis
set pin 1 low @ 0millis
set pin 2 low @ 0millis
set pin 3 low @ 0millis
set pin 4 low @ 0millis
set pin 5 low @ 0millis
set pin 6 low @ 0millis
set pin 7 low @ 0millis
set pin 8 low @ 0millis
set pin 9 low @ 0millis
set pin 10 low @ 0millis
set pin 11 low @ 0millis
set pin 12 low @ 0millis


Anyone know where I'm going wrong?!

Thanks!
Page Index Toggle Pages: 1