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

[mergeable] rework gamepad to handle more edge-cases #1624

Merged
merged 23 commits into from Mar 24, 2023
Merged

[mergeable] rework gamepad to handle more edge-cases #1624

merged 23 commits into from Mar 24, 2023

Conversation

p3r7
Copy link
Contributor

@p3r7 p3r7 commented Nov 24, 2022

so upon testing w/ @McNUG? i discovered that gamepads are even wackier than what i originally anticipated.

indeed:

  • analog sensor ranges are not standardized (a single controller can even use different sensors w/ different ranges)
  • i knew that button keycodes where all other the place, but it turns out that axis too!

this slight rework makes the following change:

  • we configure & track each individual analog sensor range & calibration (origin point, amount of noise)
  • gamepad.axis and gamepad.astick now return a per-sensor axis as its 1rst arg (dpady/dpadx, lefty/leftx & righty/rightx instead of generic X/Y, RX/RY & Z/RZ) *
  • gamepad.astick now has its val center value normalized around 0 & takes a 3rd param half_reso corresponding to the max value for each half of the travel (i.e. val can take value between [-half_reso ... half_reso])
  • new profile built from an 8BitDo SN30 Pro which is a high quality & readily available controller (unlike those of the previous profiles)

* i reused the same "per-sensor axis" naming convention as the LÖVE lua game framework.

the accompanying interactive gamepad profile generator script has also been updated & robustified.

i still plan on:

  • adding support for analog shoulder buttons (generally associated w/ either L1/R1 or L2/R2).
  • renaming gamepad.astick into something fitting any analog sensor (e.g. shoulder buttons). maybe simply gamepad.analog?
  • adding support for loading user-configured profiles (stored maybe somewhere in ~/dust/data?)

what edge-cases i don't plan to support but i'm pretty sure some crazy manufacturer has implemented:

  • dpads using buttons keycodes instead of axis event
  • analog stick using 2 axis keycode for each half axis

@p3r7
Copy link
Contributor Author

p3r7 commented Dec 8, 2022

tl;dr: so i've got a cleaner way to identify controllers in the C layer, using a "SDL" GUID.

i still have a small bug: i expected to grab this GUID as a new arg to Hid.new (lua-side) but i must have missed something in the interop declaration as i get nil (while it's well set C-side when calling w_handle_hid_add). fixed, missed an intermediary binding.

details

so i did some more research on how to best identify a controller.

SDL has a notion of controller GUID which i hoped was something explicit in the HID protocol but is in fact more of a hash.

it turns out that SDL get the fields it uses to build this GUID from libevent. so we have access to those same fields & can easily reconstruct this GUID (i've tested it on norns, it works) and adhere to the same standard as many other platforms.

one promise would be to support a bunch of controllers by importing a db of profiles (but sadly this one doesn't reference the analog sensor ranges nor their noisiness...).

@p3r7
Copy link
Contributor Author

p3r7 commented Jan 12, 2023

alright, added support for analog buttons (left/right shoulders typically).

i did a semblance of doc.

i still need to do one or two test & add handling of analog buttons in my wizard but basically we're 99% there.

@p3r7 p3r7 changed the title WIP rework gamepad to handle more edge-cases [mergeable] rework gamepad to handle more edge-cases Jan 18, 2023
@p3r7
Copy link
Contributor Author

p3r7 commented Jan 18, 2023

did a bunch of test. everything seem to be working as expected.

i tweaked some sub-menu integration code to feel more intuitive.

i'm not 100% positive about the menu callback names though (_menu.button, _menu.dpad, _menu.axis, _menu.analog). maybe should i rename them into something more "fully-qualified" (e.g. _menu.gamepad_button)?

@tehn
Copy link
Member

tehn commented Jan 19, 2023

i'm not 100% positive about the menu callback names though (_menu.button, _menu.dpad, _menu.axis, _menu.analog). maybe should i rename them into something more "fully-qualified" (e.g. _menu.gamepad_button)?

i'd prefer some namespacing, as you suggest. _menu.button is too ambiguous.

@p3r7
Copy link
Contributor Author

p3r7 commented Jan 19, 2023

ok, done for the prefixed menu callbacks.

minor inconvenience i just discovered: gamepad won't always work in textentry & filesect menus (they'd inherit the button/axis callbacks implemented in the calling script/menu).

i could make it work independently of the calling context like i did w/ keyboard.

@tehn
Copy link
Member

tehn commented Mar 23, 2023

i'd say this is good as is and if we wanted to revisit the context-sensitivity for textentry/fileselect we can do that further on?

@tehn tehn merged commit 389aa3b into monome:main Mar 24, 2023
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.

None yet

2 participants