Puredata doesn't connect to JACK

Hello guys,

I’m running Patchbox OS on my pisound. When I start pd, I get an error: JACK: couldn't connect to server, is JACK running?
So, I checked if JACK is running. It is (jackd). When I kill jackd and start a JACK server manually via qjackctl, pd doesn’t complain and runs fine. But I would like to run it without desktop, so that’s not a satisfying workaround.

I’ve already updated pd to the latest version and tried running my patch as a patchbox module. Both didn’t solve this.

Any ideas how to investigate further?

What is the output of this command:

sudo systemctl status jack

The Jack service on Patchbox OS is preconfigured (and can be reconfigured via patchbox) and should be running in the background automatically, no need to start it manually (unless it was stopped/disabled manually :slight_smile: )

● jack.service - JACK Server
   Loaded: loaded (/lib/systemd/system/jack.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-06-20 22:05:58 BST; 13h ago
 Main PID: 473 (jackd)
    Tasks: 5 (limit: 2062)
   CGroup: /system.slice/jack.service
           └─473 /usr/bin/jackd -t 2000 -R -P 95 -d alsa -d hw:pisound -r 48000 -p 256 -n 2 -X seq

Jun 20 22:06:00 patchbox jackdrc[473]: port created: pisound:midi/playback_1
Jun 20 22:06:00 patchbox jackdrc[473]: port created: pisound:midi/capture_1
Jun 20 22:06:00 patchbox jackdrc[473]: port created: LPD8:midi/playback_1
Jun 20 22:06:00 patchbox jackdrc[473]: port created: LPD8:midi/capture_1
Jun 20 22:06:00 patchbox jackdrc[473]: port created: APC-Key-25:midi/playback_1
Jun 20 22:06:00 patchbox jackdrc[473]: port created: APC-Key-25:midi/capture_1
Jun 20 22:06:12 patchbox jackdrc[473]: port created: RtMidiIn-Client:midi/capture_1
Jun 20 22:06:12 patchbox jackdrc[473]: port created: RtMidiOut-Client:midi/playback_1
Jun 21 11:08:10 patchbox jackdrc[473]: port created: pisound-ctl:midi/playback_1
Jun 21 11:08:10 patchbox jackdrc[473]: port created: pisound-ctl:midi/capture_1

looks like it’s running smoothly.

I guess the problem might be that I run pd with sudo. I use the wiringPi external to control GPIOs. When I run pd without sudo, there is no JACK error. But the GPIO stuff does not work.

So, the proper question might be: How do I make pd connect to JACK when run with sudo?

Try sudo -E puredata ... (add -E argument to sudo command, so the local environment variables get inherited by sudo)

patch@patchbox:~ $ sudo -E pd -nogui mypatch.pd
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
[...]

I’ll try to make wiringPi run without sudo. Or is there an easy way to avoid JACK altogether?
The only audio requirement is to do pitch detection on an input signal.

You may stop jack, and configure PD to use ALSA, by passing in the appropriate command line arguments to PD.

sudo systemctl disable jack --now

I found a way to run pd and wiringpi without sudo (actually easy: just add your user to the gpio group).

So I’ve reinstalled patchbox OS to get rid of all potential collateral damages I might have caused by troubleshooting. Now the preinstalled jack and pd work together :partying_face:
… at least when run in an ssh terminal.

On a remote desktop (xrdp, Microsoft Remote Desktop, same user), I still get a JACK Failure when launching pd. Any ideas on this?

Anyway, big thanks for your help so far! I’m happy there is at least one way that works.

1 Like

Does the same happen when launching PD from a terminal running in the remote desktop session?

yes, looks similar to the launch via desktop shortcut.

patch@patchbox:~ $ pd
priority 8 scheduling failed.
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

It should work, at least this does work fine on my device. :slight_smile: Some things to check:

  • sudo systemctl status jack - it should be running
  • cat /etc/environment - it should contain a line like JACK_PROMISCUOUS_SERVER=jack
  • Check ~/.pdsettings file for anything that could impact this.
  • export | grep JACK - it should print declare -x JACK_PROMISCUOUS_SERVER="jack"

Points 1 and 2 are met. In .pdsettings I don’t see anything suspicious.

export does not contain JACK. Shouldn’t it be there inherently when set in /etc/environment?

It should, does PD start if you do this just before running PD:

. /etc/environment

nope. doesn’t make a difference.

Does the output of export change after the above command?

no, it’s identical.

What’s the output of echo $-, in a newly started terminal window?

patch@patchbox:~ $ echo $-
himBHs

What’s the output of:

pam_getenv JACK_PROMISCUOUS_SERVER

patch@patchbox:~ $ pam_getenv JACK_PROMISCUOUS_SERVER
jack

Hmm, I can’t come up with any ideas of why /etc/environment wouldn’t be getting imported into your user’s environment variables…

You could try editing your ~/.bashrc and placing this line there:

export JACK_PROMISCUOUS_SERVER=jack

It should then be good to go when using ssh or terminals. (After restarting the terminal / logging back in again)