electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » How-tos
Controlling MIDI with Python in Windows - Foolproof idea?
Post new topic   Reply to topic
Page 1 of 1 [13 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
atriplex



Joined: May 30, 2006
Posts: 8
Location: Darwin, Australia

PostPosted: Wed May 31, 2006 3:36 am    Post subject: Controlling MIDI with Python in Windows - Foolproof idea?
Subject description: Using Python scripts to send MIDI signals to software.
Reply with quote  Mark this post and the followings unread

I want to try and control Audiomulch algorithmically - I've got an idea of using real time data gathered from the web to manipulate controls in Audiomulch (for instance, using the current temperature data from a weather site to control a low-pass filter). Now, MIDI is about the only way to control parameters in Audiomulch from outside the program (I've been wishing for a long time for some kind of network API...), and as I've had a bit of experience programming in Python, it seems the obvious route to take.

Has anyone else tried this? I need Python to talk to the Windows MIDI system (MIDI Out), and for Audiomulch to take the MIDI In from the same system. Now, I've tried experimenting with MIDI-OX to achieve this kind of loop-back, but it simply didn't work for me (Windows XP). MIDI OX did not show up as a system MIDI device, despite being installed.

The other side of the equation is making Python talk to MIDI. Any idea on the best way for this to be done? What Python module would be best?

_________________
-----------
Atriplex
-----------
Slumbertone:http://slumbertone.awardspace.com/ - Music for Sleeping
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed May 31, 2006 3:51 am    Post subject: Reply with quote  Mark this post and the followings unread

welcome atriplex.

For a Nord Modular project I once made an Windows TCP/IP - MIDI convertor, maybe that's usable for you. See http://www.iaf.nl/Users/BlueHell/html/nm-open/nm-open-software.htm , its the NetMIDI program.

Just start the net midi program, select the midi in and out port it must use. Your program should then connect over tcp/ip to net midi (on the port selected) and once connected you can send and receive MIDI bytes.

Its been a while since I last used it, so when there is trouble to get it to work please let me know, I'll see if I can fix it then.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
atriplex



Joined: May 30, 2006
Posts: 8
Location: Darwin, Australia

PostPosted: Wed May 31, 2006 2:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

That looks like an interesting project, I'll give it a go when I get a chance and see how it works, thanks.
_________________
-----------
Atriplex
-----------
Slumbertone:http://slumbertone.awardspace.com/ - Music for Sleeping
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
jksuperstar



Joined: Aug 20, 2004
Posts: 2503
Location: Denver
Audio files: 1
G2 patch files: 18

PostPosted: Wed May 31, 2006 7:33 pm    Post subject: Reply with quote  Mark this post and the followings unread

You can also take a look at MIDIYoke, which is found on the MIDI-OX page. It allows MIDI between software.

You can alos take a look at KeyKit, Tom it's creator, uses Python for video, and there's probably some decent hooks in the program for talking with Python, so You might be able to use something like OSC instead of MIDI, which would give you a lot more control over AudioMulch in the end...Then again, there's probably some Python OSC somewhere out there.
Back to top
View user's profile Send private message Visit poster's website
atriplex



Joined: May 30, 2006
Posts: 8
Location: Darwin, Australia

PostPosted: Thu Jun 01, 2006 4:37 am    Post subject: Reply with quote  Mark this post and the followings unread

Well, I've worked it out. Not far enough to make achieve my project above (still working on that obviously), but using the suggestons above, I've tacked a simple system together.

I got MIDI Yoke installed - I needed the NT version, which works fine.

I run Audiomulch, and set the MIDI Input through the MIDI Yoke Port 1. I set up a contraption, and do "Quick-map to MIDI controller", and set it to channel 1, controller 0.

I run BlueHell's netmidi software - and have it set to output MIDI Yoke Port 1.

Now for the skeleton of my Python code, as an example.

Code:
import telnetlib, time


This imports the two modules you'll need, telnetlib to do the simple network communications, and time, which is useful for, well, timing things.

Code:
midi = telnetlib.Telnet("localhost",1024)


Establishes a network connection to netmidi.

Code:
cc = chr(0xb0)
cont = chr(0)


Sets up some of the basic MIDI codes that need to be sent. cc contains the code to do a controller change on channel 1. You could also make this chr(0xb6) for instance, to select channel 7. cont selects the controller, from 0 to 127. I'm using controller 0.

Code:

for level in range(0,125):
   signal = cc + cont + chr(level)
   midi.write(signal)
   time.sleep(0.1)


And this little loop moves the controller from level 0 to level 125, with a 10th of a second pause between each step. I run the script, and sure enough, the slider moves.

The next step is to multi-task this, so I can be moving sliders independently at the same time, but that isn't actually too hard.

I should point out that 24 hours ago, I knew none of this. I had to go read up on MIDI control codes myself. And netmidi is a very useful bit of software, that works flawlessly.

But thanks for the help, I think I'm going to be able to beat this thing into shape, and I'll update as I go. I'm feeling confidant in what I can do with this actually - I'm always more comfortable working in a programming language than a graphical interface, like pd for instance. Cheers.

_________________
-----------
Atriplex
-----------
Slumbertone:http://slumbertone.awardspace.com/ - Music for Sleeping
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
atriplex



Joined: May 30, 2006
Posts: 8
Location: Darwin, Australia

PostPosted: Thu Jun 01, 2006 4:40 am    Post subject: Reply with quote  Mark this post and the followings unread

Oh I should also note, that for my project I don't need anything that's in time, if you know what I mean. I just need fairly rough, slow controller changes. Which is why a net-work based methods of controlling MIDI is good enough, and why using Python's fairly rough time function is good enough. It's probably not appropriate to use this technique to play the notes of a complicated song, for instance - network lag would probably mess it up.
_________________
-----------
Atriplex
-----------
Slumbertone:http://slumbertone.awardspace.com/ - Music for Sleeping
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Thu Jun 01, 2006 4:57 am    Post subject: Reply with quote  Mark this post and the followings unread

Having the TCP/IP to MIDI conversion and the controlling program on the same machine could give pretty good timing. There is an option though for TCP/IP ports that you might want to clear for that, the Naggle option. This is used to improve on throughput in noprmal use by collecting data for a while to get as much as possible into a single packet. When the Naggle option is off data will be sent immediately, NetMidi uses this I think for the TCP/IP it sends out.

UDP would have been easier maybe in this respect, but I didn't like the idea of note offs possibly not arriving at the other side (UDP has no guaranteed data delivery, but it will give better response times (out of the box)).

I've no idea how to unset the Naggle option in Python, but I could look up the Windows API call for it (you'll need a windows socket handle to be able to use it though).

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
atriplex



Joined: May 30, 2006
Posts: 8
Location: Darwin, Australia

PostPosted: Thu Jun 01, 2006 5:38 am    Post subject: Reply with quote  Mark this post and the followings unread

Quote:
I've no idea how to unset the Naggle option in Python, but I could look up the Windows API call for it (you'll need a windows socket handle to be able to use it though).


Yeah, I've just used Telnet as the simplest possible way of sending network data - it probably isn't doing pretty things in the way it divides up the control codes I send into TCP/IP packets. Better results could definately be achived if the sockets are managed at a lower level.

(I've just got threads going and am moving two controllers up and down simultaneously. Now I must go research the best way to datascrape the web for input data...)

_________________
-----------
Atriplex
-----------
Slumbertone:http://slumbertone.awardspace.com/ - Music for Sleeping
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
cappy2112



Joined: Dec 24, 2004
Posts: 2465
Location: San Jose, California
Audio files: 2
G2 patch files: 1

PostPosted: Sun Jun 04, 2006 10:40 am    Post subject: Re: Controlling MIDI with Python in Windows - Foolproof idea
Subject description: Using Python scripts to send MIDI signals to software.
Reply with quote  Mark this post and the followings unread

atriplex wrote:
I want to try and control Audiomulch algorithmically - I've got an idea of using real time data gathered from the web to manipulate controls in Audiomulch (for instance, using the current temperature data from a weather site to control a low-pass filter). Now, MIDI is about the only way to control parameters in Audiomulch from outside the program (I've been wishing for a long time for some kind of network API...), and as I've had a bit of experience programming in Python, it seems the obvious route to take.

Has anyone else tried this? I need Python to talk to the Windows MIDI system (MIDI Out), and for Audiomulch to take the MIDI In from the same system. Now, I've tried experimenting with MIDI-OX to achieve this kind of loop-back, but it simply didn't work for me (Windows XP). MIDI OX did not show up as a system MIDI device, despite being installed.

