Skip to content

Commit

Permalink
update RPM spec, cleanup and libusb logging tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
laamaa committed Apr 18, 2024
1 parent 95591f0 commit c81be0c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package/rpm/m8c.spec
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/inprint2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +58,6 @@ void infont(SDL_Texture *font) {
int w, h;

if (font == NULL) {
// prepare_inline_font();
return;
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 17 additions & 13 deletions src/usb_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -160,22 +160,26 @@ 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));
}
}

SDL_Log("Freeing interface %d", IFACE_NUM);

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;
}

Expand All @@ -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;
Expand Down

0 comments on commit c81be0c

Please sign in to comment.