From c81be0cee7e7a6c4a9f4d7bc65c3ae5f37c7f59d Mon Sep 17 00:00:00 2001 From: Jonne Kokkonen Date: Thu, 18 Apr 2024 09:03:40 +0300 Subject: [PATCH] update RPM spec, cleanup and libusb logging tweaks --- package/rpm/m8c.spec | 2 +- src/command.c | 1 - src/inprint2.c | 9 +++++---- src/main.c | 2 +- src/serial.c | 2 +- src/usb.c | 26 ++++++++++++++++---------- src/usb_audio.c | 30 +++++++++++++++++------------- 7 files changed, 41 insertions(+), 31 deletions(-) diff --git a/package/rpm/m8c.spec b/package/rpm/m8c.spec index 7b36172..90d6a83 100644 --- 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 diff --git a/src/command.c b/src/command.c index 4bdf424..3308e99 100644 --- a/src/command.c +++ b/src/command.c @@ -58,7 +58,6 @@ int process_command(uint8_t *data, uint32_t size) { {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; } diff --git a/src/inprint2.c b/src/inprint2.c index d29a7c2..58c4359 100644 --- 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 @@ void infont(SDL_Texture *font) { int w, h; if (font == NULL) { - // prepare_inline_font(); return; } @@ -90,14 +93,12 @@ void inprint(SDL_Renderer *dst, const char *str, Uint32 x, Uint32 y, 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; diff --git a/src/main.c b/src/main.c index 52385e4..295f7ec 100644 --- 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 #include diff --git a/src/serial.c b/src/serial.c index 55ce1e2..5e783aa 100644 --- a/src/serial.c +++ b/src/serial.c @@ -48,7 +48,7 @@ int list_devices() { 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)); } } diff --git a/src/usb.c b/src/usb.c index ed2b41f..8d63a75 100644 --- a/src/usb.c +++ b/src/usb.c @@ -47,7 +47,7 @@ int list_devices() { } 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 @@ static void LIBUSB_CALL xfr_cb_in(struct libusb_transfer *transfer) { } 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 @@ int init_serial(int verbose, char *preferred_device) { } } 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 disconnect() { 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); diff --git a/src/usb_audio.c b/src/usb_audio.c index 4b8414f..c425afe 100644 --- a/src/usb_audio.c +++ b/src/usb_audio.c @@ -37,7 +37,7 @@ static void cb_xfr(struct libusb_transfer *xfr) { 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 @@ static void cb_xfr(struct libusb_transfer *xfr) { 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 @@ int audio_init(int audio_buffer_size, const char *output_device_name) { 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 @@ int audio_init(int audio_buffer_size, const char *output_device_name) { 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_init(int audio_buffer_size, const char *output_device_name) { } 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 @@ int audio_destroy() { 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 @@ int audio_destroy() { SDL_CloseAudioDevice(device); } - SDL_Log("Audio closed"); + SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Audio closed"); ring_buffer_free(audio_buffer); return 1;