Created
August 28, 2020 05:03
-
-
Save catfact/9cc65031e7c75b6ad00bc6408408421b to your computer and use it in GitHub Desktop.
test of binary parameters on norns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- midi switches | |
| -- | |
| -- | |
| -- helpers. if these seem useful they could be lib'd. | |
| -- creates a "gate" parameter | |
| -- when this is mapped to a CC, it performs the "on" action if the new value is > 64, | |
| -- otherwise performs the "off" action | |
| --- @param name: must be a legal lua identifier | |
| local add_gate_param = function(name, onEvent, offEvent) | |
| params:add{type='number', id=name, name=name, min=0, max=1, default=0, action=function(val) | |
| if val > 0 then onEvent(val) else offEvent(val) end | |
| end} | |
| end | |
| -- i couldn't get this to work. i was surprised, and i do see the need for a "wrap" or "cycle" behavior in general. (i think a "cycle" parmeter type would be more useful than "toggle." | |
| local add_toggle_opt_param = function(name, onEvent, offEvent) | |
| params:add{type='option', id=name, name=name, options={'off', 'on'}, default=1, action=function(val) | |
| if val == 'on' then onEvent() else offEvent() end | |
| end} | |
| end | |
| --]] | |
| -- hm, this also does not work, | |
| -- i think b/c the "silent" setter option doesn't apply in the norns MAP UI page | |
| local add_toggle_num_param = function(name, onEvent, offEvent) | |
| state = false | |
| -- here we have to create the param first, so we can force its value | |
| params:add{type='number', id=name, name=name, min=0, max=1, default=0} | |
| params:set_action(name, function(val) | |
| print ('tog param handling '..val) | |
| if val > 0 then | |
| if state then | |
| state = false | |
| params:set(name, 0, true) | |
| offEvent(val) | |
| else | |
| state = true | |
| params:set(name, 1, true) | |
| onEvent(val) | |
| end | |
| end | |
| end) | |
| end | |
| -- `toggle` type is in fact the only option, and it's strange that it can't be mapped | |
| local add_toggle_tog_param = function(name, onEvent, offEvent) | |
| state = false | |
| -- here we have to create the param first, so we can force its value | |
| params:add{type='toggle', id=name, name=name, action=function(val) | |
| if val > 0 then | |
| onEvent(val) | |
| else | |
| offEvent(val) | |
| end | |
| end} | |
| end | |
| local add_trigger_param = function(name, event) | |
| params:add{type = 'number', id = name, name = name, min = 0, max = 1, default = 0, action = function(val) | |
| if val > 0 then event(val) end | |
| end} | |
| end | |
| init = function() | |
| -- add a dumb momentary gate | |
| add_gate_param('gate', function() print 'on' end, function() print 'off' end) | |
| -- add different attempts at toggle | |
| add_toggle_opt_param('tog_opt', function() print 'on' end, function() print 'off' end) | |
| add_toggle_num_param('tog_num', function() print 'on' end, function() print 'off' end) | |
| add_toggle_tog_param('tog_tog', function() print 'on' end, function() print 'off' end) | |
| -- add a trigger | |
| add_trigger_param('trig', function() print 'bang' end) | |
| -- add a "smart gate" which only performs actions on transitions. | |
| -- (this of course could also be a "library" function) | |
| -- as it turns out, this doesn't behave any differently from the "dumb" gate when midi-mapped | |
| -- (because by default the "dumb" gate only fires when ([0-127]/2) changes) | |
| smart_gate_state = false | |
| add_gate_param('smart_gate', | |
| function() | |
| if not smart_gate_state then | |
| smart_gate_state = true | |
| print 'on' | |
| end | |
| end, | |
| function() | |
| if smart_gate_state then | |
| smart_gate_state = false | |
| print 'off' | |
| end | |
| end | |
| ) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment