Python Script Creator/Generator (function factory)
andrej.mitrovich at gmail.com
Tue Mar 30 18:34:18 CEST 2010
I have the following situation: I've got a 3rd party application that
has a Python API. The applicaiton has integrated support for MIDI
Hardware Controllers, which can be used to manipulate various
parameters of the application. The app can also load Python User
Scripts, which can define the mapping between the Controllers and
Parameters, but they can also be used to define the behavior of those
mappings as well.
I want to provide my users a GUI App that allows them to map their
MIDI Controllers to the application's Parameters, but with a specific
behavior. Once they've defined the mappings and behavior, my
application would generate a custom Python User Script, which then
gets loaded by the 3rd party app.
I've already got MIDI covered, and the GUI. Deployment via Pyinstaller
has been taken care of as well. My application can currently map
Controllers to Parameters in a 1:1 fashion, and can generate a simple
python User Script with all the mappings. What I'm left with
implementing is the behavior part.
Let me give you a simple example of a possible behavior that the user
- The user has a button on their MIDI Hardware (a simple type of MIDI
- The first time the button is hit, a specific parameter is selected
in the 3rd party application.
- The second time the button is hit, a different parameter is
- And so on, depending on the behavior of the function that's mapped
to that MIDI button
So, in essence, a simple User Script would look something like this
if button1 was_hit_the_first_time:
buttons = (
button1 = swap_parameters()
button3 = parameter3
button4 = parameter4
What I had in mind, was to have a collection of behaviors stored in a
file (basically functions such as "swap_parameters") which the user
could select via my application, map them to a specific MIDI
Controller (such as a Button), and generate the User Script.
In essence, I'm trying to build a function factory that's specific to
the 3rd party application's provided API. But the user would have the
ability to change the way the function works. In the above example,
the user might want their MIDI Button to select parameter2 first, and
parameter1 the second time.
Has anyone had any experience with generating functionality this way,
and could you give me some pointers in the right direction? Any tips,
advice, book recommendations are more than welcome.
More information about the Python-list