qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap.c (4301B)


      1 /* Copyright 2021 3araht
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 #include QMK_KEYBOARD_H
     17 #include "version.h"
     18 
     19 // Defines names for use in layer keycodes and the keymap
     20 enum layer_names {
     21     _BASE,
     22     _RESERVE,
     23     _FN
     24 };
     25 
     26 // Defines the keycodes used by our macros in process_record_user
     27 enum custom_keycodes {
     28     L_BASE = SAFE_RANGE,
     29     L_RESERVE,
     30     VERSION
     31 };
     32 
     33 // Long press: go to _FN layer, tap: MUTE
     34 #define FN_MUTE LT(_FN, KC_MUTE)
     35 
     36 // Used to set octave to 0
     37 extern midi_config_t midi_config;
     38 
     39 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     40     /* Base */
     41     [_BASE] = LAYOUT(
     42             FN_MUTE,          MI_SUST,
     43             MI_BNDU,
     44         MI_TRSD,  MI_TRSU,   MI_C2, MI_D2, MI_E2,  MI_Fs2, MI_Ab2, MI_Bb2, MI_C3, MI_D3, MI_E3, MI_Fs3, MI_Ab3, MI_Bb3, MI_C4,  MI_D4,  MI_E4, MI_Fs4, MI_Ab4, MI_Bb4, MI_C5,
     45             MI_BNDD,            MI_Db2, MI_Eb2, MI_F2,  MI_G2,  MI_A2,  MI_B2, MI_Db3, MI_Eb3, MI_F3,  MI_G3, MI_A3,  MI_B3, MI_Db4, MI_Eb4, MI_F4,  MI_G4,  MI_A4,  MI_B4
     46     ),
     47 
     48     /* RESERVE */
     49     [_RESERVE] = LAYOUT(
     50             _______,          _______,
     51             _______,
     52         _______, _______,      _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
     53             _______,               _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
     54     ),
     55 
     56     [_FN] =  LAYOUT(
     57             _______,          XXXXXXX,
     58             MI_VELU,
     59         MI_OCTD, MI_OCTU,     L_BASE, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, VERSION, XXXXXXX, XXXXXXX,
     60             MI_VELD,               L_RESERVE, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, EE_CLR, XXXXXXX, XXXXXXX
     61     )
     62 };
     63 
     64 #if defined(ENCODER_MAP_ENABLE)
     65 const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
     66     [_BASE]    = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU)  },
     67     [_RESERVE] = { ENCODER_CCW_CW(_______, _______)  },
     68     [_FN]      = { ENCODER_CCW_CW(_______, _______)  },
     69 };
     70 #endif
     71 
     72 // commom codes called from eeconfig_init_user() and keyboard_post_init_user().
     73 void my_init(void){
     74     //  Set octave to 0
     75     midi_config.octave = QK_MIDI_OCTAVE_0 - MIDI_OCTAVE_MIN;
     76     // avoid using 127 since it is used as a special number in some sound sources.
     77     midi_config.velocity = MIDI_INITIAL_VELOCITY;
     78     default_layer_set(1UL << _BASE);
     79 }
     80 
     81 void eeconfig_init_user(void) {  // EEPROM is getting reset!
     82     midi_init();
     83     my_init(); // commom codes called from eeconfig_init_user() and keyboard_post_init_user().
     84 }
     85 
     86 void keyboard_post_init_user(void) {
     87     my_init(); // commom codes called from eeconfig_init_user() and keyboard_post_init_user().
     88 };
     89 
     90 void reset_scale_indicator(void) {
     91     //  reset transpose value and scale_indicator_col to default.
     92     midi_config.transpose = 0;
     93 }
     94 
     95 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
     96     switch (keycode) {
     97         case VERSION: // Output firmware info.
     98             if (record->event.pressed) {
     99                 SEND_STRING(QMK_KEYBOARD ":" QMK_KEYMAP " @ " QMK_VERSION " | " QMK_BUILDDATE);
    100             }
    101             break;
    102 
    103         case L_BASE:
    104             reset_scale_indicator();
    105             default_layer_set(1UL << _BASE);
    106             break;
    107 
    108         case L_RESERVE:
    109             reset_scale_indicator();
    110             default_layer_set(1UL << _RESERVE);
    111             break;
    112     }
    113     return true;
    114 }