Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 205 additions & 51 deletions data/cadence-pulse2jack
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,66 @@ else
fi

# ----------------------------------------------
wanted_capture_ports=0 # -1 means default
wanted_playback_ports=0 # -1 means default

PLAY_ONLY="no"
arg_is_for=""

case $1 in
-h|--h|--help)
echo "usage: $0 [command]
for arg in "$@";do
case "$arg" in
-h|--h|--help)
echo "usage: $0 [command]

-p Playback only with default number of channels
-p <NUMBER> Number of playback channels
-c Capture only with default number of channels
-c <NUMBER> Number of capture channels

-p, --play Playback mode only
-h, --help Show this help menu
--dummy Don't do anything, just create the needed files

-h, --help Show this help menu
--dummy Don't do anything, just create the needed files
NOTE:
When runned with no arguments, $(basename "$0") will
activate PulseAudio with both playback and record modes with default number of channels.
"
exit
;;
--dummy)
exit
;;
-c|--capture)
arg_is_for="capture"
wanted_capture_ports=-1 # -1 means default, if no (correct) argument is given.
;;
-p|--play|--playback)
arg_is_for="playback"
wanted_playback_ports=-1
;;
* )
case "$arg_is_for" in
"capture")
[ "$arg" -ge 0 ] 2>/dev/null && wanted_capture_ports="$arg"
;;
"playback")
[ "$arg" -ge 0 ] 2>/dev/null && wanted_playback_ports="$arg"
;;
esac
;;
esac
done

NOTE:
When runned with no arguments, pulse2jack will
activate PulseAudio with both playback and record modes.
"
exit
;;

--dummy)
exit
;;
if [ $wanted_capture_ports == 0 ] && [ $wanted_playback_ports == 0 ];then
#no sense to want to start/bridge pulseaudio without ports, set as default
capture_ports=-1 # -1 means default
playback_ports=-1 # -1 means default
fi

-p|--p|--play)
PLAY_ONLY="yes"
FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play.pa
;;
str_capture="channels=$wanted_capture_ports" #used for pulseaudio commands
str_playback="channels=$wanted_playback_ports" ##

*)
FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play+rec.pa
;;
esac
[ $wanted_capture_ports == -1 ] && str_capture="" # -1 means default, no command channels=n
[ $wanted_playback_ports == -1 ] && str_playback="" ##

# ----------------------------------------------

Expand All @@ -88,40 +116,166 @@ IsPulseAudioRunning()
fi
}

