forked from zynthian/zynthian-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zynthian_gui.py
executable file
·1858 lines (1445 loc) · 52.2 KB
/
zynthian_gui.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
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#******************************************************************************
# ZYNTHIAN PROJECT: Zynthian GUI
#
# Main Class and Program for Zynthian GUI
#
# Copyright (C) 2015-2016 Fernando Moyano <[email protected]>
#
#******************************************************************************
#
# This program 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 2 of
# the License, or any later version.
#
# This program 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.
#
# For a full copy of the GNU General Public License see the LICENSE.txt file.
#
#******************************************************************************
import os
import sys
import copy
import liblo
import signal
#import psutil
#import alsaseq
import logging
import threading
from time import sleep
from os.path import isfile
from datetime import datetime
from threading import Thread, Lock
from subprocess import check_output
from ctypes import c_float, c_double, CDLL
# Zynthian specific modules
import zynconf
import zynautoconnect
from zynlibs.jackpeak import lib_jackpeak, lib_jackpeak_init
from zyncoder import *
from zyncoder.zyncoder import lib_zyncoder, lib_zyncoder_init
from zyngine import zynthian_zcmidi
from zyngine import zynthian_midi_filter
#from zyngine import zynthian_engine_transport
from zyngui import zynthian_gui_config
from zyngui.zynthian_gui_controller import zynthian_gui_controller
from zyngui.zynthian_gui_selector import zynthian_gui_selector
from zyngui.zynthian_gui_info import zynthian_gui_info
from zyngui.zynthian_gui_option import zynthian_gui_option
from zyngui.zynthian_gui_admin import zynthian_gui_admin
from zyngui.zynthian_gui_snapshot import zynthian_gui_snapshot
from zyngui.zynthian_gui_layer import zynthian_gui_layer
from zyngui.zynthian_gui_layer_options import zynthian_gui_layer_options
from zyngui.zynthian_gui_engine import zynthian_gui_engine
from zyngui.zynthian_gui_midi_chan import zynthian_gui_midi_chan
from zyngui.zynthian_gui_midi_cc import zynthian_gui_midi_cc
from zyngui.zynthian_gui_midi_key_range import zynthian_gui_midi_key_range
from zyngui.zynthian_gui_audio_out import zynthian_gui_audio_out
from zyngui.zynthian_gui_midi_out import zynthian_gui_midi_out
from zyngui.zynthian_gui_audio_in import zynthian_gui_audio_in
from zyngui.zynthian_gui_bank import zynthian_gui_bank
from zyngui.zynthian_gui_preset import zynthian_gui_preset
from zyngui.zynthian_gui_control import zynthian_gui_control
from zyngui.zynthian_gui_control_xy import zynthian_gui_control_xy
from zyngui.zynthian_gui_midi_profile import zynthian_gui_midi_profile
from zyngui.zynthian_gui_zs3_learn import zynthian_gui_zs3_learn
from zyngui.zynthian_gui_zs3_options import zynthian_gui_zs3_options
from zyngui.zynthian_gui_confirm import zynthian_gui_confirm
from zyngui.zynthian_gui_keyboard import zynthian_gui_keyboard
from zyngui.zynthian_gui_keybinding import zynthian_gui_keybinding
from zyngui.zynthian_gui_main import zynthian_gui_main
from zyngui.zynthian_gui_audio_recorder import zynthian_gui_audio_recorder
from zyngui.zynthian_gui_midi_recorder import zynthian_gui_midi_recorder
if "autoeq" in zynthian_gui_config.experimental_features:
from zyngui.zynthian_gui_autoeq import zynthian_gui_autoeq
if "zynseq" in zynthian_gui_config.experimental_features:
from zyngui.zynthian_gui_stepsequencer import zynthian_gui_stepsequencer
from zyngui.zynthian_gui_touchscreen_calibration import zynthian_gui_touchscreen_calibration
#from zyngui.zynthian_gui_control_osc_browser import zynthian_gui_osc_browser
#-------------------------------------------------------------------------------
# Zynthian Main GUI Class
#-------------------------------------------------------------------------------
class zynthian_gui:
screens_sequence = ("main","layer","bank","preset","control")
note2cuia = {
"0": "POWER_OFF",
"1": "REBOOT",
"2": "RESTART_UI",
"3": "RELOAD_MIDI_CONFIG",
"4": "RELOAD_KEY_BINDING",
"5": "LAST_STATE_ACTION",
"10": "ALL_NOTES_OFF",
"11": "ALL_SOUNDS_OFF",
"12": "ALL_OFF",
"23": "TOGGLE_AUDIO_RECORD",
"24": "START_AUDIO_RECORD",
"25": "STOP_AUDIO_RECORD",
"26": "TOGGLE_AUDIO_PLAY",
"27": "START_AUDIO_PLAY",
"28": "STOP_AUDIO_PLAY",
"35": "TOGGLE_MIDI_RECORD",
"36": "START_MIDI_RECORD",
"37": "STOP_MIDI_RECORD",
"38": "TOGGLE_MIDI_PLAY",
"39": "START_MIDI_PLAY",
"40": "STOP_MIDI_PLAY",
"51": "SELECT",
"52": "SELECT_UP",
"53": "SELECT_DOWN",
"54": "BACK_UP",
"55": "BACK_DOWN",
"56": "LAYER_UP",
"57": "LAYER_DOWN",
"58": "SNAPSHOT_UP",
"59": "SNAPSHOT_DOWN",
"64": "SWITCH_BACK_SHORT",
"63": "SWITCH_BACK_BOLD",
"62": "SWITCH_BACK_LONG",
"65": "SWITCH_SELECT_SHORT",
"66": "SWITCH_SELECT_BOLD",
"67": "SWITCH_SELECT_LONG",
"60": "SWITCH_LAYER_SHORT",
"61": "SWITCH_LAYER_BOLD",
"68": "SWITCH_LAYER_LONG",
"71": "SWITCH_SNAPSHOT_SHORT",
"72": "SWITCH_SNAPSHOT_BOLD",
"73": "SWITCH_SNAPSHOT_LONG",
"80": "SCREEN_ADMIN",
"81": "SCREEN_LAYER",
"82": "SCREEN_BANK",
"83": "SCREEN_PRESET",
"84": "SCREEN_CONTROL",
"90": "MODAL_SNAPSHOT_LOAD",
"91": "MODAL_SNAPSHOT_SAVE",
"92": "MODAL_AUDIO_RECORDER",
"93": "MODAL_MIDI_RECORDER",
"94": "MODAL_ALSA_MIXER",
"95": "MODAL_STEPSEQ"
}
def __init__(self):
self.zynmidi = None
self.screens = {}
self.active_screen = None
self.modal_screen = None
self.modal_screen_back = None
self.modal_timer_id = None
self.curlayer = None
self._curlayer = None
self.dtsw = []
self.polling = False
self.loading = 0
self.loading_thread = None
self.zyncoder_thread = None
self.zynread_wait_flag = False
self.zynswitch_defered_event = None
self.exit_flag = False
self.exit_code = 0
self.midi_filter_script = None;
self.midi_learn_mode = False
self.midi_learn_zctrl = None
self.status_info = {}
self.status_counter = 0
self.zynautoconnect_audio_flag = False
self.zynautoconnect_midi_flag = False
# Create Lock object to avoid concurrence problems
self.lock = Lock()
# Load keyboard binding map
zynthian_gui_keybinding.getInstance().load()
# Get Jackd Options
self.jackd_options = zynconf.get_jackd_options()
# Initialize peakmeter audio monitor if needed
if not zynthian_gui_config.show_cpu_status:
try:
global lib_jackpeak
lib_jackpeak = lib_jackpeak_init()
lib_jackpeak.setDecay(c_float(0.2))
lib_jackpeak.setHoldCount(10)
except Exception as e:
logging.error("ERROR initializing jackpeak: %s" % e)
# Initialize Controllers (Rotary & Switches) & MIDI-router
try:
global lib_zyncoder
#Init Zyncoder Library
lib_zyncoder_init()
lib_zyncoder=zyncoder.get_lib_zyncoder()
self.zynmidi=zynthian_zcmidi()
#Init Switches
self.zynswitches_init()
self.zynswitches_midi_setup()
except Exception as e:
logging.error("ERROR initializing Controllers & MIDI-router: %s" % e)
if "zynseq" in zynthian_gui_config.experimental_features:
self.libseq = CDLL("/zynthian/zynthian-ui/zynlibs/zynseq/build/libzynseq.so")
self.libseq.init(True)
# ---------------------------------------------------------------------------
# MIDI Router Init & Config
# ---------------------------------------------------------------------------
def init_midi(self):
try:
global lib_zyncoder
#Set Global Tuning
self.fine_tuning_freq = zynthian_gui_config.midi_fine_tuning
lib_zyncoder.set_midi_filter_tuning_freq(c_double(self.fine_tuning_freq))
#Set MIDI Master Channel
lib_zyncoder.set_midi_master_chan(zynthian_gui_config.master_midi_channel)
#Set MIDI CC automode
lib_zyncoder.set_midi_ctrl_automode(zynthian_gui_config.midi_cc_automode)
#Setup MIDI filter rules
if self.midi_filter_script:
self.midi_filter_script.clean()
self.midi_filter_script = zynthian_midi_filter.MidiFilterScript(zynthian_gui_config.midi_filter_rules)
except Exception as e:
logging.error("ERROR initializing MIDI : %s" % e)
def init_midi_services(self):
#Start/Stop MIDI aux. services
self.screens['admin'].default_rtpmidi()
self.screens['admin'].default_qmidinet()
self.screens['admin'].default_touchosc()
self.screens['admin'].default_aubionotes()
def reload_midi_config(self):
zynconf.load_config()
midi_profile_fpath=zynconf.get_midi_config_fpath()
if midi_profile_fpath:
zynconf.load_config(True,midi_profile_fpath)
zynthian_gui_config.set_midi_config()
self.init_midi()
self.init_midi_services()
self.zynautoconnect()
# ---------------------------------------------------------------------------
# OSC Management
# ---------------------------------------------------------------------------
def osc_init(self, port=1370, proto=liblo.UDP):
try:
self.osc_server=liblo.Server(port,proto)
self.osc_server_port=self.osc_server.get_port()
self.osc_server_url=liblo.Address('localhost',self.osc_server_port,proto).get_url()
logging.info("ZYNTHIAN-UI OSC server running in port {}".format(self.osc_server_port))
self.osc_server.add_method(None, None, self.osc_cb_all)
#self.osc_server.start()
#except liblo.AddressError as err:
except Exception as err:
logging.error("ZYNTHIAN-UI OSC Server can't be started: {}".format(err))
def osc_end(self):
if self.osc_server:
try:
#self.osc_server.stop()
logging.info("ZYNTHIAN-UI OSC server stopped")
except Exception as err:
logging.error("Can't stop ZYNTHIAN-UI OSC server => %s" % err)
def osc_receive(self):
while self.osc_server.recv(0):
pass
#@liblo.make_method("RELOAD_MIDI_CONFIG", None)
#@liblo.make_method(None, None)
def osc_cb_all(self, path, args, types, src):
logging.info("OSC MESSAGE '%s' from '%s'" % (path, src.url))
parts = path.split("/", 2)
if parts[0]=="" and parts[1].upper()=="CUIA":
#Execute action
self.callable_ui_action(parts[2].upper(), args)
#Run autoconnect if needed
self.zynautoconnect_do()
else:
logging.warning("Not supported OSC call '{}'".format(path))
#for a, t in zip(args, types):
# logging.debug("argument of type '%s': %s" % (t, a))
# ---------------------------------------------------------------------------
# GUI Core Management
# ---------------------------------------------------------------------------
def start(self):
# Initialize jack Transport
#self.zyntransport = zynthian_engine_transport()
# Create Core UI Screens
self.screens['info'] = zynthian_gui_info()
self.screens['confirm'] = zynthian_gui_confirm()
self.screens['keyboard'] = zynthian_gui_keyboard()
self.screens['option'] = zynthian_gui_option()
self.screens['engine'] = zynthian_gui_engine()
self.screens['layer'] = zynthian_gui_layer()
self.screens['layer_options'] = zynthian_gui_layer_options()
self.screens['snapshot'] = zynthian_gui_snapshot()
self.screens['midi_chan'] = zynthian_gui_midi_chan()
self.screens['midi_cc'] = zynthian_gui_midi_cc()
self.screens['midi_key_range'] = zynthian_gui_midi_key_range()
self.screens['audio_out'] = zynthian_gui_audio_out()
self.screens['midi_out'] = zynthian_gui_midi_out()
self.screens['audio_in'] = zynthian_gui_audio_in()
self.screens['bank'] = zynthian_gui_bank()
self.screens['preset'] = zynthian_gui_preset()
self.screens['control'] = zynthian_gui_control()
self.screens['control_xy'] = zynthian_gui_control_xy()
self.screens['midi_profile'] = zynthian_gui_midi_profile()
self.screens['zs3_learn'] = zynthian_gui_zs3_learn()
self.screens['zs3_options'] = zynthian_gui_zs3_options()
self.screens['main'] = zynthian_gui_main()
self.screens['admin'] = zynthian_gui_admin()
self.screens['touchscreen_calibration'] = zynthian_gui_touchscreen_calibration()
# Create UI Apps Screens
self.screens['alsa_mixer'] = self.screens['control']
self.screens['audio_recorder'] = zynthian_gui_audio_recorder()
self.screens['midi_recorder'] = zynthian_gui_midi_recorder()
if "autoeq" in zynthian_gui_config.experimental_features:
self.screens['autoeq'] = zynthian_gui_autoeq()
if "zynseq" in zynthian_gui_config.experimental_features:
self.screens['stepseq'] = zynthian_gui_stepsequencer()
# Init Auto-connector
zynautoconnect.start()
# Initialize OSC
self.osc_init()
# Initial snapshot...
snapshot_loaded=False
# Try to load "last_state" snapshot ...
if zynthian_gui_config.restore_last_state:
snapshot_loaded=self.screens['snapshot'].load_last_state_snapshot()
# Try to load "default" snapshot ...
if not snapshot_loaded:
snapshot_loaded=self.screens['snapshot'].load_default_snapshot()
# Set empty state
if not snapshot_loaded:
# Init MIDI Subsystem => MIDI Profile
self.init_midi()
self.init_midi_services()
self.zynautoconnect()
# Show initial screen
self.show_screen('main')
# Start polling threads
self.start_polling()
self.start_loading_thread()
self.start_zyncoder_thread()
# Run autoconnect if needed
self.zynautoconnect_do()
# Initialize MPE Zones
#self.init_mpe_zones(0, 2)
def stop(self):
logging.info("STOPPING ZYNTHIAN-UI ...")
self.stop_polling()
self.osc_end()
zynautoconnect.stop()
self.screens['layer'].reset()
self.screens['midi_recorder'].stop_playing() # Need to stop timing thread
#self.zyntransport.stop()
def hide_screens(self, exclude=None):
if not exclude:
exclude = self.active_screen
exclude_obj = self.screens[exclude]
for screen_name, screen_obj in self.screens.items():
if screen_obj!=exclude_obj:
screen_obj.hide()
def show_screen(self, screen=None):
if screen is None:
if self.active_screen:
screen = self.active_screen
else:
screen = "main"
if screen=="control":
self.restore_curlayer()
self.lock.acquire()
self.hide_screens(exclude=screen)
self.screens[screen].show()
self.active_screen = screen
self.modal_screen = None
self.modal_screen_back = None
self.lock.release()
def show_active_screen(self):
self.show_screen()
def show_modal(self, screen, mode=None):
if screen=="alsa_mixer":
if self.modal_screen!=screen and self.screens['layer'].amixer_layer:
self._curlayer = self.curlayer
self.screens['layer'].amixer_layer.refresh_controllers()
self.set_curlayer(self.screens['layer'].amixer_layer)
else:
return
elif screen=="snapshot":
if mode is None:
mode = "LOAD"
self.screens['snapshot'].set_action(mode)
if self.modal_screen!=screen and self.modal_screen not in ("info","confirm"):
self.modal_screen_back = self.modal_screen
self.modal_screen=screen
self.screens[screen].show()
self.hide_screens(exclude=screen)
def close_modal(self):
self.cancel_modal_timer()
if self.modal_screen_back:
self.show_modal(self.modal_screen_back)
self.modal_screen_back = None
else:
self.show_screen()
def close_modal_timer(self, tms=3000):
self.cancel_modal_timer()
self.modal_timer_id = zynthian_gui_config.top.after(tms, self.close_modal)
def cancel_modal_timer(self):
if self.modal_timer_id:
zynthian_gui_config.top.after_cancel(self.modal_timer_id)
self.modal_timer_id = None
def toggle_modal(self, screen, mode=None):
if self.modal_screen!=screen:
self.show_modal(screen, mode)
else:
self.close_modal()
def refresh_screen(self):
screen = self.active_screen
if screen=='preset' and len(self.curlayer.preset_list)<=1:
screen='control'
self.show_screen(screen)
def get_current_screen(self):
if self.modal_screen:
return self.screens[self.modal_screen]
else:
return self.screens[self.active_screen]
def show_confirm(self, text, callback=None, cb_params=None):
self.modal_screen_back = self.modal_screen
self.modal_screen='confirm'
self.screens['confirm'].show(text, callback, cb_params)
self.hide_screens(exclude='confirm')
def show_keyboard(self, callback, text="", max_chars=None):
self.modal_screen_back = self.modal_screen
self.modal_screen="keyboard"
self.screens['keyboard'].show(callback, text, max_chars)
self.hide_screens(exclude='keyboard')
def show_info(self, text, tms=None):
self.modal_screen_back = self.modal_screen
self.modal_screen = 'info'
self.screens['info'].show(text)
self.hide_screens(exclude='info')
if tms:
zynthian_gui_config.top.after(tms, self.hide_info)
def add_info(self, text, tags=None):
self.screens['info'].add(text,tags)
def hide_info(self):
if self.modal_screen=='info':
self.close_modal()
def hide_info_timer(self, tms=3000):
if self.modal_screen=='info':
self.cancel_info_timer()
self.modal_timer_id = zynthian_gui_config.top.after(tms, self.hide_info)
def cancel_info_timer(self):
self.cancel_modal_timer()
def calibrate_touchscreen(self):
self.show_modal('touchscreen_calibration')
def load_snapshot(self):
self.show_modal("snapshot","LOAD")
def save_snapshot(self):
self.show_modal("snapshot","SAVE")
def layer_control(self, layer=None):
modal = False
if layer is not None:
if layer in self.screens['layer'].root_layers:
self._curlayer = None
else:
modal = True
self._curlayer = self.curlayer
self.set_curlayer(layer)
if self.curlayer:
# If there is a preset selection for the active layer ...
if self.curlayer.get_preset_name():
self.show_screen('control')
else:
if modal:
self.show_modal('bank')
else:
self.show_screen('bank')
# If there is only one bank, jump to preset selection
if len(self.curlayer.bank_list)<=1:
self.screens['bank'].select_action(0)
def show_control(self):
self.restore_curlayer()
self.layer_control()
def enter_midi_learn_mode(self):
self.midi_learn_mode = True
self.midi_learn_zctrl = None
lib_zyncoder.set_midi_learning_mode(1)
self.screens['control'].refresh_midi_bind()
self.screens['control'].set_select_path()
#self.show_modal('zs3_learn')
def exit_midi_learn_mode(self):
self.midi_learn_mode = False
self.midi_learn_zctrl = None
lib_zyncoder.set_midi_learning_mode(0)
self.screens['control'].refresh_midi_bind()
self.screens['control'].set_select_path()
self.show_active_screen()
def show_control_xy(self, xctrl, yctrl):
self.modal_screen='control_xy'
self.screens['control_xy'].set_controllers(xctrl, yctrl)
self.screens['control_xy'].show()
self.hide_screens(exclude='control_xy')
self.active_screen='control'
self.screens['control'].set_mode_control()
logging.debug("SHOW CONTROL-XY => %s, %s" % (xctrl.symbol, yctrl.symbol))
def set_curlayer(self, layer, save=False):
if layer is not None:
if save:
self._curlayer = self.curlayer
self.curlayer = layer
self.screens['bank'].fill_list()
self.screens['preset'].fill_list()
self.screens['control'].fill_list()
self.set_active_channel()
else:
self.curlayer = None
def restore_curlayer(self):
if self._curlayer:
self.set_curlayer(self._curlayer)
self._curlayer = None
#If "MIDI Single Active Channel" mode is enabled, set MIDI Active Channel to layer's one
def set_active_channel(self):
curlayer_chan = None
active_chan = -1
if self.curlayer:
# Don't change nothing for MIXER
if self.curlayer.engine.nickname=='MX':
return
curlayer_chan = self.curlayer.get_midi_chan()
if curlayer_chan is not None and zynthian_gui_config.midi_single_active_channel:
active_chan = curlayer_chan
cur_active_chan = lib_zyncoder.get_midi_active_chan()
if cur_active_chan==active_chan:
return
else:
logging.debug("ACTIVE CHAN: {} => {}".format(cur_active_chan, active_chan))
#if cur_active_chan>=0:
# self.all_notes_off_chan(cur_active_chan)
lib_zyncoder.set_midi_active_chan(active_chan)
self.zynswitches_midi_setup(curlayer_chan)
def get_curlayer_wait(self):
#Try until layer is ready
for j in range(100):
if self.curlayer:
return self.curlayer
else:
sleep(0.1)
def is_single_active_channel(self):
return zynthian_gui_config.midi_single_active_channel
# -------------------------------------------------------------------
# Callable UI Actions
# -------------------------------------------------------------------
def callable_ui_action(self, cuia, params=None):
logging.debug("CUIA '{}' => {}".format(cuia,params))
if cuia == "POWER_OFF":
self.screens['admin'].power_off_confirmed()
elif cuia == "REBOOT":
self.screens['admin'].reboot_confirmed()
elif cuia == "RESTART_UI":
self.screens['admin'].restart_gui()
elif cuia == "RELOAD_MIDI_CONFIG":
self.reload_midi_config()
elif cuia == "RELOAD_KEY_BINDING":
zynthian_gui_keybinding.getInstance().load()
elif cuia == "LAST_STATE_ACTION":
self.screens['admin'].last_state_action()
elif cuia == "ALL_NOTES_OFF":
self.all_notes_off()
sleep(0.1)
self.raw_all_notes_off()
elif cuia == "ALL_SOUNDS_OFF" or cuia == "ALL_OFF":
self.all_notes_off()
self.all_sounds_off()
sleep(0.1)
self.raw_all_notes_off()
elif cuia == "START_AUDIO_RECORD":
self.screens['audio_recorder'].start_recording()
elif cuia == "STOP_AUDIO_RECORD":
self.screens['audio_recorder'].stop_recording()
elif cuia == "TOGGLE_AUDIO_RECORD":
self.screens['audio_recorder'].toggle_recording()
elif cuia == "START_AUDIO_PLAY":
self.screens['audio_recorder'].start_playing()
elif cuia == "STOP_AUDIO_PLAY":
self.screens['audio_recorder'].stop_playing()
elif cuia == "TOGGLE_AUDIO_PLAY":
self.screens['audio_recorder'].toggle_playing()
elif cuia == "START_MIDI_RECORD":
self.screens['midi_recorder'].start_recording()
elif cuia == "STOP_MIDI_RECORD":
self.screens['midi_recorder'].stop_recording()
elif cuia == "TOGGLE_MIDI_RECORD":
self.screens['midi_recorder'].toggle_recording()
elif cuia == "START_MIDI_PLAY":
self.screens['midi_recorder'].start_playing()
elif cuia == "STOP_MIDI_PLAY":
self.screens['midi_recorder'].stop_playing()
elif cuia == "TOGGLE_MIDI_PLAY":
self.screens['midi_recorder'].toggle_playing()
elif cuia == "SELECT":
try:
self.get_current_screen().select(params[0])
except:
pass
elif cuia == "SELECT_UP":
try:
self.get_current_screen().select_up()
except:
pass
elif cuia == "SELECT_DOWN":
try:
self.get_current_screen().select_down()
except:
pass
elif cuia == "BACK_UP":
try:
self.get_current_screen().back_up()
except:
pass
elif cuia == "BACK_DOWN":
try:
self.get_current_screen().back_down()
except:
pass
elif cuia == "LAYER_UP":
try:
self.get_current_screen().layer_up()
except:
pass
elif cuia == "LAYER_DOWN":
try:
self.get_current_screen().layer_down()
except:
pass
elif cuia == "SNAPSHOT_UP":
try:
self.get_current_screen().snapshot_up()
except:
pass
elif cuia == "SNAPSHOT_DOWN":
try:
self.get_current_screen().snapshot_down()
except:
pass
elif cuia == "SWITCH_LAYER_SHORT":
self.zynswitch_short(0)
elif cuia == "SWITCH_LAYER_BOLD":
self.zynswitch_bold(0)
elif cuia == "SWITCH_LAYER_LONG":
self.zynswitch_long(0)
elif cuia == "SWITCH_BACK_SHORT":
self.zynswitch_short(1)
elif cuia == "SWITCH_BACK_BOLD":
self.zynswitch_bold(1)
elif cuia == "SWITCH_BACK_LONG":
self.zynswitch_long(1)
elif cuia == "SWITCH_SNAPSHOT_SHORT":
self.zynswitch_short(2)
elif cuia == "SWITCH_SNAPSHOT_BOLD":
self.zynswitch_bold(2)
elif cuia == "SWITCH_SNAPSHOT_LONG":
self.zynswitch_long(2)
elif cuia == "SWITCH_SELECT_SHORT":
self.zynswitch_short(3)
elif cuia == "SWITCH_SELECT_BOLD":
self.zynswitch_bold(3)
elif cuia == "SWITCH_SELECT_LONG":
self.zynswitch_long(3)
elif cuia == "SCREEN_ADMIN":
self.show_screen("admin")
elif cuia == "SCREEN_LAYER":
self.show_screen("layer")
elif cuia == "SCREEN_BANK":
self.show_screen("bank")
elif cuia == "SCREEN_PRESET":
self.show_screen("preset")
elif cuia == "SCREEN_CONTROL":
self.show_screen("control")
elif cuia == "MODAL_SNAPSHOT_LOAD":
self.toggle_modal("snapshot", "LOAD")
elif cuia == "MODAL_SNAPSHOT_SAVE":
self.toggle_modal("snapshot", "SAVE")
elif cuia == "MODAL_AUDIO_RECORDER":
self.toggle_modal("audio_recorder")
elif cuia == "MODAL_MIDI_RECORDER":
self.toggle_modal("midi_recorder")
elif cuia == "MODAL_ALSA_MIXER":
self.toggle_modal("alsa_mixer")
elif cuia == "MODAL_STEPSEQ" and "zynseq" in zynthian_gui_config.experimental_features:
self.toggle_modal("stepseq")
def custom_switch_ui_action(self, i, t):
try:
if t in zynthian_gui_config.custom_switch_ui_actions[i]:
self.callable_ui_action(zynthian_gui_config.custom_switch_ui_actions[i][t])
except Exception as e:
logging.warning(e)
# -------------------------------------------------------------------
# Switches
# -------------------------------------------------------------------
# Init GPIO Switches
def zynswitches_init(self):
if lib_zyncoder:
ts=datetime.now()
logging.info("SWITCHES INIT...")
for i,pin in enumerate(zynthian_gui_config.zynswitch_pin):
self.dtsw.append(ts)
lib_zyncoder.setup_zynswitch(i,pin)
logging.info("SETUP ZYNSWITCH {} => wpGPIO {}".format(i, pin))
def zynswitches_midi_setup(self, curlayer_chan=None):
logging.info("MIDI SWITCHES SETUP...")
# Configure Custom Switches
for i in range(0, zynthian_gui_config.n_custom_switches):
swi = 4 + i
event = zynthian_gui_config.custom_switch_midi_events[i]
if event is not None:
if event['chan'] is not None:
midi_chan = event['chan']
else:
midi_chan = curlayer_chan
if midi_chan is not None:
lib_zyncoder.setup_zynswitch_midi(swi, event['type'], midi_chan, event['num'])
logging.info("MIDI ZYNSWITCH {}: {} CH#{}, {}".format(swi, event['type'], midi_chan, event['num']))
else:
lib_zyncoder.setup_zynswitch_midi(swi, 0, 0, 0)
logging.info("MIDI ZYNSWITCH {}: DISABLED!".format(swi))
# Configure Zynaptik Analog Inputs (CV-IN)
for i, event in enumerate(zynthian_gui_config.zynaptik_ad_midi_events):
if event is not None:
if event['chan'] is not None:
midi_chan = event['chan']
else:
midi_chan = curlayer_chan
if midi_chan is not None:
lib_zyncoder.setup_zynaptik_cvin(i, event['type'], midi_chan, event['num'])
logging.info("ZYNAPTIK CV-IN {}: {} CH#{}, {}".format(i, event['type'], midi_chan, event['num']))
else:
lib_zyncoder.disable_zynaptik_cvin(i)
logging.info("ZYNAPTIK CV-IN {}: DISABLED!".format(i))
# Configure Zyntof Inputs (Distance Sensor)
for i, event in enumerate(zynthian_gui_config.zyntof_midi_events):
if event is not None:
if event['chan'] is not None:
midi_chan = event['chan']
else:
midi_chan = curlayer_chan
if midi_chan is not None:
lib_zyncoder.setup_zyntof(i, event['type'], midi_chan, event['num'])
logging.info("ZYNTOF {}: {} CH#{}, {}".format(i, event['type'], midi_chan, event['num']))
else:
lib_zyncoder.disable_zyntof(i)
logging.info("ZYNTOF {}: DISABLED!".format(i))
def zynswitches(self):
if lib_zyncoder:
for i in range(len(zynthian_gui_config.zynswitch_pin)):
dtus=lib_zyncoder.get_zynswitch_dtus(i, zynthian_gui_config.zynswitch_long_us)
if dtus>zynthian_gui_config.zynswitch_long_us:
self.zynswitch_long(i)
return
if dtus>zynthian_gui_config.zynswitch_bold_us:
# Double switches must be bold!!! => by now ...
if self.zynswitch_double(i):
return
self.zynswitch_bold(i)
return
if dtus>0:
#print("Switch "+str(i)+" dtus="+str(dtus))
self.zynswitch_short(i)
def zynswitch_long(self,i):
logging.info('Looooooooong Switch '+str(i))
self.start_loading()
# Standard 4 ZynSwitches
if i==0 and "zynseq" in zynthian_gui_config.experimental_features:
self.toggle_modal("stepseq")
elif i==1:
#self.callable_ui_action("ALL_OFF")
self.show_modal("admin")
elif i==2:
self.show_modal("alsa_mixer")
elif i==3:
self.screens['admin'].power_off()
# Custom ZynSwitches
elif i>=4:
self.custom_switch_ui_action(i-4, "L")
self.stop_loading()
def zynswitch_bold(self,i):
logging.info('Bold Switch '+str(i))
self.start_loading()
if self.modal_screen in ['stepseq', 'keyboard']:
self.stop_loading()
if self.screens[self.modal_screen].switch(i, 'B'):
return
# Standard 4 ZynSwitches
if i==0:
if self.active_screen=='layer' and self.modal_screen!='stepseq':
self.show_modal('stepseq')
else:
if self.active_screen=='preset':
self.screens['preset'].restore_preset()
self.show_screen('layer')
elif i==1:
if self.modal_screen: