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 0000000000..e274d846f2 --- /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 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 --- quantum/quantum.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 4 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index e274d846f2..cd7fdbb7fe 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 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/quantum.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index cd7fdbb7fe..dd5d84f826 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 -- cgit v1.2.3 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 --- quantum/quantum.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 5 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index dd5d84f826..5a978d3320 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 -- cgit v1.2.3 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 --- quantum/quantum.c | 75 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 14 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 5a978d3320..e4d7b91852 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 -- cgit v1.2.3 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 --- quantum/quantum.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 7 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index e4d7b91852..1e91ac04a4 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); } -- cgit v1.2.3 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 1e91ac04a4..34c575af42 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 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 --- quantum/quantum.c | 69 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 24 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 34c575af42..eb64a99a4d 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 -- cgit v1.2.3