-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodedmx.py
More file actions
2911 lines (2534 loc) · 110 KB
/
codedmx.py
File metadata and controls
2911 lines (2534 loc) · 110 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import dearpygui.dearpygui as dpg
import time
import re
from threading import RLock, Thread
import model
import gui
import fixtures
import numpy as np
import os
from collections import defaultdict
import json
from cProfile import Profile
from pstats import SortKey, Stats
import argparse
import subprocess
import sys
import logging
import util
logging.basicConfig(
filename="log.txt",
filemode="w",
format="[%(asctime)s][%(levelname)s][%(name)s] %(message)s",
level=logging.DEBUG,
)
logger = logging.getLogger(__name__)
PROJECT_EXTENSION = "ndmx"
VARIABLE_NAME_PATTERN = r"[a-zA-Z_][a-zA-Z\d_]*$"
HUMAN_DELAY = 0.125
DEFAULT_SEQUENCE_DURATION = 4 # beats
def get_output_configuration_window_tag(track):
return f"{track.id}.gui.output_configuration_window"
def get_source_node_window_tag(input_channel, is_id=False):
return f"{input_channel if is_id else input_channel.id}.gui.source_node_window"
def get_properties_window_tag(obj):
return f"{obj.id}.gui.properties_window"
def get_plot_tag(input_channel):
return f"{input_channel.id}.plot"
def get_node_tag(obj):
return f"{obj.id}.node"
def get_node_window_tag(clip):
return f"{clip.id}.gui.node_window"
def get_code_window_tag(obj):
return f"{obj.id}.gui.code_editor.code_window"
def get_preset_menu_bar_tag(preset):
return f"{preset.id}.menu_bar"
def get_preset_sub_menu_tag(automation):
return f"{automation.id}.preset_menu"
def get_sequences_group_tag(track):
return f"{track.id}.sequences_group"
def get_sequence_button_tag(sequence):
return f"{sequence.id}.button"
def get_preset_button_tag(preset):
return f"{preset.id}.button"
def get_channel_preset_theme(preset):
return f"{preset.id}.theme"
class Application:
"""Runs the main dpg loop and state updates."""
def __init__(self, debug):
# Debug flag.
self.debug = debug
# Model and state logic
self.state = model.ProgramState()
# State of GUI elements.
# TODO: Move to IOWindow
self.gui_state = {
# I/O type
"io_types": {
"inputs": [None] * 5,
"outputs": [None] * 5,
},
# I/O arguments
"io_args": {
"inputs": [None] * 5,
"outputs": [None] * 5,
},
# Last active clip for each track
"track_last_active_clip": {},
# Themes for each clip preset
"clip_preset_themes": {},
}
# Special DPG tags to keep track of.
self.tags = {
# Drag Point tags for the currently selected automation window
"point_tags": [],
# Things to hide in the gui when a clip is selected.
"hide_on_clip_selection": [],
}
self.cache = {"recent": []}
# Current position of the mouse
self.mouse_x, self.mouse_y = 0, 0
# Position of the mouse while being dragged.
self.mouse_drag_x, self.mouse_drag_y = 0, 0
# Position of the mouse last time it was clicked.
self.mouse_click_x, self.mouse_click_y = 0, 0
# Current code view mode.
self.code_view = gui.CLIP_INIT_CODE_VIEW
# Whether keyboard mode is enabled.
self.keyboard_mode = False
self._active_track = None
self._active_clip = None
self._active_clip_slot = None
self._active_input_channel = None
self._active_presets = {}
# TODO: These can be held in the respective Window's object.
self._properties_buffer = defaultdict(dict)
self._tap_tempo_buffer = [0, 0, 0, 0, 0]
self._quantize_amount = None
self.ctrl = False
self.shift = False
self.copy_buffer = []
self.lock = RLock()
self.past_actions = []
# Windows
self.clip_preset_window = None
self.multi_clip_preset_window = None
self.save_new_multi_clip_preset_window = None
self.clip_automation_presets_window = None
self.global_storage_debug_window = None
self.io_window = None
self.inspector_window = None
self.rename_window = None
self.track_properties_windows = {}
self.console_window = None
self.remap_midi_device_window = None
self.code_window = None
self.reorder_window = None
self.sequence_configuration_window = None
self.sequences_window = None
self.preset_configuration_window = None
self.python_modules_window = None
self.window_manager = gui.WindowManager(self)
def run(self):
"""Initialize then run the main loop."""
self.initialize()
self.main_loop()
def initialize(self):
# Init main context.
logging.debug("Create dearpygui context")
dpg.create_context()
# Initialize dpg values
logging.debug("Initializing value registry")
with dpg.value_registry():
# The last midi message received
dpg.add_string_value(default_value="", tag="last_midi_message")
# Number of global elements
dpg.add_int_value(default_value=0, tag="n_global_storage_elements")
# Create main viewport.
logging.debug("Create viewport")
dpg.create_viewport(
title=f"CodeDMX [{self.state.project_name}] *",
width=gui.SCREEN_WIDTH,
height=gui.SCREEN_HEIGHT,
x_pos=50,
y_pos=0,
large_icon=gui.ICON,
small_icon=gui.ICON,
)
#### Init Themes ####
logging.debug("Creating themes")
self.create_themes()
#### Create Console ####
logging.debug("Creating console window")
self.console_window = gui.ConsoleWindow(self.state)
logging.debug("Creating performance windows")
self.clip_preset_window = gui.ClipPresetWindow(self.state)
self.save_new_multi_clip_preset_window = gui.SaveNewMultiClipPresetWindow(
self.state
)
self.multi_clip_preset_window = gui.MultiClipPresetWindow(self.state)
self.clip_automation_presets_window = gui.ClipAutomationPresetWindow(self.state)
self.add_new_trigger_window = gui.AddNewTriggerWindow(self.state)
self.manage_trigger_window = gui.ManageTriggerWindow(self.state)
self.remap_midi_device_window = gui.RemapMidiDeviceWindow(self.state)
self.reorder_window = gui.ReorderWindow(self.state)
self.sequence_configuration_window = gui.SequenceConfigurationWindow(self.state)
self.sequences_window = gui.SequencesWindow(self.state)
self.preset_configuration_window = gui.PresetConfigurationWindow(self.state)
#### Help Window ####
self.help_window = gui.HelpWindow(self.state)
#### Global Storage Debug Window ####
self.global_storage_debug_window = gui.GlobalStorageDebugWindow(self.state)
#### Create Code Editor Windows ####
logging.debug("Creating code editor windows")
self.code_window = gui.CodeWindow(self.state)
#### Create Clip Parameters Window ####
logging.debug("Creating clip parameters window")
self.clip_params_window = gui.ClipParametersWindow(self.state)
#### Create Clip Window ####
logging.debug("Creating clip window")
self.clip_window = gui.ClipWindow(self.state)
#### Mouse/Key Handlers ####
logging.debug("Installing mouse/key handlers")
with dpg.handler_registry():
dpg.add_mouse_move_handler(callback=self.mouse_move_callback)
dpg.add_mouse_click_handler(callback=self.mouse_click_callback)
dpg.add_mouse_double_click_handler(
callback=self.mouse_double_click_callback
)
dpg.add_key_press_handler(callback=self.key_press_callback)
dpg.add_key_down_handler(callback=self.key_down_callback)
dpg.add_key_release_handler(callback=self.key_release_callback)
logging.debug("Creating inspector window")
self.inspector_window = gui.InspectorWindow(self.state)
logging.debug("Creating i/o window")
self.io_window = gui.IOWindow(self.state)
logging.debug("Creating python modules window")
self.python_modules_window = gui.PythonModulesWindow(self.state)
logging.debug("Creating rename window")
self.rename_window = gui.RenameWindow(self.state)
#### File Dialogs ####
logging.debug("Creating viewport menu bar")
self.create_viewport_menu_bar()
# Initialize Tracks
self._active_track = self.state.tracks[0]
# Need to create these after the node_editor_windows
for track in self.state.tracks:
self.track_properties_windows[track.id] = gui.TrackPropertiesWindow(
self.state, track
)
# Automation Windows
logging.debug("Creating Automation Windows")
for track in self.state.tracks:
for clip in track.clips:
if not util.valid(clip):
continue
# Moved this to CreateNewClip
#for input_channel in clip.inputs:
# self.add_input_channel_callback(
# sender=None,
# app_data=None,
# user_data=(
# "restore",
# (clip, input_channel),
# ),
# )
logging.debug("Initializing window settings")
dpg.set_viewport_resize_callback(
callback=self.window_manager.resize_windows_callback
)
self.restore_gui_state()
dpg.setup_dearpygui()
dpg.show_viewport()
# dpg.show_item_registry()
# dpg.show_metrics()
def main_loop(self):
logging.debug("Starting main loop")
# State loop runs in a separate thread so that
# lighting fixtures continue to operate even if GUI locks up.
thread = Thread(target=self.state_loop)
thread.daemon = True
thread.start()
# Gui runs in this main thread.
try:
while dpg.is_dearpygui_running():
self.update_clip_window()
with self.lock:
self.update_clip_preset_window()
self.update_gui_from_state()
dpg.render_dearpygui_frame()
dpg.destroy_context()
except Exception as e:
import traceback
logger.warning(traceback.format_exc())
logger.warning(e)
raise e
def state_loop(self):
# Runs at 60 Hz
period = 1.0 / 60.0
while True:
t_start = time.time()
self.state.update()
t_end = time.time()
delta_t = t_end - t_start
if delta_t < period:
time.sleep(period - delta_t)
def gui_lock(func):
"""Return a wrapper that will grab the GUI lock."""
def wrapper(self, sender, app_data, user_data):
with self.lock:
return func(self, sender, app_data, user_data)
return wrapper
def execute_wrapper(self, command):
"""Wrapper around execute.
Should always use this function instead of ProgramState::execute
directly, so that the Application knows when the state is modified.
"""
dpg.set_viewport_title(f"CodeDMX [{self.state.project_name}] *")
result = self.state.execute(command)
skip = [
"update_automation_point",
"set_clip",
"add_multi_clip_preset",
]
if not any(kw in command for kw in skip):
self.clip_params_window.reset()
return result
def action(self, action: gui.GuiAction):
# Gui actions can modify state. Use the lock to make sure
# the enture state is updated before the GUI tries to render.
with self.lock:
action.execute()
self.past_actions.append(action)
def update_clip_window(self):
for track_i, track in enumerate(self.state.tracks):
for clip_i, clip in enumerate(track.clips):
clip_color = [0, 0, 0, 100]
if self._active_clip_slot == (track_i, clip_i):
clip_color[2] += 155
if util.valid(clip) and clip == self._active_clip:
clip_color[2] += 255
clip_color[1] += 50
if util.valid(clip) and clip.playing:
clip_color[1] += 255
if util.valid(clip) and not clip.playing:
clip_color[2] += 100
clip_color[1] += 50
if not util.valid(clip):
if track.global_track:
clip_color[0:3] = 70, 70, 50
else:
clip_color[0:3] = 50, 50, 50
if self._active_clip_slot == (track_i, clip_i):
clip_color[3] += 50
dpg.highlight_table_cell(
"clip_window.table", clip_i + 1, track_i, color=clip_color
)
if self._active_track == track:
dpg.highlight_table_column(
"clip_window.table", track_i, color=[100, 100, 100, 255]
)
else:
dpg.highlight_table_column(
"clip_window.table", track_i, color=[0, 0, 0, 0]
)
def update_clip_preset_window(self):
for track in self.state.tracks:
active_preset = self._active_presets.get(track.id, None)
for clip in track.clips:
if util.valid(clip):
for preset in clip.presets:
button_tag = get_preset_button_tag(preset)
if active_preset == preset:
dpg.bind_item_theme(button_tag, "selected_preset2.theme")
else:
dpg.bind_item_theme(
button_tag, get_channel_preset_theme(preset)
)
def add_clip_preset_to_menu(self, clip, preset, before=None):
menu_tag = f"{self.clip_params_window.tag}.menu_bar"
preset_menu_tag = f"{menu_tag}.preset_menu"
preset_menu_bar = get_preset_menu_bar_tag(preset)
preset_theme = get_channel_preset_theme(preset)
def set_color(sender, app_data, user_data):
if app_data is None:
color = dpg.get_value(sender)
else:
color = [int(255 * v) for v in app_data]
dpg.configure_item(f"{preset_theme}.text_color", value=color)
dpg.configure_item(f"{preset_theme}.button_bg_color", value=color)
self.gui_state["clip_preset_themes"][f"{preset_theme}.text_color"] = color
self.gui_state["clip_preset_themes"][
f"{preset_theme}.button_bg_color"
] = color
def duplicate_clip_preset(sender, app_data, user_data):
clip, preset = user_data
result = self.execute_wrapper(
f"duplicate_clip_preset {clip.id} {preset.id}"
)
if not result.success:
self.state.log.append("Failed to duplicate clip")
with dpg.menu(
parent=preset_menu_tag,
tag=preset_menu_bar,
label=preset.name,
before=get_preset_menu_bar_tag(before) if util.valid(before) else 0,
):
dpg.add_menu_item(
tag=f"{preset_menu_bar}.activate",
label="Activate",
callback=self.play_clip_preset_callback,
user_data=preset,
)
dpg.add_menu_item(
tag=f"{preset_menu_bar}.edit",
label="Edit",
callback=self.preset_configuration_window.configure_and_show,
user_data=(clip, preset),
)
dpg.add_menu_item(
tag=f"{preset_menu_bar}.duplicate",
label="Duplicate",
callback=duplicate_clip_preset,
user_data=(clip, preset),
)
with dpg.menu(label="Select Color"):
with dpg.group(horizontal=True):
dpg.add_color_button(
callback=set_color, default_value=(0, 200, 255)
)
dpg.add_color_button(
callback=set_color, default_value=(0, 255, 100)
)
dpg.add_color_button(
callback=set_color, default_value=(255, 100, 100)
)
dpg.add_color_button(
callback=set_color, default_value=(255, 255, 255)
)
dpg.add_color_button(callback=set_color, default_value=(0, 0, 0))
dpg.add_color_picker(
display_type=dpg.mvColorEdit_uint8, callback=set_color
)
dpg.add_menu_item(
tag=f"{preset_menu_bar}.delete",
label="Delete",
callback=self.delete_clip_preset_callback,
user_data=preset,
)
dpg.bind_item_theme(preset_menu_bar, preset_theme)
def create_automation_input_channel_window(self, input_channel):
parent = get_source_node_window_tag(input_channel)
with dpg.window(
tag=parent,
label="Automation Window",
show=False,
no_move=True,
no_title_bar=True,
):
self.tags["hide_on_clip_selection"].append(parent)
automation = input_channel.active_automation
series_tag = f"{input_channel.id}.series"
plot_tag = get_plot_tag(input_channel)
playhead_tag = f"{input_channel.id}.gui.playhead"
ext_value_tag = f"{input_channel.id}.gui.ext_value"
menu_tag = f"{input_channel.id}.menu"
with dpg.menu_bar(tag=menu_tag):
dpg.add_menu_item(
tag=f"{input_channel.id}.gui.automation_enable_button",
label="Disable" if input_channel.mode == "automation" else "Enable",
callback=self.toggle_automation_mode_callback,
user_data=input_channel,
)
# dpg.add_menu_item(tag=f"{input_channel.id}.gui.automation_record_button", label="Record", callback=self.enable_recording_mode_callback, user_data=input_channel)
preset_menu_tag = f"{input_channel.id}.preset_menu"
with dpg.menu(tag=preset_menu_tag, label="Automation"):
dpg.add_menu_item(
label="New Automation",
callback=self.add_preset_callback,
user_data=input_channel,
)
dpg.add_menu_item(
label="Reorder",
callback=self.reorder_window.configure_and_show,
user_data=(
input_channel.automations,
preset_menu_tag,
get_preset_sub_menu_tag,
),
)
for automation in input_channel.automations:
self.add_automation_tab(input_channel, automation)
dpg.add_menu_item(
label="1",
callback=self.default_time_callback,
user_data=input_channel,
)
dpg.add_menu_item(
label="x2",
callback=self.double_time_callback,
user_data=input_channel,
)
dpg.add_menu_item(
label="/2",
callback=self.half_time_callback,
user_data=input_channel,
)
def update_automation_length(sender, app_data, user_data):
if app_data:
input_channel = user_data
input_channel.active_automation.set_length(float(app_data))
self.reset_automation_plot(input_channel)
def update_preset_name(sender, app_data, user_data):
input_channel = user_data
automation = input_channel.active_automation
if automation is None:
return
automation.name = app_data
preset_sub_menu_tag = get_preset_sub_menu_tag(automation)
dpg.configure_item(preset_sub_menu_tag, label=app_data)
prop_x_start = 600
dpg.add_text("Preset:", pos=(prop_x_start - 200, 0))
dpg.add_input_text(
tag=f"{parent}.preset_name",
label="",
default_value="",
pos=(prop_x_start - 150, 0),
on_enter=True,
callback=update_preset_name,
user_data=input_channel,
width=100,
)
dpg.add_text("Beats:", pos=(prop_x_start + 200, 0))
dpg.add_input_text(
tag=f"{parent}.beats",
label="",
default_value=input_channel.active_automation.length,
pos=(prop_x_start + 230, 0),
on_enter=True,
callback=update_automation_length,
user_data=input_channel,
width=50,
)
with dpg.plot(
label=input_channel.active_automation.name,
height=-1,
width=-1,
tag=plot_tag,
query=True,
anti_aliased=True,
no_menus=True,
):
min_value = input_channel.get_parameter("min").value
max_value = input_channel.get_parameter("max").value
x_axis_limits_tag = f"{plot_tag}.x_axis_limits"
y_axis_limits_tag = f"{plot_tag}.y_axis_limits"
dpg.add_plot_axis(
dpg.mvXAxis, label="x", tag=x_axis_limits_tag, no_gridlines=True
)
dpg.set_axis_limits(
dpg.last_item(),
gui.AXIS_MARGIN,
input_channel.active_automation.length,
)
dpg.add_plot_axis(
dpg.mvYAxis, label="y", tag=y_axis_limits_tag, no_gridlines=True
)
dpg.set_axis_limits(dpg.last_item(), min_value, max_value)
dpg.add_line_series(
[],
[],
tag=series_tag,
parent=dpg.last_item(),
)
self.reset_automation_plot(input_channel)
dpg.add_line_series(
parent=x_axis_limits_tag,
label="Playhead",
tag=playhead_tag,
x=dpg.get_axis_limits(x_axis_limits_tag),
y=dpg.get_axis_limits(y_axis_limits_tag),
)
dpg.add_line_series(
parent=y_axis_limits_tag,
label="Ext Value",
tag=ext_value_tag,
x=dpg.get_axis_limits(x_axis_limits_tag),
y=dpg.get_axis_limits(y_axis_limits_tag),
)
with dpg.popup(plot_tag, mousebutton=1):
dpg.add_menu_item(
label="Double Automation",
callback=self.double_automation_callback,
)
dpg.add_menu_item(
label="Duplicate Preset",
callback=self.duplicate_channel_preset_callback,
)
with dpg.menu(label="Set Quantize"):
dpg.add_menu_item(
label="Off",
callback=self.set_quantize_callback,
user_data=None,
)
dpg.add_menu_item(
label="1 bar",
callback=self.set_quantize_callback,
user_data=4,
)
dpg.add_menu_item(
label="1/2",
callback=self.set_quantize_callback,
user_data=2,
)
dpg.add_menu_item(
label="1/4",
callback=self.set_quantize_callback,
user_data=1,
)
dpg.add_menu_item(
label="1/8",
callback=self.set_quantize_callback,
user_data=0.5,
)
dpg.add_menu_item(
label="1/16",
callback=self.set_quantize_callback,
user_data=0.25,
)
with dpg.menu(label="Shift (Beats)"):
with dpg.menu(label="Left"):
dpg.add_menu_item(
label="4",
callback=self.shift_points_callback,
user_data=-4,
)
dpg.add_menu_item(
label="2",
callback=self.shift_points_callback,
user_data=-2,
)
dpg.add_menu_item(
label="1",
callback=self.shift_points_callback,
user_data=-1,
)
dpg.add_menu_item(
label="1/2",
callback=self.shift_points_callback,
user_data=-0.5,
)
dpg.add_menu_item(
label="1/4",
callback=self.shift_points_callback,
user_data=-0.25,
)
with dpg.menu(label="Right"):
dpg.add_menu_item(
label="4",
callback=self.shift_points_callback,
user_data=4,
)
dpg.add_menu_item(
label="2",
callback=self.shift_points_callback,
user_data=2,
)
dpg.add_menu_item(
label="1",
callback=self.shift_points_callback,
user_data=1,
)
dpg.add_menu_item(
label="1/2",
callback=self.shift_points_callback,
user_data=0.5,
)
dpg.add_menu_item(
label="1/4",
callback=self.shift_points_callback,
user_data=0.25,
)
with dpg.menu(label="Interpolation Mode"):
dpg.add_menu_item(
label="Linear",
callback=self.set_interpolation_callback,
user_data="linear",
)
dpg.add_menu_item(
label="Nearest",
callback=self.set_interpolation_callback,
user_data="nearest",
)
dpg.add_menu_item(
label="Nearest Up",
callback=self.set_interpolation_callback,
user_data="nearest-up",
)
dpg.add_menu_item(
label="Zero",
callback=self.set_interpolation_callback,
user_data="zero",
)
dpg.add_menu_item(
label="S-Linear",
callback=self.set_interpolation_callback,
user_data="slinear",
)
dpg.add_menu_item(
label="Quadratic",
callback=self.set_interpolation_callback,
user_data="quadratic",
)
dpg.add_menu_item(
label="Cubic",
callback=self.set_interpolation_callback,
user_data="cubic",
)
dpg.add_menu_item(
label="Previous",
callback=self.set_interpolation_callback,
user_data="previous",
)
dpg.add_menu_item(
label="Next",
callback=self.set_interpolation_callback,
user_data="next",
)
dpg.bind_item_theme(playhead_tag, "playhead_line.theme")
dpg.bind_item_theme(ext_value_tag, "bg_line.theme")
dpg.bind_item_theme(series_tag, "automation_line.theme")
def show_popup(sender, app_data, user_data):
input_channel = user_data
popup_tag = f"{input_channel.id}.gui.popup"
# Right click
if app_data[0] == 1:
dpg.configure_item(item=popup_tag, show=True)
def create_input_channel_window(self, input_channel):
parent = get_source_node_window_tag(input_channel)
self.tags["hide_on_clip_selection"].append(parent)
input_type = input_channel.input_type
# ColorNode
if input_type == "color":
def update_color(sender, app_data, user_data):
# Color picker returns values between 0 and 1. Convert
# to 255 int value.
rgb = [int(util.clamp(v * 255, 0, 255)) for v in app_data]
self.update_channel_value_callback(sender, rgb, user_data)
width = 520
height = 520
with dpg.window(
tag=parent,
label="Automation Window",
width=width,
height=height,
pos=(799, 18),
show=False,
no_move=True,
no_title_bar=True,
):
default_color = input_channel.get()
node_theme = get_node_tag(input_channel) + ".theme"
with dpg.theme(tag=node_theme):
with dpg.theme_component(dpg.mvAll):
dpg.add_theme_color(
tag=f"{node_theme}.color1",
target=dpg.mvNodeCol_NodeBackground,
value=default_color,
category=dpg.mvThemeCat_Nodes,
)
dpg.add_theme_color(
tag=f"{node_theme}.color2",
target=dpg.mvNodeCol_NodeBackgroundHovered,
value=default_color,
category=dpg.mvThemeCat_Nodes,
)
dpg.add_theme_color(
tag=f"{node_theme}.color3",
target=dpg.mvNodeCol_NodeBackgroundSelected,
value=default_color,
category=dpg.mvThemeCat_Nodes,
)
dpg.add_theme_color(
tag=f"{node_theme}.row_bg",
target=dpg.mvThemeCol_Button,
value=default_color,
category=dpg.mvThemeCat_Core,
)
dpg.add_color_picker(
width=height * 0.8,
height=height,
callback=update_color,
user_data=input_channel,
default_value=default_color,
display_type=dpg.mvColorEdit_uint8,
)
# ButtonNode
elif input_type == "button":
width = 520
height = 520
with dpg.window(
tag=parent,
label="Automation Window",
width=width,
height=height,
pos=(799, 18),
show=False,
no_move=True,
no_title_bar=True,
):
pass
def add_automation_tab(self, input_channel, automation):
preset_menu_tag = f"{input_channel.id}.preset_menu"
preset_sub_menu_tag = get_preset_sub_menu_tag(automation)
with dpg.menu(
parent=preset_menu_tag, tag=preset_sub_menu_tag, label=automation.name
):
dpg.add_menu_item(
tag=f"{preset_sub_menu_tag}.activate",
label="Activate",
callback=self.select_automation_callback,
user_data=(input_channel, automation),
)
dpg.add_menu_item(
tag=f"{preset_sub_menu_tag}.duplicate",
label="Duplicate",
callback=self.duplicate_channel_preset_callback,
user_data=automation,
)
dpg.add_menu_item(
tag=f"{preset_sub_menu_tag}.delete",
label="Delete",
callback=self.delete_automation_callback,
user_data=(input_channel, automation),
)
def reset_automation_plot(self, input_channel):
if not isinstance(input_channel, model.AutomatableSourceNode):
return
window_tag = get_source_node_window_tag(input_channel)
automation = input_channel.active_automation
plot_tag = get_plot_tag(input_channel)
x_axis_limits_tag = f"{plot_tag}.x_axis_limits"
y_axis_limits_tag = f"{plot_tag}.y_axis_limits"
dpg.configure_item(plot_tag, label=input_channel.active_automation.name)
dpg.set_axis_limits(
x_axis_limits_tag,
-gui.AXIS_MARGIN,
input_channel.active_automation.length + gui.AXIS_MARGIN,
)
min_value = input_channel.get_parameter("min").value
max_value = input_channel.get_parameter("max").value
y_axis_limits_tag = f"{plot_tag}.y_axis_limits"
dpg.set_axis_limits(y_axis_limits_tag, min_value, max_value)
dpg.set_value(f"{window_tag}.beats", value=automation.length)
dpg.set_value(f"{window_tag}.preset_name", value=automation.name)
# Always delete and redraw all the points
for tag in self.tags["point_tags"]:
dpg.delete_item(tag)
self.tags["point_tags"].clear()
for point in automation.points:
if point.deleted:
continue
point_tag = f"{point.id}.gui.point"
x, y = point.x, point.y
dpg.add_drag_point(
color=[0, 255, 255, 255],
default_value=[x, y],
callback=self.update_automation_point_callback,
parent=plot_tag,
tag=point_tag,
user_data=(automation, point),
thickness=1,
)
self.tags["point_tags"].append(point_tag)
# Add quantization bars
y_limits = dpg.get_axis_limits(y_axis_limits_tag)
if self._quantize_amount is not None:
i = 0
while True:
tag = f"gui.quantization_series.{i}"
if dpg.does_item_exist(tag):
dpg.delete_item(tag)
else:
break
i += 1
n_bars = int(input_channel.active_automation.length / self._quantize_amount)