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

Revision 1647, 5.2 kB (checked in by arnonym, 14 years ago)

Replace the big matrix of buttons by only one button per destination and choose the source per menu. The menu is filled when first shown to reduce startup load.

This is even real working. I have successfully switched the routing here :-)

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