diff options
| author | Gabriel Young <gabeplaysdrums@live.com> | 2017-02-18 06:19:48 -0800 |
|---|---|---|
| committer | Gabriel Young <gabeplaysdrums@live.com> | 2017-02-19 16:43:43 -0800 |
| commit | 5e6097f0154403dccb9b5658390c84441aa509bc (patch) | |
| tree | bb30ba2e37e2b867c2ff4b267e9b49a257f29c06 /quantum | |
| parent | dd8f8e6baeb1549735403edf2a2f04f07edb4bf2 (diff) | |
| download | qmk_firmware-5e6097f0154403dccb9b5658390c84441aa509bc.tar.gz qmk_firmware-5e6097f0154403dccb9b5658390c84441aa509bc.zip | |
add keycodes for transpose range
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/process_keycode/process_midi.c | 37 | ||||
| -rw-r--r-- | 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 d09aa0b38..4d60aefb1 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c | |||
| @@ -2,12 +2,13 @@ | |||
| 2 | #include "timer.h" | 2 | #include "timer.h" |
| 3 | 3 | ||
| 4 | typedef union { | 4 | typedef union { |
| 5 | uint16_t raw; | 5 | uint32_t raw; |
| 6 | struct { | 6 | struct { |
| 7 | uint8_t octave :4; | 7 | uint8_t octave :4; |
| 8 | uint8_t velocity :4; | 8 | int8_t transpose :4; |
| 9 | uint8_t channel :4; | 9 | uint8_t velocity :4; |
| 10 | uint8_t modulation_interval :4; | 10 | uint8_t channel :4; |
| 11 | uint8_t modulation_interval :4; | ||
| 11 | }; | 12 | }; |
| 12 | } midi_config_t; | 13 | } midi_config_t; |
| 13 | 14 | ||
| @@ -29,7 +30,8 @@ inline uint8_t compute_velocity(uint8_t setting) | |||
| 29 | 30 | ||
| 30 | void midi_init(void) | 31 | void midi_init(void) |
| 31 | { | 32 | { |
| 32 | midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN; | 33 | midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; |
| 34 | midi_config.transpose = 0; | ||
| 33 | midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); | 35 | midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); |
| 34 | midi_config.channel = 0; | 36 | midi_config.channel = 0; |
| 35 | midi_config.modulation_interval = 8; | 37 | midi_config.modulation_interval = 8; |
| @@ -77,7 +79,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) | |||
| 77 | uint8_t tone = keycode - MIDI_TONE_MIN; | 79 | uint8_t tone = keycode - MIDI_TONE_MIN; |
| 78 | uint8_t velocity = compute_velocity(midi_config.velocity); | 80 | uint8_t velocity = compute_velocity(midi_config.velocity); |
| 79 | if (record->event.pressed) { | 81 | if (record->event.pressed) { |
| 80 | uint8_t note = 12 * midi_config.octave + tone; | 82 | uint8_t note = 12 * midi_config.octave + tone + midi_config.transpose; |
| 81 | midi_send_noteon(&midi_device, channel, note, velocity); | 83 | midi_send_noteon(&midi_device, channel, note, velocity); |
| 82 | dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); | 84 | dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); |
| 83 | tone_status[tone] = note; | 85 | tone_status[tone] = note; |
| @@ -111,6 +113,27 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) | |||
| 111 | dprintf("midi octave %d\n", midi_config.octave); | 113 | dprintf("midi octave %d\n", midi_config.octave); |
| 112 | } | 114 | } |
| 113 | return false; | 115 | return false; |
| 116 | case MIDI_TRANSPOSE_MIN ... MIDI_TRANSPOSE_MAX: | ||
| 117 | if (record->event.pressed) { | ||
| 118 | midi_config.transpose = keycode - MI_TRNS_0; | ||
| 119 | dprintf("midi transpose %d\n", midi_config.transpose); | ||
| 120 | } | ||
| 121 | return false; | ||
| 122 | case MI_TRNSD: | ||
| 123 | if (record->event.pressed && midi_config.transpose > (MIDI_TRANSPOSE_MIN - MI_TRNS_0)) { | ||
| 124 | midi_config.transpose--; | ||
| 125 | dprintf("midi transpose %d\n", midi_config.transpose); | ||
| 126 | } | ||
| 127 | return false; | ||
| 128 | case MI_TRNSU: | ||
| 129 | if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { | ||
| 130 | const bool positive = midi_config.transpose > 0; | ||
| 131 | midi_config.transpose++; | ||
| 132 | if (positive && midi_config.transpose < 0) | ||
| 133 | midi_config.transpose--; | ||
| 134 | dprintf("midi transpose %d\n", midi_config.transpose); | ||
| 135 | } | ||
| 136 | return false; | ||
| 114 | case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: | 137 | case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: |
| 115 | if (record->event.pressed) { | 138 | if (record->event.pressed) { |
| 116 | midi_config.velocity = keycode - MIDI_VELOCITY_MIN; | 139 | midi_config.velocity = keycode - MIDI_VELOCITY_MIN; |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 4423d25ef..30cc9abdb 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
| @@ -183,6 +183,24 @@ enum quantum_keycodes { | |||
| 183 | MI_OCTD, // octave down | 183 | MI_OCTD, // octave down |
| 184 | MI_OCTU, // octave up | 184 | MI_OCTU, // octave up |
| 185 | 185 | ||
| 186 | MIDI_TRANSPOSE_MIN, | ||
| 187 | MI_TRNS_N6 = MIDI_TRANSPOSE_MIN, | ||
| 188 | MI_TRNS_N5, | ||
| 189 | MI_TRNS_N4, | ||
| 190 | MI_TRNS_N3, | ||
| 191 | MI_TRNS_N2, | ||
| 192 | MI_TRNS_N1, | ||
| 193 | MI_TRNS_0, | ||
| 194 | MI_TRNS_1, | ||
| 195 | MI_TRNS_2, | ||
| 196 | MI_TRNS_3, | ||
| 197 | MI_TRNS_4, | ||
| 198 | MI_TRNS_5, | ||
| 199 | MI_TRNS_6, | ||
| 200 | MIDI_TRANSPOSE_MAX = MI_TRNS_6, | ||
| 201 | MI_TRNSD, // transpose down | ||
| 202 | MI_TRNSU, // transpose up | ||
| 203 | |||
| 186 | MIDI_VELOCITY_MIN, | 204 | MIDI_VELOCITY_MIN, |
| 187 | MI_VEL_1 = MIDI_VELOCITY_MIN, | 205 | MI_VEL_1 = MIDI_VELOCITY_MIN, |
| 188 | MI_VEL_2, | 206 | MI_VEL_2, |
