Skip to content

Commit

Permalink
add keycodes for transpose range
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Young committed Feb 20, 2017
1 parent dd8f8e6 commit 5e6097f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
37 changes: 30 additions & 7 deletions quantum/process_keycode/process_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions quantum/quantum_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5e6097f

Please sign in to comment.