1 |
#!/usr/bin/python |
---|
2 |
# |
---|
3 |
# Copyright (C) 2005-2008 by Pieter Palmers |
---|
4 |
# 2007-2009 by Arnold Krille |
---|
5 |
# |
---|
6 |
# This file is part of FFADO |
---|
7 |
# FFADO = Free Firewire (pro-)audio drivers for linux |
---|
8 |
# |
---|
9 |
# FFADO is based upon FreeBoB. |
---|
10 |
# |
---|
11 |
# This program is free software: you can redistribute it and/or modify |
---|
12 |
# it under the terms of the GNU General Public License as published by |
---|
13 |
# the Free Software Foundation, either version 3 of the License, or |
---|
14 |
# (at your option) any later version. |
---|
15 |
# |
---|
16 |
# This program is distributed in the hope that it will be useful, |
---|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
# GNU General Public License for more details. |
---|
20 |
# |
---|
21 |
# You should have received a copy of the GNU General Public License |
---|
22 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 |
# |
---|
24 |
|
---|
25 |
import os |
---|
26 |
|
---|
27 |
from ffado.config import * |
---|
28 |
|
---|
29 |
import subprocess |
---|
30 |
|
---|
31 |
from PyQt4.QtCore import SIGNAL, SLOT, QObject, QTimer, Qt |
---|
32 |
from PyQt4.QtGui import * |
---|
33 |
|
---|
34 |
from ffado.dbus_util import * |
---|
35 |
|
---|
36 |
from ffado.panelmanager import PanelManager |
---|
37 |
|
---|
38 |
from ffado.logginghandler import * |
---|
39 |
|
---|
40 |
"""Just a small helper to ask the retry-question without a blocking messagebox""" |
---|
41 |
class StartDialog(QWidget): |
---|
42 |
def __init__(self, parent): |
---|
43 |
QWidget.__init__(self, parent) |
---|
44 |
self.setObjectName("Restart Dialog") |
---|
45 |
self.label = QLabel("<qt>Somehow the connection to the dbus-service of FFADO couldn't be established.<p>\nShall we take another try?</qt>",self) |
---|
46 |
self.button = QPushButton("Retry", self) |
---|
47 |
self.layout = QGridLayout(self) |
---|
48 |
self.layout.setContentsMargins( 50, 10, 50, 10 ) |
---|
49 |
self.layout.addWidget(self.label, 0, 0, Qt.AlignHCenter|Qt.AlignBottom) |
---|
50 |
self.layout.addWidget(self.button, 1, 0, Qt.AlignHCenter|Qt.AlignTop) |
---|
51 |
|
---|
52 |
class FFADOWindow(QMainWindow): |
---|
53 |
def __init__(self, parent): |
---|
54 |
QMainWindow.__init__(self, parent) |
---|
55 |
|
---|
56 |
self.textlogger = QTextLogger(self) |
---|
57 |
dock = QDockWidget("Log Messages",self) |
---|
58 |
dock.setWidget(self.textlogger.textedit) |
---|
59 |
logging.getLogger('').addHandler(self.textlogger) |
---|
60 |
self.addDockWidget(Qt.BottomDockWidgetArea, dock) |
---|
61 |
|
---|
62 |
self.statuslogger = QStatusLogger(self, self.statusBar(), 20) |
---|
63 |
logging.getLogger('').addHandler(self.statuslogger) |
---|
64 |
|
---|
65 |
self.manager = PanelManager(self) |
---|
66 |
self.connect(self.manager, SIGNAL("connectionLost"), self.connectToDBUS) |
---|
67 |
|
---|
68 |
filemenu = self.menuBar().addMenu("File") |
---|
69 |
quitaction = QAction("Quit", self) |
---|
70 |
quitaction.setShortcut(self.tr("Ctrl+q")) |
---|
71 |
self.connect(quitaction, SIGNAL("triggered()"), self, SLOT("close()")) |
---|
72 |
filemenu.addAction(quitaction) |
---|
73 |
|
---|
74 |
editmenu = self.menuBar().addMenu("Edit") |
---|
75 |
self.updateaction = QAction("Update Mixer Panels", self) |
---|
76 |
self.updateaction.setEnabled(False) |
---|
77 |
self.connect(self.updateaction, SIGNAL("triggered()"), self.manager.updatePanels) |
---|
78 |
editmenu.addAction(self.updateaction) |
---|
79 |
refreshaction = QAction("Refresh Current Panels", self) |
---|
80 |
self.connect(refreshaction, SIGNAL("triggered()"), self.manager.refreshPanels) |
---|
81 |
editmenu.addAction(refreshaction) |
---|
82 |
|
---|
83 |
helpmenu = self.menuBar().addMenu( "Help" ) |
---|
84 |
aboutaction = QAction( "About FFADO", self ) |
---|
85 |
self.connect( aboutaction, SIGNAL( "triggered()" ), self.aboutFFADO ) |
---|
86 |
helpmenu.addAction( aboutaction ) |
---|
87 |
aboutqtaction = QAction( "About Qt", self ) |
---|
88 |
self.connect( aboutqtaction, SIGNAL( "triggered()" ), qApp, SLOT( "aboutQt()" ) ) |
---|
89 |
helpmenu.addAction( aboutqtaction ) |
---|
90 |
|
---|
91 |
log.info( "Starting up" ) |
---|
92 |
|
---|
93 |
QTimer.singleShot( 1, self.tryStartDBUSServer ) |
---|
94 |
|
---|
95 |
def __del__(self): |
---|
96 |
log.info("__del__") |
---|
97 |
del self.manager |
---|
98 |
log.info("__del__ finished") |
---|
99 |
|
---|
100 |
def closeEvent(self, event): |
---|
101 |
log.info("closeEvent()") |
---|
102 |
event.accept() |
---|
103 |
|
---|
104 |
def connectToDBUS(self): |
---|
105 |
log.info("connectToDBUS") |
---|
106 |
try: |
---|
107 |
self.setupDeviceManager() |
---|
108 |
except dbus.DBusException, ex: |
---|
109 |
log.error("Could not communicate with the FFADO DBus service...") |
---|
110 |
if not hasattr(self,"retry"): |
---|
111 |
self.retry = StartDialog(self) |
---|
112 |
self.connect(self.retry.button, SIGNAL("clicked()"), self.tryStartDBUSServer) |
---|
113 |
if hasattr(self, "retry"): |
---|
114 |
self.manager.setParent(None) |
---|
115 |
self.setCentralWidget(self.retry) |
---|
116 |
self.retry.setEnabled(True) |
---|
117 |
|
---|
118 |
def tryStartDBUSServer(self): |
---|
119 |
try: |
---|
120 |
self.setupDeviceManager() |
---|
121 |
except dbus.DBusException, ex: |
---|
122 |
if hasattr(self, "retry"): |
---|
123 |
self.retry.setEnabled(False) |
---|
124 |
subprocess.Popen(['ffado-dbus-server', '-v3']).pid |
---|
125 |
QTimer.singleShot(5000, self.connectToDBUS) |
---|
126 |
|
---|
127 |
def setupDeviceManager(self): |
---|
128 |
devmgr = DeviceManagerInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH) |
---|
129 |
self.manager.setManager(devmgr) |
---|
130 |
if hasattr(self, "retry"): |
---|
131 |
self.retry.setParent(None) |
---|
132 |
self.setCentralWidget(self.manager) |
---|
133 |
self.updateaction.setEnabled(True) |
---|
134 |
|
---|
135 |
def aboutFFADO(self): |
---|
136 |
QMessageBox.about( self, "About FFADO", """ |
---|
137 |
<h1>ffado.org</h1> |
---|
138 |
|
---|
139 |
<p>FFADO is the new approach to have firewire audio on linux.</p> |
---|
140 |
|
---|
141 |
<p>© 2006-2008 by the FFADO developers<br />ffado is licensed under the GPLv3, for the full license text see <a href="http://www.gnu.org/licenses/">www.gnu.org/licenses</a> or the LICENSE.* files shipped with ffado.</p> |
---|
142 |
|
---|
143 |
<p>FFADO developers are:<ul> |
---|
144 |
<li>Pieter Palmers |
---|
145 |
<li>Daniel Wagner |
---|
146 |
<li>Jonathan Woithe |
---|
147 |
<li>Arnold Krille |
---|
148 |
</ul> |
---|
149 |
""" ) |
---|
150 |
|
---|
151 |
|
---|
152 |
def get_lock(process_name): |
---|
153 |
import socket |
---|
154 |
import sys |
---|
155 |
|
---|
156 |
global lock_socket |
---|
157 |
lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) |
---|
158 |
try: |
---|
159 |
lock_socket.bind('\0' + process_name) |
---|
160 |
# Lock acquired |
---|
161 |
except socket.error: |
---|
162 |
print 'ffado-mixer instance is already running' |
---|
163 |
sys.exit() |
---|
164 |
|
---|
165 |
|
---|
166 |
def ffadomain(args): |
---|
167 |
#set up logging |
---|
168 |
import logging |
---|
169 |
logging.basicConfig( datefmt="%H:%M:%S", format="%(asctime)s %(name)-16s %(levelname)-8s %(message)s" ) |
---|
170 |
|
---|
171 |
if DEBUG: |
---|
172 |
debug_level = logging.DEBUG |
---|
173 |
else: |
---|
174 |
debug_level = logging.INFO |
---|
175 |
|
---|
176 |
get_lock('ffado-mixer') |
---|
177 |
|
---|
178 |
# main loggers: |
---|
179 |
logging.getLogger('main').setLevel(debug_level) |
---|
180 |
logging.getLogger('dbus').setLevel(debug_level) |
---|
181 |
logging.getLogger('registration').setLevel(debug_level) |
---|
182 |
logging.getLogger('panelmanager').setLevel(debug_level) |
---|
183 |
logging.getLogger('configparser').setLevel(logging.INFO) |
---|
184 |
|
---|
185 |
# widgets: |
---|
186 |
logging.getLogger('matrixmixer').setLevel(debug_level) |
---|
187 |
logging.getLogger('crossbarrouter').setLevel(debug_level) |
---|
188 |
|
---|
189 |
# mixers: |
---|
190 |
logging.getLogger('audiofire').setLevel(debug_level) |
---|
191 |
logging.getLogger('bridgeco').setLevel(debug_level) |
---|
192 |
logging.getLogger('edirolfa101').setLevel(debug_level) |
---|
193 |
logging.getLogger('edirolfa66').setLevel(debug_level) |
---|
194 |
logging.getLogger('motu').setLevel(debug_level) |
---|
195 |
logging.getLogger('rme').setLevel(debug_level) |
---|
196 |
logging.getLogger('phase24').setLevel(debug_level) |
---|
197 |
logging.getLogger('phase88').setLevel(debug_level) |
---|
198 |
logging.getLogger('quatafire').setLevel(debug_level) |
---|
199 |
logging.getLogger('saffirebase').setLevel(debug_level) |
---|
200 |
logging.getLogger('saffire').setLevel(debug_level) |
---|
201 |
logging.getLogger('saffirepro').setLevel(debug_level) |
---|
202 |
|
---|
203 |
logging.getLogger('global').setLevel(debug_level) |
---|
204 |
|
---|
205 |
log = logging.getLogger('main') |
---|
206 |
|
---|
207 |
app = QApplication(args) |
---|
208 |
app.setWindowIcon( QIcon( SHAREDIR + "/icons/hi64-apps-ffado.png" ) ) |
---|
209 |
|
---|
210 |
app.setOrganizationName("FFADO") |
---|
211 |
app.setOrganizationDomain("ffado.org") |
---|
212 |
app.setApplicationName("ffado-mixer") |
---|
213 |
|
---|
214 |
mainwindow = FFADOWindow(None) |
---|
215 |
|
---|
216 |
|
---|
217 |
# rock & roll |
---|
218 |
mainwindow.show() |
---|
219 |
return app.exec_() |
---|
220 |
|
---|
221 |
if __name__ == "__main__": |
---|
222 |
import sys |
---|
223 |
sys.exit(ffadomain(sys.argv)) |
---|
224 |
|
---|
225 |
# |
---|
226 |
# vim: ts=4 sw=4 et |
---|