diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2018-05-08 17:18:15 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2018-05-08 17:18:15 -0400 |
| commit | 63d5c947d3bce7ad9db014b7930e4809aa16fa4c (patch) | |
| tree | 29f2f97b93cf652dcc40742b8b84ae9f78fad900 | |
| parent | 14b7602a65dedaf51db1c9288144765d43a83a15 (diff) | |
| download | qmk_firmware-63d5c947d3bce7ad9db014b7930e4809aa16fa4c.tar.gz qmk_firmware-63d5c947d3bce7ad9db014b7930e4809aa16fa4c.zip | |
updated music mask
| -rw-r--r-- | docs/feature_audio.md | 14 | ||||
| -rw-r--r-- | keyboards/planck/keymaps/default/config.h | 6 | ||||
| -rw-r--r-- | keyboards/planck/keymaps/default/keymap.c | 10 | ||||
| -rw-r--r-- | quantum/process_keycode/process_music.c | 34 | ||||
| -rw-r--r-- | quantum/process_keycode/process_music.h | 4 |
5 files changed, 54 insertions, 14 deletions
diff --git a/docs/feature_audio.md b/docs/feature_audio.md index 1b8ca86f4..50e389605 100644 --- a/docs/feature_audio.md +++ b/docs/feature_audio.md | |||
| @@ -89,6 +89,20 @@ By default, `MUSIC_MASK` is set to `keycode < 0xFF` which means keycodes less th | |||
| 89 | 89 | ||
| 90 | Which will capture all keycodes - be careful, this will get you stuck in music mode until you restart your keyboard! | 90 | Which will capture all keycodes - be careful, this will get you stuck in music mode until you restart your keyboard! |
| 91 | 91 | ||
| 92 | For a more advanced way to control which keycodes should still be processed, you can use `music_mask_kb(keycode)` in `<keyboard>.c` and `music_mask_user(keycode)` in your `keymap.c`: | ||
| 93 | |||
| 94 | bool music_mask_user(uint16_t keycode) { | ||
| 95 | switch (keycode) { | ||
| 96 | case RAISE: | ||
| 97 | case LOWER: | ||
| 98 | return false; | ||
| 99 | default: | ||
| 100 | return true; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | Things that return false are not part of the mask, and are always processed. | ||
| 105 | |||
| 92 | The pitch standard (`PITCH_STANDARD_A`) is 440.0f by default - to change this, add something like this to your `config.h`: | 106 | The pitch standard (`PITCH_STANDARD_A`) is 440.0f by default - to change this, add something like this to your `config.h`: |
| 93 | 107 | ||
| 94 | #define PITCH_STANDARD_A 432.0f | 108 | #define PITCH_STANDARD_A 432.0f |
diff --git a/keyboards/planck/keymaps/default/config.h b/keyboards/planck/keymaps/default/config.h index a1635f2ba..7f38058a7 100644 --- a/keyboards/planck/keymaps/default/config.h +++ b/keyboards/planck/keymaps/default/config.h | |||
| @@ -13,8 +13,6 @@ | |||
| 13 | } | 13 | } |
| 14 | #endif | 14 | #endif |
| 15 | 15 | ||
| 16 | #define MUSIC_MASK (keycode != KC_NO) | ||
| 17 | |||
| 18 | /* | 16 | /* |
| 19 | * MIDI options | 17 | * MIDI options |
| 20 | */ | 18 | */ |
| @@ -25,7 +23,7 @@ | |||
| 25 | /* enable basic MIDI features: | 23 | /* enable basic MIDI features: |
| 26 | - MIDI notes can be sent when in Music mode is on | 24 | - MIDI notes can be sent when in Music mode is on |
| 27 | */ | 25 | */ |
| 28 | 26 | ||
| 29 | #define MIDI_BASIC | 27 | #define MIDI_BASIC |
| 30 | 28 | ||
| 31 | /* enable advanced MIDI features: | 29 | /* enable advanced MIDI features: |
| @@ -39,4 +37,4 @@ | |||
| 39 | /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ | 37 | /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ |
| 40 | //#define MIDI_TONE_KEYCODE_OCTAVES 2 | 38 | //#define MIDI_TONE_KEYCODE_OCTAVES 2 |
| 41 | 39 | ||
| 42 | #endif \ No newline at end of file | 40 | #endif |
diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index b13557eee..105d8c464 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c | |||
| @@ -247,3 +247,13 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 247 | } | 247 | } |
| 248 | return true; | 248 | return true; |
| 249 | } | 249 | } |
| 250 | |||
| 251 | bool music_mask_user(uint16_t keycode) { | ||
| 252 | switch (keycode) { | ||
| 253 | case RAISE: | ||
| 254 | case LOWER: | ||
| 255 | return false; | ||
| 256 | default: | ||
| 257 | return true; | ||
| 258 | } | ||
| 259 | } | ||
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index c7f41cc38..742bb08b1 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c | |||
| @@ -28,7 +28,7 @@ bool music_activated = false; | |||
| 28 | bool midi_activated = false; | 28 | bool midi_activated = false; |
| 29 | uint8_t music_starting_note = 0x0C; | 29 | uint8_t music_starting_note = 0x0C; |
| 30 | int music_offset = 7; | 30 | int music_offset = 7; |
| 31 | uint8_t music_mode = MUSIC_MODE_CHROMATIC; | 31 | uint8_t music_mode = MUSIC_MODE_MAJOR; |
| 32 | 32 | ||
| 33 | // music sequencer | 33 | // music sequencer |
| 34 | static bool music_sequence_recording = false; | 34 | static bool music_sequence_recording = false; |
| @@ -78,10 +78,6 @@ static uint16_t music_sequence_interval = 100; | |||
| 78 | float midi_off_song[][2] = MIDI_OFF_SONG; | 78 | float midi_off_song[][2] = MIDI_OFF_SONG; |
| 79 | #endif | 79 | #endif |
| 80 | 80 | ||
| 81 | #ifndef MUSIC_MASK | ||
| 82 | #define MUSIC_MASK keycode < 0xFF | ||
| 83 | #endif | ||
| 84 | |||
| 85 | static void music_noteon(uint8_t note) { | 81 | static void music_noteon(uint8_t note) { |
| 86 | #ifdef AUDIO_ENABLE | 82 | #ifdef AUDIO_ENABLE |
| 87 | if (music_activated) | 83 | if (music_activated) |
| @@ -120,7 +116,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 120 | if (keycode == MU_ON && record->event.pressed) { | 116 | if (keycode == MU_ON && record->event.pressed) { |
| 121 | music_on(); | 117 | music_on(); |
| 122 | return false; | 118 | return false; |
| 123 | } | 119 | } |
| 124 | 120 | ||
| 125 | if (keycode == MU_OFF && record->event.pressed) { | 121 | if (keycode == MU_OFF && record->event.pressed) { |
| 126 | music_off(); | 122 | music_off(); |
| @@ -139,7 +135,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 139 | if (keycode == MI_ON && record->event.pressed) { | 135 | if (keycode == MI_ON && record->event.pressed) { |
| 140 | midi_on(); | 136 | midi_on(); |
| 141 | return false; | 137 | return false; |
| 142 | } | 138 | } |
| 143 | 139 | ||
| 144 | if (keycode == MI_OFF && record->event.pressed) { | 140 | if (keycode == MI_OFF && record->event.pressed) { |
| 145 | midi_off(); | 141 | midi_off(); |
| @@ -202,7 +198,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 202 | } | 198 | } |
| 203 | 199 | ||
| 204 | uint8_t note; | 200 | uint8_t note; |
| 205 | if (music_mode == MUSIC_MODE_CHROMATIC) | 201 | if (music_mode == MUSIC_MODE_CHROMATIC) |
| 206 | note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); | 202 | note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); |
| 207 | else if (music_mode == MUSIC_MODE_GUITAR) | 203 | else if (music_mode == MUSIC_MODE_GUITAR) |
| 208 | note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); | 204 | note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); |
| @@ -223,13 +219,31 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 223 | music_noteoff(note); | 219 | music_noteoff(note); |
| 224 | } | 220 | } |
| 225 | 221 | ||
| 226 | if (MUSIC_MASK) | 222 | if (music_mask(keycode)) |
| 227 | return false; | 223 | return false; |
| 228 | } | 224 | } |
| 229 | 225 | ||
| 230 | return true; | 226 | return true; |
| 231 | } | 227 | } |
| 232 | 228 | ||
| 229 | bool music_mask(uint16_t keycode) { | ||
| 230 | #ifdef MUSIC_MASK | ||
| 231 | return MUSIC_MASK; | ||
| 232 | #else | ||
| 233 | return music_mask_kb(keycode); | ||
| 234 | #endif | ||
| 235 | } | ||
| 236 | |||
| 237 | __attribute__((weak)) | ||
| 238 | bool music_mask_kb(uint16_t keycode) { | ||
| 239 | return music_mask_user(keycode); | ||
| 240 | } | ||
| 241 | |||
| 242 | __attribute__((weak)) | ||
| 243 | bool music_mask_user(uint16_t keycode) { | ||
| 244 | return keycode < 0xFF; | ||
| 245 | } | ||
| 246 | |||
| 233 | bool is_music_on(void) { | 247 | bool is_music_on(void) { |
| 234 | return (music_activated != 0); | 248 | return (music_activated != 0); |
| 235 | } | 249 | } |
| @@ -318,4 +332,4 @@ void midi_on_user() {} | |||
| 318 | __attribute__ ((weak)) | 332 | __attribute__ ((weak)) |
| 319 | void music_scale_user() {} | 333 | void music_scale_user() {} |
| 320 | 334 | ||
| 321 | #endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) \ No newline at end of file | 335 | #endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 773bbfa6b..8ccb7a3a5 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h | |||
| @@ -49,6 +49,10 @@ void music_mode_cycle(void); | |||
| 49 | 49 | ||
| 50 | void matrix_scan_music(void); | 50 | void matrix_scan_music(void); |
| 51 | 51 | ||
| 52 | bool music_mask(uint16_t keycode); | ||
| 53 | bool music_mask_kb(uint16_t keycode); | ||
| 54 | bool music_mask_user(uint16_t keycode); | ||
| 55 | |||
| 52 | #ifndef SCALE | 56 | #ifndef SCALE |
| 53 | #define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ | 57 | #define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ |
| 54 | 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ | 58 | 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ |
