Re: Real time event accuracy
On Wed, 09 May 2012 08:52:59 -0700 Tobiah t...@tobiah.org wrote: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I've done something similar using Fluidsynth (which I think is cross platform) to play the midi. It has the advantage that you can send it midi commands as simple human-readable strings over a socket, like: fluidsynth_socket.send(noteon 0 0 64 \n) making it easy to do things on the fly withoutwriting/reading midi files. On Linux I've found just using: time.sleep(correct_time - time.time()) before sending is accurate to the millisecond, but I understand you have to specify a (hardware) timer to achieve this for Windows. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. I haven't used it but python-pypm looks about right: pyPortMidi is a Python wrapper for PortMidi. PortMidi is a cross-platform C library for realtime MIDI control. Using pyPortMidi, you can send and receive MIDI data in realtime from Python. Besides using pyPortMidi to communicate to synthesizers and the like, it is possible to use pyPortMidi as a way to send MIDI messages between software packages on the same computer. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
On 09/05/2012 16:52, Tobiah wrote: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. For an idea of how difficult timing can be, search the Python development mailing list for PEP 418 and associated threads. Make sure you have a large supply of sandwiches and coffee cos you'll need it :) Thanks, Tobiah -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Real time event accuracy
I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Thanks, Tobiah -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
On 05/09/2012 11:52 AM, Tobiah wrote: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Thanks, Tobiah You really need to specify the OS environment you're targeting, as well as telling what program you're intending to feed MIDI into, if you've already picked one. Also, the midi file format has timing information, and that timing should be much better than trying to do it in python before sending commands to some external program. In other words, instead of sleeping in your code and then issuing one midi event, use the midi file format to send a stream of commands that will be played according to the timing information included. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
On 05/09/2012 09:13 AM, Dave Angel wrote: On 05/09/2012 11:52 AM, Tobiah wrote: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Thanks, Tobiah You really need to specify the OS environment you're targeting, as well as telling what program you're intending to feed MIDI into, if you've already picked one. I'm using Kontakt on Windows 7. The MIDI file think would be good, but (not having that computer in front of me) I don't think that Kontakt had the ability to open a MIDI file. Now, I know that I could load the file into Reaper, and use Kontakt as a plugin. My problem is that I can't afford to mess with GUI menus during my composition process. I need to edit a python program in Vi, then slap it out to python, hearing the music, then edit again. The cycle has to be very quick in order to get anything done. Loading Kontakt with a bunch of samples is very time consuming, so it needs to keep running. Now, if I could find a program that would interpret the MIDI file and send events off to Kontakt either as a plugin or standalone, then the MIDI file generation idea would be perfect. Also, the midi file format has timing information, and that timing should be much better than trying to do it in python before sending commands to some external program. In other words, instead of sleeping in your code and then issuing one midi event, use the midi file format to send a stream of commands that will be played according to the timing information included. -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
I don't know the details of how Kontakt works, but you can try pygame.midi: pygame.midi - is a portmidi wrapper orginally based on the pyportmidi wrapper. Also pygame.music can play midi files. Can get input from midi devices and can output to midi devices. For osx, linux and windows. New with pygame 1.9.0. python -m pygame.examples.midi --output (http://wiki.python.org/moin/PythonInMusic) Pedro -- http://pedrokroger.net http://musicforgeeksandnerds.com/ On May 9, 2012, at 1:33 PM, Toby wrote: On 05/09/2012 09:13 AM, Dave Angel wrote: On 05/09/2012 11:52 AM, Tobiah wrote: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Thanks, Tobiah You really need to specify the OS environment you're targeting, as well as telling what program you're intending to feed MIDI into, if you've already picked one. I'm using Kontakt on Windows 7. The MIDI file think would be good, but (not having that computer in front of me) I don't think that Kontakt had the ability to open a MIDI file. Now, I know that I could load the file into Reaper, and use Kontakt as a plugin. My problem is that I can't afford to mess with GUI menus during my composition process. I need to edit a python program in Vi, then slap it out to python, hearing the music, then edit again. The cycle has to be very quick in order to get anything done. Loading Kontakt with a bunch of samples is very time consuming, so it needs to keep running. Now, if I could find a program that would interpret the MIDI file and send events off to Kontakt either as a plugin or standalone, then the MIDI file generation idea would be perfect. Also, the midi file format has timing information, and that timing should be much better than trying to do it in python before sending commands to some external program. In other words, instead of sleeping in your code and then issuing one midi event, use the midi file format to send a stream of commands that will be played according to the timing information included. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Mark Wirt's MidiUtil is a nice library for MIDI. It doesn't do exactly what you want (it generates MIDI files) but it's a nice library and it may be a good starting point: http://code.google.com/p/midiutil/ Pedro -- http://pedrokroger.net http://musicforgeeksandnerds.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
Tobiah t...@tobiah.org writes: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I don't think you can really do this accurately enough to get good sound, but the basic mechanism is time.sleep(t) which takes a floating point argument. That turns into the appropriate microsleep, I think. I'm not even sure how to do it from C code with the Linux realtime scheduler. Traditionally for this sort of thing you'd use dedicated hardware, or else generate waveforms with a little bit of buffering in the sound card. -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
I don't think you can really do this accurately enough to get good sound, but the basic mechanism is time.sleep(t) which takes a floating point argument. That turns into the appropriate microsleep, I think. I think the time would have to come from a hardware clock. -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time event accuracy
On 05/09/2012 03:26 PM, Tobiah wrote: I don't think you can really do this accurately enough to get good sound, but the basic mechanism is time.sleep(t) which takes a floating point argument. That turns into the appropriate microsleep, I think. I think the time would have to come from a hardware clock. Python has a high-res time function when run on an Intel X86 platform, though I forget which one you should use on Windows. The problem is that Windows makes no assurance that you will be executing at that particular point in time. You can approximate it with time.sleep(), which is what Paul Rubin was suggesting. Windows is not a real time operating system. Still, if the system is lightly loaded, sleep() will probably get you within 50 milliseconds. I don't think you should even worry about it till you see the capabilities of whatever MIDI library you choose. I'd be surprised if it doesn't allow you to attach timing hints to the notes, same as the file format I discussed earlier. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list