]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/process_keycode/process_audio.c
adds music mode, music mode songs, music mask
[qmk_firmware.git] / quantum / process_keycode / process_audio.c
1 #include "audio.h"
2 #include "process_audio.h"
3
4 #ifndef VOICE_CHANGE_SONG
5     #define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
6 #endif
7 float voice_change_song[][2] = VOICE_CHANGE_SONG;
8
9 static float compute_freq_for_midi_note(uint8_t note)
10 {
11     // https://en.wikipedia.org/wiki/MIDI_tuning_standard
12     return pow(2.0, (note - 69) / 12.0) * 440.0f;
13 }
14
15 bool process_audio(uint16_t keycode, keyrecord_t *record) {
16
17     if (keycode == AU_ON && record->event.pressed) {
18       audio_on();
19       return false;
20     }
21
22     if (keycode == AU_OFF && record->event.pressed) {
23       audio_off();
24       return false;
25     }
26
27     if (keycode == AU_TOG && record->event.pressed) {
28         if (is_audio_on()) {
29             audio_off();
30         } else {
31             audio_on();
32         }
33         return false;
34     }
35
36     if (keycode == MUV_IN && record->event.pressed) {
37         voice_iterate();
38         PLAY_SONG(voice_change_song);
39         return false;
40     }
41
42     if (keycode == MUV_DE && record->event.pressed) {
43         voice_deiterate();
44         PLAY_SONG(voice_change_song);
45         return false;
46     }
47
48     return true;
49 }
50
51 void process_audio_noteon(uint8_t note) {
52     play_note(compute_freq_for_midi_note(note), 0xF);
53 }
54
55 void process_audio_noteoff(uint8_t note) {
56     stop_note(compute_freq_for_midi_note(note));
57 }
58
59 void process_audio_all_notes_off(void) {
60     stop_all_notes();
61 }
62
63 __attribute__ ((weak))
64 void audio_on_user() {}