diff --git a/actions.py b/actions.py index 1e44d57..de408c1 100644 --- a/actions.py +++ b/actions.py @@ -4,6 +4,7 @@ import data_centre.length_setter as length_setter import sys import shlex import os +import re from pythonosc import osc_message_builder from pythonosc import dispatcher from pythonosc import osc_server @@ -867,6 +868,27 @@ class Actions(object): def clear_message(self): self.message_handler.clear_all_messages() + # TODO: make this interrogate the various components for available routes to parse + @property + def parserlist(self): + return { + ( r"play_shader_([0-9])_([0-9])", self.shaders.play_that_shader ) + } - + def get_callback_for_method(self, method_name, argument): + for a in self.parserlist: + regex = a[0] + me = a[1] + matches = re.search(regex, method_name) + + if matches: + found_method = me + parsed_args = list(map(int,matches.groups())) + if argument: + args = [argument] + parsed_args + else: + args = parsed_args + + return (found_method, args) + diff --git a/user_input/midi_input.py b/user_input/midi_input.py index fc8a954..1b76f01 100644 --- a/user_input/midi_input.py +++ b/user_input/midi_input.py @@ -129,15 +129,20 @@ class MidiInput(object): self.display.refresh_display() def call_method_name(self, method_name, argument=None): + # if the target method doesnt exist, call the handler + if not hasattr(self.actions, method_name): + self.call_parse_method_name(method_name, argument) + return + if argument is not None: getattr(self.actions, method_name)(argument) else: getattr(self.actions, method_name)() - - - + def call_parse_method_name(self, method_name, argument): + method, arguments = self.actions.get_callback_for_method(method_name, argument) + method(*arguments)