The other side of the equation is making Python talk to MIDI. Any idea on the best way for this to be done? What Python module would be best?


Midiox is a com server that you can access using the Python Windows extensions.

There is a Python class in the scripts directory (Under Program Files, Midiox) that you can derive from.

If you can figure out how to use Midiox via COM without the gui being visible, please let me know

There is no built-in Python module for talking to Midi, however there is PyPortMidi which is a wrapper abort the PortMidi C DLL. Neither project is active, but WxMidi is active, but adds bulk to the task.

I'm actually shocked and dissappointed that there isn't more active support for Midi under Python
Back to top
View user's profile Send private message
tjt



Joined: Apr 05, 2003
Posts: 32
Location: San Jose, California

PostPosted: Sun Oct 08, 2006 10:48 pm    Post subject: Re: Controlling MIDI with Python in Windows - Foolproof idea
Subject description: Using Python scripts to send MIDI signals to software.
Reply with quote  Mark this post and the followings unread

cappy2112 wrote:
I need Python to talk to the Windows MIDI system (MIDI Out), ... I'm actually shocked and dissappointed that there isn't more active support for Midi under Python

You and me both. Up until recently, I used a local TCP/IP socket between python and keykit in order to do MIDI and other things keykit provides (like a Fingerworks igesture pad interface) from python. This worked reasonably well, but there were throughput/flowcontrol issues. So, I recently developed a Python module (using pyrex) which actually invokes keykit from within the python process, making both the keykit GUI and realtime MIDI I/O usable directly from within python. The integration is crude, but seems to be working well - I've already used it in several performances. My use of python is to do realtime OpenGL graphics as accompaniment to improvised music, and I use MIDI so that I can use controllers like the JL Cooper CS-32 to control the parameters of the graphics. If you have a reason to want to try and use this python interface to keykit, send me email (tjt-at-nosuch.com) and describe what you want to do. I haven't included it in the keykit distribution yet.

...Tim...
Back to top
View user's profile Send private message Visit poster's website
cappy2112



Joined: Dec 24, 2004
Posts: 2465
Location: San Jose, California
Audio files: 2
G2 patch files: 1

PostPosted: Sun Oct 08, 2006 11:16 pm    Post subject: Re: Controlling MIDI with Python in Windows - Foolproof idea
Subject description: Using Python scripts to send MIDI signals to software.
Reply with quote  Mark this post and the followings unread

tjt wrote:
cappy2112 wrote:
I need Python to talk to the Windows MIDI system (MIDI Out), ... I'm actually shocked and dissappointed that there isn't more active support for Midi under Python

You and me both. Up until recently, I used a local TCP/IP socket between python and keykit in order to do MIDI and other things keykit provides (like a Fingerworks igesture pad interface) from python. This worked reasonably well, but there were throughput/flowcontrol issues. So, I recently developed a Python module (using pyrex) which actually invokes keykit from within the python process, making both the keykit GUI and realtime MIDI I/O usable directly from within python. The integration is crude, but seems to be working well - I've already used it in several performances. My use of python is to do realtime OpenGL graphics as accompaniment to improvised music, and I use MIDI so that I can use controllers like the JL Cooper CS-32 to control the parameters of the graphics. If you have a reason to want to try and use this python interface to keykit, send me email (tjt-at-nosuch.com) and describe what you want to do. I haven't included it in the keykit distribution yet.

...Tim...


I wasn't able to get keykit working to the point where i'd want to start writign scripts for it.
I had some problems trying to get sounds out of it.
Got to go back and try it again.
Back to top
View user's profile Send private message
TonE



Joined: Sep 08, 2009
Posts: 24
Location: Mars

PostPosted: Tue Sep 08, 2009 11:05 pm    Post subject: Reply with quote  Mark this post and the followings unread

jksuperstar wrote:
Tom it's creator
Who is Tom, the secrets are hidden in the details. Smile
Back to top
View user's profile Send private message
jksuperstar



Joined: Aug 20, 2004
Posts: 2503
Location: Denver
Audio files: 1
G2 patch files: 18

PostPosted: Sat Sep 12, 2009 12:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

see user "tjt" (Tim), whose name I mistyped as "Tom" ..so many years ago...
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [13 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » How-tos
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use