Python to send Midi commands to iPad via USB

M

mikprog

Dear all,

I am asking for a design/strategy suggestion.

What I have to do is to write a Python application that will send MIDI commands to an iPad application.
All I know is that the iPad application can be connected to an external Midi deck through a usb cable and be controlled.
So I think I would connect the iPad via USB to my computer and... try to send midi commands.
I think the limitation is that the iPad will allow signaling/connection only to Midi devices, so I have to make so that my Python script pretends that my computer is a Midi device.
So far I have tried PyUSB library and I can see the iPad, but I can't send anything to it (probably because I am not pretending to be a Midi device well enough).

I am keen to try PyUSB + pygame for the Midi stuff.

Any suggestion / recommendation / hint / whatever to tell me?
I appreciate every idea at this stage!

Thanks for reading,
Mik
 
C

Chris Angelico

What I have to do is to write a Python application that will send MIDI commands to an iPad application.
All I know is that the iPad application can be connected to an external Midi deck through a usb cable and be controlled.
So I think I would connect the iPad via USB to my computer and... try to send midi commands.

Are you able to hook into ALSA? I've had reasonable success driving a
USB-MIDI cable using ALSA. See if you can do it with the inbuilt
'pmidi' app first:

$ pmidi -p 128:0 No.19.mid

(that uses port 128:0 which is a TiMidity-provided one)

If that works, you can then look for Python ALSA bindings, which I
believe are available on PyPI.

My example is from Linux, so you may need to tweak things on other OSes.

ChrisA
 
M

mikprog

On Thursday, January 24, 2013 10:44:47 AM UTC, Chris Angelico wrote:
[..]
Are you able to hook into ALSA? I've had reasonable success driving a

USB-MIDI cable using ALSA. See if you can do it with the inbuilt

'pmidi' app first:



$ pmidi -p 128:0 No.19.mid



(that uses port 128:0 which is a TiMidity-provided one)



If that works, you can then look for Python ALSA bindings, which I

believe are available on PyPI.

Thanks for your help Chris!
forgive my ignorance, but I am not sure what you mean.
I've installed pmidi and what I get is:

~$ pmidi -p 128:0 No.19.mid
Could not open file No.19.mid

Doesn't that mean that the iPad is not seen?

where:
~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 005 Device 002: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
Bus 003 Device 003: ID 413c:8157 Dell Computer Corp. Integrated Keyboard
Bus 003 Device 004: ID 413c:8158 Dell Computer Corp. Integrated Touchpad / Trackstick
Bus 006 Device 002: ID 192f:0416 Avago Technologies, Pte.
Bus 002 Device 003: ID 05ac:12a4 Apple, Inc.


Essentially the reason to use the iPad is because we have to make a demo where with our hardware we send midi commands and the iPad has a very good DJ application that can be used with a USB midi controller.
So I wish to connect our hardware to a Raspberry Pi (or similar) via BLE and then the board (Raspberry Pi) to the iPad through USB cable.

I think the weak point is communication from the Raspberry Pi (or PC) to the iPad via USB. I could actually remove that if I find a decent Linux/Python application that acts as a DJ deck.

I am having a look at pygame.midi as well, but I am not sure how to link that with a USB cable.

mik
 
M

mikprog

On Thursday, January 24, 2013 10:44:47 AM UTC, Chris Angelico wrote:
[..]
Are you able to hook into ALSA? I've had reasonable success driving a

USB-MIDI cable using ALSA. See if you can do it with the inbuilt

'pmidi' app first:



$ pmidi -p 128:0 No.19.mid



(that uses port 128:0 which is a TiMidity-provided one)



If that works, you can then look for Python ALSA bindings, which I

believe are available on PyPI.

Thanks for your help Chris!
forgive my ignorance, but I am not sure what you mean.
I've installed pmidi and what I get is:

~$ pmidi -p 128:0 No.19.mid
Could not open file No.19.mid

Doesn't that mean that the iPad is not seen?

where:
~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 005 Device 002: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
Bus 003 Device 003: ID 413c:8157 Dell Computer Corp. Integrated Keyboard
Bus 003 Device 004: ID 413c:8158 Dell Computer Corp. Integrated Touchpad / Trackstick
Bus 006 Device 002: ID 192f:0416 Avago Technologies, Pte.
Bus 002 Device 003: ID 05ac:12a4 Apple, Inc.


