Run script when stopping Jack within Cadence ?

Unofficial support for the KXStudio Linux distribution and applications.
More info at http://kxstudio.linuxaudio.org/

Moderators: MattKingUSA, khz

Post Reply
korakios
Established Member
Posts: 85
Joined: Thu Feb 14, 2013 6:00 pm

Run script when stopping Jack within Cadence ?

Post by korakios »

Hi,
Is there a way to run a script when stopping Jack server?
I need to resume Networg-Manager and pulseaudio.
folderol
Established Member
Posts: 2072
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 224 times
Been thanked: 400 times
Contact:

Re: Run script when stopping Jack within Cadence ?

Post by folderol »

If you run qjackctl that is a built-in option in 'Setup'
The Yoshimi guy {apparently now an 'elderly'}
korakios
Established Member
Posts: 85
Joined: Thu Feb 14, 2013 6:00 pm

Re: Run script when stopping Jack within Cadence ?

Post by korakios »

Ok, but I want to use Cadence if possible . Unless qjackctl starts automatically when Cadence starts and you propose a nice workaround.
Luc
Established Member
Posts: 741
Joined: Fri Mar 27, 2015 1:04 pm
Been thanked: 1 time

Re: Run script when stopping Jack within Cadence ?

Post by Luc »

I control a lot of things - including JACK - from keyboard shortcuts. These shortcuts run shell scripts which do the job.

I can share my entire approach with you, but this kind of setup is very dependent on the desktop manager (for the shortcuts) and I use fish for scripting, which you probably will have to port to bash. I haven't been fluent in bash for years.
korakios
Established Member
Posts: 85
Joined: Thu Feb 14, 2013 6:00 pm

Re: Run script when stopping Jack within Cadence ?

Post by korakios »

Well, I definitely need running some scripts when starting / closing Cadence.

The major issue is wpa_supplicant process , scanning for networks every ~2 minutes. I get ~20 xruns at once ,every 2 minutes!
I manually pause the process and after jamming I continue (it keeps wifi connection on)
Any suggestions (besides closing network) ?
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Run script when stopping Jack within Cadence ?

Post by tramp »

You can setup a shortcut menu entry or desktop starter comandline like this:

run/pre/script && cadence && run/post/script

give it a meaningful name and done.
On the road again.
Luc
Established Member
Posts: 741
Joined: Fri Mar 27, 2015 1:04 pm
Been thanked: 1 time

Re: Run script when stopping Jack within Cadence ?

Post by Luc »

korakios wrote:Well, I definitely need running some scripts when starting / closing Cadence.

The major issue is wpa_supplicant process , scanning for networks every ~2 minutes. I get ~20 xruns at once ,every 2 minutes!
I manually pause the process and after jamming I continue (it keeps wifi connection on)
Any suggestions (besides closing network) ?
Maybe you can try adding/changing this line in your wpa_supplicant.conf file:
ap_scan=0
korakios
Established Member
Posts: 85
Joined: Thu Feb 14, 2013 6:00 pm

Re: Run script when stopping Jack within Cadence ?

Post by korakios »

tramp wrote:You can setup a shortcut menu entry or desktop starter comandline like this:

run/pre/script && cadence && run/post/script

give it a meaningful name and done.
Thanks I'll try it :)
Luc wrote: Maybe you can try adding/changing this line in your wpa_supplicant.conf file:
ap_scan=0
I am afraid ,the network manager will no longer see any new wireless networks , but I'll give it a try. :)
korakios
Established Member
Posts: 85
Joined: Thu Feb 14, 2013 6:00 pm

Re: Run script when stopping Jack within Cadence ?

Post by korakios »

The only way for wpa to stop is actually stopping the process. It totally ignores whatever command I give on wpa_cli
ap_scan 0
scan_interval 0
suspend

The run/pre/script && cadence && run/post/script method is not good since I want to interact when jack starts or stops with Cadence and not when exiting Cadence application.
It's not big deal ,I can always use qjacktrl instead but I like Cadence much better.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Run script when stopping Jack within Cadence ?

Post by tramp »

If you would do that with cadence, you may use a launcher script like this:

Code: Select all

#!/bin/bash

# monitor jackd script

just_started="YES"
just_stoped="YES"

# start jackd launcher, replace with cadence
qjackctl &

sleep 5

# replace qjackctl with cadence
while [ "$(pidof qjackctl)" ]; do
while [ "$(pidof jackd)" ]; do
if [ $just_started == "YES" ]
then
    just_started="NO"
    just_stoped="YES"
    echo 'jackd is started.'
    # execute your pre script here
else
    echo 'jackd is running.'
fi
    sleep 5
done
if [ $just_stoped == "YES" ]
then
    just_started="YES"
    just_stoped="NO"
    echo 'jackd is stoped.'
    # execute your post script here
else
    echo 'only qjackctl run.'
fi
    sleep 5
done
    echo "session quit"
exit 0
Note that the echo's here are only for control, to see what's going up, you'll better remove them or comment them out when you use it in practise. You may also adjust the sleep times to your needs.
On the road again.
korakios
Established Member
Posts: 85
Joined: Thu Feb 14, 2013 6:00 pm

Re: Run script when stopping Jack within Cadence ?

Post by korakios »

Thanks @Tramp !Your script became the base for making a Template

Code: Select all

#!/bin/bash

# Do some extra things if needed before Starting Cadence
# PreUpCadence Scripts ,here:


# We can also run scripts depending on JackServer status 
# but we want only once!
JackUpScript="notRunning"
JackDownScript="notRunning"

# Start Cadence!
cadence &
# Stop PulseAudio ,you can always start it in Cadence ,or in a Session
pulseaudio -k &
# Start Jack
echo 'Starting Jack'
jack_control start &

sleep 1

# While Cadence is running
while [ "$(pgrep -f cadence.py)" ]; do

# Check if Jack is running
 status=$(jack_control status |grep -v status)

 
# If Jack is NOT Running
  if [ $status == stopped ]
    then
# Run a script ,but only once. So we check
         if [ $JackDownScript == "notRunning" ]
          then
               JackUpScript="notRunning" 
               echo "Jack is stopped ,running PostDown Script"
               JackDownScript="Running"
               # Run Something!
         fi 
         
    else
        
          if [ $JackUpScript == "notRunning" ]
          then
               JackDownScript="notRunning" 
               echo "Jack is started ,running PostUp Script"
               JackUpScript="Running"
               # Run Something else!
         fi   

   fi
# Checking every n seconds
sleep 1

done

# Exciting Cadence, no need for Low Latency Audio, stopping Jack
echo 'Stopping Jack'
jack_control stop &

# But we need some audio!
echo 'Restoring PulseAudio'
pulseaudio --start &

# Put any other PostDownCadence scripts here

exit 0
Now I have to think a way to run

Code: Select all

 kill -STOP $(pidof wpa_supplicant)
and

Code: Select all

 kill -CONT $(pidof wpa_supplicant)
:roll:

UPDATE:

Code: Select all

kdesudo "kill -CONT $(pidof wpa_supplicant)"
kdesudo "kill -STOP $(pidof wpa_supplicant)"
seems to do the trick. It requires the root password but only once.
In few words I start Cadence, kill pulse, start Jack , pause wpa (and audio glitches) in one click!
Post Reply