root/trunk/libffado/support/mixer-qt4/ffado_configuration.py

Revision 1435, 2.5 kB (checked in by arnonym, 12 years ago)

forward port the mixer-changes from 2.0-branch r1361:HEAD

Line 
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2008 by Arnold Krille
4 #
5 # This file is part of FFADO
6 # FFADO = Free Firewire (pro-)audio drivers for linux
7 #
8 # FFADO is based upon FreeBoB.
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 import re, os
25
26 class DeviceList:
27         def __init__( self, filename="" ):
28                 self.devices = list()
29                 if not filename == "":
30                         self.updateFromFile( filename )
31
32         def updateFromFile( self, filename ):
33                 if not os.path.exists( filename ):
34                         return
35                 f = open( filename, "r" )
36                 stream = f.read()
37                 stream = re.sub( "#[^#\n]*\n", "\n", stream )                               # remove the comments
38                 stream = re.sub( "\s", "", stream )                                         # remove all white-spaces and line-breaks
39                 stream = stream.replace( "device_definitions=({", "" ).replace( "});", "" ) # remove the trail and end
40                 stream = stream.replace( "\"", "" )                                         # remove the "'s around
41
42                 dev_strings = stream.split( "},{" )
43                 for s in dev_strings:
44                         item = dict()
45                         pairs = s.split(";")
46                         for p in pairs:
47                                 if not p == "":
48                                         key = p[0:p.find("=")]
49                                         value = p[p.find("=")+1:]
50                                         if re.search( "^0x[0-9a-fA-F]*", value ) != None: # convert hex-numbers to int
51                                                 value = int( value, 16 )              # or should it be long?
52                                         item[ key ] = value
53                         self.addDevice( item )
54
55         def getDeviceById( self, vendor, model ):
56                 #print "DeviceList::getDeviceById( %s, %s )" % (vendor, model )
57                 for dev in self.devices:
58                         if dev['vendorid'] == vendor and dev['modelid'] == model:
59                                 return dev
60                 tmp = dict()
61                 self.devices.append( tmp )
62                 return tmp
63
64         def addDevice( self, device_dict ):
65                 #print "DeviceList::addDevice()"
66                 dev = self.getDeviceById( device_dict['vendorid'], device_dict['modelid'] )
67                 dev.update( device_dict )
68
69
70 #
71 # Have kind of a test directly included...
72 #
73 if __name__ == "__main__":
74
75         import sys
76
77         file = sys.argv[1]
78
79         devs = DeviceList( file )
80
81         print devs.devices
82
Note: See TracBrowser for help on using the browser.