Cabbage Logo
Back to Cabbage Site

Multiple instances of Cabbage for the one user? (JACK2 with multiple users)

Today I had two instances of Cabbage working at the same time, I think from the one user, one running a reverb on a signal from the sound card via JACK and the other running the Parp demo, with both driving the same two JACK output channels. However, I was unable to reproduce this.

Is there a legitimate way of running two or more instances of Cabbage at the same time for the same user? When I try to do this the second instance immediately closes itself down.

Running two instances from different users didnā€™t work at first because only the one which is for the user which started jackd will be able to access jackd. Here is how I got this to work. I would prefer to do it all with a single user account.

The setup is much the same as that described in my May messages: Linux build of Cabbage 2.0.02 and Projucer for Debian 9.x . I am using JACK2 1.9.12. This has the updated and now properly documented (in the man page https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=891223 ) environment variable JACK_PROMISCUOUS_SERVER:

ā€œ$JACK_PROMISCUOUS_SERVER enables an alternate way of
handling the various shared resources (Unix sockets, semaphores, ā€¦).
In this mode, the generated names will not contain the user id anymore,
and the permissions of those resources will be relaxed, allowing
clients from different users to talk with the same server. Moreover, on
platforms that support it (all POSIX variants), if set to a valid Unix group
name or id, the permissions will be restricted to that group, so only
members of that group will be able to launch clients that talk to this
server. Important note: it must be set with the same value for both server
and clients to work as expected.
ā€

In May I was accessing the audio server via ssh and X-windows from a Windows machine, and that caused problems for Cabbageā€™s menus, unless I used a special technique of accessing an entire desktop of the audio server. Now I am using a Linux machine to do ordinary ssh and X-windows so I run Cabbage normally, without the cumbersome whole desktop arrangement. The sound card is an RME RayDat.

In this example I ssh to the audio server three times, twice as user robin (to set up the jackd server and to run one instance of Cabbage, and an instance of Ardour) and once as user r0 to run another instance of Cabbage. Everything is still not quite right, since my use of qjackctl is questionable - I probably donā€™t need it, and its Connect facility does not work (an empty window).

With the first (robin) login:

sudo ./hyperthreading-off.sh
hdspmixer &   (Then press Enter.)
export JACK_PROMISCUOUS_SERVER="audio"

Then with a command line copied from the one generated previously by qjackctl (using htop and filtering on ā€œjackā€) I started the jack server:

/usr/local/bin/jackd -v -dalsa -dhw:HDSPMx4fb04e -r48000 -p64 -n2 &

This ssh login is now hard to use, since jackd outputs various things continally (-v = verbose). No-doubt this could be redirected, but I let it run and started a second (robin) login:

export JACK_PROMISCUOUS_SERVER="audio"
qjackctl &

This showed the jackd server was running (its button was: STOP). I probably donā€™t really need this, as long as I find some other way of looking at the jackd patchbay, which I guess I can do by some other means.

After putting a symlink from my home directory to the Cabbage executable, I can run this, but the examples are at: /audio/csound-cabbage-build/cabbage-2.0.02/Builds/LinuxMakefile/CabbageBuild/Examples and to load them from Cabbage I do so explicitly with ā€œFile > Open Csound fileā€, rather then with ā€œFile > Examplesā€.

./Cabbage &   

(Cabbage will still write stuff to this console.)

I started a Parp on this instance of Cabbage and was able to select the required JACK output channels. So far so good.

From the same login console I was also able to run Ardour successfuly, recording the input channels, though after some time it crashed. (I am futzing around, I am yet to learn how to use Ardour properly.)

Now with a third ssh login as user r0 (I had also put a symlink in this userā€™s home directory to the actual Cabbage executable in the build directory):

export JACK_PROMISCUOUS_SERVER="audio" 
./Cabbage &

I fired up Multiverb and was able to process two channels of audio and output it via JACK.

Both instances of Cabbage worked fine together, and I assume I could extend this to several or a dozen or so different users, each running one instance of Cabbage, depending on how CPU intensive they were.

I did not consider how to patch the inputs and outputs of the two Cabbage instances together and with Ardourā€™s inputs and outputs. All three programs where working with the already existing audio channels withing JACK for the RayDat card. I think there is a way, with Ardour (and no doubt other methods) of creating some kind of patch points within JACK so I can patch signals as I wish, independent of the sound card channels.

