root/trunk/libffado/support/mixer-qt4/ffado/widgets/crossbarrouter.py

Revision 1776, 6.2 kB (checked in by arnonym, 11 years ago)

Reduce the LOC:

  • Use only strings as identifiers for the Dice::EAP::Router. Updating the router doesn't happen that often, using strings only is acceptable. And it eases handling so much.
  • Adapt the control interface.
  • Adapt the dbus interface.
  • Adapt the routers gui.
  • The peak-space is not yet working (I didn't actually test it), the peak-functions of EAP::Router return nothing.
  • And the test for the dice has to be adopted when the peaks are working again.

TODO:

  • Re-activate the peaks.
  • Adopt the mixer interface.
Line 
1 #
2 # Copyright (C) 2009 by Arnold Krille
3 #
4 # This file is part of FFADO
5 # FFADO = Free Firewire (pro-)audio drivers for linux
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 2 of the License, or
10 # (at your option) version 3 of the License.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from PyQt4 import QtGui, QtCore
22 import dbus
23
24 import logging
25 log = logging.getLogger("crossbarrouter")
26
27 class VuMeter(QtGui.QFrame):
28     def __init__(self, interface, output, input=None, parent=None):
29         QtGui.QFrame.__init__(self, parent)
30         self.setLineWidth(1)
31         self.setFrameStyle(QtGui.QFrame.Panel|QtGui.QFrame.Sunken)
32         self.setMinimumSize(20, 20)
33
34         self.level = 0
35
36         self.interface = interface
37
38         self.output = output
39         if input is None:
40             input = int(self.interface.getSourceForDestination(output))
41         self.setInput(input)
42
43     def setInput(self, input):
44         #log.debug("VuMeter.setInput() %i->%i" % (self.output, input))
45         self.input = input
46
47     def updateLevel(self, value):
48         self.level = value
49         self.update()
50
51     def paintEvent(self, event):
52         p = QtGui.QPainter(self)
53         value = self.level/4096
54         r = self.rect()
55         r.setHeight(r.height() * value)
56         r.moveBottom(self.rect().height())
57         p.fillRect(r, self.palette().highlight())
58
59 class OutputSwitcher(QtGui.QFrame):
60     """
61 The name is a bit misleading. This widget selectes sources for a specified
62 destination.
63
64 In mixer-usage this widget is at the top of the input-channel. Because the input
65 of the mixer is an available output from the routers point.
66 """
67     def __init__(self, interface, outname, parent):
68         QtGui.QFrame.__init__(self, parent)
69         self.interface = interface
70         self.outname = outname
71         self.lastin = ""
72
73         self.setLineWidth(1)
74         self.setFrameStyle(QtGui.QFrame.Sunken|QtGui.QFrame.Panel)
75
76         self.layout = QtGui.QGridLayout(self)
77         self.setLayout(self.layout)
78
79         self.lbl = QtGui.QLabel(self.outname, self)
80         self.layout.addWidget(self.lbl, 0, 0)
81
82         #self.vu = VuMeter(self.interface, self.interface.getDestinationIndex(outname), parent=self)
83         #self.layout.addWidget(self.vu, 0, 1)
84
85         sources = self.interface.getSourceNames()
86
87         self.combo = QtGui.QComboBox(self)
88         self.layout.addWidget(self.combo, 1, 0, 1, 2)
89         self.combo.addItem("Disconnected")
90         self.combo.addItems(sources)
91         src = self.interface.getSourceForDestination(self.outname)
92         if src != "":
93             self.combo.setCurrentIndex(self.combo.findText(src))
94         else:
95             self.combo.setCurrentIndex(0)
96         self.connect(self.combo, QtCore.SIGNAL("activated(QString)"), self.comboCurrentChanged)
97
98
99     def peakValue(self, value):
100         #self.vu.updateLevel(value)
101         pass
102
103     def comboCurrentChanged(self, inname):
104         #log.debug("comboCurrentChanged( %s )" % inname)
105         if inname == self.lastin:
106             return
107         if self.lastin != "":
108             self.interface.setConnectionState(self.lastin, self.outname, False)
109
110         if inname != "Disconnected":
111             if self.interface.setConnectionState(str(inname), self.outname, True):
112                 self.lastin = str(inname)
113             else:
114                 log.warning(" Failed to connect %s to %s" % (inname, self.outname))
115         else:
116             self.lastin = ""
117
118
119 class CrossbarRouter(QtGui.QWidget):
120     def __init__(self, servername, basepath, parent=None):
121         QtGui.QWidget.__init__(self, parent);
122         self.bus = dbus.SessionBus()
123         self.dev = self.bus.get_object(servername, basepath)
124         self.interface = dbus.Interface(self.dev, dbus_interface="org.ffado.Control.Element.CrossbarRouter")
125
126         self.settings = QtCore.QSettings(self)
127
128         destinations = self.interface.getDestinationNames()
129         self.outgroups = []
130         for ch in destinations:
131             tmp = str(ch).split(":")[0]
132             if not tmp in self.outgroups:
133                 self.outgroups.append(tmp)
134
135         self.biglayout = QtGui.QVBoxLayout(self)
136         self.setLayout(self.biglayout)
137
138         self.toplayout = QtGui.QHBoxLayout()
139         self.biglayout.addLayout(self.toplayout)
140
141         self.vubtn = QtGui.QPushButton("Switch VU", self)
142         self.vubtn.setCheckable(True)
143         self.connect(self.vubtn, QtCore.SIGNAL("toggled(bool)"), self.runVu)
144         self.toplayout.addWidget(self.vubtn)
145
146         self.layout = QtGui.QGridLayout()
147         self.biglayout.addLayout(self.layout)
148
149         self.switchers = {}
150         for out in destinations:
151             btn = OutputSwitcher(self.interface, out, self)
152             self.layout.addWidget(btn, int(out.split(":")[-1]) + 1, self.outgroups.index(out.split(":")[0]))
153             self.switchers[out] = btn
154
155         self.timer = QtCore.QTimer(self)
156         self.timer.setInterval(200)
157         self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.updateLevels)
158
159         self.vubtn.setChecked(self.settings.value("crossbarrouter/runvu", False).toBool())
160
161     def __del__(self):
162         print "CrossbarRouter.__del__()"
163         self.settings.setValue("crossbarrouter/runvu", self.vubtn.isChecked())
164
165     def runVu(self, run=True):
166         #log.debug("CrossbarRouter.runVu( %i )" % run)
167         if run:
168             self.timer.start()
169         else:
170             self.timer.stop()
171             for sw in self.switchers:
172                 self.switchers[sw].peakValue(0)
173
174     def updateLevels(self):
175         #log.debug("CrossbarRouter.updateLevels()")
176         peakvalues = self.interface.getPeakValues()
177         #log.debug("Got %i peaks" % len(peakvalues))
178         for peak in peakvalues:
179             #log.debug("peak = [%s,%s]" % (str(peak[0]),str(peak[1])))
180             if peak[0] >= 0:
181                 self.switchers[peak[0]].peakValue(peak[1])
182
183 #
184 # vim: sw=4 ts=4 et
Note: See TracBrowser for help on using the browser.