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

params: align 'add_separator' and 'add_group' flow with other paramtypes #1584

Merged
merged 7 commits into from
Jul 18, 2022

Conversation

dndrks
Copy link
Member

@dndrks dndrks commented Jul 13, 2022

while scripting tonight, i realized #1539 did not anticipate situations where an author might do the following:

params:add_number('my var', 'my var', 1, 127)
[...]
params:add_separator('my var')

though it's convention to use underscores within parameter ID's, the system supports ID instantiation with spaces, so there's a chance someone will accidentally clobber their useful parameter with a separator or group name. since separators and groups do not have ID's, only names, this seems like a good guardrail.

@dndrks dndrks requested a review from tehn July 13, 2022 02:23
@tehn
Copy link
Member

tehn commented Jul 13, 2022

is this the right fix? if there is a copy of the name, then it works but doesn't have an entry in the lookup? rather should it just fail and issue an error?

@dndrks
Copy link
Member Author

dndrks commented Jul 14, 2022

for sure! i was conflicted on what would be the easiest most-right fix, honestly. all the other param types use the :add method, where these conflicts are caught, but add_separator and add_group manipulate state external to the :add method.

though i'm a little gun shy about adding any fails / error messages to the params after the issues earlier this year, i popped a few into the latest commit. full fail doesn't feel necessary, since most cases of params:lookup_param seem to be motivated by .action manipulation anyway -- having an error and no overwrite to the previous instance of the action-oriented ID when a separator or group tries to use it feels a lot more informative + actionable!

