diff options
Diffstat (limited to 'quantum/process_keycode/process_music.c')
-rw-r--r-- | quantum/process_keycode/process_music.c | 127 |
1 files changed, 81 insertions, 46 deletions
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)) { |