Creating a Jamulus Patchbox Module

Jamulus is a system for playing (aka “jamming”) with other musicians remotely. In these times of Covid-19, it has become quite popular, especially for band members that can no longer practice safely in person.

I have found that the PiSound/PatchBox system makes for a good platform to run Jamulus clients (and also to act as a server). As a dedicated machine for Jamulus, the connections have minimal latency, and seem to be quite stable, and appears (at least to me) to work with less Jack connection problems than using an external USB audio interface. The only disadvantage with PiSound is having only a single guitar jack input. If you are using an XLR microphone, you need external equipment to supply phantom power, make the impedance conversion, etc. I myself use an external mic preamp box for this.

As good as PiSound/PatchBox OS combination is for running Jamulus, the default configuration has one flaw. To use Jamulus properly, you must have any “direct-monitoring” turned off. That is, there should be no pathway from input to output that doesn’t flow through the Jamulus program. Problem is, the default configuration of PatchBox OS provides such a pathway. At boot-up, it apparently hooks up the Pulse Audio JACK source and sinks to the system capture and playback. These connections must be broken before starting up a Jamulus client.

Now, a person could manually remove these connections using, say, Patchage, or the jack_disconnect command line, or write a script that does this before starting the Jamulus client, and then restore the connections after Jamulus finishes (if you want things to go back to the “default way”.

QUESTION:

While a script like that above could work, I tried instead to create a custom patchbox module that I could select when I want to be in “Jamulus mode”. All the module does is disconnect the pulse audio connections at activation, and reconnect them upon deactivating the module. I got the module to install into the patchbox module system okay, as it does work in disconnecting the Pulse Audio upon activation, and reconnecting on deactivation.

The problem is, how do I get the Jamulus patchbox module to take effect at boot-time? Is that how modules work? The one you select in the Patchbox configuration gets activated at boot? Or do you have to manually do the selection after each boot?

If the former, (can be activated at boot), well, it doesn’t work for me. Here is my patchbox-module.json file:

{
    "name": "jamulus",
    "version": "1.0.0",
    "description": "jamulus module",
    "author": "bflamig",
    "launch_mode": "auto",
    "depends_on": [
        "jack.service",
        "pisound-ctl.service"
    ],
    "scripts": {
        "launch": "disconnect_pulse.sh",
        "stop": "connect_pulse.sh"
    }
}

where the disconnect and connect scripts call jack_disconnect and jack_connect as appropriate.

So am I on the right track here? Do I have the right dependencies?

Or is there a simpler way to do what I want: to make sure these auto-connections to pulse-audio don’t happen or are removed at boot time. I would like to setup PiSound boxes for a couple of non-technical band members. Having things just work out of the box would be desirable.

BTW: For those that are interested, my patchbox module source can be found on github at bflamig/jamulus-module. I welcome any better way to write this code.

2 Likes

Looks like the issue happens, because Pulse Audio’s client is created only once someone logs into the graphical environment in the OS. The Patchbox’s module gets executed way earlier, before Pulse Audio clients are available in Jack.

Some other method of temporarily suspending Pulse Audio is necessary. Could you try keeping Pulse Audio connections as they are, but start Jamulus using a command like this:

pasuspender -- Jamulus

It’s supposed to ‘suspend’ Pulse Audio (I’m not sure how that is implemented from technical side of things) while Jamulus is running, maybe it will work out fine. :slight_smile:

I tried that. It didn’t work. Still get the pulse audio connections.

Sounds like the best way, then, is to simply start Jamulus from a script and use jack_disconnect to get rid of the pulse audio connections before starting up Jamulus.

That’d work. Patchbox modules are more tailored for applications that can be run without a GUI in the background. If you’d like to make Jamulus start automatically with a GUI, you’d have to use the XDG Autostart mechanism.

I think it’d be possible to write a Patchbox Module that’d instead of launching the app itself would reconfigure the system appropriately, so the desired GUI application would work well. We’d just need to figure out what are the right commands to run or configuration changes to make to disable the Pulse Audio plugin.

Thanks for the tip that the patchbox modules are meant more for headless applications.

It would be cool to have a patchbox module that would prevent the Pulse Audio from connecting (or simply disable Pulse Audio altogether). I tried to figure out how to do it, but I’m not quite Linux savvy enough to figure out it. But for now, a script that simply does the disconnecting does the trick.

Hey, just found these commands that work once the graphical environment is loaded to disable the Jack sink & source:

pactl unload-module module-jackdbus-detect
pactl unload-module module-jack-sink
pactl unload-module module-jack-source

These enable them again:

pactl load-module module-jackdbus-detect
pactl load-module module-jack-sink channels=2
pactl load-module module-jack-source channels=2

I think we’ll add some flags to patchbox-module.json to delay module initialization until the graphical environment is up, so that use cases like yours are covered in a future version. :slight_smile:

Hey, we’ve added an optional is_desktop flag to patchbox-module.json which delays starting the module, until the graphical environment is up. To mark the occasion, we’ve added pulse-audio-off module which keeps the Pulse Audio sink & source disabled while the module is activated. :slight_smile:

It was not as straightforward to implement as I had hoped initially, but I think this should open quite a few possibilities for Patchbox modules, as it allows for auto-starting GUI applications too. :slight_smile:

It’s available since patchbox version 1.2.0, get it by running patchbox update.

2 Likes