diff options
author | dvs1 | 2024-10-28 23:32:26 +1000 |
---|---|---|
committer | dvs1 | 2024-10-28 23:32:26 +1000 |
commit | 04dffa36f6040b661bf1af8f98e2ce1978a7df33 (patch) | |
tree | a206d1597cec0a1932794f693f335405ba24289b /aataaj.lua | |
parent | More clean ups. (diff) | |
download | JackOnAllDevices-04dffa36f6040b661bf1af8f98e2ce1978a7df33.zip JackOnAllDevices-04dffa36f6040b661bf1af8f98e2ce1978a7df33.tar.gz JackOnAllDevices-04dffa36f6040b661bf1af8f98e2ce1978a7df33.tar.bz2 JackOnAllDevices-04dffa36f6040b661bf1af8f98e2ce1978a7df33.tar.xz |
Let the user pick the best sound device.
Diffstat (limited to 'aataaj.lua')
-rwxr-xr-x | aataaj.lua | 77 |
1 files changed, 51 insertions, 26 deletions
@@ -141,45 +141,44 @@ if _.runnable('espeak-ng') then speaker = 'espeak-ng' end | |||
141 | 141 | ||
142 | 142 | ||
143 | local Cards = {} | 143 | local Cards = {} |
144 | local cnt = 0 | ||
144 | 145 | ||
145 | print('Scanning for audio devices.') | 146 | print('Scanning for audio devices.') |
146 | local cards = __'ls -d1 /proc/asound/card[0-9]*':noErr():Do() | 147 | local cards = __'ls -d1 /proc/asound/card[0-9]*':noErr():Do() |
147 | for i,l in ipairs(cards.lines) do | 148 | for i,l in ipairs(cards.lines) do |
148 | local f, e = io.open(l .. '/id', 'r') | 149 | local f, e = io.open(l .. '/id', 'r') |
149 | if nil == f then print('Could not open ' .. l .. '/id') else | 150 | if nil == f then print('Could not open ' .. l .. '/id - ' .. e) else |
150 | Cards[l] = {path = l, name = f:read('*a'):sub(1, -2), devs = {}, captureDevs = {}, playbackDevs = {}, card=i} | 151 | local n = f:read('*a'):sub(1, -2) |
151 | if 'Loopback' ~= Cards[l]['name'] then | 152 | Cards[n] = {path = l, name = n, devs = {}, captureDevs = {}, playbackDevs = {}, card=i} |
152 | Cards[l]['capture'] = __('ls -d1 ' .. l .. '/pcm[0-9]*c*'):noErr():Do() | 153 | cnt = cnt + 1 |
153 | for j,c in ipairs(Cards[l]['capture'].lines) do | 154 | if 'Loopback' ~= Cards[n]['name'] then |
154 | local n = c:match('.*pcm(%d+).*') | 155 | Cards[n]['capture'] = __('ls -d1 ' .. l .. '/pcm[0-9]*c*'):noErr():Do() |
155 | Cards[l]['captureDevs'][j] = n | 156 | for j,c in ipairs(Cards[n]['capture'].lines) do |
156 | Cards[l]['devs'][n] = n | 157 | local m = c:match('.*pcm(%d+).*') |
157 | print('\tFound capture device: ' .. Cards[l]['name'] .. '\tDEVICE: ' .. Cards[l]['captureDevs'][j] .. ' ' .. n) | 158 | Cards[n]['captureDevs'][j] = m |
159 | Cards[n]['devs'][m] = m | ||
160 | print('\tFound capture device: ' .. Cards[n]['name'] .. '\tDEVICE: ' .. Cards[n]['captureDevs'][j] .. ' ' .. m) | ||
158 | io.flush() | 161 | io.flush() |
159 | end | 162 | end |
160 | Cards[l]['playback'] = __('ls -d1 ' .. l .. '/pcm[0-9]*p*'):noErr():Do() | 163 | Cards[n]['playback'] = __('ls -d1 ' .. l .. '/pcm[0-9]*p*'):noErr():Do() |
161 | for j,p in ipairs(Cards[l]['playback'].lines) do | 164 | for j,p in ipairs(Cards[n]['playback'].lines) do |
162 | local n = p:match('.*pcm(%d+).*') | 165 | local m = p:match('.*pcm(%d+).*') |
163 | Cards[l]['playbackDevs'][j] = n | 166 | Cards[n]['playbackDevs'][j] = m |
164 | Cards[l]['devs'][n] = n | 167 | Cards[n]['devs'][m] = m |
165 | print('\tFound playback device ' .. Cards[l].card - 1 .. ' : ' .. Cards[l]['name'] .. '\tDEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n) | 168 | print('\tFound playback device ' .. Cards[n].card - 1 .. ' : ' .. Cards[n]['name'] .. '\tDEVICE: ' .. Cards[n]['playbackDevs'][j] .. ' ' .. m) |
166 | io.flush() | 169 | io.flush() |
167 | if 'JACK' ~= arg[1] then | 170 | if 'JACK' ~= arg[1] then |
168 | print('\t\tALSA_CARD=' .. Cards[l].card - 1 .. ' ' .. speaker .. ' "Found playback device ' .. Cards[l].card - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') | 171 | print('\t\tALSA_CARD=' .. Cards[n].card - 1 .. ' ' .. speaker .. ' "Found playback device ' .. Cards[n].card - 1 .. ' : ' .. Cards[n]['name'] .. ' DEVICE: ' .. Cards[n]['playbackDevs'][j] .. ' ' .. m .. '"') |
169 | io.flush() | 172 | io.flush() |
170 | end | 173 | end |
171 | end | 174 | end |
172 | end | 175 | end |
173 | end | 176 | end |
174 | end | 177 | end |
178 | table.sort(Cards, function(a, b) return a.card < b.card end) | ||
175 | print('') | 179 | print('') |
176 | io.flush() | 180 | io.flush() |
177 | 181 | ||
178 | -- #Cards kept telling me 0, no number indexes. | ||
179 | local cnt = 0 | ||
180 | for i,C in pairs(Cards) do | ||
181 | cnt = cnt + 1 | ||
182 | end | ||
183 | 182 | ||
184 | print('Your ' .. cnt .. ' audio devices are ') | 183 | print('Your ' .. cnt .. ' audio devices are ') |
185 | for k,C in pairs(Cards) do | 184 | for k,C in pairs(Cards) do |
@@ -193,13 +192,28 @@ io.flush() | |||
193 | for k,C in pairs(Cards) do | 192 | for k,C in pairs(Cards) do |
194 | print('' .. C.card - 1 .. ' : ' .. C.name) | 193 | print('' .. C.card - 1 .. ' : ' .. C.name) |
195 | __('echo "' .. C.card - 1 .. ' : ' .. C.name .. '"') | 194 | __('echo "' .. C.card - 1 .. ' : ' .. C.name .. '"') |
196 | __('ALSA_CARD=' .. C.card - 1 .. ' ' .. speaker .. ' "Device ' .. C.card - 1 .. ' ' .. C.name .. '"'):log():noErr():noOut():Do() | 195 | __('ALSA_CARD=' .. C.card - 1 .. ' ' .. speaker .. ' "Device number ' .. C.card - 1 .. ' ' .. C.name .. '"'):log():noErr():noOut():Do() |
197 | io.flush() | 196 | io.flush() |
198 | __'sleep 1':Do() | 197 | __'sleep 1':Do() |
199 | end | 198 | end |
200 | print('') | 199 | print('') |
201 | io.flush() | 200 | io.flush() |
202 | 201 | ||
202 | for k,C in pairs(Cards) do | ||
203 | print('' .. C.card - 1 .. ' : ' .. C.name) | ||
204 | __('ALSA_CARD=' .. C.card - 1 .. ' ' .. speaker .. ' "Please type the device number you heard best."'):log():noErr():noOut():fork() | ||
205 | end | ||
206 | io.write('Please type the device number you heard best - ') | ||
207 | local choice = tonumber(io.read()) -- Lua has no way of just checking IF there is ANY input, so can't do "check if there was a keypress, continue if not". | ||
208 | local ourCard = '' | ||
209 | |||
210 | for k,C in pairs(Cards) do | ||
211 | if (C.card - 1) == choice then | ||
212 | print('You choose ' .. choice .. ' ' .. C.name) | ||
213 | ourCard = C.name | ||
214 | end | ||
215 | end | ||
216 | |||
203 | 217 | ||
204 | if 'start' == arg[1] then | 218 | if 'start' == arg[1] then |
205 | __('mkdir -p ' .. options.asoundrcPath.value):Do() | 219 | __('mkdir -p ' .. options.asoundrcPath.value):Do() |
@@ -218,10 +232,8 @@ if 'start' == arg[1] then | |||
218 | ]]) | 232 | ]]) |
219 | a:close() | 233 | a:close() |
220 | end | 234 | end |
221 | local a, e = io.open(options.asoundrcPath.value .. '/' .. options.asoundrc.value, 'w') | 235 | |
222 | if nil == a then print('Could not open ' .. options.asoundrcPath.value .. '/' .. options.asoundrc.value) else | 236 | local outCard = function(a, C, j) |
223 | for i,C in pairs(Cards) do | ||
224 | for j,c in pairs(C['devs']) do | ||
225 | a:write('pcm.' .. C['name'] .. j .. ' {\n') | 237 | a:write('pcm.' .. C['name'] .. j .. ' {\n') |
226 | a:write(' type hw\n') | 238 | a:write(' type hw\n') |
227 | a:write(' card ' .. C['name'] .. '\n') | 239 | a:write(' card ' .. C['name'] .. '\n') |
@@ -232,6 +244,19 @@ if 'start' == arg[1] then | |||
232 | a:write(' card ' .. C['name'] .. '\n') | 244 | a:write(' card ' .. C['name'] .. '\n') |
233 | a:write(' device ' .. C['devs'][j] .. '\n') | 245 | a:write(' device ' .. C['devs'][j] .. '\n') |
234 | a:write('}\n\n') | 246 | a:write('}\n\n') |
247 | end | ||
248 | |||
249 | local a, e = io.open(options.asoundrcPath.value .. '/' .. options.asoundrc.value, 'w') | ||
250 | if nil == a then print('Could not open ' .. options.asoundrcPath.value .. '/' .. options.asoundrc.value .. ' - ' .. e) else | ||
251 | print('Writing suggested ALSA configuration file to ' .. options.asoundrcPath.value .. '/' .. options.asoundrc.value) | ||
252 | if '' ~= ourCard then | ||
253 | outCard(a, Cards[ourCard], '0') -- How the fuck is that a string? | ||
254 | end | ||
255 | for i,C in pairs(Cards) do | ||
256 | for j,c in pairs(C['devs']) do | ||
257 | if C.name ~= ourCard then | ||
258 | outCard(a, C, j) | ||
259 | end | ||
235 | end | 260 | end |
236 | end | 261 | end |
237 | a:write([[ | 262 | a:write([[ |