diff options
author | Jack Humbert <jack.humb@gmail.com> | 2017-03-28 09:26:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-28 09:26:54 -0400 |
commit | 7e37daa2ce6edad82de3835384176b51a8081537 (patch) | |
tree | 58f349edb063667c9ae0affd99cec2bf7a7f93cb /quantum | |
parent | 216f669276b30393fb35a409011ccdad8b521156 (diff) | |
parent | 0734f569409974624b40735fcd498dac9adba2d2 (diff) | |
download | qmk_firmware-7e37daa2ce6edad82de3835384176b51a8081537.tar.gz qmk_firmware-7e37daa2ce6edad82de3835384176b51a8081537.zip |
Merge pull request #1112 from newsboytko/newsboytko/midi-keycodes
Flesh out MIDI support
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/audio/audio.c | 322 | ||||
-rw-r--r-- | quantum/process_keycode/process_audio.c | 62 | ||||
-rw-r--r-- | quantum/process_keycode/process_audio.h | 11 | ||||
-rw-r--r-- | quantum/process_keycode/process_midi.c | 292 | ||||
-rw-r--r-- | quantum/process_keycode/process_midi.h | 225 | ||||
-rw-r--r-- | quantum/process_keycode/process_music.c | 118 | ||||
-rw-r--r-- | quantum/process_keycode/process_music.h | 6 | ||||
-rw-r--r-- | quantum/quantum.c | 9 | ||||
-rw-r--r-- | quantum/quantum.h | 7 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 241 | ||||
-rw-r--r-- | quantum/template/config.h | 23 | ||||
-rw-r--r-- | quantum/template/keymaps/default/Makefile | 2 | ||||
-rw-r--r-- | quantum/template/rules.mk | 2 |
13 files changed, 834 insertions, 486 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 2a315fd16..e1e81fd2b 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c | |||
@@ -89,15 +89,15 @@ void audio_init() | |||
89 | } | 89 | } |
90 | audio_config.raw = eeconfig_read_audio(); | 90 | audio_config.raw = eeconfig_read_audio(); |
91 | 91 | ||
92 | // Set port PC6 (OC3A and /OC4A) as output | 92 | // Set port PC6 (OC3A and /OC4A) as output |
93 | DDRC |= _BV(PORTC6); | 93 | DDRC |= _BV(PORTC6); |
94 | 94 | ||
95 | DISABLE_AUDIO_COUNTER_3_ISR; | 95 | DISABLE_AUDIO_COUNTER_3_ISR; |
96 | 96 | ||
97 | // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers | 97 | // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers |
98 | // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6 | 98 | // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6 |
99 | // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A) | 99 | // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A) |
100 | // Clock Select (CS3n) = 0b010 = Clock / 8 | 100 | // Clock Select (CS3n) = 0b010 = Clock / 8 |
101 | TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); | 101 | TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); |
102 | TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); | 102 | TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); |
103 | 103 | ||
@@ -106,6 +106,8 @@ void audio_init() | |||
106 | 106 | ||
107 | void stop_all_notes() | 107 | void stop_all_notes() |
108 | { | 108 | { |
109 | dprintf("audio stop all notes"); | ||
110 | |||
109 | if (!audio_initialized) { | 111 | if (!audio_initialized) { |
110 | audio_init(); | 112 | audio_init(); |
111 | } | 113 | } |
@@ -128,6 +130,8 @@ void stop_all_notes() | |||
128 | 130 | ||
129 | void stop_note(float freq) | 131 | void stop_note(float freq) |
130 | { | 132 | { |
133 | dprintf("audio stop note freq=%d", (int)freq); | ||
134 | |||
131 | if (playing_note) { | 135 | if (playing_note) { |
132 | if (!audio_initialized) { | 136 | if (!audio_initialized) { |
133 | audio_init(); | 137 | audio_init(); |
@@ -183,159 +187,161 @@ float vibrato(float average_freq) { | |||
183 | 187 | ||
184 | ISR(TIMER3_COMPA_vect) | 188 | ISR(TIMER3_COMPA_vect) |
185 | { | 189 | { |
186 | float freq; | 190 | float freq; |
187 | 191 | ||
188 | if (playing_note) { | 192 | if (playing_note) { |
189 | if (voices > 0) { | 193 | if (voices > 0) { |
190 | if (polyphony_rate > 0) { | 194 | if (polyphony_rate > 0) { |
191 | if (voices > 1) { | 195 | if (voices > 1) { |
192 | voice_place %= voices; | 196 | voice_place %= voices; |
193 | if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) { | 197 | if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) { |
194 | voice_place = (voice_place + 1) % voices; | 198 | voice_place = (voice_place + 1) % voices; |
195 | place = 0.0; | 199 | place = 0.0; |
196 | } | 200 | } |
197 | } | 201 | } |
198 | 202 | ||
199 | #ifdef VIBRATO_ENABLE | 203 | #ifdef VIBRATO_ENABLE |
200 | if (vibrato_strength > 0) { | 204 | if (vibrato_strength > 0) { |
201 | freq = vibrato(frequencies[voice_place]); | 205 | freq = vibrato(frequencies[voice_place]); |
202 | } else { | 206 | } else { |
203 | freq = frequencies[voice_place]; | 207 | freq = frequencies[voice_place]; |
204 | } | 208 | } |
205 | #else | 209 | #else |
206 | freq = frequencies[voice_place]; | 210 | freq = frequencies[voice_place]; |
207 | #endif | 211 | #endif |
208 | } else { | 212 | } else { |
209 | if (glissando) { | 213 | if (glissando) { |
210 | if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) { | 214 | if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) { |
211 | frequency = frequency * pow(2, 440/frequency/12/2); | 215 | frequency = frequency * pow(2, 440/frequency/12/2); |
212 | } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) { | 216 | } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) { |
213 | frequency = frequency * pow(2, -440/frequency/12/2); | 217 | frequency = frequency * pow(2, -440/frequency/12/2); |
214 | } else { | 218 | } else { |
215 | frequency = frequencies[voices - 1]; | 219 | frequency = frequencies[voices - 1]; |
216 | } | 220 | } |
217 | } else { | 221 | } else { |
218 | frequency = frequencies[voices - 1]; | 222 | frequency = frequencies[voices - 1]; |
219 | } | 223 | } |
220 | 224 | ||
221 | #ifdef VIBRATO_ENABLE | 225 | #ifdef VIBRATO_ENABLE |
222 | if (vibrato_strength > 0) { | 226 | if (vibrato_strength > 0) { |
223 | freq = vibrato(frequency); | 227 | freq = vibrato(frequency); |
224 | } else { | 228 | } else { |
225 | freq = frequency; | 229 | freq = frequency; |
226 | } | 230 | } |
227 | #else | 231 | #else |
228 | freq = frequency; | 232 | freq = frequency; |
229 | #endif | 233 | #endif |
230 | } | 234 | } |
231 | 235 | ||
232 | if (envelope_index < 65535) { | 236 | if (envelope_index < 65535) { |
233 | envelope_index++; | 237 | envelope_index++; |
234 | } | 238 | } |
235 | 239 | ||
236 | freq = voice_envelope(freq); | 240 | freq = voice_envelope(freq); |
237 | 241 | ||
238 | if (freq < 30.517578125) { | 242 | if (freq < 30.517578125) { |
239 | freq = 30.52; | 243 | freq = 30.52; |
240 | } | 244 | } |
241 | 245 | ||
242 | TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER)); | 246 | TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER)); |
243 | TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); | 247 | TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); |
244 | } | 248 | } |
245 | } | 249 | } |
246 | 250 | ||
247 | if (playing_notes) { | 251 | if (playing_notes) { |
248 | if (note_frequency > 0) { | 252 | if (note_frequency > 0) { |
249 | #ifdef VIBRATO_ENABLE | 253 | #ifdef VIBRATO_ENABLE |
250 | if (vibrato_strength > 0) { | 254 | if (vibrato_strength > 0) { |
251 | freq = vibrato(note_frequency); | 255 | freq = vibrato(note_frequency); |
252 | } else { | 256 | } else { |
253 | freq = note_frequency; | 257 | freq = note_frequency; |
254 | } | 258 | } |
255 | #else | 259 | #else |
256 | freq = note_frequency; | 260 | freq = note_frequency; |
257 | #endif | 261 | #endif |
258 | 262 | ||
259 | if (envelope_index < 65535) { | 263 | if (envelope_index < 65535) { |
260 | envelope_index++; | 264 | envelope_index++; |
261 | } | 265 | } |
262 | freq = voice_envelope(freq); | 266 | freq = voice_envelope(freq); |
263 | 267 | ||
264 | TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER)); | 268 | TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER)); |
265 | TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); | 269 | TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); |
266 | } else { | 270 | } else { |
267 | TIMER_3_PERIOD = 0; | 271 | TIMER_3_PERIOD = 0; |
268 | TIMER_3_DUTY_CYCLE = 0; | 272 | TIMER_3_DUTY_CYCLE = 0; |
269 | } | 273 | } |
270 | 274 | ||
271 | note_position++; | 275 | note_position++; |
272 | bool end_of_note = false; | 276 | bool end_of_note = false; |
273 | if (TIMER_3_PERIOD > 0) { | 277 | if (TIMER_3_PERIOD > 0) { |
274 | end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF)); | 278 | end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF)); |
275 | } else { | 279 | } else { |
276 | end_of_note = (note_position >= (note_length * 0x7FF)); | 280 | end_of_note = (note_position >= (note_length * 0x7FF)); |
277 | } | 281 | } |
278 | 282 | ||
279 | if (end_of_note) { | 283 | if (end_of_note) { |
280 | current_note++; | 284 | current_note++; |
281 | if (current_note >= notes_count) { | 285 | if (current_note >= notes_count) { |
282 | if (notes_repeat) { | 286 | if (notes_repeat) { |
283 | current_note = 0; | 287 | current_note = 0; |
284 | } else { | 288 | } else { |
285 | DISABLE_AUDIO_COUNTER_3_ISR; | 289 | DISABLE_AUDIO_COUNTER_3_ISR; |
286 | DISABLE_AUDIO_COUNTER_3_OUTPUT; | 290 | DISABLE_AUDIO_COUNTER_3_OUTPUT; |
287 | playing_notes = false; | 291 | playing_notes = false; |
288 | return; | 292 | return; |
289 | } | 293 | } |
290 | } | 294 | } |
291 | if (!note_resting && (notes_rest > 0)) { | 295 | if (!note_resting && (notes_rest > 0)) { |
292 | note_resting = true; | 296 | note_resting = true; |
293 | note_frequency = 0; | 297 | note_frequency = 0; |
294 | note_length = notes_rest; | 298 | note_length = notes_rest; |
295 | current_note--; | 299 | current_note--; |
296 | } else { | 300 | } else { |
297 | note_resting = false; | 301 | note_resting = false; |
298 | envelope_index = 0; | 302 | envelope_index = 0; |
299 | note_frequency = (*notes_pointer)[current_note][0]; | 303 | note_frequency = (*notes_pointer)[current_note][0]; |
300 | note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100); | 304 | note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100); |
301 | } | 305 | } |
302 | 306 | ||
303 | note_position = 0; | 307 | note_position = 0; |
304 | } | 308 | } |
305 | } | 309 | } |
306 | 310 | ||
307 | if (!audio_config.enable) { | 311 | if (!audio_config.enable) { |
308 | playing_notes = false; | 312 | playing_notes = false; |
309 | playing_note = false; | 313 | playing_note = false; |
310 | } | 314 | } |
311 | } | 315 | } |
312 | 316 | ||
313 | void play_note(float freq, int vol) { | 317 | void play_note(float freq, int vol) { |
314 | 318 | ||
319 | dprintf("audio play note freq=%d vol=%d", (int)freq, vol); | ||
320 | |||
315 | if (!audio_initialized) { | 321 | if (!audio_initialized) { |
316 | audio_init(); | 322 | audio_init(); |
317 | } | 323 | } |
318 | 324 | ||
319 | if (audio_config.enable && voices < 8) { | 325 | if (audio_config.enable && voices < 8) { |
320 | DISABLE_AUDIO_COUNTER_3_ISR; | 326 | DISABLE_AUDIO_COUNTER_3_ISR; |
321 | 327 | ||
322 | // Cancel notes if notes are playing | 328 | // Cancel notes if notes are playing |
323 | if (playing_notes) | 329 | if (playing_notes) |
324 | stop_all_notes(); | 330 | stop_all_notes(); |
325 | 331 | ||
326 | playing_note = true; | 332 | playing_note = true; |
327 | 333 | ||
328 | envelope_index = 0; | 334 | envelope_index = 0; |
329 | 335 | ||
330 | if (freq > 0) { | 336 | if (freq > 0) { |
331 | frequencies[voices] = freq; | 337 | frequencies[voices] = freq; |
332 | volumes[voices] = vol; | 338 | volumes[voices] = vol; |
333 | voices++; | 339 | voices++; |
334 | } | 340 | } |
335 | 341 | ||
336 | ENABLE_AUDIO_COUNTER_3_ISR; | 342 | ENABLE_AUDIO_COUNTER_3_ISR; |
337 | ENABLE_AUDIO_COUNTER_3_OUTPUT; | 343 | ENABLE_AUDIO_COUNTER_3_OUTPUT; |
338 | } | 344 | } |
339 | 345 | ||
340 | } | 346 | } |
341 | 347 | ||
@@ -346,37 +352,37 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) | |||
346 | audio_init(); | 352 | audio_init(); |
347 | } | 353 | } |
348 | 354 | ||
349 | if (audio_config.enable) { | 355 | if (audio_config.enable) { |
350 | 356 | ||
351 | DISABLE_AUDIO_COUNTER_3_ISR; | 357 | DISABLE_AUDIO_COUNTER_3_ISR; |
352 | 358 | ||
353 | // Cancel note if a note is playing | 359 | // Cancel note if a note is playing |
354 | if (playing_note) | 360 | if (playing_note) |
355 | stop_all_notes(); | 361 | stop_all_notes(); |
356 | 362 | ||
357 | playing_notes = true; | 363 | playing_notes = true; |
358 | 364 | ||
359 | notes_pointer = np; | 365 | notes_pointer = np; |
360 | notes_count = n_count; | 366 | notes_count = n_count; |
361 | notes_repeat = n_repeat; | 367 | notes_repeat = n_repeat; |
362 | notes_rest = n_rest; | 368 | notes_rest = n_rest; |
363 | 369 | ||
364 | place = 0; | 370 | place = 0; |
365 | current_note = 0; | 371 | current_note = 0; |
366 | 372 | ||
367 | note_frequency = (*notes_pointer)[current_note][0]; | 373 | note_frequency = (*notes_pointer)[current_note][0]; |
368 | note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100); | 374 | note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100); |
369 | note_position = 0; | 375 | note_position = 0; |
370 | 376 | ||
371 | 377 | ||
372 | ENABLE_AUDIO_COUNTER_3_ISR; | 378 | ENABLE_AUDIO_COUNTER_3_ISR; |
373 | ENABLE_AUDIO_COUNTER_3_OUTPUT; | 379 | ENABLE_AUDIO_COUNTER_3_OUTPUT; |
374 | } | 380 | } |
375 | 381 | ||
376 | } | 382 | } |
377 | 383 | ||
378 | bool is_playing_notes(void) { | 384 | bool is_playing_notes(void) { |
379 | return playing_notes; | 385 | return playing_notes; |
380 | } | 386 | } |
381 | 387 | ||
382 | bool is_audio_on(void) { | 388 | bool is_audio_on(void) { |
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c new file mode 100644 index 000000000..0b6380ed3 --- /dev/null +++ b/quantum/process_keycode/process_audio.c | |||
@@ -0,0 +1,62 @@ | |||
1 | #include "audio.h" | ||
2 | #include "process_audio.h" | ||
3 | |||
4 | static float compute_freq_for_midi_note(uint8_t note) | ||
5 | { | ||
6 | // https://en.wikipedia.org/wiki/MIDI_tuning_standard | ||
7 | return pow(2.0, (note - 69) / 12.0) * 440.0f; | ||
8 | } | ||
9 | |||
10 | bool process_audio(uint16_t keycode, keyrecord_t *record) { | ||
11 | |||
12 | if (keycode == AU_ON && record->event.pressed) { | ||
13 | audio_on(); | ||
14 | return false; | ||
15 | } | ||
16 | |||
17 | if (keycode == AU_OFF && record->event.pressed) { | ||
18 | audio_off(); | ||
19 | return false; | ||
20 | } | ||
21 | |||
22 | if (keycode == AU_TOG && record->event.pressed) { | ||
23 | if (is_audio_on()) | ||
24 | { | ||
25 | audio_off(); | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | audio_on(); | ||
30 | } | ||
31 | return false; | ||
32 | } | ||
33 | |||
34 | if (keycode == MUV_IN && record->event.pressed) { | ||
35 | voice_iterate(); | ||
36 | music_scale_user(); | ||
37 | return false; | ||
38 | } | ||
39 | |||
40 | if (keycode == MUV_DE && record->event.pressed) { | ||
41 | voice_deiterate(); | ||
42 | music_scale_user(); | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | return true; | ||
47 | } | ||
48 | |||
49 | void process_audio_noteon(uint8_t note) { | ||
50 | play_note(compute_freq_for_midi_note(note), 0xF); | ||
51 | } | ||
52 | |||
53 | void process_audio_noteoff(uint8_t note) { | ||
54 | stop_note(compute_freq_for_midi_note(note)); | ||
55 | } | ||
56 | |||
57 | void process_audio_all_notes_off(void) { | ||
58 | stop_all_notes(); | ||
59 | } | ||
60 | |||
61 | __attribute__ ((weak)) | ||
62 | void audio_on_user() {} \ No newline at end of file | ||
diff --git a/quantum/process_keycode/process_audio.h b/quantum/process_keycode/process_audio.h new file mode 100644 index 000000000..7ac15b733 --- /dev/null +++ b/quantum/process_keycode/process_audio.h | |||
@@ -0,0 +1,11 @@ | |||
1 | #ifndef PROCESS_AUDIO_H | ||
2 | #define PROCESS_AUDIO_H | ||
3 | |||
4 | bool process_audio(uint16_t keycode, keyrecord_t *record); | ||
5 | void process_audio_noteon(uint8_t note); | ||
6 | void process_audio_noteoff(uint8_t note); | ||
7 | void process_audio_all_notes_off(void); | ||
8 | |||
9 | void audio_on_user(void); | ||
10 | |||
11 | #endif \ No newline at end of file | ||
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 577dad43a..700c6ce8e 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c | |||
@@ -1,68 +1,238 @@ | |||
1 | #include "process_midi.h" | 1 | #include "process_midi.h" |
2 | 2 | ||
3 | bool midi_activated = false; | 3 | #ifdef MIDI_ENABLE |
4 | uint8_t midi_starting_note = 0x0C; | 4 | #include "midi.h" |
5 | int midi_offset = 7; | 5 | |
6 | 6 | #ifdef MIDI_BASIC | |
7 | bool process_midi(uint16_t keycode, keyrecord_t *record) { | 7 | |
8 | if (keycode == MI_ON && record->event.pressed) { | 8 | void process_midi_basic_noteon(uint8_t note) |
9 | midi_activated = true; | 9 | { |
10 | #ifdef AUDIO_ENABLE | 10 | midi_send_noteon(&midi_device, 0, note, 128); |
11 | music_scale_user(); | 11 | } |
12 | #endif | 12 | |
13 | return false; | 13 | void process_midi_basic_noteoff(uint8_t note) |
14 | } | 14 | { |
15 | midi_send_noteoff(&midi_device, 0, note, 0); | ||
16 | } | ||
17 | |||
18 | void process_midi_all_notes_off(void) | ||
19 | { | ||
20 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
21 | } | ||
22 | |||
23 | #endif // MIDI_BASIC | ||
24 | |||
25 | #ifdef MIDI_ADVANCED | ||
26 | |||
27 | #include "timer.h" | ||
28 | |||
29 | static uint8_t tone_status[MIDI_TONE_COUNT]; | ||
30 | |||
31 | static uint8_t midi_modulation; | ||
32 | static int8_t midi_modulation_step; | ||
33 | static uint16_t midi_modulation_timer; | ||
34 | |||
35 | inline uint8_t compute_velocity(uint8_t setting) | ||
36 | { | ||
37 | return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); | ||
38 | } | ||
15 | 39 | ||
16 | if (keycode == MI_OFF && record->event.pressed) { | 40 | void midi_init(void) |
17 | midi_activated = false; | 41 | { |
18 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 42 | midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; |
19 | return false; | 43 | midi_config.transpose = 0; |
44 | midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); | ||
45 | midi_config.channel = 0; | ||
46 | midi_config.modulation_interval = 8; | ||
47 | |||
48 | for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) | ||
49 | { | ||
50 | tone_status[i] = MIDI_INVALID_NOTE; | ||
20 | } | 51 | } |
21 | 52 | ||
22 | if (midi_activated) { | 53 | midi_modulation = 0; |
23 | if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) { | 54 | midi_modulation_step = 0; |
24 | if (record->event.pressed) { | 55 | midi_modulation_timer = 0; |
25 | midi_starting_note++; // Change key | 56 | } |
26 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 57 | |
27 | } | 58 | void midi_task(void) |
28 | return false; | 59 | { |
29 | } | 60 | if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) |
30 | if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) { | 61 | return; |
31 | if (record->event.pressed) { | 62 | midi_modulation_timer = timer_read(); |
32 | midi_starting_note--; // Change key | 63 | |
33 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 64 | if (midi_modulation_step != 0) |
34 | } | 65 | { |
35 | return false; | 66 | dprintf("midi modulation %d\n", midi_modulation); |
36 | } | 67 | midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation); |
37 | if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | 68 | |
38 | midi_offset++; // Change scale | 69 | if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) { |
39 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 70 | midi_modulation = 0; |
40 | return false; | 71 | midi_modulation_step = 0; |
41 | } | 72 | return; |
42 | if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | 73 | } |
43 | midi_offset--; // Change scale | 74 | |
44 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 75 | midi_modulation += midi_modulation_step; |
45 | return false; | 76 | |
46 | } | 77 | if (midi_modulation > 127) |
47 | // basic | 78 | midi_modulation = 127; |
48 | // uint8_t note = (midi_starting_note + SCALE[record->event.key.col + midi_offset])+12*(MATRIX_ROWS - record->event.key.row); | ||
49 | // advanced | ||
50 | // uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+12*(MATRIX_ROWS - record->event.key.row); | ||
51 | // guitar | ||
52 | uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+5*(MATRIX_ROWS - record->event.key.row); | ||
53 | // violin | ||
54 | // uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+7*(MATRIX_ROWS - record->event.key.row); | ||
55 | |||
56 | if (record->event.pressed) { | ||
57 | // midi_send_noteon(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127); | ||
58 | midi_send_noteon(&midi_device, 0, note, 127); | ||
59 | } else { | ||
60 | // midi_send_noteoff(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127); | ||
61 | midi_send_noteoff(&midi_device, 0, note, 127); | ||
62 | } | ||
63 | |||
64 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through | ||
65 | return false; | ||
66 | } | 79 | } |
67 | return true; | ||
68 | } | 80 | } |
81 | |||
82 | uint8_t midi_compute_note(uint16_t keycode) | ||
83 | { | ||
84 | return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; | ||
85 | } | ||
86 | |||
87 | bool process_midi(uint16_t keycode, keyrecord_t *record) | ||
88 | { | ||
89 | switch (keycode) { | ||
90 | case MIDI_TONE_MIN ... MIDI_TONE_MAX: | ||
91 | { | ||
92 | uint8_t channel = midi_config.channel; | ||
93 | uint8_t tone = keycode - MIDI_TONE_MIN; | ||
94 | uint8_t velocity = compute_velocity(midi_config.velocity); | ||
95 | if (record->event.pressed) { | ||
96 | uint8_t note = midi_compute_note(keycode); | ||
97 | midi_send_noteon(&midi_device, channel, note, velocity); | ||
98 | dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); | ||
99 | tone_status[tone] = note; | ||
100 | } | ||
101 | else { | ||
102 | uint8_t note = tone_status[tone]; | ||
103 | if (note != MIDI_INVALID_NOTE) | ||
104 | { | ||
105 | midi_send_noteoff(&midi_device, channel, note, velocity); | ||
106 | dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); | ||
107 | } | ||
108 | tone_status[tone] = MIDI_INVALID_NOTE; | ||
109 | } | ||
110 | return false; | ||
111 | } | ||
112 | case MIDI_OCTAVE_MIN ... MIDI_OCTAVE_MAX: | ||
113 | if (record->event.pressed) { | ||
114 | midi_config.octave = keycode - MIDI_OCTAVE_MIN; | ||
115 | dprintf("midi octave %d\n", midi_config.octave); | ||
116 | } | ||
117 | return false; | ||
118 | case MI_OCTD: | ||
119 | if (record->event.pressed && midi_config.octave > 0) { | ||
120 | midi_config.octave--; | ||
121 | dprintf("midi octave %d\n", midi_config.octave); | ||
122 | } | ||
123 | return false; | ||
124 | case MI_OCTU: | ||
125 | if (record->event.pressed && midi_config.octave < (MIDI_OCTAVE_MAX - MIDI_OCTAVE_MIN)) { | ||
126 | midi_config.octave++; | ||
127 | dprintf("midi octave %d\n", midi_config.octave); | ||
128 | } | ||
129 | return false; | ||
130 | case MIDI_TRANSPOSE_MIN ... MIDI_TRANSPOSE_MAX: | ||
131 | if (record->event.pressed) { | ||
132 | midi_config.transpose = keycode - MI_TRNS_0; | ||
133 | dprintf("midi transpose %d\n", midi_config.transpose); | ||
134 | } | ||
135 | return false; | ||
136 | case MI_TRNSD: | ||
137 | if (record->event.pressed && midi_config.transpose > (MIDI_TRANSPOSE_MIN - MI_TRNS_0)) { | ||
138 | midi_config.transpose--; | ||
139 | dprintf("midi transpose %d\n", midi_config.transpose); | ||
140 | } | ||
141 | return false; | ||
142 | case MI_TRNSU: | ||
143 | if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { | ||
144 | const bool positive = midi_config.transpose > 0; | ||
145 | midi_config.transpose++; | ||
146 | if (positive && midi_config.transpose < 0) | ||
147 | midi_config.transpose--; | ||
148 | dprintf("midi transpose %d\n", midi_config.transpose); | ||
149 | } | ||
150 | return false; | ||
151 | case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: | ||
152 | if (record->event.pressed) { | ||
153 | midi_config.velocity = keycode - MIDI_VELOCITY_MIN; | ||
154 | dprintf("midi velocity %d\n", midi_config.velocity); | ||
155 | } | ||
156 | return false; | ||
157 | case MI_VELD: | ||
158 | if (record->event.pressed && midi_config.velocity > 0) { | ||
159 | midi_config.velocity--; | ||
160 | dprintf("midi velocity %d\n", midi_config.velocity); | ||
161 | } | ||
162 | return false; | ||
163 | case MI_VELU: | ||
164 | if (record->event.pressed) { | ||
165 | midi_config.velocity++; | ||
166 | dprintf("midi velocity %d\n", midi_config.velocity); | ||
167 | } | ||
168 | return false; | ||
169 | case MIDI_CHANNEL_MIN ... MIDI_CHANNEL_MAX: | ||
170 | if (record->event.pressed) { | ||
171 | midi_config.channel = keycode - MIDI_CHANNEL_MIN; | ||
172 | dprintf("midi channel %d\n", midi_config.channel); | ||
173 | } | ||
174 | return false; | ||
175 | case MI_CHD: | ||
176 | if (record->event.pressed) { | ||
177 | midi_config.channel--; | ||
178 | dprintf("midi channel %d\n", midi_config.channel); | ||
179 | } | ||
180 | return false; | ||
181 | case MI_CHU: | ||
182 | if (record->event.pressed) { | ||
183 | midi_config.channel++; | ||
184 | dprintf("midi channel %d\n", midi_config.channel); | ||
185 | } | ||
186 | return false; | ||
187 | case MI_ALLOFF: | ||
188 | if (record->event.pressed) { | ||
189 | midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0); | ||
190 | dprintf("midi all notes off\n"); | ||
191 | } | ||
192 | return false; | ||
193 | case MI_SUS: | ||
194 | midi_send_cc(&midi_device, midi_config.channel, 0x40, record->event.pressed ? 127 : 0); | ||
195 | dprintf("midi sustain %d\n", record->event.pressed); | ||
196 | return false; | ||
197 | case MI_PORT: | ||
198 | midi_send_cc(&midi_device, midi_config.channel, 0x41, record->event.pressed ? 127 : 0); | ||
199 | dprintf("midi portamento %d\n", record->event.pressed); | ||
200 | return false; | ||
201 | case MI_SOST: | ||
202 | midi_send_cc(&midi_device, midi_config.channel, 0x42, record->event.pressed ? 127 : 0); | ||
203 | dprintf("midi sostenuto %d\n", record->event.pressed); | ||
204 | return false; | ||
205 | case MI_SOFT: | ||
206 | midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); | ||
207 | dprintf("midi soft %d\n", record->event.pressed); | ||
208 | return false; | ||
209 | case MI_LEG: | ||
210 | midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); | ||
211 | dprintf("midi legato %d\n", record->event.pressed); | ||
212 | return false; | ||
213 | case MI_MOD: | ||
214 | midi_modulation_step = record->event.pressed ? 1 : -1; | ||
215 | return false; | ||
216 | case MI_MODSD: | ||
217 | if (record->event.pressed) { | ||
218 | midi_config.modulation_interval++; | ||
219 | // prevent overflow | ||
220 | if (midi_config.modulation_interval == 0) | ||
221 | midi_config.modulation_interval--; | ||
222 | dprintf("midi modulation interval %d\n", midi_config.modulation_interval); | ||
223 | } | ||
224 | return false; | ||
225 | case MI_MODSU: | ||
226 | if (record->event.pressed && midi_config.modulation_interval > 0) { | ||
227 | midi_config.modulation_interval--; | ||
228 | dprintf("midi modulation interval %d\n", midi_config.modulation_interval); | ||
229 | } | ||
230 | return false; | ||
231 | }; | ||
232 | |||
233 | return true; | ||
234 | } | ||
235 | |||
236 | #endif // MIDI_ADVANCED | ||
237 | |||
238 | #endif // MIDI_ENABLE | ||
diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index acd4fc1b1..58b7650c6 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h | |||
@@ -3,205 +3,38 @@ | |||
3 | 3 | ||
4 | #include "quantum.h" | 4 | #include "quantum.h" |
5 | 5 | ||
6 | bool process_midi(uint16_t keycode, keyrecord_t *record); | 6 | #ifdef MIDI_ENABLE |
7 | |||
8 | #ifdef MIDI_BASIC | ||
9 | void process_midi_basic_noteon(uint8_t note); | ||
10 | void process_midi_basic_noteoff(uint8_t note); | ||
11 | void process_midi_all_notes_off(void); | ||
12 | #endif | ||
13 | |||
14 | #ifdef MIDI_ADVANCED | ||
15 | typedef union { | ||
16 | uint32_t raw; | ||
17 | struct { | ||
18 | uint8_t octave :4; | ||
19 | int8_t transpose :4; | ||
20 | uint8_t velocity :4; | ||
21 | uint8_t channel :4; | ||
22 | uint8_t modulation_interval :4; | ||
23 | }; | ||
24 | } midi_config_t; | ||
7 | 25 | ||
8 | #define MIDI(n) ((n) | 0x6000) | 26 | midi_config_t midi_config; |
9 | #define MIDI12 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000 | 27 | |
28 | void midi_init(void); | ||
29 | void midi_task(void); | ||
30 | bool process_midi(uint16_t keycode, keyrecord_t *record); | ||
10 | 31 | ||
11 | #define CHNL(note, channel) (note + (channel << 8)) | 32 | #define MIDI_INVALID_NOTE 0xFF |
33 | #define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) | ||
12 | 34 | ||
13 | #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), \ | 35 | uint8_t midi_compute_note(uint16_t keycode); |
14 | 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ | 36 | #endif // MIDI_ADVANCED |
15 | 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \ | ||
16 | 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \ | ||
17 | 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } | ||
18 | 37 | ||
19 | #define N_CN1 (0x600C + (12 * -1) + 0 ) | 38 | #endif // MIDI_ENABLE |
20 | #define N_CN1S (0x600C + (12 * -1) + 1 ) | ||
21 | #define N_DN1F (0x600C + (12 * -1) + 1 ) | ||
22 | #define N_DN1 (0x600C + (12 * -1) + 2 ) | ||
23 | #define N_DN1S (0x600C + (12 * -1) + 3 ) | ||
24 | #define N_EN1F (0x600C + (12 * -1) + 3 ) | ||
25 | #define N_EN1 (0x600C + (12 * -1) + 4 ) | ||
26 | #define N_FN1 (0x600C + (12 * -1) + 5 ) | ||
27 | #define N_FN1S (0x600C + (12 * -1) + 6 ) | ||
28 | #define N_GN1F (0x600C + (12 * -1) + 6 ) | ||
29 | #define N_GN1 (0x600C + (12 * -1) + 7 ) | ||
30 | #define N_GN1S (0x600C + (12 * -1) + 8 ) | ||
31 | #define N_AN1F (0x600C + (12 * -1) + 8 ) | ||
32 | #define N_AN1 (0x600C + (12 * -1) + 9 ) | ||
33 | #define N_AN1S (0x600C + (12 * -1) + 10) | ||
34 | #define N_BN1F (0x600C + (12 * -1) + 10) | ||
35 | #define N_BN1 (0x600C + (12 * -1) + 11) | ||
36 | #define N_C0 (0x600C + (12 * 0) + 0 ) | ||
37 | #define N_C0S (0x600C + (12 * 0) + 1 ) | ||
38 | #define N_D0F (0x600C + (12 * 0) + 1 ) | ||
39 | #define N_D0 (0x600C + (12 * 0) + 2 ) | ||
40 | #define N_D0S (0x600C + (12 * 0) + 3 ) | ||
41 | #define N_E0F (0x600C + (12 * 0) + 3 ) | ||
42 | #define N_E0 (0x600C + (12 * 0) + 4 ) | ||
43 | #define N_F0 (0x600C + (12 * 0) + 5 ) | ||
44 | #define N_F0S (0x600C + (12 * 0) + 6 ) | ||
45 | #define N_G0F (0x600C + (12 * 0) + 6 ) | ||
46 | #define N_G0 (0x600C + (12 * 0) + 7 ) | ||
47 | #define N_G0S (0x600C + (12 * 0) + 8 ) | ||
48 | #define N_A0F (0x600C + (12 * 0) + 8 ) | ||
49 | #define N_A0 (0x600C + (12 * 0) + 9 ) | ||
50 | #define N_A0S (0x600C + (12 * 0) + 10) | ||
51 | #define N_B0F (0x600C + (12 * 0) + 10) | ||
52 | #define N_B0 (0x600C + (12 * 0) + 11) | ||
53 | #define N_C1 (0x600C + (12 * 1) + 0 ) | ||
54 | #define N_C1S (0x600C + (12 * 1) + 1 ) | ||
55 | #define N_D1F (0x600C + (12 * 1) + 1 ) | ||
56 | #define N_D1 (0x600C + (12 * 1) + 2 ) | ||
57 | #define N_D1S (0x600C + (12 * 1) + 3 ) | ||
58 | #define N_E1F (0x600C + (12 * 1) + 3 ) | ||
59 | #define N_E1 (0x600C + (12 * 1) + 4 ) | ||
60 | #define N_F1 (0x600C + (12 * 1) + 5 ) | ||
61 | #define N_F1S (0x600C + (12 * 1) + 6 ) | ||
62 | #define N_G1F (0x600C + (12 * 1) + 6 ) | ||
63 | #define N_G1 (0x600C + (12 * 1) + 7 ) | ||
64 | #define N_G1S (0x600C + (12 * 1) + 8 ) | ||
65 | #define N_A1F (0x600C + (12 * 1) + 8 ) | ||
66 | #define N_A1 (0x600C + (12 * 1) + 9 ) | ||
67 | #define N_A1S (0x600C + (12 * 1) + 10) | ||
68 | #define N_B1F (0x600C + (12 * 1) + 10) | ||
69 | #define N_B1 (0x600C + (12 * 1) + 11) | ||
70 | #define N_C2 (0x600C + (12 * 2) + 0 ) | ||
71 | #define N_C2S (0x600C + (12 * 2) + 1 ) | ||
72 | #define N_D2F (0x600C + (12 * 2) + 1 ) | ||
73 | #define N_D2 (0x600C + (12 * 2) + 2 ) | ||
74 | #define N_D2S (0x600C + (12 * 2) + 3 ) | ||
75 | #define N_E2F (0x600C + (12 * 2) + 3 ) | ||
76 | #define N_E2 (0x600C + (12 * 2) + 4 ) | ||
77 | #define N_F2 (0x600C + (12 * 2) + 5 ) | ||
78 | #define N_F2S (0x600C + (12 * 2) + 6 ) | ||
79 | #define N_G2F (0x600C + (12 * 2) + 6 ) | ||
80 | #define N_G2 (0x600C + (12 * 2) + 7 ) | ||
81 | #define N_G2S (0x600C + (12 * 2) + 8 ) | ||
82 | #define N_A2F (0x600C + (12 * 2) + 8 ) | ||
83 | #define N_A2 (0x600C + (12 * 2) + 9 ) | ||
84 | #define N_A2S (0x600C + (12 * 2) + 10) | ||
85 | #define N_B2F (0x600C + (12 * 2) + 10) | ||
86 | #define N_B2 (0x600C + (12 * 2) + 11) | ||
87 | #define N_C3 (0x600C + (12 * 3) + 0 ) | ||
88 | #define N_C3S (0x600C + (12 * 3) + 1 ) | ||
89 | #define N_D3F (0x600C + (12 * 3) + 1 ) | ||
90 | #define N_D3 (0x600C + (12 * 3) + 2 ) | ||
91 | #define N_D3S (0x600C + (12 * 3) + 3 ) | ||
92 | #define N_E3F (0x600C + (12 * 3) + 3 ) | ||
93 | #define N_E3 (0x600C + (12 * 3) + 4 ) | ||
94 | #define N_F3 (0x600C + (12 * 3) + 5 ) | ||
95 | #define N_F3S (0x600C + (12 * 3) + 6 ) | ||
96 | #define N_G3F (0x600C + (12 * 3) + 6 ) | ||
97 | #define N_G3 (0x600C + (12 * 3) + 7 ) | ||
98 | #define N_G3S (0x600C + (12 * 3) + 8 ) | ||
99 | #define N_A3F (0x600C + (12 * 3) + 8 ) | ||
100 | #define N_A3 (0x600C + (12 * 3) + 9 ) | ||
101 | #define N_A3S (0x600C + (12 * 3) + 10) | ||
102 | #define N_B3F (0x600C + (12 * 3) + 10) | ||
103 | #define N_B3 (0x600C + (12 * 3) + 11) | ||
104 | #define N_C4 (0x600C + (12 * 4) + 0 ) | ||
105 | #define N_C4S (0x600C + (12 * 4) + 1 ) | ||
106 | #define N_D4F (0x600C + (12 * 4) + 1 ) | ||
107 | #define N_D4 (0x600C + (12 * 4) + 2 ) | ||
108 | #define N_D4S (0x600C + (12 * 4) + 3 ) | ||
109 | #define N_E4F (0x600C + (12 * 4) + 3 ) | ||
110 | #define N_E4 (0x600C + (12 * 4) + 4 ) | ||
111 | #define N_F4 (0x600C + (12 * 4) + 5 ) | ||
112 | #define N_F4S (0x600C + (12 * 4) + 6 ) | ||
113 | #define N_G4F (0x600C + (12 * 4) + 6 ) | ||
114 | #define N_G4 (0x600C + (12 * 4) + 7 ) | ||
115 | #define N_G4S (0x600C + (12 * 4) + 8 ) | ||
116 | #define N_A4F (0x600C + (12 * 4) + 8 ) | ||
117 | #define N_A4 (0x600C + (12 * 4) + 9 ) | ||
118 | #define N_A4S (0x600C + (12 * 4) + 10) | ||
119 | #define N_B4F (0x600C + (12 * 4) + 10) | ||
120 | #define N_B4 (0x600C + (12 * 4) + 11) | ||
121 | #define N_C5 (0x600C + (12 * 5) + 0 ) | ||
122 | #define N_C5S (0x600C + (12 * 5) + 1 ) | ||
123 | #define N_D5F (0x600C + (12 * 5) + 1 ) | ||
124 | #define N_D5 (0x600C + (12 * 5) + 2 ) | ||
125 | #define N_D5S (0x600C + (12 * 5) + 3 ) | ||
126 | #define N_E5F (0x600C + (12 * 5) + 3 ) | ||
127 | #define N_E5 (0x600C + (12 * 5) + 4 ) | ||
128 | #define N_F5 (0x600C + (12 * 5) + 5 ) | ||
129 | #define N_F5S (0x600C + (12 * 5) + 6 ) | ||
130 | #define N_G5F (0x600C + (12 * 5) + 6 ) | ||
131 | #define N_G5 (0x600C + (12 * 5) + 7 ) | ||
132 | #define N_G5S (0x600C + (12 * 5) + 8 ) | ||
133 | #define N_A5F (0x600C + (12 * 5) + 8 ) | ||
134 | #define N_A5 (0x600C + (12 * 5) + 9 ) | ||
135 | #define N_A5S (0x600C + (12 * 5) + 10) | ||
136 | #define N_B5F (0x600C + (12 * 5) + 10) | ||
137 | #define N_B5 (0x600C + (12 * 5) + 11) | ||
138 | #define N_C6 (0x600C + (12 * 6) + 0 ) | ||
139 | #define N_C6S (0x600C + (12 * 6) + 1 ) | ||
140 | #define N_D6F (0x600C + (12 * 6) + 1 ) | ||
141 | #define N_D6 (0x600C + (12 * 6) + 2 ) | ||
142 | #define N_D6S (0x600C + (12 * 6) + 3 ) | ||
143 | #define N_E6F (0x600C + (12 * 6) + 3 ) | ||
144 | #define N_E6 (0x600C + (12 * 6) + 4 ) | ||
145 | #define N_F6 (0x600C + (12 * 6) + 5 ) | ||
146 | #define N_F6S (0x600C + (12 * 6) + 6 ) | ||
147 | #define N_G6F (0x600C + (12 * 6) + 6 ) | ||
148 | #define N_G6 (0x600C + (12 * 6) + 7 ) | ||
149 | #define N_G6S (0x600C + (12 * 6) + 8 ) | ||
150 | #define N_A6F (0x600C + (12 * 6) + 8 ) | ||
151 | #define N_A6 (0x600C + (12 * 6) + 9 ) | ||
152 | #define N_A6S (0x600C + (12 * 6) + 10) | ||
153 | #define N_B6F (0x600C + (12 * 6) + 10) | ||
154 | #define N_B6 (0x600C + (12 * 6) + 11) | ||
155 | #define N_C7 (0x600C + (12 * 7) + 0 ) | ||
156 | #define N_C7S (0x600C + (12 * 7) + 1 ) | ||
157 | #define N_D7F (0x600C + (12 * 7) + 1 ) | ||
158 | #define N_D7 (0x600C + (12 * 7) + 2 ) | ||
159 | #define N_D7S (0x600C + (12 * 7) + 3 ) | ||
160 | #define N_E7F (0x600C + (12 * 7) + 3 ) | ||
161 | #define N_E7 (0x600C + (12 * 7) + 4 ) | ||
162 | #define N_F7 (0x600C + (12 * 7) + 5 ) | ||
163 | #define N_F7S (0x600C + (12 * 7) + 6 ) | ||
164 | #define N_G7F (0x600C + (12 * 7) + 6 ) | ||
165 | #define N_G7 (0x600C + (12 * 7) + 7 ) | ||
166 | #define N_G7S (0x600C + (12 * 7) + 8 ) | ||
167 | #define N_A7F (0x600C + (12 * 7) + 8 ) | ||
168 | #define N_A7 (0x600C + (12 * 7) + 9 ) | ||
169 | #define N_A7S (0x600C + (12 * 7) + 10) | ||
170 | #define N_B7F (0x600C + (12 * 7) + 10) | ||
171 | #define N_B7 (0x600C + (12 * 7) + 11) | ||
172 | #define N_C8 (0x600C + (12 * 8) + 0 ) | ||
173 | #define N_C8S (0x600C + (12 * 8) + 1 ) | ||
174 | #define N_D8F (0x600C + (12 * 8) + 1 ) | ||
175 | #define N_D8 (0x600C + (12 * 8) + 2 ) | ||
176 | #define N_D8S (0x600C + (12 * 8) + 3 ) | ||
177 | #define N_E8F (0x600C + (12 * 8) + 3 ) | ||
178 | #define N_E8 (0x600C + (12 * 8) + 4 ) | ||
179 | #define N_F8 (0x600C + (12 * 8) + 5 ) | ||
180 | #define N_F8S (0x600C + (12 * 8) + 6 ) | ||
181 | #define N_G8F (0x600C + (12 * 8) + 6 ) | ||
182 | #define N_G8 (0x600C + (12 * 8) + 7 ) | ||
183 | #define N_G8S (0x600C + (12 * 8) + 8 ) | ||
184 | #define N_A8F (0x600C + (12 * 8) + 8 ) | ||
185 | #define N_A8 (0x600C + (12 * 8) + 9 ) | ||
186 | #define N_A8S (0x600C + (12 * 8) + 10) | ||
187 | #define N_B8F (0x600C + (12 * 8) + 10) | ||
188 | #define N_B8 (0x600C + (12 * 8) + 11) | ||
189 | #define N_C8 (0x600C + (12 * 8) + 0 ) | ||
190 | #define N_C8S (0x600C + (12 * 8) + 1 ) | ||
191 | #define N_D8F (0x600C + (12 * 8) + 1 ) | ||
192 | #define N_D8 (0x600C + (12 * 8) + 2 ) | ||
193 | #define N_D8S (0x600C + (12 * 8) + 3 ) | ||
194 | #define N_E8F (0x600C + (12 * 8) + 3 ) | ||
195 | #define N_E8 (0x600C + (12 * 8) + 4 ) | ||
196 | #define N_F8 (0x600C + (12 * 8) + 5 ) | ||
197 | #define N_F8S (0x600C + (12 * 8) + 6 ) | ||
198 | #define N_G8F (0x600C + (12 * 8) + 6 ) | ||
199 | #define N_G8 (0x600C + (12 * 8) + 7 ) | ||
200 | #define N_G8S (0x600C + (12 * 8) + 8 ) | ||
201 | #define N_A8F (0x600C + (12 * 8) + 8 ) | ||
202 | #define N_A8 (0x600C + (12 * 8) + 9 ) | ||
203 | #define N_A8S (0x600C + (12 * 8) + 10) | ||
204 | #define N_B8F (0x600C + (12 * 8) + 10) | ||
205 | #define N_B8 (0x600C + (12 * 8) + 11) | ||
206 | 39 | ||
207 | #endif \ No newline at end of file | 40 | #endif \ No newline at end of file |
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 1e2648bff..f89a04ee3 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c | |||
@@ -1,5 +1,14 @@ | |||
1 | #include "process_music.h" | 1 | #include "process_music.h" |
2 | 2 | ||
3 | #ifdef AUDIO_ENABLE | ||
4 | #include "process_audio.h" | ||
5 | #endif | ||
6 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | ||
7 | #include "process_midi.h" | ||
8 | #endif | ||
9 | |||
10 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | ||
11 | |||
3 | bool music_activated = false; | 12 | bool music_activated = false; |
4 | uint8_t music_starting_note = 0x0C; | 13 | uint8_t music_starting_note = 0x0C; |
5 | int music_offset = 7; | 14 | int music_offset = 7; |
@@ -8,36 +17,41 @@ int music_offset = 7; | |||
8 | static bool music_sequence_recording = false; | 17 | static bool music_sequence_recording = false; |
9 | static bool music_sequence_recorded = false; | 18 | static bool music_sequence_recorded = false; |
10 | static bool music_sequence_playing = false; | 19 | static bool music_sequence_playing = false; |
11 | static float music_sequence[16] = {0}; | 20 | static uint8_t music_sequence[16] = {0}; |
12 | static uint8_t music_sequence_count = 0; | 21 | static uint8_t music_sequence_count = 0; |
13 | static uint8_t music_sequence_position = 0; | 22 | static uint8_t music_sequence_position = 0; |
14 | 23 | ||
15 | static uint16_t music_sequence_timer = 0; | 24 | static uint16_t music_sequence_timer = 0; |
16 | static uint16_t music_sequence_interval = 100; | 25 | static uint16_t music_sequence_interval = 100; |
17 | 26 | ||
18 | bool process_music(uint16_t keycode, keyrecord_t *record) { | 27 | static void music_noteon(uint8_t note) { |
28 | #ifdef AUDIO_ENABLE | ||
29 | process_audio_noteon(note); | ||
30 | #endif | ||
31 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | ||
32 | process_midi_basic_noteon(note); | ||
33 | #endif | ||
34 | } | ||
19 | 35 | ||
20 | if (keycode == AU_ON && record->event.pressed) { | 36 | static void music_noteoff(uint8_t note) { |
21 | audio_on(); | 37 | #ifdef AUDIO_ENABLE |
22 | return false; | 38 | process_audio_noteoff(note); |
23 | } | 39 | #endif |
40 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | ||
41 | process_midi_basic_noteoff(note); | ||
42 | #endif | ||
43 | } | ||
24 | 44 | ||
25 | if (keycode == AU_OFF && record->event.pressed) { | 45 | void music_all_notes_off(void) { |
26 | audio_off(); | 46 | #ifdef AUDIO_ENABLE |
27 | return false; | 47 | process_audio_all_notes_off(); |
28 | } | 48 | #endif |
49 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | ||
50 | process_midi_all_notes_off(); | ||
51 | #endif | ||
52 | } | ||
29 | 53 | ||
30 | if (keycode == AU_TOG && record->event.pressed) { | 54 | bool process_music(uint16_t keycode, keyrecord_t *record) { |
31 | if (is_audio_on()) | ||
32 | { | ||
33 | audio_off(); | ||
34 | } | ||
35 | else | ||
36 | { | ||
37 | audio_on(); | ||
38 | } | ||
39 | return false; | ||
40 | } | ||
41 | 55 | ||
42 | if (keycode == MU_ON && record->event.pressed) { | 56 | if (keycode == MU_ON && record->event.pressed) { |
43 | music_on(); | 57 | music_on(); |
@@ -61,22 +75,10 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
61 | return false; | 75 | return false; |
62 | } | 76 | } |
63 | 77 | ||
64 | if (keycode == MUV_IN && record->event.pressed) { | ||
65 | voice_iterate(); | ||
66 | music_scale_user(); | ||
67 | return false; | ||
68 | } | ||
69 | |||
70 | if (keycode == MUV_DE && record->event.pressed) { | ||
71 | voice_deiterate(); | ||
72 | music_scale_user(); | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | if (music_activated) { | 78 | if (music_activated) { |
77 | 79 | ||
78 | if (keycode == KC_LCTL && record->event.pressed) { // Start recording | 80 | if (keycode == KC_LCTL && record->event.pressed) { // Start recording |
79 | stop_all_notes(); | 81 | music_all_notes_off(); |
80 | music_sequence_recording = true; | 82 | music_sequence_recording = true; |
81 | music_sequence_recorded = false; | 83 | music_sequence_recorded = false; |
82 | music_sequence_playing = false; | 84 | music_sequence_playing = false; |
@@ -85,7 +87,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
85 | } | 87 | } |
86 | 88 | ||
87 | if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing | 89 | if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing |
88 | stop_all_notes(); | 90 | music_all_notes_off(); |
89 | if (music_sequence_recording) { // was recording | 91 | if (music_sequence_recording) { // was recording |
90 | music_sequence_recorded = true; | 92 | music_sequence_recorded = true; |
91 | } | 93 | } |
@@ -95,7 +97,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
95 | } | 97 | } |
96 | 98 | ||
97 | if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing | 99 | if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing |
98 | stop_all_notes(); | 100 | music_all_notes_off(); |
99 | music_sequence_recording = false; | 101 | music_sequence_recording = false; |
100 | music_sequence_playing = true; | 102 | music_sequence_playing = true; |
101 | music_sequence_position = 0; | 103 | music_sequence_position = 0; |
@@ -114,32 +116,34 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
114 | music_sequence_interval+=10; | 116 | music_sequence_interval+=10; |
115 | return false; | 117 | return false; |
116 | } | 118 | } |
119 | |||
117 | #define MUSIC_MODE_GUITAR | 120 | #define MUSIC_MODE_GUITAR |
118 | 121 | ||
119 | #ifdef MUSIC_MODE_CHROMATIC | 122 | #ifdef MUSIC_MODE_CHROMATIC |
120 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row)); | 123 | uint8_t note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); |
121 | #elif defined(MUSIC_MODE_GUITAR) | 124 | #elif defined(MUSIC_MODE_GUITAR) |
122 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 7)*5.0/12); | 125 | uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); |
123 | #elif defined(MUSIC_MODE_VIOLIN) | 126 | #elif defined(MUSIC_MODE_VIOLIN) |
124 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 5)*7.0/12); | 127 | uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); |
125 | #else | 128 | #else |
126 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); | 129 | uint8_t note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); |
127 | #endif | 130 | #endif |
128 | 131 | ||
129 | if (record->event.pressed) { | 132 | if (record->event.pressed) { |
130 | play_note(freq, 0xF); | 133 | music_noteon(note); |
131 | if (music_sequence_recording) { | 134 | if (music_sequence_recording) { |
132 | music_sequence[music_sequence_count] = freq; | 135 | music_sequence[music_sequence_count] = note; |
133 | music_sequence_count++; | 136 | music_sequence_count++; |
134 | } | 137 | } |
135 | } else { | 138 | } else { |
136 | stop_note(freq); | 139 | music_noteoff(note); |
137 | } | 140 | } |
138 | 141 | ||
139 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through | 142 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through |
140 | return false; | 143 | return false; |
141 | } | 144 | } |
142 | return true; | 145 | |
146 | return true; | ||
143 | } | 147 | } |
144 | 148 | ||
145 | bool is_music_on(void) { | 149 | bool is_music_on(void) { |
@@ -161,26 +165,26 @@ void music_on(void) { | |||
161 | 165 | ||
162 | void music_off(void) { | 166 | void music_off(void) { |
163 | music_activated = 0; | 167 | music_activated = 0; |
164 | stop_all_notes(); | 168 | music_all_notes_off(); |
165 | } | 169 | } |
166 | 170 | ||
167 | |||
168 | __attribute__ ((weak)) | ||
169 | void music_on_user() {} | ||
170 | |||
171 | __attribute__ ((weak)) | ||
172 | void audio_on_user() {} | ||
173 | |||
174 | __attribute__ ((weak)) | ||
175 | void music_scale_user() {} | ||
176 | |||
177 | void matrix_scan_music(void) { | 171 | void matrix_scan_music(void) { |
178 | if (music_sequence_playing) { | 172 | if (music_sequence_playing) { |
179 | if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { | 173 | if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { |
180 | music_sequence_timer = timer_read(); | 174 | music_sequence_timer = timer_read(); |
181 | stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]); | 175 | uint8_t prev_note = music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]; |
182 | play_note(music_sequence[music_sequence_position], 0xF); | 176 | uint8_t next_note = music_sequence[music_sequence_position]; |
177 | music_noteoff(prev_note); | ||
178 | music_noteon(next_note); | ||
183 | music_sequence_position = (music_sequence_position + 1) % music_sequence_count; | 179 | music_sequence_position = (music_sequence_position + 1) % music_sequence_count; |
184 | } | 180 | } |
185 | } | 181 | } |
186 | } | 182 | } |
183 | |||
184 | __attribute__ ((weak)) | ||
185 | void music_on_user() {} | ||
186 | |||
187 | __attribute__ ((weak)) | ||
188 | void music_scale_user() {} | ||
189 | |||
190 | #endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) \ No newline at end of file | ||
diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 318b3e387..a36514a44 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h | |||
@@ -3,6 +3,8 @@ | |||
3 | 3 | ||
4 | #include "quantum.h" | 4 | #include "quantum.h" |
5 | 5 | ||
6 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | ||
7 | |||
6 | bool process_music(uint16_t keycode, keyrecord_t *record); | 8 | bool process_music(uint16_t keycode, keyrecord_t *record); |
7 | 9 | ||
8 | bool is_music_on(void); | 10 | bool is_music_on(void); |
@@ -10,9 +12,9 @@ void music_toggle(void); | |||
10 | void music_on(void); | 12 | void music_on(void); |
11 | void music_off(void); | 13 | void music_off(void); |
12 | 14 | ||
13 | void audio_on_user(void); | ||
14 | void music_on_user(void); | 15 | void music_on_user(void); |
15 | void music_scale_user(void); | 16 | void music_scale_user(void); |
17 | void music_all_notes_off(void); | ||
16 | 18 | ||
17 | void matrix_scan_music(void); | 19 | void matrix_scan_music(void); |
18 | 20 | ||
@@ -24,4 +26,6 @@ void matrix_scan_music(void); | |||
24 | 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } | 26 | 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } |
25 | #endif | 27 | #endif |
26 | 28 | ||
29 | #endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | ||
30 | |||
27 | #endif \ No newline at end of file | 31 | #endif \ No newline at end of file |
diff --git a/quantum/quantum.c b/quantum/quantum.c index 807a7084a..5a9e771a9 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
@@ -98,8 +98,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
98 | 98 | ||
99 | void reset_keyboard(void) { | 99 | void reset_keyboard(void) { |
100 | clear_keyboard(); | 100 | clear_keyboard(); |
101 | #ifdef AUDIO_ENABLE | 101 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_ENABLE_BASIC)) |
102 | stop_all_notes(); | 102 | music_all_notes_off(); |
103 | shutdown_user(); | 103 | shutdown_user(); |
104 | #endif | 104 | #endif |
105 | wait_ms(250); | 105 | wait_ms(250); |
@@ -153,10 +153,13 @@ bool process_record_quantum(keyrecord_t *record) { | |||
153 | 153 | ||
154 | if (!( | 154 | if (!( |
155 | process_record_kb(keycode, record) && | 155 | process_record_kb(keycode, record) && |
156 | #ifdef MIDI_ENABLE | 156 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) |
157 | process_midi(keycode, record) && | 157 | process_midi(keycode, record) && |
158 | #endif | 158 | #endif |
159 | #ifdef AUDIO_ENABLE | 159 | #ifdef AUDIO_ENABLE |
160 | process_audio(keycode, record) && | ||
161 | #endif | ||
162 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | ||
160 | process_music(keycode, record) && | 163 | process_music(keycode, record) && |
161 | #endif | 164 | #endif |
162 | #ifdef TAP_DANCE_ENABLE | 165 | #ifdef TAP_DANCE_ENABLE |
diff --git a/quantum/quantum.h b/quantum/quantum.h index 259bac369..1f1bb0afd 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
@@ -35,11 +35,16 @@ extern uint32_t default_layer_state; | |||
35 | 35 | ||
36 | #ifdef MIDI_ENABLE | 36 | #ifdef MIDI_ENABLE |
37 | #include <lufa.h> | 37 | #include <lufa.h> |
38 | #ifdef MIDI_ADVANCED | ||
38 | #include "process_midi.h" | 39 | #include "process_midi.h" |
39 | #endif | 40 | #endif |
41 | #endif // MIDI_ENABLE | ||
40 | 42 | ||
41 | #ifdef AUDIO_ENABLE | 43 | #ifdef AUDIO_ENABLE |
42 | #include "audio.h" | 44 | #include "process_audio.h" |
45 | #endif | ||
46 | |||
47 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | ||
43 | #include "process_music.h" | 48 | #include "process_music.h" |
44 | #endif | 49 | #endif |
45 | 50 | ||
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 78b02a0de..1e3df9fa6 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
@@ -1,7 +1,16 @@ | |||
1 | |||
2 | #ifndef QUANTUM_KEYCODES_H | 1 | #ifndef QUANTUM_KEYCODES_H |
3 | #define QUANTUM_KEYCODES_H | 2 | #define QUANTUM_KEYCODES_H |
4 | 3 | ||
4 | #ifndef MIDI_ENABLE_STRICT | ||
5 | #define MIDI_ENABLE_STRICT 0 | ||
6 | #endif | ||
7 | |||
8 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)) | ||
9 | #ifndef MIDI_TONE_KEYCODE_OCTAVES | ||
10 | #define MIDI_TONE_KEYCODE_OCTAVES 3 | ||
11 | #endif | ||
12 | #endif | ||
13 | |||
5 | enum quantum_keycodes { | 14 | enum quantum_keycodes { |
6 | // Ranges used in shortucuts - not to be used directly | 15 | // Ranges used in shortucuts - not to be used directly |
7 | QK_TMK = 0x0000, | 16 | QK_TMK = 0x0000, |
@@ -107,9 +116,230 @@ enum quantum_keycodes { | |||
107 | MUV_IN, | 116 | MUV_IN, |
108 | MUV_DE, | 117 | MUV_DE, |
109 | 118 | ||
110 | // Midi mode on/off | 119 | // Midi |
111 | MIDI_ON, | 120 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
112 | MIDI_OFF, | 121 | MI_ON, // send midi notes when music mode is enabled |
122 | MI_OFF, // don't send midi notes when music mode is enabled | ||
123 | #endif | ||
124 | |||
125 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)) | ||
126 | MIDI_TONE_MIN, | ||
127 | |||
128 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 0 | ||
129 | MI_C = MIDI_TONE_MIN, | ||
130 | MI_Cs, | ||
131 | MI_Db = MI_Cs, | ||
132 | MI_D, | ||
133 | MI_Ds, | ||
134 | MI_Eb = MI_Ds, | ||
135 | MI_E, | ||
136 | MI_F, | ||
137 | MI_Fs, | ||
138 | MI_Gb = MI_Fs, | ||
139 | MI_G, | ||
140 | MI_Gs, | ||
141 | MI_Ab = MI_Gs, | ||
142 | MI_A, | ||
143 | MI_As, | ||
144 | MI_Bb = MI_As, | ||
145 | MI_B, | ||
146 | #endif | ||
147 | |||
148 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 1 | ||
149 | MI_C_1, | ||
150 | MI_Cs_1, | ||
151 | MI_Db_1 = MI_Cs_1, | ||
152 | MI_D_1, | ||
153 | MI_Ds_1, | ||
154 | MI_Eb_1 = MI_Ds_1, | ||
155 | MI_E_1, | ||
156 | MI_F_1, | ||
157 | MI_Fs_1, | ||
158 | MI_Gb_1 = MI_Fs_1, | ||
159 | MI_G_1, | ||
160 | MI_Gs_1, | ||
161 | MI_Ab_1 = MI_Gs_1, | ||
162 | MI_A_1, | ||
163 | MI_As_1, | ||
164 | MI_Bb_1 = MI_As_1, | ||
165 | MI_B_1, | ||
166 | #endif | ||
167 | |||
168 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 2 | ||
169 | MI_C_2, | ||
170 | MI_Cs_2, | ||
171 | MI_Db_2 = MI_Cs_2, | ||
172 | MI_D_2, | ||
173 | MI_Ds_2, | ||
174 | MI_Eb_2 = MI_Ds_2, | ||
175 | MI_E_2, | ||
176 | MI_F_2, | ||
177 | MI_Fs_2, | ||
178 | MI_Gb_2 = MI_Fs_2, | ||
179 | MI_G_2, | ||
180 | MI_Gs_2, | ||
181 | MI_Ab_2 = MI_Gs_2, | ||
182 | MI_A_2, | ||
183 | MI_As_2, | ||
184 | MI_Bb_2 = MI_As_2, | ||
185 | MI_B_2, | ||
186 | #endif | ||
187 | |||
188 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 3 | ||
189 | MI_C_3, | ||
190 | MI_Cs_3, | ||
191 | MI_Db_3 = MI_Cs_3, | ||
192 | MI_D_3, | ||
193 | MI_Ds_3, | ||
194 | MI_Eb_3 = MI_Ds_3, | ||
195 | MI_E_3, | ||
196 | MI_F_3, | ||
197 | MI_Fs_3, | ||
198 | MI_Gb_3 = MI_Fs_3, | ||
199 | MI_G_3, | ||
200 | MI_Gs_3, | ||
201 | MI_Ab_3 = MI_Gs_3, | ||
202 | MI_A_3, | ||
203 | MI_As_3, | ||
204 | MI_Bb_3 = MI_As_3, | ||
205 | MI_B_3, | ||
206 | #endif | ||
207 | |||
208 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 4 | ||
209 | MI_C_4, | ||
210 | MI_Cs_4, | ||
211 | MI_Db_4 = MI_Cs_4, | ||
212 | MI_D_4, | ||
213 | MI_Ds_4, | ||
214 | MI_Eb_4 = MI_Ds_4, | ||
215 | MI_E_4, | ||
216 | MI_F_4, | ||
217 | MI_Fs_4, | ||
218 | MI_Gb_4 = MI_Fs_4, | ||
219 | MI_G_4, | ||
220 | MI_Gs_4, | ||
221 | MI_Ab_4 = MI_Gs_4, | ||
222 | MI_A_4, | ||
223 | MI_As_4, | ||
224 | MI_Bb_4 = MI_As_4, | ||
225 | MI_B_4, | ||
226 | #endif | ||
227 | |||
228 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5 | ||
229 | MI_C_5, | ||
230 | MI_Cs_5, | ||
231 | MI_Db_5 = MI_Cs_5, | ||
232 | MI_D_5, | ||
233 | MI_Ds_5, | ||
234 | MI_Eb_5 = MI_Ds_5, | ||
235 | MI_E_5, | ||
236 | MI_F_5, | ||
237 | MI_Fs_5, | ||
238 | MI_Gb_5 = MI_Fs_5, | ||
239 | MI_G_5, | ||
240 | MI_Gs_5, | ||
241 | MI_Ab_5 = MI_Gs_5, | ||
242 | MI_A_5, | ||
243 | MI_As_5, | ||
244 | MI_Bb_5 = MI_As_5, | ||
245 | MI_B_5, | ||
246 | #endif | ||
247 | |||
248 | #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5 | ||
249 | MIDI_TONE_MAX = MI_B_5, | ||
250 | #elif MIDI_TONE_KEYCODE_OCTAVES > 4 | ||
251 | MIDI_TONE_MAX = MI_B_4, | ||
252 | #elif MIDI_TONE_KEYCODE_OCTAVES > 3 | ||
253 | MIDI_TONE_MAX = MI_B_3, | ||
254 | #elif MIDI_TONE_KEYCODE_OCTAVES > 2 | ||
255 | MIDI_TONE_MAX = MI_B_2, | ||
256 | #elif MIDI_TONE_KEYCODE_OCTAVES > 1 | ||
257 | MIDI_TONE_MAX = MI_B_1, | ||
258 | #elif MIDI_TONE_KEYCODE_OCTAVES > 0 | ||
259 | MIDI_TONE_MAX = MI_B, | ||
260 | #endif | ||
261 | |||
262 | MIDI_OCTAVE_MIN, | ||
263 | MI_OCT_N2 = MIDI_OCTAVE_MIN, | ||
264 | MI_OCT_N1, | ||
265 | MI_OCT_0, | ||
266 | MI_OCT_1, | ||
267 | MI_OCT_2, | ||
268 | MI_OCT_3, | ||
269 | MI_OCT_4, | ||
270 | MI_OCT_5, | ||
271 | MI_OCT_6, | ||
272 | MI_OCT_7, | ||
273 | MIDI_OCTAVE_MAX = MI_OCT_7, | ||
274 | MI_OCTD, // octave down | ||
275 | MI_OCTU, // octave up | ||
276 | |||
277 | MIDI_TRANSPOSE_MIN, | ||
278 | MI_TRNS_N6 = MIDI_TRANSPOSE_MIN, | ||
279 | MI_TRNS_N5, | ||
280 | MI_TRNS_N4, | ||
281 | MI_TRNS_N3, | ||
282 | MI_TRNS_N2, | ||
283 | MI_TRNS_N1, | ||
284 | MI_TRNS_0, | ||
285 | MI_TRNS_1, | ||
286 | MI_TRNS_2, | ||
287 | MI_TRNS_3, | ||
288 | MI_TRNS_4, | ||
289 | MI_TRNS_5, | ||
290 | MI_TRNS_6, | ||
291 | MIDI_TRANSPOSE_MAX = MI_TRNS_6, | ||
292 | MI_TRNSD, // transpose down | ||
293 | MI_TRNSU, // transpose up | ||
294 | |||
295 | MIDI_VELOCITY_MIN, | ||
296 | MI_VEL_1 = MIDI_VELOCITY_MIN, | ||
297 | MI_VEL_2, | ||
298 | MI_VEL_3, | ||
299 | MI_VEL_4, | ||
300 | MI_VEL_5, | ||
301 | MI_VEL_6, | ||
302 | MI_VEL_7, | ||
303 | MI_VEL_8, | ||
304 | MI_VEL_9, | ||
305 | MI_VEL_10, | ||
306 | MIDI_VELOCITY_MAX = MI_VEL_10, | ||
307 | MI_VELD, // velocity down | ||
308 | MI_VELU, // velocity up | ||
309 | |||
310 | MIDI_CHANNEL_MIN, | ||
311 | MI_CH1 = MIDI_CHANNEL_MIN, | ||
312 | MI_CH2, | ||
313 | MI_CH3, | ||
314 | MI_CH4, | ||
315 | MI_CH5, | ||
316 | MI_CH6, | ||
317 | MI_CH7, | ||
318 | MI_CH8, | ||
319 | MI_CH9, | ||
320 | MI_CH10, | ||
321 | MI_CH11, | ||
322 | MI_CH12, | ||
323 | MI_CH13, | ||
324 | MI_CH14, | ||
325 | MI_CH15, | ||
326 | MI_CH16, | ||
327 | MIDI_CHANNEL_MAX = MI_CH16, | ||
328 | MI_CHD, // previous channel | ||
329 | MI_CHU, // next channel | ||
330 | |||
331 | MI_ALLOFF, // all notes off | ||
332 | |||
333 | MI_SUS, // sustain | ||
334 | MI_PORT, // portamento | ||
335 | MI_SOST, // sostenuto | ||
336 | MI_SOFT, // soft pedal | ||
337 | MI_LEG, // legato | ||
338 | |||
339 | MI_MOD, // modulation | ||
340 | MI_MODSD, // decrease modulation speed | ||
341 | MI_MODSU, // increase modulation speed | ||
342 | #endif // MIDI_ADVANCED | ||
113 | 343 | ||
114 | // Backlight functionality | 344 | // Backlight functionality |
115 | BL_0, | 345 | BL_0, |
@@ -279,9 +509,6 @@ enum quantum_keycodes { | |||
279 | #define BL_ON BL_9 | 509 | #define BL_ON BL_9 |
280 | #define BL_OFF BL_0 | 510 | #define BL_OFF BL_0 |
281 | 511 | ||
282 | #define MI_ON MIDI_ON | ||
283 | #define MI_OFF MIDI_OFF | ||
284 | |||
285 | // GOTO layer - 16 layers max | 512 | // GOTO layer - 16 layers max |
286 | // when: | 513 | // when: |
287 | // ON_PRESS = 1 | 514 | // ON_PRESS = 1 |
diff --git a/quantum/template/config.h b/quantum/template/config.h index c61c4a618..7393097e1 100644 --- a/quantum/template/config.h +++ b/quantum/template/config.h | |||
@@ -159,4 +159,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
159 | //#define NO_ACTION_MACRO | 159 | //#define NO_ACTION_MACRO |
160 | //#define NO_ACTION_FUNCTION | 160 | //#define NO_ACTION_FUNCTION |
161 | 161 | ||
162 | /* | ||
163 | * MIDI options | ||
164 | */ | ||
165 | |||
166 | /* Prevent use of disabled MIDI features in the keymap */ | ||
167 | //#define MIDI_ENABLE_STRICT 1 | ||
168 | |||
169 | /* enable basic MIDI features: | ||
170 | - MIDI notes can be sent when in Music mode is on | ||
171 | */ | ||
172 | //#define MIDI_BASIC | ||
173 | |||
174 | /* enable advanced MIDI features: | ||
175 | - MIDI notes can be added to the keymap | ||
176 | - Octave shift and transpose | ||
177 | - Virtual sustain, portamento, and modulation wheel | ||
178 | - etc. | ||
179 | */ | ||
180 | //#define MIDI_ADVANCED | ||
181 | |||
182 | /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ | ||
183 | //#define MIDI_TONE_KEYCODE_OCTAVES 1 | ||
184 | |||
162 | #endif | 185 | #endif |
diff --git a/quantum/template/keymaps/default/Makefile b/quantum/template/keymaps/default/Makefile index f4671a9d1..29f11bbc7 100644 --- a/quantum/template/keymaps/default/Makefile +++ b/quantum/template/keymaps/default/Makefile | |||
@@ -9,7 +9,7 @@ CONSOLE_ENABLE = no # Console for debug(+400) | |||
9 | COMMAND_ENABLE = yes # Commands for debug and configuration | 9 | COMMAND_ENABLE = yes # Commands for debug and configuration |
10 | NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 10 | NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
11 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | 11 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality |
12 | MIDI_ENABLE = no # MIDI controls | 12 | MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) |
13 | AUDIO_ENABLE = no # Audio output on port C6 | 13 | AUDIO_ENABLE = no # Audio output on port C6 |
14 | UNICODE_ENABLE = no # Unicode | 14 | UNICODE_ENABLE = no # Unicode |
15 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 15 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
diff --git a/quantum/template/rules.mk b/quantum/template/rules.mk index bad3387bf..a1f9377d8 100644 --- a/quantum/template/rules.mk +++ b/quantum/template/rules.mk | |||
@@ -61,7 +61,7 @@ SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend | |||
61 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 61 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
62 | NKRO_ENABLE ?= no # USB Nkey Rollover | 62 | NKRO_ENABLE ?= no # USB Nkey Rollover |
63 | BACKLIGHT_ENABLE ?= no # Enable keyboard backlight functionality on B7 by default | 63 | BACKLIGHT_ENABLE ?= no # Enable keyboard backlight functionality on B7 by default |
64 | MIDI_ENABLE ?= no # MIDI controls | 64 | MIDI_ENABLE ?= no # MIDI support (+2400 to 4200, depending on config) |
65 | UNICODE_ENABLE ?= no # Unicode | 65 | UNICODE_ENABLE ?= no # Unicode |
66 | BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID | 66 | BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID |
67 | AUDIO_ENABLE ?= no # Audio output on port C6 | 67 | AUDIO_ENABLE ?= no # Audio output on port C6 |