-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdca_plotter.py
261 lines (214 loc) · 10.3 KB
/
dca_plotter.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# This file is a derivation of work on - and as such shares the same
# licence as - Linux Show Player
#
# Linux Show Player:
# Copyright 2012-2021 Francesco Ceruti <[email protected]>
#
# This file:
# Copyright 2021 s0600204
#
# Linux Show Player 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.
#
# Linux Show Player 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 Linux Show Player. If not, see <http://www.gnu.org/licenses/>.
# pylint: disable=missing-docstring
# pylint: disable=no-name-in-module
from PyQt5.QtCore import QT_TRANSLATE_NOOP
from PyQt5.QtWidgets import QAction
# pylint: disable=import-error
from lisp.core.plugin import Plugin
from lisp.core.signal import Signal
from lisp.plugins.list_layout.layout import ListLayout
from lisp.ui.settings.app_configuration import AppConfigurationDialog
from lisp.ui.settings.session_configuration import SessionConfigurationDialog
from lisp.ui.ui_utils import translate
from dca_plotter.config.channel_assign import ChannelAssignConfig
from dca_plotter.cue.change_cue import DcaChangeCue
from dca_plotter.cue.reset_cue import DcaResetCue
from dca_plotter.dca_plotter_settings import DcaPlotterSettings
from dca_plotter.mapper.dialog import DcaMappingDialog
from dca_plotter.mapper.model import DcaMappingModel
from dca_plotter.roles.roles_switcher import RolesSwitcher
from dca_plotter.roles.roles_switcher_model import RolesSwitcherModel
from dca_plotter.tracker.model import DcaTrackingModel
from dca_plotter.tracker.view import DcaTrackingView
class DcaPlotter(Plugin):
"""Provides the ability to plot DCA/VCA assignments"""
Name = 'DCA/VCA Plotter'
Authors = ('s0600204',)
Depends = ('Midi', 'MidiFixtureControl')
Description = 'Provides the ability to plot DCA/VCA assignments'
CueCategory = QT_TRANSLATE_NOOP("CueCategory", "DCA/VCA Manipulation")
_mapping_menu_action = None
_mapping_dialog = None
_mapping_model = None
_roles_menu_action = None
_roles_switcher_dialog = None
_roles_switcher_model = None
_tracking_model = None
_tracker_view = None
_cue_types = (DcaChangeCue, DcaResetCue)
initialised = Signal()
def __init__(self, app):
super().__init__(app)
# Register the settings widget
AppConfigurationDialog.registerSettingsPage(
'plugins.dca_plotter', DcaPlotterSettings, DcaPlotter.Config)
DcaPlotter.Config.updated.connect(self._on_config_update)
# Register the session-level configuration of inputs
SessionConfigurationDialog.registerSettingsPage(
'channel_assign', ChannelAssignConfig, self)
# Register our cue types
for cue_type in self._cue_types:
app.cue_factory.register_factory(cue_type.__name__, cue_type)
app.window.registerSimpleCueMenu(cue_type, self.CueCategory)
self._roles_switcher_model = RolesSwitcherModel()
self._roles_menu_action = QAction(translate('dca_plotter', 'Roles Switcher'),
self.app.window)
self._roles_menu_action.triggered.connect(self._open_switcher_dialog)
self.app.window.menuTools.addAction(self._roles_menu_action)
def _open_mapper_dialog(self):
if not self.mapper_enabled():
return
if not self._mapping_dialog:
self._mapping_dialog = DcaMappingDialog(self._mapping_model)
self._mapping_dialog.open()
def _open_switcher_dialog(self):
if not self._roles_switcher_dialog:
self._roles_switcher_dialog = RolesSwitcher(self._roles_switcher_model)
self._roles_switcher_dialog.open()
def _pre_session_deinitialisation(self, _):
'''Called when session is being de-init'd.'''
layout = self.app.layout
self._roles_switcher_model.roleUpdated.disconnect(self._tracking_model.role_assign_swap)
if isinstance(layout, ListLayout):
layout.model.item_added.disconnect(self._on_cue_added)
layout.model.item_moved.disconnect(self._on_cue_moved)
layout.model.item_removed.disconnect(self._on_cue_removed)
layout.view.listView.currentItemChanged.disconnect(self._on_cue_selected)
if self._tracker_view:
self._tracker_view.deinitialise()
self._tracker_view = None
def finalize(self):
'''Called when application is closing'''
super().finalize()
self._tracker_view = None
def _on_session_initialised(self, _):
"""Post-session-initialisation init.
Called after the plugin session-configuration have been set, but before cues have
been restored (in the case of loading from file).
"""
layout = self.app.layout
# Create the session's dca-tracking model
# This model does not contain cues.
# Instead it tracks which mics are muted and are currently assigned where
self._tracking_model = DcaTrackingModel(self.mapper_enabled())
# Renew the options in the Role Switcher
self._roles_switcher_model.renew(self.SessionConfig)
self._roles_switcher_model.roleUpdated.connect(self._tracking_model.role_assign_swap)
# If the mapper is not to be used we don't need to have it or its menu option in existence
if not self.mapper_enabled():
if self._mapping_menu_action:
self.app.window.menuTools.removeAction(self._mapping_menu_action)
self._mapping_menu_action = None
self._mapping_model = None
if self._mapping_dialog:
self._mapping_dialog.close()
self.initialised.emit()
return
# Draw the tracker
self._tracker_view = DcaTrackingView(parent=layout.view.parent())
layout.view.layout().addWidget(self._tracker_view)
# Create the mapping model.
# This model *does* contain cues - or references to them - and with the
# aid of the listeners below gets updated when certain cues are updated.
self._mapping_model = DcaMappingModel()
if self._mapping_dialog:
self._mapping_dialog.setModel(self._mapping_model)
# Create an entry in the "Tools" menu
if not self._mapping_menu_action:
self._mapping_menu_action = QAction('DCA Mapper', self.app.window)
self._mapping_menu_action.triggered.connect(self._open_mapper_dialog)
self.app.window.menuTools.addAction(self._mapping_menu_action)
# Listeners for cue actions
layout.model.item_added.connect(self._on_cue_added)
layout.model.item_moved.connect(self._on_cue_moved)
layout.model.item_removed.connect(self._on_cue_removed)
layout.view.listView.currentItemChanged.connect(self._on_cue_selected)
self.initialised.emit()
def _on_config_update(self, args):
if 'blanking_text' in args:
self._tracking_model.regenerate_current()
def _on_session_config_altered(self, _):
# Renew the options in the Role Switcher
self._roles_switcher_model.renew(self.SessionConfig)
self._tracking_model.regenerate_current()
def _on_cue_selected(self, current, _):
"""Action to take when a cue is selected.
This function only gets called if the session is in the "List" layout.
With the "Cart" layout, selecting a cue calls the cue.
(And there are no other layouts currently.)
"""
if current and self._mapping_model:
if self._is_supported_cuetype(current.cue.type):
self._tracking_model.select_cue(current.cue)
else:
self._tracking_model.clear_current_diff()
def _on_cue_added(self, cue):
"""Action to take when a cue is added to the List Layout."""
if self._is_supported_cuetype(cue.type):
self._mapping_model.append_cuerow(cue)
cue.property_changed.connect(self._tracking_model.on_cue_update)
def _on_cue_moved(self, _, new_index):
"""Action to take when a cue is moved in the List Layout."""
cue = self.app.layout.model.item(new_index)
if self._is_supported_cuetype(cue.type):
self._mapping_model.move_cuerow(cue, new_index)
def _on_cue_removed(self, cue):
"""Action to take when a cue is removed from the List Layout."""
if self._is_supported_cuetype(cue.type):
self._mapping_model.remove_cuerow(cue)
cue.property_changed.disconnect(self._tracking_model.on_cue_update)
def assignables(self, types):
"""
Returns tuples that represent the various assignable elements
(microphones, fx-returns, etc).
"""
assignables = []
for group in ['role', 'choir']:
if group in types:
for role_id in self.SessionConfig['assigns'][group]:
assignables.append((group, role_id))
for assignable in ['input', 'fx']:
if assignable in types:
count = len(self.SessionConfig['assigns'][assignable])
if count == 0:
count = self.Config[assignable + '_channel_count']
assignables.extend([(assignable, num + 1) for num in range(count)])
return assignables
def mapper_enabled(self):
return isinstance(self.app.layout, ListLayout)
def mapper(self):
return self._mapping_model
def resolve_role(self, role_id):
current = self._roles_switcher_model.current(role_id)
if current:
return current
if role_id in self.SessionConfig['assigns']['role']:
return tuple(self.SessionConfig['assigns']['role'][role_id]['default'])
return None
def resolve_choir(self, choir_id):
choir_assigns = self.SessionConfig['assigns']['choir'][choir_id]['assigns']
return [tuple(assign) for assign in choir_assigns]
def tracker(self):
return self._tracking_model
def _is_supported_cuetype(self, cue_type):
return cue_type in [ct.__name__ for ct in self._cue_types]