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

Refactor undermidi for the Erlang NIF #56

Closed
27 of 35 tasks
Tracked by #52 ...
oubiwann opened this issue Sep 15, 2024 · 0 comments
Closed
27 of 35 tasks
Tracked by #52 ...

Refactor undermidi for the Erlang NIF #56

oubiwann opened this issue Sep 15, 2024 · 0 comments
Milestone

Comments

@oubiwann
Copy link
Contributor

oubiwann commented Sep 15, 2024

Use cases:

  • I would like to support the ability to operate multiple MIDI devices simultaneously and unambiguously
  • I would like the ability to operate on a given MIDI channel and use that channel until the system is told to use a different channel
  • In the event of recoverable issues in undermidi, the OS MIDI system, or the MIDI devices themselves, I would like to preserve state and not have to redo undermidi/device setup.
  • In the event of unrecoverable issues where undermidi or the Erlang VM itself has to be completely shutdown and restarted, I would like to resume sessions without having to redo undermidi/device setup.

The first two bullets reduce the number of arguments that need to be passed to MIDI functions for every call. The third bullet can be addressed with maintaining state in ETS. The fourth bullet can be addressed with maintaining state in DETS. These lead to the following capabilities that can be implemented in an undermidi gen_server:

  • The maintaining of state keyed to MIDI device name
  • The addition of "current channel" to the device state
  • The creation of an ETS table upon gen_server startup
  • Either the use of DETS instead of ETS, or the ability to regularly write ETS to DETS

Tasks:

  • Name the gen_server (maybe "devices"?)
  • Define a state data structure isolated per-device
  • Decide upon the use of ETS, DETS, or both
  • Create a server API (see below)

Device server functions:

  • new/1:
    • takes a string value
    • errs out if the string provided is not one of those in the result returned from the list-devices function
    • creates an entry in the state table for the device, if it doesn't exist
    • creates an Erlang process (probably dynamic OTP child) that is unique for this device (so that the user never needs to pass the device name to any functions when using this PID)
  • read/0:
    • dump all state
  • read/1:
    • dump state for a specific device
  • read/2:
    • get the value for the given key of a specific device
  • 🚫write/1:
    • replace all state with new state
  • write/2:
    • replace all the state of a specific device
  • 🚫write/3:
    • replace the value associated with the state key of a specific device

Child process functions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant