diff options
author | cbdev <cb@cbcdn.com> | 2021-07-28 14:01:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-28 14:01:28 +0200 |
commit | 96b727c43595ab80ac2eb370f25e197987e88f55 (patch) | |
tree | 162aaa19c7ad9db9bc593506daa6f2bbbb9e11a9 /configs/latch.lua | |
parent | 22111533d32a30dd52d51a7264c67f8afc7a6bd7 (diff) | |
parent | 4359b0cc0793ce76c3e7917a951052ea17aba355 (diff) | |
download | midimonster-96b727c43595ab80ac2eb370f25e197987e88f55.tar.gz midimonster-96b727c43595ab80ac2eb370f25e197987e88f55.tar.bz2 midimonster-96b727c43595ab80ac2eb370f25e197987e88f55.zip |
Merge pull request #94 from phedders/prh-examples
Merge lua examples from phedders
Diffstat (limited to 'configs/latch.lua')
-rw-r--r-- | configs/latch.lua | 51 |
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 |