From 1a8c0dd22d6a2255511d0db6a456315541b5815b Mon Sep 17 00:00:00 2001 From: Erez Zukerman Date: Sun, 15 May 2016 00:27:32 -0400 Subject: Leader key implementation (#326) * implements leader key for planck experimental * allows override of leader timeout * adds ability to use the leader key in seq * fixes leader keycode * adds chording prototype * fixes keycode detection * moves music mode to quantum.c * disables chording by default * updates process_action functions to return bool --- quantum/quantum.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 quantum/quantum.c (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c new file mode 100644 index 000000000..e274d846f --- /dev/null +++ b/quantum/quantum.c @@ -0,0 +1,167 @@ +#include "quantum.h" + +__attribute__ ((weak)) +void matrix_init_kb(void) {} + +__attribute__ ((weak)) +void matrix_scan_kb(void) {} + +__attribute__ ((weak)) +bool process_action_kb(keyrecord_t *record) { + return true; +} + +__attribute__ ((weak)) +void leader_start(void) {} + +__attribute__ ((weak)) +void leader_end(void) {} + +#ifdef AUDIO_ENABLE + uint8_t starting_note = 0x0C; + int offset = 0; + bool music_activated = false; +#endif + +// Leader key stuff +bool leading = false; +uint16_t leader_time = 0; + +uint16_t leader_sequence[3] = {0, 0, 0}; +uint8_t leader_sequence_size = 0; + +// Chording stuff +#define CHORDING_MAX 4 +bool chording = false; + +uint8_t chord_keys[CHORDING_MAX] = {0}; +uint8_t chord_key_count = 0; +uint8_t chord_key_down = 0; + +bool keys_chord(uint8_t keys[]) { + uint8_t keys_size = sizeof(keys)/sizeof(keys[0]); + bool pass = true; + uint8_t in = 0; + for (uint8_t i = 0; i < chord_key_count; i++) { + bool found = false; + for (uint8_t j = 0; j < keys_size; j++) { + if (chord_keys[i] == (keys[j] & 0xFF)) { + in++; // detects key in chord + found = true; + break; + } + } + if (found) + continue; + if (chord_keys[i] != 0) { + pass = false; // makes sure rest are blank + } + } + return (pass && (in == keys_size)); +} + +bool process_action_quantum(keyrecord_t *record) { + + /* This gets the keycode from the key pressed */ + keypos_t key = record->event.key; + uint16_t keycode; + + #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) + uint8_t layer; + + if (record->event.pressed) { + layer = layer_switch_get_layer(key); + update_source_layers_cache(key, layer); + } else { + layer = read_source_layers_cache(key); + } + keycode = keymap_key_to_keycode(layer, key); + #else + keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); + #endif + + #ifdef AUDIO_ENABLE + if (music_activated) { + if (record->event.pressed) { + play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); + } else { + stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); + } + if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through + return false; + } + #endif + + + +#ifndef DISABLE_LEADER + // Leader key set-up + if (record->event.pressed) { + if (!leading && keycode == KC_LEAD) { + leader_start(); + leading = true; + leader_time = timer_read(); + leader_sequence_size = 0; + leader_sequence[0] = 0; + leader_sequence[1] = 0; + leader_sequence[2] = 0; + return false; + } + if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) { + leader_sequence[leader_sequence_size] = keycode; + leader_sequence_size++; + return false; + } + } +#endif + +#define DISABLE_CHORDING +#ifndef DISABLE_CHORDING + + if (keycode >= 0x5700 && keycode <= 0x57FF) { + if (record->event.pressed) { + if (!chording) { + chording = true; + for (uint8_t i = 0; i < CHORDING_MAX; i++) + chord_keys[i] = 0; + chord_key_count = 0; + chord_key_down = 0; + } + chord_keys[chord_key_count] = (keycode & 0xFF); + chord_key_count++; + chord_key_down++; + return false; + } else { + if (chording) { + chord_key_down--; + if (chord_key_down == 0) { + chording = false; + // Chord Dictionary + if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) { + register_code(KC_A); + unregister_code(KC_A); + return false; + } + for (uint8_t i = 0; i < chord_key_count; i++) { + register_code(chord_keys[i]); + unregister_code(chord_keys[i]); + return false; + } + } + } + } + } + +#endif + + + return process_action_kb(record); +} + +void matrix_init_quantum() { + matrix_init_kb(); +} + +void matrix_scan_quantum() { + matrix_scan_kb(); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 15719f3574c6274ee0f3ec87431927c5a523aa3e Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 15 May 2016 00:40:59 -0400 Subject: adds a sequencer to the music mode (#330) * implements leader key for planck experimental * allows override of leader timeout * adds ability to use the leader key in seq * fixes leader keycode * adds chording prototype * fixes keycode detection * moves music mode to quantum.c * disables chording by default * adds music sequencer functionality * implements audio/music functions in quantum.c * Merge branch 'master' into process-record --- keyboard/planck/keymaps/experimental/keymap.c | 72 +----------------- quantum/audio/audio.c | 11 ++- quantum/audio/audio.h | 1 + quantum/keymap_common.h | 15 +++- quantum/quantum.c | 104 +++++++++++++++++++++++++- 5 files changed, 122 insertions(+), 81 deletions(-) (limited to 'quantum/quantum.c') diff --git a/keyboard/planck/keymaps/experimental/keymap.c b/keyboard/planck/keymaps/experimental/keymap.c index 8dc158c73..8bc7334c9 100644 --- a/keyboard/planck/keymaps/experimental/keymap.c +++ b/keyboard/planck/keymaps/experimental/keymap.c @@ -20,8 +20,7 @@ extern keymap_config_t keymap_config; #define _DVORAK 2 #define _LOWER 3 #define _RAISE 4 -#define _MUSIC 5 -#define _PLOVER 6 +#define _PLOVER 5 #define _ADJUST 16 // Macro name shortcuts @@ -31,12 +30,6 @@ extern keymap_config_t keymap_config; #define LOWER M(_LOWER) #define RAISE M(_RAISE) #define M_BL 5 -#define AUD_OFF M(6) -#define AUD_ON M(7) -#define MUS_OFF M(8) -#define MUS_ON M(9) -#define VC_IN M(10) -#define VC_DE M(11) #define PLOVER M(12) #define EXT_PLV M(13) @@ -136,16 +129,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} }, -/* Music (reserved for process_action_user) - * - */ -[_MUSIC] = { - {XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX}, - {XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX}, - {XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX}, - {XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, LOWER, XXXXXXX, XXXXXXX, RAISE, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX} -}, - /* Plover layer (http://opensteno.org) * ,-----------------------------------------------------------------------------------. * | # | # | # | # | # | # | # | # | # | # | # | # | @@ -178,8 +161,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ [_ADJUST] = { {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, - {_______, _______, _______, AUD_ON, AUD_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, - {_______, VC_DE, VC_IN, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______}, + {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, + {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, _______, _______, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} } @@ -205,7 +188,6 @@ float tone_colemak[][2] = SONG(COLEMAK_SOUND); float tone_plover[][2] = SONG(PLOVER_SOUND); float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND); -float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); float goodbye[][2] = SONG(GOODBYE_SOUND); #endif @@ -274,53 +256,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) unregister_code(KC_RSFT); } break; - case 6: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - audio_off(); - #endif - } - break; - case 7: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - audio_on(); - PLAY_NOTE_ARRAY(tone_startup, false, 0); - #endif - } - break; - case 8: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - music_activated = false; - stop_all_notes(); - #endif - } - break; - case 9: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - PLAY_NOTE_ARRAY(music_scale, false, 0); - music_activated = true; - #endif - } - break; - case 10: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - voice_iterate(); - PLAY_NOTE_ARRAY(music_scale, false, 0); - #endif - } - break; - case 11: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - voice_deiterate(); - PLAY_NOTE_ARRAY(music_scale, false, 0); - #endif - } - break; case 12: if (record->event.pressed) { #ifdef AUDIO_ENABLE @@ -330,7 +265,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) layer_off(_RAISE); layer_off(_LOWER); layer_off(_ADJUST); - layer_off(_MUSIC); layer_on(_PLOVER); if (!eeconfig_is_enabled()) { eeconfig_init(); diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 27b64f8c9..243f49f0e 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -478,12 +478,11 @@ void increase_tempo(uint8_t tempo_change) { // Override these functions in your keymap file to play different tunes on // startup and bootloader jump __attribute__ ((weak)) -void play_startup_tone() -{ -} +void play_startup_tone() {} __attribute__ ((weak)) -void play_goodbye_tone() -{ -} +void play_goodbye_tone() {} + +__attribute__ ((weak)) +void audio_on_callback(void) {} //------------------------------------------------------------------------------ diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index 4ba879bbb..fe8506131 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -29,6 +29,7 @@ bool is_audio_on(void); void audio_toggle(void); void audio_on(void); void audio_off(void); +void audio_on_callback(void); // Vibrato rate functions diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 2ad1ba6c6..4107d575b 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -191,8 +191,6 @@ extern const uint16_t fn_actions[]; #define RESET 0x5000 #define DEBUG 0x5001 -#define KC_LEAD 0x5014 - // MAGIC keycodes #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 @@ -217,6 +215,19 @@ extern const uint16_t fn_actions[]; #define AG_SWAP MAGIC_SWAP_ALT_GUI #define AG_NORM MAGIC_UNSWAP_ALT_GUI +#define KC_LEAD 0x5014 + +// Audio on/off +#define AU_ON 0x5020 +#define AU_OFF 0x5021 + +// Music mode on/off +#define MU_ON 0x5022 +#define MU_OFF 0x5023 + +// Music voice iterate +#define MUV_IN 0x5024 +#define MUV_DE 0x5025 // GOTO layer - 16 layers max // when: diff --git a/quantum/quantum.c b/quantum/quantum.c index e274d846f..cd7fdbb7f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -21,6 +21,7 @@ void leader_end(void) {} uint8_t starting_note = 0x0C; int offset = 0; bool music_activated = false; + float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); #endif // Leader key stuff @@ -60,6 +61,15 @@ bool keys_chord(uint8_t keys[]) { return (pass && (in == keys_size)); } +static bool music_sequence_recording = false; +static bool music_sequence_playing = false; +static float music_sequence[16] = {0}; +static uint8_t music_sequence_count = 0; +static uint8_t music_sequence_position = 0; + +static uint16_t music_sequence_timer = 0; +static uint16_t music_sequence_interval = 100; + bool process_action_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ @@ -81,12 +91,87 @@ bool process_action_quantum(keyrecord_t *record) { #endif #ifdef AUDIO_ENABLE - if (music_activated) { + if (keycode == AU_ON && record->event.pressed) { + audio_on(); + audio_on_callback(); + return false; + } + + if (keycode == AU_OFF && record->event.pressed) { + audio_off(); + return false; + } + + if (keycode == MU_ON && record->event.pressed) { + music_activated = true; + PLAY_NOTE_ARRAY(music_scale, false, 0); + return false; + } + + if (keycode == MU_OFF && record->event.pressed) { + music_activated = false; + stop_all_notes(); + return false; + } + + if (keycode == MUV_IN && record->event.pressed) { + voice_iterate(); + PLAY_NOTE_ARRAY(music_scale, false, 0); + return false; + } + + if (keycode == MUV_DE && record->event.pressed) { + voice_deiterate(); + PLAY_NOTE_ARRAY(music_scale, false, 0); + return false; + } + + if (music_activated) { + + if (keycode == KC_LCTL && record->event.pressed) { // Start recording + stop_all_notes(); + music_sequence_recording = true; + music_sequence_playing = false; + music_sequence_count = 0; + return false; + } + if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing + stop_all_notes(); + music_sequence_recording = false; + music_sequence_playing = false; + return false; + } + if (keycode == KC_LGUI && record->event.pressed) { // Start playing + stop_all_notes(); + music_sequence_recording = false; + music_sequence_playing = true; + music_sequence_position = 0; + music_sequence_timer = 0; + return false; + } + + if (keycode == KC_UP) { + if (record->event.pressed) + music_sequence_interval-=10; + return false; + } + if (keycode == KC_DOWN) { + if (record->event.pressed) + music_sequence_interval+=10; + return false; + } + + float freq = ((float)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)); if (record->event.pressed) { - play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); + play_note(freq, 0xF); + if (music_sequence_recording) { + music_sequence[music_sequence_count] = freq; + music_sequence_count++; + } } else { - stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); - } + stop_note(freq); + } + if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through return false; } @@ -163,5 +248,16 @@ void matrix_init_quantum() { } void matrix_scan_quantum() { + #ifdef AUDIO_ENABLE + if (music_sequence_playing) { + if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { + music_sequence_timer = timer_read(); + stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]); + play_note(music_sequence[music_sequence_position], 0xF); + music_sequence_position = (music_sequence_position + 1) % music_sequence_count; + } + } + + #endif matrix_scan_kb(); } \ No newline at end of file -- cgit v1.2.3-70-g09d2 From bf5c2ccee5497523c214dae7aacdc27fdbb0f235 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 15 May 2016 00:47:25 -0400 Subject: splits process_action up to handle records separately (#329) * implements leader key for planck experimental * allows override of leader timeout * adds ability to use the leader key in seq * fixes leader keycode * adds chording prototype * fixes keycode detection * moves music mode to quantum.c * disables chording by default * adds music sequencer functionality * implements audio/music functions in quantum.c * splits up process_action to allow independent processing of actions * merging? --- quantum/keymap_common.h | 3 +++ quantum/quantum.c | 11 +++++++++- tmk_core/common/action.c | 47 ++++++++++++++++++++++------------------ tmk_core/common/action.h | 7 +++--- tmk_core/common/action_tapping.c | 30 ++++++++++++------------- 5 files changed, 58 insertions(+), 40 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 4107d575b..0074ab164 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -191,6 +191,9 @@ extern const uint16_t fn_actions[]; #define RESET 0x5000 #define DEBUG 0x5001 +#define KC_LEAD 0x5014 + + // MAGIC keycodes #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 diff --git a/quantum/quantum.c b/quantum/quantum.c index cd7fdbb7f..dd5d84f82 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -70,7 +70,7 @@ static uint8_t music_sequence_position = 0; static uint16_t music_sequence_timer = 0; static uint16_t music_sequence_interval = 100; -bool process_action_quantum(keyrecord_t *record) { +bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; @@ -90,6 +90,14 @@ bool process_action_quantum(keyrecord_t *record) { keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); #endif + // This is how you use actions here + // if (keycode == KC_LEAD) { + // action_t action; + // action.code = ACTION_DEFAULT_LAYER_SET(0); + // process_action(record, action); + // return false; + // } + #ifdef AUDIO_ENABLE if (keycode == AU_ON && record->event.pressed) { audio_on(); @@ -259,5 +267,6 @@ void matrix_scan_quantum() { } #endif + matrix_scan_kb(); } \ No newline at end of file diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index c026b96d9..be6dea2b7 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -46,7 +46,7 @@ void action_exec(keyevent_t event) #ifndef NO_ACTION_TAPPING action_tapping_process(record); #else - process_action(&record); + process_record(&record); if (!IS_NOEVENT(record.event)) { dprint("processed: "); debug_record(record); dprintln(); } @@ -56,25 +56,43 @@ void action_exec(keyevent_t event) #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) bool disable_action_cache = false; -void process_action_nocache(keyrecord_t *record) +void process_record_nocache(keyrecord_t *record) { disable_action_cache = true; - process_action(record); + process_record(record); disable_action_cache = false; } #else -void process_action_nocache(keyrecord_t *record) +void process_record_nocache(keyrecord_t *record) { - process_action(record); + process_record(record); } #endif __attribute__ ((weak)) -bool process_action_quantum(keyrecord_t *record) { +bool process_record_quantum(keyrecord_t *record) { return true; } -void process_action(keyrecord_t *record) +void process_record(keyrecord_t *record) +{ + if (IS_NOEVENT(record->event)) { return; } + + if(!process_record_quantum(record)) + return; + + action_t action = store_or_get_action(record->event.pressed, record->event.key); + dprint("ACTION: "); debug_action(action); +#ifndef NO_ACTION_LAYER + dprint(" layer_state: "); layer_debug(); + dprint(" default_layer_state: "); default_layer_debug(); +#endif + dprintln(); + + process_action(record, action); +} + +void process_action(keyrecord_t *record, action_t action) { bool do_release_oneshot = false; keyevent_t event = record->event; @@ -82,8 +100,6 @@ void process_action(keyrecord_t *record) uint8_t tap_count = record->tap.count; #endif - if (IS_NOEVENT(event)) { return; } - #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) if (has_oneshot_layer_timed_out()) { dprintf("Oneshot layer: timeout\n"); @@ -91,17 +107,6 @@ void process_action(keyrecord_t *record) } #endif - if (!process_action_quantum(record)) - return; - - action_t action = store_or_get_action(event.pressed, event.key); - dprint("ACTION: "); debug_action(action); -#ifndef NO_ACTION_LAYER - dprint(" layer_state: "); layer_debug(); - dprint(" default_layer_state: "); default_layer_debug(); -#endif - dprintln(); - if (event.pressed) { // clear the potential weak mods left by previously pressed keys clear_weak_mods(); @@ -451,7 +456,7 @@ void process_action(keyrecord_t *record) if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) { record->event.pressed = false; layer_on(get_oneshot_layer()); - process_action(record); + process_record(record); layer_off(get_oneshot_layer()); } #endif diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 7d1cbafe9..e8aa12a7c 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h @@ -59,14 +59,15 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); /* keyboard-specific key event (pre)processing */ -bool process_action_quantum(keyrecord_t *record); +bool process_record_quantum(keyrecord_t *record); /* Utilities for actions. */ #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) extern bool disable_action_cache; #endif -void process_action_nocache(keyrecord_t *record); -void process_action(keyrecord_t *record); +void process_record_nocache(keyrecord_t *record); +void process_record(keyrecord_t *record); +void process_action(keyrecord_t *record, action_t action); void register_code(uint8_t code); void unregister_code(uint8_t code); void register_mods(uint8_t mods); diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index e6343e6da..ff78d7f2a 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c @@ -89,7 +89,7 @@ bool process_tapping(keyrecord_t *keyp) debug("Tapping: First tap(0->1).\n"); tapping_key.tap.count = 1; debug_tapping_key(); - process_action(&tapping_key); + process_record(&tapping_key); // copy tapping state keyp->tap = tapping_key.tap; @@ -103,7 +103,7 @@ bool process_tapping(keyrecord_t *keyp) */ else if (IS_RELEASED(event) && waiting_buffer_typed(event)) { debug("Tapping: End. No tap. Interfered by typing key\n"); - process_action(&tapping_key); + process_record(&tapping_key); tapping_key = (keyrecord_t){}; debug_tapping_key(); // enqueue @@ -131,7 +131,7 @@ bool process_tapping(keyrecord_t *keyp) } // Release of key should be process immediately. debug("Tapping: release event of a key pressed before tapping\n"); - process_action(keyp); + process_record(keyp); return true; } else { @@ -148,7 +148,7 @@ bool process_tapping(keyrecord_t *keyp) if (IS_TAPPING_KEY(event.key) && !event.pressed) { debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); keyp->tap = tapping_key.tap; - process_action(keyp); + process_record(keyp); tapping_key = *keyp; debug_tapping_key(); return true; @@ -157,7 +157,7 @@ bool process_tapping(keyrecord_t *keyp) if (tapping_key.tap.count > 1) { debug("Tapping: Start new tap with releasing last tap(>1).\n"); // unregister key - process_action(&(keyrecord_t){ + process_record(&(keyrecord_t){ .tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, @@ -175,7 +175,7 @@ bool process_tapping(keyrecord_t *keyp) if (!IS_NOEVENT(event)) { debug("Tapping: key event while last tap(>0).\n"); } - process_action(keyp); + process_record(keyp); return true; } } @@ -185,7 +185,7 @@ bool process_tapping(keyrecord_t *keyp) if (tapping_key.tap.count == 0) { debug("Tapping: End. Timeout. Not tap(0): "); debug_event(event); debug("\n"); - process_action(&tapping_key); + process_record(&tapping_key); tapping_key = (keyrecord_t){}; debug_tapping_key(); return false; @@ -193,7 +193,7 @@ bool process_tapping(keyrecord_t *keyp) if (IS_TAPPING_KEY(event.key) && !event.pressed) { debug("Tapping: End. last timeout tap release(>0)."); keyp->tap = tapping_key.tap; - process_action(keyp); + process_record(keyp); tapping_key = (keyrecord_t){}; return true; } @@ -201,7 +201,7 @@ bool process_tapping(keyrecord_t *keyp) if (tapping_key.tap.count > 1) { debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); // unregister key - process_action(&(keyrecord_t){ + process_record(&(keyrecord_t){ .tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, @@ -219,7 +219,7 @@ bool process_tapping(keyrecord_t *keyp) if (!IS_NOEVENT(event)) { debug("Tapping: key event while last timeout tap(>0).\n"); } - process_action(keyp); + process_record(keyp); return true; } } @@ -233,7 +233,7 @@ bool process_tapping(keyrecord_t *keyp) keyp->tap = tapping_key.tap; if (keyp->tap.count < 15) keyp->tap.count += 1; debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); - process_action(keyp); + process_record(keyp); tapping_key = *keyp; debug_tapping_key(); return true; @@ -253,12 +253,12 @@ bool process_tapping(keyrecord_t *keyp) // should none in buffer // FIX: interrupted when other key is pressed tapping_key.tap.interrupted = true; - process_action(keyp); + process_record(keyp); return true; } } else { if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); - process_action(keyp); + process_record(keyp); return true; } } else { @@ -280,7 +280,7 @@ bool process_tapping(keyrecord_t *keyp) debug_tapping_key(); return true; } else { - process_action(keyp); + process_record(keyp); return true; } } @@ -347,7 +347,7 @@ void waiting_buffer_scan_tap(void) WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { tapping_key.tap.count = 1; waiting_buffer[i].tap.count = 1; - process_action(&tapping_key); + process_record(&tapping_key); debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); debug_waiting_buffer(); -- cgit v1.2.3-70-g09d2 From fde477a927edc6b4207a6968d44aeed021e8b300 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 15 May 2016 00:51:06 -0400 Subject: updates midi functionality (#331) * implements leader key for planck experimental * allows override of leader timeout * adds ability to use the leader key in seq * fixes leader keycode * adds chording prototype * fixes keycode detection * moves music mode to quantum.c * disables chording by default * adds music sequencer functionality * implements audio/music functions in quantum.c * splits up process_action to allow independent processing of actions * moves midi stuff to quantum.c * adds additional scales for midi --- keyboard/planck/keymaps/experimental/keymap.c | 6 +- keyboard/planck/keymaps/experimental/makefile.mk | 5 +- quantum/keymap_common.c | 5 -- quantum/keymap_common.h | 5 ++ quantum/quantum.c | 88 ++++++++++++++++++++++-- quantum/quantum.h | 3 +- quantum/quantum.mk | 6 +- tmk_core/protocol/lufa/lufa.c | 2 +- 8 files changed, 103 insertions(+), 17 deletions(-) (limited to 'quantum/quantum.c') diff --git a/keyboard/planck/keymaps/experimental/keymap.c b/keyboard/planck/keymaps/experimental/keymap.c index 8bc7334c9..2f8a0510a 100644 --- a/keyboard/planck/keymaps/experimental/keymap.c +++ b/keyboard/planck/keymaps/experimental/keymap.c @@ -162,7 +162,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_ADJUST] = { {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, - {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, _______, _______, _______, _______, _______, _______, _______}, + {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} } @@ -227,8 +227,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) case _LOWER: if (record->event.pressed) { layer_on(_LOWER); + #ifdef BACKLIGHT_ENABLE breathing_speed_set(2); breathing_pulse(); + #endif update_tri_layer(_LOWER, _RAISE, _ADJUST); } else { layer_off(_LOWER); @@ -238,8 +240,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) case _RAISE: if (record->event.pressed) { layer_on(_RAISE); + #ifdef BACKLIGHT_ENABLE breathing_speed_set(2); breathing_pulse(); + #endif update_tri_layer(_LOWER, _RAISE, _ADJUST); } else { layer_off(_RAISE); diff --git a/keyboard/planck/keymaps/experimental/makefile.mk b/keyboard/planck/keymaps/experimental/makefile.mk index 99fbfbd0b..6c1e05b65 100644 --- a/keyboard/planck/keymaps/experimental/makefile.mk +++ b/keyboard/planck/keymaps/experimental/makefile.mk @@ -1,2 +1,5 @@ AUDIO_ENABLE = yes -NKRO_ENABLE = yes \ No newline at end of file +NKRO_ENABLE = yes +MIDI_ENABLE = yes +BACKLIGHT_ENABLE = no +COMMAND_ENABLE = no \ No newline at end of file diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 0184770c4..2aae13e67 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -282,11 +282,6 @@ static action_t keycode_to_action(uint16_t keycode) action.code = ACTION_MODS_ONESHOT(mod); } break; - #ifdef MIDI_ENABLE - case 0x6000 ... 0x6FFF: - action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); - break; - #endif case 0x7000 ... 0x7FFF: action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); break; diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 0074ab164..07020150a 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -195,6 +195,7 @@ extern const uint16_t fn_actions[]; + // MAGIC keycodes #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 #define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003 @@ -232,6 +233,10 @@ extern const uint16_t fn_actions[]; #define MUV_IN 0x5024 #define MUV_DE 0x5025 +// Midi mode on/off +#define MI_ON 0x5026 +#define MI_OFF 0x5027 + // GOTO layer - 16 layers max // when: // ON_PRESS = 1 diff --git a/quantum/quantum.c b/quantum/quantum.c index dd5d84f82..5a978d332 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -19,11 +19,15 @@ void leader_end(void) {} #ifdef AUDIO_ENABLE uint8_t starting_note = 0x0C; - int offset = 0; + int offset = 7; bool music_activated = false; float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); #endif +#ifdef MIDI_ENABLE + bool midi_activated = false; +#endif + // Leader key stuff bool leading = false; uint16_t leader_time = 0; @@ -98,6 +102,82 @@ bool process_record_quantum(keyrecord_t *record) { // return false; // } + #ifdef MIDI_ENABLE + if (keycode == MI_ON && record->event.pressed) { + midi_activated = true; + PLAY_NOTE_ARRAY(music_scale, false, 0); + return false; + } + + if (keycode == MI_OFF && record->event.pressed) { + midi_activated = false; + midi_send_cc(&midi_device, 0, 0x7B, 0); + return false; + } + + if (midi_activated) { + if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) { + if (record->event.pressed) { + starting_note++; // Change key + midi_send_cc(&midi_device, 0, 0x7B, 0); + // midi_send_cc(&midi_device, 1, 0x7B, 0); + // midi_send_cc(&midi_device, 2, 0x7B, 0); + // midi_send_cc(&midi_device, 3, 0x7B, 0); + // midi_send_cc(&midi_device, 4, 0x7B, 0); + } + return false; + } + if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) { + if (record->event.pressed) { + starting_note--; // Change key + midi_send_cc(&midi_device, 0, 0x7B, 0); + // midi_send_cc(&midi_device, 1, 0x7B, 0); + // midi_send_cc(&midi_device, 2, 0x7B, 0); + // midi_send_cc(&midi_device, 3, 0x7B, 0); + // midi_send_cc(&midi_device, 4, 0x7B, 0); + } + return false; + } + if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { + offset++; // Change scale + midi_send_cc(&midi_device, 0, 0x7B, 0); + // midi_send_cc(&midi_device, 1, 0x7B, 0); + // midi_send_cc(&midi_device, 2, 0x7B, 0); + // midi_send_cc(&midi_device, 3, 0x7B, 0); + // midi_send_cc(&midi_device, 4, 0x7B, 0); + return false; + } + if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { + offset--; // Change scale + midi_send_cc(&midi_device, 0, 0x7B, 0); + // midi_send_cc(&midi_device, 1, 0x7B, 0); + // midi_send_cc(&midi_device, 2, 0x7B, 0); + // midi_send_cc(&midi_device, 3, 0x7B, 0); + // midi_send_cc(&midi_device, 4, 0x7B, 0); + return false; + } + // basic + // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row); + // advanced + // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row); + // guitar + uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row); + // violin + // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row); + + if (record->event.pressed) { + // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); + midi_send_noteon(&midi_device, 0, note, 127); + } else { + // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); + midi_send_noteoff(&midi_device, 0, note, 127); + } + + if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through + return false; + } + #endif + #ifdef AUDIO_ENABLE if (keycode == AU_ON && record->event.pressed) { audio_on(); @@ -169,7 +249,7 @@ bool process_record_quantum(keyrecord_t *record) { return false; } - float freq = ((float)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)); + float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)); if (record->event.pressed) { play_note(freq, 0xF); if (music_sequence_recording) { @@ -185,8 +265,6 @@ bool process_record_quantum(keyrecord_t *record) { } #endif - - #ifndef DISABLE_LEADER // Leader key set-up if (record->event.pressed) { @@ -267,6 +345,6 @@ void matrix_scan_quantum() { } #endif - + matrix_scan_kb(); } \ No newline at end of file diff --git a/quantum/quantum.h b/quantum/quantum.h index db726ad42..bfecdb262 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -13,7 +13,8 @@ #include "audio.h" #endif #ifdef MIDI_ENABLE - #include + // #include + #include #endif #include "action_layer.h" #include "eeconfig.h" diff --git a/quantum/quantum.mk b/quantum/quantum.mk index b45ad850a..e7ccfd659 100644 --- a/quantum/quantum.mk +++ b/quantum/quantum.mk @@ -24,9 +24,9 @@ ifndef CUSTOM_MATRIX SRC += $(QUANTUM_DIR)/matrix.c endif -ifeq ($(strip $(MIDI_ENABLE)), yes) - SRC += $(QUANTUM_DIR)/keymap_midi.c -endif +#ifeq ($(strip $(MIDI_ENABLE)), yes) +# SRC += $(QUANTUM_DIR)/keymap_midi.c +#endif ifeq ($(strip $(AUDIO_ENABLE)), yes) SRC += $(QUANTUM_DIR)/audio/audio.c diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index f03f9a9b9..aba94cd59 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -883,7 +883,7 @@ int main(void) midi_register_cc_callback(&midi_device, cc_callback); midi_register_sysex_callback(&midi_device, sysex_callback); - init_notes(); + // init_notes(); // midi_send_cc(&midi_device, 0, 1, 2); // midi_send_cc(&midi_device, 15, 1, 0); // midi_send_noteon(&midi_device, 0, 64, 127); -- cgit v1.2.3-70-g09d2 From 0428214b905e5f8b3bed721885957ce249ba4991 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 18 May 2016 23:14:00 -0400 Subject: adds music and audio toggles (#337) * Updated personal layouts * tweaked personal * Nightly - Audio Cleanup Refactored the LUTs. Abstracted some of the registers out of audio to use more functional names. Split audio into audio and audio_pwm. WIP * nightly - collapsed code * Added check for note playing to LEDs * Usability tweaks * TWEAE * nightly added extra kcs to keymap common * turned on Plank audio * Added backlight breathing to atomic * reverted accidental merge * Added music and audio toggles to Quantum.c * Redid the audio callbacks * music/audio_on_user --- keyboard/atomic/keymaps/pvc/keymap.c | 48 +++++++++++++---------- quantum/audio/audio.c | 8 +++- quantum/audio/audio.h | 6 +-- quantum/keymap_common.h | 14 ++++--- quantum/quantum.c | 75 +++++++++++++++++++++++++++++------- quantum/quantum.h | 7 ++++ 6 files changed, 114 insertions(+), 44 deletions(-) (limited to 'quantum/quantum.c') diff --git a/keyboard/atomic/keymaps/pvc/keymap.c b/keyboard/atomic/keymaps/pvc/keymap.c index ff7384268..8431654d7 100644 --- a/keyboard/atomic/keymaps/pvc/keymap.c +++ b/keyboard/atomic/keymaps/pvc/keymap.c @@ -15,8 +15,7 @@ #define LAYER_LOWER 4 #define LAYER_FUNCTION 5 #define LAYER_MOUSE 6 -#define LAYER_MUSIC 7 -#define LAYER_ADJUST 8 +#define LAYER_ADJUST 7 #define MACRO_QWERTY 0 #define MACRO_COLEMAK 1 @@ -63,8 +62,8 @@ #define M_BDFLT M(MACRO_BREATH_DEFAULT) -#define MUS_TOG M(MACRO_MUSIC_TOGGLE) -#define AUD_TOG M(MACRO_AUDIO_TOGGLE) +//#define MU_TOG M(MACRO_MUSIC_TOGGLE) +//#define AU_TOG M(MACRO_AUDIO_TOGGLE) #define VC_UP M(MACRO_INC_VOICE) #define VC_DOWN M(MACRO_DEC_VOICE) @@ -219,20 +218,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #endif - [LAYER_MUSIC] = { // MUSIC - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_UPPER, XXXXXXX, XXXXXXX, M_LOWER, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - }, - [LAYER_ADJUST] = { // ADJUST - { _______, TIMBR_1, TIMBR_2, TIMBR_3, TIMBR_4, TMPO_UP, TMPO_DN, TMPO_DF, _______, _______, _______, MUS_TOG, AUD_TOG, ________________ }, + { _______, TIMBR_1, TIMBR_2, TIMBR_3, TIMBR_4, TMPO_UP, TMPO_DN, TMPO_DF, _______, _______, _______, MU_TOG, AU_TOG, ________________ }, { _______, M_QWRTY, M_COLMK, M_DVORK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ }, { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ________________, _______ }, - { _______, _______, _______, _______, M_BACKL, RESET, _______, M_MOUSE, _______, _______, _______, ________________, VC_UP, _______ }, - { _______, _______, _______, _______, _______, ________________, _______, _______, _______, _______, _______, _______, VC_DOWN, _______ }, + { _______, _______, _______, _______, M_BACKL, RESET, _______, M_MOUSE, _______, _______, _______, ________________, MUV_IN, _______ }, + { _______, _______, _______, _______, _______, ________________, _______, _______, _______, _______, _______, _______, MUV_DE, _______ }, }, @@ -259,13 +250,14 @@ float tone_colemak[][2] = SONG(COLEMAK_SOUND); float tone_audio_on[][2] = SONG(CLOSE_ENCOUNTERS_5_NOTE); float tone_music_on[][2] = SONG(DOE_A_DEER); +float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); + float tone_caps_on[][2] = SONG(CAPS_LOCK_ON_SOUND); float tone_caps_off[][2] = SONG(CAPS_LOCK_OFF_SOUND); float tone_numlk_on[][2] = SONG(NUM_LOCK_ON_SOUND); float tone_numlk_off[][2] = SONG(NUM_LOCK_OFF_SOUND); float tone_scroll_on[][2] = SONG(SCROLL_LOCK_ON_SOUND); float tone_scroll_off[][2] = SONG(SCROLL_LOCK_OFF_SOUND); -float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); #endif /* AUDIO_ENABLE */ @@ -434,6 +426,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) } break; +/* case MACRO_AUDIO_TOGGLE: if (record->event.pressed) { @@ -464,7 +457,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) } } break; - case MACRO_INC_VOICE: if (record->event.pressed) { @@ -484,6 +476,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #endif } break; +*/ #endif /* AUDIO_ENABLE */ @@ -505,8 +498,8 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef AUDIO_ENABLE - -void process_action_user(keyrecord_t *record) +/* +bool process_action_user(keyrecord_t *record) { uint8_t starting_note = 0x0C; @@ -524,7 +517,7 @@ void process_action_user(keyrecord_t *record) } } } - +*/ void matrix_init_user(void) { @@ -590,4 +583,19 @@ void play_goodbye_tone() stop_all_notes(); } +void play_audio_on_tone(void) +{ + PLAY_NOTE_ARRAY(tone_audio_on, false, STACCATO); +} + +void play_music_on_tone(void) +{ + PLAY_NOTE_ARRAY(tone_music_on, false, STACCATO); +} + +void play_music_scale(void) +{ + PLAY_NOTE_ARRAY(music_scale, false, STACCATO); +} + #endif /* AUDIO_ENABLE */ \ No newline at end of file diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 243f49f0e..32f64417e 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -381,11 +381,14 @@ bool is_audio_on(void) { void audio_toggle(void) { audio_config.enable ^= 1; eeconfig_update_audio(audio_config.raw); + if (audio_config.enable) + audio_on_user(); } void audio_on(void) { audio_config.enable = 1; eeconfig_update_audio(audio_config.raw); + audio_on_user(); } void audio_off(void) { @@ -484,5 +487,8 @@ __attribute__ ((weak)) void play_goodbye_tone() {} __attribute__ ((weak)) -void audio_on_callback(void) {} +void audio_on_user() {} + +__attribute__ ((weak)) +void play_music_scale() {} //------------------------------------------------------------------------------ diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index fe8506131..b46f587bb 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -29,7 +29,6 @@ bool is_audio_on(void); void audio_toggle(void); void audio_on(void); void audio_off(void); -void audio_on_callback(void); // Vibrato rate functions @@ -87,9 +86,10 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) bool is_playing_notes(void); + void play_goodbye_tone(void); void play_startup_tone(void); - - +void audio_on_user(void); +void play_music_scale(void); #endif \ No newline at end of file diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 07020150a..1cbe8c61c 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -224,18 +224,20 @@ extern const uint16_t fn_actions[]; // Audio on/off #define AU_ON 0x5020 #define AU_OFF 0x5021 +#define AU_TOG 0x5022 // Music mode on/off -#define MU_ON 0x5022 -#define MU_OFF 0x5023 +#define MU_ON 0x5023 +#define MU_OFF 0x5024 +#define MU_TOG 0x5025 // Music voice iterate -#define MUV_IN 0x5024 -#define MUV_DE 0x5025 +#define MUV_IN 0x5026 +#define MUV_DE 0x5027 // Midi mode on/off -#define MI_ON 0x5026 -#define MI_OFF 0x5027 +#define MI_ON 0x5028 +#define MI_OFF 0x5029 // GOTO layer - 16 layers max // when: diff --git a/quantum/quantum.c b/quantum/quantum.c index 5a978d332..e4d7b9185 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1,4 +1,5 @@ #include "quantum.h" +#include "timer.h" __attribute__ ((weak)) void matrix_init_kb(void) {} @@ -17,11 +18,11 @@ void leader_start(void) {} __attribute__ ((weak)) void leader_end(void) {} +uint8_t starting_note = 0x0C; +int offset = 7; + #ifdef AUDIO_ENABLE - uint8_t starting_note = 0x0C; - int offset = 7; bool music_activated = false; - float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); #endif #ifdef MIDI_ENABLE @@ -105,7 +106,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef MIDI_ENABLE if (keycode == MI_ON && record->event.pressed) { midi_activated = true; - PLAY_NOTE_ARRAY(music_scale, false, 0); + play_music_scale(); return false; } @@ -181,7 +182,6 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef AUDIO_ENABLE if (keycode == AU_ON && record->event.pressed) { audio_on(); - audio_on_callback(); return false; } @@ -190,31 +190,53 @@ bool process_record_quantum(keyrecord_t *record) { return false; } + if (keycode == AU_TOG && record->event.pressed) { + if (is_audio_on()) + { + audio_off(); + } + else + { + audio_on(); + } + return false; + } + if (keycode == MU_ON && record->event.pressed) { - music_activated = true; - PLAY_NOTE_ARRAY(music_scale, false, 0); + music_on(); return false; } if (keycode == MU_OFF && record->event.pressed) { - music_activated = false; - stop_all_notes(); + music_off(); return false; } + if (keycode == MU_TOG && record->event.pressed) { + if (music_activated) + { + music_off(); + } + else + { + music_on(); + } + return false; + } + if (keycode == MUV_IN && record->event.pressed) { voice_iterate(); - PLAY_NOTE_ARRAY(music_scale, false, 0); + play_music_scale(); return false; } if (keycode == MUV_DE && record->event.pressed) { voice_deiterate(); - PLAY_NOTE_ARRAY(music_scale, false, 0); + play_music_scale(); return false; } - if (music_activated) { + if (music_activated) { if (keycode == KC_LCTL && record->event.pressed) { // Start recording stop_all_notes(); @@ -258,7 +280,7 @@ bool process_record_quantum(keyrecord_t *record) { } } else { stop_note(freq); - } + } if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through return false; @@ -347,4 +369,29 @@ void matrix_scan_quantum() { #endif matrix_scan_kb(); -} \ No newline at end of file +} + +bool is_music_on(void) { + return (music_activated != 0); +} + +void music_toggle(void) { + if (!music_activated) { + music_on(); + } else { + music_off(); + } +} + +void music_on(void) { + music_activated = 1; + music_on_user(); +} + +void music_off(void) { + music_activated = 0; + stop_all_notes(); +} + +__attribute__ ((weak)) +void music_on_user() {} \ No newline at end of file diff --git a/quantum/quantum.h b/quantum/quantum.h index bfecdb262..f4d8f09d4 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -46,4 +46,11 @@ void leader_end(void); #define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) +bool is_music_on(void); +void music_toggle(void); +void music_on(void); +void music_off(void); + +void music_on_user(void); + #endif \ No newline at end of file -- cgit v1.2.3-70-g09d2 From b732b79b49b098dba8e14493c745075f336747d8 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 18 May 2016 23:47:16 -0400 Subject: adapts unicode to quantum.c (#333) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Unicode to have unicode input you need to: - set your OS input method to UNICODE if needed - enable unicode in your makefile - copy the action_function from keyboard/planck/keymaps/unicode/unicode.c to your keymap.c set the target OS method in your keymap.c: void matrix_init_user() { set_unicode_mode(UC_OSX); } you can then switch when you want with: set_unicode_mode(UC_OSX); set_unicode_mode(UC_LNX); set_unicode_mode(UC_WIN); put some unicode codes in your keymap like so: UC(0x0061) I did change the bit mask in quantum/keymap_common.c and .h I’m afraid we will need uint32 to get a total support for all unicode tables or relocate the handler as @mbarkhau did. * rearranges keycode values, hooks-up unicode * removes extra lalt ref * adds unicode shortcuts and example --- keyboard/planck/keymaps/unicode/keymap.c | 326 ++++++++++++++++++++++++++++ keyboard/planck/keymaps/unicode/makefile.mk | 1 + quantum/keymap_common.c | 26 +-- quantum/keymap_common.h | 76 +++---- quantum/keymap_unicode.c | 61 ------ quantum/quantum.c | 79 ++++++- quantum/quantum.h | 44 ++-- quantum/quantum.mk | 4 - quantum/unicode.h | 128 +++++++++++ tmk_core/common.mk | 4 + 10 files changed, 609 insertions(+), 140 deletions(-) create mode 100644 keyboard/planck/keymaps/unicode/keymap.c create mode 100644 keyboard/planck/keymaps/unicode/makefile.mk delete mode 100644 quantum/keymap_unicode.c create mode 100644 quantum/unicode.h (limited to 'quantum/quantum.c') diff --git a/keyboard/planck/keymaps/unicode/keymap.c b/keyboard/planck/keymaps/unicode/keymap.c new file mode 100644 index 000000000..d73e7e09d --- /dev/null +++ b/keyboard/planck/keymaps/unicode/keymap.c @@ -0,0 +1,326 @@ +/* + Copyright + 2015 Jack Humbert + 2016 Francois Marlier + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + For more info on how this works per OS, see here + https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input +*/ + + +#include "planck.h" +#include "action_layer.h" +#ifdef AUDIO_ENABLE + #include "audio.h" +#endif +#include "eeconfig.h" + +extern keymap_config_t keymap_config; + +// Each layer gets a name for readability, which is then used in the keymap matrix below. +// The underscores don't mean anything - you can have a layer called STUFF or any other name. +// Layer names don't all need to be of the same length, obviously, and you can also skip them +// entirely and just use numbers. +#define _QWERTY 0 +#define _COLEMAK 1 +#define _DVORAK 2 +#define _LOWER 3 +#define _RAISE 4 +#define _PLOVER 5 +#define _ADJUST 16 + +// Macro name shortcuts +#define QWERTY M(_QWERTY) +#define COLEMAK M(_COLEMAK) +#define DVORAK M(_DVORAK) +#define LOWER M(_LOWER) +#define RAISE M(_RAISE) +#define M_BL 5 +#define PLOVER M(12) +#define EXT_PLV M(13) +#define TOG_OUT M(14) + +// Fillers to make layering more clear +#define _______ KC_TRNS +#define XXXXXXX KC_NO + + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + +/* Qwerty + * ,-----------------------------------------------------------------------------------. + * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | S | D | F | G | H | J | K | L | ; | " | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_QWERTY] = { + {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, + {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, + {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} +}, + +/* Colemak + * ,-----------------------------------------------------------------------------------. + * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | R | S | T | D | H | N | E | I | O | " | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_COLEMAK] = { + {KC_TAB, UC_q, UC_w, UC_f, UC_p, UC_g, UC_j, UC_l, UC_u, UC_y, UC_SCLN, UC_BSPC}, + {KC_ESC, UC_a, UC_r, UC_s, UC_t, UC_d, UC_h, UC_n, UC_e, UC_i, UC_o, UC_QUOT}, + {KC_LSFT, UC_z, UC_x, UC_c, UC_v, UC_b, UC_k, UC_m, UC_COMM, UC_DOT, UC_SLSH, KC_ENT}, + {KC_TRNS, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} +}, + +/* Dvorak + * ,-----------------------------------------------------------------------------------. + * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | O | E | U | I | D | H | T | N | S | / | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_DVORAK] = { + {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, + {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, + {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} +}, + +/* Lower + * ,-----------------------------------------------------------------------------------. + * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ +[_LOWER] = { + {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, + {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, + {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} +}, + +/* Raise + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ +[_RAISE] = { + {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, + {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, + {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} +}, + +/* Plover layer (http://opensteno.org) + * ,-----------------------------------------------------------------------------------. + * | # | # | # | # | # | # | # | # | # | # | # | # | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | S | T | P | H | * | * | F | P | L | T | D | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * |TogOut| S | K | W | R | * | * | R | B | G | S | Z | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Exit | | | A | O | | E | U | | | | + * `-----------------------------------------------------------------------------------' + */ + +[_PLOVER] = { + {KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 }, + {XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC}, + {TOG_OUT, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, + {EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX} +}, + +/* Adjust (Lower + Raise) + * ,-----------------------------------------------------------------------------------. + * | | Reset| | | | | | | | | | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | |Voice-|Voice+|Mus on|Musoff| | | | | | | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | | | | | + * `-----------------------------------------------------------------------------------' + */ +[_ADJUST] = { + {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, + {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, + {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} +} + + +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +#ifdef AUDIO_ENABLE +float tone_startup[][2] = { + {440.0*pow(2.0,(31)/12.0), 12}, + {440.0*pow(2.0,(28)/12.0), 8}, + {440.0*pow(2.0,(19)/12.0), 8}, + {440.0*pow(2.0,(24)/12.0), 8}, + {440.0*pow(2.0,(28)/12.0), 20} +}; + +float tone_qwerty[][2] = SONG(QWERTY_SOUND); +float tone_dvorak[][2] = SONG(DVORAK_SOUND); +float tone_colemak[][2] = SONG(COLEMAK_SOUND); +float tone_plover[][2] = SONG(PLOVER_SOUND); +float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND); + +float goodbye[][2] = SONG(GOODBYE_SOUND); +#endif + + +void persistant_default_layer_set(uint16_t default_layer) { + eeconfig_update_default_layer(default_layer); + default_layer_set(default_layer); +} + +const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) +{ + switch(id) { + case _QWERTY: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_qwerty, false, 0); + #endif + persistant_default_layer_set(1UL<<_QWERTY); + } + break; + case _COLEMAK: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_colemak, false, 0); + #endif + persistant_default_layer_set(1UL<<_COLEMAK); + } + break; + case _DVORAK: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_dvorak, false, 0); + #endif + persistant_default_layer_set(1UL<<_DVORAK); + } + break; + case _LOWER: + if (record->event.pressed) { + layer_on(_LOWER); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } else { + layer_off(_LOWER); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } + break; + case _RAISE: + if (record->event.pressed) { + layer_on(_RAISE); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } else { + layer_off(_RAISE); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } + break; + case M_BL: + if (record->event.pressed) { + register_code(KC_RSFT); + #ifdef BACKLIGHT_ENABLE + backlight_step(); + #endif + } else { + unregister_code(KC_RSFT); + } + break; + case 12: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + stop_all_notes(); + PLAY_NOTE_ARRAY(tone_plover, false, 0); + #endif + layer_off(_RAISE); + layer_off(_LOWER); + layer_off(_ADJUST); + layer_on(_PLOVER); + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + keymap_config.raw = eeconfig_read_keymap(); + keymap_config.nkro = 1; + eeconfig_update_keymap(keymap_config.raw); + } + break; + case 13: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_plover_gb, false, 0); + #endif + layer_off(_PLOVER); + } + break; + case 14: + if (record->event.pressed) { + return MACRO( D(E), D(R), D(F), D(V), D(O), D(L), U(E), U(R), U(F), U(V), U(O), U(L), END ); + } + break; + } + return MACRO_NONE; +}; + +void matrix_init_user(void) { + #ifdef AUDIO_ENABLE + _delay_ms(20); // stops the tick + PLAY_NOTE_ARRAY(tone_startup, false, 0); + #endif +} + +#ifdef AUDIO_ENABLE +void play_goodbye_tone() +{ + PLAY_NOTE_ARRAY(goodbye, false, 0); + _delay_ms(150); +} +#endif + + diff --git a/keyboard/planck/keymaps/unicode/makefile.mk b/keyboard/planck/keymaps/unicode/makefile.mk new file mode 100644 index 000000000..9b27b08be --- /dev/null +++ b/keyboard/planck/keymaps/unicode/makefile.mk @@ -0,0 +1 @@ +UNICODE_ENABLE = yes # Unicode diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 2aae13e67..1d9ab2e05 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -31,7 +31,6 @@ along with this program. If not, see . #include "keymap_midi.h" #endif - extern keymap_config_t keymap_config; #include @@ -154,20 +153,22 @@ static action_t keycode_to_action(uint16_t keycode) case KC_TRNS: action.code = ACTION_TRANSPARENT; break; - case 0x0100 ... 0x1FFF: ; + case LCTL(0) ... 0x1FFF: ; // Has a modifier // Split it up action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key break; - case 0x2000 ... 0x2FFF: + case FUNC(0) ... FUNC(0xFFF): ; // Is a shortcut for function layer, pull last 12bits // This means we have 4,096 FN macros at our disposal return keymap_func_to_action(keycode & 0xFFF); break; - case 0x3000 ... 0x3FFF: ; - // When the code starts with 3, it's an action macro. + case M(0) ... M(0xFF): action.code = ACTION_MACRO(keycode & 0xFF); break; + case LT(0, 0) ... LT(0xFF, 0xF): + action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); + break; #ifdef BACKLIGHT_ENABLE case BL_0 ... BL_15: action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F); @@ -201,7 +202,7 @@ static action_t keycode_to_action(uint16_t keycode) print("\nDEBUG: enabled.\n"); debug_enable = true; break; - case 0x5002 ... 0x50FF: + case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI: // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { eeconfig_init(); @@ -251,7 +252,7 @@ static action_t keycode_to_action(uint16_t keycode) } eeconfig_update_keymap(keymap_config.raw); break; - case 0x5100 ... 0x56FF: ; + case TO(0, 1) ... OSM(0xFF): ; // Layer movement shortcuts // See .h to see constraints/usage int type = (keycode >> 0x8) & 0xF; @@ -282,18 +283,9 @@ static action_t keycode_to_action(uint16_t keycode) action.code = ACTION_MODS_ONESHOT(mod); } break; - case 0x7000 ... 0x7FFF: + case MT(0, 0) ... MT(0xF, 0xFF): action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); break; - case 0x8000 ... 0x8FFF: - action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); - break; - #ifdef UNICODE_ENABLE - case 0x8000000 ... 0x8FFFFFF: - uint16_t unicode = keycode & ~(0x8000); - action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8); - break; - #endif default: action.code = ACTION_NO; break; diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 1cbe8c61c..91d5c09c1 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -163,38 +163,13 @@ extern const uint16_t fn_actions[]; #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) -// These affect the backlight (if your keyboard has one). -// We don't need to comment them out if your keyboard doesn't have a backlight, -// since they don't take up any space. -#define BL_ON 0x4009 -#define BL_OFF 0x4000 -#define BL_0 0x4000 -#define BL_1 0x4001 -#define BL_2 0x4002 -#define BL_3 0x4003 -#define BL_4 0x4004 -#define BL_5 0x4005 -#define BL_6 0x4006 -#define BL_7 0x4007 -#define BL_8 0x4008 -#define BL_9 0x4009 -#define BL_10 0x400A -#define BL_11 0x400B -#define BL_12 0x400C -#define BL_13 0x400D -#define BL_14 0x400E -#define BL_15 0x400F -#define BL_DEC 0x4010 -#define BL_INC 0x4011 -#define BL_TOGG 0x4012 -#define BL_STEP 0x4013 +// 0x3100+ is free + +// L-ayer, T-ap - 256 keycode max, 16 layer max +#define LT(layer, kc) (kc | 0x4000 | ((layer & 0xF) << 8)) #define RESET 0x5000 #define DEBUG 0x5001 -#define KC_LEAD 0x5014 - - - // MAGIC keycodes #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 @@ -239,6 +214,32 @@ extern const uint16_t fn_actions[]; #define MI_ON 0x5028 #define MI_OFF 0x5029 +// These affect the backlight (if your keyboard has one). +// We don't need to comment them out if your keyboard doesn't have a backlight, +// since they don't take up any space. +#define BL_ON 0x5079 +#define BL_OFF 0x5070 +#define BL_0 0x5070 +#define BL_1 0x5071 +#define BL_2 0x5072 +#define BL_3 0x5073 +#define BL_4 0x5074 +#define BL_5 0x5075 +#define BL_6 0x5076 +#define BL_7 0x5077 +#define BL_8 0x5078 +#define BL_9 0x5079 +#define BL_10 0x507A +#define BL_11 0x507B +#define BL_12 0x507C +#define BL_13 0x507D +#define BL_14 0x507E +#define BL_15 0x507F +#define BL_DEC 0x5080 +#define BL_INC 0x5081 +#define BL_TOGG 0x5082 +#define BL_STEP 0x5083 + // GOTO layer - 16 layers max // when: // ON_PRESS = 1 @@ -261,6 +262,8 @@ extern const uint16_t fn_actions[]; // One-shot mod #define OSM(layer) (layer | 0x5600) +// chording is currently at 0x57xx + // M-od, T-ap - 256 keycode max #define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8)) #define CTL_T(kc) MT(0x1, kc) @@ -276,14 +279,13 @@ extern const uint16_t fn_actions[]; #define KC_HYPR HYPR(KC_NO) #define KC_MEH MEH(KC_NO) -// L-ayer, T-ap - 256 keycode max, 16 layer max -#define LT(layer, kc) (kc | 0x8000 | ((layer & 0xF) << 8)) - -// For sending unicode codes. -// You may not send codes over 1FFF -- this supports most of UTF8. -// To have a key that sends out Œ, go UC(0x0152) -#define UNICODE(n) (n | 0x8000) -#define UC(n) UNICODE(n) +#ifdef UNICODE_ENABLE + // For sending unicode codes. + // You may not send codes over 7FFF -- this supports most of UTF8. + // To have a key that sends out Œ, go UC(0x0152) + #define UNICODE(n) (n | 0x8000) + #define UC(n) UNICODE(n) +#endif // For tri-layer void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c deleted file mode 100644 index a44965e61..000000000 --- a/quantum/keymap_unicode.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2015 Jack Humbert - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "keymap_common.h" - -uint16_t hextokeycode(int hex) { - if (hex == 0x0) { - return KC_0; - } else if (hex < 0xA) { - return KC_1 + (hex - 0x1); - } else { - return KC_A + (hex - 0xA); - } -} - -void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) -{ - - // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input - - if (record->event.pressed) { - uint16_t unicode = (opt << 8) | id; - register_code(KC_LALT); - - register_code(hextokeycode((unicode & 0xF000) >> 12)); - unregister_code(hextokeycode((unicode & 0xF000) >> 12)); - register_code(hextokeycode((unicode & 0x0F00) >> 8)); - unregister_code(hextokeycode((unicode & 0x0F00) >> 8)); - register_code(hextokeycode((unicode & 0x00F0) >> 4)); - unregister_code(hextokeycode((unicode & 0x00F0) >> 4)); - register_code(hextokeycode((unicode & 0x000F))); - unregister_code(hextokeycode((unicode & 0x000F))); - - /* Test 'a' */ - // register_code(hextokeycode(0x0)); - // unregister_code(hextokeycode(0x0)); - // register_code(hextokeycode(0x0)); - // unregister_code(hextokeycode(0x0)); - // register_code(hextokeycode(0x6)); - // unregister_code(hextokeycode(0x6)); - // register_code(hextokeycode(0x1)); - // unregister_code(hextokeycode(0x1)); - - unregister_code(KC_LALT); - } - return; -} \ No newline at end of file diff --git a/quantum/quantum.c b/quantum/quantum.c index e4d7b9185..1e91ac04a 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -23,6 +23,18 @@ int offset = 7; #ifdef AUDIO_ENABLE bool music_activated = false; + float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); + + // music sequencer + static bool music_sequence_recording = false; + static bool music_sequence_playing = false; + static float music_sequence[16] = {0}; + static uint8_t music_sequence_count = 0; + static uint8_t music_sequence_position = 0; + + static uint16_t music_sequence_timer = 0; + static uint16_t music_sequence_interval = 100; + #endif #ifdef MIDI_ENABLE @@ -44,6 +56,10 @@ uint8_t chord_keys[CHORDING_MAX] = {0}; uint8_t chord_key_count = 0; uint8_t chord_key_down = 0; +#ifdef UNICODE_ENABLE + static uint8_t input_mode; +#endif + bool keys_chord(uint8_t keys[]) { uint8_t keys_size = sizeof(keys)/sizeof(keys[0]); bool pass = true; @@ -66,14 +82,25 @@ bool keys_chord(uint8_t keys[]) { return (pass && (in == keys_size)); } -static bool music_sequence_recording = false; -static bool music_sequence_playing = false; -static float music_sequence[16] = {0}; -static uint8_t music_sequence_count = 0; -static uint8_t music_sequence_position = 0; +#ifdef UNICODE_ENABLE + +uint16_t hex_to_keycode(uint8_t hex) +{ + if (hex == 0x0) { + return KC_0; + } else if (hex < 0xA) { + return KC_1 + (hex - 0x1); + } else { + return KC_A + (hex - 0xA); + } +} + +void set_unicode_mode(uint8_t os_target) +{ + input_mode = os_target; +} -static uint16_t music_sequence_timer = 0; -static uint16_t music_sequence_interval = 100; +#endif bool process_record_quantum(keyrecord_t *record) { @@ -347,6 +374,44 @@ bool process_record_quantum(keyrecord_t *record) { #endif +#ifdef UNICODE_ENABLE + + if (keycode > UNICODE(0) && record->event.pressed) { + uint16_t unicode = keycode & 0x7FFF; + switch(input_mode) { + case UC_OSX: + register_code(KC_LALT); + break; + case UC_LNX: + register_code(KC_LCTL); + register_code(KC_LSFT); + register_code(KC_U); + unregister_code(KC_U); + break; + case UC_WIN: + register_code(KC_LALT); + register_code(KC_PPLS); + unregister_code(KC_PPLS); + break; + } + for(int i = 3; i >= 0; i--) { + uint8_t digit = ((unicode >> (i*4)) & 0xF); + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + } + switch(input_mode) { + case UC_OSX: + case UC_WIN: + unregister_code(KC_LALT); + break; + case UC_LNX: + unregister_code(KC_LCTL); + unregister_code(KC_LSFT); + break; + } + } + +#endif return process_action_kb(record); } diff --git a/quantum/quantum.h b/quantum/quantum.h index f4d8f09d4..d4da77289 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -13,9 +13,12 @@ #include "audio.h" #endif #ifdef MIDI_ENABLE - // #include #include #endif +#ifdef UNICODE_ENABLE + #include "unicode.h" +#endif + #include "action_layer.h" #include "eeconfig.h" #include @@ -27,24 +30,37 @@ extern uint32_t default_layer_state; extern uint32_t layer_state; #endif -bool music_activated; +#ifdef AUDIO_ENABLE + bool music_activated; +#endif -void matrix_init_kb(void); -void matrix_scan_kb(void); -bool process_action_kb(keyrecord_t *record); +#ifdef UNICODE_ENABLE + #define UC_OSX 0 + #define UC_LNX 1 + #define UC_WIN 2 + #define UC_BSD 3 -void leader_start(void); -void leader_end(void); + void set_unicode_input_mode(uint8_t os_target); +#endif + +#ifndef DISABLE_LEADER + void leader_start(void); + void leader_end(void); + + #ifndef LEADER_TIMEOUT + #define LEADER_TIMEOUT 200 + #endif + #define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0) + #define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0) + #define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3)) -#ifndef LEADER_TIMEOUT - #define LEADER_TIMEOUT 200 + #define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size + #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) #endif -#define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0) -#define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0) -#define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3)) -#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size -#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) +void matrix_init_kb(void); +void matrix_scan_kb(void); +bool process_action_kb(keyrecord_t *record); bool is_music_on(void); void music_toggle(void); diff --git a/quantum/quantum.mk b/quantum/quantum.mk index e7ccfd659..c099d6793 100644 --- a/quantum/quantum.mk +++ b/quantum/quantum.mk @@ -34,10 +34,6 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes) SRC += $(QUANTUM_DIR)/audio/luts.c endif -ifeq ($(strip $(UNICODE_ENABLE)), yes) - SRC += $(QUANTUM_DIR)/keymap_unicode.c -endif - ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) SRC += $(QUANTUM_DIR)/light_ws2812.c SRC += $(QUANTUM_DIR)/rgblight.c diff --git a/quantum/unicode.h b/quantum/unicode.h new file mode 100644 index 000000000..756ec8bc3 --- /dev/null +++ b/quantum/unicode.h @@ -0,0 +1,128 @@ +/* +Copyright 2016 Jack Humbert +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef UNICODE_H +#define UNICODE_H + +#include "quantum.h" +#include + +#define UC_BSPC UC(0x0008) + +#define UC_SPC UC(0x0020) + +#define UC_EXLM UC(0x0021) +#define UC_DQUT UC(0x0022) +#define UC_HASH UC(0x0023) +#define UC_DLR UC(0x0024) +#define UC_PERC UC(0x0025) +#define UC_AMPR UC(0x0026) +#define UC_QUOT UC(0x0027) +#define UC_LPRN UC(0x0028) +#define UC_RPRN UC(0x0029) +#define UC_ASTR UC(0x002A) +#define UC_PLUS UC(0x002B) +#define UC_COMM UC(0x002C) +#define UC_DASH UC(0x002D) +#define UC_DOT UC(0x002E) +#define UC_SLSH UC(0x002F) + +#define UC_0 UC(0x0030) +#define UC_1 UC(0x0031) +#define UC_2 UC(0x0032) +#define UC_3 UC(0x0033) +#define UC_4 UC(0x0034) +#define UC_5 UC(0x0035) +#define UC_6 UC(0x0036) +#define UC_7 UC(0x0037) +#define UC_8 UC(0x0038) +#define UC_9 UC(0x0039) + +#define UC_COLN UC(0x003A) +#define UC_SCLN UC(0x003B) +#define UC_LT UC(0x003C) +#define UC_EQL UC(0x003D) +#define UC_GT UC(0x003E) +#define UC_QUES UC(0x003F) +#define UC_AT UC(0x0040) + +#define UC_A UC(0x0041) +#define UC_B UC(0x0042) +#define UC_C UC(0x0043) +#define UC_D UC(0x0044) +#define UC_E UC(0x0045) +#define UC_F UC(0x0046) +#define UC_G UC(0x0047) +#define UC_H UC(0x0048) +#define UC_I UC(0x0049) +#define UC_J UC(0x004A) +#define UC_K UC(0x004B) +#define UC_L UC(0x004C) +#define UC_M UC(0x004D) +#define UC_N UC(0x004E) +#define UC_O UC(0x004F) +#define UC_P UC(0x0050) +#define UC_Q UC(0x0051) +#define UC_R UC(0x0052) +#define UC_S UC(0x0053) +#define UC_T UC(0x0054) +#define UC_U UC(0x0055) +#define UC_V UC(0x0056) +#define UC_W UC(0x0057) +#define UC_X UC(0x0058) +#define UC_Y UC(0x0059) +#define UC_Z UC(0x005A) + +#define UC_LBRC UC(0x005B) +#define UC_BSLS UC(0x005C) +#define UC_RBRC UC(0x005D) +#define UC_CIRM UC(0x005E) +#define UC_UNDR UC(0x005F) + +#define UC_GRV UC(0x0060) + +#define UC_a UC(0x0061) +#define UC_b UC(0x0062) +#define UC_c UC(0x0063) +#define UC_d UC(0x0064) +#define UC_e UC(0x0065) +#define UC_f UC(0x0066) +#define UC_g UC(0x0067) +#define UC_h UC(0x0068) +#define UC_i UC(0x0069) +#define UC_j UC(0x006A) +#define UC_k UC(0x006B) +#define UC_l UC(0x006C) +#define UC_m UC(0x006D) +#define UC_n UC(0x006E) +#define UC_o UC(0x006F) +#define UC_p UC(0x0070) +#define UC_q UC(0x0071) +#define UC_r UC(0x0072) +#define UC_s UC(0x0073) +#define UC_t UC(0x0074) +#define UC_u UC(0x0075) +#define UC_v UC(0x0076) +#define UC_w UC(0x0077) +#define UC_x UC(0x0078) +#define UC_y UC(0x0079) +#define UC_z UC(0x007A) + +#define UC_LCBR UC(0x007B) +#define UC_PIPE UC(0x007C) +#define UC_RCBR UC(0x007D) +#define UC_TILD UC(0x007E) +#define UC_DEL UC(0x007F) + +#endif \ No newline at end of file diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 9cb2eb8ec..b5d7e39dd 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -60,6 +60,10 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes) OPT_DEFS += -DAUDIO_ENABLE endif +ifeq ($(strip $(UNICODE_ENABLE)), yes) + OPT_DEFS += -DUNICODE_ENABLE +endif + ifeq ($(strip $(USB_6KRO_ENABLE)), yes) OPT_DEFS += -DUSB_6KRO_ENABLE endif -- cgit v1.2.3-70-g09d2 From 0275d444d77c9d85d2189b09d8813fb76dc4d566 Mon Sep 17 00:00:00 2001 From: purpleP Date: Thu, 19 May 2016 15:36:28 +0300 Subject: fixed small bug with AUDIO_ENABLED (#339) --- quantum/quantum.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 1e91ac04a..34c575af4 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -20,7 +20,7 @@ void leader_end(void) {} uint8_t starting_note = 0x0C; int offset = 7; - + #ifdef AUDIO_ENABLE bool music_activated = false; float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); @@ -435,28 +435,29 @@ void matrix_scan_quantum() { matrix_scan_kb(); } +#ifdef AUDIO_ENABLE + bool is_music_on(void) { + return (music_activated != 0); + } -bool is_music_on(void) { - return (music_activated != 0); -} - -void music_toggle(void) { - if (!music_activated) { - music_on(); - } else { - music_off(); - } -} + void music_toggle(void) { + if (!music_activated) { + music_on(); + } else { + music_off(); + } + } -void music_on(void) { - music_activated = 1; - music_on_user(); -} + void music_on(void) { + music_activated = 1; + music_on_user(); + } -void music_off(void) { - music_activated = 0; - stop_all_notes(); -} + void music_off(void) { + music_activated = 0; + stop_all_notes(); + } +#endif __attribute__ ((weak)) -void music_on_user() {} \ No newline at end of file +void music_on_user() {} -- cgit v1.2.3-70-g09d2 From 287eb7ad148abc8fe3fb014218d71e205fd9131d Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 24 May 2016 11:56:53 -0400 Subject: Converted audio play functions to *_user (#349) * Updated personal layouts * tweaked personal * Nightly - Audio Cleanup Refactored the LUTs. Abstracted some of the registers out of audio to use more functional names. Split audio into audio and audio_pwm. WIP * nightly - collapsed code * Added check for note playing to LEDs * Usability tweaks * TWEAE * nightly added extra kcs to keymap common * turned on Plank audio * Added backlight breathing to atomic * reverted accidental merge * Added music and audio toggles to Quantum.c * Redid the audio callbacks * Adjusted default planck layout to use the user tone naming * tabs to spaces * Rewrote the ALL recipe to allow for faster parallel make * tabs to spaces * Renamed custom event functions to be 'startup_user' and 'shutdown_user'. Also moved the prototypes around. * Tweaked pvc atomic layout to work with the pvc planck. * updates midi scale calling --- keyboard/atomic/keymaps/pvc/keymap.c | 41 +---- keyboard/planck/keymaps/default/keymap.c | 43 +++-- keyboard/planck/keymaps/pvc/config.h | 2 +- keyboard/planck/keymaps/pvc/keymap.c | 291 ++++++++++++------------------- quantum/audio/audio.c | 17 -- quantum/audio/audio.h | 6 +- quantum/keymap_common.c | 3 +- quantum/quantum.c | 69 +++++--- quantum/quantum.h | 4 + tmk_core/common/command.c | 13 +- tmk_core/rules.mk | 8 +- 11 files changed, 215 insertions(+), 282 deletions(-) (limited to 'quantum/quantum.c') diff --git a/keyboard/atomic/keymaps/pvc/keymap.c b/keyboard/atomic/keymaps/pvc/keymap.c index 8431654d7..f16ec8a6e 100644 --- a/keyboard/atomic/keymaps/pvc/keymap.c +++ b/keyboard/atomic/keymaps/pvc/keymap.c @@ -62,8 +62,6 @@ #define M_BDFLT M(MACRO_BREATH_DEFAULT) -//#define MU_TOG M(MACRO_MUSIC_TOGGLE) -//#define AU_TOG M(MACRO_AUDIO_TOGGLE) #define VC_UP M(MACRO_INC_VOICE) #define VC_DOWN M(MACRO_DEC_VOICE) @@ -156,11 +154,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* UPPER * .---------------------------------------------------------------------------------------------------------------------- 2u ------------. - * | PRINT | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | NUM LK | / | * | - | NUM LK | SCR LK | XXXXXX . PAUSE | + * | PRINT | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | NUM LK | / | * | | NUM LK | SCR LK | XXXXXX . PAUSE | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------| - * | | F1 | F2 | F3 | F4 | | | 7 | 8 | 9 | + | ~ | | | INS | + * | | F1 | F2 | F3 | F4 | | | 7 | 8 | 9 | - | | | | INS | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------| - * | CAP LK | F5 | F6 | F7 | F8 | | | 4 | 5 | 6 | + | ` | XXXXXX . | HOME | + * | CAP LK | F5 | F6 | F7 | F8 | | | 4 | 5 | 6 | + | | XXXXXX . | HOME | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------| * | | F9 | F10 | F11 | F12 | | | 1 | 2 | 3 | ENTER | XXXXXX . | | END | * |--------+--------+--------+--------+--------+- 2u ------------+--------+--------+--------+--------+-----------------+--------+--------| @@ -498,31 +496,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef AUDIO_ENABLE -/* -bool process_action_user(keyrecord_t *record) -{ - - uint8_t starting_note = 0x0C; - int offset = 7; - - if (IS_LAYER_ON(LAYER_MUSIC)) - { - if (record->event.pressed) - { - play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); - } - else - { - stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); - } - } -} -*/ - void matrix_init_user(void) { set_voice(default_voice); - play_startup_tone(); + startup_user(); println("Matrix Init"); } @@ -570,30 +547,30 @@ void led_set_user(uint8_t usb_led) } -void play_startup_tone() +void startup_user() { _delay_ms(10); // gets rid of tick PLAY_NOTE_ARRAY(tone_my_startup, false, STACCATO); } -void play_goodbye_tone() +void shutdown_user() { PLAY_NOTE_ARRAY(tone_my_goodbye, false, STACCATO); _delay_ms(2000); stop_all_notes(); } -void play_audio_on_tone(void) +void audio_on_user(void) { PLAY_NOTE_ARRAY(tone_audio_on, false, STACCATO); } -void play_music_on_tone(void) +void music_on_user(void) { PLAY_NOTE_ARRAY(tone_music_on, false, STACCATO); } -void play_music_scale(void) +void music_scale_user(void) { PLAY_NOTE_ARRAY(music_scale, false, STACCATO); } diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c index 36d496416..3d6289817 100644 --- a/keyboard/planck/keymaps/default/keymap.c +++ b/keyboard/planck/keymaps/default/keymap.c @@ -174,21 +174,16 @@ const uint16_t PROGMEM fn_actions[] = { }; #ifdef AUDIO_ENABLE -float tone_startup[][2] = { - {440.0*pow(2.0,(31)/12.0), 12}, - {440.0*pow(2.0,(28)/12.0), 8}, - {440.0*pow(2.0,(19)/12.0), 8}, - {440.0*pow(2.0,(24)/12.0), 8}, - {440.0*pow(2.0,(28)/12.0), 20} -}; +float tone_startup[][2] = SONG(STARTUP_SOUND); float tone_qwerty[][2] = SONG(QWERTY_SOUND); float tone_dvorak[][2] = SONG(DVORAK_SOUND); float tone_colemak[][2] = SONG(COLEMAK_SOUND); float tone_plover[][2] = SONG(PLOVER_SOUND); float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND); +float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); -float goodbye[][2] = SONG(GOODBYE_SOUND); +float tone_goodbye[][2] = SONG(GOODBYE_SOUND); #endif @@ -288,16 +283,34 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) }; void matrix_init_user(void) { - #ifdef AUDIO_ENABLE - _delay_ms(20); // stops the tick - PLAY_NOTE_ARRAY(tone_startup, false, 0); - #endif + #ifdef AUDIO_ENABLE + startup_user(); + #endif } #ifdef AUDIO_ENABLE -void play_goodbye_tone() + +void startup_user() +{ + _delay_ms(20); // gets rid of tick + PLAY_NOTE_ARRAY(tone_startup, false, 0); +} + +void shutdown_user() { - PLAY_NOTE_ARRAY(goodbye, false, 0); - _delay_ms(150); + PLAY_NOTE_ARRAY(tone_goodbye, false, 0); + _delay_ms(150); + stop_all_notes(); } + +void music_on_user(void) +{ + music_scale_user(); +} + +void music_scale_user(void) +{ + PLAY_NOTE_ARRAY(music_scale, false, 0); +} + #endif diff --git a/keyboard/planck/keymaps/pvc/config.h b/keyboard/planck/keymaps/pvc/config.h index b8960038a..b64893108 100644 --- a/keyboard/planck/keymaps/pvc/config.h +++ b/keyboard/planck/keymaps/pvc/config.h @@ -74,7 +74,7 @@ along with this program. If not, see . */ /* disable debug print */ -#define NO_DEBUG +//#define NO_DEBUG /* disable print */ //#define NO_PRINT diff --git a/keyboard/planck/keymaps/pvc/keymap.c b/keyboard/planck/keymaps/pvc/keymap.c index 177f04484..2fc5f0da1 100644 --- a/keyboard/planck/keymaps/pvc/keymap.c +++ b/keyboard/planck/keymaps/pvc/keymap.c @@ -8,43 +8,44 @@ #include "song_list.h" #endif -#define LAYER_QWERTY 0 -#define LAYER_COLEMAK 1 -#define LAYER_DVORAK 2 -#define LAYER_LOWER 3 -#define LAYER_RAISE 4 -#define LAYER_FUNCTION 5 -#define LAYER_MOUSE 6 -#define LAYER_MUSIC 7 -#define LAYER_ADJUST 8 - -#define MACRO_QWERTY 0 -#define MACRO_COLEMAK 1 -#define MACRO_DVORAK 2 -#define MACRO_LOWER 3 -#define MACRO_RAISE 4 -#define MACRO_FUNCTION 5 -#define MACRO_MOUSE 6 -#define MACRO_TIMBRE_1 7 -#define MACRO_TIMBRE_2 8 -#define MACRO_TIMBRE_3 9 -#define MACRO_TIMBRE_4 10 -#define MACRO_TEMPO_U 11 -#define MACRO_TEMPO_D 12 -#define MACRO_TONE_DEFAULT 13 -#define MACRO_MUSIC_ON 14 -#define MACRO_MUSIC_OFF 15 -#define MACRO_AUDIO_ON 16 -#define MACRO_AUDIO_OFF 17 -#define MACRO_INC_VOICE 18 -#define MACRO_DEC_VOICE 19 -#define MACRO_BACKLIGHT 20 +#define LAYER_QWERTY 0 +#define LAYER_COLEMAK 1 +#define LAYER_DVORAK 2 +#define LAYER_UPPER 3 +#define LAYER_LOWER 4 +#define LAYER_FUNCTION 5 +#define LAYER_MOUSE 6 +#define LAYER_ADJUST 7 + +#define MACRO_QWERTY 0 +#define MACRO_COLEMAK 1 +#define MACRO_DVORAK 2 +#define MACRO_UPPER 3 +#define MACRO_LOWER 4 +#define MACRO_FUNCTION 5 +#define MACRO_MOUSE 6 +#define MACRO_TIMBRE_1 7 +#define MACRO_TIMBRE_2 8 +#define MACRO_TIMBRE_3 9 +#define MACRO_TIMBRE_4 10 +#define MACRO_TEMPO_U 11 +#define MACRO_TEMPO_D 12 +#define MACRO_TONE_DEFAULT 13 +#define MACRO_MUSIC_TOGGLE 14 +#define MACRO_AUDIO_TOGGLE 16 +#define MACRO_INC_VOICE 18 +#define MACRO_DEC_VOICE 19 +#define MACRO_BACKLIGHT 20 +#define MACRO_BREATH_TOGGLE 21 +#define MACRO_BREATH_SPEED_INC 23 +#define MACRO_BREATH_SPEED_DEC 24 +#define MACRO_BREATH_DEFAULT 25 #define M_QWRTY M(MACRO_QWERTY) #define M_COLMK M(MACRO_COLEMAK) #define M_DVORK M(MACRO_DVORAK) +#define M_UPPER M(MACRO_UPPER) #define M_LOWER M(MACRO_LOWER) -#define M_RAISE M(MACRO_RAISE) #define M_FUNCT M(MACRO_FUNCTION) #define M_MOUSE M(MACRO_MOUSE) #define TIMBR_1 M(MACRO_TIMBRE_1) @@ -55,12 +56,12 @@ #define TMPO_DN M(MACRO_TEMPO_D) #define TMPO_DF M(MACRO_TONE_DEFAULT) #define M_BACKL M(MACRO_BACKLIGHT) +#define M_BRTOG M(MACRO_BREATH_TOGGLE) +#define M_BSPDU M(MACRO_BREATH_SPEED_INC) +#define M_BSPDD M(MACRO_BREATH_SPEED_DEC) +#define M_BDFLT M(MACRO_BREATH_DEFAULT) -#define MUS_ON M(MACRO_MUSIC_ON) -#define MUS_OFF M(MACRO_MUSIC_OFF) -#define AUD_OFF M(MACRO_AUDIO_OFF) -#define AUD_ON M(MACRO_AUDIO_ON) #define VC_UP M(MACRO_INC_VOICE) #define VC_DOWN M(MACRO_DEC_VOICE) @@ -76,6 +77,7 @@ #define SC_ACLS LALT(KC_F4) #define SC_CCLS LCTL(KC_F4) +#define OS_SHFT KC_FN0 #define _______ KC_TRNS #define XXXXXXX KC_NO @@ -90,17 +92,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| * | ESC | A | S | D | F | G | H | J | K | L | ; | ' | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LSHIFT | Z | X | C | V | B | N | M | , | . | / | ENTER | + * | LSHIFT | Z | X | C | V | B | N | M | , | . | UP | ENTER | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LCTRL | LWIN | FN | LALT | RAISE | SPACE | SPACE | LOWER | UP | DOWN | LEFT | RIGHT | + * | LCTRL | LWIN | FN | LALT | UPPER | SPACE | SPACE | LOWER | SHIFT | LEFT | DOWN | RIGHT | * '-----------------------------------------------------------------------------------------------------------' */ - [LAYER_QWERTY] = { /* QWERTY */ - { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC }, + [LAYER_QWERTY] = { // QWERTY + { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC }, { KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT }, - { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_RAISE, KC_SPC, KC_SPC, M_LOWER, KC_UP, KC_DOWN, KC_LEFT, KC_RGHT }, + { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_ENT }, + { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_UPPER, KC_SPC, KC_SPC, M_LOWER, OS_SHFT, KC_LEFT, KC_DOWN, KC_RGHT }, }, /* COLEMAK @@ -109,77 +111,77 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| * | BACKSP | A | R | S | T | D | H | N | E | I | O | ' | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LSHIFT | Z | X | C | V | B | K | M | , | . | / | ENTER | + * | LSHIFT | Z | X | C | V | B | K | M | , | . | UP | ENTER | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LCTRL | LWIN | FN | LALT | RAISE | SPACE | SPACE | LOWER | UP | DOWN | LEFT | RIGHT | + * | LCTRL | LWIN | FN | LALT | UPPER | SPACE | SPACE | LOWER | SHIFT | LEFT | DOWN | RIGHT | * '-----------------------------------------------------------------------------------------------------------' */ - [LAYER_COLEMAK] = { /* COLEMAK */ + [LAYER_COLEMAK] = { // COLEMAK { KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_ESC }, { KC_BSPC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT }, - { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_RAISE, KC_SPC, KC_SPC, M_LOWER, KC_UP, KC_DOWN, KC_LEFT, KC_RGHT }, + { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_UP, KC_ENT }, + { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_UPPER, KC_SPC, KC_SPC, M_LOWER, OS_SHFT, KC_LEFT, KC_DOWN, KC_RGHT }, }, /* DVORAK * .-----------------------------------------------------------------------------------------------------------. * | TAB | ' | , | . | P | Y | F | G | C | R | L | BACKSP | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | ESC | A | O | E | U | I | D | H | T | N | S | ' | + * | ESC | A | O | E | U | I | D | H | T | N | S | / | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| * | LSHIFT | ; | Q | J | K | X | B | M | W | V | Z | ENTER | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LCTRL | LWIN | FN | LALT | RAISE | SPACE | SPACE | LOWER | UP | DOWN | LEFT | RIGHT | + * | LCTRL | LWIN | FN | LALT | UPPER | SPACE | SPACE | LOWER | UP | DOWN | LEFT | RIGHT | * '-----------------------------------------------------------------------------------------------------------' */ - [LAYER_DVORAK] = { /* DVORAK */ + [LAYER_DVORAK] = { // DVORAK { KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC }, { KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH }, { KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, - { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_RAISE, KC_SPC, KC_SPC, M_LOWER, KC_UP, KC_DOWN, KC_LEFT, KC_RGHT }, + { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_UPPER, KC_SPC, KC_SPC, M_LOWER, KC_UP, KC_DOWN, KC_LEFT, KC_RGHT }, }, -/* Raise +/* UPPER * .-----------------------------------------------------------------------------------------------------------. - * | ~ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | DEL | + * | PRINT | F1 | F2 | F3 | F4 | NUM LK | / | 7 | 8 | 9 | - | DEL | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | XXXXXX | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | [ | ] | \ | + * | CAP LK | F5 | F6 | F7 | F8 | SCR LK | * | 4 | 5 | 6 | + | INS | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LSHIFT | F7 | F8 | F9 | F10 | F11 | F12 | XXXXXX | XXXXXX | XXXXXX | XXXXXX | ENTER | - * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LCTRL | LWIN | FN | LALT | RAISE | BACKSP | BACKSP | LOWER | PG UP | PG DN | HOME | END | + * | | F9 | F10 | F11 | F12 | PAUSE | | 1 | 2 | 3 | ENTER | HOME | + * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------| + * | | | | | | 0 | 0 | | RALT | . | ENTER | END | * '-----------------------------------------------------------------------------------------------------------' */ - [LAYER_RAISE] = { /* RAISED */ - { KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL }, - { XXXXXXX, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS }, - { _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { _______, _______, _______, _______, _______, KC_BSPC, KC_BSPC, _______, KC_PGUP, KC_PGDN, KC_HOME, KC_END }, + [LAYER_UPPER] = { // UPPER + { KC_PSCR, KC_F1, KC_F2, KC_F3, KC_F4, KC_NLCK, KC_PSLS, KC_KP_7, KC_KP_8, KC_KP_9, KC_PMNS, KC_DEL }, + { KC_CAPS, KC_F5, KC_F6, KC_F7, KC_F8, KC_SLCK, KC_PAST, KC_KP_4, KC_KP_5, KC_KP_6, KC_PPLS, KC_INS }, + { _______, KC_F9, KC_F10, KC_F11, KC_F12, KC_PAUS, XXXXXXX, KC_KP_1, KC_KP_2, KC_KP_3, KC_PENT, KC_HOME }, + { _______, _______, _______, _______, _______, KC_KP_0, KC_KP_0, _______, KC_RALT, KC_PDOT, KC_PENT, KC_END }, }, - -/* LOWERED +/* LOWER * .-----------------------------------------------------------------------------------------------------------. - * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | INS | + * | | $ | { | [ | ( | % | # | ) | ] | } | @ | PG UP | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | XXXXXX | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | + * | | ^ | * | + | - | ; | : | _ | ' | " | ` | PG DN | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LSHIFT | F7 | F8 | F9 | F10 | F11 | F12 | XXXXXX | XXXXXX | XXXXXX | XXXXXX | ENTER | - * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LCTRL | LWIN | FN | LALT | RAISE | BACKSP | BACKSP | LOWER | PG UP | PG DN | HOME | END | + * | | | | & | ! | ~ | / | \ | = | < | > | ? | HOME | + * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------| + * | | | | | | | | | | | | END | * '-----------------------------------------------------------------------------------------------------------' */ - [LAYER_LOWER] = { /* LOWERED */ - { KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_INS }, - { XXXXXXX, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS }, - { _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { _______, _______, _______, _______, _______, KC_BSPC, KC_BSPC, _______, KC_PGUP, KC_PGDN, KC_HOME, KC_END }, + [LAYER_LOWER] = { // LOWER + { _______, KC_DLR, KC_LCBR, KC_LBRC, KC_LPRN, KC_PERC, KC_HASH, KC_RPRN, KC_RBRC, KC_RCBR, KC_AT, KC_PGUP }, + { _______, KC_CIRC, KC_ASTR, KC_PPLS, KC_PMNS, KC_SCLN, KC_COLN, KC_UNDS, KC_QUOT, KC_DQT, KC_GRV, KC_PGDN }, + { _______, KC_PIPE, KC_AMPR, KC_EXLM, KC_TILD, KC_SLSH, KC_BSLS, KC_EQL, KC_LT, KC_GT, KC_QUES, KC_HOME }, + { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END }, }, + /* FUNCTION * .-----------------------------------------------------------------------------------------------------------. * | NUM LK | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | PAUSE | @@ -188,10 +190,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| * | SCR LK | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | MUTE | * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------| - * | LCTRL | LWIN | FN | LALT | RAISE | PLAY | PLAY | LOWER | VOL UP | VOL DN | NEXT | PREV | + * | LCTRL | LWIN | FN | LALT | UPPER | PLAY | PLAY | LOWER | VOL UP | VOL DN | NEXT | PREV | * '-----------------------------------------------------------------------------------------------------------' */ - [LAYER_FUNCTION] = { /* FUNCTION */ + [LAYER_FUNCTION] = { // FUNCTION { KC_NLCK, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_PAUS }, { KC_CAPS, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, KC_PSCR }, { KC_SLCK, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MUTE }, @@ -200,7 +202,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #ifdef MOUSEKEY_ENABLE - [LAYER_MOUSE] = { /* MOUSE */ + [LAYER_MOUSE] = { // MOUSE { KC_ESC, KC_ACL0, KC_ACL1, KC_ACL2, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC }, { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, { _______, KC_BTN5, KC_BTN4, KC_BTN3, KC_BTN2, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_WH_U, KC_WH_D }, @@ -209,21 +211,13 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #endif - [LAYER_MUSIC] = { /* MUSIC */ - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_RAISE, XXXXXXX, XXXXXXX, M_LOWER, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX }, - }, - - [LAYER_ADJUST] = { /* ADJUST */ - { _______, TIMBR_1, TIMBR_2, TIMBR_3, TIMBR_4, TMPO_UP, TMPO_DN, TMPO_DF, MUS_ON, MUS_OFF, AUD_ON, AUD_OFF }, + [LAYER_ADJUST] = { // ADJUST + { _______, TIMBR_1, TIMBR_2, TIMBR_3, TIMBR_4, TMPO_UP, TMPO_DN, TMPO_DF, _______, _______, MU_TOG, AU_TOG }, { _______, M_QWRTY, M_COLMK, M_DVORK, _______, _______, _______, _______, _______, _______, _______, _______ }, - { _______, _______, _______, _______, M_BACKL, RESET, _______, M_MOUSE, _______, _______, _______, _______ }, - { _______, _______, _______, _______, _______, _______, _______, _______, VC_UP, VC_DOWN, _______, _______ }, + { _______, _______, _______, _______, M_BACKL, RESET, _______, M_MOUSE, _______, _______, MUV_IN, _______ }, + { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, MUV_DE, _______ }, }, - /* [LAYER_EMPTY] = { { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, }, @@ -263,6 +257,7 @@ void persistant_default_layer_set(uint16_t default_layer) } const uint16_t PROGMEM fn_actions[] = { + [0] = ACTION_MODS_ONESHOT(MOD_LSFT), }; const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) @@ -306,25 +301,25 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) if (record->event.pressed) { layer_on(LAYER_LOWER); - update_tri_layer(LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); + update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST); } else { layer_off(LAYER_LOWER); - update_tri_layer(LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); + update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST); } break; - case MACRO_RAISE: + case MACRO_UPPER: if (record->event.pressed) { - layer_on(LAYER_RAISE); - update_tri_layer(LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); + layer_on(LAYER_UPPER); + update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST); } else { - layer_off(LAYER_RAISE); - update_tri_layer(LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); + layer_off(LAYER_UPPER); + update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST); } break; @@ -393,65 +388,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) } break; - case MACRO_AUDIO_OFF: - if (record->event.pressed) - { - #ifdef AUDIO_ENABLE - audio_off(); - #endif - } - break; - - case MACRO_AUDIO_ON: - if (record->event.pressed) - { - #ifdef AUDIO_ENABLE - audio_on(); - PLAY_NOTE_ARRAY(tone_audio_on, false, STACCATO); - #endif - } - break; - - case MACRO_MUSIC_ON: - if (record->event.pressed) - { - #ifdef AUDIO_ENABLE - PLAY_NOTE_ARRAY(tone_music_on, false, STACCATO); - layer_on(LAYER_MUSIC); - #endif - } - break; - - case MACRO_MUSIC_OFF: - if (record->event.pressed) - { - #ifdef AUDIO_ENABLE - layer_off(LAYER_MUSIC); - stop_all_notes(); - #endif - } - break; - - case MACRO_INC_VOICE: - if (record->event.pressed) - { - #ifdef AUDIO_ENABLE - voice_iterate(); - PLAY_NOTE_ARRAY(music_scale, false, STACCATO); - #endif - } - break; - - case MACRO_DEC_VOICE: - if (record->event.pressed) - { - #ifdef AUDIO_ENABLE - voice_deiterate(); - PLAY_NOTE_ARRAY(music_scale, false, STACCATO); - #endif - } - break; - #endif /* AUDIO_ENABLE */ default: @@ -464,31 +400,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef AUDIO_ENABLE - -void process_action_user(keyrecord_t *record) -{ - - uint8_t starting_note = 0x0C; - int offset = 7; - - if (IS_LAYER_ON(LAYER_MUSIC)) - { - if (record->event.pressed) - { - play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); - } - else - { - stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); - } - } -} - - void matrix_init_user(void) { set_voice(default_voice); - play_startup_tone(); + startup_user(); println("Matrix Init"); } @@ -532,16 +447,32 @@ void led_set_user(uint8_t usb_led) } -void play_startup_tone() +void startup_user() { _delay_ms(10); // gets rid of tick PLAY_NOTE_ARRAY(tone_my_startup, false, STACCATO); } -void play_goodbye_tone() +void shutdown_user() { PLAY_NOTE_ARRAY(tone_my_goodbye, false, STACCATO); - _delay_ms(1000); + _delay_ms(2000); + stop_all_notes(); +} + +void audio_on_user(void) +{ + PLAY_NOTE_ARRAY(tone_audio_on, false, STACCATO); +} + +void music_on_user(void) +{ + PLAY_NOTE_ARRAY(tone_music_on, false, STACCATO); +} + +void music_scale_user(void) +{ + PLAY_NOTE_ARRAY(music_scale, false, STACCATO); } #endif /* AUDIO_ENABLE */ \ No newline at end of file diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 32f64417e..3ca249fdf 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -475,20 +475,3 @@ void increase_tempo(uint8_t tempo_change) { note_tempo -= tempo_change; } } - - -//------------------------------------------------------------------------------ -// Override these functions in your keymap file to play different tunes on -// startup and bootloader jump -__attribute__ ((weak)) -void play_startup_tone() {} - -__attribute__ ((weak)) -void play_goodbye_tone() {} - -__attribute__ ((weak)) -void audio_on_user() {} - -__attribute__ ((weak)) -void play_music_scale() {} -//------------------------------------------------------------------------------ diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index b46f587bb..00d45f7ac 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -5,6 +5,7 @@ #include "musical_notes.h" #include "song_list.h" #include "voices.h" +#include "quantum.h" #ifndef AUDIO_H #define AUDIO_H @@ -87,9 +88,4 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) bool is_playing_notes(void); -void play_goodbye_tone(void); -void play_startup_tone(void); -void audio_on_user(void); -void play_music_scale(void); - #endif \ No newline at end of file diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 1d9ab2e05..ba7269388 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -26,6 +26,7 @@ along with this program. If not, see . #include "backlight.h" #include "bootloader.h" #include "eeconfig.h" +#include "quantum.h" #ifdef MIDI_ENABLE #include "keymap_midi.h" @@ -190,7 +191,7 @@ static action_t keycode_to_action(uint16_t keycode) clear_keyboard(); #ifdef AUDIO_ENABLE stop_all_notes(); - play_goodbye_tone(); + shutdown_user(); #endif _delay_ms(250); #ifdef ATREUS_ASTAR diff --git a/quantum/quantum.c b/quantum/quantum.c index 34c575af4..eb64a99a4 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -23,17 +23,16 @@ int offset = 7; #ifdef AUDIO_ENABLE bool music_activated = false; - float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); - // music sequencer - static bool music_sequence_recording = false; - static bool music_sequence_playing = false; - static float music_sequence[16] = {0}; - static uint8_t music_sequence_count = 0; - static uint8_t music_sequence_position = 0; +// music sequencer +static bool music_sequence_recording = false; +static bool music_sequence_playing = false; +static float music_sequence[16] = {0}; +static uint8_t music_sequence_count = 0; +static uint8_t music_sequence_position = 0; - static uint16_t music_sequence_timer = 0; - static uint16_t music_sequence_interval = 100; +static uint16_t music_sequence_timer = 0; +static uint16_t music_sequence_interval = 100; #endif @@ -133,7 +132,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef MIDI_ENABLE if (keycode == MI_ON && record->event.pressed) { midi_activated = true; - play_music_scale(); + music_scale_user(); return false; } @@ -230,37 +229,37 @@ bool process_record_quantum(keyrecord_t *record) { } if (keycode == MU_ON && record->event.pressed) { - music_on(); - return false; + music_on(); + return false; } if (keycode == MU_OFF && record->event.pressed) { - music_off(); - return false; + music_off(); + return false; } if (keycode == MU_TOG && record->event.pressed) { if (music_activated) { - music_off(); + music_off(); } else { - music_on(); + music_on(); } return false; } if (keycode == MUV_IN && record->event.pressed) { - voice_iterate(); - play_music_scale(); - return false; + voice_iterate(); + music_scale_user(); + return false; } if (keycode == MUV_DE && record->event.pressed) { - voice_deiterate(); - play_music_scale(); - return false; + voice_deiterate(); + music_scale_user(); + return false; } if (music_activated) { @@ -272,12 +271,14 @@ bool process_record_quantum(keyrecord_t *record) { music_sequence_count = 0; return false; } + if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing stop_all_notes(); music_sequence_recording = false; music_sequence_playing = false; return false; } + if (keycode == KC_LGUI && record->event.pressed) { // Start playing stop_all_notes(); music_sequence_recording = false; @@ -289,12 +290,13 @@ bool process_record_quantum(keyrecord_t *record) { if (keycode == KC_UP) { if (record->event.pressed) - music_sequence_interval-=10; + music_sequence_interval-=10; return false; } + if (keycode == KC_DOWN) { if (record->event.pressed) - music_sequence_interval+=10; + music_sequence_interval+=10; return false; } @@ -459,5 +461,24 @@ void matrix_scan_quantum() { } #endif + +//------------------------------------------------------------------------------ +// Override these functions in your keymap file to play different tunes on +// different events such as startup and bootloader jump + +__attribute__ ((weak)) +void startup_user() {} + +__attribute__ ((weak)) +void shutdown_user() {} + __attribute__ ((weak)) void music_on_user() {} + +__attribute__ ((weak)) +void audio_on_user() {} + +__attribute__ ((weak)) +void music_scale_user() {} + +//------------------------------------------------------------------------------ \ No newline at end of file diff --git a/quantum/quantum.h b/quantum/quantum.h index d4da77289..69a0d8126 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -67,6 +67,10 @@ void music_toggle(void); void music_on(void); void music_off(void); +void startup_user(void); +void shutdown_user(void); +void audio_on_user(void); void music_on_user(void); +void music_scale_user(void); #endif \ No newline at end of file diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index 9edcc42a0..024d7c67a 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -33,20 +33,21 @@ along with this program. If not, see . #include "led.h" #include "command.h" #include "backlight.h" +#include "quantum.h" #ifdef MOUSEKEY_ENABLE #include "mousekey.h" #endif #ifdef PROTOCOL_PJRC -# include "usb_keyboard.h" -# ifdef EXTRAKEY_ENABLE -# include "usb_extra.h" -# endif + #include "usb_keyboard.h" + #ifdef EXTRAKEY_ENABLE + #include "usb_extra.h" + #endif #endif #ifdef PROTOCOL_VUSB -# include "usbdrv.h" + #include "usbdrv.h" #endif #ifdef AUDIO_ENABLE @@ -358,7 +359,7 @@ static bool command_common(uint8_t code) print("\n\nJumping to bootloader... "); #ifdef AUDIO_ENABLE stop_all_notes(); - play_goodbye_tone(); + shutdown_user(); #else _delay_ms(1000); #endif diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 552f32331..1d384574f 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -366,7 +366,13 @@ ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) # Default target. -all: begin gccversion sizebefore build sizeafter end +all: + $(MAKE) begin + $(MAKE) gccversion + $(MAKE) sizebefore + $(MAKE) build + $(MAKE) sizeafter + $(MAKE) end # Change the build target to build a HEX file or a library. build: elf hex eep lss sym -- cgit v1.2.3-70-g09d2