summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-06-28 18:09:09 +0200
committerBad Diode <bd@badd10de.dev>2023-06-28 18:09:09 +0200
commit9bce3c39f535edcc4cd7cc830824f6806e3de98b (patch)
treecc17e91e047107ba897d62478d1b756ddb817431
parent5bafdd1511d37373022f809cfc2a0589a1d8de38 (diff)
downloadlaunchpad-polymaker-9bce3c39f535edcc4cd7cc830824f6806e3de98b.tar.gz
launchpad-polymaker-9bce3c39f535edcc4cd7cc830824f6806e3de98b.zip
Add velocity sensitivity control
-rw-r--r--src/app.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/app.c b/src/app.c
index 0c3806b..de3d796 100644
--- a/src/app.c
+++ b/src/app.c
@@ -32,6 +32,8 @@
32 32
33#include "app.h" 33#include "app.h"
34 34
35#define LERP(x, y0, y1) ((float)y0 + (float)x * ((float)y1 - (float)y0))
36
35// Font. 37// Font.
36u16 font_numbers[10] = { 38u16 font_numbers[10] = {
37 /* 39 /*
@@ -150,6 +152,7 @@ typedef enum Button {
150 POLY_PAD_DEVICE = POLY_TOP_ROW + 6, 152 POLY_PAD_DEVICE = POLY_TOP_ROW + 6,
151 POLY_PAD_USER = POLY_TOP_ROW + 7, 153 POLY_PAD_USER = POLY_TOP_ROW + 7,
152 POLY_PAD_ACTIVE = 11, 154 POLY_PAD_ACTIVE = 11,
155 POLY_PAD_KBD_SENS = 11 + 6,
153 POLY_PAD_STEAL = 11 + 7, 156 POLY_PAD_STEAL = 11 + 7,
154 POLY_PAD_MIN_CH_0 = POLY_PAD_ROW_0 + 0, 157 POLY_PAD_MIN_CH_0 = POLY_PAD_ROW_0 + 0,
155 POLY_PAD_MIN_CH_1 = POLY_PAD_ROW_0 + 1, 158 POLY_PAD_MIN_CH_1 = POLY_PAD_ROW_0 + 1,
@@ -214,6 +217,13 @@ typedef enum Stealing {
214 POLY_STEAL_LOW = 3, 217 POLY_STEAL_LOW = 3,
215} Stealing; 218} Stealing;
216 219
220typedef enum Sensitivity {
221 SENS_NO = 0,
222 SENS_LOW = 1,
223 SENS_MED = 2,
224 SENS_HIGH = 3,
225} Sensitivity;
226
217typedef struct Color { 227typedef struct Color {
218 int r; 228 int r;
219 int g; 229 int g;
@@ -259,6 +269,7 @@ typedef struct State {
259 // Keyboard. 269 // Keyboard.
260 u8 kbd_octave; 270 u8 kbd_octave;
261 u8 kbd_root; 271 u8 kbd_root;
272 Sensitivity kbd_sense;
262} State; 273} State;
263 274
264// Globals. 275// Globals.
@@ -299,9 +310,18 @@ poly_active_toggle(void) {
299} 310}
300 311
301void 312void
313poly_kbd_sens_cycle(void) {
314 poly_stop_all();
315 state.kbd_sense++;
316 if (state.kbd_sense > SENS_HIGH) {
317 state.kbd_sense = SENS_NO;
318 }
319}
320
321void
302poly_steal_cycle(void) { 322poly_steal_cycle(void) {
303 poly_stop_all(); 323 poly_stop_all();
304 state.stealing += 1; 324 state.stealing++;
305 if (state.stealing > POLY_STEAL_LOW) { 325 if (state.stealing > POLY_STEAL_LOW) {
306 state.stealing = POLY_STEAL_OFF; 326 state.stealing = POLY_STEAL_OFF;
307 } 327 }
@@ -483,6 +503,7 @@ app_surface_event(u8 type, u8 index, u8 value) {
483 // Handle active toggle. 503 // Handle active toggle.
484 case POLY_PAD_ACTIVE: { poly_active_toggle(); } break; 504 case POLY_PAD_ACTIVE: { poly_active_toggle(); } break;
485 case POLY_PAD_STEAL: { poly_steal_cycle(); } break; 505 case POLY_PAD_STEAL: { poly_steal_cycle(); } break;
506 case POLY_PAD_KBD_SENS: { poly_kbd_sens_cycle(); } break;
486 default: break; 507 default: break;
487 } 508 }
488 } 509 }
@@ -516,15 +537,29 @@ app_surface_event(u8 type, u8 index, u8 value) {
516 return; 537 return;
517 } 538 }
518 u8 channel = 0; 539 u8 channel = 0;
519 // TODO: Velocity on/off/curve configuration.
520 // TODO: Aftertouch? 540 // TODO: Aftertouch?
521 // TODO: Per KBD channel selection. 541 // TODO: Per KBD channel selection.
522 int note = kbd_find_note(index); 542 int note = kbd_find_note(index);
523 if (note == -1) { 543 if (note == -1) {
524 return; 544 return;
525 } 545 }
526
527 if (value) { 546 if (value) {
547 float vel = value;
548 switch (state.kbd_sense) {
549 case SENS_NO: { value = 100; } break;
550 case SENS_LOW: {
551 vel = LERP(vel / 127, 55, 105);
552 value = vel;
553 } break;
554 case SENS_MED: {
555 vel = LERP(vel / 127, 40, 110);
556 value = vel;
557 } break;
558 case SENS_HIGH: {
559 vel = LERP(vel / 127, 20, 120);
560 value = vel;
561 } break;
562 }
528 app_midi_event(USBSTANDALONE, NOTEON | channel, note, value); 563 app_midi_event(USBSTANDALONE, NOTEON | channel, note, value);
529 } else { 564 } else {
530 app_midi_event(USBSTANDALONE, NOTEOFF | channel, note, value); 565 app_midi_event(USBSTANDALONE, NOTEOFF | channel, note, value);
@@ -751,6 +786,16 @@ draw_poly_steal_button(void) {
751} 786}
752 787
753void 788void
789draw_poly_kbd_sens_button(void) {
790 switch (state.kbd_sense) {
791 case SENS_NO: { DRAW(POLY_PAD_KBD_SENS, RED); } break;
792 case SENS_LOW: { DRAW(POLY_PAD_KBD_SENS, CYAN); } break;
793 case SENS_MED: { DRAW(POLY_PAD_KBD_SENS, ORANGE); } break;
794 case SENS_HIGH: { DRAW(POLY_PAD_KBD_SENS, PURPLE); } break;
795 }
796}
797
798void
754draw_poly_main(void) { 799draw_poly_main(void) {
755 DRAW(POLY_PAD_SESSION, GREY); 800 DRAW(POLY_PAD_SESSION, GREY);
756 print_number((n_voices / 10) % 10, WHITE, 0, 0); 801 print_number((n_voices / 10) % 10, WHITE, 0, 0);
@@ -827,6 +872,7 @@ draw_poly_setup(void) {
827 draw_max_channel(); 872 draw_max_channel();
828 draw_sel_channel(); 873 draw_sel_channel();
829 draw_poly_steal_button(); 874 draw_poly_steal_button();
875 draw_poly_kbd_sens_button();
830 draw_poly_active_button(); 876 draw_poly_active_button();
831} 877}
832 878
@@ -904,6 +950,7 @@ app_init(const u16 *adc_raw) {
904 .mode = MOD_POLY_MAIN, 950 .mode = MOD_POLY_MAIN,
905 .kbd_octave = 0, 951 .kbd_octave = 0,
906 .kbd_root = 0, 952 .kbd_root = 0,
953 .kbd_sense = SENS_MED,
907 }; 954 };
908 } 955 }
909 956