Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Keyboard Input Handling: Row Editor (FamiTrackerView.cpp)

nyanpasu64 edited this page Jul 16, 2020 · 4 revisions

Keyboard input is handled by class CFamiTrackerView.

Keyboard input comes from OnKeyDown and OnChar.

  • Keycode is int64_t (TODO change types), since it helps catch function signature errors.
    • Keycodes encompass A-Z, 0-9, and a series of Win32/MFC VK_... constants, and do not match ASCII/Unicode in general.
    • This was the only method of input in FamiTracker and 0CC.
  • Character is a strong_typedef of int, which does not support arithmetic operations.
    • Characters are CP1252 (eventually Unicode?) and match ASCII.
  • Input is a std::variant<Keycode, Character>.

All keys with associated characters trigger both OnKeyDown and OnChar. OnKeyDown handles alphanumeric keys and special mappings. OnChar handles non-alphanumeric characters (effect names only, at the moment). If you add special mappings (Clear, Repeat, Echo Buffer...) on top of non-alphanumeric effects (=00), OnKeyDown (mapping) triggers, then OnChar (=00).

  • OnKeyDown handles keycodes, and passes HandleKeyboardInput a Keycode.

    • HandleKeyboardInput's children process alphanumeric keycodes and special mappings.
    • Children ignore non-alphanumeric keys, if they're not special keys.
  • OnChar handles characters, and passes HandleKeyboardInput a non-alphanumeric Character.

    • OnChar drops all alphanumeric characters.
    • OnChar drops key repeats (if desired).
  • HandleKeyboardInput takes an Input (Keycode or Character). If input is Keycode, HandleKeyboardInput drops key repeats (if desired).

    • Most child functions are never called on Character inputs, and only get passed Keycodes.
    • Character inputs are ignored unless the cursor is in the effect name column.
    • If the cursor is in the effect name column, EditEffNumberColumn gets called.
  • EditEffNumberColumn takes an Input, unlike other functions.

    • Effect names are expressed in ASCII, so EditEffNumberColumn aborts on non-alphanumeric Keycodes (which don't match ASCII).

Lessons learned: std::variant is a pain to work with. https://github.com/solodon4/Mach7 supports pattern-matching, but only on boost::variant. I can't tell if it's a precompiler or a library.

Docs: