From 2cc9f84ec3d0b6788ee99e288476cd18377ab18d Mon Sep 17 00:00:00 2001 From: Tristan Rowley Date: Fri, 31 Jan 2020 23:20:52 +0000 Subject: [PATCH] can route actions through user-defined formulas, eg "sin(x*pi)" --- plugins/ManipulatePlugin.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/plugins/ManipulatePlugin.py b/plugins/ManipulatePlugin.py index d6c14d0..5397f83 100644 --- a/plugins/ManipulatePlugin.py +++ b/plugins/ManipulatePlugin.py @@ -1,5 +1,19 @@ import data_centre.plugin_collection from data_centre.plugin_collection import ActionsPlugin#, SequencePlugin +#import math +from math import sin, cos, tan, log, exp, pi + +""" +add to midi or osc mapping +use |f: : to bookend your formula + +eg + + "control_change 48": { + "DEFAULT": ["set_the_shader_param_0_layer_offset_0_continuous|invert|f:sin(x*pi):&&print_arguments","set_strobe_amount_continuous"], + "NAV_DETOUR": ["set_detour_speed_position_continuous"] + }, +""" class ManipulatePlugin(ActionsPlugin): disabled = False @@ -10,9 +24,13 @@ class ManipulatePlugin(ActionsPlugin): @property def parserlist(self): return [ - ( r"(.*)\|invert$", self.invert ), + ( r"^(.*)\|invert$", self.invert ), + ( r"^(.*)\|f:(.*):$", self.formula ), + ( r"^set_variable_([a-zA-Z0-9]+)$", self.set_variable ) ] + variables = {} + def invert(self, action, value): # invert the value self.pc.actions.call_method_name( @@ -20,3 +38,16 @@ class ManipulatePlugin(ActionsPlugin): # if you were calling an action with no argument, use eg: # "toggle_automation_pause", None ) + + def formula(self, action, formula, value): + self.variables['x'] = value + print("evaluating formula `%s` with value `%s`" % (formula, value)) + value = eval(formula, globals(), self.variables) + print("got evaluated value `%s`" % value) + + self.pc.actions.call_method_name( + action, value + ) + + def set_variable(self, var_name, value): + self.variables[var_name] = value