add midi layout and slider controls
This commit is contained in:
parent
34a7d47e49
commit
809a62b64d
@ -7,15 +7,16 @@ import usb_hid
|
||||
|
||||
from kb import KMKKeyboard
|
||||
|
||||
from kmk.extensions.RGB import RGB, AnimationModes
|
||||
from kmk.keys import KC
|
||||
from kmk.extensions.RGB import RGB, AnimationModes
|
||||
from kmk.modules.potentiometer import PotentiometerHandler
|
||||
from kmk.modules.layers import Layers
|
||||
from kmk.modules.midi import MidiKeys
|
||||
|
||||
keyboard = KMKKeyboard()
|
||||
keyboard.modules.append(Layers())
|
||||
keyboard.modules.append(MidiKeys())
|
||||
|
||||
#
|
||||
rgb_ext = RGB(
|
||||
val_default=10, val_limit=100, # out of 255
|
||||
pixel_pin=keyboard.rgb_pixel_pin, num_pixels=keyboard.rgb_num_pixels,
|
||||
@ -26,22 +27,35 @@ keyboard.extensions.append(rgb_ext)
|
||||
_______ = KC.TRNS
|
||||
XXXXXXX = KC.NO
|
||||
|
||||
FN1 = KC.MO(1)
|
||||
FN2 = KC.MO(2)
|
||||
FN3 = KC.MO(3)
|
||||
MIDI = KC.TG(4)
|
||||
BASE_LAYER_IDX = 0
|
||||
FN1_LAYER_IDX = 1
|
||||
FN2_LAYER_IDX = 2
|
||||
FN3_LAYER_IDX = 3
|
||||
MIDI_LAYER_IDX = 4
|
||||
|
||||
FN1 = KC.MO(FN1_LAYER_IDX)
|
||||
FN2 = KC.MO(FN2_LAYER_IDX)
|
||||
FN3 = KC.MO(FN3_LAYER_IDX)
|
||||
MIDI = KC.TG(MIDI_LAYER_IDX)
|
||||
|
||||
RGB_TOG = KC.RGB_TOG
|
||||
RAINBOW = KC.RGB_MODE_RAINBOW
|
||||
|
||||
def get_kb_rgb_obj(keyboard):
|
||||
rgb = None
|
||||
for ext in keyboard.extensions:
|
||||
if type(ext) is RGB:
|
||||
rgb = ext
|
||||
break
|
||||
return rgb
|
||||
|
||||
cc = ConsumerControl(usb_hid.devices)
|
||||
# keyboard.level_lock = 0
|
||||
keyboard.last_level = 0
|
||||
|
||||
level_steps = 17
|
||||
|
||||
# System volume
|
||||
def slider_1_handler(state):
|
||||
|
||||
def set_sys_vol(state):
|
||||
# print(f"slider 1 state: {state}")
|
||||
|
||||
# if keyboard.level_lock == 1:
|
||||
@ -79,14 +93,11 @@ def slider_1_handler(state):
|
||||
return
|
||||
|
||||
# LEDs Color or animation speed
|
||||
def slider_2_handler(state):
|
||||
rgb = None
|
||||
for ext in keyboard.extensions:
|
||||
if type(ext) is RGB:
|
||||
rgb = ext
|
||||
break
|
||||
def set_led_var(state):
|
||||
rgb = get_kb_rgb_obj(keyboard)
|
||||
if rgb is None:
|
||||
return
|
||||
|
||||
if rgb.animation_mode == AnimationModes.STATIC:
|
||||
rgb.hue = int((state['position'] / 127) * 359)
|
||||
else:
|
||||
@ -94,13 +105,8 @@ def slider_2_handler(state):
|
||||
rgb._do_update()
|
||||
return
|
||||
|
||||
# Keyboard Brightness
|
||||
def slider_3_handler(state):
|
||||
rgb = None
|
||||
for ext in keyboard.extensions:
|
||||
if type(ext) is RGB:
|
||||
rgb = ext
|
||||
break
|
||||
def set_led_brightness(state):
|
||||
rgb = get_kb_rgb_obj(keyboard)
|
||||
if rgb is None:
|
||||
return
|
||||
|
||||
@ -108,6 +114,24 @@ def slider_3_handler(state):
|
||||
rgb._do_update()
|
||||
return
|
||||
|
||||
def slider_1_handler(state):
|
||||
set_sys_vol(state)
|
||||
|
||||
def slider_2_handler(state):
|
||||
if keyboard.active_layers[0] == MIDI_LAYER_IDX:
|
||||
# use as MIDI Pitch wheel
|
||||
key = KC.MIDI_PB( int(state['position'] / 16383) ) # 8192 midpoint for no bend
|
||||
keyboard.tap_key(key)
|
||||
else:
|
||||
set_led_var(state)
|
||||
|
||||
def slider_3_handler(state):
|
||||
if keyboard.active_layers[0] == MIDI_LAYER_IDX:
|
||||
# use as MIDI note velocity
|
||||
keyboard.__midi_velocity = int(state['position'] / 127)
|
||||
else:
|
||||
set_led_brightness(state)
|
||||
|
||||
faders = PotentiometerHandler()
|
||||
faders.pins = (
|
||||
(board.RV1, slider_1_handler, False),
|
||||
@ -116,6 +140,8 @@ faders.pins = (
|
||||
)
|
||||
keyboard.modules.append(faders)
|
||||
|
||||
def MN(note : str):
|
||||
return KC.MIDI_NOTE(note, keyboard.__midi_velocity)
|
||||
|
||||
keyboard.keymap = [
|
||||
[ # Base Layer
|
||||
@ -151,10 +177,10 @@ keyboard.keymap = [
|
||||
],
|
||||
|
||||
[ # MIDI Layer
|
||||
MIDI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
MIDI, MN('E3'), MN('F#3'),MN('G#3'),MN('A#3'),XXXXXXX, MN('C#4'),MN('D#4'),XXXXXXX, MN('F#4'),MN('G#4'),MN('A#4'),MN('C5'),MN('C#5'), _______, _______,
|
||||
_______, MN('F3'), MN('G3'), MN('A3'), MN('B3'), MN('C4'), MN('D4'), MN('E4'), MN('F4'), MN('G4'), MN('A4'), MN('B4'), _______, _______,
|
||||
_______, XXXXXXX, MN('C#2'),MN('D32'),XXXXXXX, MN('F#2'),MN('G#2'),MN('A#2'),XXXXXXX, MN('C#3'),MN('D#3'),XXXXXXX, _______, _______, _______,
|
||||
_______, MN('B1'), MN('C2'), MN('D2'), MN('E2'), MN('F2'), MN('G2'), MN('A2'), MN('B2'), MN('C3'), MN('D3'), MN('E3'), _______, _______,
|
||||
XXXXXXX, _______, _______, _______, _______, _______, _______, XXXXXXX, _______, _______, _______,
|
||||
],
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user