def __init__(self): self.zynmidi = None self.screens = {} self.active_screen = None self.modal_screen = 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)
def do_reset(self): try: zynthian_gui_keybinding.getInstance().reset_config() zynthian_gui_keybinding.getInstance().save() self.reload_key_binding_flag = True except Exception as e: logging.error("Resetting keyboard binding to defaults failed: {}".format(e)) return format(e)
def get(self, errors=None): if self.reload_key_binding_flag: self.reload_key_binding() zynthian_gui_keybinding.getInstance().load() config=OrderedDict([]) config['UI_KEYBINDING_MAP'] = zynthian_gui_keybinding.getInstance().config['map'] config['UI_KEYBINDING_ENABLED'] = zynthian_gui_keybinding.getInstance().isEnabled() super().get("ui_keybind.html", "Keyboard Binding", config, errors)
def update_map_entry(self, param, value): action, param = param.split(':') try: if param == "keysym": logging.debug("Update binding for {}: {}".format(action, value)) zynthian_gui_keybinding.getInstance().set_binding_keysym(action, value) else: logging.debug("Add modifier for {}: {}".format(action, param)) zynthian_gui_keybinding.getInstance().add_binding_modifier(action, param) except Exception as e: logging.error("Failed to set binding for {}: {}".format(action, e))
def cb_keybinding(self, event): logging.debug("Key press {} {}".format(event.keycode, event.keysym)) if not zynthian_gui_keybinding.getInstance().isEnabled(): logging.debug("Key binding is disabled - ignoring key press") return # Ignore TAB key (for now) to avoid confusing widget focus change if event.keysym == "Tab": return # Space is not recognised as keysym so need to convert keycode if event.keycode == 65: keysym = "Space" else: keysym = event.keysym action = zynthian_gui_keybinding.getInstance().get_key_action( keysym, event.state) if action != None: self.zyngui.callable_ui_action(action)
def do_save(self): try: data = tornado.escape.recursive_unicode(self.request.arguments) enable = False zynthian_gui_keybinding.getInstance().reset_modifiers() for key, value in data.items(): try: if key == "enable_keybinding": logging.debug("Key-binding enabled!") enable = True else: logging.debug("Map Action '{}' => {}".format( key, value[0])) self.update_map_entry(key, value[0]) except Exception as e: pass zynthian_gui_keybinding.getInstance().enable(enable) zynthian_gui_keybinding.getInstance().save() self.reload_key_binding_flag = True except Exception as e: logging.error("Saving keyboard binding failed: {}".format(e)) return format(e)
def callable_ui_action(self, cuia, params=None): 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 == "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 == "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)
def callable_ui_action(self, cuia, params=None): 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 == "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_PRESET": self.show_screen("preset") 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": self.toggle_modal("stepseq")