-
Notifications
You must be signed in to change notification settings - Fork 12
/
firemix.py
executable file
·107 lines (86 loc) · 3.9 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
# This file is part of Firemix.
#
# Copyright 2013-2020 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 PyQt5 import QtCore, QtWidgets
try:
import qdarkstyle
except ImportError:
qdarkstyle = None
from firemix_app import FireMixApp
from ui.firemixgui import FireMixGUI
def call_ignoring_exceptions(func):
try:
func()
except Exception as e:
logging.getLogger("firemix").exception("Ignoring exception during shutdown request")
def sig_handler(app, sig, frame):
logging.getLogger("firemix").info("Received signal %d. Shutting down.", sig)
call_ignoring_exceptions(app.stop)
call_ignoring_exceptions(app.exit)
call_ignoring_exceptions(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("--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", "-v", action='count', default=0,
help="Enable verbose log output. Specify more than once for more output")
parser.add_argument("--noaudio", action='store_const', const=True, default=False, help="Disable audio processing client")
args = parser.parse_args()
if args.verbose >= 2:
log.setLevel(logging.DEBUG)
elif args.verbose >= 1:
log.setLevel(logging.INFO)
log.info("Booting FireMix...")
qt_app = QtWidgets.QApplication(sys.argv)
if qdarkstyle is not None:
qt_app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
app = FireMixApp(qt_app, args)
signal.signal(signal.SIGINT, functools.partial(sig_handler, app))
app.start()
if args.gui:
gui = FireMixGUI(app=app)
app.gui = gui
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.keys()):
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()