if (IsPulseAudioRunning); then
StartBridged()
{
if (`jack_lsp | grep "PulseAudio JACK Sink:" > /dev/null`); then
{
echo "PulseAudio is already running and bridged to JACK"
}
#write pulseaudio config file in a tmp file
pa_file=$(mktemp --suffix .pa)
echo .fail > $pa_file

### Automatically restore the volume of streams and devices
echo load-module module-device-restore >> $pa_file
echo load-module module-stream-restore >> $pa_file
echo load-module module-card-restore >> $pa_file

### Load Jack modules
[ $wanted_capture_ports != 0 ] && echo load-module module-jack-source $str_capture >> $pa_file
[ $wanted_playback_ports != 0 ] && echo load-module module-jack-sink $str_playback >> $pa_file

### Load unix protocol
echo load-module module-native-protocol-unix >> $pa_file

### Automatically restore the default sink/source when changed by the user
### during runtime
### NOTE: This should be loaded as early as possible so that subsequent modules
### that look up the default sink/source get the right value
echo load-module module-default-device-restore >> $pa_file

### Automatically move streams to the default sink if the sink they are
### connected to dies, similar for sources
echo load-module module-rescue-streams >> $pa_file

### Make sure we always have a sink around, even if it is a null sink.
echo load-module module-always-sink >> $pa_file

### Make Jack default
[ $wanted_capture_ports != 0 ] && echo set-default-source jack_in >> $pa_file
[ $wanted_playback_ports != 0 ] && echo set-default-sink jack_out >> $pa_file

if (`pulseaudio --daemonize --high-priority --realtime --exit-idle-time=-1 --file=$pa_file -n`); then
echo "Initiated PulseAudio successfully!"
else
{
echo "PulseAudio is already running, bridge it..."
echo "Failed to initialize PulseAudio!"
fi
}

if [ "$PLAY_ONLY" == "yes" ]; then
{
pactl load-module module-jack-sink > /dev/null
pacmd set-default-source jack_in > /dev/null
}
else
{
pactl load-module module-jack-sink > /dev/null
pactl load-module module-jack-source > /dev/null
pacmd set-default-sink jack_out > /dev/null
killReStart()
{
pulseaudio -k && StartBridged
exit
}

JackNotRunning()
{
echo "JACK seems not running, start JACK before bridge PulseAudio"
exit 1
}

if (IsPulseAudioRunning); then
{
#count all Jack Audio Physical ports
all_jack_lsp=$(jack_lsp -p -t) || JackNotRunning
output_physical_lines=$(echo "$all_jack_lsp"|grep -n "output,physical,"|cut -d':' -f1)
input_physical_lines=$( echo "$all_jack_lsp"|grep -n "input,physical," |cut -d':' -f1)
audio_lines=$(echo "$all_jack_lsp" |grep -n " audio"|cut -d':' -f1)

capture_physical_ports=0
playback_physical_ports=0

for out_phy_line in $output_physical_lines;do
if echo "$audio_lines"|grep -q $(($out_phy_line + 1));then
((capture_physical_ports++))
fi
done

for in_phy_line in $input_physical_lines;do
if echo "$audio_lines"|grep -q $(($in_phy_line + 1));then
((playback_physical_ports++))
fi
done

#count PulseAudio jack ports
current_playback_ports=$(echo "$all_jack_lsp"|grep ^"PulseAudio JACK Sink:" |wc -l)
current_capture_ports=$( echo "$all_jack_lsp"|grep ^"PulseAudio JACK Source:"|wc -l)

#if number of pulseaudio ports equal to physical ports, consider pulseaudio module is running the default mode (no channels=n)
[ $current_capture_ports == $capture_physical_ports ] && current_capture_ports=-1
[ $current_playback_ports == $playback_physical_ports ] && current_playback_ports=-1
[ $wanted_capture_ports == $capture_physical_ports ] && wanted_capture_ports=-1
[ $wanted_playback_ports == $playback_physical_ports ] && wanted_playback_ports=-1

if [ $wanted_capture_ports == $current_capture_ports ] && [ $wanted_playback_ports == $current_playback_ports ];then
echo "PulseAudio is already started and bridged to Jack with $current_capture_ports inputs and $current_playback_ports outputs, nothing to do !"
exit
fi

if [ $current_capture_ports != $wanted_capture_ports ];then
if [ $current_capture_ports != 0 ];then
echo "unload PulseAudio JACK Source"
pactl unload-module module-jack-source > /dev/null || killReStart
fi

if [ $wanted_capture_ports != 0 ];then
echo "load PulseAudio JACK Source $str_capture"

pactl load-module module-jack-source $str_capture > /dev/null
pacmd set-default-source jack_in > /dev/null
}
fi

echo "Done"
}
fi

if [ $current_playback_ports != $wanted_playback_ports ];then
if [ $current_playback_ports != 0 ];then
echo "unload PulseAudio JACK Sink"
pactl unload-module module-jack-sink > /dev/null || killReStart
fi

if [ $wanted_playback_ports != 0 ];then
echo "load PulseAudio JACK Sink $str_playback"

pactl load-module module-jack-sink $str_playback > /dev/null
pactl set-default-sink jack_out > /dev/null
fi
fi
}
else
{
if (`pulseaudio --daemonize --high-priority --realtime --exit-idle-time=-1 --file=$FILE -n`); then
echo "Initiated PulseAudio successfully!"
else
echo "Failed to initialize PulseAudio!"
fi
{
StartBridged
# #write pulseaudio config file in a tmp file
# pa_file=$(mktemp --suffix .pa)
# echo .fail > $pa_file
#
# ### Automatically restore the volume of streams and devices
# echo load-module module-device-restore >> $pa_file
# echo load-module module-stream-restore >> $pa_file
# echo load-module module-card-restore >> $pa_file
#
# ### Load Jack modules
# [ $wanted_capture_ports != 0 ] && echo load-module module-jack-source $str_capture >> $pa_file
# [ $wanted_playback_ports != 0 ] && echo load-module module-jack-sink $str_playback >> $pa_file
#
# ### Load unix protocol
# echo load-module module-native-protocol-unix >> $pa_file
#
# ### Automatically restore the default sink/source when changed by the user
# ### during runtime
# ### NOTE: This should be loaded as early as possible so that subsequent modules
# ### that look up the default sink/source get the right value
# echo load-module module-default-device-restore >> $pa_file
#
# ### Automatically move streams to the default sink if the sink they are
# ### connected to dies, similar for sources
# echo load-module module-rescue-streams >> $pa_file
#
# ### Make sure we always have a sink around, even if it is a null sink.
# echo load-module module-always-sink >> $pa_file
#
# ### Make Jack default
# [ $wanted_capture_ports != 0 ] && echo set-default-source jack_in >> $pa_file
# [ $wanted_playback_ports != 0 ] && echo set-default-sink jack_out >> $pa_file
#
# if (`pulseaudio --daemonize --high-priority --realtime --exit-idle-time=-1 --file=$pa_file -n`); then
# echo "Initiated PulseAudio successfully!"
# else
# echo "Failed to initialize PulseAudio!"
# fi
}
fi
14 changes: 7 additions & 7 deletions resources/ui/cadence.ui
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="b_pulse_channels">
<property name="text">
<string>Channels</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
Expand Down Expand Up @@ -956,13 +963,6 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tb_pulse_options">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
63 changes: 56 additions & 7 deletions resources/ui/cadence_tb_pa.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,69 @@
<rect>
<x>0</x>
<y>0</y>
<width>317</width>
<height>72</height>
<width>218</width>
<height>124</height>
</rect>
</property>
<property name="windowTitle">
<string>PulseAudio Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="cb_playback_only">
<property name="text">
<string>Playback Mode only</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelPulseInputs">
<property name="text">
<string>Input Channels :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPulseOutputs">
<property name="text">
<string>Output Channels :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBoxPulseInputs">
<property name="specialValueText">
<string>Default</string>
</property>
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxPulseOutputs">
<property name="specialValueText">
<string>Default</string>
</property>
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
Expand Down
Loading