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

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