forked from Openlights/firemix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiremix.py
88 lines (71 loc) · 3.44 KB
/
firemix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# This file is part of Firemix.
#
# Copyright 2013-2016 Jonathan Evans <[email protected]>
#
# Firemix is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Firemix is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Firemix. If not, see <http://www.gnu.org/licenses/>.
import argparse
import functools
import logging
import signal
import sys
from PySide import QtCore, QtGui
from firemix_app import FireMixApp
from ui.firemixgui import FireMixGUI
def sig_handler(app, sig, frame):
logging.getLogger("firemix").info("Received signal %d. Shutting down.", sig)
app.stop()
app.exit()
app.qt_app.exit()
def main():
logging.basicConfig(level=logging.ERROR)
log = logging.getLogger("firemix")
parser = argparse.ArgumentParser(description="Firelight mixer and preset host")
parser.add_argument("scene", type=str, help="Scene file to load (create scenes with FireSim)")
parser.add_argument("--playlist", type=str, help="Playlist file to load", default=None)
parser.add_argument("--profile", action='store_const', const=True, default=False, help="Enable profiling")
parser.add_argument("--yappi", action='store_const', const=True, default=False, help="Enable YAPPI")
parser.add_argument("--nogui", dest='gui', action='store_false',
default=True, help="Disable GUI")
parser.add_argument("--preset", type=str, help="Specify a preset name to run only that preset (useful for debugging)")
parser.add_argument("--verbose", action='store_const', const=True, default=False, help="Enable verbose log output")
parser.add_argument("--noaudio", action='store_const', const=True, default=False, help="Disable audio processing client")
args = parser.parse_args()
if args.verbose:
log.setLevel(logging.DEBUG)
log.info("Booting FireMix...")
qt_app = QtGui.QApplication(sys.argv, args.gui)
app = FireMixApp(qt_app, args)
signal.signal(signal.SIGINT, functools.partial(sig_handler, app))
app.start()
if args.gui:
gui = FireMixGUI(app=app)
gui.show()
else:
# When the UI isn't running, the Qt application spends all its time
# running in its event loop (implemented in C). During that time, we
# can't process any (Unix) signals in Python. So, in order to handle
# signals, we have to occationally execute some Python code. We just do
# nothing when the timeout fires.
timer = QtCore.QTimer()
timer.start(500)
timer.timeout.connect(lambda: None)
qt_app.exec_()
if args.profile:
print "------ TICK TIME HISTOGRAM ------"
elapsed = (app.mixer._stop_time - app.mixer._start_time)
print "%d frames in %0.2f seconds (%0.2f FPS) " % (app.mixer._num_frames, elapsed, app.mixer._num_frames / elapsed)
for c in sorted(app.mixer._tick_time_data.iterkeys()):
print "[%d fps]:\t%4d\t%0.2f%%" % (c, app.mixer._tick_time_data[c], (float(app.mixer._tick_time_data[c]) / app.mixer._num_frames) * 100.0)
if __name__ == "__main__":
main()