mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-12 03:10:17 +01:00
map generic bank/slot midi command eg 'play_shader_0_0' to method
This commit is contained in:
22
actions.py
22
actions.py
@@ -4,6 +4,7 @@ import data_centre.length_setter as length_setter
|
|||||||
import sys
|
import sys
|
||||||
import shlex
|
import shlex
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from pythonosc import osc_message_builder
|
from pythonosc import osc_message_builder
|
||||||
from pythonosc import dispatcher
|
from pythonosc import dispatcher
|
||||||
from pythonosc import osc_server
|
from pythonosc import osc_server
|
||||||
@@ -867,6 +868,27 @@ class Actions(object):
|
|||||||
def clear_message(self):
|
def clear_message(self):
|
||||||
self.message_handler.clear_all_messages()
|
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)
|
||||||
|
|
||||||
|
|||||||
@@ -129,15 +129,20 @@ class MidiInput(object):
|
|||||||
self.display.refresh_display()
|
self.display.refresh_display()
|
||||||
|
|
||||||
def call_method_name(self, method_name, argument=None):
|
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:
|
if argument is not None:
|
||||||
getattr(self.actions, method_name)(argument)
|
getattr(self.actions, method_name)(argument)
|
||||||
else:
|
else:
|
||||||
getattr(self.actions, method_name)()
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user