I want to change octaves or transpositions when turning the knob on my keyboard. What could I do to get the following code to work?
typedef enum {
ENCODER_MODE_OCTAVE,
ENCODER_MODE_TRANSPOSE,
} encoder_mode_t;
encoder_mode_t encoder_mode = ENCODER_MODE_OCTAVE;
bool encoder_update_user(uint8_t index, bool clockwise) {
if (layer_state_is(MIDI_BASE)) {
if (clockwise) {
if (encoder_mode == ENCODER_MODE_OCTAVE) {
tap_code16(MI_OCTU);
} else {
tap_code16(MI_TRSU);
}
} else {
if (encoder_mode == ENCODER_MODE_OCTAVE) {
tap_code16(MI_OCTD);
} else {
tap_code16(MI_TRSD);
}
}
}
return false;
}
- I receive 'something' when turning the knob, but it's not
MI_OCTxorMI_TRSx. - The documentation specifies
tap_code16(<kc>);so I'm thinking that I can only sendKC_xkeycodes, but I am unsure. - Using
MI_OCTxorMI_TRSxin my keymap works. - As a last option, I could implement octave and transposition changes in
process_record_userby adding or subtracting from the midi note values before usingmidi_send_noteon, but I am hoping for a 'simpler' solution.
You are correct. MIDI events and real keyboard events are processed separately:
OCTxandTRSxare processed inprocess_midi, which is part of the process that regular keymap goes through, but not part oftap_code*. Moreover, those OCTx/TRSx and other MIDI functions are not exposed for users to call.I do have an idea, but haven't looked into this myself, so please take it as a grain of salt.
The goal here is to utilize those internal MIDI functions that are already in
process_midi, and we want to be able to do this fromprocess_record_user(orpre_process_record_user). The idea is to change the content of*recordon the fly so the keycode becomes MI_OCTx. When it reachesprocess_midi, it'll do what MI_OCTx is supposed to do. I expect you'll need to do some(un)register_codeto keep the queue clean.