aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2018-05-08 17:18:15 -0400
committerJack Humbert <jack.humb@gmail.com>2018-05-08 17:18:15 -0400
commit63d5c947d3bce7ad9db014b7930e4809aa16fa4c (patch)
tree29f2f97b93cf652dcc40742b8b84ae9f78fad900
parent14b7602a65dedaf51db1c9288144765d43a83a15 (diff)
downloadfirmware-63d5c947d3bce7ad9db014b7930e4809aa16fa4c.tar.gz
firmware-63d5c947d3bce7ad9db014b7930e4809aa16fa4c.tar.bz2
firmware-63d5c947d3bce7ad9db014b7930e4809aa16fa4c.zip
updated music mask
-rw-r--r--docs/feature_audio.md14
-rw-r--r--keyboards/planck/keymaps/default/config.h6
-rw-r--r--keyboards/planck/keymaps/default/keymap.c10
-rw-r--r--quantum/process_keycode/process_music.c34
-rw-r--r--quantum/process_keycode/process_music.h4
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
Which will capture all keycodes - be careful, this will get you stuck in music mode until you restart your keyboard!
+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`:
+
+ bool music_mask_user(uint16_t keycode) {
+ switch (keycode) {
+ case RAISE:
+ case LOWER:
+ return false;
+ default:
+ return true;
+ }
+ }
+
+Things that return false are not part of the mask, and are always processed.
+
The pitch standard (`PITCH_STANDARD_A`) is 440.0f by default - to change this, add something like this to your `config.h`:
#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 @@
}
#endif
-#define MUSIC_MASK (keycode != KC_NO)
-
/*
* MIDI options
*/
@@ -25,7 +23,7 @@
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
-
+
#define MIDI_BASIC
/* enable advanced MIDI features:
@@ -39,4 +37,4 @@
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 2
-#endif \ No newline at end of file
+#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) {
}
return true;
}
+
+bool music_mask_user(uint16_t keycode) {
+ switch (keycode) {
+ case RAISE:
+ case LOWER:
+ return false;
+ default:
+ return true;
+ }
+}
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;
bool midi_activated = false;
uint8_t music_starting_note = 0x0C;
int music_offset = 7;
-uint8_t music_mode = MUSIC_MODE_CHROMATIC;
+uint8_t music_mode = MUSIC_MODE_MAJOR;
// music sequencer
static bool music_sequence_recording = false;
@@ -78,10 +78,6 @@ static uint16_t music_sequence_interval = 100;
float midi_off_song[][2] = MIDI_OFF_SONG;
#endif
-#ifndef MUSIC_MASK
- #define MUSIC_MASK keycode < 0xFF
-#endif
-
static void music_noteon(uint8_t note) {
#ifdef AUDIO_ENABLE
if (music_activated)
@@ -120,7 +116,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
if (keycode == MU_ON && record->event.pressed) {
music_on();
return false;
- }
+ }
if (keycode == MU_OFF && record->event.pressed) {
music_off();
@@ -139,7 +135,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
if (keycode == MI_ON && record->event.pressed) {
midi_on();
return false;
- }
+ }
if (keycode == MI_OFF && record->event.pressed) {
midi_off();
@@ -202,7 +198,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
}
uint8_t note;
- if (music_mode == MUSIC_MODE_CHROMATIC)
+ if (music_mode == MUSIC_MODE_CHROMATIC)
note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
else if (music_mode == MUSIC_MODE_GUITAR)
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) {
music_noteoff(note);
}
- if (MUSIC_MASK)
+ if (music_mask(keycode))
return false;
}
return true;
}
+bool music_mask(uint16_t keycode) {
+ #ifdef MUSIC_MASK
+ return MUSIC_MASK;
+ #else
+ return music_mask_kb(keycode);
+ #endif
+}
+
+__attribute__((weak))
+bool music_mask_kb(uint16_t keycode) {
+ return music_mask_user(keycode);
+}
+
+__attribute__((weak))
+bool music_mask_user(uint16_t keycode) {
+ return keycode < 0xFF;
+}
+
bool is_music_on(void) {
return (music_activated != 0);
}
@@ -318,4 +332,4 @@ void midi_on_user() {}
__attribute__ ((weak))
void music_scale_user() {}
-#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) \ No newline at end of file
+#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);
void matrix_scan_music(void);
+bool music_mask(uint16_t keycode);
+bool music_mask_kb(uint16_t keycode);
+bool music_mask_user(uint16_t keycode);
+
#ifndef SCALE
#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), \
0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \