aboutsummaryrefslogtreecommitdiffstats
path: root/aataaj.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xaataaj.lua77
1 files changed, 51 insertions, 26 deletions
diff --git a/aataaj.lua b/aataaj.lua
index e044ed1..9acea95 100755
--- a/aataaj.lua
+++ b/aataaj.lua
@@ -141,45 +141,44 @@ if _.runnable('espeak-ng') then speaker = 'espeak-ng' end
141 141
142 142
143local Cards = {} 143local Cards = {}
144local cnt = 0
144 145
145print('Scanning for audio devices.') 146print('Scanning for audio devices.')
146local cards = __'ls -d1 /proc/asound/card[0-9]*':noErr():Do() 147local cards = __'ls -d1 /proc/asound/card[0-9]*':noErr():Do()
147for i,l in ipairs(cards.lines) do 148for 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
174end 177end
178table.sort(Cards, function(a, b) return a.card < b.card end)
175print('') 179print('')
176io.flush() 180io.flush()
177 181
178-- #Cards kept telling me 0, no number indexes.
179local cnt = 0
180for i,C in pairs(Cards) do
181 cnt = cnt + 1
182end
183 182
184print('Your ' .. cnt .. ' audio devices are ') 183print('Your ' .. cnt .. ' audio devices are ')
185for k,C in pairs(Cards) do 184for k,C in pairs(Cards) do
@@ -193,13 +192,28 @@ io.flush()
193for k,C in pairs(Cards) do 192for 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()
199end 198end
200print('') 199print('')
201io.flush() 200io.flush()
202 201
202for 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()
205end
206io.write('Please type the device number you heard best - ')
207local 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".
208local ourCard = ''
209
210for 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
215end
216
203 217
204if 'start' == arg[1] then 218if '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([[