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 |
|
---|
40 |
def updateLevel(self, value): |
---|
41 |
self.level = value |
---|
42 |
self.update() |
---|
43 |
|
---|
44 |
def paintEvent(self, event): |
---|
45 |
p = QtGui.QPainter(self) |
---|
46 |
value = self.level/4096 |
---|
47 |
r = self.rect() |
---|
48 |
r.setHeight(r.height() * value) |
---|
49 |
r.moveBottom(self.rect().height()) |
---|
50 |
p.fillRect(r, self.palette().highlight()) |
---|
51 |
|
---|
52 |
class OutputSwitcher(QtGui.QFrame): |
---|
53 |
""" |
---|
54 |
The name is a bit misleading. This widget selectes sources for a specified |
---|
55 |
destination. |
---|
56 |
|
---|
57 |
In mixer-usage this widget is at the top of the input-channel. Because the input |
---|
58 |
of the mixer is an available output from the routers point. |
---|
59 |
""" |
---|
60 |
def __init__(self, interface, outname, parent): |
---|
61 |
QtGui.QFrame.__init__(self, parent) |
---|
62 |
self.interface = interface |
---|
63 |
self.outname = outname |
---|
64 |
self.lastin = "" |
---|
65 |
|
---|
66 |
self.setLineWidth(1) |
---|
67 |
self.setFrameStyle(QtGui.QFrame.Sunken|QtGui.QFrame.Panel) |
---|
68 |
|
---|
69 |
self.layout = QtGui.QGridLayout(self) |
---|
70 |
self.setLayout(self.layout) |
---|
71 |
|
---|
72 |
self.lbl = QtGui.QLabel(self.outname, self) |
---|
73 |
self.layout.addWidget(self.lbl, 0, 0) |
---|
74 |
|
---|
75 |
self.vu = VuMeter(self.interface, outname, parent=self) |
---|
76 |
self.layout.addWidget(self.vu, 0, 1) |
---|
77 |
|
---|
78 |
sources = self.interface.getSourceNames() |
---|
79 |
|
---|
80 |
self.combo = QtGui.QComboBox(self) |
---|
81 |
self.layout.addWidget(self.combo, 1, 0, 1, 2) |
---|
82 |
self.combo.addItem("Disconnected") |
---|
83 |
self.combo.addItems(sources) |
---|
84 |
src = self.interface.getSourceForDestination(self.outname) |
---|
85 |
if src != "": |
---|
86 |
self.combo.setCurrentIndex(self.combo.findText(src)) |
---|
87 |
else: |
---|
88 |
self.combo.setCurrentIndex(0) |
---|
89 |
self.connect(self.combo, QtCore.SIGNAL("activated(QString)"), self.comboCurrentChanged) |
---|
90 |
|
---|
91 |
|
---|
92 |
def peakValue(self, value): |
---|
93 |
#self.vu.updateLevel(value) |
---|
94 |
pass |
---|
95 |
|
---|
96 |
def comboCurrentChanged(self, inname): |
---|
97 |
#log.debug("comboCurrentChanged( %s )" % inname) |
---|
98 |
if inname == self.lastin: |
---|
99 |
return |
---|
100 |
if self.lastin != "": |
---|
101 |
self.interface.setConnectionState(self.lastin, self.outname, False) |
---|
102 |
|
---|
103 |
if inname != "Disconnected": |
---|
104 |
if self.interface.setConnectionState(str(inname), self.outname, True): |
---|
105 |
self.lastin = str(inname) |
---|
106 |
else: |
---|
107 |
log.warning(" Failed to connect %s to %s" % (inname, self.outname)) |
---|
108 |
else: |
---|
109 |
self.lastin = "" |
---|
110 |
|
---|
111 |
|
---|
112 |
class CrossbarRouter(QtGui.QWidget): |
---|
113 |
def __init__(self, servername, basepath, parent=None): |
---|
114 |
QtGui.QWidget.__init__(self, parent); |
---|
115 |
self.bus = dbus.SessionBus() |
---|
116 |
self.dev = self.bus.get_object(servername, basepath) |
---|
117 |
self.interface = dbus.Interface(self.dev, dbus_interface="org.ffado.Control.Element.CrossbarRouter") |
---|
118 |
|
---|
119 |
self.settings = QtCore.QSettings(self) |
---|
120 |
|
---|
121 |
destinations = self.interface.getDestinationNames() |
---|
122 |
self.outgroups = [] |
---|
123 |
for ch in destinations: |
---|
124 |
tmp = str(ch).split(":")[0] |
---|
125 |
if not tmp in self.outgroups: |
---|
126 |
self.outgroups.append(tmp) |
---|
127 |
|
---|
128 |
self.biglayout = QtGui.QVBoxLayout(self) |
---|
129 |
self.setLayout(self.biglayout) |
---|
130 |
|
---|
131 |
self.toplayout = QtGui.QHBoxLayout() |
---|
132 |
self.biglayout.addLayout(self.toplayout) |
---|
133 |
|
---|
134 |
self.vubtn = QtGui.QPushButton("Switch VU", self) |
---|
135 |
self.vubtn.setCheckable(True) |
---|
136 |
self.connect(self.vubtn, QtCore.SIGNAL("toggled(bool)"), self.runVu) |
---|
137 |
self.toplayout.addWidget(self.vubtn) |
---|
138 |
|
---|
139 |
self.layout = QtGui.QGridLayout() |
---|
140 |
self.biglayout.addLayout(self.layout) |
---|
141 |
|
---|
142 |
self.switchers = {} |
---|
143 |
for out in destinations: |
---|
144 |
btn = OutputSwitcher(self.interface, out, self) |
---|
145 |
self.layout.addWidget(btn, int(out.split(":")[-1]) + 1, self.outgroups.index(out.split(":")[0])) |
---|
146 |
self.switchers[out] = btn |
---|
147 |
|
---|
148 |
self.timer = QtCore.QTimer(self) |
---|
149 |
self.timer.setInterval(200) |
---|
150 |
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.updateLevels) |
---|
151 |
|
---|
152 |
self.vubtn.setChecked(self.settings.value("crossbarrouter/runvu", False).toBool()) |
---|
153 |
|
---|
154 |
def __del__(self): |
---|
155 |
print "CrossbarRouter.__del__()" |
---|
156 |
self.settings.setValue("crossbarrouter/runvu", self.vubtn.isChecked()) |
---|
157 |
|
---|
158 |
def runVu(self, run=True): |
---|
159 |
#log.debug("CrossbarRouter.runVu( %i )" % run) |
---|
160 |
if run: |
---|
161 |
self.timer.start() |
---|
162 |
else: |
---|
163 |
self.timer.stop() |
---|
164 |
for sw in self.switchers: |
---|
165 |
self.switchers[sw].peakValue(0) |
---|
166 |
|
---|
167 |
def updateLevels(self): |
---|
168 |
#log.debug("CrossbarRouter.updateLevels()") |
---|
169 |
peakvalues = self.interface.getPeakValues() |
---|
170 |
log.debug("Got %i peaks" % len(peakvalues)) |
---|
171 |
for peak in peakvalues: |
---|
172 |
#log.debug("peak = [%s,%s]" % (str(peak[0]),str(peak[1]))) |
---|
173 |
if peak[0] >= 0: |
---|
174 |
self.switchers[peak[0]].peakValue(peak[1]) |
---|
175 |
|
---|
176 |
# |
---|
177 |
# vim: sw=4 ts=4 et |
---|