- tonyhughes
- Posts: 951
- Joined: Wed Dec 26, 2012 3:46 am
Send and receive MIDI commands to/from USB MIDI device
THIS STARTED AS A REQUEST FOR HELP, BUT IS SLOWLY TURNING INTO A HOWTO AS I FIGURE IT OUT MYSELF. JUMP IN IF YOU HAVE ANYTHING TO ADD.
I have:
Raspberry Pi Model B
Raspbian (latest updates, clean install)
Generic USB to MIDI adapter with in/out MIDI plugs ("Ashton" brand which is a cheapie brand of music gear here in NZ selling just about everything, so clearly theyre just packaging up cheap and cheerful Chinese stuff).
Boss GT100 guitar multieffects unit with MIDI out (sends Program Changes and some CCs, but not Notes).
Cheap generic unbranded 192 channel DMX lighting controller (similar to Chauvet Obey 40), with MIDI in (*only* accepts MIDI Notes).
I need an intermediary device to translate the GT100 MIDI messages into MIDI messages the DMX controller can understand.
Bome Midi Translator Classic works perfectly and requires a Windows 7 machine to do the job. I have this working now.
I'd rather use a Raspberry Pi which is cheaper, and more durable in terms of being loaded in and out of vehicles with other gear 8 times a week for gigs.
Actual function is to change our stage lighting (turn it on and off, change scenes/colours/chases etc) when I select presets on my GT100, as we dont have a sound/lighting person, but would like more variation than just having "auto" or "sound" turned on.
I want to listen for incoming MIDI commands (which may be CC's or PC's), and I want to send MIDI commands (Notes).
(Basically take and incoming message, use another program to evaluate it, and generate a new outgoing message)
The incoming messages should be either written to a file or passed as an argument to another program.
The outgoing messages should be received as arguments, or picked up from a file.
(I am happy and comfortable writing a BASH script to perform the middle bits)
The Pi will be dedicated to the task, so Im open to any OS.
Latency is not an issue at all for me, this is not for audio.
I have:
Raspberry Pi Model B
Raspbian (latest updates, clean install)
Generic USB to MIDI adapter with in/out MIDI plugs ("Ashton" brand which is a cheapie brand of music gear here in NZ selling just about everything, so clearly theyre just packaging up cheap and cheerful Chinese stuff).
Boss GT100 guitar multieffects unit with MIDI out (sends Program Changes and some CCs, but not Notes).
Cheap generic unbranded 192 channel DMX lighting controller (similar to Chauvet Obey 40), with MIDI in (*only* accepts MIDI Notes).
I need an intermediary device to translate the GT100 MIDI messages into MIDI messages the DMX controller can understand.
Bome Midi Translator Classic works perfectly and requires a Windows 7 machine to do the job. I have this working now.
I'd rather use a Raspberry Pi which is cheaper, and more durable in terms of being loaded in and out of vehicles with other gear 8 times a week for gigs.
Actual function is to change our stage lighting (turn it on and off, change scenes/colours/chases etc) when I select presets on my GT100, as we dont have a sound/lighting person, but would like more variation than just having "auto" or "sound" turned on.
I want to listen for incoming MIDI commands (which may be CC's or PC's), and I want to send MIDI commands (Notes).
(Basically take and incoming message, use another program to evaluate it, and generate a new outgoing message)
The incoming messages should be either written to a file or passed as an argument to another program.
The outgoing messages should be received as arguments, or picked up from a file.
(I am happy and comfortable writing a BASH script to perform the middle bits)
The Pi will be dedicated to the task, so Im open to any OS.
Latency is not an issue at all for me, this is not for audio.
Last edited by tonyhughes on Wed Apr 13, 2016 6:29 am, edited 2 times in total.
- tonyhughes
- Posts: 951
- Joined: Wed Dec 26, 2012 3:46 am
Re: Send and receive MIDI commands to/from USB MIDI device
I have run
amidi -l
and my USB devices ports are listed (No extra software had to be installed). Yay.
Next step - see if i can see some midi data on screen by specifying the port in amidi and dumping output to screen.
amidi -l
and my USB devices ports are listed (No extra software had to be installed). Yay.
Next step - see if i can see some midi data on screen by specifying the port in amidi and dumping output to screen.
- tonyhughes
- Posts: 951
- Joined: Wed Dec 26, 2012 3:46 am
Re: Send and receive MIDI commands to/from USB MIDI device
Plugged in a MIDI device
used
$ amidi --port="hw:1,0,0" --dump
To specifiy the first port for my device listed in $ amidi -l
Pressed my first foot controller button and got the following output:
Pressed the second button and got
and third got
Theres a clear pattern to these obviously 
These should be the codes for standard MIDI program control messages.
I also have some switches on my device that send CCs... Ill try that...
First one is sending
Second one is sending
Remaining tasks (help if you know how please!!!)
used
$ amidi --port="hw:1,0,0" --dump
To specifiy the first port for my device listed in $ amidi -l
Pressed my first foot controller button and got the following output:
Code: Select all
B0 00 00
90 20 00
C0 00Code: Select all
B0 00 00
90 20 00
C0 01Code: Select all
B0 00 00
90 20 00
C0 02These should be the codes for standard MIDI program control messages.
I also have some switches on my device that send CCs... Ill try that...
First one is sending
Code: Select all
B0 01 7F
B0 01 00Code: Select all
B0 02 7F
90 02 00Remaining tasks (help if you know how please!!!)
- Get these messages through to my BASH script where I can read them, and decide what outgoing message to generate based on it.
Send an outgoing MIDI message on the second port.
- tonyhughes
- Posts: 951
- Joined: Wed Dec 26, 2012 3:46 am
Re: Send and receive MIDI commands to/from USB MIDI device
Code: Select all
amidi --port="hw:,0,0" --receive-mididata.syxAny ideas on getting this information written as plain text?
** EDIT - it was blindingly simple.... just redirect output of the amidi dump command to a file with bash.
Code: Select all
amidi --port="hw:,0,0" -d > mididata.txt
Now to get a script to hopefully tail the file and act upon on it (im only expecting one new midi message every 10 seconds or more, so I can just brutally hit the file constantly for a new message in the last line several times a second - not pretty, but it will get me going).
- tonyhughes
- Posts: 951
- Joined: Wed Dec 26, 2012 3:46 am
Re: Send and receive MIDI commands to/from USB MIDI device
Happily tail-ing the text file 50 times a second, and displaying the last line of the tail to screen. Keeps up beautifully with a midi rocker pedal. Just using
and a loop in Bash to do it 50 times a second.
Next to do something with the tail output (but only if its changed, as I dont want to hit the DMX controller 50 times a second!).
Code: Select all
tail -n1 midi.txtNext to do something with the tail output (but only if its changed, as I dont want to hit the DMX controller 50 times a second!).
- tonyhughes
- Posts: 951
- Joined: Wed Dec 26, 2012 3:46 am
Re: Send and receive MIDI commands to/from USB MIDI device
Looks like I'll set a variable to be the contents of the tail command, and then I can set up a series of IF statements for my MIDI translations (will only be around 12 MIDI translations, so 12 IF statements), and if one of them is a hit, it can send its new MIDI message to the output MIDI port via amidi.
Re: Send and receive MIDI commands to/from USB MIDI device
You seem to be moving along, and that's great, but if I understand you, you're going to have problems sending MIDI data out over USB. The Pi/2/3 acts only as a host, not as a device, so you cannot plug another host into a USB port, and have the Pi act as a MIDI device.
-
6by9
- Raspberry Pi Engineer & Forum Moderator

