aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-12-10 10:57:52 -0500
committerJack Humbert <jack.humb@gmail.com>2017-12-10 10:59:47 -0500
commita7c61f2947528f79383dfe63e654346afce0d14a (patch)
tree99bb52489b94916aae58538f3d050651cfbe7b16 /quantum/process_keycode
parentd1feb8744aeb14f4ff024507b25d224e77de60a0 (diff)
downloadqmk_firmware-a7c61f2947528f79383dfe63e654346afce0d14a.tar.gz
qmk_firmware-a7c61f2947528f79383dfe63e654346afce0d14a.zip
fix up midi stuff w/music mode
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_music.c81
-rw-r--r--quantum/process_keycode/process_music.h6
2 files changed, 79 insertions, 8 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
27bool music_activated = false; 27bool music_activated = false;
28bool midi_activated = false;
28uint8_t music_starting_note = 0x0C; 29uint8_t music_starting_note = 0x0C;
29int music_offset = 7; 30int music_offset = 7;
30uint8_t music_mode = MUSIC_MODE_CHROMATIC; 31uint8_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
76static void music_noteon(uint8_t note) { 85static 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
85static void music_noteoff(uint8_t note) { 96static 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
94void music_all_notes_off(void) { 107void 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
261bool is_midi_on(void) {
262 return (midi_activated != 0);
263}
264
265void midi_toggle(void) {
266 if (!midi_activated) {
267 midi_on();
268 } else {
269 midi_off();
270 }
271}
272
273void 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
281void 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
227void music_mode_cycle(void) { 289void 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))
249void music_on_user() {} 311void music_on_user() {}
250 312
251__attribute__ ((weak)) 313__attribute__ ((weak))
314void midi_on_user() {}
315
316__attribute__ ((weak))
252void music_scale_user() {} 317void 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);
36void music_on(void); 36void music_on(void);
37void music_off(void); 37void music_off(void);
38 38
39bool is_midi_on(void);
40void midi_toggle(void);
41void midi_on(void);
42void midi_off(void);
43
39void music_on_user(void); 44void music_on_user(void);
45void midi_on_user(void);
40void music_scale_user(void); 46void music_scale_user(void);
41void music_all_notes_off(void); 47void music_all_notes_off(void);
42void music_mode_cycle(void); 48void music_mode_cycle(void);