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

Revision 1649, 5.0 kB (checked in by arnonym, 15 years ago)

Just flesh out a widget for each destination. Getting the peak-meter is postponed to tomorrow.

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 class OutputSwitcher(QtGui.QFrame):
25     """
26 The name is a bit misleading. This widget selectes sources for a specified
27 destination.
28
29 In mixer-usage this widget is at the top of the input-channel. Because the input
30 of the mixer is an available output from the routers point.
31 """
32     def __init__(self, interface, outname, parent):
33         QtGui.QFrame.__init__(self, parent)
34         self.interface = interface
35         self.outname = outname
36
37         self.setLineWidth(1)
38
39         self.layout = QtGui.QGridLayout(self)
40         self.setLayout(self.layout)
41
42         self.lbl = QtGui.QLabel(self.outname, self)
43         self.layout.addWidget(self.lbl, 0, 0, 1, 2)
44
45         self.btn = QtGui.QPushButton("Sel.", self)
46         self.layout.addWidget(self.btn, 1, 0)
47
48         self.exclusiveGroup = QtGui.QActionGroup(self)
49
50         sources = self.interface.getSourceNames()
51         self.ingroups = {}
52         for ch in sources:
53             tmp = str(ch).split(":")[0]
54             if tmp not in self.ingroups:
55                 self.ingroups[tmp] = 0
56             self.ingroups[tmp] += 1
57         #print "Detected ingroups: %s" % str(self.ingroups)
58
59         self.menu = QtGui.QMenu(self)
60         self.btn.setMenu(self.menu)
61
62         for group in self.ingroups:
63             submenu = InGroupMenu(self.interface, self.outname, group, self.ingroups[group], self, self.exclusiveGroup)
64             self.menu.addMenu(submenu)
65
66 class InGroupMenu(QtGui.QMenu):
67     def __init__(self, interface, outname, inname, insize, parent, exclusiveGroup = None):
68         QtGui.QMenu.__init__(self, inname, parent)
69         self.interface = interface
70         self.outname = str(outname)
71         self.inname = str(inname)
72         self.insize = insize
73         self.connect(self, QtCore.SIGNAL("aboutToShow()"), self.showMenu)
74
75         self.lock = False
76         if exclusiveGroup:
77             self.exclusiveGroup = exclusiveGroup
78         else:
79             self.exclusiveGroup = QtGui.QActionGroup(self)
80
81     def showMenu(self):
82         #print "About to show the menu"
83         if len(self.actions()) < self.insize:
84             # Do a lazy init of the sub-items.
85             for i in range(self.insize):
86                 action = QtGui.QAction("%s:%02i" % (self.inname,i), self)
87                 action.setCheckable(True)
88                 self.connect(action, QtCore.SIGNAL("toggled(bool)"), self.connectionSwitched)
89                 self.exclusiveGroup.addAction(action)
90                 self.addAction(action)
91                 idx = self.interface.getDestinationIndex(self.outname)
92                 sourceidx = self.interface.getSourceForDestination(idx)
93                 #print self.interface.getConnectionState(sourceidx, idx)
94                 source = self.interface.getSourceName(sourceidx)
95                 self.lock = True
96                 for action in self.actions():
97                     action.setChecked(action.text() == source)
98                 self.lock = False
99
100     def connectionSwitched(self, checked):
101         if self.lock: return
102         print "connectionSwitched( %s ) sender: %s" % (str(checked),str(self.sender()))
103         inname = str(self.sender().text())
104         print " source=%s destination=%s  possible? %s" % (inname, self.outname, self.interface.canConnectNamed(inname, self.outname))
105         print " connectionState is now %s" % self.interface.setConnectionStateNamed(inname, self.outname, checked)
106
107
108 class CrossbarRouter(QtGui.QWidget):
109     def __init__(self, servername, basepath, parent=None):
110         QtGui.QWidget.__init__(self, parent);
111         self.bus = dbus.SessionBus()
112         self.dev = self.bus.get_object(servername, basepath)
113         self.interface = dbus.Interface(self.dev, dbus_interface="org.ffado.Control.Element.CrossbarRouter")
114
115         destinations = self.interface.getDestinationNames()
116         self.outgroups = []
117         for ch in destinations:
118             tmp = str(ch).split(":")[0]
119             if not tmp in self.outgroups:
120                 self.outgroups.append(tmp)
121
122         self.layout = QtGui.QGridLayout(self)
123         self.setLayout(self.layout)
124
125         for out in destinations:
126             btn = OutputSwitcher(self.interface, out, self)
127             self.layout.addWidget(btn, int(out.split(":")[-1]), self.outgroups.index(out.split(":")[0]))
128
129 #
130 # vim: sw=4 ts=4 et
Note: See TracBrowser for help on using the browser.