Essentially the reason to use the iPad is because we have to make a demo where with our hardware we send midi commands and the iPad has a very good DJ application that can be used with a USB midi controller.
So I wish to connect our hardware to a Raspberry Pi (or similar) via BLE and then the board (Raspberry Pi) to the iPad through USB cable.

I think the weak point is communication from the Raspberry Pi (or PC) to the iPad via USB. I could actually remove that if I find a decent Linux/Python application that acts as a DJ deck.

I am having a look at pygame.midi as well, but I am not sure how to link that with a USB cable.

mik
 
C

Chris Angelico

Thanks for your help Chris!
forgive my ignorance, but I am not sure what you mean.
I've installed pmidi and what I get is:

~$ pmidi -p 128:0 No.19.mid
Could not open file No.19.mid

Doesn't that mean that the iPad is not seen?

Heya! That was just an example; I used track number 19 from the opera
"Iolanthe" as my test file. Pick any other MIDI file you have handy.
Though, I may have my commands mixed up; aplaymidi may be more what
you want.

In any case, the key is the port number. Try this to enumerate ports:

$ aplaymidi -l

That's lower-case l for list. If that tells you about something that
looks like your iPad, you're in luck, ALSA has already done most of
the work! And you should be able to play any file with:

$ aplaymidi -p X:Y some-file.mid

where X:Y is from the first column of aplaymidi -l output.

On my system currently, I have 128:0 through 128:3 from TiMidity, and
14:0 "Midi Through". When my USB device is connected, I get a couple
more ports from it.

ChrisA
 
M

mikprog

[..]
Heya! That was just an example; I used track number 19 from the opera

"Iolanthe" as my test file. Pick any other MIDI file you have handy.


This is exactly the point where I feel dumb :)


[..]
$ aplaymidi -l

I think I am not lucky :-(

$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0

I get the same either the iPad is connected or not.
So I guess is not recognized.
Shame.

I'll keep on investigating, hopefully without loosing any of my neurons.

Thanks,
mik
 
M

mikprog

[..]
Heya! That was just an example; I used track number 19 from the opera

"Iolanthe" as my test file. Pick any other MIDI file you have handy.


This is exactly the point where I feel dumb :)


[..]
$ aplaymidi -l

I think I am not lucky :-(

$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0

I get the same either the iPad is connected or not.
So I guess is not recognized.
Shame.

I'll keep on investigating, hopefully without loosing any of my neurons.

Thanks,
mik
 
C

Chris Angelico

I think I am not lucky :-(

$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0

I get the same either the iPad is connected or not.
So I guess is not recognized.
Shame.

I'll keep on investigating, hopefully without loosing any of my neurons.

Yeah, this is the bit where you have to poke around with iPad stuff.
They say "there's an app for that"; maybe there's a way to turn an
iPad into a USB MIDI device. I did a quick Google search for 'ipad usb
midi' and there seem to be some decent hits, so your luck mightn't
have completely run out yet.

ChrisA
 
R

rusi

Dear all,

I am asking for a design/strategy suggestion.

What I have to do is to write a Python application that will send MIDI commands to an iPad application.
All I know is that the iPad application can be connected to an external Midi deck through a usb cable and be controlled.
So I think I would connect the iPad via USB to my computer and... try to send midi commands.
I think the limitation is that the iPad will allow signaling/connection only to Midi devices, so I have to make so that my Python script pretends that my computer is a Midi device.
So far I have tried PyUSB library and I can see the iPad, but I can't send anything to it (probably because I am not pretending to be a Midi device well enough).

I am keen to try PyUSB + pygame for the Midi stuff.

Any suggestion / recommendation / hint / whatever to tell me?
I appreciate every idea at this stage!

Thanks for reading,
Mik

Some suggestions:
1. The linux audio list will serve you better than the python list for
this line of questions
2. Before worrying about python get your 'plumbing' right with
dedicated midi s/w like rosegarden, qtractor etc
3. [I dont understand much midi but…] look at aconnect, aseqnet in
addition to pmidi, aplaymidi
4. On some recent linuxes, (notably ubuntu) timidity is broken thanks
to pulseaudio. In particular, timidity as a normal program works does
not imply that timidity as a server works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top