diff options
author | Gabriel Young <gabeplaysdrums@live.com> | 2017-02-25 19:25:33 -0800 |
---|---|---|
committer | Gabriel Young <gabeplaysdrums@live.com> | 2017-02-25 19:25:33 -0800 |
commit | 1000799d1ef594bf9f48076986ec300ef9e536db (patch) | |
tree | e561400e2a5f2e0c27238b1e2602164140039918 /quantum/process_keycode/process_audio.c | |
parent | 525be99ee938aa6e48448d7dd6ea6e6fe50bb36d (diff) | |
download | qmk_firmware-1000799d1ef594bf9f48076986ec300ef9e536db.tar.gz qmk_firmware-1000799d1ef594bf9f48076986ec300ef9e536db.zip |
Factor basic note processing into respective processors
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 0000000000..5b5da546ea --- /dev/null +++ b/quantum/process_keycode/process_audio.c @@ -0,0 +1,62 @@ +#include "process_audio.h" +#include "audio.h" + +static float compute_freq_for_midi_note(uint8_t note) +{ + // https://en.wikipedia.org/wiki/MIDI_tuning_standard + return pow(2.0, (note - 69) / 12.0) * 440.0f; +} + +bool process_audio(uint16_t keycode, keyrecord_t *record) { + + if (keycode == AU_ON && record->event.pressed) { + audio_on(); + return false; + } + + if (keycode == AU_OFF && record->event.pressed) { + audio_off(); + return false; + } + + if (keycode == AU_TOG && record->event.pressed) { + if (is_audio_on()) + { + audio_off(); + } + else + { + audio_on(); + } + return false; + } + + if (keycode == MUV_IN && record->event.pressed) { + voice_iterate(); + music_scale_user(); + return false; + } + + if (keycode == MUV_DE && record->event.pressed) { + voice_deiterate(); + music_scale_user(); + return false; + } + + return true +} + +void process_audio_noteon(uint8_t note) { + play_note(compute_freq_for_midi_note(note), 0xF); +} + +void process_audio_noteoff(uint8_t note) { + stop_note(compute_freq_for_midi_note(note)); +} + +void process_audio_stop_all_notes(void) { + stop_all_notes(); +} + +__attribute__ ((weak)) +void audio_on_user() {}
\ No newline at end of file |