- Posts: 11443
- Joined: Wed Dec 04, 2013 11:27 am
- Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
Re: Send and receive MIDI commands to/from USB MIDI device
I assume you've found the MIDI spec to interpret your hex dumps - https://www.midi.org/specifications/cat ... nce-tables
It wasn't clear from your comment as to whether you'd seen a pattern, or had actually interpreted them.
Code: Select all
B0 00 00 Chan 1, Bank Select 0
90 20 00 Chan 1, Note 32 on, velocity 0 (interpreted as note off)
C0 00 Chan 1, Program Change 0Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
-
sjcaldwell
- Posts: 5
- Joined: Thu Apr 28, 2016 5:21 pm
Re: Send and receive MIDI commands to/from USB MIDI device
So if I have the following setup, should it work:
Controller with Midi out connected to Midi to USB converter going into my a PI usb port
Device with Midi in connected to Midi to USB converter cable coming out of separate PI usb port
Can I convert what is coming in from the controller to what I want to go to the device?
Controller Midi Out -> Converter Cable -> PI - USB1 -> PI -> PI USB2 -> Converter Cable - Device Midi Out
I'd like to take a single Program change from the controller and have it generate a series of events to midi out
IE
PC1 Channel 1 -> Converter Software on PI -> PC1 Channel 1
-> CC #32 value 0 (Bank Select) Channel 2
-> PC5 Channel 2
-> CC#7 value 0 (volument - Channel 2
... And maybe more
This way I could control multiple midi devices with a single control change on my midi controller.
Controller with Midi out connected to Midi to USB converter going into my a PI usb port
Device with Midi in connected to Midi to USB converter cable coming out of separate PI usb port
Can I convert what is coming in from the controller to what I want to go to the device?
Controller Midi Out -> Converter Cable -> PI - USB1 -> PI -> PI USB2 -> Converter Cable - Device Midi Out
I'd like to take a single Program change from the controller and have it generate a series of events to midi out
IE
PC1 Channel 1 -> Converter Software on PI -> PC1 Channel 1
-> CC #32 value 0 (Bank Select) Channel 2
-> PC5 Channel 2
-> CC#7 value 0 (volument - Channel 2
... And maybe more
This way I could control multiple midi devices with a single control change on my midi controller.
Re: Send and receive MIDI commands to/from USB MIDI device
I don't believe so, as I said.
-
sjcaldwell
- Posts: 5
- Joined: Thu Apr 28, 2016 5:21 pm
Re: Send and receive MIDI commands to/from USB MIDI device
I'll give it a try because the cable I'm using is USB to Midi so I don't see why it wouldn't work. It seems to me on the Midi side of the cable it wouldn't care, it is just either midi in or out device. Midi connectors have not concept of host verses device, just in midi in and midi out.
The below is a single midi to USB cable
PI USB ---------------------------------------------> Midi Out to Target Midi Device
+--------------------------------------------< Midi In From Controller
Object of the PI would be to take Midi In - And put it into a file. PI applicsation would then read the file, translate it and then send translated to Midi out.
Are you saying you cannot send Midi commands out from A PI?
The below is a single midi to USB cable
PI USB ---------------------------------------------> Midi Out to Target Midi Device
+--------------------------------------------< Midi In From Controller
Object of the PI would be to take Midi In - And put it into a file. PI applicsation would then read the file, translate it and then send translated to Midi out.
Are you saying you cannot send Midi commands out from A PI?
-
sjcaldwell
- Posts: 5
- Joined: Thu Apr 28, 2016 5:21 pm
Re: Send and receive MIDI commands to/from USB MIDI device
I'm able to do this
amidi --port="hw:1,0,0" --dump > mididata.txt
amidi --port="hw:,1,0,0" -S `cat mididata.txt"
The first command reads from the input port (controller) and stores the data
The second commend takes the file and passes it to the output port (my device) (same USB converter cable) and it works.
So I know the interface will work and I can pass the commands from midi in (controller) to midi out (device) using the usb converter cable on my PI.
Next step is to figure out how to take the input, and based on different input parameters, map it to specific output parameters.
So essentially I know it is possible with the right programming and standard midi to USB cable. No special midi interface card I need to develop. Just a software exercise now.
amidi --port="hw:1,0,0" --dump > mididata.txt
amidi --port="hw:,1,0,0" -S `cat mididata.txt"
The first command reads from the input port (controller) and stores the data
The second commend takes the file and passes it to the output port (my device) (same USB converter cable) and it works.
So I know the interface will work and I can pass the commands from midi in (controller) to midi out (device) using the usb converter cable on my PI.
Next step is to figure out how to take the input, and based on different input parameters, map it to specific output parameters.
So essentially I know it is possible with the right programming and standard midi to USB cable. No special midi interface card I need to develop. Just a software exercise now.
Re: Send and receive MIDI commands to/from USB MIDI device
Hey sjcaldwell,
Love this post and have a few questions if you wouldn't mind helping out a complete newbie.
I'm looking to do something similar, create just essentially a midi controller that all it does is has multiple inputs, maybe one is connected to a synth, another to a drum machine, etc.
Either through an external hard drive or SD card there would be already edited and created midi files.
It shouldn't be a problem for me to send those midi files TO the different devices, right? You never went any farther with your posts after stating you thought it was possible.
I know Python and have been messing around with the PI, ultimately I will probably use an arduino and PI combo, but how did this end up working for you and do you think what I was explaining is possible?
ANY advice or help is greatly appreciated, thanks again for posting your progress!
Love this post and have a few questions if you wouldn't mind helping out a complete newbie.
I'm looking to do something similar, create just essentially a midi controller that all it does is has multiple inputs, maybe one is connected to a synth, another to a drum machine, etc.
Either through an external hard drive or SD card there would be already edited and created midi files.
It shouldn't be a problem for me to send those midi files TO the different devices, right? You never went any farther with your posts after stating you thought it was possible.
I know Python and have been messing around with the PI, ultimately I will probably use an arduino and PI combo, but how did this end up working for you and do you think what I was explaining is possible?
ANY advice or help is greatly appreciated, thanks again for posting your progress!
-
sjcaldwell
- Posts: 5
- Joined: Thu Apr 28, 2016 5:21 pm
Re: Send and receive MIDI commands to/from USB MIDI device
Never went any further. Too much other stuff going on. Ended up buying Bome midi translator on my small laptop windows PC.
Just no time for my programming hobby for now.
Just no time for my programming hobby for now.
Re: Send and receive MIDI commands to/from USB MIDI device
Sorry to dig out 1 year old post but :
Great great work, thanks a lot !
Did you manage to send MIDI out ?
YCN-
Great great work, thanks a lot !
Did you manage to send MIDI out ?
YCN-
-
sjcaldwell
- Posts: 5
- Joined: Thu Apr 28, 2016 5:21 pm
Re: Send and receive MIDI commands to/from USB MIDI device
No I went the easy route and bought a Bomebox
-
theotherdavidcook
- Posts: 1
- Joined: Mon May 22, 2017 6:08 pm
Re: Send and receive MIDI commands to/from USB MIDI device
I get what he's doing... I do the same but I have it set up using a Novation like grid controller.
The PAD generates MIDI messages which is fed thru USB/MIDI to the Pi... which is running QLC+ Lighting controller software. QLC in turn generates the DMX output which is routed to the USB->DMX dongle selected in QLC setup.
From what I understand, as long as you are getting MIDI thruput, you should be able to do this...
My rig uses a Launchpad clone, providing 64 scene/chase/fx buttons, and 16 'bump' buttons. All are fully configurable withing QLC. Basically you create a 'scene or function' then assign that to a MIDI note/CC/PRGCHG/etc.
___________ . . . . . . . . .______
| Launchpad |---------------->| R Pi3 | ----------------> Lights
|__________| (usb-midi) . |______| (usb-dmx)
The PAD generates MIDI messages which is fed thru USB/MIDI to the Pi... which is running QLC+ Lighting controller software. QLC in turn generates the DMX output which is routed to the USB->DMX dongle selected in QLC setup.
From what I understand, as long as you are getting MIDI thruput, you should be able to do this...
My rig uses a Launchpad clone, providing 64 scene/chase/fx buttons, and 16 'bump' buttons. All are fully configurable withing QLC. Basically you create a 'scene or function' then assign that to a MIDI note/CC/PRGCHG/etc.
___________ . . . . . . . . .______
| Launchpad |---------------->| R Pi3 | ----------------> Lights
|__________| (usb-midi) . |______| (usb-dmx)
Re: Send and receive MIDI commands to/from USB MIDI device
Hi,
You too dug this many year old post ahah!
You got a nice project, from your message I don't really get if you did it or not.
My question here was to generate MIDI out, from my investigation, MIDI is only some serial communication with a specific baudrate and specific way of talking, but I still don't really know if I can sen MIDI from the pi without any extra hardware.
I'm still thinking about building a MIDI keypad with the RPi, but I didn't take the time yet.
If you have any leads about that I'll be happy to get them !
YCN
You too dug this many year old post ahah!
You got a nice project, from your message I don't really get if you did it or not.
My question here was to generate MIDI out, from my investigation, MIDI is only some serial communication with a specific baudrate and specific way of talking, but I still don't really know if I can sen MIDI from the pi without any extra hardware.
I'm still thinking about building a MIDI keypad with the RPi, but I didn't take the time yet.
If you have any leads about that I'll be happy to get them !
YCN
Re: Send and receive MIDI commands to/from USB MIDI device
Hey guys im working on a similar project involving a USB MIDI interface. I was wondering if anyone knew how to send the incoming midi commands as arguments or something to a python program in REALTIME (important cause im making this floppy drive piano thing actual musical instrument). Basically i need the output from the "amidi --port="hw:1,0,0" --dump" command as a variable in a python program or something.
Re: Send and receive MIDI commands to/from USB MIDI device
Hi
I own a similar USB midi device I use for a project of mine. I had to perform some tests using input and outpout, and I did it very easily with python and rtmidi package this way :
If you're comfortable with BASH, Python will be a piece of cake.
Don't hesitate if you have questions about this
Regards
Damien
I own a similar USB midi device I use for a project of mine. I had to perform some tests using input and outpout, and I did it very easily with python and rtmidi package this way :
Code: Select all
import time
import rtmidi
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
print "use this list to know what device you have to use as ouput :"
print "out : " + str(available_ports)
midiin = rtmidi.MidiIn()
available_ports_in = midiin.get_ports()
print "use this list to know what device you have to use as input :"
print "in : " + str(available_ports_in)
midiout.open_port(1)
midiin.open_port(0) #I chose 0 but you may have to choose another one, depending on your config
midiin.set_callback(input_callback)
def input_callback(a, b):
print "received " + str(a, b)
outBytes = []
print "write your conversion routines here"
outBytes.append(1)
outBytes.append(2)
print "then send result :"
midiout.send_message(note_off)
while True:
#have to wait here as anything happens in callback
time.sleep(1)Don't hesitate if you have questions about this
Regards
Damien
Re: Send and receive MIDI commands to/from USB MIDI device
Hi YCN
You can send/receive MIDI data with the embedded UART of the RPi... but you did not mention that MIDI requires also an electrical adaptation, that make the UART unusable as is.
You can find a lot of things on the internet about it, but you need extra hardware.
My USB MIDI adapter cost me 12€ (I actually bought it without any idea of what I could do with it) and does the job.
Making your own electrical interface will be more expensive for sure.
For my needs, I used an arduino as MIDI sender (Arduino UNO + 2 resistors, but it could be done without the arduino and with Tx signal of RPi). The receiver circuit, connected to the Rx pin of the RPi, is very simple, but needs you to buy needed components and tools and to spend some time building it.
Then you'll have to configure your kernel and develop a piece of software program.
No doubt the USB MIDI device is simplier ! You only have to develop the piece of software program.
The project I'm working on requires very low latency, so I did build the circuit (only receiver side), configure the kernel and develop my piece of software program (C++). If you want to do the same, I can help you.
Regards
Damien
You can send/receive MIDI data with the embedded UART of the RPi... but you did not mention that MIDI requires also an electrical adaptation, that make the UART unusable as is.
You can find a lot of things on the internet about it, but you need extra hardware.
My USB MIDI adapter cost me 12€ (I actually bought it without any idea of what I could do with it) and does the job.
Making your own electrical interface will be more expensive for sure.
For my needs, I used an arduino as MIDI sender (Arduino UNO + 2 resistors, but it could be done without the arduino and with Tx signal of RPi). The receiver circuit, connected to the Rx pin of the RPi, is very simple, but needs you to buy needed components and tools and to spend some time building it.
Then you'll have to configure your kernel and develop a piece of software program.
No doubt the USB MIDI device is simplier ! You only have to develop the piece of software program.
The project I'm working on requires very low latency, so I did build the circuit (only receiver side), configure the kernel and develop my piece of software program (C++). If you want to do the same, I can help you.
Regards
Damien
Re: Send and receive MIDI commands to/from USB MIDI device
In the Wolfram Language you can open a stream to read the output from "amidi -p <port> -d"
The variable "r" gets updated at every incoming sysex signal from your device.
Code: Select all
Close /@ Streams[]; // Quiet
stream = OpenRead@"!amidi -p <port> -d";
While[r =!= EndOfFile ,
r = ReadLine@stream ]Re: Send and receive MIDI commands to/from USB MIDI device
Hi guys,
Thanks for the feedback, actually, I'm going to use another uC to do the midi message sending, it will also have some ADCs and DACs for buttons and also possibly for a CV out.
This way I will do the following, the linux board (RPI for now) will do the high level processing : UI (with a screen) and audio processing and also treatment of the I/O.
And the uC will do the Real time processing : sending the msg onto the MIDI UART and also handling the audio out and CV out. This seems to be doable at least for the initial POC. And might be easily maintainable. I believe RPI is a little bit too much for what I want to do, but let's see.
Regards,
YCN-
Thanks for the feedback, actually, I'm going to use another uC to do the midi message sending, it will also have some ADCs and DACs for buttons and also possibly for a CV out.
This way I will do the following, the linux board (RPI for now) will do the high level processing : UI (with a screen) and audio processing and also treatment of the I/O.
And the uC will do the Real time processing : sending the msg onto the MIDI UART and also handling the audio out and CV out. This seems to be doable at least for the initial POC. And might be easily maintainable. I believe RPI is a little bit too much for what I want to do, but let's see.
Regards,
YCN-
Re: Send and receive MIDI commands to/from USB MIDI device
I just buying the gear (including my first RPi; should be arriving today) for a very similar project.
I'm going to read through all the comments here with interest, but here's what I'm planning...
I'm currently using QLC+ on a win10 PC for my lighting controller software.
I have an enttec USB DMX pro dongle, and I use a BOSS ES-5 with midi out to control my effects pedals and to send the PC data for switching lighting patterns.
QLC+ is free and open source, but for a small fee you can get a custom image for the RPi SD card (I don't know what its based on).
There is a good forum on the QLC+ page for support, and I've already spoken to users on there that have working projects using a RPi with midi input. There is even a low cost, DIY DMX controller post on there.
My plan is to use my new RPi 3B+ with the custom QLC+ image, a powered usb hub created for the RPi, my enttec dongle and a Roland UM-ONE mk2 usb to midi cable. Once that is up and running I want to create a hat with MIDI in / DMX out connectors so its all self contained.
The QLC+ image for the RPi can be configured so that at power up of the RPi it opens the software, loads your lighting file, and starts playback. I've been told this works fine, but haven't had chance to try it myself.
I'm going to read through all the comments here with interest, but here's what I'm planning...
I'm currently using QLC+ on a win10 PC for my lighting controller software.
I have an enttec USB DMX pro dongle, and I use a BOSS ES-5 with midi out to control my effects pedals and to send the PC data for switching lighting patterns.
QLC+ is free and open source, but for a small fee you can get a custom image for the RPi SD card (I don't know what its based on).
There is a good forum on the QLC+ page for support, and I've already spoken to users on there that have working projects using a RPi with midi input. There is even a low cost, DIY DMX controller post on there.
My plan is to use my new RPi 3B+ with the custom QLC+ image, a powered usb hub created for the RPi, my enttec dongle and a Roland UM-ONE mk2 usb to midi cable. Once that is up and running I want to create a hat with MIDI in / DMX out connectors so its all self contained.
The QLC+ image for the RPi can be configured so that at power up of the RPi it opens the software, loads your lighting file, and starts playback. I've been told this works fine, but haven't had chance to try it myself.
Re: Send and receive MIDI commands to/from USB MIDI device
Digging out this old thread again since somebody might find these helpful:
https://github.com/aiobofh/midi-utils
https://pypi.org/project/mido/
http://confusionstudios.com/mjdj/
https://github.com/aiobofh/midi-utils
https://pypi.org/project/mido/
http://confusionstudios.com/mjdj/