Hello people!
Firstly I'd like to say I'm not an advanced user so please be patient with me if I say stupid things ! and thanks in advance!!
I've been trying to use USB-MIDI Devices without computer (using standard Serial MIDI with 5 pin DIN conectors) for my Music Gigs. I recently managed to do so using the USB Host Shield V2 from Circuit at home.
The USB Host Shield:
http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino
Using the Library and Example that Yuuichi Akagawa provided in this link:
The circuit is very basic, Arduino UNO, with USB-Host Shield on top, and a MIDI output from Arduino TX using an 220ohm resistor.
With the example from Yuuichi Akagawa, I managed to recieve successfully and "translate" to standard MIDI a few USB-MIDI controllers already... I thought everything was working 100% perfect untill I recieve the other day my new MIDI Controller, The Quneo by Keith McMillen: QuNeo USB MIDI Drum Pad Controller for Music Production | Keith McMillen Instruments
The special thing about this controller is that is capable of sending multiple MIDI values from each button (or sensor). Each of the buttons can send Note on-off + Velocity, CC of the pressure applied, X and Y position also using CC´s (Midi Control Changes). In total is capable of sending 4 MIDI values simulateously...
Using MIDI-OX which is a MIDI Monitor application for PC, I can visualize the Stream of MIDI data recieved by the controller. Using the controller with the provided USB straight in to the computer, the MIDI Stream shows how certain MIDI values arrive all at the same time. All the values are recieved as expected.
www.inspektorgadjet.com/Downloads/Using-USB.jpg
However if I use the Arduino solution, many values are missed, and some not recieved at all... I think this is due to the fact that the Controller is sending some of this values exactly at the same time, and Arduino is listening to just one MIDI message at a time. In this case the MIDI Monitor shows that the stream of values is unconsistent... and all the values are recieved in different times, there is no 2 values hapening at the same time.
www.inspektorgadjet.com/Downloads/using-arduino.jpg
So my question is, how can I manage this multiple values simultaneously?
Thanks a lot!!
/*
*******************************************************************************
* USB-MIDI to Legacy Serial MIDI converter
*
* Idea from LPK25 USB-MIDI to Serial MIDI converter
*Â by Collin Cunningham - makezine.com
*******************************************************************************
*/
#include <Usb.h>
#include <usbhub.h>
#include <usbh_midi.h>
USBÂ Usb;
USBHub Hub1(&Usb);
MIDIÂ Midi1(&Usb);
MIDIÂ Midi2(&Usb);
void MIDI_poll();
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);
void setup()
{
 Serial.begin(31250);
 if (Usb.Init() == -1) {
  while(1); //halt
 }
 delay(200);
}
void loop()
{
 unsigned long t1;
 Usb.Task();
 t1 = micros();
 if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
 {
  MIDI_poll();
 }
 doDelay(t1, micros(), 10);
}
// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
  byte outBuf[ 3 ];
  uint8_t size;
  if( (size=Midi1.RcvData(outBuf)) > 0 ){
   //MIDI Output
   Serial.write(outBuf, size);
  }
  if( (size=Midi2.RcvData(outBuf)) > 0 ){
   //MIDI Output
   Serial.write(outBuf, size);
  } Â
}
// Delay time (max 16383 us)
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime)
{
  unsigned long t3;
  if( t1 > t2 ){
   t3 = (4294967295 - t1 + t2);
  }else{
   t3 = t2 - t1;
  }
  if( t3 < delayTime ){
   delayMicroseconds(delayTime - t3);
  }
}