From 41422f3ba2baec71ea85e90e7e357f2a7a3b2267 Mon Sep 17 00:00:00 2001 From: Eldin Zenderink Date: Sat, 7 Sep 2024 21:36:47 +0200 Subject: [PATCH] v0.0.4 - Fix issue where mapping to insert key frame would stop mapping to selection groups to work --- MidiControl.py | 71 +++++++++++++++++++++++++------------------------- __init__.py | 12 ++++----- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/MidiControl.py b/MidiControl.py index 6be863b..dfad9ef 100644 --- a/MidiControl.py +++ b/MidiControl.py @@ -65,14 +65,14 @@ class ControllerButtonBindingState: # Controller to register keyframe(s) (note: all properties) key_frame_control = None - bind_control_state = ControllerButtonBindingState.NONE - button_velocity_pressed = 0 + key_frame_bind_control_state = ControllerButtonBindingState.NONE + keyframe_insert_button_velocity_pressed = 0 # Selection group buttons bound selection_to_map = None - bind_selection_state = ControllerButtonBindingState.NONE + select_group_bind_selection_state = ControllerButtonBindingState.NONE controller_selection_mapping = {} - button_velocity_pressed = 0 + select_group_button_velocity_pressed = 0 # Frame position update controllers_to_set_frame = { @@ -211,6 +211,7 @@ def obj_prop_change_update(self): new_obj['value'] = getattr(obj, prop) self.current_object_data[f"{prop}"] = copy.copy( new_obj) + self.mapping_error = None else: self.mapping_error = f"Failed parsing properties, too many!" @@ -273,6 +274,7 @@ def obj_prop_change_update(self): new_obj["type"] = str(type(value)) self.current_object_data[prop] = copy.copy( new_obj) + self.mapping_error = None else: self.mapping_error = f"Failed parsing properties, too many!" @@ -311,13 +313,14 @@ def frame_update(self): self.controllers_to_set_frame_current_frame = bpy.context.scene.frame_current def redraw_ui(self): - for screen in self.screens: - try: + if self.screens == None: + return + try: + for screen in self.screens: for area in screen.areas: area.tag_redraw() - except Exception as e: - print(e) - print("Screen error") + except Exception as e: + print("Screen error") def update_data(self, mapping, new_value): for obj in bpy.context.selected_objects: @@ -402,7 +405,7 @@ def save_to_blend(self): "controller_names": self.controller_names, "controller_mapping": self.controller_property_mapping, "selection_groups": self.controller_selection_mapping, - "controller_keyframe_bind": {"controller": self.key_frame_control, "velocity": self.button_velocity_pressed} + "controller_keyframe_bind": {"controller": self.key_frame_control, "velocity": self.keyframe_insert_button_velocity_pressed} } try: setattr(self.context.scene, 'midicontrol_data', json.dumps(to_save)) @@ -419,7 +422,7 @@ def load_from_blend(self): self.controller_selection_mapping = json_object["selection_groups"] self.key_frame_control = json_object[ "controller_keyframe_bind"]["controller"] - self.button_velocity_pressed = json_object[ + self.keyframe_insert_button_velocity_pressed = json_object[ "controller_keyframe_bind"]["velocity"] self.loaded_from_blend = True except Exception as e: @@ -436,38 +439,36 @@ def midi_callback(self, midi_data): value = midi_data[0][2] if velocity != self.midi_last_control_velocity: - if self.bind_control_state == self.ControllerButtonBindingState.PENDING: + if self.key_frame_bind_control_state == self.ControllerButtonBindingState.PENDING: self.key_frame_control = control - - if str(control) == str(self.key_frame_control): - if self.button_velocity_pressed == 0: - self.button_velocity_pressed = velocity - self.bind_control_state = self.ControllerButtonBindingState.NONE - + self.keyframe_insert_button_velocity_pressed = velocity # self.save_to_blend() + self.key_frame_bind_control_state = self.ControllerButtonBindingState.BOUND + + elif self.select_group_bind_selection_state == self.ControllerButtonBindingState.PENDING: + new_selection_mapping = { + "name": self.selection_to_map["name"], + "selected_objects": self.selection_to_map["selected"], + "velocity": velocity + } + self.controller_selection_mapping[str( + control)] = new_selection_mapping + self.select_group_button_velocity_pressed = velocity + + self.select_group_bind_selection_state = self.ControllerButtonBindingState.BOUND + + elif self.key_frame_bind_control_state == self.ControllerButtonBindingState.BOUND and \ + velocity == self.keyframe_insert_button_velocity_pressed and \ + self.key_frame_control == control: + self.insert_keyframes() - elif velocity == self.button_velocity_pressed: - self.insert_keyframes() - - if self.bind_selection_state == self.ControllerButtonBindingState.PENDING: - if self.button_velocity_pressed == 0: - new_selection_mapping = { - "name": self.selection_to_map["name"], - "selected_objects": self.selection_to_map["selected"], - "velocity": velocity - } - self.controller_selection_mapping[str( - control)] = new_selection_mapping - self.bind_selection_state = self.ControllerButtonBindingState.NONE # self.save_to_blend() - - else: + elif self.select_group_bind_selection_state == self.ControllerButtonBindingState.BOUND and \ + velocity == self.select_group_button_velocity_pressed: if str(control) in self.controller_selection_mapping: self.select_objects( self.controller_selection_mapping[str(control)]["selected_objects"]) - if str(control) == str(self.key_frame_control) and velocity == self.button_velocity_pressed: - self.insert_keyframes() self.midi_last_control_velocity = velocity diff --git a/__init__.py b/__init__.py index 17cfb03..708f0d5 100644 --- a/__init__.py +++ b/__init__.py @@ -236,9 +236,9 @@ def execute(self, context): midi_control = scene.MidiControl if self.start: - midi_control.bind_control_state = midi_control.ControllerButtonBindingState.PENDING + midi_control.key_frame_bind_control_state = midi_control.ControllerButtonBindingState.PENDING elif self.reset: - midi_control.bind_control_state = midi_control.ControllerButtonBindingState.NONE + midi_control.key_frame_bind_control_state = midi_control.ControllerButtonBindingState.NONE midi_control.key_frame_control = None # Very cheeky # midi_control.save_to_blend() @@ -270,10 +270,10 @@ def execute(self, context): "name": self.name } midi_control.selection_to_map = copy.copy(to_map) - midi_control.bind_selection_state = midi_control.ControllerButtonBindingState.PENDING + midi_control.select_group_bind_selection_state = midi_control.ControllerButtonBindingState.PENDING else: midi_control.selection_to_map = None - midi_control.bind_selection_state = midi_control.ControllerButtonBindingState.NONE + midi_control.select_group_bind_selection_state = midi_control.ControllerButtonBindingState.NONE # Very cheeky # midi_control.save_to_blend() @@ -538,7 +538,7 @@ def draw(self, context): op.reset = False op.start = True - if midi_control.bind_control_state == midi_control.ControllerButtonBindingState.PENDING: + if midi_control.key_frame_bind_control_state == midi_control.ControllerButtonBindingState.PENDING: row = box.row() row.label(text="Press a button to bind!") @@ -761,7 +761,7 @@ def draw(self, context): if midi_control.midi_open: layout.label(text="Map Current Selection") - if midi_control.bind_selection_state == midi_control.ControllerButtonBindingState.NONE: + if midi_control.select_group_bind_selection_state != midi_control.ControllerButtonBindingState.PENDING: box = layout.box() row = box.row() row.label(text="Selection Group Name:")