Saturday, June 19, 2010

D-Bus in VMPK

Yesterday, I've released VMPK 0.3.2 with a new D-Bus interface. VMPK is not a KDE application, it uses only Qt4, so a D-Bus interface wasn't included by default. This VMPK feature is far from perfect, and it will require some improvements in future releases, but it is a start.

What can be done with this D-Bus thing? D-Bus provides a mechanism to send and receive messages between processes (it is an IPC, inter process communication mechanism). This allows one application to be controlled from another one, or from a script. This is the classic application automation scenario solved in Windows with COM/DCOM, and in Mac OSX with AppleScript. D-Bus is a cross platform solution, with nice Qt4 bindings: the module QtDBus. The Qt4 SDK for Windows doesn't include this module, and anyway the bus daemon and libraries are external dependencies. D-Bus has been adopted in Linux by the KDE and Gnome desktops replacing other former solutions.

As use case demos, in a directory named "dbus" of the VMPK source tarball, there are a Bash script playing a simple tune and two Python scripts showing how to remotely execute actions and receive signals from VMPK. Another interesting use case for this D-Bus interface is to define new hot keys to send MIDI messages using VMPK. For instance, let's define Alt+S to send a sustain=100 control change, and Alt+Z to send sustain=0. Here is a brief how-to for the KDE desktop.

To configure hot keys in KDE, run the program "Personal Settings (Configure Desktop)", and select "Computer Administration" -> "Input Actions", or launch the command 'kcmshell4 khotkeys' from a terminal. Here you can create a new group with the name "VMPK", and two new actions (new -> global shortcut -> D-Bus command) for your controllers. Name your actions for instance "sustain on" and "sustain off", and assign the key strokes in the tab labeled "Trigger". In the tab "Action", the data for "sustain on" is:

Remote application: net.sourceforge.vmpk
Remote object: /
Function: controlchange
Arguments: 64 100

The arguments are a pair of numbers, first the controller number, and then the control value. 64 is the sustain (hold1) controller, and 100 is the value. The arguments for the "Sustain Off" are "64 0".

You must activate the check boxes in the actions tree, to enable the new hot keys. You can also set conditions for the group, for instance checking that the window title or class matches the VMPK main window.

Note that you need to compile VMPK with ENABLE_DBUS activated. The binary packages for Windows and Mac OSX don't have this option enabled.

Binary packages? didn't say I something about stopping to ship binary packages of my programs? Yes, there are no binary Linux packages for this VMPK release. The question is that I can provide a single VMPK package for Windows that includes all dependencies (a few Qt4 and runtime DLL), and this package runs in XP, Server, Vista and Windows7. Same for Mac OSX, where I can provide a single application bundle compiled in Universal mode (x86 and PPC) including all the dependencies as well. The burden for Linux is the existence of RPM and DEB package types, with differences among several distros, and several versions, and processors, and whatever. VMPK is provided by several major distros already. If it is not yet included in your distro, open a request in the distribution tracker or compile it from sources.