diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2017-07-22 00:14:26 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-07-23 14:59:29 -0400 |
| commit | 415d38ba9ee20424ce354ed5f8e590fae58b863f (patch) | |
| tree | 663b609ace954533aff4a964b4c7cb3300bd73cd /quantum/process_keycode | |
| parent | 9abbbe70890ee0a0c619411c76a2c7b82b1b49d5 (diff) | |
| download | qmk_firmware-415d38ba9ee20424ce354ed5f8e590fae58b863f.tar.gz qmk_firmware-415d38ba9ee20424ce354ed5f8e590fae58b863f.zip | |
adds music mode, music mode songs, music mask
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_audio.c | 16 | ||||
| -rw-r--r-- | quantum/process_keycode/process_music.c | 127 | ||||
| -rw-r--r-- | quantum/process_keycode/process_music.h | 9 |
3 files changed, 99 insertions, 53 deletions
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index 0b6380ed3..eb74796fa 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c | |||
| @@ -1,6 +1,11 @@ | |||
| 1 | #include "audio.h" | 1 | #include "audio.h" |
| 2 | #include "process_audio.h" | 2 | #include "process_audio.h" |
| 3 | 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 | |||
| 4 | static float compute_freq_for_midi_note(uint8_t note) | 9 | static float compute_freq_for_midi_note(uint8_t note) |
| 5 | { | 10 | { |
| 6 | // https://en.wikipedia.org/wiki/MIDI_tuning_standard | 11 | // https://en.wikipedia.org/wiki/MIDI_tuning_standard |
| @@ -20,12 +25,9 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { | |||
| 20 | } | 25 | } |
| 21 | 26 | ||
| 22 | if (keycode == AU_TOG && record->event.pressed) { | 27 | if (keycode == AU_TOG && record->event.pressed) { |
| 23 | if (is_audio_on()) | 28 | if (is_audio_on()) { |
| 24 | { | ||
| 25 | audio_off(); | 29 | audio_off(); |
| 26 | } | 30 | } else { |
| 27 | else | ||
| 28 | { | ||
| 29 | audio_on(); | 31 | audio_on(); |
| 30 | } | 32 | } |
| 31 | return false; | 33 | return false; |
| @@ -33,13 +35,13 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { | |||
| 33 | 35 | ||
| 34 | if (keycode == MUV_IN && record->event.pressed) { | 36 | if (keycode == MUV_IN && record->event.pressed) { |
| 35 | voice_iterate(); | 37 | voice_iterate(); |
| 36 | music_scale_user(); | 38 | PLAY_SONG(voice_change_song); |
| 37 | return false; | 39 | return false; |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | if (keycode == MUV_DE && record->event.pressed) { | 42 | if (keycode == MUV_DE && record->event.pressed) { |
| 41 | voice_deiterate(); | 43 | voice_deiterate(); |
| 42 | music_scale_user(); | 44 | PLAY_SONG(voice_change_song); |
| 43 | return false; | 45 | return false; |
| 44 | } | 46 | } |
| 45 | 47 | ||
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index ec2287df1..63841d1e8 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | bool music_activated = false; | 27 | bool music_activated = false; |
| 28 | uint8_t music_starting_note = 0x0C; | 28 | uint8_t music_starting_note = 0x0C; |
| 29 | int music_offset = 7; | 29 | int music_offset = 7; |
| 30 | uint8_t music_mode = MUSIC_MODE_CHROMATIC; | ||
| 30 | 31 | ||
| 31 | // music sequencer | 32 | // music sequencer |
| 32 | static bool music_sequence_recording = false; | 33 | static bool music_sequence_recording = false; |
| @@ -46,10 +47,32 @@ static uint16_t music_sequence_interval = 100; | |||
| 46 | #ifndef MUSIC_OFF_SONG | 47 | #ifndef MUSIC_OFF_SONG |
| 47 | #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) | 48 | #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) |
| 48 | #endif | 49 | #endif |
| 50 | #ifndef CHROMATIC_SONG | ||
| 51 | #define CHROMATIC_SONG SONG(CHROMATIC_SOUND) | ||
| 52 | #endif | ||
| 53 | #ifndef GUITAR_SONG | ||
| 54 | #define GUITAR_SONG SONG(GUITAR_SOUND) | ||
| 55 | #endif | ||
| 56 | #ifndef VIOLIN_SONG | ||
| 57 | #define VIOLIN_SONG SONG(VIOLIN_SOUND) | ||
| 58 | #endif | ||
| 59 | #ifndef MAJOR_SONG | ||
| 60 | #define MAJOR_SONG SONG(MAJOR_SOUND) | ||
| 61 | #endif | ||
| 62 | float music_mode_songs[NUMBER_OF_MODES][5][2] = { | ||
| 63 | CHROMATIC_SONG, | ||
| 64 | GUITAR_SONG, | ||
| 65 | VIOLIN_SONG, | ||
| 66 | MAJOR_SONG | ||
| 67 | }; | ||
| 49 | float music_on_song[][2] = MUSIC_ON_SONG; | 68 | float music_on_song[][2] = MUSIC_ON_SONG; |
| 50 | float music_off_song[][2] = MUSIC_OFF_SONG; | 69 | float music_off_song[][2] = MUSIC_OFF_SONG; |
| 51 | #endif | 70 | #endif |
| 52 | 71 | ||
| 72 | #ifndef MUSIC_MASK | ||
| 73 | #define MUSIC_MASK keycode < 0xFF | ||
| 74 | #endif | ||
| 75 | |||
| 53 | static void music_noteon(uint8_t note) { | 76 | static void music_noteon(uint8_t note) { |
| 54 | #ifdef AUDIO_ENABLE | 77 | #ifdef AUDIO_ENABLE |
| 55 | process_audio_noteon(note); | 78 | process_audio_noteon(note); |
| @@ -98,59 +121,63 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 98 | return false; | 121 | return false; |
| 99 | } | 122 | } |
| 100 | 123 | ||
| 101 | if (music_activated) { | 124 | if (keycode == MU_MOD && record->event.pressed) { |
| 125 | music_mode_cycle(); | ||
| 126 | return false; | ||
| 127 | } | ||
| 102 | 128 | ||
| 103 | if (keycode == KC_LCTL && record->event.pressed) { // Start recording | 129 | if (music_activated) { |
| 104 | music_all_notes_off(); | 130 | if (record->event.pressed) { |
| 105 | music_sequence_recording = true; | 131 | if (keycode == KC_LCTL) { // Start recording |
| 106 | music_sequence_recorded = false; | 132 | music_all_notes_off(); |
| 107 | music_sequence_playing = false; | 133 | music_sequence_recording = true; |
| 108 | music_sequence_count = 0; | 134 | music_sequence_recorded = false; |
| 109 | return false; | 135 | music_sequence_playing = false; |
| 110 | } | 136 | music_sequence_count = 0; |
| 137 | return false; | ||
| 138 | } | ||
| 111 | 139 | ||
| 112 | if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing | 140 | if (keycode == KC_LALT) { // Stop recording/playing |
| 113 | music_all_notes_off(); | 141 | music_all_notes_off(); |
| 114 | if (music_sequence_recording) { // was recording | 142 | if (music_sequence_recording) { // was recording |
| 115 | music_sequence_recorded = true; | 143 | music_sequence_recorded = true; |
| 144 | } | ||
| 145 | music_sequence_recording = false; | ||
| 146 | music_sequence_playing = false; | ||
| 147 | return false; | ||
| 116 | } | 148 | } |
| 117 | music_sequence_recording = false; | ||
| 118 | music_sequence_playing = false; | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | 149 | ||
| 122 | if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing | 150 | if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing |
| 123 | music_all_notes_off(); | 151 | music_all_notes_off(); |
| 124 | music_sequence_recording = false; | 152 | music_sequence_recording = false; |
| 125 | music_sequence_playing = true; | 153 | music_sequence_playing = true; |
| 126 | music_sequence_position = 0; | 154 | music_sequence_position = 0; |
| 127 | music_sequence_timer = 0; | 155 | music_sequence_timer = 0; |
| 128 | return false; | 156 | return false; |
| 129 | } | 157 | } |
| 130 | 158 | ||
| 131 | if (keycode == KC_UP) { | 159 | if (keycode == KC_UP) { |
| 132 | if (record->event.pressed) | 160 | music_sequence_interval-=10; |
| 133 | music_sequence_interval-=10; | 161 | return false; |
| 134 | return false; | 162 | } |
| 135 | } | ||
| 136 | 163 | ||
| 137 | if (keycode == KC_DOWN) { | 164 | if (keycode == KC_DOWN) { |
| 138 | if (record->event.pressed) | 165 | music_sequence_interval+=10; |
| 139 | music_sequence_interval+=10; | 166 | return false; |
| 140 | return false; | 167 | } |
| 141 | } | 168 | } |
| 142 | 169 | ||
| 143 | #define MUSIC_MODE_GUITAR | 170 | uint8_t note; |
| 144 | 171 | if (music_mode == MUSIC_MODE_CHROMATIC) | |
| 145 | #ifdef MUSIC_MODE_CHROMATIC | 172 | note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); |
| 146 | uint8_t note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); | 173 | else if (music_mode == MUSIC_MODE_GUITAR) |
| 147 | #elif defined(MUSIC_MODE_GUITAR) | 174 | note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); |
| 148 | uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); | 175 | else if (music_mode == MUSIC_MODE_VIOLIN) |
| 149 | #elif defined(MUSIC_MODE_VIOLIN) | 176 | note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); |
| 150 | uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); | 177 | else if (music_mode == MUSIC_MODE_MAJOR) |
| 151 | #else | 178 | note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); |
| 152 | uint8_t note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); | 179 | else |
| 153 | #endif | 180 | note = music_starting_note; |
| 154 | 181 | ||
| 155 | if (record->event.pressed) { | 182 | if (record->event.pressed) { |
| 156 | music_noteon(note); | 183 | music_noteon(note); |
| @@ -162,7 +189,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 162 | music_noteoff(note); | 189 | music_noteoff(note); |
| 163 | } | 190 | } |
| 164 | 191 | ||
| 165 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through | 192 | if (MUSIC_MASK) |
| 166 | return false; | 193 | return false; |
| 167 | } | 194 | } |
| 168 | 195 | ||
| @@ -197,6 +224,14 @@ void music_off(void) { | |||
| 197 | #endif | 224 | #endif |
| 198 | } | 225 | } |
| 199 | 226 | ||
| 227 | void music_mode_cycle(void) { | ||
| 228 | music_all_notes_off(); | ||
| 229 | music_mode = (music_mode + 1) % NUMBER_OF_MODES; | ||
| 230 | #ifdef AUDIO_ENABLE | ||
| 231 | PLAY_SONG(music_mode_songs[music_mode]); | ||
| 232 | #endif | ||
| 233 | } | ||
| 234 | |||
| 200 | void matrix_scan_music(void) { | 235 | void matrix_scan_music(void) { |
| 201 | if (music_sequence_playing) { | 236 | if (music_sequence_playing) { |
| 202 | if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { | 237 | if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { |
diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 8dfbf041f..ee027197c 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h | |||
| @@ -21,6 +21,14 @@ | |||
| 21 | 21 | ||
| 22 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | 22 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
| 23 | 23 | ||
| 24 | enum music_modes { | ||
| 25 | MUSIC_MODE_CHROMATIC, | ||
| 26 | MUSIC_MODE_GUITAR, | ||
| 27 | MUSIC_MODE_VIOLIN, | ||
| 28 | MUSIC_MODE_MAJOR, | ||
| 29 | NUMBER_OF_MODES | ||
| 30 | }; | ||
| 31 | |||
| 24 | bool process_music(uint16_t keycode, keyrecord_t *record); | 32 | bool process_music(uint16_t keycode, keyrecord_t *record); |
| 25 | 33 | ||
| 26 | bool is_music_on(void); | 34 | bool is_music_on(void); |
| @@ -31,6 +39,7 @@ void music_off(void); | |||
| 31 | void music_on_user(void); | 39 | void music_on_user(void); |
| 32 | void music_scale_user(void); | 40 | void music_scale_user(void); |
| 33 | void music_all_notes_off(void); | 41 | void music_all_notes_off(void); |
| 42 | void music_mode_cycle(void); | ||
| 34 | 43 | ||
| 35 | void matrix_scan_music(void); | 44 | void matrix_scan_music(void); |
| 36 | 45 | ||
