aboutsummaryrefslogtreecommitdiffhomepage
path: root/configs/latch.lua
diff options
context:
space:
mode:
authorPaul Hedderly <paul+github@.mjr.org>2021-07-26 14:01:01 +0100
committerPaul Hedderly <paul+github@.mjr.org>2021-07-26 14:01:01 +0100
commit838486b13e00129368fed70be6a583a5b0899c71 (patch)
tree4db252337d45b17c052b3d9f96de09ab6a5ca84d /configs/latch.lua
parent22111533d32a30dd52d51a7264c67f8afc7a6bd7 (diff)
downloadmidimonster-838486b13e00129368fed70be6a583a5b0899c71.tar.gz
midimonster-838486b13e00129368fed70be6a583a5b0899c71.tar.bz2
midimonster-838486b13e00129368fed70be6a583a5b0899c71.zip
prh: new example config to latch a non-motorised fader
Diffstat (limited to 'configs/latch.lua')
-rw-r--r--configs/latch.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/configs/latch.lua b/configs/latch.lua
new file mode 100644
index 0000000..569cae2
--- /dev/null
+++ b/configs/latch.lua
@@ -0,0 +1,51 @@
+-- Trackpad input by Paul Hedderly
+-- Expects two inputs - one master and one slave
+-- The first is to track a contolled input for example a
+-- sound desk fader.
+-- The slave is for a fader on a non-motorised surface...
+-- The idea is that the slave is not forwarded to the
+-- first/main output until it is close in value to the master
+-- This is to avoid sudden jumps when using a secondary
+-- non-motorised controller.
+--
+-- Example config - here using a nanok as a slave to an X32
+--
+-- [midi x32]
+-- read = X32Live
+-- write = X32Live
+--
+-- [midi nanoK]
+-- read = nanoKEY
+-- write = nanoKEY
+--
+-- [lua latch]
+-- script = latch.lua
+-- default-handler = latch
+--
+-- x32.ch0.cc1 > latch.0.master
+-- nanoK.ch0.cc1 > latch.0.slave
+-- latch.0.latched > x32.ch0.cc1
+
+threshold=0.03
+saved={}
+
+function latch(v)
+ i=input_channel(); separator=i:find("%.")
+ channel=i:sub(0,separator-1)
+ control=i:sub(1+separator,-1)
+
+ -- Setup the saved value if not yet seen
+ if saved[channel]==nil then
+ saved[channel]=v
+ end
+
+ if control == "master" then
+ saved[channel]=v
+ elseif control == "slave" then
+ diff=math.abs(v-saved[channel])
+ if diff < threshold then
+ saved[channel]=v
+ output(channel..".latched",v)
+ end
+ end
+end