From a5895a0696855c946025e156a392fba5898b8778 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Sat, 19 Oct 2024 15:37:35 +1000 Subject: Use the new exists function to decide what to do, and how. --- aataaj.lua | 71 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/aataaj.lua b/aataaj.lua index 83f870b..90749e2 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -265,11 +265,13 @@ end local asoundrcPath = '/var/lib/aataaj' local asoundrc = 'asoundrc' local GUI = 'qjackctl' ---local GUI = 'catia' +if APT.exists('catia') then GUI = 'catia' end local alias = { -- {name='Screen', dev='HDMI9'}, } +local speaker = 'espeak' +if APT.exists('espeak-ng') then speaker = 'espeak-ng' end local Cards = {} @@ -294,8 +296,8 @@ for i,l in ipairs(cards.lines) do Cards[l]['devs'][n] = n print("\tFound playback device " .. i - 1 .. " : " .. Cards[l]['name'] .. "\tDEVICE: " .. Cards[l]['playbackDevs'][j] .. ' ' .. n) if 'JACK' ~= args[1] then --- print('\t\tALSA_CARD=' .. i - 1 .. ' espeak "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') - APT.exe('ALSA_CARD=' .. i - 1 .. ' espeak "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"'):noErr():Do() + print('\t\tALSA_CARD=' .. i - 1 .. ' ' .. speaker .. ' "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') + APT.exe('ALSA_CARD=' .. i - 1 .. ' ' .. speaker .. ' "Found playback device ' .. i - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"'):noErr():Do() APT.exe('sleep 1') end end @@ -492,24 +494,28 @@ elseif 'JACK' == args[1] then print(GUI) APT.exe(GUI):fork() end - print("jack-plumbing") - APT.exe('jack-plumbing -o /var/lib/aataaj/jack-plumbing 2>/dev/null'):fork() - -- Bridge ALSA ports to JACK ports. Only handles MIDI. - -- 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)/ - --a2j_control actually starts a2jmidid. - ----a2jmidid -e -u & - -- 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. - print("a2j_control") - APT.exe('a2j_control --ehw && a2j_control --start'):Do() - print("sleep 2") - APT.exe('sleep 2'):Do() - print("") + if APT.exists('jack-plumbing') then + print("jack-plumbing") + APT.exe('jack-plumbing -o /var/lib/aataaj/jack-plumbing 2>/dev/null'):fork() + end + if APT.exists('a2j_control') then + -- Bridge ALSA ports to JACK ports. Only handles MIDI. + -- 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)/ + --a2j_control actually starts a2jmidid. + ----a2jmidid -e -u & + -- 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. + print("a2j_control") + APT.exe('a2j_control --ehw && a2j_control --start'):Do() +-- print("sleep 2") +-- APT.exe('sleep 2'):Do() + print("") + end - --local AIN = "alsa_in" - local AIN = "zita-a2j" - --local AOUT = "alsa_out" - local AOUT = "zita-j2a" + local AIN = "alsa_in" + if APT.exists('zita-a2j') then AIN = 'zita-a2j' end + local AOUT = "alsa_out" + if APT.exists('zita-j2a') then AOUT = 'zita-j2a' end print("Basic ALSA sound devices converted to JACK.") for i,C in pairs(alias) do @@ -547,14 +553,17 @@ elseif 'JACK' == args[1] then end print("") - print("Scanning for joysticks.") - local sticks = APT.exe('ls -1 /dev/input/js[0-9]*'):noErr():Do() - for i,l in ipairs(sticks.lines) do - print("aseqjoy " .. l) - -- Buttons switch to that numbered MIDI channel, defaults to 1. - -- Axis are mapped to MIDI controllers 10 - 15 - -- -r means to use high resolution MIDI values. - APT.exe('aseqjoy -d ' .. l:sub(-1,-1) .. ' -r'):fork() + if APT.exists('aseqjoy') then + print("Scanning for joysticks.") + local sticks = APT.exe('ls -1 /dev/input/js[0-9]*'):noErr():Do() + for i,l in ipairs(sticks.lines) do + print("aseqjoy " .. l) + -- Buttons switch to that numbered MIDI channel, defaults to 1. + -- Axis are mapped to MIDI controllers 10 - 15 + -- -r means to use high resolution MIDI values. + APT.exe('aseqjoy -d ' .. l:sub(-1,-1) .. ' -r'):fork() + end + print("") end print('qsynth') @@ -562,7 +571,9 @@ elseif 'JACK' == args[1] then print("") - print('Stop our jack-plumbing, eventually.') - APT.exe('sleep 4'):Do() - APT.killEmAll("jack-plumbing"):Do() + if APT.exists('jack-plumbing') then + print('Stop our jack-plumbing, eventually.') + APT.exe('sleep 4'):Do() + APT.killEmAll{"jack-plumbing"} + end end -- cgit v1.1