shithub: m8c

Download patch

ref: c81be0cee7e7a6c4a9f4d7bc65c3ae5f37c7f59d
parent: 95591f047b35ec0340196382767dfc922ad68c58
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Thu Apr 18 05:03:40 EDT 2024

update RPM spec, cleanup and libusb logging tweaks

--- a/package/rpm/m8c.spec
+++ b/package/rpm/m8c.spec
@@ -1,5 +1,5 @@
 Name:           m8c
-Version:        1.6.0
+Version:        1.7.0
 Release:        1%{?dist}
 Summary:        m8c is a client for Dirtywave M8 music tracker's headless mode
 
--- a/src/command.c
+++ b/src/command.c
@@ -58,7 +58,6 @@
           {decodeInt16(recv_buf, 5), decodeInt16(recv_buf, 7)}, // size w/h
           {recv_buf[9], recv_buf[10], recv_buf[11]}};           // color r/g/b
 
-      //SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"x:%i, y:%i, w:%i, h:%i",rectcmd.pos.x,rectcmd.pos.y,rectcmd.size.width,rectcmd.size.height);
       draw_rectangle(&rectcmd);
       return 1;
     }
--- a/src/inprint2.c
+++ b/src/inprint2.c
@@ -8,6 +8,10 @@
 #define CHARACTERS_PER_ROW 94
 #define CHARACTERS_PER_COLUMN 1
 
+// Offset for seeking from limited character sets
+static const int font_offset =
+    127 - (CHARACTERS_PER_ROW * CHARACTERS_PER_COLUMN);
+
 static SDL_Renderer *selected_renderer = NULL;
 static SDL_Texture *inline_font = NULL;
 static SDL_Texture *selected_font = NULL;
@@ -54,7 +58,6 @@
   int w, h;
 
   if (font == NULL) {
-    // prepare_inline_font();
     return;
   }
 
@@ -90,14 +93,12 @@
   s_rect.h = selected_font_h / CHARACTERS_PER_COLUMN;
   d_rect.w = s_rect.w;
   d_rect.h = s_rect.h;
-  // d_rect.w = selected_inline_font->glyph_x;
-  // d_rect.h = selected_inline_font->glyph_y;
 
   if (dst == NULL)
     dst = selected_renderer;
 
   for (; *str; str++) {
-    int id = (int)*str - 33;
+    int id = (int)*str - font_offset;
 #if (CHARACTERS_PER_COLUMN != 1)
     int row = id / CHARACTERS_PER_ROW;
     int col = id % CHARACTERS_PER_ROW;
--- a/src/main.c
+++ b/src/main.c
@@ -3,7 +3,7 @@
 
 /* Uncomment this line to enable debug messages or call make with `make
    CFLAGS=-DDEBUG_MSG` */
-#define DEBUG_MSG
+// #define DEBUG_MSG
 
 #include <SDL.h>
 #include <signal.h>
--- a/src/serial.c
+++ b/src/serial.c
@@ -48,7 +48,7 @@
     struct sp_port *port = port_list[i];
 
     if (detect_m8_serial_device(port)) {
-      printf("Found M8 device: %s", sp_get_port_name(port));
+      SDL_Log("Found M8 device: %s", sp_get_port_name(port));
     }
   }
 
--- a/src/usb.c
+++ b/src/usb.c
@@ -47,7 +47,7 @@
     }
 
     if (desc.idVendor == M8_VID && desc.idProduct == M8_PID) {
-      printf("Found M8 device: %d:%d\n", libusb_get_port_number(device), libusb_get_bus_number(device));
+      SDL_Log("Found M8 device: %d:%d\n", libusb_get_port_number(device), libusb_get_bus_number(device));
     }
   }
   libusb_free_device_list(device_list, 1);
@@ -74,6 +74,10 @@
 }
 
 int bulk_transfer(int endpoint, uint8_t *serial_buf, int count, unsigned int timeout_ms) {
+  if (devh == NULL) {
+    return -1;
+  }
+  
   int completed = 0;
 
   struct libusb_transfer *transfer;
@@ -252,7 +256,7 @@
     }
   }
   if (devh == NULL) {
-    SDL_Log("libusb_open_device_with_vid_pid returned invalid handle");
+    SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "libusb_open_device_with_vid_pid returned invalid handle");
     return 0;
   }
   SDL_Log("USB device init success");
