' Gambas module file

' Copyright(C) 2011-2014, Michał Głowienka aka eloaders <eloaders@linux.pl>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Public Logs As New Logger
Public Version As String
Public ASOUND_ID As String
Public ASOUND_CODEC As String
Public ASOUND_ALSADV As String
Public ASOUND_INPUT As String
Public Id As String
Public hwdep As String
Public pcm As String
Public sound_cards As String

Public Sub _inits()
  Dim ASOUND_CARDS As String
  Dim ASOUND_CARDS_LIST As String[]
  Dim i As Integer
  
  Shell "grep '\\[' /proc/asound/cards | cut -d ':' -f 2" Wait To ASOUND_CARDS
  ASOUND_CARDS_LIST = Split(ASOUND_CARDS, "\n", "%%")
  For i = 1 To ASOUND_CARDS_LIST.Count - 1
   If ASOUND_CARDS_LIST[i] = Null Then
    ASOUND_CARDS_LIST.Delete(i)
   Endif
  Next
   Finfosys.ComboBox6.List = ASOUND_CARDS_LIST
   Finfosys.ComboBox6.Index = 0
   _get_informations()
End

Public Sub _get_informations()
   Dim ASOUND_INPUT As String
   Dim ASOUND_INPUT_LIST_NAME As String
   Dim ASOUND_INPUT_LIST As String[]
   Dim i As Integer
   Try ASOUND_ID = File.Load("/proc/asound/card" & Finfosys.ComboBox6.Index & "/id")
   Try ASOUND_ALSADV = File.Load("/proc/asound/version")
   ASOUND_ID = Replace(ASOUND_ID, "\n", "")
   Shell "grep 'Codec:' /proc/asound/" & ASOUND_ID & "/codec*" Wait To ASOUND_CODEC
   Finfosys.Label73.Text = Replace(ASOUND_CODEC, "\n", "") & "  "
   Finfosys.Label9.Text = Replace(Replace(ASOUND_ALSADV, "\n", ""), "Advanced Linux Sound Architecture", "ALSA")
   Shell "ls /sys/class/sound/card" & Finfosys.ComboBox6.Index & " | grep input | sort" Wait To ASOUND_INPUT
   ASOUND_INPUT_LIST = Split(ASOUND_INPUT, "\n", "%%")
   
   For i = 1 To ASOUND_INPUT_LIST.Count - 1
    If ASOUND_INPUT_LIST[i] = Null Then
       ASOUND_INPUT_LIST.Delete(i)
    Endif
   Next
   Finfosys.ComboBox9.List = ASOUND_INPUT_LIST
   Finfosys.ComboBox9.Index = 0
   'ComboBox9
   'file:///sys/class/sound/card0/input6/name
   
End

Public Sub _INPUT_NAME()
 Try Finfosys.Label78.text = Replace(File.Load("/sys/class/sound/card" & Finfosys.ComboBox6.Index & "/" & Finfosys.ComboBox9.Text & "/name"), "\n", "")
 Try Finfosys.TextArea18.text = File.Load("/proc/asound/card" & Finfosys.ComboBox6.Index & "/codec#0")
 
End
