aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorGabriel Young <gabeplaysdrums@live.com>2017-02-18 21:07:07 -0800
committerGabriel Young <gabeplaysdrums@live.com>2017-02-19 16:43:45 -0800
commitae0752dff552a07fb52e08c7057979959959d247 (patch)
tree1f1c1dc6605e20ddf46894cef2e6b52bd2dc2b81 /quantum/process_keycode
parent5e6097f0154403dccb9b5658390c84441aa509bc (diff)
downloadqmk_firmware-ae0752dff552a07fb52e08c7057979959959d247.tar.gz
qmk_firmware-ae0752dff552a07fb52e08c7057979959959d247.zip
expose midi_config
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_midi.c23
-rw-r--r--quantum/process_keycode/process_midi.h18
2 files changed, 24 insertions, 17 deletions
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index 4d60aefb1..9190fa047 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -1,22 +1,6 @@
1#include "process_midi.h" 1#include "process_midi.h"
2#include "timer.h" 2#include "timer.h"
3 3
4typedef union {
5 uint32_t raw;
6 struct {
7 uint8_t octave :4;
8 int8_t transpose :4;
9 uint8_t velocity :4;
10 uint8_t channel :4;
11 uint8_t modulation_interval :4;
12 };
13} midi_config_t;
14
15midi_config_t midi_config;
16
17#define MIDI_INVALID_NOTE 0xFF
18
19#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
20static uint8_t tone_status[MIDI_TONE_COUNT]; 4static uint8_t tone_status[MIDI_TONE_COUNT];
21 5
22static uint8_t midi_modulation; 6static uint8_t midi_modulation;
@@ -70,6 +54,11 @@ void midi_task(void)
70 } 54 }
71} 55}
72 56
57uint8_t midi_compute_note(uint16_t keycode)
58{
59 return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose;
60}
61
73bool process_midi(uint16_t keycode, keyrecord_t *record) 62bool process_midi(uint16_t keycode, keyrecord_t *record)
74{ 63{
75 switch (keycode) { 64 switch (keycode) {
@@ -79,7 +68,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
79 uint8_t tone = keycode - MIDI_TONE_MIN; 68 uint8_t tone = keycode - MIDI_TONE_MIN;
80 uint8_t velocity = compute_velocity(midi_config.velocity); 69 uint8_t velocity = compute_velocity(midi_config.velocity);
81 if (record->event.pressed) { 70 if (record->event.pressed) {
82 uint8_t note = 12 * midi_config.octave + tone + midi_config.transpose; 71 uint8_t note = midi_compute_note(keycode);
83 midi_send_noteon(&midi_device, channel, note, velocity); 72 midi_send_noteon(&midi_device, channel, note, velocity);
84 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); 73 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
85 tone_status[tone] = note; 74 tone_status[tone] = note;
diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h
index 66ce60b0e..ffd41579f 100644
--- a/quantum/process_keycode/process_midi.h
+++ b/quantum/process_keycode/process_midi.h
@@ -4,8 +4,26 @@
4#include "quantum.h" 4#include "quantum.h"
5#include "midi.h" 5#include "midi.h"
6 6
7typedef union {
8 uint32_t raw;
9 struct {
10 uint8_t octave :4;
11 int8_t transpose :4;
12 uint8_t velocity :4;
13 uint8_t channel :4;
14 uint8_t modulation_interval :4;
15 };
16} midi_config_t;
17
18midi_config_t midi_config;
19
7void midi_init(void); 20void midi_init(void);
8void midi_task(void); 21void midi_task(void);
9bool process_midi(uint16_t keycode, keyrecord_t *record); 22bool process_midi(uint16_t keycode, keyrecord_t *record);
10 23
24#define MIDI_INVALID_NOTE 0xFF
25#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
26
27uint8_t midi_compute_note(uint16_t keycode);
28
11#endif \ No newline at end of file 29#endif \ No newline at end of file