[linux-audio-user] Mapping MIDI events to X events
brinkman at math.TU-Berlin.DE
Thu Dec 30 22:01:44 EST 2004
> how does this work?
At the implementation level, there are two main modules, pyseq.py and
pyrobot.py, with some supporting C code.
pyseq.py exposes the MIDI event struct of the ALSA sequencer to Python
and provides some basic functionality for waiting for, processing, and
sending MIDI events. I've actually been having a lot of fun with pyseq.py
alone because it lets you build MIDI filters and such on the fly. If you
run pyseq.py as a main program (by saying 'python pyseq.py'), it behaves
like a MIDI version of the venerable tee command, and I find that quite
useful for snooping out communications between various bits of MIDI gears.
pyrobot.py sort of mimics Java's java.awt.Robot using the XTest library,
i.e., it lets you create and record X events like mouse clicks, key
strokes, and mouse motions.
> this sound very interesting! you
> can click in a virtual knob for instance and move a
> pitch bend for example and tweak the knob?
Basically, yes. The way midimap.py works is that it listens to incoming
control events, and if it receives a kind of event it doesn't know how
to handle, it opens a little dialog that lets you decide what you want
to do with it. Currently there are four ways of handling control events:
- Button: Map a button on the MIDI keyboard to a sequence of X events.
After pushing a new button, you can record the sequence assigned to
this event. For instance, if your sequence consists of a mouse click
on a track in rosegarden, followed by the Delete key, then pushing
this button will amount to activating and clearing a track.
Also, you can make sliders and dials on the keyboard act like buttons:
You specify a threshold and whether a rising edge or falling edge (or
both) is supposed to be interpreted as a button event.
- Slider: If you choose this option, then a slider on the keyboard
will be mapped to a linear mouse dragging event on some GUI. You
calibrate it by clicking on the bottom, top, and current location
of your slider.
- Circular Dial: Much like slider, except the mouse will be dragged
in a circular motion rather than a linear one. You calibrate it
by clicking on the center of the dial plus the bottom, top, and current
- Linear Dial: This name sounds like a bit of an oxymoron, but I so far
I haven't been able to think of a better name. This one's supposed to
deal with widgets that look like dials on the screen, but you actually
change them by pressing a mouse button on the widget and dragging the
mouse up or down in a linear motion. Those things are quite common.
For instance, rosegarden, zynaddsubfx, and hydrogen all use widgets
of this kind.
> this could
> give instant control for non-midi-controlable
> aplications? did i understand well?
That's right. For instance, when I was working on the bit that deals
with linear sliders, I used the vertical scrollbar of my web browserr
for testing purposes. This particular example is not terribly useful,
but I'm sure there are lots of programs that could benefit from
MIDI input, even if they don't belong in the audio world. Also, the
ability to assign entire sequences of X events to single buttons on
the keyboard is quite general and should have lots of applications.
Suggestions are welcome!
More information about the Linux-audio-user