Python to send Midi commands to iPad via USB
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On Thursday, January 24, 2013 9:43:31 AM UTC, Hazard Seventyfour wrote: > Hello, > > > > I new in this python and decided to learn more about it, so i can make an own > script :), > > > > for all senior can you suggest me the best, friendly and easy use with nice > GUI editor for me, and have many a good features such as auto complete/auto > correct. > > > > any recommend? Thanks ^_^ Hi, an editor is pretty much a matter of personal preferences. I personally like Eclipse as I use it for most of my projects (not only Python) so I use Eclipse + PyDev plug-in for Python. mik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to send Midi commands to iPad via USB
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to send Midi commands to iPad via USB
[..] > > > ~$ 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 PortClient name Port name 14:0Midi 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 -- http://mail.python.org/mailman/listinfo/python-list
software app and Python: any experience?
Hi guys, I am thinking of driving a DJ application from Python. I am running Linux and I found the Mixxx app. Does anyone know if there are python bindings, or if this is possible at all? or does anyone have experience with another software that does the same DJ thing? I have also found the pymixxx module that I could install... but I didn't find any documentation so far or example code that could help me start (I'm keeping on searching). Finally maybe that there is any DJ app that could be driven by pygame.midi? Any idea appreciated. Sorry to fail to be more specific. Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixxx DJ app and Python
On Tuesday, January 29, 2013 4:13:09 PM UTC, David Hutto wrote: [..] > > >> or does anyone have experience with another software that does the same DJ > >> thing? > > > > > Hydrogen, and audacity work perfectly together. Hi David, thanks for your reply. I am not sure though that this is going to help me. We have built a kind of basic controller that sends commands via bluetooth. Then I should have some device (like a linux pc or raspberry Pi) where I have my applications that listen for these bluetooth commands and drives a DJ application accordingly (like mixing two sounds, sync them etc). Obviously to write the whole application will take ages and I saw that the Mixxx one does everything I want. So I am searching for a way to interface to it programatically. Do you mean that Hydrogen and Audacity would replace the Mixxx app and I can call their functionality from Python? Or were you thinking about something else? Thanks, Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixxx DJ app and Python
On Tuesday, January 29, 2013 4:45:18 PM UTC, Ben wrote: > This may not be too helpful, but I built a TCP server into the Mixxx > application (in C++). I placed the server in ratecontroller (as I needed to > vary the rate remotely). I then could send and receive TCP packets with a > single board computer that ran a python client. Hi Ben, this would be actually interesting to look at. If you are not going to face problems, please send me the code. Thanks, Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixxx DJ app and Python
On Tuesday, January 29, 2013 4:42:07 PM UTC, David Hutto wrote: [..] > > Well you can just use their(Mixx's) source code that they used from > > another wav form manipulation library(more than likely), after the > > trigger from the bluetooth. If you're talking voice, and music to > > sync, then either go with transmitting at the same, or take two > > receivers(one for each transmitter), and run them in unison on > > different frequencies, after they've been received.. > > > > I've never tried this, but it seems logical. > Thanks David. It seems that the code is in C++ so I should write Python wrappers myself, which could be interesting, but given the time frame I have is just not possible, Pity :-( However I was not going to transmit sounds, but just commands to mix the sounds that are already in the same machine were the Mixxx is going to run. I hope I will have time to come back to it in future. Thanks. Mik -- http://mail.python.org/mailman/listinfo/python-list
improving performance of writing into a pipe
Hi guys, on an embedded linux system (BeagleBoard) I am writing data coming from bluetooth dongle into a pipe. The function is the following one: def write_to_pipe(line): # next line ensures that bytes like '0x09' are not translated into '\t' for #example, and they are sent as such hexbytes = "\\x" + "\\x".join([hex(ord(c))[2:].zfill(2) for c in line]) wrap = ["echo -en '", "' > /tmp/mypipe"] msg = hexbytes.join(wrap) print "DBG: sending: ", msg try: os.popen( msg ) except: print "Error: write_to_pipe has failed!" Now I typically receive 4 bytes from the bluetooth dongle and that is fine. However when I receive many more than that it seems that the writing into the pipe is too slow. Is there any clever/obvious way to improve the code above? (I am quite sure there is to be honest). Thanks for any suggestion! Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
On Monday, February 18, 2013 3:21:53 PM UTC, Oscar Benjamin wrote: [..] > > Can you not open the pipe file directly in Python code? e.g. > > > > fout = open('/tmp/mypipe', 'w') > > fout.write(data) > > > > I guess that this would be more efficient than using os.popen to run echo. > > that's an idea, thanks Oscar. However I get an exception while trying to open the queue: fout = open('/tmp/mypipe', 'w') I have tried it in a command line and the call doesn't return until in another terminal I open the same queue for reading (???) I have created the queue with: mkfifo /tmp/mypipe any clue? mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
[..] > > I don't see an exception in your answer. Where did you put it for us? > well I just did print a message: PIPEPATH = ["/tmp/mypipe"] [..] try: self.process = os.popen( self.PIPEPATH, 'w') except: print "Error while trying opening the pipe!" print "check: ", self.PIPEPATH exit() I see the error messages. It's quite frustrating as I think I am doing something really stupid in here. Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
On Monday, February 18, 2013 6:12:01 PM UTC, Michael Torrie wrote: > On 02/18/2013 10:00 AM, mikp...@gmail.com wrote: > > > [..] > > >> > > >> I don't see an exception in your answer. Where did you put it for us? > > >> > > > > > > well I just did print a message: > > > > > > PIPEPATH = ["/tmp/mypipe"] > > > > > > [..] > > > try: > > > self.process = os.popen( self.PIPEPATH, 'w') > > > except: > > > print "Error while trying opening the pipe!" > > > print "check: ", self.PIPEPATH > > > exit() > > > > > > I see the error messages. > > > > Unfortunately your attempt to catch this exception is hiding the true > > cause. You need to give us the actual exception. Otherwise it could be > > anything from self.PIPEPATH not existing to who knows what. > > > > Almost never do you want to catch all exceptions like you're doing. You > > should only catch the specific exceptions you know how to deal with in > > your code. > > > > For testing purposes, if your code really is as you put it, then > catching exceptions is kind of silly since you're just re-raising the > exception (sort of) but without any contextual information that would > make the error meaningful. Ok, I get your point. But on the other hand how do I know what to catch if I have no clue what is causing the error? There must be a way to catch all the possible errors and then investigate what is the problem, right? (which is not what I have done so far). Or rather: what would you try to catch in this particular case? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
> > Once you get your script working you can try to provoke errors, and for > > those errors you can recover from you can write error handlers. For IOError > > and Python < 3.3 that may involve inspecting the errno attribute and > > conditionally reraising. Ok. > By the way, I don't think > > > >> > PIPEPATH = ["/tmp/mypipe"] > > >> > self.process = os.popen( self.PIPEPATH, 'w') > > > > can work. As a few people already told you the built-in open() Few people? I thought Oscar was a singular person, not a group of people :-) Seriously, I am convinced by that approach (thanks) and I wish to go that way, but the problem I am getting now is that the open fails and then I can't go on. Also, I am now looking at the subprocess as os.popen seems deprecated. Any opinion on that? Thanks for your suggestion. Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
On Monday, February 18, 2013 7:29:09 PM UTC, Serhiy Storchaka wrote: > On 18.02.13 17:12, mikp...@gmail.com wrote: > > > on an embedded linux system (BeagleBoard) I am writing data coming from > > bluetooth dongle into a pipe. > > > The function is the following one: > > > > > > > > > def write_to_pipe(line): > > > > > > # next line ensures that bytes like '0x09' are not translated into > > '\t' for > > > #example, and they are sent as such > > > hexbytes = "\\x" + "\\x".join([hex(ord(c))[2:].zfill(2) for c in line]) > > > wrap = ["echo -en '", "' > /tmp/mypipe"] > > > msg = hexbytes.join(wrap) > > > print "DBG: sending: ", msg > > > > > > try: > > > os.popen( msg ) > > > except: > > > print "Error: write_to_pipe has failed!" > > > > > > > > > Now I typically receive 4 bytes from the bluetooth dongle and that is fine. > > > However when I receive many more than that it seems that the writing into > > the pipe is too slow. > > > > > > Is there any clever/obvious way to improve the code above? > > > (I am quite sure there is to be honest). > > > > def write_to_pipe(line): > > hexbytes = ''.join('\\x%02x' % ord(c) for c in line) > > with open('/tmp/mypipe', 'w') as f: > > f.write(hexbytes) I'll take your hexbytes = '' line (which is surely more efficient than mine). However whit this approach open + write it seems the pipe doesn't get the data... I am not sure what is going on. At this point I suspect it could be a problem on the pipe itself (which I inherited). It is just weird that the pipe accept this correctly: wrap = ["echo -en '", "' > /tmp/midi"] msg = hexbytes.join(wrap) os.popen( msg ) but seems to be careless of approach open + write. I need to investigate there. Thanks a lot, to you and to everyone else. Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
> > def write_to_pipe(line): > > hexbytes = ''.join('\\x%02x' % ord(c) for c in line) > > with open('/tmp/mypipe', 'w') as f: > > f.write(hexbytes) Update: with a fix in the pipe THIS was the right way to do it, and it now works. Thanks a lot Serhiy to you and to everyone else. Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
> > Thanks a lot Serhiy to you and to everyone else. > > > Do you mind telling us what fix you applied? Oh, apologies Peter, I thought it was clear as I posted it after the lines written by Serhiy. So it was what Serhiy suggest in addition to some (?minor?) modification to the pipe itself, which I cannot comment about as I don't have access to it. But apparently the problem of not being able to open it was due to it. (It does not help much I am afraid... but that's all I know). Mik -- http://mail.python.org/mailman/listinfo/python-list
Re: improving performance of writing into a pipe
On Tuesday, February 19, 2013 5:47:16 PM UTC, Michael Torrie wrote: > On 02/19/2013 02:24 AM, mikp...@gmail.com wrote: > > > Or rather: what would you try to catch in this particular case? > > > As Peter said, nothing for now. But you seem very resistant to telling > > us what exception was raised. Michael believe me: I am not resistant or try to hide anything! As written before, I don't know what exception to search for, so I wrote the (wrong) code: except: print "error" Let's why I don't have a clue about it. But someone already explained me that I should not do this. > > Though looking at your code more closely I can see that likely the error > > is related to the fact that /tmp/mypipe is not an executable program. Yes it is and has rwx permissions. Unfortunately I don't have access to the code in the pipe. > > popen (which is deprecated and replaced by the subprocess module) is for > > running programs and communicating with them over pipes created by the > > popen function. So your code is not likely to ever work as it is > > presently given. > > > > Here's the bash equivalent of your code: > > > > $ mkfifo /tmp/path > > $ cat > $ echo hello, world | /tmp/path > > > > Bash will say, "bash: /tmp/path: Permission denied" > > > > The correct bash line is: > > $ echo hello, world > /tmp/path > > > > popen() (and subprocess) is the equivalent of the first bash command. > > open() is the equivalent of the second line. > > Do you understand the difference? I think I do now, thanks. mik -- http://mail.python.org/mailman/listinfo/python-list