Arduino Forum

Using Arduino => Audio => Topic started by: OzGrant on Mar 05, 2011, 12:00 am

Title: MIDI plus USB serial
Post by: OzGrant on Mar 05, 2011, 12:00 am
G'day,
I want to send a MIDI command via the USB and then send it out as a MIDI signal.
The MIDI lib used pin 0 and 1, as does the USB port.
Is there a way around this? Even a hardware solution would be welcomed.

Title: Re: MIDI plus USB serial
Post by: WilliamK Govinda on Mar 05, 2011, 01:24 am
There's a MIDI driver that takes MIDI Data from any Serial port. Since the Arduino sends Serial info via USB too, you could just use that driver and all is done. Just need to google for it, as I don't recall the name, sorry.

Wk
Title: Re: MIDI plus USB serial
Post by: OzGrant on Mar 05, 2011, 03:07 am
Have three different MIDI lib's all use tx/rx pins. Have another guy blending in NewSoftwareSerial Lib, but he has not finished yet.
So now want to try a Hardware solution, use a FET to switch between the usb chip and the MIDI signal.
Was hoping someone had done this already.
Title: Re: MIDI plus USB serial
Post by: Grumpy_Mike on Mar 08, 2011, 03:00 pm
Getting MIDI into a PC or Mac through the USB port
http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html (http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html)
Title: Re: MIDI plus USB serial
Post by: audioguytodd on Mar 13, 2011, 03:40 am

Getting MIDI into a PC or Mac through the USB port
http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html (http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html)


I have not tried that way because I saw this about it:
Quote
Lag times may be too long for some uses approximately 26ms (see below).


26 ms is just was to long for me.
Title: Re: MIDI plus USB serial
Post by: Grumpy_Mike on Mar 15, 2011, 07:49 pm
Quote
I have not tried that way because I saw this about it


So you believed this without any further details?

The latency will depend on the computer that implements it, so it is a bit rash to make a blanket condemnation of the whole system without further details. See if it works for your setup.

Quote
26 ms is just was to long for me.

Is this a real requirement or specmanship?
Title: Re: MIDI plus USB serial
Post by: ccblai on Mar 16, 2011, 04:59 am
The latency will depend on the computer that implements it, so it is a bit rash to make a blanket condemnation of the whole system without further details. See if it works for your setup.
Title: Re: MIDI plus USB serial
Post by: audioguytodd on Mar 18, 2011, 03:08 am

Quote
I have not tried that way because I saw this about it


So you believed this without any further details?

The latency will depend on the computer that implements it, so it is a bit rash to make a blanket condemnation of the whole system without further details. See if it works for your setup.

Quote
26 ms is just was to long for me.

Is this a real requirement or specmanship?


Well, I wasn't saying that nobody should try it. I will give it a try this week just to see.
Yes, <26ms is a requirement in my MIDI controller application. But for others it may not be that big of a deal.
Title: Re: MIDI plus USB serial
Post by: chloris on Mar 18, 2011, 06:35 am
Low latency audio via usb serial can be achieved with a realtime kernel. 

http://www.linuxjournal.com/video/hyper-low-latency-audio-real-time-kernel (http://www.linuxjournal.com/video/hyper-low-latency-audio-real-time-kernel)

Hope it helps.

Have fun.

Title: Re: MIDI plus USB serial
Post by: pjrc on Mar 23, 2011, 01:25 am
I recently added USB MIDI to Teensyduino.  It requires a AVR chip with native USB, like the one on Teensy.  Regular Arduino doesn't have this, unless you try using the 8u2 chip on Uno (which probably doesn't have enough memory, but if you compile for Teensy 1.0 and get a .HEX file under 4k, it might work).  If you have a compatible board, you should get latency of 1ms or less, and lots of bandwidth, since it's direct 12 Mbit/sec USB.  There's a send_now() function which forces any buffered data USB packet to be immediately made available to the USB host controller.  If you don't call send_now() after sending MIDI messages, the packet gets sent within the next 1ms USB frame.

This USB MIDI code is pretty new.  A few people have used it with success, and I sent and received a bunch of messages to/from Puredata.  If you give it a try, please let me know how it works for you.

Title: Re: MIDI plus USB serial
Post by: Sinborn on Apr 01, 2011, 03:35 am
The 26 ms is mostly from the Garage Band ->audio drivers->audio hardware part of the signal chain.  I would actually consider that good for a stock audio interface, trying to control a virtual instrument in real time.

