From 5e6097f0154403dccb9b5658390c84441aa509bc Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 18 Feb 2017 06:19:48 -0800 Subject: [PATCH] add keycodes for transpose range --- quantum/process_keycode/process_midi.c | 37 +++++++++++++++++++++----- quantum/quantum_keycodes.h | 18 +++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index d09aa0b382..4d60aefb1c 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -2,12 +2,13 @@ #include "timer.h" typedef union { - uint16_t raw; + uint32_t raw; struct { - uint8_t octave :4; - uint8_t velocity :4; - uint8_t channel :4; - uint8_t modulation_interval :4; + uint8_t octave :4; + int8_t transpose :4; + uint8_t velocity :4; + uint8_t channel :4; + uint8_t modulation_interval :4; }; } midi_config_t; @@ -29,7 +30,8 @@ inline uint8_t compute_velocity(uint8_t setting) void midi_init(void) { - midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN; + midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; + midi_config.transpose = 0; midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); midi_config.channel = 0; midi_config.modulation_interval = 8; @@ -77,7 +79,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) uint8_t tone = keycode - MIDI_TONE_MIN; uint8_t velocity = compute_velocity(midi_config.velocity); if (record->event.pressed) { - uint8_t note = 12 * midi_config.octave + tone; + uint8_t note = 12 * midi_config.octave + tone + midi_config.transpose; midi_send_noteon(&midi_device, channel, note, velocity); dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); tone_status[tone] = note; @@ -111,6 +113,27 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) dprintf("midi octave %d\n", midi_config.octave); } return false; + case MIDI_TRANSPOSE_MIN ... MIDI_TRANSPOSE_MAX: + if (record->event.pressed) { + midi_config.transpose = keycode - MI_TRNS_0; + dprintf("midi transpose %d\n", midi_config.transpose); + } + return false; + case MI_TRNSD: + if (record->event.pressed && midi_config.transpose > (MIDI_TRANSPOSE_MIN - MI_TRNS_0)) { + midi_config.transpose--; + dprintf("midi transpose %d\n", midi_config.transpose); + } + return false; + case MI_TRNSU: + if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { + const bool positive = midi_config.transpose > 0; + midi_config.transpose++; + if (positive && midi_config.transpose < 0) + midi_config.transpose--; + dprintf("midi transpose %d\n", midi_config.transpose); + } + return false; case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: if (record->event.pressed) { midi_config.velocity = keycode - MIDI_VELOCITY_MIN; diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 4423d25eff..30cc9abdb4 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -183,6 +183,24 @@ enum quantum_keycodes { MI_OCTD, // octave down MI_OCTU, // octave up + MIDI_TRANSPOSE_MIN, + MI_TRNS_N6 = MIDI_TRANSPOSE_MIN, + MI_TRNS_N5, + MI_TRNS_N4, + MI_TRNS_N3, + MI_TRNS_N2, + MI_TRNS_N1, + MI_TRNS_0, + MI_TRNS_1, + MI_TRNS_2, + MI_TRNS_3, + MI_TRNS_4, + MI_TRNS_5, + MI_TRNS_6, + MIDI_TRANSPOSE_MAX = MI_TRNS_6, + MI_TRNSD, // transpose down + MI_TRNSU, // transpose up + MIDI_VELOCITY_MIN, MI_VEL_1 = MIDI_VELOCITY_MIN, MI_VEL_2,