monome / norns

norns is many sound instruments.
http://monome.org
GNU General Public License v3.0
633 stars 147 forks source link

fix lfo constructor ahead of params #1753

Closed dndrks closed 10 months ago

dndrks commented 10 months ago

as reported at lines, creating an LFO using the constructor methods should automatically populate the relevant settings when :add_params is invoked.

mode and reset_target were not being set as parameters correctly, as their values were not being matched to the table of options -- instead of doing a key lookup, i had accidentally passed the string values as the index. period was also not being handled correctly. i also needed to extend the group parameter count.

this PR corrects these issues!

test script:

_lfos = require 'lfo' -- assign the library to a general variable
engine.name = 'PolyPerc'
s = require 'sequins'

function init()
  hz_vals = s{400,600,200,350}
  sync_vals = s{1,1/3,1/2,1/6,2}
  clock.run(iter)

  screen_dirty = true

  -- IMPORTANT! set your LFO's 'min' and 'max' *before* adding params, so they can scale appropriately:
  cutoff_lfo = _lfos:add{min = 200, max = 5000}
  cutoff_lfo:start()
  cutoff_lfo:set('mode','free')
  cutoff_lfo:set('depth',1)
  cutoff_lfo:set('period',2)
  -- now we can add params:
  cutoff_lfo:add_params('cutoff_lfo', 'cutoff', 'LFOs')

  cutoff_lfo:set('action', function(scaled, raw) engine.cutoff(scaled) screen_dirty = true end)

  redraw_screen = metro.init(check_dirty,1/15,-1)
  redraw_screen:start()
end

function iter()
  while true do
    clock.sync(sync_vals())
    hertz = hz_vals()
    engine.hz(hertz)
  end
end

function check_dirty()
  if screen_dirty then
    redraw()
    screen_dirty = false
  end
end

function redraw()
   screen.clear()
   screen.move(64,40)
   screen.font_size(20)
   screen.text_center(util.round(cutoff_lfo:get('scaled'),0.01)..'hz')
   screen.update()
end