Skip to content

Commit 68edde6

Browse files
authored
Merge pull request #3347 from porras/pipewire
Use pipewire on Linux if available (like on raspberry)
2 parents 41a6728 + 9c161d4 commit 68edde6

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

app/server/ruby/bin/daemon.rb

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ def self.os
638638
raise "Unsupported platform #{RUBY_PLATFORM}"
639639
end
640640
end
641+
642+
def self.pipewire?
643+
`which pw-link`
644+
$?.success?
645+
end
641646
end
642647

643648
class KillSwitch
@@ -1218,8 +1223,9 @@ def read_log
12181223
def run_pre_start_commands
12191224
case Util.os
12201225
when :linux, :raspberry
1221-
#Start Jack if not already running
1222-
if `jack_wait -c`.include? 'not running'
1226+
if Util.pipewire?
1227+
Util.log 'No need to start Jackd, using pipewire instead'
1228+
elsif `jack_wait -c`.include? 'not running'
12231229
#Jack not running - start a new instance
12241230
Util.log "Jackd not running on system. Starting..."
12251231
@jack_booter = JackBooter.new
@@ -1231,27 +1237,29 @@ def run_pre_start_commands
12311237

12321238
def run_post_start_commands
12331239
case Util.os
1234-
#modify case if you want linux as well as raspberry pi to use pipewire
1235-
when :raspberry #,:linux
1236-
Thread.new do
1237-
Kernel.sleep 5
1238-
hdmiL=`/usr/bin/pw-link -iI |grep -P '(hdmi).*(playback_FL)'|awk '{ print $1 }'`
1239-
hdmiR=`/usr/bin/pw-link -iI |grep -P '(hdmi).*(playback_FR)'|awk '{ print $1 }'`
1240-
1241-
sco1=`/usr/bin/pw-link -oI |grep -P '(SuperCollider:out_1)' |awk '{ print $1 }'`
1242-
sco2=`/usr/bin/pw-link -oI |grep -P '(SuperCollider:out_2)' |awk '{ print $1 }'`
1243-
1244-
system("pw-link #{sco1.strip} #{hdmiL.strip}")
1245-
system("pw-link #{sco2.strip} #{hdmiR.strip}")
1246-
end
1247-
#comment out this when section if you want linux to use pulseaudio as raspberry-pi above
1248-
when :linux
1240+
when :raspberry, :linux
12491241
Thread.new do
12501242
Kernel.sleep 5
1251-
# Note:
1252-
# need to modify this to take account for @num_inputs and @num_outputs.
1253-
# These might not always be set to two channels each.
1254-
if @jack_booter
1243+
if Util.pipewire?
1244+
port_type = if Util.os == :raspberry
1245+
'hdmi'
1246+
else
1247+
'alsa_output'
1248+
end
1249+
inputs = `pw-link -iI`.lines
1250+
left_id = inputs.grep(/#{port_type}.*playback_FL$/).first.to_i
1251+
right_id = inputs.grep(/#{port_type}.*playback_FR$/).first.to_i
1252+
1253+
outputs = `pw-link -oI`.lines
1254+
sco1 = outputs.grep(/SuperCollider:out_1$/).first.to_i
1255+
sco2 = outputs.grep(/SuperCollider:out_2$/).first.to_i
1256+
1257+
system("pw-link #{sco1} #{left_id}")
1258+
system("pw-link #{sco2} #{right_id}")
1259+
elsif @jackbooter
1260+
# Note:
1261+
# need to modify this to take account for @num_inputs and @num_outputs.
1262+
# These might not always be set to two channels each.
12551263
#First clear up any pulseaudio remains of module-loopback source=jack_in
12561264
`pactl list short modules |grep source=jack_in| cut -f1 | xargs -L1 pactl unload-module`
12571265
`pactl load-module module-jack-source channels=2 connect=0 client_name=JACK_to_PulseAudio`
@@ -1271,7 +1279,6 @@ def run_post_start_commands
12711279
end
12721280
end
12731281

1274-
12751282
def unify_toml_opts_hash(toml_opts_hash)
12761283
opts = {}
12771284

0 commit comments

Comments
 (0)