From 09e6a8eb28ee4f4c9eb4b8347f822146b0df51a5 Mon Sep 17 00:00:00 2001 From: dan derks Date: Tue, 12 Jul 2022 23:10:18 -0400 Subject: [PATCH 01/10] initial upload + unload lfo's after use --- lua/core/script.lua | 4 + lua/lib/lfo.lua | 420 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 424 insertions(+) create mode 100644 lua/lib/lfo.lua diff --git a/lua/core/script.lua b/lua/core/script.lua index f2a8a1814..1a0646214 100644 --- a/lua/core/script.lua +++ b/lua/core/script.lua @@ -27,6 +27,10 @@ Script.clear = function() package.loaded['asl'] = nil end + if package.loaded['lfo'] then + package.loaded['lfo'] = nil + end + -- script local state local state = { } diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua new file mode 100644 index 000000000..e3dabebe5 --- /dev/null +++ b/lua/lib/lfo.lua @@ -0,0 +1,420 @@ +--- module for creating parameter LFOs +-- @module lib.LFO +-- @release v1.0 +-- @author dndrks +-- adapted from code examples by Mark Eats (Changes) + justmat (hnds) + +local LFO = {} + +LFO.max_per_group = 8 +LFO.groups = {} +LFO.parent_strings = {} + +LFO.rates = {1/16,1/8,1/4,5/16,1/3,3/8,1/2,3/4,1,1.5,2,3,4,6,8,16,32,64,128,256,512,1024} +LFO.rates_as_strings = {"1/16","1/8","1/4","5/16","1/3","3/8","1/2","3/4","1","1.5","2","3","4","6","8","16","32","64","128","256","512","1024"} + +local frm = require 'formatters' +local update_freq = 128 +local main_header_added = false +local clock_action_appended = false +local tempo_updater_clock; +local lfos_all_loaded = {} + +local function new_lfo_table() + return + { + available = LFO.max_per_group, + parent_group = {}, + targets = {}, + actions = {}, + progress = {}, + freqs = {}, + values = {}, + rand_values = {}, + update = {}, + counter = nil, + param_types = {}, + } +end + +local function lfo_params_visibility(state, group, i) + if lfos_all_loaded[group] then + params[state](params, "lfo position "..group.." "..i) + params[state](params, "lfo depth "..group.." "..i) + params[state](params, "lfo mode "..group.." "..i) + if state == "show" then + if params:get("lfo mode "..group.." "..i) == 1 then + params:hide("lfo free "..group.." "..i) + params:show("lfo bars "..group.." "..i) + elseif params:get("lfo mode "..group.." "..i) == 2 then + params:hide("lfo bars "..group.." "..i) + params:show("lfo free "..group.." "..i) + end + else + params:hide("lfo bars "..group.." "..i) + params:hide("lfo free "..group.." "..i) + end + params[state](params, "lfo shape "..group.." "..i) + params[state](params, "lfo min "..group.." "..i) + params[state](params, "lfo max "..group.." "..i) + params[state](params, "lfo reset "..group.." "..i) + params[state](params, "lfo reset target "..group.." "..i) + _menu.rebuild_params() + end +end + +local function return_param_to_baseline(group,i) + -- when an LFO is turned off, the affected parameter will return to its pre-enabled value, + -- if it was registered with 'param action' + params:lookup_param(LFO.groups[group].targets[i]):bang() +end + +local function build_lfo_spec(group,i,bound) + local lfo_target = LFO.groups[group].targets[i] + local param_spec = params:lookup_param(lfo_target) + + -- number: + if param_spec.t == 1 then + params:add{ + type = 'number', + id = 'lfo '..bound..' '..group..' '..i, + name = 'lfo '..bound, + min = param_spec.min, + max = param_spec.max, + default = (bound == nil and param_spec.value or (bound == 'min' and param_spec.min or (bound == 'current' and params:get(lfo_target) or param_spec.max))), + formatter = param_spec.formatter + } + -- option: + elseif param_spec.t == 2 then + params:add{ + type = 'option', + id = 'lfo '..bound..' '..group..' '..i, + name = 'lfo '..bound, + options = param_spec.option, + default = (bound == nil and param_spec.value or (bound == 'min' and 1 or (bound == 'current' and params:get(lfo_target) or param_spec.count))) + } + -- control: + elseif param_spec.t == 3 then + params:add{ + type = 'control', + id = 'lfo '..bound..' '..group..' '..i, + name = 'lfo '..bound, + controlspec = controlspec.new( + param_spec.controlspec.minval, + param_spec.controlspec.maxval, + param_spec.controlspec.warp, + param_spec.controlspec.step, + (bound == nil and param_spec.controlspec.default or (bound == 'min' and param_spec.controlspec.minval or (bound == 'current' and params:get(lfo_target) or param_spec.controlspec.maxval))), + param_spec.controlspec.units, + param_spec.controlspec.quantum, + param_spec.controlspec.wrap + ), + formatter = param_spec.formatter + } + -- taper: + elseif param_spec.t == 5 then + params:add{ + type = 'taper', + id = 'lfo '..bound..' '..group..' '..i, + name = 'lfo '..bound, + min = param_spec.min, + max = param_spec.max, + default = (bound == nil and param_spec.value or (bound == 'min' and param_spec.min or (bound == 'current' and params:get(lfo_target) or param_spec.max))), + k = param_spec.k, + units = param_spec.units + } + -- binary (adapted to controlspec): + elseif param_spec.t == 9 then + params:add{ + type = 'control', + id = 'lfo '..bound..' '..group..' '..i, + name = 'lfo '..bound, + controlspec = controlspec.new( + 0, + 1, + 'lin', + 1, + (bound == nil and param_spec.value or (bound == 'min' and 0 or (bound == 'current' and params:get(lfo_target) or 1))), + nil, + 1, + nil + ), + formatter = function(param) return( + param:get() == 1 and "on" or "off") + end + } + end +end + +local function update_lfo_freqs(group) + for i = 1,#LFO.groups[group].targets do + LFO.groups[group].freqs[i] = 1 / util.linexp(1, #LFO.groups[group].targets, 1, 1, i) + end +end + +local function reset_lfo_phase(group,which) + if which == nil then + for i = 1, #LFO.groups[group].targets do + LFO.groups[group].progress[i] = math.pi * (params:string("lfo reset target "..group.." "..i) == "floor" and 1.5 or 2.5) + end + else + LFO.groups[group].progress[which] = math.pi * (params:string("lfo reset target "..group.." "..which) == "floor" and 1.5 or 2.5) + end +end + +local function sync_lfos(group, i) + if params:get("lfo mode "..group.." "..i) == 1 then + LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("lfo bars "..group.." "..i)] * 4) + else + LFO.groups[group].freqs[i] = params:get("lfo free "..group.." "..i) + end +end + +local function process_lfo(group) + local delta = (1 / update_freq) * 2 * math.pi + local lfo_parent = LFO.groups[group] + if lfos_all_loaded[group] then + for i = 1,#lfo_parent.targets do + + lfo_parent.progress[i] = lfo_parent.progress[i] + delta * lfo_parent.freqs[i] + local min = params:get("lfo min "..group.." "..i) + local max = params:get("lfo max "..group.." "..i) + if min > max then + local old_min = min + local old_max = max + min = old_max + max = old_min + end + + local percentage = math.abs(min-max) * (params:get("lfo depth "..group.." "..i)/100) + local value = util.linlin(-1,1,min,min + percentage,math.sin(lfo_parent.progress[i])) + + if value ~= lfo_parent.values[i] and (params:get("lfo depth "..group.." "..i)/100 > 0) then + lfo_parent.values[i] = value + if params:string("lfo "..group.." "..i) == "on" then + local mid; + local scaled_min; + local scaled_max; + + if params:string("lfo position "..group.." "..i) == 'from min' then + scaled_min = min + scaled_max = min + percentage + mid = util.linlin(min,max,scaled_min,scaled_max,(min+max)/2) + elseif params:string("lfo position "..group.." "..i) == 'from center' then + mid = (min+max)/2 + local centroid_mid = math.abs(min-max) * ((params:get("lfo depth "..group.." "..i)/100)/2) + scaled_min = mid - centroid_mid + scaled_max = mid + centroid_mid + value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) + elseif params:string("lfo position "..group.." "..i) == 'from max' then + mid = (min+max)/2 + value = max - value + scaled_min = max - (math.abs(min-max) * (params:get("lfo depth "..group.." "..i)/100)) + scaled_max = max + mid = math.abs(util.linlin(min,max,scaled_min,scaled_max,mid)) + value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) + elseif params:string("lfo position "..group.." "..i) == 'from current' then + mid = params:get(lfo_parent.targets[i]) + local centroid_mid = math.abs(min-max) * ((params:get("lfo depth "..group.." "..i)/100)/2) + scaled_min = mid - centroid_mid + scaled_max = mid + centroid_mid + value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) + end + + if params:string("lfo shape "..group.." "..i) == "sine" then + if lfo_parent.param_types[i] == 1 or lfo_parent.param_types[i] == 2 or lfo_parent.param_types[i] == 9 then + value = util.round(value,1) + end + value = util.clamp(value,min,max) + lfo_parent.actions[lfo_parent.targets[i]](value) + elseif params:string("lfo shape "..group.." "..i) == "square" then + local square_value; + square_value = value >= mid and max or min + square_value = util.linlin(min,max,scaled_min,scaled_max,square_value) + square_value = util.clamp(square_value,min,max) + lfo_parent.actions[lfo_parent.targets[i]](square_value) + elseif params:string("lfo shape "..group.." "..i) == "random" then + local prev_value = lfo_parent.rand_values[i] + lfo_parent.rand_values[i] = value >= mid and max or min + local rand_value; + if prev_value ~= lfo_parent.rand_values[i] then + rand_value = util.linlin(min,max,scaled_min,scaled_max,math.random(math.floor(min*100),math.floor(max*100))/100) + if lfo_parent.param_types[i] == 1 or lfo_parent.param_types[i] == 2 or lfo_parent.param_types[i] == 9 then + rand_value = util.round(rand_value,1) + end + rand_value = util.clamp(rand_value,min,max) + lfo_parent.actions[lfo_parent.targets[i]](rand_value) + end + end + end + end + + end + end +end + +function LFO:register(param, parent_group, fn) + + if self.groups[parent_group] == nil then + LFO.groups[parent_group] = new_lfo_table() + table.insert(LFO.parent_strings, parent_group) + end + if #self.groups[parent_group].targets < self.max_per_group then + table.insert(self.groups[parent_group].targets, param) + self.groups[parent_group].available = self.groups[parent_group].available - 1 + else + print("LFO ERROR: limit of "..LFO.max_per_group.." entries per LFO group, ignoring "..parent_group.." / "..param) + goto done + end + + if not fn or fn == 'map param' then + fn = function(val) params:set(param, val) end + elseif fn == 'param action' then + fn = function(val) params:lookup_param(param).action(val) end + end + + self.groups[parent_group].actions[param] = fn + + ::done:: + +end + +function LFO:set_action(param, parent_group, fn) + self.groups[parent_group].actions[param] = fn +end + +function LFO:add_params(parent_group, separator_name, silent) + + if not main_header_added and separator_name ~= nil then + params:add_separator(separator_name) + main_header_added = true + end + + local group = parent_group + params:add_group(group, 12 * #self.groups[group].targets) + + for i = 1,#self.groups[group].targets do + + self.groups[group].param_types[i] = params:lookup_param(self.groups[group].targets[i]).t + + params:add_separator(params:lookup_param(self.groups[group].targets[i]).name) + + params:add_option("lfo "..group.." "..i,"lfo",{"off","on"},1) + params:set_action("lfo "..group.." "..i,function(x) + sync_lfos(group, i) + if x == 1 then + return_param_to_baseline(group, i) + lfo_params_visibility("hide", group, i) + elseif x == 2 then + lfo_params_visibility("show", group, i) + end + end) + + params:add_number("lfo depth "..group.." "..i,"depth",0,100,0,function(param) return (param:get().."%") end) + params:set_action("lfo depth "..group.." "..i, function(x) + if x == 0 then + return_param_to_baseline(group, i) + end + end) + + build_lfo_spec(group,i,"min") + build_lfo_spec(group,i,"max") + + params:add_option("lfo position "..group.." "..i, "lfo position", {"from min", "from center", "from max", "from current"},1) + + params:add_option("lfo mode "..group.." "..i, "lfo mode", {"bars","free"},1) + params:set_action("lfo mode "..group.." "..i, + function(x) + if x == 1 and params:string("lfo "..group.." "..i) == "on" then + params:hide("lfo free "..group.." "..i) + params:show("lfo bars "..group.." "..i) + self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("lfo bars "..group.." "..i)] * 4) + elseif x == 2 and params:string("lfo "..group.." "..i) == "on" then + params:hide("lfo bars "..group.." "..i) + params:show("lfo free "..group.." "..i) + self.groups[group].freqs[i] = params:get("lfo free "..group.." "..i) + end + _menu.rebuild_params() + end + ) + + params:add_option("lfo bars "..group.." "..i, "lfo rate", self.rates_as_strings, 9) + params:set_action("lfo bars "..group.." "..i, + function(x) + if params:string("lfo mode "..group.." "..i) == "bars" then + self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[x] * 4) + end + end + ) + params:add{ + type='control', + id="lfo free "..group.." "..i, + name="lfo rate", + controlspec=controlspec.new(0.001,4,'exp',0.001,0.05,'hz',0.001) + } + params:set_action("lfo free "..group.." "..i, + function(x) + if params:string("lfo mode "..group.." "..i) == "free" then + self.groups[group].freqs[i] = x + end + end + ) + + params:add_option("lfo shape "..group.." "..i, "lfo shape", {"sine","square","random"},1) + + params:add_trigger("lfo reset "..group.." "..i, "reset lfo") + params:set_action("lfo reset "..group.." "..i, function(x) reset_lfo_phase(group,i) end) + + params:add_option("lfo reset target "..group.." "..i, "reset lfo to", {"floor","ceiling"}, 1) + + params:hide("lfo free "..group.." "..i) + end + + lfos_all_loaded[group] = true + + if not silent then + params:bang() + end + + self.groups[group].update = function() + process_lfo(group) + end + + self.groups[group].counter = metro.init(self.groups[group].update, 1 / update_freq) + self.groups[group].counter:start() + + reset_lfo_phase(group) + update_lfo_freqs(group) + + if not clock_action_appended then + local system_tempo_change_handler = params:lookup_param("clock_tempo").action + + local lfo_change_handler = function(bpm) + system_tempo_change_handler(bpm) + if tempo_updater_clock then + clock.cancel(tempo_updater_clock) + end + tempo_updater_clock = clock.run( + function() + clock.sleep(0.05) + for k,v in pairs(self.groups) do + for i = 1,#LFO.groups[k].freqs do + sync_lfos(k, i) + end + end + end + ) + end + + params:set_action("clock_tempo", lfo_change_handler) + -- since clock params get rebuilt as part of a script clear, + -- it seems okay to append without re-establishing: + -- https://github.com/monome/norns/blob/main/lua/core/script.lua#L100 + + clock_action_appended = true + + end + +end + +return LFO \ No newline at end of file From 8935b8c124d8fceda37fa93048e3406fc2a2eaef Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 13 Jul 2022 08:02:05 -0400 Subject: [PATCH 02/10] default = 'param action' and track fn mapping --- lua/lib/lfo.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua index e3dabebe5..7b49c46bc 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/lfo.lua @@ -34,6 +34,7 @@ local function new_lfo_table() update = {}, counter = nil, param_types = {}, + fn = {} } end @@ -267,10 +268,12 @@ function LFO:register(param, parent_group, fn) goto done end - if not fn or fn == 'map param' then - fn = function(val) params:set(param, val) end - elseif fn == 'param action' then + if not fn or fn == 'param action' then + self.groups[parent_group].fn[param] = 'param action' fn = function(val) params:lookup_param(param).action(val) end + elseif fn == 'map param' then + self.groups[parent_group].fn[param] = fn + fn = function(val) params:set(param, val) end end self.groups[parent_group].actions[param] = fn @@ -294,10 +297,10 @@ function LFO:add_params(parent_group, separator_name, silent) params:add_group(group, 12 * #self.groups[group].targets) for i = 1,#self.groups[group].targets do + local target_id = self.groups[group].targets[i] + self.groups[group].param_types[i] = params:lookup_param(target_id).t - self.groups[group].param_types[i] = params:lookup_param(self.groups[group].targets[i]).t - - params:add_separator(params:lookup_param(self.groups[group].targets[i]).name) + params:add_separator(params:lookup_param(target_id).name) params:add_option("lfo "..group.." "..i,"lfo",{"off","on"},1) params:set_action("lfo "..group.." "..i,function(x) @@ -320,7 +323,13 @@ function LFO:add_params(parent_group, separator_name, silent) build_lfo_spec(group,i,"min") build_lfo_spec(group,i,"max") - params:add_option("lfo position "..group.." "..i, "lfo position", {"from min", "from center", "from max", "from current"},1) + local position_options; + if self.groups[group].fn[target_id] == 'param action' then + position_options = {"from min", "from center", "from max", "from current"} + else + position_options = {"from min", "from center", "from max"} + end + params:add_option("lfo position "..group.." "..i, "lfo position", position_options, 1) params:add_option("lfo mode "..group.." "..i, "lfo mode", {"bars","free"},1) params:set_action("lfo mode "..group.." "..i, From 33f64bb801681fdf7366349bd37b4e4a610de635 Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 13 Jul 2022 14:03:48 -0400 Subject: [PATCH 03/10] add function type lookup table --- lua/lib/lfo.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua index 7b49c46bc..ce90e464f 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/lfo.lua @@ -33,8 +33,8 @@ local function new_lfo_table() rand_values = {}, update = {}, counter = nil, - param_types = {}, - fn = {} + param_type = {}, + fn_type = {} } end @@ -223,7 +223,7 @@ local function process_lfo(group) end if params:string("lfo shape "..group.." "..i) == "sine" then - if lfo_parent.param_types[i] == 1 or lfo_parent.param_types[i] == 2 or lfo_parent.param_types[i] == 9 then + if lfo_parent.param_type[i] == 1 or lfo_parent.param_type[i] == 2 or lfo_parent.param_type[i] == 9 then value = util.round(value,1) end value = util.clamp(value,min,max) @@ -240,7 +240,7 @@ local function process_lfo(group) local rand_value; if prev_value ~= lfo_parent.rand_values[i] then rand_value = util.linlin(min,max,scaled_min,scaled_max,math.random(math.floor(min*100),math.floor(max*100))/100) - if lfo_parent.param_types[i] == 1 or lfo_parent.param_types[i] == 2 or lfo_parent.param_types[i] == 9 then + if lfo_parent.param_type[i] == 1 or lfo_parent.param_type[i] == 2 or lfo_parent.param_type[i] == 9 then rand_value = util.round(rand_value,1) end rand_value = util.clamp(rand_value,min,max) @@ -269,11 +269,13 @@ function LFO:register(param, parent_group, fn) end if not fn or fn == 'param action' then - self.groups[parent_group].fn[param] = 'param action' + self.groups[parent_group].fn_type[param] = 'param action' fn = function(val) params:lookup_param(param).action(val) end elseif fn == 'map param' then - self.groups[parent_group].fn[param] = fn + self.groups[parent_group].fn_type[param] = 'map param' fn = function(val) params:set(param, val) end + else + self.groups[parent_group].fn_type[param] = 'custom' end self.groups[parent_group].actions[param] = fn @@ -298,7 +300,7 @@ function LFO:add_params(parent_group, separator_name, silent) for i = 1,#self.groups[group].targets do local target_id = self.groups[group].targets[i] - self.groups[group].param_types[i] = params:lookup_param(target_id).t + self.groups[group].param_type[i] = params:lookup_param(target_id).t params:add_separator(params:lookup_param(target_id).name) @@ -324,7 +326,7 @@ function LFO:add_params(parent_group, separator_name, silent) build_lfo_spec(group,i,"max") local position_options; - if self.groups[group].fn[target_id] == 'param action' then + if self.groups[group].fn_type[target_id] == 'param action' then position_options = {"from min", "from center", "from max", "from current"} else position_options = {"from min", "from center", "from max"} From cc92efbbfb2381d9c5e78edae72c931fb6b7affc Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 13 Jul 2022 14:34:20 -0400 Subject: [PATCH 04/10] add ldoc notes --- lua/lib/lfo.lua | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua index ce90e464f..324627dfd 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/lfo.lua @@ -1,5 +1,5 @@ --- module for creating parameter LFOs --- @module lib.LFO +-- @module lib.lfo -- @release v1.0 -- @author dndrks -- adapted from code examples by Mark Eats (Changes) + justmat (hnds) @@ -254,6 +254,10 @@ local function process_lfo(group) end end +--- Register an LFO to a parameter. +-- @tparam string param The parameter ID to control. +-- @tparam string parent_group An organizing group name. Each parent_group has 8 LFOs and consumes one system metro. +-- @tparam[opt] function By default, an LFO will call the parameter action, without affecting the parameter state. Pass a function to override default behavior. function LFO:register(param, parent_group, fn) if self.groups[parent_group] == nil then @@ -268,6 +272,18 @@ function LFO:register(param, parent_group, fn) goto done end + self:set_action(param, parent_group, fn) + + ::done:: + +end + +--- Set an LFO's action. +-- Only needed to change the LFO action after registration. +-- @tparam string param The parameter ID to target. +-- @tparam string parent_group The organizing group name. +-- @tparam[opt] function By default, an LFO will call the parameter action, without affecting the parameter state. Pass a function to override default behavior. +function LFO:set_action(param, parent_group, fn) if not fn or fn == 'param action' then self.groups[parent_group].fn_type[param] = 'param action' fn = function(val) params:lookup_param(param).action(val) end @@ -279,15 +295,12 @@ function LFO:register(param, parent_group, fn) end self.groups[parent_group].actions[param] = fn - - ::done:: - -end - -function LFO:set_action(param, parent_group, fn) - self.groups[parent_group].actions[param] = fn end +--- Add an LFO group's menu parameters. +-- @tparam string parent_group The organizing group name. +-- @tparam string separator_name The separator name used to collect all LFO groups. +-- @tparam boolean Suppress params:bang() after instantiating LFO parameters. Use 'true' until your last LFO parameter group. function LFO:add_params(parent_group, separator_name, silent) if not main_header_added and separator_name ~= nil then From 4c5ce10e7116031d381635748a475e8706e78d44 Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 13 Jul 2022 16:02:50 -0400 Subject: [PATCH 05/10] bars -> clocked --- lua/lib/lfo.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua index 324627dfd..6603d1934 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/lfo.lua @@ -46,13 +46,13 @@ local function lfo_params_visibility(state, group, i) if state == "show" then if params:get("lfo mode "..group.." "..i) == 1 then params:hide("lfo free "..group.." "..i) - params:show("lfo bars "..group.." "..i) + params:show("lfo clocked "..group.." "..i) elseif params:get("lfo mode "..group.." "..i) == 2 then - params:hide("lfo bars "..group.." "..i) + params:hide("lfo clocked "..group.." "..i) params:show("lfo free "..group.." "..i) end else - params:hide("lfo bars "..group.." "..i) + params:hide("lfo clocked "..group.." "..i) params:hide("lfo free "..group.." "..i) end params[state](params, "lfo shape "..group.." "..i) @@ -165,7 +165,7 @@ end local function sync_lfos(group, i) if params:get("lfo mode "..group.." "..i) == 1 then - LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("lfo bars "..group.." "..i)] * 4) + LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("lfo clocked "..group.." "..i)] * 4) else LFO.groups[group].freqs[i] = params:get("lfo free "..group.." "..i) end @@ -346,15 +346,15 @@ function LFO:add_params(parent_group, separator_name, silent) end params:add_option("lfo position "..group.." "..i, "lfo position", position_options, 1) - params:add_option("lfo mode "..group.." "..i, "lfo mode", {"bars","free"},1) + params:add_option("lfo mode "..group.." "..i, "lfo mode", {"clocked","free"},1) params:set_action("lfo mode "..group.." "..i, function(x) if x == 1 and params:string("lfo "..group.." "..i) == "on" then params:hide("lfo free "..group.." "..i) - params:show("lfo bars "..group.." "..i) - self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("lfo bars "..group.." "..i)] * 4) + params:show("lfo clocked "..group.." "..i) + self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("lfo clocked "..group.." "..i)] * 4) elseif x == 2 and params:string("lfo "..group.." "..i) == "on" then - params:hide("lfo bars "..group.." "..i) + params:hide("lfo clocked "..group.." "..i) params:show("lfo free "..group.." "..i) self.groups[group].freqs[i] = params:get("lfo free "..group.." "..i) end @@ -362,10 +362,10 @@ function LFO:add_params(parent_group, separator_name, silent) end ) - params:add_option("lfo bars "..group.." "..i, "lfo rate", self.rates_as_strings, 9) - params:set_action("lfo bars "..group.." "..i, + params:add_option("lfo clocked "..group.." "..i, "lfo rate", self.rates_as_strings, 9) + params:set_action("lfo clocked "..group.." "..i, function(x) - if params:string("lfo mode "..group.." "..i) == "bars" then + if params:string("lfo mode "..group.." "..i) == "clocked" then self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[x] * 4) end end From 3a14e12c25c08bdb801b15ede36f9737b8933f31 Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 13 Jul 2022 16:12:09 -0400 Subject: [PATCH 06/10] no spaces in param IDs --- lua/lib/lfo.lua | 135 ++++++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 68 deletions(-) diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua index 6603d1934..a82d96173 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/lfo.lua @@ -24,7 +24,6 @@ local function new_lfo_table() return { available = LFO.max_per_group, - parent_group = {}, targets = {}, actions = {}, progress = {}, @@ -40,26 +39,26 @@ end local function lfo_params_visibility(state, group, i) if lfos_all_loaded[group] then - params[state](params, "lfo position "..group.." "..i) - params[state](params, "lfo depth "..group.." "..i) - params[state](params, "lfo mode "..group.." "..i) + params[state](params, "lfo_position_"..group.."_"..i) + params[state](params, "lfo_depth_"..group.."_"..i) + params[state](params, "lfo_mode_"..group.."_"..i) if state == "show" then - if params:get("lfo mode "..group.." "..i) == 1 then - params:hide("lfo free "..group.." "..i) - params:show("lfo clocked "..group.." "..i) - elseif params:get("lfo mode "..group.." "..i) == 2 then - params:hide("lfo clocked "..group.." "..i) - params:show("lfo free "..group.." "..i) + if params:get("lfo_mode_"..group.."_"..i) == 1 then + params:hide("lfo_free_"..group.."_"..i) + params:show("lfo_clocked_"..group.."_"..i) + elseif params:get("lfo_mode_"..group.."_"..i) == 2 then + params:hide("lfo_clocked_"..group.."_"..i) + params:show("lfo_free_"..group.."_"..i) end else - params:hide("lfo clocked "..group.." "..i) - params:hide("lfo free "..group.." "..i) + params:hide("lfo_clocked_"..group.."_"..i) + params:hide("lfo_free_"..group.."_"..i) end - params[state](params, "lfo shape "..group.." "..i) - params[state](params, "lfo min "..group.." "..i) - params[state](params, "lfo max "..group.." "..i) - params[state](params, "lfo reset "..group.." "..i) - params[state](params, "lfo reset target "..group.." "..i) + params[state](params, "lfo_shape_"..group.."_"..i) + params[state](params, "lfo_min_"..group.."_"..i) + params[state](params, "lfo_max_"..group.."_"..i) + params[state](params, "lfo_reset_"..group.."_"..i) + params[state](params, "lfo_reset_target_"..group.."_"..i) _menu.rebuild_params() end end @@ -78,7 +77,7 @@ local function build_lfo_spec(group,i,bound) if param_spec.t == 1 then params:add{ type = 'number', - id = 'lfo '..bound..' '..group..' '..i, + id = 'lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, min = param_spec.min, max = param_spec.max, @@ -89,7 +88,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 2 then params:add{ type = 'option', - id = 'lfo '..bound..' '..group..' '..i, + id = 'lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, options = param_spec.option, default = (bound == nil and param_spec.value or (bound == 'min' and 1 or (bound == 'current' and params:get(lfo_target) or param_spec.count))) @@ -98,7 +97,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 3 then params:add{ type = 'control', - id = 'lfo '..bound..' '..group..' '..i, + id = 'lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, controlspec = controlspec.new( param_spec.controlspec.minval, @@ -116,7 +115,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 5 then params:add{ type = 'taper', - id = 'lfo '..bound..' '..group..' '..i, + id = 'lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, min = param_spec.min, max = param_spec.max, @@ -128,7 +127,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 9 then params:add{ type = 'control', - id = 'lfo '..bound..' '..group..' '..i, + id = 'lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, controlspec = controlspec.new( 0, @@ -156,18 +155,18 @@ end local function reset_lfo_phase(group,which) if which == nil then for i = 1, #LFO.groups[group].targets do - LFO.groups[group].progress[i] = math.pi * (params:string("lfo reset target "..group.." "..i) == "floor" and 1.5 or 2.5) + LFO.groups[group].progress[i] = math.pi * (params:string("lfo_reset_target_"..group.."_"..i) == "floor" and 1.5 or 2.5) end else - LFO.groups[group].progress[which] = math.pi * (params:string("lfo reset target "..group.." "..which) == "floor" and 1.5 or 2.5) + LFO.groups[group].progress[which] = math.pi * (params:string("lfo_reset_target_"..group.."_"..which) == "floor" and 1.5 or 2.5) end end local function sync_lfos(group, i) - if params:get("lfo mode "..group.." "..i) == 1 then - LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("lfo clocked "..group.." "..i)] * 4) + if params:get("lfo_mode_"..group.."_"..i) == 1 then + LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("lfo_clocked_"..group.."_"..i)] * 4) else - LFO.groups[group].freqs[i] = params:get("lfo free "..group.." "..i) + LFO.groups[group].freqs[i] = params:get("lfo_free_"..group.."_"..i) end end @@ -178,8 +177,8 @@ local function process_lfo(group) for i = 1,#lfo_parent.targets do lfo_parent.progress[i] = lfo_parent.progress[i] + delta * lfo_parent.freqs[i] - local min = params:get("lfo min "..group.." "..i) - local max = params:get("lfo max "..group.." "..i) + local min = params:get("lfo_min_"..group.."_"..i) + local max = params:get("lfo_max_"..group.."_"..i) if min > max then local old_min = min local old_max = max @@ -187,54 +186,54 @@ local function process_lfo(group) max = old_min end - local percentage = math.abs(min-max) * (params:get("lfo depth "..group.." "..i)/100) + local percentage = math.abs(min-max) * (params:get("lfo_depth_"..group.."_"..i)/100) local value = util.linlin(-1,1,min,min + percentage,math.sin(lfo_parent.progress[i])) - if value ~= lfo_parent.values[i] and (params:get("lfo depth "..group.." "..i)/100 > 0) then + if value ~= lfo_parent.values[i] and (params:get("lfo_depth_"..group.."_"..i)/100 > 0) then lfo_parent.values[i] = value - if params:string("lfo "..group.." "..i) == "on" then + if params:string("lfo_"..group.."_"..i) == "on" then local mid; local scaled_min; local scaled_max; - if params:string("lfo position "..group.." "..i) == 'from min' then + if params:string("lfo_position_"..group.."_"..i) == 'from min' then scaled_min = min scaled_max = min + percentage mid = util.linlin(min,max,scaled_min,scaled_max,(min+max)/2) - elseif params:string("lfo position "..group.." "..i) == 'from center' then + elseif params:string("lfo_position_"..group.."_"..i) == 'from center' then mid = (min+max)/2 - local centroid_mid = math.abs(min-max) * ((params:get("lfo depth "..group.." "..i)/100)/2) + local centroid_mid = math.abs(min-max) * ((params:get("lfo_depth_"..group.."_"..i)/100)/2) scaled_min = mid - centroid_mid scaled_max = mid + centroid_mid value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) - elseif params:string("lfo position "..group.." "..i) == 'from max' then + elseif params:string("lfo_position_"..group.."_"..i) == 'from max' then mid = (min+max)/2 value = max - value - scaled_min = max - (math.abs(min-max) * (params:get("lfo depth "..group.." "..i)/100)) + scaled_min = max - (math.abs(min-max) * (params:get("lfo_depth_"..group.."_"..i)/100)) scaled_max = max mid = math.abs(util.linlin(min,max,scaled_min,scaled_max,mid)) value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) - elseif params:string("lfo position "..group.." "..i) == 'from current' then + elseif params:string("lfo_position_"..group.."_"..i) == 'from current' then mid = params:get(lfo_parent.targets[i]) - local centroid_mid = math.abs(min-max) * ((params:get("lfo depth "..group.." "..i)/100)/2) + local centroid_mid = math.abs(min-max) * ((params:get("lfo_depth_"..group.."_"..i)/100)/2) scaled_min = mid - centroid_mid scaled_max = mid + centroid_mid value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) end - if params:string("lfo shape "..group.." "..i) == "sine" then + if params:string("lfo_shape_"..group.."_"..i) == "sine" then if lfo_parent.param_type[i] == 1 or lfo_parent.param_type[i] == 2 or lfo_parent.param_type[i] == 9 then value = util.round(value,1) end value = util.clamp(value,min,max) lfo_parent.actions[lfo_parent.targets[i]](value) - elseif params:string("lfo shape "..group.." "..i) == "square" then + elseif params:string("lfo_shape_"..group.."_"..i) == "square" then local square_value; square_value = value >= mid and max or min square_value = util.linlin(min,max,scaled_min,scaled_max,square_value) square_value = util.clamp(square_value,min,max) lfo_parent.actions[lfo_parent.targets[i]](square_value) - elseif params:string("lfo shape "..group.." "..i) == "random" then + elseif params:string("lfo_shape_"..group.."_"..i) == "random" then local prev_value = lfo_parent.rand_values[i] lfo_parent.rand_values[i] = value >= mid and max or min local rand_value; @@ -317,8 +316,8 @@ function LFO:add_params(parent_group, separator_name, silent) params:add_separator(params:lookup_param(target_id).name) - params:add_option("lfo "..group.." "..i,"lfo",{"off","on"},1) - params:set_action("lfo "..group.." "..i,function(x) + params:add_option("lfo_"..group.."_"..i,"lfo",{"off","on"},1) + params:set_action("lfo_"..group.."_"..i,function(x) sync_lfos(group, i) if x == 1 then return_param_to_baseline(group, i) @@ -328,8 +327,8 @@ function LFO:add_params(parent_group, separator_name, silent) end end) - params:add_number("lfo depth "..group.." "..i,"depth",0,100,0,function(param) return (param:get().."%") end) - params:set_action("lfo depth "..group.." "..i, function(x) + params:add_number("lfo_depth_"..group.."_"..i,"depth",0,100,0,function(param) return (param:get().."%") end) + params:set_action("lfo_depth_"..group.."_"..i, function(x) if x == 0 then return_param_to_baseline(group, i) end @@ -344,54 +343,54 @@ function LFO:add_params(parent_group, separator_name, silent) else position_options = {"from min", "from center", "from max"} end - params:add_option("lfo position "..group.." "..i, "lfo position", position_options, 1) + params:add_option("lfo_position_"..group.."_"..i, "lfo position", position_options, 1) - params:add_option("lfo mode "..group.." "..i, "lfo mode", {"clocked","free"},1) - params:set_action("lfo mode "..group.." "..i, + params:add_option("lfo_mode_"..group.."_"..i, "lfo mode", {"clocked","free"},1) + params:set_action("lfo_mode_"..group.."_"..i, function(x) - if x == 1 and params:string("lfo "..group.." "..i) == "on" then - params:hide("lfo free "..group.." "..i) - params:show("lfo clocked "..group.." "..i) - self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("lfo clocked "..group.." "..i)] * 4) - elseif x == 2 and params:string("lfo "..group.." "..i) == "on" then - params:hide("lfo clocked "..group.." "..i) - params:show("lfo free "..group.." "..i) - self.groups[group].freqs[i] = params:get("lfo free "..group.." "..i) + if x == 1 and params:string("lfo_"..group.."_"..i) == "on" then + params:hide("lfo_free_"..group.."_"..i) + params:show("lfo_clocked_"..group.."_"..i) + self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("lfo_clocked_"..group.."_"..i)] * 4) + elseif x == 2 and params:string("lfo_"..group.."_"..i) == "on" then + params:hide("lfo_clocked_"..group.."_"..i) + params:show("lfo_free_"..group.."_"..i) + self.groups[group].freqs[i] = params:get("lfo_free_"..group.."_"..i) end _menu.rebuild_params() end ) - params:add_option("lfo clocked "..group.." "..i, "lfo rate", self.rates_as_strings, 9) - params:set_action("lfo clocked "..group.." "..i, + params:add_option("lfo_clocked_"..group.."_"..i, "lfo rate", self.rates_as_strings, 9) + params:set_action("lfo_clocked_"..group.."_"..i, function(x) - if params:string("lfo mode "..group.." "..i) == "clocked" then + if params:string("lfo_mode_"..group.."_"..i) == "clocked" then self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[x] * 4) end end ) params:add{ type='control', - id="lfo free "..group.." "..i, + id="lfo_free_"..group.."_"..i, name="lfo rate", controlspec=controlspec.new(0.001,4,'exp',0.001,0.05,'hz',0.001) } - params:set_action("lfo free "..group.." "..i, + params:set_action("lfo_free_"..group.."_"..i, function(x) - if params:string("lfo mode "..group.." "..i) == "free" then + if params:string("lfo_mode_"..group.."_"..i) == "free" then self.groups[group].freqs[i] = x end end ) - params:add_option("lfo shape "..group.." "..i, "lfo shape", {"sine","square","random"},1) + params:add_option("lfo_shape_"..group.."_"..i, "lfo shape", {"sine","square","random"},1) - params:add_trigger("lfo reset "..group.." "..i, "reset lfo") - params:set_action("lfo reset "..group.." "..i, function(x) reset_lfo_phase(group,i) end) + params:add_trigger("lfo_reset_"..group.."_"..i, "reset lfo") + params:set_action("lfo_reset_"..group.."_"..i, function(x) reset_lfo_phase(group,i) end) - params:add_option("lfo reset target "..group.." "..i, "reset lfo to", {"floor","ceiling"}, 1) + params:add_option("lfo_reset_target_"..group.."_"..i, "reset lfo to", {"floor","ceiling"}, 1) - params:hide("lfo free "..group.." "..i) + params:hide("lfo_free_"..group.."_"..i) end lfos_all_loaded[group] = true From de72288750fc13b65f993feec098190de8df1f8a Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 13 Jul 2022 18:20:19 -0400 Subject: [PATCH 07/10] remove 'frm', not used --- lua/lib/lfo.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/lib/lfo.lua b/lua/lib/lfo.lua index a82d96173..06e36f109 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/lfo.lua @@ -13,7 +13,6 @@ LFO.parent_strings = {} LFO.rates = {1/16,1/8,1/4,5/16,1/3,3/8,1/2,3/4,1,1.5,2,3,4,6,8,16,32,64,128,256,512,1024} LFO.rates_as_strings = {"1/16","1/8","1/4","5/16","1/3","3/8","1/2","3/4","1","1.5","2","3","4","6","8","16","32","64","128","256","512","1024"} -local frm = require 'formatters' local update_freq = 128 local main_header_added = false local clock_action_appended = false From fe8f75192151cb5309af0195acd103adc5eff347 Mon Sep 17 00:00:00 2001 From: dan derks Date: Tue, 19 Jul 2022 16:38:47 -0400 Subject: [PATCH 08/10] rename library to 'param_lfo' --- lua/core/script.lua | 4 +- lua/lib/{lfo.lua => param_lfo.lua} | 144 ++++++++++++++--------------- 2 files changed, 74 insertions(+), 74 deletions(-) rename lua/lib/{lfo.lua => param_lfo.lua} (71%) diff --git a/lua/core/script.lua b/lua/core/script.lua index 1a0646214..8426e744e 100644 --- a/lua/core/script.lua +++ b/lua/core/script.lua @@ -27,8 +27,8 @@ Script.clear = function() package.loaded['asl'] = nil end - if package.loaded['lfo'] then - package.loaded['lfo'] = nil + if package.loaded['param_lfo'] then + package.loaded['param_lfo'] = nil end -- script local state diff --git a/lua/lib/lfo.lua b/lua/lib/param_lfo.lua similarity index 71% rename from lua/lib/lfo.lua rename to lua/lib/param_lfo.lua index 06e36f109..1ad1a57a0 100644 --- a/lua/lib/lfo.lua +++ b/lua/lib/param_lfo.lua @@ -1,5 +1,5 @@ --- module for creating parameter LFOs --- @module lib.lfo +-- @module lib.param_lfo -- @release v1.0 -- @author dndrks -- adapted from code examples by Mark Eats (Changes) + justmat (hnds) @@ -38,26 +38,26 @@ end local function lfo_params_visibility(state, group, i) if lfos_all_loaded[group] then - params[state](params, "lfo_position_"..group.."_"..i) - params[state](params, "lfo_depth_"..group.."_"..i) - params[state](params, "lfo_mode_"..group.."_"..i) + params[state](params, "p_lfo_position_"..group.."_"..i) + params[state](params, "p_lfo_depth_"..group.."_"..i) + params[state](params, "p_lfo_mode_"..group.."_"..i) if state == "show" then - if params:get("lfo_mode_"..group.."_"..i) == 1 then - params:hide("lfo_free_"..group.."_"..i) - params:show("lfo_clocked_"..group.."_"..i) - elseif params:get("lfo_mode_"..group.."_"..i) == 2 then - params:hide("lfo_clocked_"..group.."_"..i) - params:show("lfo_free_"..group.."_"..i) + if params:get("p_lfo_mode_"..group.."_"..i) == 1 then + params:hide("p_lfo_free_"..group.."_"..i) + params:show("p_lfo_clocked_"..group.."_"..i) + elseif params:get("p_lfo_mode_"..group.."_"..i) == 2 then + params:hide("p_lfo_clocked_"..group.."_"..i) + params:show("p_lfo_free_"..group.."_"..i) end else - params:hide("lfo_clocked_"..group.."_"..i) - params:hide("lfo_free_"..group.."_"..i) + params:hide("p_lfo_clocked_"..group.."_"..i) + params:hide("p_lfo_free_"..group.."_"..i) end - params[state](params, "lfo_shape_"..group.."_"..i) - params[state](params, "lfo_min_"..group.."_"..i) - params[state](params, "lfo_max_"..group.."_"..i) - params[state](params, "lfo_reset_"..group.."_"..i) - params[state](params, "lfo_reset_target_"..group.."_"..i) + params[state](params, "p_lfo_shape_"..group.."_"..i) + params[state](params, "p_lfo_min_"..group.."_"..i) + params[state](params, "p_lfo_max_"..group.."_"..i) + params[state](params, "p_lfo_reset_"..group.."_"..i) + params[state](params, "p_lfo_reset_target_"..group.."_"..i) _menu.rebuild_params() end end @@ -76,7 +76,7 @@ local function build_lfo_spec(group,i,bound) if param_spec.t == 1 then params:add{ type = 'number', - id = 'lfo_'..bound..'_'..group..'_'..i, + id = 'p_lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, min = param_spec.min, max = param_spec.max, @@ -87,7 +87,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 2 then params:add{ type = 'option', - id = 'lfo_'..bound..'_'..group..'_'..i, + id = 'p_lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, options = param_spec.option, default = (bound == nil and param_spec.value or (bound == 'min' and 1 or (bound == 'current' and params:get(lfo_target) or param_spec.count))) @@ -96,7 +96,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 3 then params:add{ type = 'control', - id = 'lfo_'..bound..'_'..group..'_'..i, + id = 'p_lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, controlspec = controlspec.new( param_spec.controlspec.minval, @@ -114,7 +114,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 5 then params:add{ type = 'taper', - id = 'lfo_'..bound..'_'..group..'_'..i, + id = 'p_lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, min = param_spec.min, max = param_spec.max, @@ -126,7 +126,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 9 then params:add{ type = 'control', - id = 'lfo_'..bound..'_'..group..'_'..i, + id = 'p_lfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, controlspec = controlspec.new( 0, @@ -154,18 +154,18 @@ end local function reset_lfo_phase(group,which) if which == nil then for i = 1, #LFO.groups[group].targets do - LFO.groups[group].progress[i] = math.pi * (params:string("lfo_reset_target_"..group.."_"..i) == "floor" and 1.5 or 2.5) + LFO.groups[group].progress[i] = math.pi * (params:string("p_lfo_reset_target_"..group.."_"..i) == "floor" and 1.5 or 2.5) end else - LFO.groups[group].progress[which] = math.pi * (params:string("lfo_reset_target_"..group.."_"..which) == "floor" and 1.5 or 2.5) + LFO.groups[group].progress[which] = math.pi * (params:string("p_lfo_reset_target_"..group.."_"..which) == "floor" and 1.5 or 2.5) end end local function sync_lfos(group, i) - if params:get("lfo_mode_"..group.."_"..i) == 1 then - LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("lfo_clocked_"..group.."_"..i)] * 4) + if params:get("p_lfo_mode_"..group.."_"..i) == 1 then + LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("p_lfo_clocked_"..group.."_"..i)] * 4) else - LFO.groups[group].freqs[i] = params:get("lfo_free_"..group.."_"..i) + LFO.groups[group].freqs[i] = params:get("p_lfo_free_"..group.."_"..i) end end @@ -176,8 +176,8 @@ local function process_lfo(group) for i = 1,#lfo_parent.targets do lfo_parent.progress[i] = lfo_parent.progress[i] + delta * lfo_parent.freqs[i] - local min = params:get("lfo_min_"..group.."_"..i) - local max = params:get("lfo_max_"..group.."_"..i) + local min = params:get("p_lfo_min_"..group.."_"..i) + local max = params:get("p_lfo_max_"..group.."_"..i) if min > max then local old_min = min local old_max = max @@ -185,54 +185,54 @@ local function process_lfo(group) max = old_min end - local percentage = math.abs(min-max) * (params:get("lfo_depth_"..group.."_"..i)/100) + local percentage = math.abs(min-max) * (params:get("p_lfo_depth_"..group.."_"..i)/100) local value = util.linlin(-1,1,min,min + percentage,math.sin(lfo_parent.progress[i])) - if value ~= lfo_parent.values[i] and (params:get("lfo_depth_"..group.."_"..i)/100 > 0) then + if value ~= lfo_parent.values[i] and (params:get("p_lfo_depth_"..group.."_"..i)/100 > 0) then lfo_parent.values[i] = value - if params:string("lfo_"..group.."_"..i) == "on" then + if params:string("p_lfo_"..group.."_"..i) == "on" then local mid; local scaled_min; local scaled_max; - if params:string("lfo_position_"..group.."_"..i) == 'from min' then + if params:string("p_lfo_position_"..group.."_"..i) == 'from min' then scaled_min = min scaled_max = min + percentage mid = util.linlin(min,max,scaled_min,scaled_max,(min+max)/2) - elseif params:string("lfo_position_"..group.."_"..i) == 'from center' then + elseif params:string("p_lfo_position_"..group.."_"..i) == 'from center' then mid = (min+max)/2 - local centroid_mid = math.abs(min-max) * ((params:get("lfo_depth_"..group.."_"..i)/100)/2) + local centroid_mid = math.abs(min-max) * ((params:get("p_lfo_depth_"..group.."_"..i)/100)/2) scaled_min = mid - centroid_mid scaled_max = mid + centroid_mid value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) - elseif params:string("lfo_position_"..group.."_"..i) == 'from max' then + elseif params:string("p_lfo_position_"..group.."_"..i) == 'from max' then mid = (min+max)/2 value = max - value - scaled_min = max - (math.abs(min-max) * (params:get("lfo_depth_"..group.."_"..i)/100)) + scaled_min = max - (math.abs(min-max) * (params:get("p_lfo_depth_"..group.."_"..i)/100)) scaled_max = max mid = math.abs(util.linlin(min,max,scaled_min,scaled_max,mid)) value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) - elseif params:string("lfo_position_"..group.."_"..i) == 'from current' then + elseif params:string("p_lfo_position_"..group.."_"..i) == 'from current' then mid = params:get(lfo_parent.targets[i]) - local centroid_mid = math.abs(min-max) * ((params:get("lfo_depth_"..group.."_"..i)/100)/2) + local centroid_mid = math.abs(min-max) * ((params:get("p_lfo_depth_"..group.."_"..i)/100)/2) scaled_min = mid - centroid_mid scaled_max = mid + centroid_mid value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) end - if params:string("lfo_shape_"..group.."_"..i) == "sine" then + if params:string("p_lfo_shape_"..group.."_"..i) == "sine" then if lfo_parent.param_type[i] == 1 or lfo_parent.param_type[i] == 2 or lfo_parent.param_type[i] == 9 then value = util.round(value,1) end value = util.clamp(value,min,max) lfo_parent.actions[lfo_parent.targets[i]](value) - elseif params:string("lfo_shape_"..group.."_"..i) == "square" then + elseif params:string("p_lfo_shape_"..group.."_"..i) == "square" then local square_value; square_value = value >= mid and max or min square_value = util.linlin(min,max,scaled_min,scaled_max,square_value) square_value = util.clamp(square_value,min,max) lfo_parent.actions[lfo_parent.targets[i]](square_value) - elseif params:string("lfo_shape_"..group.."_"..i) == "random" then + elseif params:string("p_lfo_shape_"..group.."_"..i) == "random" then local prev_value = lfo_parent.rand_values[i] lfo_parent.rand_values[i] = value >= mid and max or min local rand_value; @@ -266,7 +266,7 @@ function LFO:register(param, parent_group, fn) table.insert(self.groups[parent_group].targets, param) self.groups[parent_group].available = self.groups[parent_group].available - 1 else - print("LFO ERROR: limit of "..LFO.max_per_group.." entries per LFO group, ignoring "..parent_group.." / "..param) + print("PARAMETER LFO ERROR: limit of "..LFO.max_per_group.." entries per LFO group, ignoring "..parent_group.." / "..param) goto done end @@ -302,21 +302,21 @@ end function LFO:add_params(parent_group, separator_name, silent) if not main_header_added and separator_name ~= nil then - params:add_separator(separator_name) + params:add_separator('p_lfo_header', separator_name) main_header_added = true end local group = parent_group - params:add_group(group, 12 * #self.groups[group].targets) + params:add_group('p_lfo_grp_'..group, group, 12 * #self.groups[group].targets) for i = 1,#self.groups[group].targets do local target_id = self.groups[group].targets[i] self.groups[group].param_type[i] = params:lookup_param(target_id).t - params:add_separator(params:lookup_param(target_id).name) + params:add_separator('p_lfo_sep_'..params:lookup_param(target_id).id, params:lookup_param(target_id).name) - params:add_option("lfo_"..group.."_"..i,"lfo",{"off","on"},1) - params:set_action("lfo_"..group.."_"..i,function(x) + params:add_option("p_lfo_"..group.."_"..i,"lfo",{"off","on"},1) + params:set_action("p_lfo_"..group.."_"..i,function(x) sync_lfos(group, i) if x == 1 then return_param_to_baseline(group, i) @@ -326,8 +326,8 @@ function LFO:add_params(parent_group, separator_name, silent) end end) - params:add_number("lfo_depth_"..group.."_"..i,"depth",0,100,0,function(param) return (param:get().."%") end) - params:set_action("lfo_depth_"..group.."_"..i, function(x) + params:add_number("p_lfo_depth_"..group.."_"..i,"depth",0,100,0,function(param) return (param:get().."%") end) + params:set_action("p_lfo_depth_"..group.."_"..i, function(x) if x == 0 then return_param_to_baseline(group, i) end @@ -342,54 +342,54 @@ function LFO:add_params(parent_group, separator_name, silent) else position_options = {"from min", "from center", "from max"} end - params:add_option("lfo_position_"..group.."_"..i, "lfo position", position_options, 1) + params:add_option("p_lfo_position_"..group.."_"..i, "lfo position", position_options, 1) - params:add_option("lfo_mode_"..group.."_"..i, "lfo mode", {"clocked","free"},1) - params:set_action("lfo_mode_"..group.."_"..i, + params:add_option("p_lfo_mode_"..group.."_"..i, "lfo mode", {"clocked","free"},1) + params:set_action("p_lfo_mode_"..group.."_"..i, function(x) - if x == 1 and params:string("lfo_"..group.."_"..i) == "on" then - params:hide("lfo_free_"..group.."_"..i) - params:show("lfo_clocked_"..group.."_"..i) - self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("lfo_clocked_"..group.."_"..i)] * 4) - elseif x == 2 and params:string("lfo_"..group.."_"..i) == "on" then - params:hide("lfo_clocked_"..group.."_"..i) - params:show("lfo_free_"..group.."_"..i) - self.groups[group].freqs[i] = params:get("lfo_free_"..group.."_"..i) + if x == 1 and params:string("p_lfo_"..group.."_"..i) == "on" then + params:hide("p_lfo_free_"..group.."_"..i) + params:show("p_lfo_clocked_"..group.."_"..i) + self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("p_lfo_clocked_"..group.."_"..i)] * 4) + elseif x == 2 and params:string("p_lfo_"..group.."_"..i) == "on" then + params:hide("p_lfo_clocked_"..group.."_"..i) + params:show("p_lfo_free_"..group.."_"..i) + self.groups[group].freqs[i] = params:get("p_lfo_free_"..group.."_"..i) end _menu.rebuild_params() end ) - params:add_option("lfo_clocked_"..group.."_"..i, "lfo rate", self.rates_as_strings, 9) - params:set_action("lfo_clocked_"..group.."_"..i, + params:add_option("p_lfo_clocked_"..group.."_"..i, "lfo rate", self.rates_as_strings, 9) + params:set_action("p_lfo_clocked_"..group.."_"..i, function(x) - if params:string("lfo_mode_"..group.."_"..i) == "clocked" then + if params:string("p_lfo_mode_"..group.."_"..i) == "clocked" then self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[x] * 4) end end ) params:add{ type='control', - id="lfo_free_"..group.."_"..i, + id="p_lfo_free_"..group.."_"..i, name="lfo rate", controlspec=controlspec.new(0.001,4,'exp',0.001,0.05,'hz',0.001) } - params:set_action("lfo_free_"..group.."_"..i, + params:set_action("p_lfo_free_"..group.."_"..i, function(x) - if params:string("lfo_mode_"..group.."_"..i) == "free" then + if params:string("p_lfo_mode_"..group.."_"..i) == "free" then self.groups[group].freqs[i] = x end end ) - params:add_option("lfo_shape_"..group.."_"..i, "lfo shape", {"sine","square","random"},1) + params:add_option("p_lfo_shape_"..group.."_"..i, "lfo shape", {"sine","square","random"},1) - params:add_trigger("lfo_reset_"..group.."_"..i, "reset lfo") - params:set_action("lfo_reset_"..group.."_"..i, function(x) reset_lfo_phase(group,i) end) + params:add_trigger("p_lfo_reset_"..group.."_"..i, "reset lfo") + params:set_action("p_lfo_reset_"..group.."_"..i, function(x) reset_lfo_phase(group,i) end) - params:add_option("lfo_reset_target_"..group.."_"..i, "reset lfo to", {"floor","ceiling"}, 1) + params:add_option("p_lfo_reset_target_"..group.."_"..i, "reset lfo to", {"floor","ceiling"}, 1) - params:hide("lfo_free_"..group.."_"..i) + params:hide("p_lfo_free_"..group.."_"..i) end lfos_all_loaded[group] = true From 12843e7a719ea537e3ccd6240748d195b41f1245 Mon Sep 17 00:00:00 2001 From: dan derks Date: Tue, 19 Jul 2022 16:41:02 -0400 Subject: [PATCH 09/10] rename to 'param-lfo' --- lua/core/script.lua | 4 ++-- lua/lib/{param_lfo.lua => param-lfo.lua} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename lua/lib/{param_lfo.lua => param-lfo.lua} (99%) diff --git a/lua/core/script.lua b/lua/core/script.lua index 8426e744e..c2605a245 100644 --- a/lua/core/script.lua +++ b/lua/core/script.lua @@ -27,8 +27,8 @@ Script.clear = function() package.loaded['asl'] = nil end - if package.loaded['param_lfo'] then - package.loaded['param_lfo'] = nil + if package.loaded['param-lfo'] then + package.loaded['param-lfo'] = nil end -- script local state diff --git a/lua/lib/param_lfo.lua b/lua/lib/param-lfo.lua similarity index 99% rename from lua/lib/param_lfo.lua rename to lua/lib/param-lfo.lua index 1ad1a57a0..6ae353390 100644 --- a/lua/lib/param_lfo.lua +++ b/lua/lib/param-lfo.lua @@ -1,5 +1,5 @@ --- module for creating parameter LFOs --- @module lib.param_lfo +-- @module lib.param-lfo -- @release v1.0 -- @author dndrks -- adapted from code examples by Mark Eats (Changes) + justmat (hnds) From 628a8335b36e9b499379ff8a0f9285b875a58025 Mon Sep 17 00:00:00 2001 From: dan derks Date: Wed, 20 Jul 2022 13:14:11 -0400 Subject: [PATCH 10/10] p_lfo -> plfo just cosmetic, but looks way better --- lua/lib/param-lfo.lua | 140 +++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/lua/lib/param-lfo.lua b/lua/lib/param-lfo.lua index 6ae353390..d16b8947c 100644 --- a/lua/lib/param-lfo.lua +++ b/lua/lib/param-lfo.lua @@ -38,26 +38,26 @@ end local function lfo_params_visibility(state, group, i) if lfos_all_loaded[group] then - params[state](params, "p_lfo_position_"..group.."_"..i) - params[state](params, "p_lfo_depth_"..group.."_"..i) - params[state](params, "p_lfo_mode_"..group.."_"..i) + params[state](params, "plfo_position_"..group.."_"..i) + params[state](params, "plfo_depth_"..group.."_"..i) + params[state](params, "plfo_mode_"..group.."_"..i) if state == "show" then - if params:get("p_lfo_mode_"..group.."_"..i) == 1 then - params:hide("p_lfo_free_"..group.."_"..i) - params:show("p_lfo_clocked_"..group.."_"..i) - elseif params:get("p_lfo_mode_"..group.."_"..i) == 2 then - params:hide("p_lfo_clocked_"..group.."_"..i) - params:show("p_lfo_free_"..group.."_"..i) + if params:get("plfo_mode_"..group.."_"..i) == 1 then + params:hide("plfo_free_"..group.."_"..i) + params:show("plfo_clocked_"..group.."_"..i) + elseif params:get("plfo_mode_"..group.."_"..i) == 2 then + params:hide("plfo_clocked_"..group.."_"..i) + params:show("plfo_free_"..group.."_"..i) end else - params:hide("p_lfo_clocked_"..group.."_"..i) - params:hide("p_lfo_free_"..group.."_"..i) + params:hide("plfo_clocked_"..group.."_"..i) + params:hide("plfo_free_"..group.."_"..i) end - params[state](params, "p_lfo_shape_"..group.."_"..i) - params[state](params, "p_lfo_min_"..group.."_"..i) - params[state](params, "p_lfo_max_"..group.."_"..i) - params[state](params, "p_lfo_reset_"..group.."_"..i) - params[state](params, "p_lfo_reset_target_"..group.."_"..i) + params[state](params, "plfo_shape_"..group.."_"..i) + params[state](params, "plfo_min_"..group.."_"..i) + params[state](params, "plfo_max_"..group.."_"..i) + params[state](params, "plfo_reset_"..group.."_"..i) + params[state](params, "plfo_reset_target_"..group.."_"..i) _menu.rebuild_params() end end @@ -76,7 +76,7 @@ local function build_lfo_spec(group,i,bound) if param_spec.t == 1 then params:add{ type = 'number', - id = 'p_lfo_'..bound..'_'..group..'_'..i, + id = 'plfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, min = param_spec.min, max = param_spec.max, @@ -87,7 +87,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 2 then params:add{ type = 'option', - id = 'p_lfo_'..bound..'_'..group..'_'..i, + id = 'plfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, options = param_spec.option, default = (bound == nil and param_spec.value or (bound == 'min' and 1 or (bound == 'current' and params:get(lfo_target) or param_spec.count))) @@ -96,7 +96,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 3 then params:add{ type = 'control', - id = 'p_lfo_'..bound..'_'..group..'_'..i, + id = 'plfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, controlspec = controlspec.new( param_spec.controlspec.minval, @@ -114,7 +114,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 5 then params:add{ type = 'taper', - id = 'p_lfo_'..bound..'_'..group..'_'..i, + id = 'plfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, min = param_spec.min, max = param_spec.max, @@ -126,7 +126,7 @@ local function build_lfo_spec(group,i,bound) elseif param_spec.t == 9 then params:add{ type = 'control', - id = 'p_lfo_'..bound..'_'..group..'_'..i, + id = 'plfo_'..bound..'_'..group..'_'..i, name = 'lfo '..bound, controlspec = controlspec.new( 0, @@ -154,18 +154,18 @@ end local function reset_lfo_phase(group,which) if which == nil then for i = 1, #LFO.groups[group].targets do - LFO.groups[group].progress[i] = math.pi * (params:string("p_lfo_reset_target_"..group.."_"..i) == "floor" and 1.5 or 2.5) + LFO.groups[group].progress[i] = math.pi * (params:string("plfo_reset_target_"..group.."_"..i) == "floor" and 1.5 or 2.5) end else - LFO.groups[group].progress[which] = math.pi * (params:string("p_lfo_reset_target_"..group.."_"..which) == "floor" and 1.5 or 2.5) + LFO.groups[group].progress[which] = math.pi * (params:string("plfo_reset_target_"..group.."_"..which) == "floor" and 1.5 or 2.5) end end local function sync_lfos(group, i) - if params:get("p_lfo_mode_"..group.."_"..i) == 1 then - LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("p_lfo_clocked_"..group.."_"..i)] * 4) + if params:get("plfo_mode_"..group.."_"..i) == 1 then + LFO.groups[group].freqs[i] = 1/(clock.get_beat_sec() * LFO.rates[params:get("plfo_clocked_"..group.."_"..i)] * 4) else - LFO.groups[group].freqs[i] = params:get("p_lfo_free_"..group.."_"..i) + LFO.groups[group].freqs[i] = params:get("plfo_free_"..group.."_"..i) end end @@ -176,8 +176,8 @@ local function process_lfo(group) for i = 1,#lfo_parent.targets do lfo_parent.progress[i] = lfo_parent.progress[i] + delta * lfo_parent.freqs[i] - local min = params:get("p_lfo_min_"..group.."_"..i) - local max = params:get("p_lfo_max_"..group.."_"..i) + local min = params:get("plfo_min_"..group.."_"..i) + local max = params:get("plfo_max_"..group.."_"..i) if min > max then local old_min = min local old_max = max @@ -185,54 +185,54 @@ local function process_lfo(group) max = old_min end - local percentage = math.abs(min-max) * (params:get("p_lfo_depth_"..group.."_"..i)/100) + local percentage = math.abs(min-max) * (params:get("plfo_depth_"..group.."_"..i)/100) local value = util.linlin(-1,1,min,min + percentage,math.sin(lfo_parent.progress[i])) - if value ~= lfo_parent.values[i] and (params:get("p_lfo_depth_"..group.."_"..i)/100 > 0) then + if value ~= lfo_parent.values[i] and (params:get("plfo_depth_"..group.."_"..i)/100 > 0) then lfo_parent.values[i] = value - if params:string("p_lfo_"..group.."_"..i) == "on" then + if params:string("plfo_"..group.."_"..i) == "on" then local mid; local scaled_min; local scaled_max; - if params:string("p_lfo_position_"..group.."_"..i) == 'from min' then + if params:string("plfo_position_"..group.."_"..i) == 'from min' then scaled_min = min scaled_max = min + percentage mid = util.linlin(min,max,scaled_min,scaled_max,(min+max)/2) - elseif params:string("p_lfo_position_"..group.."_"..i) == 'from center' then + elseif params:string("plfo_position_"..group.."_"..i) == 'from center' then mid = (min+max)/2 - local centroid_mid = math.abs(min-max) * ((params:get("p_lfo_depth_"..group.."_"..i)/100)/2) + local centroid_mid = math.abs(min-max) * ((params:get("plfo_depth_"..group.."_"..i)/100)/2) scaled_min = mid - centroid_mid scaled_max = mid + centroid_mid value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) - elseif params:string("p_lfo_position_"..group.."_"..i) == 'from max' then + elseif params:string("plfo_position_"..group.."_"..i) == 'from max' then mid = (min+max)/2 value = max - value - scaled_min = max - (math.abs(min-max) * (params:get("p_lfo_depth_"..group.."_"..i)/100)) + scaled_min = max - (math.abs(min-max) * (params:get("plfo_depth_"..group.."_"..i)/100)) scaled_max = max mid = math.abs(util.linlin(min,max,scaled_min,scaled_max,mid)) value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) - elseif params:string("p_lfo_position_"..group.."_"..i) == 'from current' then + elseif params:string("plfo_position_"..group.."_"..i) == 'from current' then mid = params:get(lfo_parent.targets[i]) - local centroid_mid = math.abs(min-max) * ((params:get("p_lfo_depth_"..group.."_"..i)/100)/2) + local centroid_mid = math.abs(min-max) * ((params:get("plfo_depth_"..group.."_"..i)/100)/2) scaled_min = mid - centroid_mid scaled_max = mid + centroid_mid value = util.linlin(-1,1,scaled_min, scaled_max, math.sin(lfo_parent.progress[i])) end - if params:string("p_lfo_shape_"..group.."_"..i) == "sine" then + if params:string("plfo_shape_"..group.."_"..i) == "sine" then if lfo_parent.param_type[i] == 1 or lfo_parent.param_type[i] == 2 or lfo_parent.param_type[i] == 9 then value = util.round(value,1) end value = util.clamp(value,min,max) lfo_parent.actions[lfo_parent.targets[i]](value) - elseif params:string("p_lfo_shape_"..group.."_"..i) == "square" then + elseif params:string("plfo_shape_"..group.."_"..i) == "square" then local square_value; square_value = value >= mid and max or min square_value = util.linlin(min,max,scaled_min,scaled_max,square_value) square_value = util.clamp(square_value,min,max) lfo_parent.actions[lfo_parent.targets[i]](square_value) - elseif params:string("p_lfo_shape_"..group.."_"..i) == "random" then + elseif params:string("plfo_shape_"..group.."_"..i) == "random" then local prev_value = lfo_parent.rand_values[i] lfo_parent.rand_values[i] = value >= mid and max or min local rand_value; @@ -302,21 +302,21 @@ end function LFO:add_params(parent_group, separator_name, silent) if not main_header_added and separator_name ~= nil then - params:add_separator('p_lfo_header', separator_name) + params:add_separator('plfo_header', separator_name) main_header_added = true end local group = parent_group - params:add_group('p_lfo_grp_'..group, group, 12 * #self.groups[group].targets) + params:add_group('plfo_grp_'..group, group, 12 * #self.groups[group].targets) for i = 1,#self.groups[group].targets do local target_id = self.groups[group].targets[i] self.groups[group].param_type[i] = params:lookup_param(target_id).t - params:add_separator('p_lfo_sep_'..params:lookup_param(target_id).id, params:lookup_param(target_id).name) + params:add_separator('plfo_sep_'..params:lookup_param(target_id).id, params:lookup_param(target_id).name) - params:add_option("p_lfo_"..group.."_"..i,"lfo",{"off","on"},1) - params:set_action("p_lfo_"..group.."_"..i,function(x) + params:add_option("plfo_"..group.."_"..i,"lfo",{"off","on"},1) + params:set_action("plfo_"..group.."_"..i,function(x) sync_lfos(group, i) if x == 1 then return_param_to_baseline(group, i) @@ -326,8 +326,8 @@ function LFO:add_params(parent_group, separator_name, silent) end end) - params:add_number("p_lfo_depth_"..group.."_"..i,"depth",0,100,0,function(param) return (param:get().."%") end) - params:set_action("p_lfo_depth_"..group.."_"..i, function(x) + params:add_number("plfo_depth_"..group.."_"..i,"depth",0,100,0,function(param) return (param:get().."%") end) + params:set_action("plfo_depth_"..group.."_"..i, function(x) if x == 0 then return_param_to_baseline(group, i) end @@ -342,54 +342,54 @@ function LFO:add_params(parent_group, separator_name, silent) else position_options = {"from min", "from center", "from max"} end - params:add_option("p_lfo_position_"..group.."_"..i, "lfo position", position_options, 1) + params:add_option("plfo_position_"..group.."_"..i, "lfo position", position_options, 1) - params:add_option("p_lfo_mode_"..group.."_"..i, "lfo mode", {"clocked","free"},1) - params:set_action("p_lfo_mode_"..group.."_"..i, + params:add_option("plfo_mode_"..group.."_"..i, "lfo mode", {"clocked","free"},1) + params:set_action("plfo_mode_"..group.."_"..i, function(x) - if x == 1 and params:string("p_lfo_"..group.."_"..i) == "on" then - params:hide("p_lfo_free_"..group.."_"..i) - params:show("p_lfo_clocked_"..group.."_"..i) - self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("p_lfo_clocked_"..group.."_"..i)] * 4) - elseif x == 2 and params:string("p_lfo_"..group.."_"..i) == "on" then - params:hide("p_lfo_clocked_"..group.."_"..i) - params:show("p_lfo_free_"..group.."_"..i) - self.groups[group].freqs[i] = params:get("p_lfo_free_"..group.."_"..i) + if x == 1 and params:string("plfo_"..group.."_"..i) == "on" then + params:hide("plfo_free_"..group.."_"..i) + params:show("plfo_clocked_"..group.."_"..i) + self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[params:get("plfo_clocked_"..group.."_"..i)] * 4) + elseif x == 2 and params:string("plfo_"..group.."_"..i) == "on" then + params:hide("plfo_clocked_"..group.."_"..i) + params:show("plfo_free_"..group.."_"..i) + self.groups[group].freqs[i] = params:get("plfo_free_"..group.."_"..i) end _menu.rebuild_params() end ) - params:add_option("p_lfo_clocked_"..group.."_"..i, "lfo rate", self.rates_as_strings, 9) - params:set_action("p_lfo_clocked_"..group.."_"..i, + params:add_option("plfo_clocked_"..group.."_"..i, "lfo rate", self.rates_as_strings, 9) + params:set_action("plfo_clocked_"..group.."_"..i, function(x) - if params:string("p_lfo_mode_"..group.."_"..i) == "clocked" then + if params:string("plfo_mode_"..group.."_"..i) == "clocked" then self.groups[group].freqs[i] = 1/(clock.get_beat_sec() * self.rates[x] * 4) end end ) params:add{ type='control', - id="p_lfo_free_"..group.."_"..i, + id="plfo_free_"..group.."_"..i, name="lfo rate", controlspec=controlspec.new(0.001,4,'exp',0.001,0.05,'hz',0.001) } - params:set_action("p_lfo_free_"..group.."_"..i, + params:set_action("plfo_free_"..group.."_"..i, function(x) - if params:string("p_lfo_mode_"..group.."_"..i) == "free" then + if params:string("plfo_mode_"..group.."_"..i) == "free" then self.groups[group].freqs[i] = x end end ) - params:add_option("p_lfo_shape_"..group.."_"..i, "lfo shape", {"sine","square","random"},1) + params:add_option("plfo_shape_"..group.."_"..i, "lfo shape", {"sine","square","random"},1) - params:add_trigger("p_lfo_reset_"..group.."_"..i, "reset lfo") - params:set_action("p_lfo_reset_"..group.."_"..i, function(x) reset_lfo_phase(group,i) end) + params:add_trigger("plfo_reset_"..group.."_"..i, "reset lfo") + params:set_action("plfo_reset_"..group.."_"..i, function(x) reset_lfo_phase(group,i) end) - params:add_option("p_lfo_reset_target_"..group.."_"..i, "reset lfo to", {"floor","ceiling"}, 1) + params:add_option("plfo_reset_target_"..group.."_"..i, "reset lfo to", {"floor","ceiling"}, 1) - params:hide("p_lfo_free_"..group.."_"..i) + params:hide("plfo_free_"..group.."_"..i) end lfos_all_loaded[group] = true