diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2017-12-10 10:57:52 -0500 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-12-10 10:59:47 -0500 |
| commit | a7c61f2947528f79383dfe63e654346afce0d14a (patch) | |
| tree | 99bb52489b94916aae58538f3d050651cfbe7b16 | |
| parent | d1feb8744aeb14f4ff024507b25d224e77de60a0 (diff) | |
| download | qmk_firmware-a7c61f2947528f79383dfe63e654346afce0d14a.tar.gz qmk_firmware-a7c61f2947528f79383dfe63e654346afce0d14a.zip | |
fix up midi stuff w/music mode
| -rw-r--r-- | quantum/process_keycode/process_music.c | 81 | ||||
| -rw-r--r-- | quantum/process_keycode/process_music.h | 6 | ||||
| -rw-r--r-- | quantum/quantum.c | 2 | ||||
| -rw-r--r-- | quantum/quantum_keycodes.h | 5 |
4 files changed, 83 insertions, 11 deletions
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 63841d1e8..f69d13ff5 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | 25 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
| 26 | 26 | ||
| 27 | bool music_activated = false; | 27 | bool music_activated = false; |
| 28 | bool midi_activated = false; | ||
| 28 | uint8_t music_starting_note = 0x0C; | 29 | uint8_t music_starting_note = 0x0C; |
| 29 | int music_offset = 7; | 30 | int music_offset = 7; |
| 30 | uint8_t music_mode = MUSIC_MODE_CHROMATIC; | 31 | uint8_t music_mode = MUSIC_MODE_CHROMATIC; |
| @@ -47,6 +48,12 @@ static uint16_t music_sequence_interval = 100; | |||
| 47 | #ifndef MUSIC_OFF_SONG | 48 | #ifndef MUSIC_OFF_SONG |
| 48 | #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) | 49 | #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) |
| 49 | #endif | 50 | #endif |
| 51 | #ifndef MIDI_ON_SONG | ||
| 52 | #define MIDI_ON_SONG SONG(MUSIC_ON_SOUND) | ||
| 53 | #endif | ||
| 54 | #ifndef MIDI_OFF_SONG | ||
| 55 | #define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND) | ||
| 56 | #endif | ||
| 50 | #ifndef CHROMATIC_SONG | 57 | #ifndef CHROMATIC_SONG |
| 51 | #define CHROMATIC_SONG SONG(CHROMATIC_SOUND) | 58 | #define CHROMATIC_SONG SONG(CHROMATIC_SOUND) |
| 52 | #endif | 59 | #endif |
| @@ -67,6 +74,8 @@ static uint16_t music_sequence_interval = 100; | |||
| 67 | }; | 74 | }; |
| 68 | float music_on_song[][2] = MUSIC_ON_SONG; | 75 | float music_on_song[][2] = MUSIC_ON_SONG; |
| 69 | float music_off_song[][2] = MUSIC_OFF_SONG; | 76 | float music_off_song[][2] = MUSIC_OFF_SONG; |
| 77 | float midi_on_song[][2] = MIDI_ON_SONG; | ||
| 78 | float midi_off_song[][2] = MIDI_OFF_SONG; | ||
| 70 | #endif | 79 | #endif |
| 71 | 80 | ||
| 72 | #ifndef MUSIC_MASK | 81 | #ifndef MUSIC_MASK |
| @@ -75,28 +84,34 @@ static uint16_t music_sequence_interval = 100; | |||
| 75 | 84 | ||
| 76 | static void music_noteon(uint8_t note) { | 85 | static void music_noteon(uint8_t note) { |
| 77 | #ifdef AUDIO_ENABLE | 86 | #ifdef AUDIO_ENABLE |
| 78 | process_audio_noteon(note); | 87 | if (music_activated) |
| 88 | process_audio_noteon(note); | ||
| 79 | #endif | 89 | #endif |
| 80 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | 90 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) |
| 81 | process_midi_basic_noteon(note); | 91 | if (midi_activated) |
| 92 | process_midi_basic_noteon(note); | ||
| 82 | #endif | 93 | #endif |
| 83 | } | 94 | } |
| 84 | 95 | ||
| 85 | static void music_noteoff(uint8_t note) { | 96 | static void music_noteoff(uint8_t note) { |
| 86 | #ifdef AUDIO_ENABLE | 97 | #ifdef AUDIO_ENABLE |
| 87 | process_audio_noteoff(note); | 98 | if (music_activated) |
| 99 | process_audio_noteoff(note); | ||
| 88 | #endif | 100 | #endif |
| 89 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | 101 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) |
| 90 | process_midi_basic_noteoff(note); | 102 | if (midi_activated) |
| 103 | process_midi_basic_noteoff(note); | ||
| 91 | #endif | 104 | #endif |
| 92 | } | 105 | } |
| 93 | 106 | ||
| 94 | void music_all_notes_off(void) { | 107 | void music_all_notes_off(void) { |
| 95 | #ifdef AUDIO_ENABLE | 108 | #ifdef AUDIO_ENABLE |
| 96 | process_audio_all_notes_off(); | 109 | if (music_activated) |
| 110 | process_audio_all_notes_off(); | ||
| 97 | #endif | 111 | #endif |
| 98 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) | 112 | #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) |
| 99 | process_midi_all_notes_off(); | 113 | if (midi_activated) |
| 114 | process_midi_all_notes_off(); | ||
| 100 | #endif | 115 | #endif |
| 101 | } | 116 | } |
| 102 | 117 | ||
| @@ -105,7 +120,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 105 | if (keycode == MU_ON && record->event.pressed) { | 120 | if (keycode == MU_ON && record->event.pressed) { |
| 106 | music_on(); | 121 | music_on(); |
| 107 | return false; | 122 | return false; |
| 108 | } | 123 | } |
| 109 | 124 | ||
| 110 | if (keycode == MU_OFF && record->event.pressed) { | 125 | if (keycode == MU_OFF && record->event.pressed) { |
| 111 | music_off(); | 126 | music_off(); |
| @@ -121,12 +136,31 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 121 | return false; | 136 | return false; |
| 122 | } | 137 | } |
| 123 | 138 | ||
| 139 | if (keycode == MI_ON && record->event.pressed) { | ||
| 140 | midi_on(); | ||
| 141 | return false; | ||
| 142 | } | ||
| 143 | |||
| 144 | if (keycode == MI_OFF && record->event.pressed) { | ||
| 145 | midi_off(); | ||
| 146 | return false; | ||
| 147 | } | ||
| 148 | |||
| 149 | if (keycode == MI_TOG && record->event.pressed) { | ||
| 150 | if (midi_activated) { | ||
| 151 | midi_off(); | ||
| 152 | } else { | ||
| 153 | midi_on(); | ||
| 154 | } | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 124 | if (keycode == MU_MOD && record->event.pressed) { | 158 | if (keycode == MU_MOD && record->event.pressed) { |
| 125 | music_mode_cycle(); | 159 | music_mode_cycle(); |
| 126 | return false; | 160 | return false; |
| 127 | } | 161 | } |
| 128 | 162 | ||
| 129 | if (music_activated) { | 163 | if (music_activated || midi_activated) { |
| 130 | if (record->event.pressed) { | 164 | if (record->event.pressed) { |
| 131 | if (keycode == KC_LCTL) { // Start recording | 165 | if (keycode == KC_LCTL) { // Start recording |
| 132 | music_all_notes_off(); | 166 | music_all_notes_off(); |
| @@ -224,6 +258,34 @@ void music_off(void) { | |||
| 224 | #endif | 258 | #endif |
| 225 | } | 259 | } |
| 226 | 260 | ||
| 261 | bool is_midi_on(void) { | ||
| 262 | return (midi_activated != 0); | ||
| 263 | } | ||
| 264 | |||
| 265 | void midi_toggle(void) { | ||
| 266 | if (!midi_activated) { | ||
| 267 | midi_on(); | ||
| 268 | } else { | ||
| 269 | midi_off(); | ||
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | void midi_on(void) { | ||
| 274 | midi_activated = 1; | ||
| 275 | #ifdef AUDIO_ENABLE | ||
| 276 | PLAY_SONG(midi_on_song); | ||
| 277 | #endif | ||
| 278 | midi_on_user(); | ||
| 279 | } | ||
| 280 | |||
| 281 | void midi_off(void) { | ||
| 282 | process_midi_all_notes_off(); | ||
| 283 | midi_activated = 0; | ||
| 284 | #ifdef AUDIO_ENABLE | ||
| 285 | PLAY_SONG(midi_off_song); | ||
| 286 | #endif | ||
| 287 | } | ||
| 288 | |||
| 227 | void music_mode_cycle(void) { | 289 | void music_mode_cycle(void) { |
| 228 | music_all_notes_off(); | 290 | music_all_notes_off(); |
| 229 | music_mode = (music_mode + 1) % NUMBER_OF_MODES; | 291 | music_mode = (music_mode + 1) % NUMBER_OF_MODES; |
| @@ -249,6 +311,9 @@ __attribute__ ((weak)) | |||
| 249 | void music_on_user() {} | 311 | void music_on_user() {} |
| 250 | 312 | ||
| 251 | __attribute__ ((weak)) | 313 | __attribute__ ((weak)) |
| 314 | void midi_on_user() {} | ||
| 315 | |||
| 316 | __attribute__ ((weak)) | ||
| 252 | void music_scale_user() {} | 317 | void music_scale_user() {} |
| 253 | 318 | ||
| 254 | #endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) \ No newline at end of file | 319 | #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 ee027197c..773bbfa6b 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h | |||
| @@ -36,7 +36,13 @@ void music_toggle(void); | |||
| 36 | void music_on(void); | 36 | void music_on(void); |
| 37 | void music_off(void); | 37 | void music_off(void); |
| 38 | 38 | ||
| 39 | bool is_midi_on(void); | ||
| 40 | void midi_toggle(void); | ||
| 41 | void midi_on(void); | ||
| 42 | void midi_off(void); | ||
| 43 | |||
| 39 | void music_on_user(void); | 44 | void music_on_user(void); |
| 45 | void midi_on_user(void); | ||
| 40 | void music_scale_user(void); | 46 | void music_scale_user(void); |
| 41 | void music_all_notes_off(void); | 47 | void music_all_notes_off(void); |
| 42 | void music_mode_cycle(void); | 48 | void music_mode_cycle(void); |
diff --git a/quantum/quantum.c b/quantum/quantum.c index dee2fc4b6..e2280b707 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -132,7 +132,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 132 | 132 | ||
| 133 | void reset_keyboard(void) { | 133 | void reset_keyboard(void) { |
| 134 | clear_keyboard(); | 134 | clear_keyboard(); |
| 135 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_ENABLE_BASIC)) | 135 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
| 136 | music_all_notes_off(); | 136 | music_all_notes_off(); |
| 137 | uint16_t timer_start = timer_read(); | 137 | uint16_t timer_start = timer_read(); |
| 138 | PLAY_SONG(goodbye_song); | 138 | PLAY_SONG(goodbye_song); |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 048da3267..f2cb25718 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
| @@ -152,8 +152,9 @@ enum quantum_keycodes { | |||
| 152 | 152 | ||
| 153 | // Midi | 153 | // Midi |
| 154 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) | 154 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
| 155 | MI_ON, // send midi notes when music mode is enabled | 155 | MI_ON, |
| 156 | MI_OFF, // don't send midi notes when music mode is enabled | 156 | MI_OFF, |
| 157 | MI_TOG, | ||
| 157 | #endif | 158 | #endif |
| 158 | 159 | ||
| 159 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)) | 160 | #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)) |
