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/process_keycode/process_audio.c | |
| 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/process_keycode/process_audio.c')
| -rw-r--r-- | quantum/process_keycode/process_audio.c | 62 |
1 files changed, 62 insertions, 0 deletions
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 | ||
