root/branches/libffado-2.0/support/mixer-qt4/mixer_saffire_base.py

Revision 1367, 6.0 kB (checked in by ppalmers, 12 years ago)

use the python logging framework for the mixer debug messages (QT4 only)

Line 
1 #
2 # Copyright (C) 2005-2008 by Pieter Palmers
3 #
4 # This file is part of FFADO
5 # FFADO = Free Firewire (pro-)audio drivers for linux
6 #
7 # FFADO is based upon FreeBoB.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 2 of the License, or
12 # (at your option) version 3 of the License.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 from PyQt4.QtCore import SIGNAL, SLOT, QObject
24
25 import logging
26 log = logging.getLogger('saffirebase')
27
28 # the class that holds all actual control code
29 class SaffireMixerBase:
30     def __init__(self):
31         pass
32
33     def updateMatrixVolume(self,a0):
34         sender = self.sender()
35         #vol = 0x7FFF-a0
36         vol = a0
37         log.debug("set %s %d %d to %d" % (
38                     self.VolumeControls[sender][0],
39                     self.VolumeControls[sender][1],
40                     self.VolumeControls[sender][2],
41                     vol))
42         self.hw.setMatrixMixerValue(self.VolumeControls[sender][0],
43                                     self.VolumeControls[sender][1],
44                                     self.VolumeControls[sender][2],
45                                     vol)
46     def updateLowResVolume(self,a0):
47         sender = self.sender()
48         vol = a0
49         log.debug("set %s to %d" % (
50                     self.VolumeControlsLowRes[sender][0],
51                     vol))
52         self.hw.setDiscrete(self.VolumeControlsLowRes[sender][0], vol)
53
54     def updateSelector(self,a0):
55         sender = self.sender()
56         if a0:
57             state = 1
58         else:
59             state = 0
60         log.debug("set %s to %d" % (
61                     self.SelectorControls[sender][0],
62                     state))
63         self.hw.setDiscrete(self.SelectorControls[sender][0], state)
64
65         # if there are linked selector controls, update them
66         if len(self.SelectorControls[sender]) >= 2:
67             linked = self.SelectorControls[sender][1]
68             for ctl in linked:
69                 if ctl.state():
70                     state = 1
71                 else:
72                     state = 0
73                 self.hw.setDiscrete(self.SelectorControls[ctl][0], state)
74
75     def triggerButton(self):
76         sender = self.sender()
77         log.debug("trigger %s" % (
78                     self.TriggerButtonControls[sender][0]))
79         self.hw.setDiscrete(self.TriggerButtonControls[sender][0], 1)
80
81     def saveText(self):
82         sender = self.sender()
83         textbox = self.saveTextControls[sender][0]
84         log.debug("save %s" % (
85                     textbox.text().ascii()))
86         self.hw.setText(self.TextControls[textbox][0], textbox.text().ascii())
87
88     def initCombo(self, combo):
89         path = self.ComboControls[combo][0]
90         combo.clear()
91         nb_items = self.hw.enumCount(path)
92         for i in range( nb_items ):
93             combo.insertItem( nb_items, self.hw.enumGetLabel(path, i) )
94         combo.setCurrentIndex( self.hw.enumSelected(path) )
95
96     def selectCombo(self, mode):
97         sender = self.sender()
98         path = self.ComboControls[sender][0]
99         self.hw.enumSelect(path, mode)
100         sender.setCurrentIndex( self.hw.enumSelected(path) )
101
102     def updateValues(self):
103         for ctrl, info in self.VolumeControls.iteritems():
104             vol = self.hw.getMatrixMixerValue(self.VolumeControls[ctrl][0],
105                                                 self.VolumeControls[ctrl][1],
106                                                 self.VolumeControls[ctrl][2])
107             log.debug("%s volume is %d" % (ctrl.objectName() , 0x7FFF-vol))
108             #ctrl.setValue(0x7FFF-vol)
109             ctrl.setValue(vol)
110         for ctrl, info in self.VolumeControlsLowRes.iteritems():
111             vol = self.hw.getDiscrete(self.VolumeControlsLowRes[ctrl][0])
112
113             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
114             ctrl.setValue(vol)
115
116         for ctrl, info in self.SelectorControls.iteritems():
117             state = self.hw.getDiscrete(self.SelectorControls[ctrl][0])
118             log.debug("%s state is %d" % (ctrl.objectName() , state))
119             if state:
120                 ctrl.setChecked(True)
121             else:
122                 ctrl.setChecked(False)
123
124         for ctrl, info in self.TriggerButtonControls.iteritems():
125             pass
126
127         for ctrl, info in self.TextControls.iteritems():
128             text = self.hw.getText(self.TextControls[ctrl][0])
129             log.debug("%s text is %s" % (ctrl.objectName() , text))
130             ctrl.setText(text)
131
132         for ctrl, info in self.ComboControls.iteritems():
133             self.initCombo(ctrl)
134
135     def polledUpdateVolumeLowRes(self, srcpath, ctrl):
136         vol = self.hw.getDiscrete(srcpath)
137         #log.debug("polledUpdateVolumeLowRes: vol = %s" % vol)
138         #ctrl.setValue(255-vol)
139         ctrl.setValue(vol)
140
141     def initValues(self):
142         self.updateValues()
143         for ctrl, info in self.VolumeControls.iteritems():
144             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixVolume)
145
146         for ctrl, info in self.VolumeControlsLowRes.iteritems():
147             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateLowResVolume)
148
149         for ctrl, info in self.SelectorControls.iteritems():
150             QObject.connect(ctrl,SIGNAL('stateChanged(int)'),self.updateSelector)
151
152         for ctrl, info in self.TriggerButtonControls.iteritems():
153             QObject.connect(ctrl,SIGNAL('clicked()'),self.triggerButton)
154
155         for ctrl, info in self.saveTextControls.iteritems():
156             QObject.connect(ctrl,SIGNAL('clicked()'), self.saveText)
157
158         for ctrl, info in self.ComboControls.iteritems():
159             QObject.connect(ctrl, SIGNAL('activated(int)'), self.selectCombo)
Note: See TracBrowser for help on using the browser.