root/trunk/libffado/support/mixer-qt4/ffado/mixer/generic_dice_eap.py

Revision 2473, 5.4 kB (checked in by philippe, 9 years ago)

ffado-mixer/DICE EAP: file saving of settings. Complementary commit: Add saving of mixer section

  • Property svn:mergeinfo set to
Line 
1 #
2 # Copyright (C) 2009-2010 by Arnold Krille
3 #               2013 by Philippe Carriere
4 #
5 # This file is part of FFADO
6 # FFADO = Free Firewire (pro-)audio drivers for linux
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 2 of the License, or
11 # (at your option) version 3 of the License.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 from PyQt4 import QtGui, QtCore, Qt
23 import dbus
24
25 from ffado.widgets.matrixmixer import MatrixMixer
26 from ffado.widgets.crossbarrouter import *
27
28 from ffado.config import *
29
30 class Generic_Dice_EAP(QtGui.QWidget):
31     def __init__(self, parent=None):
32         QtGui.QWidget.__init__(self, parent)
33         self.layout = QtGui.QGridLayout(self)
34         self.setLayout(self.layout)
35         self.tabs = QtGui.QTabWidget(self)
36         self.tabs.setTabPosition(QtGui.QTabWidget.West)
37         self.layout.addWidget(self.tabs)
38
39     def buildMixer(self):
40         #print self.hw
41         #print self.hw.getText("/Generic/Nickname")
42         self.mixer = MatrixMixer(self.hw.servername, self.hw.basepath+"/EAP/MatrixMixer", self, "Columns_are_outputs", -1, None, None, False, QtGui.QTabWidget.North, QtGui.QTabWidget.Rounded)
43         self.tabs.addTab(self.mixer, "Mixer")
44
45         self.router_scrollarea = self.buildRouter(self.hw.servername, self.hw.basepath+"/EAP/Router")
46         self.tabs.addTab(self.router_scrollarea, "Crossbar Router")
47
48     def buildRouter(self, servername, path):
49         self.router = CrossbarRouter(servername, path, self)
50         self.connect(self.router, QtCore.SIGNAL("MixerRoutingChanged"), self.mixer.updateRouting)
51         scrollarea = QtGui.QScrollArea(self.tabs)
52         scrollarea.setWidgetResizable(True)
53         scrollarea.setWidget(self.router)
54         return scrollarea
55
56     def onSamplerateChange(self):
57         # Router configuration is samplerate dependent for DICE EAP devices
58         # Destroy and redraw the crossbar router view when called
59         n = self.tabs.indexOf(self.router_scrollarea)
60         self.tabs.removeTab(n)
61         self.router.destroy()
62         self.router_scrollarea.destroy()
63
64         self.router_scrollarea = self.buildRouter(self.hw.servername, self.hw.basepath+"/EAP/Router")
65         self.tabs.insertTab(n, self.router_scrollarea, "Crossbar Router")
66         self.tabs.setCurrentWidget(self.router_scrollarea)
67
68         self.mixer.updateRouting()
69
70     def saveSettings(self, indent):
71         saveString = []
72         idt = indent + "  "
73         saveString.append('%s<mixer>\n' % indent)
74         saveString.extend(self.mixer.saveSettings(idt))
75         # Do not forget to mention the adopted rule for matrix columns mixer
76         #  This might be useful for future import function
77         saveString.append("%s  <col_rule>\n" % indent)
78         saveString.append("%s    Columns_are_outputs\n" % indent)
79         saveString.append("%s  </col_rule>\n" % indent)
80         saveString.append('%s</mixer>\n' % indent)
81         saveString.append('%s<router>\n' % indent)
82         saveString.extend(self.router.saveSettings(idt))
83         saveString.append('%s</router>\n' % indent)
84         return saveString
85
86     def readSettings(self, readString):
87         try:
88             idxb = readString.index('<mixer>')
89             idxe = readString.index('</mixer>')
90         except Exception:
91             log.debug("No mixer settings found")
92             idxb = -1
93             idxe = -1
94         if idxb >= 0:
95             if idxe > idxb + 1:
96                 stringMixer = []
97                 for s in readString[idxb+1:idxe]:
98                     stringMixer.append(s)
99                 # When trying to import from a different device, the rule for column interpretation is
100                 # not necessarily the same
101                 try:
102                     idx = stringMixer.index('<col_rule>')
103                 except Exception:
104                     log.debug('Do not know how to handle column versus input/output')
105                     idx = -1
106                 transpose_coeff = False
107                 if idx >=0:
108                     if stringMixer[idx+1].find("Columns_are_outputs") == -1:
109                         log.debug('Transposing the matrix coefficient; you are importing, are not you ?')
110                         transpose_coeff = True
111                 if self.mixer.readSettings(stringMixer, transpose_coeff):
112                     log.debug("Mixer settings modified")
113                 del stringMixer
114         try:
115             idxb = readString.index('<router>')
116             idxe = readString.index('</router>')
117         except Exception:
118             log.debug("No router settings found")
119             idxb = -1
120             idxe = -1
121         if idxb >= 0:
122             if idxe > idxb + 1:
123                 stringRouter = []
124                 for s in readString[idxb+1:idxe]:
125                     stringRouter.append(s)
126                 if self.router.readSettings(stringRouter):
127                     log.debug("Router settings modified")
128                 del stringRouter
129
130     #def getDisplayTitle(self):
131     #    return "Saffire PRO40/PRO24 Mixer"
132
133 #
134 # vim: et ts=4 sw=4
Note: See TracBrowser for help on using the browser.