Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add input quantum + wrap to controlspec, add wrap to number param #1149

Merged
merged 2 commits into from Jun 30, 2020

Conversation

@csboling
Copy link
Contributor

@csboling csboling commented Jun 30, 2020

Fixes #1144

Adds a quantum arg to controlspec which is used to define the fraction of the value range that params:delta adjusts by, rather than this being fixed at 1% of the range.

It is also sometimes useful to have params with values that wrap around rather than clamping, e.g. angles -- this is the case for the script I'm currently working on which is why I started messing with this. Added a wrap option to both control and number params.

Since this winds up being a lot of args on ControlSpec.new now I added a ControlSpec.def method which accepts a table -- I looked around a bit but I'm not sure what if any naming convention exists for positional vs keyword-argument style constructors. The table args for ControlSpec.def are min and max for consistency with params:add, rather than minvalue and maxvalue as the positional args are named. Perhaps the positional args should be changed to min and max for clarity of the luadocs?

Test script for all the new functionality:

function init()
  params:add{
    type='control',
    id='ctl',
    name='ctl',
    controlspec=controlspec.def{
      min=0,
      max=10,
      warp='lin',
      step=0.01,
      default=0,
      quantum=0.05,
      wrap=true,
    },
  }
  params:add{
    type='number',
    id='num',
    name='num',
    min=0,
    max=3,
    wrap=true,
  }
end

function enc(n, d)
  if n == 2 then
    params:delta('ctl', d)
    redraw()
  end
  if n == 3 then
    params:delta('num', d * 0.1)
    redraw()
  end
end

function redraw()
  screen.clear()
  screen.move(0, 8)
  screen.text('ctl: ' .. params:get('ctl'))
  screen.move(0, 16)
  screen.text('num: ' .. params:get('num'))
  screen.update()
end
@tehn
tehn approved these changes Jun 30, 2020
Copy link
Member

@tehn tehn left a comment

this is fantastic, thank you. it makes so much sense to use a table initializer for controldefs, and the wrap feature is a very helpful addition.

i agree on renaming minval and maxval to min and max for consistency.

@csboling
Copy link
Contributor Author

@csboling csboling commented Jun 30, 2020

renaming minval and maxval to min and max for consistency

Addressed in 287a526 and added default values for these (0 and 1) since the table passed to ControlSpec.def might not set them.

@tehn
tehn approved these changes Jun 30, 2020
@tehn tehn merged commit d1e0a37 into monome:master Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants