aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordvs12024-10-22 13:51:59 +1000
committerdvs12024-10-22 13:51:59 +1000
commite4d51e4c5904895dd599d099e857ccebdf1714fc (patch)
treefeffbbef3f4eed362eeb347f31dd769ba85e3cb2
parentConvert example user script to new exe stuff. (diff)
downloadJackOnAllDevices-e4d51e4c5904895dd599d099e857ccebdf1714fc.zip
JackOnAllDevices-e4d51e4c5904895dd599d099e857ccebdf1714fc.tar.gz
JackOnAllDevices-e4d51e4c5904895dd599d099e857ccebdf1714fc.tar.bz2
JackOnAllDevices-e4d51e4c5904895dd599d099e857ccebdf1714fc.tar.xz
Lots of little tweaks about how _ works.
Diffstat (limited to '')
-rwxr-xr-x.aataaj_JACK.lua2
-rwxr-xr-x_.lua37
-rwxr-xr-xaataaj.lua68
-rwxr-xr-xtest_.lua6
4 files changed, 70 insertions, 43 deletions
diff --git a/.aataaj_JACK.lua b/.aataaj_JACK.lua
index 21e7938..91888d2 100755
--- a/.aataaj_JACK.lua
+++ b/.aataaj_JACK.lua
@@ -11,4 +11,4 @@ local E = _.E
11local C = _.C 11local C = _.C
12local __ = _._ 12local __ = _._
13 13
14if _.exists('qsynth') then __('qsynth'):fork() end 14if _.runnable'qsynth' then __'qsynth':forkOnce() end
diff --git a/_.lua b/_.lua
index c1710ee..42c3b4a 100755
--- a/_.lua
+++ b/_.lua
@@ -59,10 +59,12 @@ _._ = function(c)
59 self.logging = true 59 self.logging = true
60 return self 60 return self
61 end 61 end
62
62 function exe:show() 63 function exe:show()
63 self.showing = true 64 self.showing = true
64 return self 65 return self
65 end 66 end
67
66 function exe:Nice(c) 68 function exe:Nice(c)
67 if nil == c then 69 if nil == c then
68 self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd 70 self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd
@@ -71,6 +73,7 @@ _._ = function(c)
71 end 73 end
72 return self 74 return self
73 end 75 end
76
74 function exe:timeout(c) 77 function exe:timeout(c)
75 -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well. 78 -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well.
76 -- --kill-after means "send KILL after TERM fails. 79 -- --kill-after means "send KILL after TERM fails.
@@ -81,33 +84,40 @@ _._ = function(c)
81 end 84 end
82 return self 85 return self
83 end 86 end
84 function exe:also(c) 87
88 function exe:also(c) -- Should be called "then" but that's a reserved word.
85 if nil == c then c = '' else c = ' ' .. c end 89 if nil == c then c = '' else c = ' ' .. c end
86 self.cmd = self.cmd .. '; ' .. c .. ' ' 90 self.cmd = self.cmd .. '; ' .. c .. ' '
87 return self 91 return self
88 end 92 end
93
89 function exe:And(c) 94 function exe:And(c)
90 if nil == c then c = '' else c = ' ' .. c end 95 if nil == c then c = '' else c = ' ' .. c end
91 self.cmd = self.cmd .. ' && ' .. c .. ' ' 96 self.cmd = self.cmd .. ' && ' .. c .. ' '
92 return self 97 return self
93 end 98 end
99
94 function exe:Or(c) 100 function exe:Or(c)
95 if nil == c then c = '' end 101 if nil == c then c = '' end
96 self.cmd = self.cmd .. ' || ' .. c .. ' ' 102 self.cmd = self.cmd .. ' || ' .. c .. ' '
97 return self 103 return self
98 end 104 end
105
99 function exe:noErr() 106 function exe:noErr()
100 self.cmd = self.cmd .. ' 2>/dev/null ' 107 self.cmd = self.cmd .. ' 2>/dev/null '
101 return self 108 return self
102 end 109 end
110
103 function exe:noOut() 111 function exe:noOut()
104 self.cmd = self.cmd .. ' 1>/dev/null ' 112 self.cmd = self.cmd .. ' 1>/dev/null '
105 return self 113 return self
106 end 114 end
115
107 function exe:wait(w) 116 function exe:wait(w)
108 self.cmd = self.cmd .. ' && touch ' .. w .. ' ' 117 self.cmd = self.cmd .. ' && touch ' .. w .. ' '
109 return self 118 return self
110 end 119 end
120
111 function exe:Do() 121 function exe:Do()
112 --[[ "The condition expression of a control structure can return any 122 --[[ "The condition expression of a control structure can return any
113 value. Both false and nil are considered false. All values different 123 value. Both false and nil are considered false. All values different
@@ -135,23 +145,40 @@ _._ = function(c)
135 end 145 end
136 return self 146 return self
137 end 147 end
148
138 function exe:fork(host) 149 function exe:fork(host)
139 if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end 150-- if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end
140 self.cmd = '{ ' .. self.cmd .. ' ; } & ' 151 self.cmd = '{ ' .. self.cmd .. ' ; } & '
141 if true == self.logging then D(" forking - " .. self.cmd) end 152 if true == self.logging then D(" forking - " .. self.cmd) end
142 os.execute(self.cmd) 153 os.execute(self.cmd)
143 return self 154 return self
144 end 155 end
156
157 function exe:forkOnce()
158 if _.running(self.command) then
159 D('Already running ' .. self.command)
160 else
161 self:fork()
162 end
163 end
164
145 return exe 165 return exe
146end 166end
167
147local __ = _._ 168local __ = _._
148 169
170_.runnable = function(c)
171 return ( 0 == __('which ' .. c):Do().status )
172end
149 173
150_.exists = function(c) 174_.running = function(c)
151 if 0 == __('which ' .. c):Do().status then return true end 175 return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) )
152 return false
153end 176end
154 177
178_.exists = function(f)
179 local h, e = io.open(f, "r")
180 if nil == h then return false else h:close(); return true end
181end
155 182
156_.killEmAll = function(all) 183_.killEmAll = function(all)
157 for i,l in ipairs(all) do 184 for i,l in ipairs(all) do
diff --git a/aataaj.lua b/aataaj.lua
index a92e0fb..26db4d2 100755
--- a/aataaj.lua
+++ b/aataaj.lua
@@ -118,8 +118,8 @@ if 0 ~= #args then
118 _.killEmAll{'jmcore', 'qjackctl'} 118 _.killEmAll{'jmcore', 'qjackctl'}
119 -- Catia is python, and no easy way to kill it. 119 -- Catia is python, and no easy way to kill it.
120 -- Also it keeps jackdbus alive, no matter how hard you kill it. 120 -- Also it keeps jackdbus alive, no matter how hard you kill it.
121 __("pkill -TERM -u $USER -f catia"):Do() 121 __"pkill -TERM -u $USER -f catia":Do()
122 __("sleep 2"):Do() 122 __"sleep 2":Do()
123 _.killEmAll{'jackdbus', 'a2jmidid'} 123 _.killEmAll{'jackdbus', 'a2jmidid'}
124 return(0) 124 return(0)
125 elseif 'JACK' == args[1] then 125 elseif 'JACK' == args[1] then
@@ -149,18 +149,18 @@ end
149local asoundrcPath = '/var/lib/aataaj' 149local asoundrcPath = '/var/lib/aataaj'
150local asoundrc = 'asoundrc' 150local asoundrc = 'asoundrc'
151local GUI = 'qjackctl' 151local GUI = 'qjackctl'
152if _.exists('catia') then GUI = 'catia' end 152if _.runnable('catia') then GUI = 'catia' end
153local alias = { 153local alias = {
154-- {name='Screen', dev='HDMI9'}, 154-- {name='Screen', dev='HDMI9'},
155 } 155 }
156 156
157local speaker = 'espeak' 157local speaker = 'espeak'
158if _.exists('espeak-ng') then speaker = 'espeak-ng' end 158if _.runnable('espeak-ng') then speaker = 'espeak-ng' end
159 159
160local Cards = {} 160local Cards = {}
161 161
162print('Scanning for audio devices.') 162print('Scanning for audio devices.')
163local cards = __('ls -d1 /proc/asound/card[0-9]*'):noErr():Do() 163local cards = __'ls -d1 /proc/asound/card[0-9]*':noErr():Do()
164for i,l in ipairs(cards.lines) do 164for i,l in ipairs(cards.lines) do
165 local f, e = io.open(l .. '/id', "r") 165 local f, e = io.open(l .. '/id', "r")
166 if nil == f then print("Could not open " .. l .. '/id') else 166 if nil == f then print("Could not open " .. l .. '/id') else
@@ -182,7 +182,7 @@ for i,l in ipairs(cards.lines) do
182 if 'JACK' ~= args[1] then 182 if 'JACK' ~= args[1] then
183 print('\t\tALSA_CARD=' .. i - 1 .. ' ' .. speaker .. ' "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') 183 print('\t\tALSA_CARD=' .. i - 1 .. ' ' .. speaker .. ' "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"')
184 __('ALSA_CARD=' .. i - 1 .. ' ' .. speaker .. ' "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"'):noErr():Do() 184 __('ALSA_CARD=' .. i - 1 .. ' ' .. speaker .. ' "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"'):noErr():Do()
185 __('sleep 1'):Do() 185 __'sleep 1':Do()
186 end 186 end
187 end 187 end
188 end 188 end
@@ -363,31 +363,29 @@ elseif 'JACK' == args[1] then
363 print('') 363 print('')
364 print("Start up JACK and friends.") 364 print("Start up JACK and friends.")
365 print("jack_control") 365 print("jack_control")
366 __('jack_control start'):Do() 366 __[[jack_control start
367 __('jack_control ds alsa'):Do() 367 jack_control ds alsa]]:Do()
368 --jack_control dps device hw:RIG,0 368 --jack_control dps device hw:RIG,0
369 local r = __('jack_control status'):Do().status 369 while 0 ~= __'jack_control status':Do().status do
370 while r ~= 0 do 370 print("Waiting for JACK")
371 print("Waiting for JACK - sleep 1") 371 __'sleep 1':Do()
372 __('sleep 1'):Do()
373 r = __('jack_control status'):Do().status
374 end 372 end
375 if nil ~= GUI then 373 if nil ~= GUI then
376 print(GUI) 374 print(GUI)
377 __(GUI):fork() 375 __(GUI):forkOnce()
378 end 376 end
379 if _.exists('jack-plumbing') then 377 if _.runnable'jack-plumbing' then
380 print("jack-plumbing") 378 print("jack-plumbing")
381 __('jack-plumbing -o /var/lib/aataaj/jack-plumbing 2>/dev/null'):fork() 379 __'jack-plumbing -o /var/lib/aataaj/jack-plumbing 2>/dev/null':fork()
382 end 380 end
383 if _.exists('a2j_control') then 381 if _.runnable'a2j_control' then
384 -- Bridge ALSA ports to JACK ports. Only handles MIDI. 382 -- Bridge ALSA ports to JACK ports. Only handles MIDI.
385 -- MIDI via a2jmidid. The --ehw enables hardware ports as well, equal to using the seq MIDI drivare according to https://freeshell.de/~murks/posts/ALSA_and_JACK_MIDI_explained_(by_a_dummy_for_dummies)/ 383 -- MIDI via a2jmidid. The --ehw enables hardware ports as well, equal to using the seq MIDI drivare according to https://freeshell.de/~murks/posts/ALSA_and_JACK_MIDI_explained_(by_a_dummy_for_dummies)/
386 --a2j_control actually starts a2jmidid. 384 --a2j_control actually starts a2jmidid.
387 ----a2jmidid -e -u & 385 ----a2jmidid -e -u &
388 -- I think the jack_control start and my current alsa config means a2jmidid gets started anyway. But seem to need this bit to get the joystick covered. 386 -- I think the jack_control start and my current alsa config means a2jmidid gets started anyway. But seem to need this bit to get the joystick covered.
389 print("a2j_control") 387 print("a2j_control")
390 __('a2j_control --ehw && a2j_control --start'):Do() 388 __'a2j_control --ehw && a2j_control --start':Do()
391-- print("sleep 2") 389-- print("sleep 2")
392-- __('sleep 2'):Do() 390-- __('sleep 2'):Do()
393 print("") 391 print("")
@@ -395,9 +393,9 @@ elseif 'JACK' == args[1] then
395 393
396 394
397 local AIN = "alsa_in" 395 local AIN = "alsa_in"
398 if _.exists('zita-a2j') then AIN = 'zita-a2j' end 396 if _.runnable'zita-a2j' then AIN = 'zita-a2j' end
399 local AOUT = "alsa_out" 397 local AOUT = "alsa_out"
400 if _.exists('zita-j2a') then AOUT = 'zita-j2a' end 398 if _.runnable'zita-j2a' then AOUT = 'zita-j2a' end
401 399
402 print("Basic ALSA sound devices converted to JACK.") 400 print("Basic ALSA sound devices converted to JACK.")
403 for i,C in pairs(alias) do 401 for i,C in pairs(alias) do
@@ -406,15 +404,15 @@ elseif 'JACK' == args[1] then
406 end 404 end
407 print("HW playback: cloop\tDEVICE: cloop") 405 print("HW playback: cloop\tDEVICE: cloop")
408 -- No idea why, cloop wont work with zita-a2j. 406 -- No idea why, cloop wont work with zita-a2j.
409 __('alsa_in -j cloop -d cloop'):fork() 407 __'alsa_in -j cloop -d cloop':fork()
410 --__('sleep 1'):Do() 408 --__[[sleep 1
411 --__('jack_connect cloop:capture_1 system:playback_1'):Do() 409 -- jack_connect cloop:capture_1 system:playback_1o()
412 --__('jack_connect cloop:capture_2 system:playback_2'):Do() 410 -- jack_connect cloop:capture_2 system:playback_2]]:Do()
413 print("HW playback: ploop\tDEVICE: ploop") 411 print("HW playback: ploop\tDEVICE: ploop")
414 __('alsa_out -j ploop -d ploop'):fork() 412 __'alsa_out -j ploop -d ploop':fork()
415 --__('sleep 1'):Do() 413 --__[[sleep 1
416 --__('jack_connect system:capture_1 ploop:playback_1'):Do() 414 -- jack_connect system:capture_1 ploop:playback_1
417 --__('jack_connect system:capture_2 ploop:playback_2'):Do() 415 -- jack_connect system:capture_2 ploop:playback_2]]:Do()
418 416
419 417
420 print("") 418 print("")
@@ -424,7 +422,7 @@ elseif 'JACK' == args[1] then
424 for j,c in ipairs(C['playbackDevs']) do 422 for j,c in ipairs(C['playbackDevs']) do
425 print("HW playback: " .. C['name'] .. "\tDEVICE: " .. C['playbackDevs'][j]) 423 print("HW playback: " .. C['name'] .. "\tDEVICE: " .. C['playbackDevs'][j])
426 __(AOUT .. ' -j ' .. C['name'] .. "_" .. C['playbackDevs'][j] .. '-in -d ' .. C['name'] .. C['playbackDevs'][j]):fork() 424 __(AOUT .. ' -j ' .. C['name'] .. "_" .. C['playbackDevs'][j] .. '-in -d ' .. C['name'] .. C['playbackDevs'][j]):fork()
427 -- __('sleep 1'):Do() 425 -- __'sleep 1':Do()
428 -- __('jack_connect cloop:capture_1 ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in' .. ':playback_1'):Do() 426 -- __('jack_connect cloop:capture_1 ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in' .. ':playback_1'):Do()
429 -- __('jack_connect cloop:capture_2 ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in' .. ':playback_2'):Do() 427 -- __('jack_connect cloop:capture_2 ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in' .. ':playback_2'):Do()
430 end 428 end
@@ -435,9 +433,9 @@ elseif 'JACK' == args[1] then
435 end 433 end
436 print("") 434 print("")
437 435
438 if _.exists('aseqjoy') then 436 if _.runnable('aseqjoy') then
439 print("Scanning for joysticks.") 437 print("Scanning for joysticks.")
440 local sticks = __('ls -1 /dev/input/js[0-9]*'):noErr():Do() 438 local sticks = __'ls -1 /dev/input/js[0-9]*':noErr():Do()
441 for i,l in ipairs(sticks.lines) do 439 for i,l in ipairs(sticks.lines) do
442 print("aseqjoy " .. l) 440 print("aseqjoy " .. l)
443 -- Buttons switch to that numbered MIDI channel, defaults to 1. 441 -- Buttons switch to that numbered MIDI channel, defaults to 1.
@@ -448,14 +446,14 @@ elseif 'JACK' == args[1] then
448 print("") 446 print("")
449 end 447 end
450 448
451 if _.exists('jack-plumbing') then 449 if _.runnable('jack-plumbing') then
452 print('Stop our jack-plumbing, eventually.') 450 print('Stop our jack-plumbing, eventually.')
453 __('sleep 4'):Do() 451 __'sleep 4':Do()
454 _.killEmAll{"jack-plumbing"} 452 _.killEmAll{"jack-plumbing"}
455 end 453 end
456 454
457 if _.exists('~/.aataaj_JACK.lua') then 455 if _.runnable('~/.aataaj_JACK.lua') then
458 print('Running users aataaj_JACK.lua') 456 print('Running users aataaj_JACK.lua')
459 __('~/.aataaj_JACK.lua'):Do() 457 __'~/.aataaj_JACK.lua':Do()
460 end 458 end
461end 459end
diff --git a/test_.lua b/test_.lua
index 5e914b4..629c151 100755
--- a/test_.lua
+++ b/test_.lua
@@ -74,10 +74,10 @@ end
74 74
75 75
76local GUI = 'qjackctl' 76local GUI = 'qjackctl'
77if _.exists'catia' then GUI = 'catia' end 77if _.runnable'catia' then GUI = 'catia' end
78 78
79local speaker = 'espeak' 79local speaker = 'espeak'
80if _.exists'espeak-ng' then speaker = 'espeak-ng' end 80if _.runnable'espeak-ng' then speaker = 'espeak-ng' end
81 81
82 82
83 83
@@ -114,3 +114,5 @@ print(__'exit 42':log():show():Do().status)
114print(__'return 42':log():show():Do().status) 114print(__'return 42':log():show():Do().status)
115print(__'command NoSuchCommand':log():show():Do().status) 115print(__'command NoSuchCommand':log():show():Do().status)
116 116
117__'qpdfview':forkOnce()
118__'qpdfview':forkOnce()