ref: 143454cc8f00abe1652d0aba1582a99c6166e11c
parent: 78bcd02e1c155026c74ab4dce7b0f1ed3a54dba6
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Fri Mar 28 05:36:50 EDT 2025
Implement input logging, fix keyjazz handling, and debug RTMIDI backend Improved logging by adding debug messages for controller and keyjazz inputs. Added special cases for keyjazz note off handling. Updated MIDI functions to reflect unimplemented status with error logs and minor refactors for better readability and safety.
--- a/src/backends/m8_libserialport.c
+++ b/src/backends/m8_libserialport.c
@@ -238,6 +238,7 @@
}
int m8_send_msg_controller(const uint8_t input) {+ SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Sending controller input %d", input);
const unsigned char buf[2] = {'C', input};const size_t nbytes = 2;
const int result = sp_blocking_write(m8_port, buf, nbytes, 5);
@@ -249,8 +250,26 @@
}
int m8_send_msg_keyjazz(const uint8_t note, uint8_t velocity) {+
+ // Cap velocity to 7bits
if (velocity > 0x7F)
velocity = 0x7F;
+
+ // Special case for note off
+ if (note == 0xFF && velocity == 0x00) {+ SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Sending keyjazz note off");
+ const unsigned char buf[2] = {'K', 0xFF};+ const size_t nbytes = 2;
+ const int result = sp_blocking_write(m8_port, buf, nbytes, 5);
+ if (result != nbytes) {+ SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error sending keyjazz, code %d", result);
+ return -1;
+ }
+ return 1;
+ }
+
+ // Regular note on message
+ SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Sending keyjazz note %d, velocity %d", note, velocity);
const unsigned char buf[3] = {'K', note, velocity};const size_t nbytes = 3;
const int result = sp_blocking_write(m8_port, buf, nbytes, 5);
--- a/src/backends/m8_rtmidi.c
+++ b/src/backends/m8_rtmidi.c
@@ -216,7 +216,13 @@
}
int m8_send_msg_controller(const unsigned char input) {- const unsigned char input_sysex[9] = {0xF0, 0x00, 0x02, 0x61, 0x00, 0x00, 'C', input, 0xF7};+ SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "MIDI key inputs not implemented yet");
+ return 0;
+#if 0
+ SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Sending controller input 0x%02X", input);
+ // Encode a 8bit byte to two 7-bit bytes
+ //const unsigned char sysex_encoded_input[2] = {input & 0x7F, (input >> 7) & 0x01};+ const unsigned char input_sysex[10] = {0xF0, 0x00, 0x02, 0x61, 0x00, 0x00, 'C', sysex_encoded_input[0], sysex_encoded_input[1], 0xF7};const int result = rtmidi_out_send_message(midi_out, &input_sysex[0], sizeof(input_sysex));
if (result != 0) {SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Failed to send key input message");
@@ -223,12 +229,29 @@
return 0;
}
return 1;
+#endif
}
int m8_send_msg_keyjazz(const unsigned char note, unsigned char velocity) {+ SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "MIDI keyjazz not implemented yet");
+ return 0;
+#if 0
if (velocity > 0x7F) {velocity = 0x7F;
}
+
+ // Special case for note off
+ if (note == 0xFF && velocity == 0x00) {+ const unsigned char all_notes_off_sysex[9] = {0xF0, 0x00, 0x02, 0x61, 0x00, 0x00, 'K', 0xFF, 0xF7};+ const int result =
+ rtmidi_out_send_message(midi_out, &all_notes_off_sysex[0], sizeof(all_notes_off_sysex));
+ if (result != 0) {+ SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Failed to send all notes off");
+ return 0;
+ }
+ return 1;
+ }
+
const unsigned char keyjazz_sysex[10] = {0xF0, 0x00, 0x02, 0x61, 0x00,0x00, 'K', note, velocity, 0xF7};
const int result = rtmidi_out_send_message(midi_out, &keyjazz_sysex[0], sizeof(keyjazz_sysex));
@@ -237,9 +260,10 @@
return 0;
}
return 1;
+#endif
}
-int m8_process_data(config_params_s conf) {+int m8_process_data(const config_params_s *conf) {static unsigned int empty_cycles = 0;
@@ -253,7 +277,7 @@
}
} else {empty_cycles++;
- if (empty_cycles >= conf.wait_packets) {+ if (empty_cycles >= conf->wait_packets) { SDL_Log("No messages received for %d cycles, assuming device disconnected", empty_cycles);close_and_free_midi_ports();
return 0;
--- a/src/input.c
+++ b/src/input.c
@@ -145,6 +145,7 @@
if (note_value >= 0) {key.value = note_value;
return key;
+
}
// Not a note key, handle other settings
--
⑨