led-controller-version-3-effect-creation 3.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- led_controller_version_3_effect_creation-3.0.2.dist-info/METADATA +144 -0
- led_controller_version_3_effect_creation-3.0.2.dist-info/RECORD +25 -0
- led_controller_version_3_effect_creation-3.0.2.dist-info/WHEEL +4 -0
- led_controller_version_3_effect_creation-3.0.2.dist-info/entry_points.txt +3 -0
- lefx/effect_creation/__init__.py +54 -0
- lefx/effect_creation/build.py +217 -0
- lefx/effect_creation/cli.py +156 -0
- lefx/effect_creation/imports.py +143 -0
- lefx/effect_creation/scaffold.py +330 -0
- lefx/effect_creation/source.py +258 -0
- lefx/effect_creation/studio/__init__.py +95 -0
- lefx/effect_creation/studio/app.py +169 -0
- lefx/effect_creation/studio/authoring.py +196 -0
- lefx/effect_creation/studio/blueprint.py +759 -0
- lefx/effect_creation/studio/calibrate.py +185 -0
- lefx/effect_creation/studio/calibration_page.py +420 -0
- lefx/effect_creation/studio/catalogue.py +219 -0
- lefx/effect_creation/studio/parameters.py +730 -0
- lefx/effect_creation/studio/preset_dialog.py +188 -0
- lefx/effect_creation/studio/project.py +302 -0
- lefx/effect_creation/studio/ring.py +172 -0
- lefx/effect_creation/studio/session.py +307 -0
- lefx/effect_creation/studio/source_editor.py +902 -0
- lefx/effect_creation/studio/window.py +656 -0
- lefx/effect_creation/validate.py +263 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
"""The workbench: browse on the left, tune in the middle, watch on the right.
|
|
2
|
+
|
|
3
|
+
The layout is the workflow. You find a definition, you change its parameters,
|
|
4
|
+
and you see what that did — in that order, left to right, with nothing to click
|
|
5
|
+
between the change and the result.
|
|
6
|
+
|
|
7
|
+
Two decisions are worth stating, because both could reasonably have gone the
|
|
8
|
+
other way:
|
|
9
|
+
|
|
10
|
+
* **Live by default.** Every change is applied immediately for the forms where
|
|
11
|
+
that means something. Tuning a colour by pressing Apply after each nudge is
|
|
12
|
+
not tuning. Events are the exception and always will be: emitting one thirty
|
|
13
|
+
times a second because a slider moved would be a different effect than the one
|
|
14
|
+
under test.
|
|
15
|
+
* **The frames come from the device path.** The monitor draws what the sink was
|
|
16
|
+
handed, not a private re-render. A preview that renders separately agrees with
|
|
17
|
+
the device right up until the moment it does not, which is the moment you
|
|
18
|
+
would be relying on it.
|
|
19
|
+
|
|
20
|
+
Frames arrive on the service's render thread. They cross into the GUI thread
|
|
21
|
+
through a signal, which is the only safe way to touch a widget from elsewhere.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import logging
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
from PySide6.QtCore import Qt, Signal
|
|
30
|
+
from PySide6.QtGui import QAction
|
|
31
|
+
from PySide6.QtWidgets import (
|
|
32
|
+
QCheckBox,
|
|
33
|
+
QComboBox,
|
|
34
|
+
QDoubleSpinBox,
|
|
35
|
+
QGroupBox,
|
|
36
|
+
QHBoxLayout,
|
|
37
|
+
QLabel,
|
|
38
|
+
QLineEdit,
|
|
39
|
+
QListWidget,
|
|
40
|
+
QListWidgetItem,
|
|
41
|
+
QMainWindow,
|
|
42
|
+
QMessageBox,
|
|
43
|
+
QPushButton,
|
|
44
|
+
QScrollArea,
|
|
45
|
+
QSplitter,
|
|
46
|
+
QStatusBar,
|
|
47
|
+
QTabWidget,
|
|
48
|
+
QVBoxLayout,
|
|
49
|
+
QWidget,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
from lefx.sdk import DefinitionKind
|
|
53
|
+
|
|
54
|
+
from . import catalogue
|
|
55
|
+
from .calibration_page import CalibrationPage
|
|
56
|
+
from .parameters import SchemaForm
|
|
57
|
+
from .preset_dialog import PresetDialog
|
|
58
|
+
from .project import Project, iter_paths, remember
|
|
59
|
+
from .ring import RingMonitor
|
|
60
|
+
from .source_editor import SourceEditorPage
|
|
61
|
+
from .session import NULL_OUTPUT, STUDIO_CHANNEL, StudioSession, available_outputs, device_in_use
|
|
62
|
+
|
|
63
|
+
logger = logging.getLogger("lefx.effect_creation.studio.window")
|
|
64
|
+
|
|
65
|
+
KIND_FILTERS: list[tuple[str, DefinitionKind | None]] = [
|
|
66
|
+
("Alle", None),
|
|
67
|
+
("States", DefinitionKind.STATE),
|
|
68
|
+
("Controlled Overlays", DefinitionKind.CONTROLLED_OVERLAY),
|
|
69
|
+
("Timed Overlays", DefinitionKind.TIMED_OVERLAY),
|
|
70
|
+
("Events", DefinitionKind.EVENT),
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class StudioWindow(QMainWindow):
|
|
75
|
+
"""One window, one session, one effect being looked at."""
|
|
76
|
+
|
|
77
|
+
frame_received = Signal(tuple)
|
|
78
|
+
|
|
79
|
+
def __init__(self, session: StudioSession, *, initial_output: str = NULL_OUTPUT) -> None:
|
|
80
|
+
super().__init__()
|
|
81
|
+
self.session = session
|
|
82
|
+
self.entries: list[catalogue.Entry] = []
|
|
83
|
+
self.selected: catalogue.Entry | None = None
|
|
84
|
+
self.config_form: SchemaForm | None = None
|
|
85
|
+
self.inputs_form: SchemaForm | None = None
|
|
86
|
+
self._applying = False
|
|
87
|
+
|
|
88
|
+
self.setWindowTitle("LEFX Studio")
|
|
89
|
+
self.resize(1280, 760)
|
|
90
|
+
self._build()
|
|
91
|
+
|
|
92
|
+
# Queued by Qt because it is emitted from the render thread. Both
|
|
93
|
+
# monitors watch the same frames; whichever page is in front is showing
|
|
94
|
+
# what the device is being sent, not a rendering of its own.
|
|
95
|
+
self.frame_received.connect(self.monitor.set_colors)
|
|
96
|
+
self.frame_received.connect(self.calibration.monitor.set_colors)
|
|
97
|
+
self.frame_received.connect(self.editor.monitor.set_colors)
|
|
98
|
+
self.session.set_frame_listener(self.frame_received.emit)
|
|
99
|
+
|
|
100
|
+
self._select_output(initial_output)
|
|
101
|
+
|
|
102
|
+
# -- construction -------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
def _build(self) -> None:
|
|
105
|
+
splitter = QSplitter(Qt.Orientation.Horizontal)
|
|
106
|
+
splitter.addWidget(self._build_browser())
|
|
107
|
+
splitter.addWidget(self._build_editor())
|
|
108
|
+
splitter.addWidget(self._build_monitor())
|
|
109
|
+
splitter.setStretchFactor(0, 2)
|
|
110
|
+
splitter.setStretchFactor(1, 3)
|
|
111
|
+
splitter.setStretchFactor(2, 3)
|
|
112
|
+
|
|
113
|
+
self.calibration = CalibrationPage(self.session)
|
|
114
|
+
self.editor = SourceEditorPage(self.session)
|
|
115
|
+
|
|
116
|
+
self.tabs = QTabWidget()
|
|
117
|
+
self.tabs.addTab(splitter, "Player")
|
|
118
|
+
self.tabs.addTab(self.calibration, "Kalibrierung")
|
|
119
|
+
self.tabs.addTab(self.editor, "Neuer Effekt")
|
|
120
|
+
self.tabs.currentChanged.connect(self._on_tab_changed)
|
|
121
|
+
self.setCentralWidget(self.tabs)
|
|
122
|
+
|
|
123
|
+
self.setStatusBar(QStatusBar())
|
|
124
|
+
self._build_menu()
|
|
125
|
+
|
|
126
|
+
def _on_tab_changed(self, index: int) -> None:
|
|
127
|
+
# The calibration page needs to know which device it is measuring, and
|
|
128
|
+
# the output can have changed since it was last looked at.
|
|
129
|
+
page = self.tabs.widget(index)
|
|
130
|
+
if page is self.calibration:
|
|
131
|
+
self.calibration.refresh()
|
|
132
|
+
elif page is self.editor:
|
|
133
|
+
self.editor.refresh()
|
|
134
|
+
|
|
135
|
+
def _build_menu(self) -> None:
|
|
136
|
+
project_menu = self.menuBar().addMenu("&Projekt")
|
|
137
|
+
open_action = QAction("Projekt öffnen …", self)
|
|
138
|
+
open_action.setShortcut("Ctrl+O")
|
|
139
|
+
open_action.triggered.connect(self._choose_project)
|
|
140
|
+
project_menu.addAction(open_action)
|
|
141
|
+
where_action = QAction("Pfade zeigen", self)
|
|
142
|
+
where_action.triggered.connect(self._show_paths)
|
|
143
|
+
project_menu.addAction(where_action)
|
|
144
|
+
|
|
145
|
+
catalogue_menu = self.menuBar().addMenu("&Katalog")
|
|
146
|
+
reload_action = QAction("Quellen neu laden", self)
|
|
147
|
+
reload_action.setShortcut("F5")
|
|
148
|
+
reload_action.triggered.connect(self._reload_sources)
|
|
149
|
+
catalogue_menu.addAction(reload_action)
|
|
150
|
+
build_action = QAction("Katalog bauen", self)
|
|
151
|
+
build_action.setShortcut("Ctrl+B")
|
|
152
|
+
build_action.setToolTip("Jede Quelle packen und die Sets neu bauen")
|
|
153
|
+
build_action.triggered.connect(self._build_catalogue)
|
|
154
|
+
catalogue_menu.addAction(build_action)
|
|
155
|
+
|
|
156
|
+
output_menu = self.menuBar().addMenu("&Ausgabe")
|
|
157
|
+
clear_action = QAction("Alles löschen", self)
|
|
158
|
+
clear_action.triggered.connect(self._clear_everything)
|
|
159
|
+
output_menu.addAction(clear_action)
|
|
160
|
+
|
|
161
|
+
# -- the project --------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
def _choose_project(self) -> None:
|
|
164
|
+
from PySide6.QtWidgets import QFileDialog
|
|
165
|
+
|
|
166
|
+
current = self.session.project
|
|
167
|
+
chosen = QFileDialog.getExistingDirectory(
|
|
168
|
+
self, "Projektverzeichnis wählen", str(current.root if current else "")
|
|
169
|
+
)
|
|
170
|
+
if chosen:
|
|
171
|
+
self.use_project(Project.at(chosen))
|
|
172
|
+
|
|
173
|
+
def use_project(self, project: Project) -> None:
|
|
174
|
+
"""Point the whole window at another checkout.
|
|
175
|
+
|
|
176
|
+
Everything derived from the root moves at once — where effects are read
|
|
177
|
+
from, where a calibration is kept, where a new source is offered. A
|
|
178
|
+
studio that changed only some of those would be editing one project and
|
|
179
|
+
writing into another.
|
|
180
|
+
"""
|
|
181
|
+
self.session.use(project)
|
|
182
|
+
remember(project)
|
|
183
|
+
self.setWindowTitle(f"LEFX Studio — {project.label}")
|
|
184
|
+
self._reload_sources()
|
|
185
|
+
self.calibration.refresh()
|
|
186
|
+
self.editor.refresh()
|
|
187
|
+
if not project.looks_like_a_project:
|
|
188
|
+
self.statusBar().showMessage(
|
|
189
|
+
f"{project.root} enthält noch keinen Katalog — „Neuer Effekt“ legt den ersten an.",
|
|
190
|
+
12000,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
def _show_paths(self) -> None:
|
|
194
|
+
project = self.session.project
|
|
195
|
+
if project is None:
|
|
196
|
+
return
|
|
197
|
+
lines = "\n".join(f"{label}: {path}" for label, path in iter_paths(project))
|
|
198
|
+
QMessageBox.information(self, "Projektpfade", lines)
|
|
199
|
+
|
|
200
|
+
def _build_catalogue(self) -> None:
|
|
201
|
+
"""Build every set in the project, without needing a terminal.
|
|
202
|
+
|
|
203
|
+
The standalone build has no ``scripts/`` to shell out to, and a tool
|
|
204
|
+
that can write a source should be able to build it.
|
|
205
|
+
"""
|
|
206
|
+
project = self.session.project
|
|
207
|
+
if project is None:
|
|
208
|
+
return
|
|
209
|
+
try:
|
|
210
|
+
results = project.build_catalogue()
|
|
211
|
+
except Exception as exc:
|
|
212
|
+
QMessageBox.critical(self, "Build fehlgeschlagen", str(exc))
|
|
213
|
+
return
|
|
214
|
+
if not results:
|
|
215
|
+
QMessageBox.information(
|
|
216
|
+
self, "Nichts zu bauen", f"Keine Effekt-Sets unter {project.catalogue_root}."
|
|
217
|
+
)
|
|
218
|
+
return
|
|
219
|
+
summary = "\n".join(
|
|
220
|
+
f"{item['set_id']}: {item['effect_count']} Definitionen" for item in results
|
|
221
|
+
)
|
|
222
|
+
self._reload_sources()
|
|
223
|
+
QMessageBox.information(self, "Katalog gebaut", summary)
|
|
224
|
+
|
|
225
|
+
def _build_browser(self) -> QWidget:
|
|
226
|
+
panel = QWidget()
|
|
227
|
+
layout = QVBoxLayout(panel)
|
|
228
|
+
|
|
229
|
+
self.search = QLineEdit()
|
|
230
|
+
self.search.setPlaceholderText("Suchen: Id, Titel, Beschreibung, Quelle, Tag")
|
|
231
|
+
self.search.setClearButtonEnabled(True)
|
|
232
|
+
self.search.textChanged.connect(self._refresh_list)
|
|
233
|
+
|
|
234
|
+
self.kind_filter = QComboBox()
|
|
235
|
+
for label, _ in KIND_FILTERS:
|
|
236
|
+
self.kind_filter.addItem(label)
|
|
237
|
+
self.kind_filter.currentIndexChanged.connect(self._refresh_list)
|
|
238
|
+
|
|
239
|
+
self.source_filter = QComboBox()
|
|
240
|
+
self.source_filter.addItem("Alle Quellen")
|
|
241
|
+
self.source_filter.currentIndexChanged.connect(self._refresh_list)
|
|
242
|
+
|
|
243
|
+
self.list = QListWidget()
|
|
244
|
+
self.list.currentItemChanged.connect(self._on_selected)
|
|
245
|
+
|
|
246
|
+
layout.addWidget(self.search)
|
|
247
|
+
filters = QHBoxLayout()
|
|
248
|
+
filters.addWidget(self.kind_filter, stretch=1)
|
|
249
|
+
filters.addWidget(self.source_filter, stretch=1)
|
|
250
|
+
layout.addLayout(filters)
|
|
251
|
+
layout.addWidget(self.list, stretch=1)
|
|
252
|
+
return panel
|
|
253
|
+
|
|
254
|
+
def _build_editor(self) -> QWidget:
|
|
255
|
+
panel = QWidget()
|
|
256
|
+
layout = QVBoxLayout(panel)
|
|
257
|
+
|
|
258
|
+
self.headline = QLabel("Nichts ausgewählt")
|
|
259
|
+
self.headline.setStyleSheet("font-size: 15px; font-weight: 600;")
|
|
260
|
+
self.subline = QLabel("")
|
|
261
|
+
self.subline.setWordWrap(True)
|
|
262
|
+
self.subline.setStyleSheet("color: #888;")
|
|
263
|
+
layout.addWidget(self.headline)
|
|
264
|
+
layout.addWidget(self.subline)
|
|
265
|
+
|
|
266
|
+
self.preset_row = QHBoxLayout()
|
|
267
|
+
self.preset_row.addWidget(QLabel("Preset"))
|
|
268
|
+
self.preset_box = QComboBox()
|
|
269
|
+
self.preset_box.currentIndexChanged.connect(self._on_preset_chosen)
|
|
270
|
+
self.preset_row.addWidget(self.preset_box, stretch=1)
|
|
271
|
+
layout.addLayout(self.preset_row)
|
|
272
|
+
|
|
273
|
+
self.scroll = QScrollArea()
|
|
274
|
+
self.scroll.setWidgetResizable(True)
|
|
275
|
+
self.form_host = QWidget()
|
|
276
|
+
self.form_layout = QVBoxLayout(self.form_host)
|
|
277
|
+
self.form_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
278
|
+
self.scroll.setWidget(self.form_host)
|
|
279
|
+
layout.addWidget(self.scroll, stretch=1)
|
|
280
|
+
|
|
281
|
+
actions = QHBoxLayout()
|
|
282
|
+
self.live_box = QCheckBox("Live")
|
|
283
|
+
self.live_box.setChecked(True)
|
|
284
|
+
self.live_box.setToolTip("Jede Änderung sofort anwenden (nie für Events)")
|
|
285
|
+
self.preset_button = QPushButton("Als Preset sichern …")
|
|
286
|
+
self.preset_button.setToolTip(
|
|
287
|
+
"Die aktuellen Werte benennen und in die Quelle des Effekts schreiben"
|
|
288
|
+
)
|
|
289
|
+
self.preset_button.clicked.connect(self._curate_preset)
|
|
290
|
+
self.play_button = QPushButton("Abspielen")
|
|
291
|
+
self.play_button.clicked.connect(self._apply)
|
|
292
|
+
self.stop_button = QPushButton("Beenden")
|
|
293
|
+
self.stop_button.clicked.connect(self._stop_current)
|
|
294
|
+
actions.addWidget(self.live_box)
|
|
295
|
+
actions.addStretch(1)
|
|
296
|
+
actions.addWidget(self.preset_button)
|
|
297
|
+
actions.addWidget(self.stop_button)
|
|
298
|
+
actions.addWidget(self.play_button)
|
|
299
|
+
layout.addLayout(actions)
|
|
300
|
+
return panel
|
|
301
|
+
|
|
302
|
+
def _build_monitor(self) -> QWidget:
|
|
303
|
+
panel = QWidget()
|
|
304
|
+
layout = QVBoxLayout(panel)
|
|
305
|
+
|
|
306
|
+
output_box = QGroupBox("Ausgabe")
|
|
307
|
+
output_layout = QVBoxLayout(output_box)
|
|
308
|
+
self.output_box = QComboBox()
|
|
309
|
+
for name in available_outputs():
|
|
310
|
+
self.output_box.addItem(name)
|
|
311
|
+
self.output_box.currentTextChanged.connect(self._select_output)
|
|
312
|
+
output_layout.addWidget(self.output_box)
|
|
313
|
+
|
|
314
|
+
self.output_state = QLabel("—")
|
|
315
|
+
self.output_state.setWordWrap(True)
|
|
316
|
+
output_layout.addWidget(self.output_state)
|
|
317
|
+
layout.addWidget(output_box)
|
|
318
|
+
|
|
319
|
+
self.monitor = RingMonitor(self.session.led_count)
|
|
320
|
+
layout.addWidget(self.monitor, stretch=1)
|
|
321
|
+
|
|
322
|
+
view = QHBoxLayout()
|
|
323
|
+
indices = QCheckBox("Indizes")
|
|
324
|
+
indices.setChecked(True)
|
|
325
|
+
indices.toggled.connect(self.monitor.set_show_indices)
|
|
326
|
+
sectors = QCheckBox("15°-Sektoren")
|
|
327
|
+
sectors.toggled.connect(self.monitor.set_show_sectors)
|
|
328
|
+
view.addWidget(indices)
|
|
329
|
+
view.addWidget(sectors)
|
|
330
|
+
view.addStretch(1)
|
|
331
|
+
layout.addLayout(view)
|
|
332
|
+
|
|
333
|
+
global_box = QGroupBox("Global")
|
|
334
|
+
global_layout = QHBoxLayout(global_box)
|
|
335
|
+
global_layout.addWidget(QLabel("Helligkeit"))
|
|
336
|
+
self.brightness = QDoubleSpinBox()
|
|
337
|
+
self.brightness.setRange(0.0, 1.0)
|
|
338
|
+
self.brightness.setSingleStep(0.05)
|
|
339
|
+
self.brightness.setValue(1.0)
|
|
340
|
+
self.brightness.valueChanged.connect(
|
|
341
|
+
lambda value: self._guarded(lambda: self.session.set_output(brightness=float(value)))
|
|
342
|
+
)
|
|
343
|
+
self.enabled = QCheckBox("an")
|
|
344
|
+
self.enabled.setChecked(True)
|
|
345
|
+
self.enabled.toggled.connect(
|
|
346
|
+
lambda value: self._guarded(lambda: self.session.set_output(enabled=bool(value)))
|
|
347
|
+
)
|
|
348
|
+
global_layout.addWidget(self.brightness)
|
|
349
|
+
global_layout.addWidget(self.enabled)
|
|
350
|
+
layout.addWidget(global_box)
|
|
351
|
+
return panel
|
|
352
|
+
|
|
353
|
+
# -- the output ---------------------------------------------------------
|
|
354
|
+
|
|
355
|
+
def _select_output(self, name: str) -> None:
|
|
356
|
+
if not name:
|
|
357
|
+
return
|
|
358
|
+
if name != NULL_OUTPUT:
|
|
359
|
+
busy = device_in_use()
|
|
360
|
+
if busy is not None:
|
|
361
|
+
QMessageBox.warning(
|
|
362
|
+
self,
|
|
363
|
+
"Gerät ist belegt",
|
|
364
|
+
f"{busy}.\n\nNur ein Prozess kann ein Gerät halten. Beende den Dienst, "
|
|
365
|
+
"oder wähle eine andere Ausgabe.",
|
|
366
|
+
)
|
|
367
|
+
self._set_output_box(self.session.output_name)
|
|
368
|
+
return
|
|
369
|
+
try:
|
|
370
|
+
self.session.open(name)
|
|
371
|
+
except Exception as exc:
|
|
372
|
+
logger.exception("could not open %s", name)
|
|
373
|
+
QMessageBox.critical(self, "Ausgabe nicht verfügbar", f"{name}: {exc}")
|
|
374
|
+
self._set_output_box(NULL_OUTPUT)
|
|
375
|
+
self.session.open(NULL_OUTPUT)
|
|
376
|
+
|
|
377
|
+
self.monitor.set_led_count(self.session.led_count)
|
|
378
|
+
self._reload_sources()
|
|
379
|
+
self._refresh_output_state()
|
|
380
|
+
self.calibration.refresh()
|
|
381
|
+
self.editor.refresh()
|
|
382
|
+
|
|
383
|
+
def _set_output_box(self, name: str) -> None:
|
|
384
|
+
self.output_box.blockSignals(True)
|
|
385
|
+
index = self.output_box.findText(name)
|
|
386
|
+
if index >= 0:
|
|
387
|
+
self.output_box.setCurrentIndex(index)
|
|
388
|
+
self.output_box.blockSignals(False)
|
|
389
|
+
|
|
390
|
+
def _refresh_output_state(self) -> None:
|
|
391
|
+
status = self.session.sink_status()
|
|
392
|
+
if status.available:
|
|
393
|
+
self.output_state.setText(f"✓ {self.session.output_name}")
|
|
394
|
+
self.output_state.setStyleSheet("color: #4c9;")
|
|
395
|
+
else:
|
|
396
|
+
self.output_state.setText(f"✗ {self.session.output_name}: {status.detail or 'nicht verfügbar'}")
|
|
397
|
+
self.output_state.setStyleSheet("color: #d76;")
|
|
398
|
+
|
|
399
|
+
# -- the catalogue ------------------------------------------------------
|
|
400
|
+
|
|
401
|
+
def _reload_sources(self) -> None:
|
|
402
|
+
if self.session.service is None:
|
|
403
|
+
return
|
|
404
|
+
try:
|
|
405
|
+
self.session.reload_sources()
|
|
406
|
+
except Exception as exc:
|
|
407
|
+
logger.warning("reloading sources failed: %s", exc)
|
|
408
|
+
registry = self.session.registry
|
|
409
|
+
self.entries = catalogue.entries(registry.list_effects())
|
|
410
|
+
|
|
411
|
+
current = self.source_filter.currentText()
|
|
412
|
+
self.source_filter.blockSignals(True)
|
|
413
|
+
self.source_filter.clear()
|
|
414
|
+
self.source_filter.addItem("Alle Quellen")
|
|
415
|
+
for source_id in registry.source_ids():
|
|
416
|
+
self.source_filter.addItem(source_id)
|
|
417
|
+
restored = self.source_filter.findText(current)
|
|
418
|
+
self.source_filter.setCurrentIndex(max(0, restored))
|
|
419
|
+
self.source_filter.blockSignals(False)
|
|
420
|
+
|
|
421
|
+
self._refresh_list()
|
|
422
|
+
self.statusBar().showMessage(
|
|
423
|
+
f"{len(self.entries)} Definitionen, {len(registry.list_presets())} Presets", 4000
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
def _refresh_list(self) -> None:
|
|
427
|
+
kind = KIND_FILTERS[max(0, self.kind_filter.currentIndex())][1]
|
|
428
|
+
source = self.source_filter.currentText()
|
|
429
|
+
shown = catalogue.filtered(
|
|
430
|
+
self.entries,
|
|
431
|
+
query=self.search.text(),
|
|
432
|
+
kind=kind,
|
|
433
|
+
source_id=None if self.source_filter.currentIndex() <= 0 else source,
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
keep = self.selected.effect_id if self.selected is not None else None
|
|
437
|
+
self.list.blockSignals(True)
|
|
438
|
+
self.list.clear()
|
|
439
|
+
for entry in shown:
|
|
440
|
+
item = QListWidgetItem(f"{entry.title}\n{entry.kind_label} · {entry.effect.source_id}")
|
|
441
|
+
item.setData(Qt.ItemDataRole.UserRole, entry.effect_id)
|
|
442
|
+
self.list.addItem(item)
|
|
443
|
+
self.list.blockSignals(False)
|
|
444
|
+
|
|
445
|
+
if keep is not None:
|
|
446
|
+
for row in range(self.list.count()):
|
|
447
|
+
if self.list.item(row).data(Qt.ItemDataRole.UserRole) == keep:
|
|
448
|
+
self.list.setCurrentRow(row)
|
|
449
|
+
return
|
|
450
|
+
if self.list.count():
|
|
451
|
+
self.list.setCurrentRow(0)
|
|
452
|
+
|
|
453
|
+
# -- selection and editing ---------------------------------------------
|
|
454
|
+
|
|
455
|
+
def _on_selected(self, item: QListWidgetItem | None, _previous=None) -> None:
|
|
456
|
+
if item is None:
|
|
457
|
+
return
|
|
458
|
+
effect_id = item.data(Qt.ItemDataRole.UserRole)
|
|
459
|
+
entry = next((one for one in self.entries if one.effect_id == effect_id), None)
|
|
460
|
+
if entry is None:
|
|
461
|
+
return
|
|
462
|
+
self.selected = entry
|
|
463
|
+
self._rebuild_forms(entry)
|
|
464
|
+
|
|
465
|
+
def _rebuild_forms(self, entry: catalogue.Entry) -> None:
|
|
466
|
+
definition = entry.definition
|
|
467
|
+
playback = catalogue.playback_for(definition)
|
|
468
|
+
provider = catalogue.pulls_a_provider(definition)
|
|
469
|
+
|
|
470
|
+
self.headline.setText(f"{entry.title} · {entry.effect_id}")
|
|
471
|
+
notes = [entry.kind_label, f"Quelle: {entry.effect.source_id}"]
|
|
472
|
+
if provider:
|
|
473
|
+
notes.append(f"liest Capability „{provider}“ vom Gerät")
|
|
474
|
+
if definition.description:
|
|
475
|
+
notes.append(definition.description)
|
|
476
|
+
self.subline.setText(" · ".join(notes))
|
|
477
|
+
|
|
478
|
+
while self.form_layout.count():
|
|
479
|
+
widget = self.form_layout.takeAt(0).widget()
|
|
480
|
+
if widget is not None:
|
|
481
|
+
widget.setParent(None)
|
|
482
|
+
widget.deleteLater()
|
|
483
|
+
|
|
484
|
+
self.config_form = SchemaForm(definition.parameter_schema, on_change=self._on_edited)
|
|
485
|
+
config_box = QGroupBox("Parameter")
|
|
486
|
+
QVBoxLayout(config_box).addWidget(self.config_form)
|
|
487
|
+
self.form_layout.addWidget(config_box)
|
|
488
|
+
|
|
489
|
+
self.inputs_form = None
|
|
490
|
+
schema = getattr(definition, "runtime_input_schema", {}) or {}
|
|
491
|
+
if schema and provider is None:
|
|
492
|
+
# Pushed inputs: nothing supplies them, so the studio does.
|
|
493
|
+
self.inputs_form = SchemaForm(schema, on_change=self._on_edited)
|
|
494
|
+
inputs_box = QGroupBox("Runtime-Eingaben")
|
|
495
|
+
QVBoxLayout(inputs_box).addWidget(self.inputs_form)
|
|
496
|
+
self.form_layout.addWidget(inputs_box)
|
|
497
|
+
elif schema:
|
|
498
|
+
# Pulled inputs: the device supplies them and the studio must not
|
|
499
|
+
# pretend to. Showing editable fields here would produce values that
|
|
500
|
+
# the next sample overwrites, which reads as the controls not working.
|
|
501
|
+
note = QLabel(
|
|
502
|
+
f"Die Werte liefert das Gerät über die Capability „{provider}“.\n"
|
|
503
|
+
"Ausgabe umschalten, um gegen ein anderes Gerät zu prüfen."
|
|
504
|
+
)
|
|
505
|
+
note.setWordWrap(True)
|
|
506
|
+
note.setStyleSheet("color: #888; padding: 6px;")
|
|
507
|
+
self.form_layout.addWidget(note)
|
|
508
|
+
|
|
509
|
+
self.config_form.set_values(catalogue.starting_config(definition))
|
|
510
|
+
if self.inputs_form is not None:
|
|
511
|
+
self.inputs_form.set_values(catalogue.starting_inputs(definition))
|
|
512
|
+
|
|
513
|
+
self._rebuild_presets(entry)
|
|
514
|
+
self.play_button.setText("Auslösen" if not playback.repeatable else "Abspielen")
|
|
515
|
+
self.stop_button.setEnabled(playback.verb != "event")
|
|
516
|
+
if playback.repeatable and self.live_box.isChecked():
|
|
517
|
+
self._apply()
|
|
518
|
+
|
|
519
|
+
def _rebuild_presets(self, entry: catalogue.Entry) -> None:
|
|
520
|
+
presets = self.session.registry.list_presets(effect_id=entry.effect_id)
|
|
521
|
+
self.preset_box.blockSignals(True)
|
|
522
|
+
self.preset_box.clear()
|
|
523
|
+
self.preset_box.addItem("— keins —", None)
|
|
524
|
+
for preset in presets:
|
|
525
|
+
self.preset_box.addItem(preset.title or preset.preset_id, preset.preset_id)
|
|
526
|
+
self.preset_box.blockSignals(False)
|
|
527
|
+
self.preset_box.setEnabled(bool(presets))
|
|
528
|
+
|
|
529
|
+
def _on_preset_chosen(self, index: int) -> None:
|
|
530
|
+
if self.selected is None or self.config_form is None or index <= 0:
|
|
531
|
+
return
|
|
532
|
+
preset_id = self.preset_box.currentData()
|
|
533
|
+
preset = next(
|
|
534
|
+
(
|
|
535
|
+
one
|
|
536
|
+
for one in self.session.registry.list_presets(effect_id=self.selected.effect_id)
|
|
537
|
+
if one.preset_id == preset_id
|
|
538
|
+
),
|
|
539
|
+
None,
|
|
540
|
+
)
|
|
541
|
+
self.config_form.set_values(
|
|
542
|
+
catalogue.starting_config(self.selected.definition, preset)
|
|
543
|
+
)
|
|
544
|
+
self._on_edited()
|
|
545
|
+
|
|
546
|
+
def _curate_preset(self) -> None:
|
|
547
|
+
"""Keep what is on screen, in the place a build will find it again.
|
|
548
|
+
|
|
549
|
+
Written into the *source*, not into the loaded package: a preset that
|
|
550
|
+
lived only in the running catalogue would last until the next build.
|
|
551
|
+
Afterwards the sources are reloaded, so the new preset appears in the
|
|
552
|
+
list it will be chosen from from now on.
|
|
553
|
+
"""
|
|
554
|
+
if self.selected is None or self.config_form is None:
|
|
555
|
+
return
|
|
556
|
+
project = self.session.project
|
|
557
|
+
dialog = PresetDialog(
|
|
558
|
+
self.selected.definition,
|
|
559
|
+
self.config_form.values(),
|
|
560
|
+
self,
|
|
561
|
+
source_roots=project.source_roots if project else None,
|
|
562
|
+
)
|
|
563
|
+
if dialog.exec() != PresetDialog.DialogCode.Accepted:
|
|
564
|
+
return
|
|
565
|
+
|
|
566
|
+
self.statusBar().showMessage(f"Preset in {dialog.written} geschrieben", 8000)
|
|
567
|
+
QMessageBox.information(
|
|
568
|
+
self,
|
|
569
|
+
"Preset gesichert",
|
|
570
|
+
f"Geschrieben nach:\n{dialog.written}\n\n"
|
|
571
|
+
"Es steckt jetzt in der Quelle. Nach dem nächsten "
|
|
572
|
+
"'scripts/build_effects.py' ist es auch im gebauten Set.",
|
|
573
|
+
)
|
|
574
|
+
|
|
575
|
+
def _on_edited(self) -> None:
|
|
576
|
+
if not self.live_box.isChecked() or self.selected is None:
|
|
577
|
+
return
|
|
578
|
+
if not catalogue.playback_for(self.selected.definition).repeatable:
|
|
579
|
+
return
|
|
580
|
+
self._apply()
|
|
581
|
+
|
|
582
|
+
# -- driving the engine -------------------------------------------------
|
|
583
|
+
|
|
584
|
+
def _apply(self) -> None:
|
|
585
|
+
if self.selected is None or self.config_form is None or self.session.service is None:
|
|
586
|
+
return
|
|
587
|
+
if self._applying:
|
|
588
|
+
return
|
|
589
|
+
self._applying = True
|
|
590
|
+
try:
|
|
591
|
+
definition = self.selected.definition
|
|
592
|
+
playback = catalogue.playback_for(definition)
|
|
593
|
+
config = self.config_form.values()
|
|
594
|
+
inputs = self.inputs_form.values() if self.inputs_form is not None else {}
|
|
595
|
+
|
|
596
|
+
if playback.verb == "state":
|
|
597
|
+
self.session.play_state(definition.id, config)
|
|
598
|
+
elif playback.verb == "overlay":
|
|
599
|
+
self.session.play_overlay(
|
|
600
|
+
definition.id,
|
|
601
|
+
config,
|
|
602
|
+
inputs,
|
|
603
|
+
channel=STUDIO_CHANNEL if playback.needs_channel else None,
|
|
604
|
+
)
|
|
605
|
+
else:
|
|
606
|
+
self.session.emit(definition.id, config)
|
|
607
|
+
self.statusBar().showMessage(f"{definition.id} angewendet", 2000)
|
|
608
|
+
except Exception as exc:
|
|
609
|
+
# A rejected value is ordinary while editing — half a colour name is
|
|
610
|
+
# not a colour yet. It belongs in the status bar, not in a dialog
|
|
611
|
+
# that has to be dismissed before the next keystroke.
|
|
612
|
+
self.statusBar().showMessage(str(exc), 6000)
|
|
613
|
+
finally:
|
|
614
|
+
self._applying = False
|
|
615
|
+
self._refresh_output_state()
|
|
616
|
+
|
|
617
|
+
def _stop_current(self) -> None:
|
|
618
|
+
if self.selected is None:
|
|
619
|
+
return
|
|
620
|
+
playback = catalogue.playback_for(self.selected.definition)
|
|
621
|
+
self._guarded(
|
|
622
|
+
self.session.clear_overlay
|
|
623
|
+
if playback.verb == "overlay"
|
|
624
|
+
else lambda: self.session.service.clear_state()
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
def _clear_everything(self) -> None:
|
|
628
|
+
self._guarded(self.session.clear_everything)
|
|
629
|
+
|
|
630
|
+
def _guarded(self, action) -> Any:
|
|
631
|
+
if self.session.service is None:
|
|
632
|
+
return None
|
|
633
|
+
try:
|
|
634
|
+
return action()
|
|
635
|
+
except Exception as exc:
|
|
636
|
+
self.statusBar().showMessage(str(exc), 6000)
|
|
637
|
+
return None
|
|
638
|
+
|
|
639
|
+
# -- shutdown -----------------------------------------------------------
|
|
640
|
+
|
|
641
|
+
def closeEvent(self, event) -> None: # noqa: N802 — Qt's spelling
|
|
642
|
+
"""Let go of the device on the way out.
|
|
643
|
+
|
|
644
|
+
The studio holds a USB endpoint or a socket while it runs, and a window
|
|
645
|
+
that closed without releasing it would leave the next thing to start
|
|
646
|
+
unable to find its device with nothing on screen to explain why.
|
|
647
|
+
"""
|
|
648
|
+
self.session.set_frame_listener(None)
|
|
649
|
+
# Before the session goes: a calibration run holds the device's own
|
|
650
|
+
# calibration aside while it measures, and it has to be given back.
|
|
651
|
+
self.calibration.close()
|
|
652
|
+
self.session.close()
|
|
653
|
+
super().closeEvent(event)
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
__all__ = ["KIND_FILTERS", "StudioWindow"]
|