1 |
# |
---|
2 |
# Copyright (C) 2008 by Arnold Krille |
---|
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 QObject, pyqtSignature |
---|
24 |
from PyQt4.QtGui import QWidget, QMessageBox |
---|
25 |
from ffado.config import * |
---|
26 |
|
---|
27 |
import logging |
---|
28 |
log = logging.getLogger('global') |
---|
29 |
|
---|
30 |
class GlobalMixer(QWidget): |
---|
31 |
def __init__(self, parent, name=None): |
---|
32 |
QWidget.__init__(self, parent) |
---|
33 |
uicLoad("ffado/mixer/globalmixer", self) |
---|
34 |
self.setName(name) |
---|
35 |
|
---|
36 |
def setName(self,name): |
---|
37 |
if name is not None: |
---|
38 |
self.lblName.setText(name) |
---|
39 |
self.lblName.show() |
---|
40 |
else: |
---|
41 |
self.lblName.hide() |
---|
42 |
|
---|
43 |
@pyqtSignature("int") |
---|
44 |
def on_clocksource_activated( self, clock ): |
---|
45 |
#log.debug("updateClockSource( " + str(clock) + " )") |
---|
46 |
if self.clockselect.canChangeValue(): |
---|
47 |
self.clockselect.select( clock ) |
---|
48 |
else: |
---|
49 |
msg = QMessageBox() |
---|
50 |
msg.question( msg, "Error", \ |
---|
51 |
"<qt>Clock source change not permitted. Is streaming active?</qt>", \ |
---|
52 |
QMessageBox.Ok ) |
---|
53 |
self.clocksource.setEnabled(False) |
---|
54 |
return |
---|
55 |
|
---|
56 |
selected = self.clockselect.selected() |
---|
57 |
if selected != clock: |
---|
58 |
clockname = self.clockselect.getEnumLabel( clock ) |
---|
59 |
msg = QMessageBox() |
---|
60 |
msg.question( msg, "Failed to select clock source", \ |
---|
61 |
"<qt>Could not select %s as clock source.</qt>" % clockname, \ |
---|
62 |
QMessageBox.Ok ) |
---|
63 |
self.clocksource.setCurrentIndex( selected ) |
---|
64 |
|
---|
65 |
@pyqtSignature("int") |
---|
66 |
def on_samplerate_activated( self, sr ): |
---|
67 |
log.debug("on_samplerate_activated( " + str(sr) + " )") |
---|
68 |
# If there's no clock, don't bother trying to set the sample rate |
---|
69 |
if (self.no_clock == 1): |
---|
70 |
return |
---|
71 |
if self.samplerateselect.canChangeValue(): |
---|
72 |
self.samplerateselect.select( sr ) |
---|
73 |
if 'onSamplerateChange' in dir(self): |
---|
74 |
self.onSamplerateChange() |
---|
75 |
log.debug("Mixer configuration updated") |
---|
76 |
else: |
---|
77 |
msg = QMessageBox() |
---|
78 |
msg.question( msg, "Error", \ |
---|
79 |
"<qt>Sample rate change not permitted. Is streaming active?</qt>", \ |
---|
80 |
QMessageBox.Ok ) |
---|
81 |
self.samplerate.setEnabled(False) |
---|
82 |
return |
---|
83 |
|
---|
84 |
selected = self.samplerateselect.selected() |
---|
85 |
if selected != sr: |
---|
86 |
srname = self.samplerateselect.getEnumLabel( sr ) |
---|
87 |
msg = QMessageBox() |
---|
88 |
msg.question( msg, "Failed to select sample rate", \ |
---|
89 |
"<qt>Could not select %s as samplerate.</qt>" % srname, \ |
---|
90 |
QMessageBox.Ok ) |
---|
91 |
self.samplerate.setCurrentIndex( selected ) |
---|
92 |
|
---|
93 |
@pyqtSignature("") |
---|
94 |
def on_txtNickname_returnPressed( self ): |
---|
95 |
if self.nickname.canChangeValue(): |
---|
96 |
asciiData = self.txtNickname.text().toAscii() |
---|
97 |
self.nickname.setText( asciiData.data() ) |
---|
98 |
else: |
---|
99 |
self.txtNickname.setText( self.nickname.text() ) |
---|
100 |
|
---|
101 |
def refreshSampleRates( self ): |
---|
102 |
no_clock_status = 0 |
---|
103 |
n_rates = self.samplerateselect.count() |
---|
104 |
if (n_rates<1 or self.samplerateselect.getEnumLabel(0)=="0"): |
---|
105 |
no_clock_status = 1; |
---|
106 |
|
---|
107 |
# Except for changes to the "no clock" status (where the number of |
---|
108 |
# "frequencies" can remain at 1), the following test won't account |
---|
109 |
# for cases where the frequency list changes but the total number of |
---|
110 |
# frequencies remains the same. If a device comes along for which |
---|
111 |
# this is a problem, an alternative approach will be needed. |
---|
112 |
if (no_clock_status!=self.no_clock or n_rates!=self.num_rates): |
---|
113 |
self.no_clock = 0; |
---|
114 |
self.num_rates = n_rates |
---|
115 |
self.samplerate.clear() |
---|
116 |
for i in range( self.num_rates ): |
---|
117 |
label = self.samplerateselect.getEnumLabel( i ) |
---|
118 |
if (label == "0"): |
---|
119 |
label = "No clock found"; |
---|
120 |
self.no_clock = 1; |
---|
121 |
self.samplerate.insertItem( self.num_rates, label ) |
---|
122 |
if (self.no_clock != 1): |
---|
123 |
self.samplerate.setCurrentIndex( self.samplerateselect.selected() ) |
---|
124 |
else: |
---|
125 |
self.samplerate.setCurrentIndex(0); |
---|
126 |
|
---|
127 |
def initValues( self ): |
---|
128 |
#print "GlobalMixer::initValues()" |
---|
129 |
nb_clocks = self.clockselect.count() |
---|
130 |
for i in range( nb_clocks ): |
---|
131 |
self.clocksource.insertItem( nb_clocks, self.clockselect.getEnumLabel( i ) ) |
---|
132 |
self.clocksource.setCurrentIndex( self.clockselect.selected() ) |
---|
133 |
|
---|
134 |
self.no_clock = 0; |
---|
135 |
self.num_rates = -1; |
---|
136 |
self.refreshSampleRates(); |
---|
137 |
|
---|
138 |
self.txtNickname.setText( self.nickname.text() ) |
---|
139 |
|
---|
140 |
self.samplerate.setEnabled(self.samplerateselect.canChangeValue()) |
---|
141 |
self.clocksource.setEnabled(self.clockselect.canChangeValue()) |
---|
142 |
if self.nickname.canChangeValue(): |
---|
143 |
self.txtNickname.setEnabled(True) |
---|
144 |
else: |
---|
145 |
self.txtNickname.setEnabled(False) |
---|
146 |
|
---|
147 |
self.streaming_status = self.streamingstatus.selected() |
---|
148 |
|
---|
149 |
def polledUpdate(self): |
---|
150 |
self.samplerate.setEnabled(self.samplerateselect.canChangeValue()) |
---|
151 |
self.clocksource.setEnabled(self.clockselect.canChangeValue()) |
---|
152 |
self.txtNickname.setEnabled(self.nickname.canChangeValue()) |
---|
153 |
ss = self.streamingstatus.selected() |
---|
154 |
ss_txt = self.streamingstatus.getEnumLabel(ss) |
---|
155 |
if ss_txt == 'Idle': |
---|
156 |
self.chkStreamIn.setChecked(False) |
---|
157 |
self.chkStreamOut.setChecked(False) |
---|
158 |
elif ss_txt == 'Sending': |
---|
159 |
self.chkStreamIn.setChecked(False) |
---|
160 |
self.chkStreamOut.setChecked(True) |
---|
161 |
elif ss_txt == 'Receiving': |
---|
162 |
self.chkStreamIn.setChecked(True) |
---|
163 |
self.chkStreamOut.setChecked(False) |
---|
164 |
elif ss_txt == 'Both': |
---|
165 |
self.chkStreamIn.setChecked(True) |
---|
166 |
self.chkStreamOut.setChecked(True) |
---|
167 |
|
---|
168 |
if (ss!=self.streaming_status and ss_txt!='Idle'): |
---|
169 |
sr = self.samplerate.currentIndex() |
---|
170 |
self.samplerate.setCurrentIndex( self.samplerateselect.selected() ) |
---|
171 |
# Check (and update) if device configuration needs to be updated |
---|
172 |
if ( self.samplerateselect.devConfigChanged(sr) ): |
---|
173 |
log.debug("Samplerate modified by external client") |
---|
174 |
if 'onSamplerateChange' in dir(self): |
---|
175 |
self.onSamplerateChange() |
---|
176 |
log.debug("Mixer configuration updated ") |
---|
177 |
else: |
---|
178 |
log.debug("Mixer configuration need to be updated but no means is provided") |
---|
179 |
self.streaming_status = ss |
---|
180 |
|
---|
181 |
# Allow for devices whose sample rates can change dynamically (for |
---|
182 |
# example, in response to changes in external clock frequency) |
---|
183 |
self.refreshSampleRates(); |
---|
184 |
|
---|
185 |
def saveSettings(self, indent): |
---|
186 |
saveString = [] |
---|
187 |
saveString.append('%s<nickname>\n' % indent) |
---|
188 |
saveString.append('%s ' % indent + str(self.txtNickname.text()) + '\n') |
---|
189 |
saveString.append('%s</nickname>\n' % indent) |
---|
190 |
saveString.append('%s<clock>\n' % indent) |
---|
191 |
saveString.append('%s ' % indent + str(self.clockselect.getEnumLabel(self.clockselect.selected())) + '\n') |
---|
192 |
saveString.append('%s</clock>\n' % indent) |
---|
193 |
saveString.append('%s<samplerate>\n' % indent) |
---|
194 |
saveString.append('%s ' % indent + str(self.samplerateselect.getEnumLabel(self.samplerateselect.selected())) + ' \n') |
---|
195 |
saveString.append('%s</samplerate>\n' % indent) |
---|
196 |
return saveString |
---|
197 |
|
---|
198 |
def readSettings(self, readString): |
---|
199 |
# Nickname |
---|
200 |
try: |
---|
201 |
idx = readString.index('<nickname>') |
---|
202 |
except Exception: |
---|
203 |
print "No nickname found" |
---|
204 |
idx = -1 |
---|
205 |
if idx >= 0: |
---|
206 |
nickname = readString[idx+1] |
---|
207 |
if self.nickname.canChangeValue(): |
---|
208 |
self.txtNickname.setText(nickname) |
---|
209 |
self.on_txtNickname_returnPressed() |
---|
210 |
log.debug("Nickname changed for %s" % nickname) |
---|
211 |
# Clock |
---|
212 |
try: |
---|
213 |
idx = readString.index('<clock>') |
---|
214 |
except Exception: |
---|
215 |
print "No clock found" |
---|
216 |
idx = -1 |
---|
217 |
if idx >= 0: |
---|
218 |
clock = readString[idx+1] |
---|
219 |
nb_clocks = self.clockselect.count() |
---|
220 |
clockLabel = [] |
---|
221 |
for i in range( nb_clocks ): |
---|
222 |
clockLabel.append(self.clockselect.getEnumLabel(i)) |
---|
223 |
try: |
---|
224 |
idxclock = clockLabel.index(clock) |
---|
225 |
except Exception: |
---|
226 |
print "No %s clock found" % clock |
---|
227 |
idxclock = -1 |
---|
228 |
if idxclock >= 0: |
---|
229 |
self.on_clocksource_activated(idxclock) |
---|
230 |
self.clocksource.setCurrentIndex(self.clockselect.selected()) |
---|
231 |
log.debug("Clock set to index %d (%s)" % (idxclock, clock)) |
---|
232 |
del clockLabel |
---|
233 |
# Samplerate |
---|
234 |
try: |
---|
235 |
idx = readString.index('<samplerate>') |
---|
236 |
except Exception: |
---|
237 |
print "Samplerate not found" |
---|
238 |
idx = -1 |
---|
239 |
if idx >= 0: |
---|
240 |
samplerate = readString[idx+1] |
---|
241 |
nb_srate = self.samplerateselect.count() |
---|
242 |
srateLabel = [] |
---|
243 |
for i in range( nb_srate ): |
---|
244 |
srateLabel.append(self.samplerateselect.getEnumLabel(i)) |
---|
245 |
try: |
---|
246 |
idxsrate = srateLabel.index(samplerate) |
---|
247 |
except Exception: |
---|
248 |
print "No %s samplerate found" % samplerate |
---|
249 |
idxsrate = -1 |
---|
250 |
if idxsrate >= 0: |
---|
251 |
self.on_samplerate_activated(idxsrate) |
---|
252 |
self.samplerate.setCurrentIndex(self.samplerateselect.selected()) |
---|
253 |
log.debug("Samplerate set to index %d (%s)" % (idxsrate, samplerate)) |
---|
254 |
|
---|
255 |
# vim: et |
---|