@@ -96,8 +96,14 @@ class NeuralRack : public TextEntry
9696 ui->win ->parent_struct = ui;
9797 ui->win ->private_struct = (void *)this ;
9898 ui->win ->scale .gravity = NORTHWEST;
99+ ui->win ->func .key_press_callback = get_key;
99100 plugin_create_controller_widgets (ui," standalone" );
100101
102+ for (int i = 0 ; i < GUI_ELEMENTS; i++) {
103+ ui->elem [i]->private_struct = (void *)this ;
104+ ui->elem [i]->func .key_press_callback = get_key;
105+ }
106+
101107 EngineMenu = menubar_add_menu (Menu, " Engine" );
102108 #if defined(HAVE_PA)
103109 #if defined(_WIN32)
@@ -493,6 +499,41 @@ class NeuralRack : public TextEntry
493499 }
494500 }
495501
502+ static void get_key (void *w_, void *key_, void *user_data) {
503+ Widget_t *w = (Widget_t*)w_;
504+ if (!w) return ;
505+ NeuralRack *self = static_cast <NeuralRack*>(w->private_struct );
506+ XKeyEvent *key = (XKeyEvent*)key_;
507+ if (!key) return ;
508+ char buf[32 ];
509+ memset (buf, 0 , 32 );
510+ bool status = os_get_keyboard_input (w, key, buf, sizeof (buf) - 1 );
511+ // numpad key's didn't support shift mask so let's check them separate
512+ bool isNumPad = (key->keycode >= 79 && key->keycode <= 90 ) ? true : false ;
513+ // fprintf(stderr, "%d %s\n", key->keycode, buf);
514+ if ((status || isNumPad) && (key->state & ShiftMask || std::isdigit (buf[0 ]))){
515+ int v = key->keycode ;
516+ // numpad keycode to num
517+ if (v == 79 ) v = 7 ;
518+ else if (v == 80 ) v = 8 ;
519+ else if (v == 81 ) v = 9 ;
520+ else if (v == 83 ) v = 4 ;
521+ else if (v == 84 ) v = 5 ;
522+ else if (v == 85 ) v = 6 ;
523+ else if (v == 87 ) v = 1 ;
524+ else if (v == 88 ) v = 2 ;
525+ else if (v == 89 ) v = 3 ;
526+ else if (v == 90 ) v = 0 ;
527+ else v -= 9 ;
528+ if (v > 9 ) v = 0 ;
529+ if (key->state & ShiftMask) {
530+ v += 10 ;
531+ }
532+ // fprintf(stderr, "load %i\n", v);
533+ self->loadPreset (v);
534+ }
535+ }
536+
496537 static void draw_menubar (void *w_, void * user_data) noexcept {
497538 Widget_t *w = (Widget_t*)w_;
498539 Metrics_t metrics;
0 commit comments