I am building a MIDI encoder out of an Uno, and I could use a direct USB connection to a computer.  I may have to test this out, I really don't like how slow standard MIDI is  :P
Title: Re: MIDI plus USB serial
Post by: Grumpy_Mike on Apr 05, 2011, 06:44 pm
Quote
I really don't like how slow standard MIDI is

The use OSC - MIDI has been around for more years than I care to remember and it was obsolete 15 years ago. Problem is it is so simple and so ubiquitous. 
Title: Re: MIDI plus USB serial
Post by: audioguytodd on Apr 06, 2011, 03:53 am

Quote
I really don't like how slow standard MIDI is

The use OSC - MIDI has been around for more years than I care to remember and it was obsolete 15 years ago. Problem is it is so simple and so ubiquitous. 

Yes, I have been using MIDI professionally since 1985. It is amazing that the hardware manufacturers agreed to any standard at all. There have been many attempts to 'update' it (MIDI II, etc...) and the manufacturers are reluctant.
It is what it is.  :)
Title: Re: MIDI plus USB serial
Post by: Grag38 on Apr 06, 2011, 08:10 am
if it a serious trouble for use about using Serial AND Midi, you just have to upgrade to Arduino Mega !
It will allow you to use until 4 serial devices.
So from with one Midi I/O and with one Serial, you will get two serial left. Arduino Mega isn't so expensive !

Best regards

Grag38
Title: Re: MIDI plus USB serial
Post by: pjrc on Apr 06, 2011, 02:26 pm
You could also use Teensy, at $16, which uses native USB for very fast Serial.print(), and completely separate serial port you can use for MIDI.

It also has USB MIDI, and can do Serial.print() to the serial montitor window while sending MIDI at USB speed (in that mode it acts as a USB multifunction device for 2 communication channels on a single USB), and those are both separate from the serial port, so you can simultaneously send/receive MIDI there there too.  But there is only 1 serial port capable of 31250 baud MIDI, so if you want 2 actual serial ports, Arduino Mega and Sanguino are the only choices.

For full disclosure, I am involved with PJRC and Teensy.
Title: Re: MIDI plus USB serial
Post by: WilliamK Govinda on Apr 08, 2011, 07:30 pm
I was playing around with a code another user contributed, and created a VST plugin that reads the Serial data from our Beat707 unit and outputs Midi Notes. It works perfectly. Now I can also do a .exe app that does the same. Right now I'm doing it oriented to Beat707, but the idea is to make it open-source and based on Juce, so anyone can use it for their arduino midi projects without the need of a midi interface.

Wk
Title: Re: MIDI plus USB serial
Post by: audioguytodd on Apr 09, 2011, 04:17 am

I was playing around with a code another user contributed, and created a VST plugin that reads the Serial data from our Beat707 unit and outputs Midi Notes. It works perfectly. Now I can also do a .exe app that does the same. Right now I'm doing it oriented to Beat707, but the idea is to make it open-source and based on Juce, so anyone can use it for their arduino midi projects without the need of a midi interface.

Wk

That would be VERY useful WilliamK.  :)
Title: Re: MIDI plus USB serial
Post by: WilliamK Govinda on Apr 09, 2011, 07:20 pm
Here's a quick video of energyXT loading the VST file that connects to Beat707 via the USB cable. No MIDI devices were used for this example, but Beat707 is sending regular MIDI data via the Virtual Serial connected thanks to the FDI chip. Resuming: no hardware or software changes. (at least no big software changes)

http://www.youtube.com/watch?v=l0JL9lz6kvI

During the Beat707 startup, it starts at 57600bps, sends 4 bytes of a code to the serial output, waits 1 second, and if nothing is received, it re-starts the serial port at 31250bps and enables the midi connection.

The VST file checks all Serial ports, for each port, it waits 2 seconds, so the Arduino has time to reboot and send that 4 bytes of code above, and if the code the VST reads is ok, it sends an OK message back so the Arduino goes to USB mode. After that, they "talk" to each other. ;-)

Wk
Title: Re: MIDI plus USB serial
Post by: audioguytodd on Apr 11, 2011, 05:53 pm
That looks great!!!! Please announce it in this forum when you release the VST. I would love to give it a try!!! :)
Title: Re: MIDI plus USB serial
Post by: WilliamK Govinda on Apr 13, 2011, 01:15 am
The code is pretty much done, I just posted in a new thread.

http://arduino.cc/forum/index.php/topic,58334.0.html

Now I need to figure out the Stand-Alone version. ;-)

Wk