====== JACK2 control ====== jackdmp control scripts. ===== About ===== Recent versions of [[http://jackaudio.org|Jack2]] aka. jackdmp can be controlled via Dbus and most interestingly, jackdmp allows the backend-driver to be replaced dynamically even while jackd is running! There's two main use-cases that motivated me: * to be able to quickly switch between the internal and an external soundcard. * to have JACK sessions survive system suspend/resume cycles using the "dummy" driver. I hardly ever re-boot my laptop and I keep jackd running anytime (( jackd - especially at low latencies - increases power-consumption quite a bit: so the only time I'm not running jackd is when traveling to places where there's no power-outlet fi. [[http://rg42.org/_media/blog/back_from_finland/online_smile.jpg|here]].)). So far I use [[qjackctl_dbus|Qjackctl's Dbus]] interface to start/stop jackd during suspend; disadvantage is that it terminates all existing jack sessions; it's not a big deal since most apps can simply re-connect but if jackd can be kept running: why not do so? I did the switch: jackd here is now jackdmp.. while audio-applications are ignorant about the change and everything there works just like it was before with jack1, suspend-resume and qjackctl is now somewhat broken. qjackctl (v0.3.6.22) sometimes gets stuck when switching backends; this is a major bummer since I like it's connection patchbay. ''patchage'' (v0.4.4) suffers a similar issue. It does not update the ports correctly. Anyway those problems can be fixed in future releases (and were in qjackctl 0.3.6.24). But I hit another little snag: Calling ''jack_control sm'' - which is needed to switch the backend - drops existing connections to system:* i/o ports. OK. The ports may be different in some setups but they're not here: switching between two stereo cards. Long story short, here are two shell-scripts. The first to switch between different sound-cards retaining connections. and a second to take care of switching to the dummy-driver and back during suspend/resume cycles. They're rather pragmatic hacks, but good enough to get started. ===== Setup ===== Installation steps: - install latest qjackctl (>= 0.3.6.24) and jackdmp (>=1.9.6) and enable DBus-interface in qjackctl's Setup->Misc. - copy the ''myjackctl.sh'' script to some folder and make it executable (''chmod +x myjackctl.sh''). - save the ''90myjackctl.sh'' script to ''/etc/pm/sleep.d'' or a similar folder where it gets executed as hook during suspend/resume - edit the ''90myjackctl.sh'' and set the path to ''myjackctl.sh'' - optionally create a ''~/.myjackctl'' file (example below) which allows to override the settings when resuming the system. By default the parameters used before suspend are restored. - test it: - start jackdmp: either via qjactctl, or eg with: ''myjackctl.sh alsa hw:0 1024 48000 3'' - start some music, fi. mplayer - ''sudo etc/pm/sleep.d/90jack2ctl.sh suspend'' -> qjackctl is disconnected and jackdmp-dummy audiodriver is loaded. - ''sudo etc/pm/sleep.d/90jack2ctl.sh resume'' -> previous audio settings are restored and qjackctl reconnected. - call sudo ''pm-suspend'' (or activate your computer's suspend-button aka close-lid) to test a real suspend/resume cycle. ===== myjackctl features and limitations ===== * easy switch between jackdmp backends retaining system port connections * suspend script works for multiple-users, but at most one jackdmp per user. * dummy driver is created with identical numeber of I/O ports as previous interface. * tested on Debian. ===== The Source ===== * [[http://rg42.org/gitweb/?p=myjackctl.git;a=snapshot;h=HEAD|download the scripts]] as tar.gz * The source is also available from %%git://rg42.org/myjackctl%% * [[http://rg42.org/gitweb/?p=myjackctl.git|browse git repository]] ''~/bin/myjackctl.sh'': extern>http://rg42.org/gitweb/?p=myjackctl.git;a=blob_plain;f=myjackctl.sh;hb=HEAD ''/etc/pm/sleep.d/90myjackctl.sh'': extern>http://rg42.org/gitweb/?p=myjackctl.git;a=blob_plain;f=90myjackctl.sh;hb=HEAD ''~/.myjackctl'': optional extern>http://rg42.org/gitweb/?p=myjackctl.git;a=blob_plain;f=dot_myjackctl;hb=HEAD ===== Notes ===== myjackctl.sh does intentionally not use ''jack_control''. The reason for this is that calling ''jack_control'' from a pm-suspend hook cancels the suspend and the system returns without sleeping. I have no idea why this happens, but simply using dbus-send works. (addendum: I experience similar behaviour when using ''which myjackctl.sh'' in the pm hook script instead of hardcoding its path.) The ''DSESSIONBUS'' environment variable at the top of ''myjackctl.sh'' is required to allow the script to be run in a setuid (''su'') session. What's left ToDo? * The port-reconnection should become optional and can be improved (see note in source) * multiple jack-servers of the same user could be supported - if that is possible jack-dbus at all. * jack-realtime parameters need to be unhardcoded. * the suspend/resume script should check for ''rtirq'' before it calls it; also use ''rtctl'' or similar. {{tag>jack development audio floss}}