aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-07-22 00:14:26 -0400
committerJack Humbert <jack.humb@gmail.com>2017-07-23 14:59:29 -0400
commit415d38ba9ee20424ce354ed5f8e590fae58b863f (patch)
tree663b609ace954533aff4a964b4c7cb3300bd73cd
parent9abbbe70890ee0a0c619411c76a2c7b82b1b49d5 (diff)
downloadqmk_firmware-415d38ba9ee20424ce354ed5f8e590fae58b863f.tar.gz
qmk_firmware-415d38ba9ee20424ce354ed5f8e590fae58b863f.zip
adds music mode, music mode songs, music mask
-rw-r--r--keyboards/planck/keymaps/default/config.h23
-rw-r--r--keyboards/planck/keymaps/default/keymap.c2
-rw-r--r--keyboards/preonic/keymaps/default/config.h23
-rw-r--r--keyboards/preonic/keymaps/default/keymap.c2
-rw-r--r--quantum/audio/audio.h4
-rw-r--r--quantum/audio/song_list.h32
-rw-r--r--quantum/process_keycode/process_audio.c16
-rw-r--r--quantum/process_keycode/process_music.c127
-rw-r--r--quantum/process_keycode/process_music.h9
-rw-r--r--quantum/quantum_keycodes.h3
10 files changed, 164 insertions, 77 deletions
diff --git a/keyboards/planck/keymaps/default/config.h b/keyboards/planck/keymaps/default/config.h
index 1ce547b94..b406e2fed 100644
--- a/keyboards/planck/keymaps/default/config.h
+++ b/keyboards/planck/keymaps/default/config.h
@@ -3,6 +3,18 @@
3 3
4#include "../../config.h" 4#include "../../config.h"
5 5
6#ifdef AUDIO_ENABLE
7 #define STARTUP_SONG SONG(PLANCK_SOUND)
8 // #define STARTUP_SONG SONG(NO_SOUND)
9
10 #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
11 SONG(COLEMAK_SOUND), \
12 SONG(DVORAK_SOUND) \
13 }
14#endif
15
16#define MUSIC_MASK (keycode != KC_NO)
17
6/* 18/*
7 * MIDI options 19 * MIDI options
8 */ 20 */
@@ -13,18 +25,9 @@
13/* enable basic MIDI features: 25/* enable basic MIDI features:
14 - MIDI notes can be sent when in Music mode is on 26 - MIDI notes can be sent when in Music mode is on
15*/ 27*/
28
16#define MIDI_BASIC 29#define MIDI_BASIC
17 30
18#ifdef AUDIO_ENABLE
19 #define STARTUP_SONG SONG(PLANCK_SOUND)
20 // #define STARTUP_SONG SONG(NO_SOUND)
21
22 #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
23 SONG(COLEMAK_SOUND), \
24 SONG(DVORAK_SOUND) \
25 }
26#endif
27
28/* enable advanced MIDI features: 31/* enable advanced MIDI features:
29 - MIDI notes can be added to the keymap 32 - MIDI notes can be added to the keymap
30 - Octave shift and transpose 33 - Octave shift and transpose
diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c
index 34a011b0c..f71a2b59b 100644
--- a/keyboards/planck/keymaps/default/keymap.c
+++ b/keyboards/planck/keymaps/default/keymap.c
@@ -164,7 +164,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
164 */ 164 */
165[_ADJUST] = { 165[_ADJUST] = {
166 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL }, 166 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
167 {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, 167 {_______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______},
168 {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______}, 168 {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
169 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} 169 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
170} 170}
diff --git a/keyboards/preonic/keymaps/default/config.h b/keyboards/preonic/keymaps/default/config.h
index 1ce547b94..003fd259c 100644
--- a/keyboards/preonic/keymaps/default/config.h
+++ b/keyboards/preonic/keymaps/default/config.h
@@ -3,6 +3,18 @@
3 3
4#include "../../config.h" 4#include "../../config.h"
5 5
6#ifdef AUDIO_ENABLE
7 #define STARTUP_SONG SONG(PLANCK_SOUND)
8 // #define STARTUP_SONG SONG(NO_SOUND)
9
10 #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
11 SONG(COLEMAK_SOUND), \
12 SONG(DVORAK_SOUND) \
13 }
14#endif
15
16#define MUSIC_MASK (keycode != KC_NO)
17
6/* 18/*
7 * MIDI options 19 * MIDI options
8 */ 20 */
@@ -13,17 +25,8 @@
13/* enable basic MIDI features: 25/* enable basic MIDI features:
14 - MIDI notes can be sent when in Music mode is on 26 - MIDI notes can be sent when in Music mode is on
15*/ 27*/
16#define MIDI_BASIC
17
18#ifdef AUDIO_ENABLE
19 #define STARTUP_SONG SONG(PLANCK_SOUND)
20 // #define STARTUP_SONG SONG(NO_SOUND)
21 28
22 #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \ 29#define MIDI_BASIC
23 SONG(COLEMAK_SOUND), \
24 SONG(DVORAK_SOUND) \
25 }
26#endif
27 30
28/* enable advanced MIDI features: 31/* enable advanced MIDI features:
29 - MIDI notes can be added to the keymap 32 - MIDI notes can be added to the keymap
diff --git a/keyboards/preonic/keymaps/default/keymap.c b/keyboards/preonic/keymaps/default/keymap.c
index 491f4ae85..01f40542c 100644
--- a/keyboards/preonic/keymaps/default/keymap.c
+++ b/keyboards/preonic/keymaps/default/keymap.c
@@ -158,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
158[_ADJUST] = { 158[_ADJUST] = {
159 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12}, 159 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
160 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, 160 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
161 {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______}, 161 {_______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______},
162 {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______}, 162 {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
163 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} 163 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
164} 164}
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index e29770e3b..79e0da229 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -100,8 +100,8 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat);
100#define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0])))) 100#define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
101#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \ 101#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
102 _Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"") 102 _Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
103#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false); 103#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false)
104#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true); 104#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true)
105 105
106bool is_playing_notes(void); 106bool is_playing_notes(void);
107 107
diff --git a/quantum/audio/song_list.h b/quantum/audio/song_list.h
index 6960bee6d..f355d371b 100644
--- a/quantum/audio/song_list.h
+++ b/quantum/audio/song_list.h
@@ -139,6 +139,38 @@
139 E__NOTE(_B5), \ 139 E__NOTE(_B5), \
140 E__NOTE(_A5 ), 140 E__NOTE(_A5 ),
141 141
142#define VOICE_CHANGE_SOUND \
143 Q__NOTE(_A5 ), \
144 Q__NOTE(_CS6), \
145 Q__NOTE(_E6 ), \
146 Q__NOTE(_A6 ),
147
148#define CHROMATIC_SOUND \
149 Q__NOTE(_A5 ), \
150 Q__NOTE(_AS5 ), \
151 Q__NOTE(_B5), \
152 Q__NOTE(_C6 ), \
153 Q__NOTE(_CS6 ),
154
155#define MAJOR_SOUND \
156 Q__NOTE(_A5 ), \
157 Q__NOTE(_B5 ), \
158 Q__NOTE(_CS6), \
159 Q__NOTE(_D6 ), \
160 Q__NOTE(_E6 ),
161
162#define GUITAR_SOUND \
163 Q__NOTE(_E5 ), \
164 Q__NOTE(_A5), \
165 Q__NOTE(_D6 ), \
166 Q__NOTE(_G6 ),
167
168#define VIOLIN_SOUND \
169 Q__NOTE(_G5 ), \
170 Q__NOTE(_D6), \
171 Q__NOTE(_A6 ), \
172 Q__NOTE(_E7 ),
173
142#define CAPS_LOCK_ON_SOUND \ 174#define CAPS_LOCK_ON_SOUND \
143 E__NOTE(_A3), \ 175 E__NOTE(_A3), \
144 E__NOTE(_B3), 176 E__NOTE(_B3),
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
7float voice_change_song[][2] = VOICE_CHANGE_SONG;
8
4static float compute_freq_for_midi_note(uint8_t note) 9static 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 @@
27bool music_activated = false; 27bool music_activated = false;
28uint8_t music_starting_note = 0x0C; 28uint8_t music_starting_note = 0x0C;
29int music_offset = 7; 29int music_offset = 7;
30uint8_t music_mode = MUSIC_MODE_CHROMATIC;
30 31
31// music sequencer 32// music sequencer
32static bool music_sequence_recording = false; 33static 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
53static void music_noteon(uint8_t note) { 76static 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
227void 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
200void matrix_scan_music(void) { 235void 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
24enum music_modes {
25 MUSIC_MODE_CHROMATIC,
26 MUSIC_MODE_GUITAR,
27 MUSIC_MODE_VIOLIN,
28 MUSIC_MODE_MAJOR,
29 NUMBER_OF_MODES
30};
31
24bool process_music(uint16_t keycode, keyrecord_t *record); 32bool process_music(uint16_t keycode, keyrecord_t *record);
25 33
26bool is_music_on(void); 34bool is_music_on(void);
@@ -31,6 +39,7 @@ void music_off(void);
31void music_on_user(void); 39void music_on_user(void);
32void music_scale_user(void); 40void music_scale_user(void);
33void music_all_notes_off(void); 41void music_all_notes_off(void);
42void music_mode_cycle(void);
34 43
35void matrix_scan_music(void); 44void matrix_scan_music(void);
36 45
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index c863b887a..06ab6d18d 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -132,6 +132,9 @@ enum quantum_keycodes {
132 MU_OFF, 132 MU_OFF,
133 MU_TOG, 133 MU_TOG,
134 134
135 // Music mode cycle
136 MU_MOD,
137
135 // Music voice iterate 138 // Music voice iterate
136 MUV_IN, 139 MUV_IN,
137 MUV_DE, 140 MUV_DE,