@@ -310,18 +314,20 @@
 
   int rc;
 
-  for (int if_num = 0; if_num < 2; if_num++) {
-    rc = libusb_release_interface(devh, if_num);
-    if (rc < 0) {
-      SDL_Log("Error releasing interface: %s", libusb_error_name(rc));
-      return 0;
+  if (devh != NULL) {
+    
+    for (int if_num = 0; if_num < 2; if_num++) {
+      rc = libusb_release_interface(devh, if_num);
+      if (rc < 0) {
+        SDL_Log("Error releasing interface: %s", libusb_error_name(rc));
+        return 0;
+      }
     }
-  }
 
-  do_exit = 1;
+    do_exit = 1;
 
-  if (devh != NULL) {
     libusb_close(devh);
+
   }
 
   SDL_WaitThread(usb_thread, NULL);
--- a/src/usb_audio.c
+++ b/src/usb_audio.c
@@ -37,7 +37,7 @@
     struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i];
 
     if (pack->status != LIBUSB_TRANSFER_COMPLETED) {
-      SDL_Log("XFR callback error (status %d: %s)", pack->status,
+      SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "XFR callback error (status %d: %s)", pack->status,
               libusb_error_name(pack->status));
       /* This doesn't happen, so bail out if it does. */
       return;
@@ -47,13 +47,13 @@
     if (sdl_audio_device_id != 0) {
       uint32_t actual = ring_buffer_push(audio_buffer, data, pack->actual_length);
       if (actual == -1) {
-        SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Buffer overflow!");
+        SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Buffer overflow!");
       }
     }
   }
 
   if (libusb_submit_transfer(xfr) < 0) {
-    SDL_Log("error re-submitting URB\n");
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "error re-submitting URB\n");
     SDL_free(xfr->buffer);
   }
 }
@@ -100,23 +100,23 @@
 
   rc = libusb_claim_interface(devh, IFACE_NUM);
   if (rc < 0) {
-    SDL_Log("Error claiming interface: %s\n", libusb_error_name(rc));
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error claiming interface: %s\n", libusb_error_name(rc));
     return rc;
   }
 
   rc = libusb_set_interface_alt_setting(devh, IFACE_NUM, 1);
   if (rc < 0) {
-    SDL_Log("Error setting alt setting: %s\n", libusb_error_name(rc));
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error setting alt setting: %s\n", libusb_error_name(rc));
     return rc;
   }
 
   if (!SDL_WasInit(SDL_INIT_AUDIO)) {
     if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
-      SDL_Log("Init audio failed %s", SDL_GetError());
+      SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Init audio failed %s", SDL_GetError());
       return -1;
     }
   } else {
-    SDL_Log("Audio was already initialised");
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Audio was already initialised");
   }
 
   static SDL_AudioSpec audio_spec;
@@ -149,9 +149,9 @@
   SDL_PauseAudioDevice(sdl_audio_device_id, 0);
 
   // Good to go
-  SDL_Log("Starting capture");
+  SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Starting capture");
   if ((rc = benchmark_in()) < 0) {
-    SDL_Log("Capture failed to start: %d", rc);
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Capture failed to start: %d", rc);
     return rc;
   }
 
@@ -160,14 +160,18 @@
 }
 
 int audio_destroy() {
-  SDL_Log("Closing audio");
+  if (devh == NULL) {
+    return -1;
+  }
 
+  SDL_LogDebug(SDL_LOG_CATEGORY_AUDIO, "Closing audio");
+
   int i, rc;
 
   for (i = 0; i < NUM_TRANSFERS; i++) {
     rc = libusb_cancel_transfer(xfr[i]);
     if (rc < 0) {
-      SDL_Log("Error cancelling transfer: %s\n", libusb_error_name(rc));
+      SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error cancelling transfer: %s\n", libusb_error_name(rc));
     }
   }
 
@@ -175,7 +179,7 @@
 
   rc = libusb_release_interface(devh, IFACE_NUM);
   if (rc < 0) {
-    SDL_Log("Error releasing interface: %s\n", libusb_error_name(rc));
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error releasing interface: %s\n", libusb_error_name(rc));
     return rc;
   }
 
@@ -186,7 +190,7 @@
     SDL_CloseAudioDevice(device);
   }
 
-  SDL_Log("Audio closed");
+  SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Audio closed");
 
   ring_buffer_free(audio_buffer);
   return 1;
--