What is a suitable software design approach for handling user input from hardware buttons, where the function of each button depends on state?
I'm designing a musical instrument which has a lot of hardware buttons (something like a Novation Launchpad or Monome Grid). I'm used to building screen based software, where you can show and hide buttons depending on context and each button generally only has one function. But hardware buttons are a very different challenge and my code is rapidly turning into an unmanageable mess of
For example a single button may have these functions:
- if the transport is playing, pressing it launches the clip
- unless the
Selectkey is held when pressing it, in which case it selects the clip
- if the transport is not playing, then pressing it selects the clip, even if
Selectis not held
Deleteis held when pressing the button, it deletes the clip
- if the button is long pressed, then it copies the clip
- but if no clip exists in the slot corresponding to that button, then instead of all the above, a clip is created in that slot
... and all of that is just for one view of the app, other views may be completely different.
This is obviously some kind of state machine, but the number of states is huge – practically infinite if you consider that you can program any song into it – so I'm not sure if that's a useful abstraction. I've had a look at the Monome Grid tutorials but their examples are no better than my code.