Python to send Midi commands to iPad via USB

Discussion in 'Python' started by mikprog@gmail.com, Jan 24, 2013.

  1. Guest

    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
    , Jan 24, 2013
    #1
    1. Advertising

  2. On Thu, Jan 24, 2013 at 9:31 PM, <> wrote:
    > 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
    Chris Angelico, Jan 24, 2013
    #2
    1. Advertising

  3. Guest

    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
    , Jan 24, 2013
    #3
  4. Guest

    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
    , Jan 24, 2013
    #4
  5. On Thu, Jan 24, 2013 at 10:48 PM, <> wrote:
    > 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
    Chris Angelico, Jan 24, 2013
    #5
  6. Guest

    [..]

    >
    > > ~$ 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.



    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
    , Jan 24, 2013
    #6
  7. Guest

    [..]

    >
    > > ~$ 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.



    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
    , Jan 24, 2013
    #7
  8. On Thu, Jan 24, 2013 at 11:25 PM, <> wrote:
    > 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
    Chris Angelico, Jan 24, 2013
    #8
  9. rusi Guest

    On Jan 24, 3:31 pm, wrote:
    > 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
    rusi, Jan 24, 2013
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugo Villeneuve

    Java MIDI output device to MIDI Yoke.

    Hugo Villeneuve, Jul 4, 2003, in forum: Java
    Replies:
    0
    Views:
    923
    Hugo Villeneuve
    Jul 4, 2003
  2. Gilly
    Replies:
    6
    Views:
    408
    Ken Starks
    May 4, 2008
  3. Asbjørn Bjørnstad
    Replies:
    0
    Views:
    421
    Asbjørn Bjørnstad
    Oct 9, 2008
  4. Rick T
    Replies:
    0
    Views:
    265
    Rick T
    Jun 30, 2011
  5. Setia Budi

    Send commands to USB device in Python

    Setia Budi, Feb 11, 2014, in forum: Python
    Replies:
    1
    Views:
    77
Loading...

Share This Page