aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Young <gabeplaysdrums@live.com>2017-02-18 05:32:55 -0800
committerGabriel Young <gabeplaysdrums@live.com>2017-02-19 16:43:02 -0800
commitdd8f8e6baeb1549735403edf2a2f04f07edb4bf2 (patch)
tree459ba917de580e7bdb5b2bad9688486209b46825
parent7c5e510fe2e57d1b3c0f98612f1f89d413c07525 (diff)
downloadqmk_firmware-dd8f8e6baeb1549735403edf2a2f04f07edb4bf2.tar.gz
qmk_firmware-dd8f8e6baeb1549735403edf2a2f04f07edb4bf2.zip
implement modulation
-rw-r--r--quantum/process_keycode/process_midi.c58
-rw-r--r--quantum/process_keycode/process_midi.h201
-rw-r--r--quantum/quantum_keycodes.h6
-rw-r--r--tmk_core/protocol/lufa/lufa.c2
4 files changed, 61 insertions, 206 deletions
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index f7a8b6650..d09aa0b38 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -1,4 +1,5 @@
1#include "process_midi.h" 1#include "process_midi.h"
2#include "timer.h"
2 3
3typedef union { 4typedef union {
4 uint16_t raw; 5 uint16_t raw;
@@ -6,6 +7,7 @@ typedef union {
6 uint8_t octave :4; 7 uint8_t octave :4;
7 uint8_t velocity :4; 8 uint8_t velocity :4;
8 uint8_t channel :4; 9 uint8_t channel :4;
10 uint8_t modulation_interval :4;
9 }; 11 };
10} midi_config_t; 12} midi_config_t;
11 13
@@ -16,6 +18,10 @@ midi_config_t midi_config;
16#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) 18#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
17static uint8_t tone_status[MIDI_TONE_COUNT]; 19static uint8_t tone_status[MIDI_TONE_COUNT];
18 20
21static uint8_t midi_modulation;
22static int8_t midi_modulation_step;
23static uint16_t midi_modulation_timer;
24
19inline uint8_t compute_velocity(uint8_t setting) 25inline uint8_t compute_velocity(uint8_t setting)
20{ 26{
21 return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); 27 return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1));
@@ -26,14 +32,40 @@ void midi_init(void)
26 midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN; 32 midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN;
27 midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); 33 midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN);
28 midi_config.channel = 0; 34 midi_config.channel = 0;
29 #ifdef MIDI_USE_NOTE_ON_ARRAY 35 midi_config.modulation_interval = 8;
30 notes_on.length = 0; 36
31 #else
32 for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) 37 for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++)
33 { 38 {
34 tone_status[i] = MIDI_INVALID_NOTE; 39 tone_status[i] = MIDI_INVALID_NOTE;
35 } 40 }
36 #endif 41
42 midi_modulation = 0;
43 midi_modulation_step = 0;
44 midi_modulation_timer = 0;
45}
46
47void midi_task(void)
48{
49 if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval)
50 return;
51 midi_modulation_timer = timer_read();
52
53 if (midi_modulation_step != 0)
54 {
55 dprintf("midi modulation %d\n", midi_modulation);
56 midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation);
57
58 if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) {
59 midi_modulation = 0;
60 midi_modulation_step = 0;
61 return;
62 }
63
64 midi_modulation += midi_modulation_step;
65
66 if (midi_modulation > 127)
67 midi_modulation = 127;
68 }
37} 69}
38 70
39bool process_midi(uint16_t keycode, keyrecord_t *record) 71bool process_midi(uint16_t keycode, keyrecord_t *record)
@@ -141,6 +173,24 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
141 midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); 173 midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0);
142 dprintf("midi legato %d\n", record->event.pressed); 174 dprintf("midi legato %d\n", record->event.pressed);
143 return false; 175 return false;
176 case MI_MOD:
177 midi_modulation_step = record->event.pressed ? 1 : -1;
178 return false;
179 case MI_MODSD:
180 if (record->event.pressed) {
181 midi_config.modulation_interval++;
182 // prevent overflow
183 if (midi_config.modulation_interval == 0)
184 midi_config.modulation_interval--;
185 dprintf("midi modulation interval %d\n", midi_config.modulation_interval);
186 }
187 return false;
188 case MI_MODSU:
189 if (record->event.pressed && midi_config.modulation_interval > 0) {
190 midi_config.modulation_interval--;
191 dprintf("midi modulation interval %d\n", midi_config.modulation_interval);
192 }
193 return false;
144 }; 194 };
145 195
146 return true; 196 return true;
diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h
index b0e0aeb83..66ce60b0e 100644
--- a/quantum/process_keycode/process_midi.h
+++ b/quantum/process_keycode/process_midi.h
@@ -5,206 +5,7 @@
5#include "midi.h" 5#include "midi.h"
6 6
7void midi_init(void); 7void midi_init(void);
8 8void midi_task(void);
9bool process_midi(uint16_t keycode, keyrecord_t *record); 9bool process_midi(uint16_t keycode, keyrecord_t *record);
10 10
11#define MIDI(n) ((n) | 0x6000)
12#define MIDI12 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000
13
14#define CHNL(note, channel) (note + (channel << 8))
15
16#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
17 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
18 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
19 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
20 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
21
22#define N_CN1 (0x600C + (12 * -1) + 0 )
23#define N_CN1S (0x600C + (12 * -1) + 1 )
24#define N_DN1F (0x600C + (12 * -1) + 1 )
25#define N_DN1 (0x600C + (12 * -1) + 2 )
26#define N_DN1S (0x600C + (12 * -1) + 3 )
27#define N_EN1F (0x600C + (12 * -1) + 3 )
28#define N_EN1 (0x600C + (12 * -1) + 4 )
29#define N_FN1 (0x600C + (12 * -1) + 5 )
30#define N_FN1S (0x600C + (12 * -1) + 6 )
31#define N_GN1F (0x600C + (12 * -1) + 6 )
32#define N_GN1 (0x600C + (12 * -1) + 7 )
33#define N_GN1S (0x600C + (12 * -1) + 8 )
34#define N_AN1F (0x600C + (12 * -1) + 8 )
35#define N_AN1 (0x600C + (12 * -1) + 9 )
36#define N_AN1S (0x600C + (12 * -1) + 10)
37#define N_BN1F (0x600C + (12 * -1) + 10)
38#define N_BN1 (0x600C + (12 * -1) + 11)
39#define N_C0 (0x600C + (12 * 0) + 0 )
40#define N_C0S (0x600C + (12 * 0) + 1 )
41#define N_D0F (0x600C + (12 * 0) + 1 )
42#define N_D0 (0x600C + (12 * 0) + 2 )
43#define N_D0S (0x600C + (12 * 0) + 3 )
44#define N_E0F (0x600C + (12 * 0) + 3 )
45#define N_E0 (0x600C + (12 * 0) + 4 )
46#define N_F0 (0x600C + (12 * 0) + 5 )
47#define N_F0S (0x600C + (12 * 0) + 6 )
48#define N_G0F (0x600C + (12 * 0) + 6 )
49#define N_G0 (0x600C + (12 * 0) + 7 )
50#define N_G0S (0x600C + (12 * 0) + 8 )
51#define N_A0F (0x600C + (12 * 0) + 8 )
52#define N_A0 (0x600C + (12 * 0) + 9 )
53#define N_A0S (0x600C + (12 * 0) + 10)
54#define N_B0F (0x600C + (12 * 0) + 10)
55#define N_B0 (0x600C + (12 * 0) + 11)
56#define N_C1 (0x600C + (12 * 1) + 0 )
57#define N_C1S (0x600C + (12 * 1) + 1 )
58#define N_D1F (0x600C + (12 * 1) + 1 )
59#define N_D1 (0x600C + (12 * 1) + 2 )
60#define N_D1S (0x600C + (12 * 1) + 3 )
61#define N_E1F (0x600C + (12 * 1) + 3 )
62#define N_E1 (0x600C + (12 * 1) + 4 )
63#define N_F1 (0x600C + (12 * 1) + 5 )
64#define N_F1S (0x600C + (12 * 1) + 6 )
65#define N_G1F (0x600C + (12 * 1) + 6 )
66#define N_G1 (0x600C + (12 * 1) + 7 )
67#define N_G1S (0x600C + (12 * 1) + 8 )
68#define N_A1F (0x600C + (12 * 1) + 8 )
69#define N_A1 (0x600C + (12 * 1) + 9 )
70#define N_A1S (0x600C + (12 * 1) + 10)
71#define N_B1F (0x600C + (12 * 1) + 10)
72#define N_B1 (0x600C + (12 * 1) + 11)
73#define N_C2 (0x600C + (12 * 2) + 0 )
74#define N_C2S (0x600C + (12 * 2) + 1 )
75#define N_D2F (0x600C + (12 * 2) + 1 )
76#define N_D2 (0x600C + (12 * 2) + 2 )
77#define N_D2S (0x600C + (12 * 2) + 3 )
78#define N_E2F (0x600C + (12 * 2) + 3 )
79#define N_E2 (0x600C + (12 * 2) + 4 )
80#define N_F2 (0x600C + (12 * 2) + 5 )
81#define N_F2S (0x600C + (12 * 2) + 6 )
82#define N_G2F (0x600C + (12 * 2) + 6 )
83#define N_G2 (0x600C + (12 * 2) + 7 )
84#define N_G2S (0x600C + (12 * 2) + 8 )
85#define N_A2F (0x600C + (12 * 2) + 8 )
86#define N_A2 (0x600C + (12 * 2) + 9 )
87#define N_A2S (0x600C + (12 * 2) + 10)
88#define N_B2F (0x600C + (12 * 2) + 10)
89#define N_B2 (0x600C + (12 * 2) + 11)
90#define N_C3 (0x600C + (12 * 3) + 0 )
91#define N_C3S (0x600C + (12 * 3) + 1 )
92#define N_D3F (0x600C + (12 * 3) + 1 )
93#define N_D3 (0x600C + (12 * 3) + 2 )
94#define N_D3S (0x600C + (12 * 3) + 3 )
95#define N_E3F (0x600C + (12 * 3) + 3 )
96#define N_E3 (0x600C + (12 * 3) + 4 )
97#define N_F3 (0x600C + (12 * 3) + 5 )
98#define N_F3S (0x600C + (12 * 3) + 6 )
99#define N_G3F (0x600C + (12 * 3) + 6 )
100#define N_G3 (0x600C + (12 * 3) + 7 )
101#define N_G3S (0x600C + (12 * 3) + 8 )
102#define N_A3F (0x600C + (12 * 3) + 8 )
103#define N_A3 (0x600C + (12 * 3) + 9 )
104#define N_A3S (0x600C + (12 * 3) + 10)
105#define N_B3F (0x600C + (12 * 3) + 10)
106#define N_B3 (0x600C + (12 * 3) + 11)
107#define N_C4 (0x600C + (12 * 4) + 0 )
108#define N_C4S (0x600C + (12 * 4) + 1 )
109#define N_D4F (0x600C + (12 * 4) + 1 )
110#define N_D4 (0x600C + (12 * 4) + 2 )
111#define N_D4S (0x600C + (12 * 4) + 3 )
112#define N_E4F (0x600C + (12 * 4) + 3 )
113#define N_E4 (0x600C + (12 * 4) + 4 )
114#define N_F4 (0x600C + (12 * 4) + 5 )
115#define N_F4S (0x600C + (12 * 4) + 6 )
116#define N_G4F (0x600C + (12 * 4) + 6 )
117#define N_G4 (0x600C + (12 * 4) + 7 )
118#define N_G4S (0x600C + (12 * 4) + 8 )
119#define N_A4F (0x600C + (12 * 4) + 8 )
120#define N_A4 (0x600C + (12 * 4) + 9 )
121#define N_A4S (0x600C + (12 * 4) + 10)
122#define N_B4F (0x600C + (12 * 4) + 10)
123#define N_B4 (0x600C + (12 * 4) + 11)
124#define N_C5 (0x600C + (12 * 5) + 0 )
125#define N_C5S (0x600C + (12 * 5) + 1 )
126#define N_D5F (0x600C + (12 * 5) + 1 )
127#define N_D5 (0x600C + (12 * 5) + 2 )
128#define N_D5S (0x600C + (12 * 5) + 3 )
129#define N_E5F (0x600C + (12 * 5) + 3 )
130#define N_E5 (0x600C + (12 * 5) + 4 )
131#define N_F5 (0x600C + (12 * 5) + 5 )
132#define N_F5S (0x600C + (12 * 5) + 6 )
133#define N_G5F (0x600C + (12 * 5) + 6 )
134#define N_G5 (0x600C + (12 * 5) + 7 )
135#define N_G5S (0x600C + (12 * 5) + 8 )
136#define N_A5F (0x600C + (12 * 5) + 8 )
137#define N_A5 (0x600C + (12 * 5) + 9 )
138#define N_A5S (0x600C + (12 * 5) + 10)
139#define N_B5F (0x600C + (12 * 5) + 10)
140#define N_B5 (0x600C + (12 * 5) + 11)
141#define N_C6 (0x600C + (12 * 6) + 0 )
142#define N_C6S (0x600C + (12 * 6) + 1 )
143#define N_D6F (0x600C + (12 * 6) + 1 )
144#define N_D6 (0x600C + (12 * 6) + 2 )
145#define N_D6S (0x600C + (12 * 6) + 3 )
146#define N_E6F (0x600C + (12 * 6) + 3 )
147#define N_E6 (0x600C + (12 * 6) + 4 )
148#define N_F6 (0x600C + (12 * 6) + 5 )
149#define N_F6S (0x600C + (12 * 6) + 6 )
150#define N_G6F (0x600C + (12 * 6) + 6 )
151#define N_G6 (0x600C + (12 * 6) + 7 )
152#define N_G6S (0x600C + (12 * 6) + 8 )
153#define N_A6F (0x600C + (12 * 6) + 8 )
154#define N_A6 (0x600C + (12 * 6) + 9 )
155#define N_A6S (0x600C + (12 * 6) + 10)
156#define N_B6F (0x600C + (12 * 6) + 10)
157#define N_B6 (0x600C + (12 * 6) + 11)
158#define N_C7 (0x600C + (12 * 7) + 0 )
159#define N_C7S (0x600C + (12 * 7) + 1 )
160#define N_D7F (0x600C + (12 * 7) + 1 )
161#define N_D7 (0x600C + (12 * 7) + 2 )
162#define N_D7S (0x600C + (12 * 7) + 3 )
163#define N_E7F (0x600C + (12 * 7) + 3 )
164#define N_E7 (0x600C + (12 * 7) + 4 )
165#define N_F7 (0x600C + (12 * 7) + 5 )
166#define N_F7S (0x600C + (12 * 7) + 6 )
167#define N_G7F (0x600C + (12 * 7) + 6 )
168#define N_G7 (0x600C + (12 * 7) + 7 )
169#define N_G7S (0x600C + (12 * 7) + 8 )
170#define N_A7F (0x600C + (12 * 7) + 8 )
171#define N_A7 (0x600C + (12 * 7) + 9 )
172#define N_A7S (0x600C + (12 * 7) + 10)
173#define N_B7F (0x600C + (12 * 7) + 10)
174#define N_B7 (0x600C + (12 * 7) + 11)
175#define N_C8 (0x600C + (12 * 8) + 0 )
176#define N_C8S (0x600C + (12 * 8) + 1 )
177#define N_D8F (0x600C + (12 * 8) + 1 )
178#define N_D8 (0x600C + (12 * 8) + 2 )
179#define N_D8S (0x600C + (12 * 8) + 3 )
180#define N_E8F (0x600C + (12 * 8) + 3 )
181#define N_E8 (0x600C + (12 * 8) + 4 )
182#define N_F8 (0x600C + (12 * 8) + 5 )
183#define N_F8S (0x600C + (12 * 8) + 6 )
184#define N_G8F (0x600C + (12 * 8) + 6 )
185#define N_G8 (0x600C + (12 * 8) + 7 )
186#define N_G8S (0x600C + (12 * 8) + 8 )
187#define N_A8F (0x600C + (12 * 8) + 8 )
188#define N_A8 (0x600C + (12 * 8) + 9 )
189#define N_A8S (0x600C + (12 * 8) + 10)
190#define N_B8F (0x600C + (12 * 8) + 10)
191#define N_B8 (0x600C + (12 * 8) + 11)
192#define N_C8 (0x600C + (12 * 8) + 0 )
193#define N_C8S (0x600C + (12 * 8) + 1 )
194#define N_D8F (0x600C + (12 * 8) + 1 )
195#define N_D8 (0x600C + (12 * 8) + 2 )
196#define N_D8S (0x600C + (12 * 8) + 3 )
197#define N_E8F (0x600C + (12 * 8) + 3 )
198#define N_E8 (0x600C + (12 * 8) + 4 )
199#define N_F8 (0x600C + (12 * 8) + 5 )
200#define N_F8S (0x600C + (12 * 8) + 6 )
201#define N_G8F (0x600C + (12 * 8) + 6 )
202#define N_G8 (0x600C + (12 * 8) + 7 )
203#define N_G8S (0x600C + (12 * 8) + 8 )
204#define N_A8F (0x600C + (12 * 8) + 8 )
205#define N_A8 (0x600C + (12 * 8) + 9 )
206#define N_A8S (0x600C + (12 * 8) + 10)
207#define N_B8F (0x600C + (12 * 8) + 10)
208#define N_B8 (0x600C + (12 * 8) + 11)
209
210#endif \ No newline at end of file 11#endif \ No newline at end of file
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index f2b9509b5..4423d25ef 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -224,8 +224,12 @@ enum quantum_keycodes {
224 MI_SUS, // sustain 224 MI_SUS, // sustain
225 MI_PORT, // portamento 225 MI_PORT, // portamento
226 MI_SOST, // sostenuto 226 MI_SOST, // sostenuto
227 MI_SOFT, // soft 227 MI_SOFT, // soft pedal
228 MI_LEG, // legato 228 MI_LEG, // legato
229
230 MI_MOD, // modulation
231 MI_MODSD, // decrease modulation speed
232 MI_MODSU, // increase modulation speed
229#endif 233#endif
230 234
231 // Backlight functionality 235 // Backlight functionality
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index fb60658df..bd2498057 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1180,7 +1180,7 @@ int main(void)
1180 1180
1181#ifdef MIDI_ENABLE 1181#ifdef MIDI_ENABLE
1182 midi_device_process(&midi_device); 1182 midi_device_process(&midi_device);
1183 // MIDI_Task(); 1183 midi_task();
1184#endif 1184#endif
1185 1185
1186#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) 1186#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE)