shithub: m8c

Download patch

ref: 46775e49af8cbca8cc49c23baa546fce9ad87b7a
parent: 3dd55d91838f71eccaa80e06a7006e5ff5925081
author: laamaa <jonne.kokkonen@gmail.com>
date: Tue Sep 16 20:06:16 EDT 2025

fix keyjazz velocity adjustment logic (fixes #208), correct scancode assignments, and add delay for M8 display initialization with libserialport

--- a/src/backends/m8_libserialport.c
+++ b/src/backends/m8_libserialport.c
@@ -345,12 +345,15 @@
 int m8_enable_display(const unsigned char reset_display) {
   SDL_Log("Enabling and resetting M8 display");
 
-  const char buf[1] = {'E'};
-  int result = sp_blocking_write(m8_port, buf, 1, 5);
+  const char buf_enable[1] = {'E'};
+  int result = sp_blocking_write(m8_port, buf_enable, 1, 5);
   if (result != 1) {
     SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error enabling M8 display, code %d", result);
     return 0;
   }
+
+  // Wait for things to warm up
+  SDL_Delay(500);
 
   if (reset_display) {
     result = m8_reset_display();
--- a/src/config.c
+++ b/src/config.c
@@ -51,8 +51,8 @@
   c.key_reset = SDL_SCANCODE_R;
   c.key_jazz_inc_octave = SDL_SCANCODE_KP_MULTIPLY;
   c.key_jazz_dec_octave = SDL_SCANCODE_KP_DIVIDE;
-  c.key_jazz_inc_velocity = SDL_SCANCODE_KP_MINUS;
-  c.key_jazz_dec_velocity = SDL_SCANCODE_KP_PLUS;
+  c.key_jazz_inc_velocity = SDL_SCANCODE_KP_PLUS;
+  c.key_jazz_dec_velocity = SDL_SCANCODE_KP_MINUS;
   c.key_toggle_audio = SDL_SCANCODE_F12;
   c.key_toggle_log = SDL_SCANCODE_F2;
 
--- a/src/input.c
+++ b/src/input.c
@@ -85,13 +85,18 @@
     if (keyjazz_velocity > (is_fine_adjustment ? KEYJAZZ_MIN_VELOCITY + step : step)) {
       keyjazz_velocity -= step;
       display_keyjazz_overlay(1, keyjazz_base_octave, keyjazz_velocity);
+    } else if (keyjazz_velocity - step < KEYJAZZ_MIN_VELOCITY) {
+      keyjazz_velocity = KEYJAZZ_MIN_VELOCITY;
+      display_keyjazz_overlay(1, keyjazz_base_octave, keyjazz_velocity);
     }
   } else if (scancode == conf->key_jazz_inc_velocity) {
     const int step = is_fine_adjustment ? KEYJAZZ_FINE_VELOCITY_STEP : KEYJAZZ_COARSE_VELOCITY_STEP;
-    const int max = is_fine_adjustment ? KEYJAZZ_MAX_VELOCITY : (KEYJAZZ_MAX_VELOCITY - step);
-    if (keyjazz_velocity < max) {
+    if (keyjazz_velocity <= (KEYJAZZ_MAX_VELOCITY - step)) {
       keyjazz_velocity += step;
       display_keyjazz_overlay(1, keyjazz_base_octave, keyjazz_velocity);
+    } else if (keyjazz_velocity + step >= KEYJAZZ_MAX_VELOCITY) {
+      keyjazz_velocity = KEYJAZZ_MAX_VELOCITY;
+      display_keyjazz_overlay(1, keyjazz_base_octave, keyjazz_velocity);
     }
   }
 }
@@ -103,7 +108,6 @@
   // Check if this is a note key
   const int note_value = get_note_for_scancode(event->key.scancode);
   if (note_value >= 0) {
-    SDL_Log("vel %d", keyjazz_velocity);
     key.value = note_value;
     return key;
   }
--