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

Change MIDI velocity implementation to allow direct control of velocity value #9940

Merged
merged 7 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 17 additions & 6 deletions quantum/process_keycode/process_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 /
void midi_init(void) {
midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN;
midi_config.transpose = 0;
midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN);
midi_config.velocity = (compute_velocity(MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN));
midi_config.channel = 0;
midi_config.modulation_interval = 8;

Expand All @@ -66,7 +66,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) {
case MIDI_TONE_MIN ... MIDI_TONE_MAX: {
uint8_t channel = midi_config.channel;
uint8_t tone = keycode - MIDI_TONE_MIN;
uint8_t velocity = compute_velocity(midi_config.velocity);
uint8_t velocity = midi_config.velocity;
if (record->event.pressed) {
uint8_t note = midi_compute_note(keycode);
midi_send_noteon(&midi_device, channel, note, velocity);
Expand Down Expand Up @@ -122,19 +122,30 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) {
return false;
case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX:
if (record->event.pressed) {
midi_config.velocity = keycode - MIDI_VELOCITY_MIN;
midi_config.velocity = compute_velocity(keycode - MIDI_VELOCITY_MIN);
dprintf("midi velocity %d\n", midi_config.velocity);
}
return false;
case MI_VELD:
if (record->event.pressed && midi_config.velocity > 0) {
midi_config.velocity--;
if (midi_config.velocity > 12 ) {
jakobkg marked this conversation as resolved.
Show resolved Hide resolved
midi_config.velocity -= 13;
}
else {
jakobkg marked this conversation as resolved.
Show resolved Hide resolved
midi_config.velocity = 0;
}

dprintf("midi velocity %d\n", midi_config.velocity);
}
return false;
case MI_VELU:
if (record->event.pressed) {
midi_config.velocity++;
if (record->event.pressed && midi_config.velocity < 127) {
if (midi_config.velocity < 115 ) {
jakobkg marked this conversation as resolved.
Show resolved Hide resolved
midi_config.velocity += 13;
}
else {
jakobkg marked this conversation as resolved.
Show resolved Hide resolved
midi_config.velocity = 127;
}
dprintf("midi velocity %d\n", midi_config.velocity);
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion quantum/process_keycode/process_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef union {
struct {
uint8_t octave : 4;
int8_t transpose : 4;
uint8_t velocity : 4;
uint8_t velocity;
drashna marked this conversation as resolved.
Show resolved Hide resolved
uint8_t channel : 4;
uint8_t modulation_interval : 4;
};
Expand Down