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 = a0 |
---|
36 |
log.debug("set %s %d %d to %d" % ( |
---|
37 |
self.VolumeControls[sender][0], |
---|
38 |
self.VolumeControls[sender][1], |
---|
39 |
self.VolumeControls[sender][2], |
---|
40 |
vol)) |
---|
41 |
self.hw.setMatrixMixerValue(self.VolumeControls[sender][0], |
---|
42 |
self.VolumeControls[sender][1], |
---|
43 |
self.VolumeControls[sender][2], |
---|
44 |
vol) |
---|
45 |
def updateLowResVolume(self,a0): |
---|
46 |
sender = self.sender() |
---|
47 |
vol = 127 - a0 |
---|
48 |
log.debug("set %s to %d" % ( |
---|
49 |
self.VolumeControlsLowRes[sender][0], |
---|
50 |
vol)) |
---|
51 |
self.hw.setDiscrete(self.VolumeControlsLowRes[sender][0], vol) |
---|
52 |
|
---|
53 |
def updateSelector(self,a0): |
---|
54 |
sender = self.sender() |
---|
55 |
if a0: |
---|
56 |
state = 1 |
---|
57 |
else: |
---|
58 |
state = 0 |
---|
59 |
log.debug("set %s to %d" % ( |
---|
60 |
self.SelectorControls[sender][0], |
---|
61 |
state)) |
---|
62 |
self.hw.setDiscrete(self.SelectorControls[sender][0], state) |
---|
63 |
|
---|
64 |
# if there are linked selector controls, update them |
---|
65 |
if len(self.SelectorControls[sender]) >= 2: |
---|
66 |
linked = self.SelectorControls[sender][1] |
---|
67 |
for ctl in linked: |
---|
68 |
if ctl.isChecked(): |
---|
69 |
state = 1 |
---|
70 |
else: |
---|
71 |
state = 0 |
---|
72 |
self.hw.setDiscrete(self.SelectorControls[ctl][0], state) |
---|
73 |
|
---|
74 |
def triggerButton(self): |
---|
75 |
sender = self.sender() |
---|
76 |
log.debug("trigger %s" % ( |
---|
77 |
self.TriggerButtonControls[sender][0])) |
---|
78 |
self.hw.setDiscrete(self.TriggerButtonControls[sender][0], 1) |
---|
79 |
|
---|
80 |
def saveText(self): |
---|
81 |
sender = self.sender() |
---|
82 |
textbox = self.saveTextControls[sender][0] |
---|
83 |
log.debug("save %s" % ( |
---|
84 |
textbox.text().ascii())) |
---|
85 |
self.hw.setText(self.TextControls[textbox][0], textbox.text().ascii()) |
---|
86 |
|
---|
87 |
def initCombo(self, combo): |
---|
88 |
path = self.ComboControls[combo][0] |
---|
89 |
combo.clear() |
---|
90 |
nb_items = self.hw.enumCount(path) |
---|
91 |
for i in range( nb_items ): |
---|
92 |
combo.insertItem( nb_items, self.hw.enumGetLabel(path, i) ) |
---|
93 |
combo.setCurrentIndex( self.hw.enumSelected(path) ) |
---|
94 |
|
---|
95 |
def selectCombo(self, mode): |
---|
96 |
sender = self.sender() |
---|
97 |
path = self.ComboControls[sender][0] |
---|
98 |
self.hw.enumSelect(path, mode) |
---|
99 |
sender.setCurrentIndex( self.hw.enumSelected(path) ) |
---|
100 |
|
---|
101 |
def updateValues(self): |
---|
102 |
for ctrl, info in self.VolumeControls.iteritems(): |
---|
103 |
vol = self.hw.getMatrixMixerValue(self.VolumeControls[ctrl][0], |
---|
104 |
self.VolumeControls[ctrl][1], |
---|
105 |
self.VolumeControls[ctrl][2]) |
---|
106 |
log.debug("%s volume is %d" % (ctrl.objectName() , vol)) |
---|
107 |
ctrl.setValue(vol) |
---|
108 |
for ctrl, info in self.VolumeControlsLowRes.iteritems(): |
---|
109 |
vol = self.hw.getDiscrete(self.VolumeControlsLowRes[ctrl][0]) |
---|
110 |
|
---|
111 |
log.debug("%s volume is %d" % (ctrl.objectName() , 127-vol)) |
---|
112 |
ctrl.setValue(127 - vol) |
---|
113 |
|
---|
114 |
for ctrl, info in self.SelectorControls.iteritems(): |
---|
115 |
state = self.hw.getDiscrete(self.SelectorControls[ctrl][0]) |
---|
116 |
log.debug("%s state is %d" % (ctrl.objectName() , state)) |
---|
117 |
if state: |
---|
118 |
ctrl.setChecked(True) |
---|
119 |
else: |
---|
120 |
ctrl.setChecked(False) |
---|
121 |
|
---|
122 |
for ctrl, info in self.TriggerButtonControls.iteritems(): |
---|
123 |
pass |
---|
124 |
|
---|
125 |
for ctrl, info in self.TextControls.iteritems(): |
---|
126 |
text = self.hw.getText(self.TextControls[ctrl][0]) |
---|
127 |
log.debug("%s text is %s" % (ctrl.objectName() , text)) |
---|
128 |
ctrl.setText(text) |
---|
129 |
|
---|
130 |
for ctrl, info in self.ComboControls.iteritems(): |
---|
131 |
self.initCombo(ctrl) |
---|
132 |
|
---|
133 |
def polledUpdateVolumeLowRes(self, srcpath, ctrl, divider=1): |
---|
134 |
vol = self.hw.getDiscrete(srcpath) / divider |
---|
135 |
#log.debug("polledUpdateVolumeLowRes: vol = %s" % 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) |
---|