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

Revision 1298, 5.9 kB (checked in by ppalmers, 13 years ago)

add Qt4 port of the mixer (only for audiofire and saffire ATM). needed since PyQt?3 doesn't support DBUS signals.

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 # the class that holds all actual control code
26 class SaffireMixerBase:
27     def __init__(self):
28         pass
29
30     def updateMatrixVolume(self,a0):
31         sender = self.sender()
32         #vol = 0x7FFF-a0
33         vol = a0
34         print "set %s %d %d to %d" % (
35                     self.VolumeControls[sender][0],
36                     self.VolumeControls[sender][1],
37                     self.VolumeControls[sender][2],
38                     vol)
39         self.hw.setMatrixMixerValue(self.VolumeControls[sender][0],
40                                     self.VolumeControls[sender][1],
41                                     self.VolumeControls[sender][2],
42                                     vol)
43     def updateLowResVolume(self,a0):
44         sender = self.sender()
45         vol = a0
46         print "set %s to %d" % (
47                     self.VolumeControlsLowRes[sender][0],
48                     vol)
49         self.hw.setDiscrete(self.VolumeControlsLowRes[sender][0], vol)
50
51     def updateSelector(self,a0):
52         sender = self.sender()
53         if a0:
54             state = 1
55         else:
56             state = 0
57         print "set %s to %d" % (
58                     self.SelectorControls[sender][0],
59                     state)
60         self.hw.setDiscrete(self.SelectorControls[sender][0], state)
61
62         # if there are linked selector controls, update them
63         if len(self.SelectorControls[sender]) >= 2:
64             linked = self.SelectorControls[sender][1]
65             for ctl in linked:
66                 if ctl.state():
67                     state = 1
68                 else:
69                     state = 0
70                 self.hw.setDiscrete(self.SelectorControls[ctl][0], state)
71
72     def triggerButton(self):
73         sender = self.sender()
74         print "trigger %s" % (
75                     self.TriggerButtonControls[sender][0])
76         self.hw.setDiscrete(self.TriggerButtonControls[sender][0], 1)
77
78     def saveText(self):
79         sender = self.sender()
80         textbox = self.saveTextControls[sender][0]
81         print "save %s" % (
82                     textbox.text().ascii())
83         self.hw.setText(self.TextControls[textbox][0], textbox.text().ascii())
84
85     def initCombo(self, combo):
86         path = self.ComboControls[combo][0]
87         combo.clear()
88         nb_items = self.hw.enumCount(path)
89         for i in range( nb_items ):
90             combo.insertItem( nb_items, self.hw.enumGetLabel(path, i) )
91         combo.setCurrentIndex( self.hw.enumSelected(path) )
92
93     def selectCombo(self, mode):
94         sender = self.sender()
95         path = self.ComboControls[sender][0]
96         self.hw.enumSelect(path, mode)
97         sender.setCurrentIndex( self.hw.enumSelected(path) )
98
99     def updateValues(self):
100         for ctrl, info in self.VolumeControls.iteritems():
101             vol = self.hw.getMatrixMixerValue(self.VolumeControls[ctrl][0],
102                                                 self.VolumeControls[ctrl][1],
103                                                 self.VolumeControls[ctrl][2])
104             print "%s volume is %d" % (ctrl.objectName() , 0x7FFF-vol)
105             #ctrl.setValue(0x7FFF-vol)
106             ctrl.setValue(vol)
107         for ctrl, info in self.VolumeControlsLowRes.iteritems():
108             vol = self.hw.getDiscrete(self.VolumeControlsLowRes[ctrl][0])
109
110             print "%s volume is %d" % (ctrl.objectName() , vol)
111             ctrl.setValue(vol)
112
113         for ctrl, info in self.SelectorControls.iteritems():
114             state = self.hw.getDiscrete(self.SelectorControls[ctrl][0])
115             print "%s state is %d" % (ctrl.objectName() , state)
116             if state:
117                 ctrl.setChecked(True)
118             else:
119                 ctrl.setChecked(False)
120
121         for ctrl, info in self.TriggerButtonControls.iteritems():
122             pass
123
124         for ctrl, info in self.TextControls.iteritems():
125             text = self.hw.getText(self.TextControls[ctrl][0])
126             print "%s text is %s" % (ctrl.objectName() , text)
127             ctrl.setText(text)
128
129         for ctrl, info in self.ComboControls.iteritems():
130             self.initCombo(ctrl)
131
132     def polledUpdateVolumeLowRes(self, srcpath, ctrl):
133         vol = self.hw.getDiscrete(srcpath)
134         #print "polledUpdateVolumeLowRes: vol = %s" % vol
135         #ctrl.setValue(255-vol)
136         ctrl.setValue(vol)
137
138     def initValues(self):
139         self.updateValues()
140         for ctrl, info in self.VolumeControls.iteritems():
141             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixVolume)
142
143         for ctrl, info in self.VolumeControlsLowRes.iteritems():
144             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateLowResVolume)
145
146         for ctrl, info in self.SelectorControls.iteritems():
147             QObject.connect(ctrl,SIGNAL('stateChanged(int)'),self.updateSelector)
148
149         for ctrl, info in self.TriggerButtonControls.iteritems():
150             QObject.connect(ctrl,SIGNAL('clicked()'),self.triggerButton)
151
152         for ctrl, info in self.saveTextControls.iteritems():
153             QObject.connect(ctrl,SIGNAL('clicked()'), self.saveText)
154
155         for ctrl, info in self.ComboControls.iteritems():
156             QObject.connect(ctrl, SIGNAL('activated(int)'), self.selectCombo)
Note: See TracBrowser for help on using the browser.