220714: i also sorta wonder if separators and groups (since their states can be scripted) should adhere to the id/name mechanism that all other parameters require. i can imagine situations where an author wouldn't likely care about separators being blocked from registration (eg. if i'm instantiating a separator named 'voice 1' across many groups of params) as well as situations where they would (eg. if i'm hoping to selectively hide/show specific 'voice 1'-named separators under certain conditions). i wonder if the option to add a unique ID to separators and groups could help clear up these cases?

@dndrks
Copy link
Member Author

dndrks commented Jul 15, 2022

i wonder if the option to add a unique ID to separators and groups could help clear up these cases?

got to spend some time on this and it works! i ended up changing :add_separator and :add_group to use the standard :add method (like all the other parameter builders), so that ID conflicts could be accurately tallied and errors printed. this required adhering to the name and id requirement of all other paramtypes, which required placing some guardrails for expected historical invocation:

separators

  • if a separator is added using params:add_separator(<name string>), then the separator's ID will be the <name string>
    • if another separator shares the same string, there is a gentle alert printed that the ID is being stolen by the most-recently-added separator instance
    • if another non-separator parameter type is already established as using that string as its ID, there is a notice that the ID collides with a non-separator and will not be overwritten
    • if another non-separator parameter type tries to use that string as its ID, maiden will post the collision warning
  • if a separator is added using params:add_separator(<id_string>, <name string>), then it registers like any other parameter to the lookup (preferred)
  • if a separator is added using params:add_separator(), then the separator's ID will register as 'separator'
    • if norns finds a conflicting 'separator' ID entry in the lookup, it will not post the collision warning (i'm assuming not identifying a separator in any way means it won't be manipulated)

groups

  • if a group is added using params:add_group(<name string>, <count>), then the group's ID will be the <name string>
    • if another group shares the same string, there is a gentle alert printed that the ID is being stolen by the most-recently-added group instance
    • if another non-group parameter type is already established as using that string as its ID, there is a notice that the ID collides with a non-group and will not be overwritten
    • if another non-group parameter type tries to use that string as its ID, maiden will post the collision warning
  • if a group is added using params:add_group(<id_string>, <name string>, <count>), then it registers like any other parameter to the lookup (preferred)
  • if a group is added using params:add_group(), then the group's ID will register as 'group' and it will have a default group of 1
    • if norns finds a conflicting 'group' entry in the lookup, it will not post the collision warning (i'm assuming not identifying a group in any way means it won't be manipulated)

in all cases, the important thing is to not add the parameter lookup for a meaningful conflict, which this addresses!

example script
function init()
  
  print("1 --------")
  -- will not error, historical use:
  params:add_group('test group one',1)
  params:add_separator('1')
  print('historical use will not error')
  
  print("2 --------")
  -- will error, as ID's are same
  params:add_group('name with spaces') -- if just name is provided, this becomes the ID
  params:add_number('name with spaces', 'name with spaces') -- ID is same as group!
  print("   ^ parameters with identical ID's will cause error")
  
  print("3 --------")
  -- will alert, as group ID's conflict:
  params:add_group('test group two', 1)
  params:add_separator('three')
  params:add_group('test group two', 1)
  params:add_separator('four')
  print("   ^ groups with identical names will alert because they do not have unique ID's")
  
  print("4 --------")
  -- will not error, group ID's provided:
  params:add_group('g_test_1', 'test group one',1)
  params:add_number('number_1a','1a', 0, 100, math.random(100))
  params:add_group('g_test_2', 'test group one',1)
  params:add_number('number_1b','1b', 0, 100, math.random(100))
  print("groups with identical names did not error because they have unique ID's")
  
  print("5 --------")
  -- will error, as separator id's conflict:
  params:add_separator('five')
  params:add_separator('five')
  print("   ^ separators with identical ID's will alert")
  
  print("6 --------")
  -- will not error, as separator id's are different:
  params:add_separator('sep_fiveA', 'five')
  params:add_separator('sep_fiveB', 'five')
  print("separators with identical names did not error because they have unique ID's")
  
  print("7 --------")
  -- will not error, as default 'separator' ID is skipped:
  params:add_separator()
  params:add_separator()
  print("separators without ID's or names are given 'separator' as an ID, but norns will not call it out as an error")
  
  print("8 --------")
  -- will not error, as default 'group' ID is skipped:
  params:add_group()
  params:add_separator('example_8a','hello')
  params:add_group()
  params:add_separator('example_8b','good to see you')
  print("groups without ID's or names are given 'group' as an ID, but norns will not call it out as an error")
end

please feel free to lmk if this all feels aligned or if there's more to consider! i just wanna get all param types using the same basic building blocks, totally open to any redirects / feedback -- tyty!

@dndrks dndrks changed the title hotfix: if separator or group name is already registered, do not overwrite params: align 'add_separator' and 'add_group' flow with other paramtypes Jul 15, 2022
@dndrks
Copy link
Member Author

dndrks commented Jul 15, 2022

ok, ready for real now -- sorry for the extra traffic!

@tehn tehn merged commit 2e2164e into main Jul 18, 2022
@tehn tehn deleted the params-separator-hotfix branch July 18, 2022 19:10
@dndrks
Copy link
Member Author

dndrks commented Jul 19, 2022

had a quick thought, @tehn -- entering MAP mode on params surfaces the param ID for each parameter, but the current code excludes separators and groups from this changeover. do we want to retain this behavior now that groups and separators can have ID's? if only a single string is provided at instantiation (eg. historical use of passing a name only), the ID defaults to the name, so shouldn't cause any backwards compatibility issues and i could see an author using the MAP mode to double-check their parameter IDs populate correctly.

just lmk which way you feel we should go and i'll propose the small change in another PR if we should adjust!

tehn added a commit that referenced this pull request Sep 27, 2023
* add PSET number to PSET actions + add delete action (#1544)

* add PSET number to callbacks + add delete callback

* fix passing pset_number in delete action

* Revert "fix passing pset_number in delete action"

This reverts commit 7f98bb2.

* fix pset_number in read action

* clean up formatting

* remove unnecessary nil checks

* update paramset docs

* fix parameter name passing to params:delete

* add pset_number to docs

* releases.txt

* remove nonexistent post_filter_fc_mod command from softcut param factory

* Update pmap.lua

* typo fix (#1560)

* fix registration for screen_display_image_region

* Update readme.md

* add note to readme regarding release flag

* use abl_link C API for link clock

* init session state

* add param separators to lookup table (#1539)

* add param separators to lookup table for hide/show

* add unnamed failsafe

* add visibility lookup for strings

* fix name forcing

* cleanup DSP 'lab work' folder (#1580)

* add script-definable action for when clock tempo changes (#1575)

* add clock.temo_changed callback

* clean up naming

* reset handler when clocks are cleaned up

* fold in artem's feedback

* remove 'source' pass, remove redundant nils

* params: align 'add_separator' and 'add_group' flow with other paramtypes (#1584)

* protect against casual param naming

* protect groups, too

* add error message

* change separator and group addition

* specify overwrite conditions

* overwrite flag allows for continuity for param count

* allow hidden param to be registered

* add parameter-based lfo scripting library (#1585)

* initial upload + unload lfo's after use

* default = 'param action' and track fn mapping

* add function type lookup table

* add ldoc notes

* bars -> clocked

* no spaces in param IDs

* remove 'frm', not used

* rename library to 'param_lfo'

* rename to 'param-lfo'

* p_lfo -> plfo

just cosmetic, but looks way better

* apply menu password entry to SMB + hotspot (#1570)

* unify smb + hotspot password change

* Update link

* Revert "Update link"

This reverts commit 55fff78.

* Revert "Merge branch 'main' into password-helper"

This reverts commit 66fe798, reversing
changes made to 651d7c0.

* Revert "Revert "Merge branch 'main' into password-helper""

This reverts commit b797f04.

* maiden inaccessible

* robust message for hotspot password change

* fix to add midi data when device is removed (issue #1557)  (#1562)

* typo fix

* fix to add midi data when device is removed (issue #1557)

code fixed and doc info updated for issue #1557: #1557

* Place downbeats correctly.

Without this change, a swing of 66 will shift some events early and some events late from where they would otherwise be. With this change, a swing of 66 leaves some beats alone, and shifts other beats late from where they would otherwise be. 

Example to evaluate change, run as a norns script:

```
engine.name = "PolyPerc"
local lattice = require("lattice")

function init()
    l = lattice:new()
    p1 = l:new_pattern{
        enabled = true,
        division = 1/4,
        action = function(t)
            print("q", t)
            engine.hz(440) 
        end,
    }
    p2 = l:new_pattern{
        enabled = true,
        division = 1/8,
        swing = 66,
        action = function(t)
            print("e", t)
            engine.hz(660)
        end,
    }
    l:start()
end
```

In this example, the expected behavior is that two events (440 and 660) fall on the "down" beat, and then one (660) falls on the "up" beat, but with a "triplet feel". Without the change we get the "eighth notes" falling before and after the quarter note, but not on it.

* Revert "add parameter-based lfo scripting library (#1585)" (#1588)

This reverts commit 221531a.

* Revert "fix to add midi data when device is removed (issue #1557)  (#1562)" (#1589)

This reverts commit a808394.

* add 'lfo' (#1591)

* add lib/lfospec

a general-purpose scripting library for establishing LFOs, with optional parameter UI control

* add lfospec attributions

* protect against nil IDs

* add note about clocks + start/stop with parameter menu

* update params per entry

* Use lattice for LFOs, so they share clocks, and allow setting ppqn

* attribution and unused var cleanup

* change name and fold in feedback

* register 'norns.lfo' table, manage from script.lua

* Update script.lua

* check for nil norns.lfo

* remove note about clocks

since using lattice, there's no worry about counting clocks

* add API text to LFO:add

okay, this is the last touch! sorry for all the final countdown updates 😬

Co-authored-by: Naomi Seyfer <naomi@seyfer.org>

* execute global Midi.remove callback (#1590)

this runs the global, customizable midi device removal callback when a device is unplugged (if the device is registered by the norns midi system), in addition to and without affecting the per-device removal callback (if defined.)

alternative to PR #1562, addressing issue #1557

* 220802

* releases.txt

* hotfix: lfo `:add` (#1593)

* hotfix: lfo `:add`

gah! the `:add` method wasn't properly invoking the `.new` function

* Update lfo.lua

* rest of the lfo hotfix (#1594)

* hotfix: lfo `:add`

gah! the `:add` method wasn't properly invoking the `.new` function

* Update lfo.lua

* Update lfo.lua

* releases.txt

* gamepad support (#1439)

* basic gamepad support w/ whitelist

* basic support for gamepad in global menu

* fix missing clear callback

* handling of analog joysticks & numeric dpads

* optim: faster lookup of event code 2 axis

* (cont.)

* fix bad name for axis properties

* bug fixes, catchall axis callback vs dpad/apad

* rename `apad` into `astick` (analog stick)

* mark dpad as naalog for bufalo model, fix typo

* do not debug log

* do not add separators to PSET file (#1598)

* fixed screen curve param descriptions (#1603)

* Update paramset.lua (#1605)

* expand acceptable accum CC values (#1606)

a tiny change that allows controllers to send any CC value above 64 for "up" and any below for "down". previously it had to just be 65 and 63 which isn't supported by all controllers.

* add TAPE previewing to fileselect (#1607)

* add previewing to fileselect

* working

* stop previewing on key and always on left scroll

* Tweaks to the keyboard (#1611)

* handle osc messages for the keyboard

* change parameters with +/- keys

* allow holding key to scroll menu

* toggle menu with F5 key

* goto menu if F1-4 are pressed

* add version error (#1613)

* add previewing to fileselect

* working

* stop previewing on key and always on left scroll

* add version error message

* working

* address issue #1612 (#1617)

adds a call to the script-defined `clock.tempo_change_handler` function whenever the `clock_tempo` parameter is changed in the parameters UI from an external source

* work on lattice v2 (#1616)

* work on v2

* preserve 'new_pattern' for backwards-compatibility

* quarter note is good actually lol

* incorporate tyler's comments

* docblock, comments, and semantic changes

Co-authored-by: Tyler Etters <tyler@etters.co>

* fix `_menu.keychar` not getting called (#1619)

* prevent global menu shortcut messing up w/ sub-menu's (#1620)

* fix undefined `gamepad` when `script.clear` gets called (#1621)

* fix: document sprocket ordering (#1625)

* update lfo lib to use lattice sprockets (#1626)

* add password length failsafes for WPA-PSK (#1627)

WPA-PSK requires a sequence between 8 and 63 ASCII characters, so if a user uses this prompt to change their password to something shorter, then they won't be able to access hotspot (due to the conveniences added by #1570).

to help guardrail, this commit adds:
- an on-screen `textentry` check which shows a countdown to 8 characters and a warning if the password goes beyond 63
- a character count check to `m.passdone`, which will only change all passwords if the string length is >= 8 and < 64, otherwise it prints warnings to maiden that the password has not been changed

* 221214

* releases.txt

* update.sh fix

* update docs

* releases.txt

* `new_pattern` was missing return keyword (#1629)

* lfo fixes + improvements (#1630)

fixed locally global variables for `scaled_min` / `scaled_max`, `mid`, and `rand_value`, which interfered with square and random waves when multiple LFOs were running with different min/max values.

added `mid: rising` and `mid: falling` as options for the `reset_target`, which allows more control over how the reset affects the starting value

* add osc.cleanup() to script.lua (#1643)

* allow sending midi clock to all devices simultaneously (#1642)

* Add files via upload

* toggles for targeting device clock out

builds out @tehn's feedback from #1642 :
- any currently-ported midi device will populate in the 'midi clock out' section of 'PARAMS > CLOCK'
- each visible entry has a toggle to receive norns clock
- toggles get saved/restored as part of `system.state` during clean reboots

follow the approach brian outlined actually saves us from doing any if's during each clock tick!

* longer short name

cleaned up formatting to match the SYSTEM > DEVICES > MIDI syntax, which allows for up to 20 characters to display comfortably before aliasing

Co-authored-by: dan derks <derks.dan@gmail.com>

* fix lattice transport value getting increased in steps of 5 (#1638)

* fix lattice ppqn resolution divded by 5

* order sprockets once per pulse

* Make maiden-repl compile on macOS 13.1 Ventura (#1645)

* Change wrap to use math instead of iteration, and happen in constant time (#1577)

* clean up device callbacks (#1646)

* remove unnecessary _menu.rebuild_params() (#1647)

this gets called elsewhere throughout the stack (including MIDI device add/remove), which makes this unnecessary -- it also seems to cause race-condition conflicts as the rebuild attempts to index parameters which don't yet exist

* Update device_midi.c

blind fix attempt for dropped sysex bytes

* fix typo (want stop byte not start byte)

* Add UK keyboard option. (#1651)

* Remove error from unknown key press. (#1654)

* fix argument indices for buffer_clear_region_channel (#1656)

this is a blind fix attempt for issue #1652

* lua NRT processing function (#1634)

* not working

* still not working

* first draft

* fix typo

* refactor: attempt to pass buffer data rather than function

* catch silly typo

* process_chunk should match OscInterface.cpp

* working! refactor to allow longer sections to be processed

* fix errors

* catch typos

* refactor to use shared memory

* attempt to not cause stack overflow, fix wscript so norns ./wafs correctly

* catch typo, add debug prints

* attempt to prevent poke failing to open shared memory

* strange not-working place

* catch small typo, add debug print

* attempt to prevent error on second call to process

* working

* refactor to use clocks to chunk up softcut_process

* fix weaver bugs, change lua API

* fix: catch typo

* Update docs for screen.fill() and screen.stroke(). (#1660)

* new crow4 features on norns (#1662)

* run ldoc

* regenerate docs

* better separator labeling in core params (#1665)

* better separator labeling

* Update audio.lua

* reduce 'send_midi_clock' var scope (#1666)

during release testing, i realized that after my ~40th script load, `clock.sync` calls were off by a tenth of a beat, compounding as i continued to load scripts.

when i verified #b932b0d sparked the issue's emergence, i realized that the `send_midi_clock` table was being added to each time `clock.add_params()` was called, but never emptied out. so, eventually, the clock was doing 24ppqn calls on a table with *tons* of entries.

i guess nice to accidentally stress-test that a lot of devices could receive MIDI clock before timing issues emerged? anyway, fixed now!

* Implement character/key conversion (#1659)

* Implement character/key conversion.

* Remove char_to_code().

* [mergeable] rework `gamepad` to handle more edge-cases (#1624)

* rework gamepad to handle more edge-cases

* woops

* SDL-format GUID generation for HID devices

* (cont., missed this one binding)

* use this new GUID as id in known controller models table

* add guid in controller conf, some 8bitdo masquerade as xbox 360

* log guid

* actually use guid in `gamepad.process` callback

* analog btn support, fix std order X axis, no meta btn state

* fix value of sign in gamepad.axis() when analog button

* remove dead code

* re-introduce denoize for analog buttons, comments

* call gamepad.analog after computing state

* on sensors, negative half is generally 1+ bigger than positive one

* tweak submenu integration

* disable verbose mode

* prevent trigger script cb if in menu, add _menu.analog

* prefix all new `menu` callbacks w/ `gamepad_`

* rounding the half-reso may be counter-intuitive, document instead

* sometimes lower half bigger, sometimes upper one...

* fix actual resolution for this controller

* be resilient against "lean" config files (w/ empty maps ommited)

* add system/settings menu, move items, add battery_warning (#1668)

* add system/settings menu, move items, add battery_warning

* yikes booleans

* fixes

* export png (#1669)

* changelog

* norns.expand_filesystem() (#1670)

* Update norns.lua

* Update norns.lua

* releases.txt

* allow user to add gamepad profiles without tempering w/ core (#1671)

* allow user to add gamepad models without tempering w/ core

* more explicit var names

* Revert "lua NRT processing function (#1634)" (#1673)

This reverts commit 0c06b09.

* changelog

* releases.txt

* Update settings.lua (#1675)

* revert export_png and rename export_screenshot (#1676)

* changelog, version, releases.txt

* releases.txt

* fix: softcut.voice_sync order documentation

softcut's `voice_sync` command has its arguments reversed in the API docs

* add fade_time correction, as well!

* fix fade_time parameter names

* add filters to fileselect (#1678)

* add filters to fileselect

* Update fileselect.lua

* remove whitespace

* fix midi clock double-tap (#1680)

* changelog, version

* update.sh ancient typo

* Update releases.txt

* fix #1681 (#1682)

ah! i had totally spaced on the auto-shortening of long filenames by appending '...', which confused the "is this a file or is this a folder?" mechanism! this is now fixed + and i will ask for community testing!

* 230614

* changelog

* releases.txt beta

* releases.txt stable

* Return correct 7th chords from musicutil.generate_chord_scale_degree  (#1688)

* Support half-diminished chords and correct scale degrees

* Add remaining missing 7th chords to roman notation: dominant, minor major, augmented major

* Use M decorator for Augmented Major 7, expand docs

* More docstring tweaks

* Update scale chord tables for Augmented Major 7 (27)

* Add new glyphs with FontForge instead of PixelForge

* Add alt_names Min7b5 and Maj7#5 for consistency w/teletype

* Ensure that disk field can represent size of larger sd cards (#1690)

Co-authored-by: Chris Aquino <aquino.chris@pm.me>

* lfo library: v2 (#1692)

* 'saw' -> 'tri', add 'up' and 'down', fix init

* build params from lfo spec

* add phase

* tune 'RESTART' (#1695)

* midi mapping touchups (#1696)

* fix user gamepad profile lookup + new model (#1697)

* fix: user-defined gamepad profile lookup

* new gamepad model: Retrolink B00GWKL3Y4

* more info

* disable hciuart in update (#1700)

* make variable y in util.wrap local (#1704)

* fix: debounce tape preview in fileselect (closes #1628) (#1703)

---------

Co-authored-by: dan derks <derks.dan@gmail.com>
Co-authored-by: brian crabtree <tehn@nnnnnnnn.co>
Co-authored-by: zbs <86270534+zjb-s@users.noreply.github.com>
Co-authored-by: Jonathan Snyder <52048666+jaseknighter@users.noreply.github.com>
Co-authored-by: Greg Wuller <greg@afofo.com>
Co-authored-by: Tyler Etters <tyleretters@users.noreply.github.com>
Co-authored-by: Artem Popov <artfwo@gmail.com>
Co-authored-by: Naomi Seyfer <naomi@seyfer.org>
Co-authored-by: Jordan Besly <11557146+p3r7@users.noreply.github.com>
Co-authored-by: Tom Waters <github@random-works.co.uk>
Co-authored-by: Rylee Alanza Lyman <46907231+ryleelyman@users.noreply.github.com>
Co-authored-by: Zack <zack.scholl@gmail.com>
Co-authored-by: Tyler Etters <tyler@etters.co>
Co-authored-by: kasperbauer <kasperbauer@users.noreply.github.com>
Co-authored-by: Anders Östlin <anders.ostlin@gmail.com>
Co-authored-by: Nik Silver <nik@niksilver.com>
Co-authored-by: trent <trent.gill@gmail.com>
Co-authored-by: brian crabtree <tehn@monome.org>
Co-authored-by: Michael Dewberry <michael.dewberry@gmail.com>
Co-authored-by: Chris Aquino <chris@thunderbird.net>
Co-authored-by: Chris Aquino <aquino.chris@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants