Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bandominedoni same note fix #20352

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions keyboards/bandominedoni/bandominedoni.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,41 @@
*/

#include "bandominedoni.h"
#include "version.h"

static uint8_t midi_sub_ch = DEFAULT_SUB_CH_NUMBER; // By default, DEFAULT_SUB_CH_NUMBER is used for sub ch.

// By default( when use_alt_ch_gr == false), DEFAULT ch group (DEFAULT_MAIN_CH_NUMBER for entirely, or right side when separated, DEFAULT_SUB_CH_NUMBER for left side) is used.
// When false, ALT ch group (ALT_MAIN_CH_NUMBER for entirely, or right side when separated, ALT_SUB_CH_NUMBER for left side) is used.
static bool use_alt_ch_gr = false;

static uint8_t my_tone_status[MY_TONE_COUNT];

void my_process_midi4single_note(uint8_t channel, uint16_t keycode, keyrecord_t *record, uint8_t *my_tone_status) {
uint8_t mytone = keycode - MY_TONE_MIN;
uint16_t mykeycode = mytone + MIDI_TONE_MIN;
// uint16_t mykeycode = keycode - MY_TONE_MIN;
// uint8_t mytone = mykeycode - MIDI_TONE_MIN;
uint8_t velocity = midi_config.velocity;
// uprintf("keycode=%u,mykeycode=%u,mytone =%u,velo = %u\n", keycode, mykeycode, mytone, velocity);
if (record->event.pressed) {
if (my_tone_status[mytone] == MIDI_INVALID_NOTE) {
uint8_t note = midi_compute_note(mykeycode);
midi_send_noteon(&midi_device, channel, note, velocity);
dprintf("midi noteon channel:%d note:%d mytone:%d velocity:%d\n", channel, note, mytone, velocity);
// uprintf("midi noteon channel:%d note:%d mytone:%d velocity:%d\n", channel, note, mytone, velocity);
my_tone_status[mytone] = note; // store root_note status.
}
} else {
uint8_t note = my_tone_status[mytone];
if (note != MIDI_INVALID_NOTE) {
midi_send_noteoff(&midi_device, channel, note, velocity);
dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
// uprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
}
my_tone_status[mytone] = MIDI_INVALID_NOTE;
}
}

#ifdef RGB_MATRIX_ENABLE

Expand Down Expand Up @@ -117,3 +152,78 @@ static enum { UNKNOWN, LEFT, RIGHT } hand_side = UNKNOWN;
return (hand_side == LEFT);
}
}

void my_init(void){
#ifndef VIA_ENABLE
for (uint8_t i = 0; i < MY_TONE_COUNT; i++) {
my_tone_status[i] = MIDI_INVALID_NOTE;
}
#endif

// Set octave to 0
midi_config.octave = QK_MIDI_OCTAVE_0 - MIDI_OCTAVE_MIN;

// avoid using 127 since it is used as a special number in some sound sources.
midi_config.velocity = MIDI_INITIAL_VELOCITY;
}

void eeconfig_init_kb(void) {
midi_init();
my_init();
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_enable();
rgb_matrix_set_speed(RGB_MATRIX_DEFAULT_SPD);
rgb_matrix_sethsv(HSV_BLUE);

rgb_matrix_mode(RGB_MATRIX_SOLID_REACTIVE);
// rgb_matrix_mode(RGB_MATRIX_RAINBOW_MOVING_CHEVRON);
#endif
eeconfig_init_user();
}

void keyboard_post_init_kb(void) {
my_init();

#ifdef RGB_MATRIX_ENABLE
# ifndef VIA_ENABLE
// party mode (for LED soldering test. Enable rainbow color effect, and disable led_indicator to check all LEDs)
rgb_matrix_mode(RGB_MATRIX_RAINBOW_MOVING_CHEVRON);
# else
rgb_matrix_mode(RGB_MATRIX_SOLID_REACTIVE);
# endif
#endif

keyboard_post_init_user();
}

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (!process_record_user(keycode, record)) {
return false;
}

switch (keycode) {
case VERSION: // Output firmware info.
if (record->event.pressed) {
SEND_STRING(QMK_KEYBOARD ":" QMK_KEYMAP " @ " QMK_VERSION " " QMK_GIT_HASH " | " QMK_BUILDDATE);
}
break;

case TGLCHGR:
if (record->event.pressed) {
use_alt_ch_gr = !use_alt_ch_gr;
if (use_alt_ch_gr) {
midi_sub_ch = ALT_SUB_CH_NUMBER;
} else { // default
midi_sub_ch = DEFAULT_SUB_CH_NUMBER;
}
}
break;

case MY_TONE_MIN ... MY_TONE_MAX: // MY tone
// uprintf("keycode=%u, MY_C3=%u, MY_Db2 =%u, MY_MIN = %u, MY_MAX = %u\n", keycode, MY_C3, MY_Db2, MY_TONE_MIN, MY_TONE_MAX);
// DO NOT THROW BELOW into 'if (record->event.pressed) {}' STATEMENT SINCE IT IS USED IN THE FUNCTION BELOW.
my_process_midi4single_note(midi_sub_ch, keycode, record, my_tone_status);
break;
}
return true;
}
156 changes: 156 additions & 0 deletions keyboards/bandominedoni/bandominedoni.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,168 @@
// Long press: go to _FN layer, tap: MUTE
#define FN_MUTE LT(_FN, KC_MUTE)
#define DF_QWER DF(_QWERTY)
#define DF_COLE DF(_COLEMAK)
#define MIS_EIS LT(_MISC,KC_LNG2)
#define MIS_KAN LT(_MISC,KC_LNG1)

#define _________________QWERTY_L1_________________ KC_Q, KC_W, KC_E, KC_R, KC_T
#define _________________QWERTY_L2_________________ KC_A, KC_S, KC_D, KC_F, KC_G
#define _________________QWERTY_L3_________________ KC_Z, KC_X, KC_C, KC_V, KC_B

#define _________________QWERTY_R1_________________ KC_Y, KC_U, KC_I, KC_O, KC_P
#define _________________QWERTY_R2_________________ KC_H, KC_J, KC_K, KC_L, KC_SCLN
#define _________________QWERTY_R3_________________ KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH

#define _________________COLEMAK_L1________________ KC_Q, KC_W, KC_F, KC_P, KC_G
#define _________________COLEMAK_L2________________ KC_A, KC_R, KC_S, KC_T, KC_D
#define _________________COLEMAK_L3________________ KC_Z, KC_X, KC_C, KC_V, KC_B

#define _________________COLEMAK_R1________________ KC_J, KC_L, KC_U, KC_Y, KC_SCLN
#define _________________COLEMAK_R2________________ KC_H, KC_N, KC_E, KC_I, KC_O
#define _________________COLEMAK_R3________________ KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH

#define _________________NUMBER_L__________________ KC_1, KC_2, KC_3, KC_4, KC_5
// #define _________________NUMBER_R__________________ KC_6, KC_7, KC_8, KC_9, KC_0

#define _________________FUNC__L___________________ KC_F1, KC_F2, KC_F3, KC_F4, KC_F5
// #define _________________FUNC__R___________________ KC_F6, KC_F7, KC_F8, KC_F9, KC_F10

// define which MIDI ch to use.
// Note that (actual MIDI ch# - 1) -> 0 .. 15 is used for coding.
// ch1
#define DEFAULT_SUB_CH_NUMBER 0
// ch2
#define ALT_SUB_CH_NUMBER 1

enum custom_keycodes {
VERSION = QK_KB,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only get 64 keyboard level keycodes https://github.com/qmk/qmk_firmware/blob/master/data/constants/keycodes/keycodes_0.0.2.hjson#L6, and can count 75 which would be invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, oh…
I can’t use QK_USER in the KB level, can I?

BYW, Thanks for changing the base branch to develop.

TGLCHGR, // ToGgLe CH GRoup

// MY tone to distinguish the notes to avoid sustain effect, etc.
// Since the # of codes exceeds the limit of QK_KB range (=64), these are stated here.
MY_TONE_MIN = QK_USER,

MY_C = MY_TONE_MIN,
MY_Cs,
MY_Db = MY_Cs,
MY_D,
MY_Ds,
MY_Eb = MY_Ds,
MY_E,
MY_F,
MY_Fs,
MY_Gb = MY_Fs,
MY_G,
MY_Gs,
MY_Ab = MY_Gs,
MY_A,
MY_As,
MY_Bb = MY_As,
MY_B,

MY_C1,
MY_Cs1,
MY_Db1 = MY_Cs1,
MY_D1,
MY_Ds1,
MY_Eb1 = MY_Ds1,
MY_E1,
MY_F1,
MY_Fs1,
MY_Gb1 = MY_Fs1,
MY_G1,
MY_Gs1,
MY_Ab1 = MY_Gs1,
MY_A1,
MY_As1,
MY_Bb1 = MY_As1,
MY_B1,

MY_C2,
MY_Cs2,
MY_Db2 = MY_Cs2,
MY_D2,
MY_Ds2,
MY_Eb2 = MY_Ds2,
MY_E2,
MY_F2,
MY_Fs2,
MY_Gb2 = MY_Fs2,
MY_G2,
MY_Gs2,
MY_Ab2 = MY_Gs2,
MY_A2,
MY_As2,
MY_Bb2 = MY_As2,
MY_B2,

MY_C3,
MY_Cs3,
MY_Db3 = MY_Cs3,
MY_D3,
MY_Ds3,
MY_Eb3 = MY_Ds3,
MY_E3,
MY_F3,
MY_Fs3,
MY_Gb3 = MY_Fs3,
MY_G3,
MY_Gs3,
MY_Ab3 = MY_Gs3,
MY_A3,
MY_As3,
MY_Bb3 = MY_As3,
MY_B3,

MY_C4,
MY_Cs4,
MY_Db4 = MY_Cs4,
MY_D4,
MY_Ds4,
MY_Eb4 = MY_Ds4,
MY_E4,
MY_F4,
MY_Fs4,
MY_Gb4 = MY_Fs4,
MY_G4,
MY_Gs4,
MY_Ab4 = MY_Gs4,
MY_A4,
MY_As4,
MY_Bb4 = MY_As4,
MY_B4,

MY_C5,
MY_Cs5,
MY_Db5 = MY_Cs5,
MY_D5,
MY_Ds5,
MY_Eb5 = MY_Ds5,
MY_E5,
MY_F5,
MY_Fs5,
MY_Gb5 = MY_Fs5,
MY_G5,
MY_Gs5,
MY_Ab5 = MY_Gs5,
MY_A5,
MY_As5,
MY_Bb5 = MY_As5,
MY_B5,

MY_C6,
MY_TONE_MAX = MY_C6
};

#define MY_TONE_COUNT (MY_TONE_MAX - MY_TONE_MIN + 1)

void my_process_midi4single_note(uint8_t channel, uint16_t keycode, keyrecord_t *record, uint8_t *my_tone_status);

// Overriding is_keyboard_left() in qmk_firmware/quantum/split_common/split_util.c to limit the handedness check only once.
// reason: bandoMIneDonI has no space on right hand side to use "SPLIT_HAND_MATRIX_GRID".
// However, It enables to decide the handedness by the HW by adding one condition: "not to press any keys (especially r30) dusing startup."
bool is_keyboard_left(void);

#ifdef MIDI_ENABLE
extern MidiDevice midi_device;
#endif // MIDI_ENABLE
15 changes: 15 additions & 0 deletions keyboards/bandominedoni/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
"manufacturer": "3araht",
"url": "https://github.com/3araht",
"maintainer": "3araht",
"features": {
"midi": true,
"extrakey": true,
"bootmagic": false,
"command": false,
"console": false,
"mousekey": false,
"nkro": false,
"rgblight": false,
"audio": false
},
"encoder": {
"enabled": true
},
"usb": {
"vid": "0xFEED",
"pid": "0xF4B5",
Expand All @@ -17,6 +31,7 @@
},
"diode_direction": "COL2ROW",
"split": {
"enabled": true,
"soft_serial_pin": "D2",
"encoder": {
"right": {
Expand Down
Loading