Thanks for Cabbage!

Always doing things the hard way Robbin :joy: Iā€™m glad it worked in the end, and hope you can build on it for your own work. What high on my list of things to do is add support in the Cabbage patcher for different plugins formats such as native VST, and AU.

Hi Rory,

I tried again to get two instances of Cabbage run by the same user to work.

A likely cause of the failure would be the second instance not being able to open the config file for writing. The config file directory name is in /Source/Application/CabbageDocumentWindow.cpp. I could have altered this and rebuilt, but instead hacked the binary by finding the string ā€œ~/.config/Cabbage2ā€ and changing the final character to ā€˜0ā€™ with a hex editor (bless). The hacked binary runs fine on its own and with an ordinary binary running for another user. However, when I run it while the ordinary binary is already running for the same user, it writes its own config file (if it did not already exist) or presumably reads it OK, but then fails with:

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

I donā€™t know how applications work with JACK, but JACK is configured to work fine with the same application running in multiple instances, one for each user, so I wonder why it might object to working with two copies of the same application for the same user.

If this is not a fundamental limitation of JACK, then it must be something in Cabbage. If so, can you suggest where in the source I might look to make each CabbageN instance appear distinct to JACK or do whatever is required to make them all work, if run from the same user.

That would be great to be able to patch in various plugins in addition to the Csound CSD files.

My reason for wanting to run multiple instances of Cabbage on the same machine is that there might be multiple quite different reasons for running it; each CSD file (or perhaps all the CSD files in a patch) will be running on one core, so limiting the total amount of work which can be done; the machines have 12 cores; and with four of them I will be able to run lots of Cabbage instances.

Can you try the latest master branch? I can now run multiple instances, with each hooking into Jack on my Ubuntu box.

I donā€™t have time at present to build a new bunch of source code after building a new version of JUCE. However, I did implement the one change you made to achieve this - deleting the DBG and quit() lines in Cabbage.cpp:

I used the hex editor as mentioned above on the resulting executable to make two executables Cabbage0 and Cabbage1 which have their own config directories, ~/.config/Cabbage0 and ~/.config/Cabbage1.

Then I started JACK conventionally with qjackctl, not using the fancy arrangements described above for it working with applications from multiple users.

I was able to run Cabbage0 and Cabbage1 perfectly well together from the one user account.

I then ran another instance of Cabbage1 and they all worked fine together, though I expect that the two instances of Cabbage1 will be reading and writing the same config file, which might confuse them or me.

Thanks for this! This means I will be able to make a small fleet of executables 0 to 9, each with their own config settings, each of which I will typically run one instance of at once. I would probable run number 1 first, and then 2, with 0 counting as 10 if I ever get that far. This is because within JACK, the inputs and outputs of each instance of CabbageN are named JUCEJack-01, JUCEJack-02 in order of when the programs started (I think - I will test it later, to see if it is according to when they start playing).

1 Like

After compiling Cabbage as noted in Increasing the size of the Settings dialogue box & I/O channel lists so the audio channel list boxes show 10 pairs of channels each, and with the change noted above to allow multiple instances of Cabbage for the same user to run at the same time, I used a hex editor (bless, though I found it crashed frequently) on the resulting executable to produce 10 executables named Cabbage0 to Cabbage9. Each has a single byte edited to match its name so, for instance, Cabbage8 saves its config file in ~/.config/Cabbage8/ . The program must use the same string to create the name of the config file itself, and in this example the file is Cabbage8.settings.

These are all with the same user and I am not doing any of the above fancy stuff to make JACK work with applications from users other than the one which started it. I started jackd from qjackctl, and am using qjackctl to view the connections.

By starting them in order 0 to 9 their entries in JACK were JUCEJack, JUCEJack-01, JUCEJack02 . . .JUCEJack09. Since the sound card has 36 audio channels and each instance of Cabbage is prompted by this to open 36 input and 36 output channels, JACK is handling 396 input and 396 output channels! This is at 48kHz. The two busy jackd processes are using 8 to 9% of a coreā€™s worth of compute power. The Cabbage instances are running reverbs, fractal and other noise CSD files, some MiniPops drum machines (!!!) and various synthesizers. Each Cabbage instance doesnā€™t seem to average more than this CPU usage.

:astonished:

Thatā€™s pretty astonishing. Says more about JUCE and Csound then Cabbage, but still, itā€™s remrakable that you can get away with this!