* Change some variable naming conventions

* Make return control paths less dependent on variables
This commit is contained in:
libretroadmin 2025-07-11 02:15:12 +02:00
parent bca5cafaa6
commit 2dbb9f62d8
9 changed files with 220 additions and 178 deletions

View File

@ -288,6 +288,7 @@ int alsa_init_pcm(snd_pcm_t **pcm,
snd_pcm_name(*pcm)); snd_pcm_name(*pcm));
return 0; return 0;
error: error:
if (params) if (params)
snd_pcm_hw_params_free(params); snd_pcm_hw_params_free(params);

View File

@ -118,19 +118,14 @@ static const char *wave_format_name(const WAVEFORMATEXTENSIBLE *format)
const char* wasapi_error(DWORD error) const char* wasapi_error(DWORD error)
{ {
static char error_message[256]; static char s[256];
FormatMessage( FormatMessage(
FORMAT_MESSAGE_IGNORE_INSERTS FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_FROM_SYSTEM, | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, NULL, error,
error,
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
error_message, s, sizeof(s) - 1, NULL);
sizeof(error_message) - 1, return s;
NULL);
return error_message;
} }
static const char* wasapi_data_flow_name(EDataFlow data_flow) static const char* wasapi_data_flow_name(EDataFlow data_flow)

View File

@ -1922,19 +1922,6 @@ static int pcm_avail_update(struct pcm *pcm)
return pcm_mmap_avail(pcm); return pcm_mmap_avail(pcm);
} }
#if 0
/* No longer used */
static int pcm_state(struct pcm *pcm)
{
int err = pcm_sync_ptr(pcm, 0);
if (err < 0)
return err;
return pcm->mmap_status->state;
}
#endif
/** Waits for frames to be available for read or write operations. /** Waits for frames to be available for read or write operations.
* @param pcm A PCM handle. * @param pcm A PCM handle.
* @param timeout The maximum amount of time to wait for, in terms of milliseconds. * @param timeout The maximum amount of time to wait for, in terms of milliseconds.

View File

@ -631,16 +631,17 @@ static bool win32_drag_query_file(HWND hwnd, WPARAM wparam)
if (DragQueryFileW((HDROP)wparam, 0xFFFFFFFF, NULL, 0)) if (DragQueryFileW((HDROP)wparam, 0xFFFFFFFF, NULL, 0))
{ {
wchar_t wszFilename[4096]; wchar_t wszFilename[4096];
bool okay = false; bool ret = false;
char *szFilename = NULL; char *szFilename = NULL;
wszFilename[0] = L'\0'; wszFilename[0] = L'\0';
DragQueryFileW((HDROP)wparam, 0, wszFilename, sizeof(wszFilename)); DragQueryFileW((HDROP)wparam, 0, wszFilename, sizeof(wszFilename));
szFilename = utf16_to_utf8_string_alloc(wszFilename); szFilename = utf16_to_utf8_string_alloc(wszFilename);
okay = win32_load_content_from_gui(szFilename); ret = win32_load_content_from_gui(szFilename);
if (szFilename) if (szFilename)
free(szFilename); free(szFilename);
return okay; if (ret)
return true;
} }
return false; return false;
} }

View File

@ -148,8 +148,6 @@ static void ps3_end_camera(ps3_input_t *ps3)
static int ps3_setup_camera(ps3_input_t *ps3) static int ps3_setup_camera(ps3_input_t *ps3)
{ {
int error = 0;
cameraGetType(0, &ps3->type); cameraGetType(0, &ps3->type);
if (ps3->type == CAM_TYPE_PLAYSTATION_EYE) if (ps3->type == CAM_TYPE_PLAYSTATION_EYE)
{ {
@ -163,24 +161,20 @@ static int ps3_setup_camera(ps3_input_t *ps3)
{ {
case CAMERA_ERRO_DOUBLE_OPEN: case CAMERA_ERRO_DOUBLE_OPEN:
cameraClose(0); cameraClose(0);
error = 1; return 1;
break;
case CAMERA_ERRO_NO_DEVICE_FOUND:
error = 1;
break;
case 0: case 0:
ps3->camread.buffer = ps3->camInf.buffer; ps3->camread.buffer = ps3->camInf.buffer;
ps3->camread.version = 0x0100; ps3->camread.version = 0x0100;
ps3->cam_buf = (u8 *)(u64)ps3->camread.buffer; ps3->cam_buf = (u8 *)(u64)ps3->camread.buffer;
break; break;
case CAMERA_ERRO_NO_DEVICE_FOUND:
default: default:
error = 1; return 1;
break;
} }
} }
else else
error = 1; return 1;
return error; return 0;
} }
#if 0 #if 0

View File

@ -224,7 +224,7 @@ bool nested_list_add_item(nested_list_t *list,
bool success = false; bool success = false;
if (!list || string_is_empty(address)) if (!list || string_is_empty(address))
goto end; return false;
/* If delim is NULL or address contains a single /* If delim is NULL or address contains a single
* token, then we are adding an item to the top * token, then we are adding an item to the top
@ -249,10 +249,10 @@ bool nested_list_add_item(nested_list_t *list,
} }
else else
{ {
size_t i;
nested_list_t *current_list = list; nested_list_t *current_list = list;
nested_list_item_t *parent_item = NULL; nested_list_item_t *parent_item = NULL;
nested_list_item_t *next_item = NULL; nested_list_item_t *next_item = NULL;
size_t i;
/* Loop over list item ids */ /* Loop over list item ids */
for (i = 0; i < id_list.size; i++) for (i = 0; i < id_list.size; i++)
@ -482,9 +482,9 @@ nested_list_t *nested_list_item_get_parent_list(nested_list_item_t *list_item)
*/ */
nested_list_t *nested_list_item_get_children(nested_list_item_t *list_item) nested_list_t *nested_list_item_get_children(nested_list_item_t *list_item)
{ {
if (!list_item || if ( !list_item
!list_item->children || || !list_item->children
(RBUF_LEN(list_item->children->items) < 1)) || (RBUF_LEN(list_item->children->items) < 1))
return NULL; return NULL;
return list_item->children; return list_item->children;
@ -504,7 +504,6 @@ const char *nested_list_item_get_id(nested_list_item_t *list_item)
{ {
if (!list_item) if (!list_item)
return NULL; return NULL;
return list_item->id; return list_item->id;
} }

View File

@ -1044,17 +1044,15 @@ uint8_t task_get_flags(retro_task_t *task)
char* task_get_error(retro_task_t *task) char* task_get_error(retro_task_t *task)
{ {
char *error = NULL; char *s = NULL;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
slock_lock(property_lock); slock_lock(property_lock);
#endif #endif
error = task->error; s = task->error;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
slock_unlock(property_lock); slock_unlock(property_lock);
#endif #endif
return s;
return error;
} }
int8_t task_get_progress(retro_task_t *task) int8_t task_get_progress(retro_task_t *task)

View File

@ -23,25 +23,28 @@
#define CORE_MIDI_QUEUE_SIZE 1024 #define CORE_MIDI_QUEUE_SIZE 1024
typedef struct { typedef struct
midi_event_t events[CORE_MIDI_QUEUE_SIZE]; ///< Event buffer {
int read_index; ///< Current read position midi_event_t events[CORE_MIDI_QUEUE_SIZE]; /* Event buffer */
int write_index; ///< Current write position int read_index; /* Current read position */
int write_index; /* Current write position */
} coremidi_queue_t; } coremidi_queue_t;
typedef struct { typedef struct
MIDIClientRef client; ///< CoreMIDI client {
MIDIPortRef input_port; ///< Input port for receiving MIDI data MIDIClientRef client; /* CoreMIDI client */
MIDIPortRef output_port; ///< Output port for sending MIDI data MIDIPortRef input_port; /* Input port for receiving MIDI data */
MIDIEndpointRef input_endpoint; ///< Selected input endpoint MIDIPortRef output_port; /* Output port for sending MIDI data */
MIDIEndpointRef output_endpoint; ///< Selected output endpoint MIDIEndpointRef input_endpoint; /* Selected input endpoint */
coremidi_queue_t input_queue; ///< Queue for incoming MIDI events MIDIEndpointRef output_endpoint; /* Selected output endpoint */
coremidi_queue_t input_queue; /* Queue for incoming MIDI events */
} coremidi_t; } coremidi_t;
/// Write to the queue /* Write to the queue */
static bool coremidi_queue_write(coremidi_queue_t *q, const midi_event_t *ev) { static bool coremidi_queue_write(coremidi_queue_t *q, const midi_event_t *ev)
{
int next_write = (q->write_index + 1) % CORE_MIDI_QUEUE_SIZE; int next_write = (q->write_index + 1) % CORE_MIDI_QUEUE_SIZE;
if (next_write == q->read_index) // Queue full if (next_write == q->read_index) /* Queue full */
return false; return false;
memcpy(&q->events[q->write_index], ev, sizeof(*ev)); memcpy(&q->events[q->write_index], ev, sizeof(*ev));
@ -49,31 +52,35 @@ static bool coremidi_queue_write(coremidi_queue_t *q, const midi_event_t *ev) {
return true; return true;
} }
/// MIDIReadProc callback function /* MIDIReadProc callback function */
static void midi_read_callback(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) { static void midi_read_callback(const MIDIPacketList *pktlist,
void *readProcRefCon, void *srcConnRefCon)
{
uint32_t i;
midi_event_t event;
coremidi_t *d = (coremidi_t *)readProcRefCon; coremidi_t *d = (coremidi_t *)readProcRefCon;
const MIDIPacket *packet = &pktlist->packet[0]; const MIDIPacket *packet = &pktlist->packet[0];
midi_event_t event;
uint32_t i;
for (i = 0; i < pktlist->numPackets; i++) { for (i = 0; i < pktlist->numPackets; i++)
{
const uint8_t *data = packet->data; const uint8_t *data = packet->data;
size_t length = packet->length; size_t length = packet->length;
const MIDITimeStamp timestamp = packet->timeStamp; const MIDITimeStamp timestamp = packet->timeStamp;
while (length > 0) { while (length > 0)
{
size_t msg_size = midi_driver_get_event_size(data[0]); size_t msg_size = midi_driver_get_event_size(data[0]);
if (msg_size == 0 || msg_size > length) if (msg_size == 0 || msg_size > length)
break; break;
event.data = (uint8_t *)data; event.data = (uint8_t*)data;
event.data_size = msg_size; event.data_size = msg_size;
event.delta_time = (uint32_t)timestamp; event.delta_time = (uint32_t)timestamp;
// Add to queue /* Add to queue */
coremidi_queue_write(&d->input_queue, &event); coremidi_queue_write(&d->input_queue, &event);
data += msg_size; data += msg_size;
length -= msg_size; length -= msg_size;
} }
@ -81,40 +88,53 @@ static void midi_read_callback(const MIDIPacketList *pktlist, void *readProcRefC
} }
} }
/// Initialize the CoreMIDI client and ports /* Initialize the CoreMIDI client and ports */
static void *coremidi_init(const char *input, const char *output) { static void *coremidi_init(const char *input, const char *output)
{
OSStatus err;
coremidi_t *d = (coremidi_t *)calloc(1, sizeof(coremidi_t)); coremidi_t *d = (coremidi_t *)calloc(1, sizeof(coremidi_t));
if (!d) { if (!d)
{
RARCH_ERR("[MIDI] Out of memory.\n"); RARCH_ERR("[MIDI] Out of memory.\n");
return NULL; return NULL;
} }
OSStatus err = MIDIClientCreate(CFSTR("RetroArch MIDI Client"), NULL, NULL, &d->client); err = MIDIClientCreate(CFSTR("RetroArch MIDI Client"),
if (err != noErr) { NULL, NULL, &d->client);
if (err != noErr)
{
RARCH_ERR("[MIDI] MIDIClientCreate failed: %d.\n", err); RARCH_ERR("[MIDI] MIDIClientCreate failed: %d.\n", err);
free(d); free(d);
return NULL; return NULL;
} else {
RARCH_LOG("[MIDI] CoreMIDI client created successfully.\n");
} }
// Create input port if specified RARCH_LOG("[MIDI] CoreMIDI client created successfully.\n");
if (input) {
err = MIDIInputPortCreate(d->client, CFSTR("Input Port"), midi_read_callback, d, &d->input_port); /* Create input port if specified */
if (err != noErr) { if (input)
{
err = MIDIInputPortCreate(d->client, CFSTR("Input Port"),
midi_read_callback, d, &d->input_port);
if (err != noErr)
{
RARCH_ERR("[MIDI] MIDIInputPortCreate failed: %d.\n", err); RARCH_ERR("[MIDI] MIDIInputPortCreate failed: %d.\n", err);
MIDIClientDispose(d->client); MIDIClientDispose(d->client);
free(d); free(d);
return NULL; return NULL;
} }
} else { }
else
{
RARCH_LOG("[MIDI] CoreMIDI input port created successfully.\n"); RARCH_LOG("[MIDI] CoreMIDI input port created successfully.\n");
} }
// Create output port if specified /* Create output port if specified */
if (output) { if (output)
err = MIDIOutputPortCreate(d->client, CFSTR("Output Port"), &d->output_port); {
if (err != noErr) { err = MIDIOutputPortCreate(d->client,
CFSTR("Output Port"), &d->output_port);
if (err != noErr)
{
RARCH_ERR("[MIDI] MIDIOutputPortCreate failed: %d.\n", err); RARCH_ERR("[MIDI] MIDIOutputPortCreate failed: %d.\n", err);
if (d->input_port) if (d->input_port)
MIDIPortDispose(d->input_port); MIDIPortDispose(d->input_port);
@ -122,36 +142,44 @@ static void *coremidi_init(const char *input, const char *output) {
free(d); free(d);
return NULL; return NULL;
} }
} else { }
else
{
RARCH_LOG("[MIDI] CoreMIDI output port created successfully.\n"); RARCH_LOG("[MIDI] CoreMIDI output port created successfully.\n");
} }
return d; return d;
} }
/// Get available input devices /* Get available input devices */
static bool coremidi_get_avail_inputs(struct string_list *inputs) { static bool coremidi_get_avail_inputs(struct string_list *inputs)
{
ItemCount count = MIDIGetNumberOfSources(); ItemCount count = MIDIGetNumberOfSources();
union string_list_elem_attr attr = {0}; union string_list_elem_attr attr = {0};
for (ItemCount i = 0; i < count; i++) { for (ItemCount i = 0; i < count; i++)
{
MIDIEndpointRef endpoint = MIDIGetSource(i); MIDIEndpointRef endpoint = MIDIGetSource(i);
CFStringRef name; CFStringRef name;
char buf[256]; char buf[256];
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name); OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
if (err == noErr) { if (err == noErr)
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)) { {
if (!string_list_append(inputs, buf, attr)) { if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8))
{
if (!string_list_append(inputs, buf, attr))
{
RARCH_ERR("[MIDI] Failed to append input device to list: %s.\n", buf); RARCH_ERR("[MIDI] Failed to append input device to list: %s.\n", buf);
CFRelease(name); CFRelease(name);
return false; return false;
} else {
RARCH_LOG("[MIDI] Input device added to list: %s.\n", buf);
} }
RARCH_LOG("[MIDI] Input device added to list: %s.\n", buf);
} }
CFRelease(name); CFRelease(name);
} else { }
else
{
RARCH_WARN("[MIDI] Failed to get display name for input device %d: %d.\n", i, err); RARCH_WARN("[MIDI] Failed to get display name for input device %d: %d.\n", i, err);
} }
} }
@ -159,29 +187,34 @@ static bool coremidi_get_avail_inputs(struct string_list *inputs) {
return true; return true;
} }
/// Get available output devices /* Get available output devices */
static bool coremidi_get_avail_outputs(struct string_list *outputs) { static bool coremidi_get_avail_outputs(struct string_list *outputs)
{
ItemCount count = MIDIGetNumberOfDestinations(); ItemCount count = MIDIGetNumberOfDestinations();
union string_list_elem_attr attr = {0}; union string_list_elem_attr attr = {0};
for (ItemCount i = 0; i < count; i++) { for (ItemCount i = 0; i < count; i++)
{
char buf[256];
MIDIEndpointRef endpoint = MIDIGetDestination(i); MIDIEndpointRef endpoint = MIDIGetDestination(i);
CFStringRef name; CFStringRef name;
char buf[256];
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name); OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
if (err == noErr) { if (err == noErr)
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)) { {
if (!string_list_append(outputs, buf, attr)) { if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8))
{
if (!string_list_append(outputs, buf, attr))
{
RARCH_ERR("[MIDI] Failed to append output device to list: %s.\n", buf); RARCH_ERR("[MIDI] Failed to append output device to list: %s.\n", buf);
CFRelease(name); CFRelease(name);
return false; return false;
} else {
RARCH_LOG("[MIDI] Output device added to list: %s.\n", buf);
} }
RARCH_LOG("[MIDI] Output device added to list: %s.\n", buf);
} }
CFRelease(name); CFRelease(name);
} else { }
else
{
RARCH_WARN("[MIDI] Failed to get display name for output device %d: %d.\n", i, err); RARCH_WARN("[MIDI] Failed to get display name for output device %d: %d.\n", i, err);
} }
} }
@ -189,47 +222,55 @@ static bool coremidi_get_avail_outputs(struct string_list *outputs) {
return true; return true;
} }
/// Set the input device /* Set the input device */
static bool coremidi_set_input(void *p, const char *input) { static bool coremidi_set_input(void *p, const char *input)
{
ItemCount count;
coremidi_t *d = (coremidi_t *)p; coremidi_t *d = (coremidi_t *)p;
if (!d || !d->input_port) { if (!d || !d->input_port)
{
RARCH_WARN("[MIDI] Input port not initialized.\n"); RARCH_WARN("[MIDI] Input port not initialized.\n");
return false; return false;
} }
// Disconnect current input endpoint /* Disconnect current input endpoint */
if (d->input_endpoint) { if (d->input_endpoint)
{
RARCH_LOG("[MIDI] Disconnecting current input endpoint.\n"); RARCH_LOG("[MIDI] Disconnecting current input endpoint.\n");
MIDIPortDisconnectSource(d->input_port, d->input_endpoint); MIDIPortDisconnectSource(d->input_port, d->input_endpoint);
d->input_endpoint = 0; d->input_endpoint = 0;
} }
// If input is NULL or "Off", just return success /* If input is NULL or "Off", just return success */
if (!input || string_is_equal(input, "Off")) { if (!input || string_is_equal(input, "Off"))
{
RARCH_LOG("[MIDI] Input set to Off.\n"); RARCH_LOG("[MIDI] Input set to Off.\n");
return true; return true;
} }
// Find the input endpoint by name /* Find the input endpoint by name */
ItemCount count = MIDIGetNumberOfSources(); count = MIDIGetNumberOfSources();
for (ItemCount i = 0; i < count; i++) { for (ItemCount i = 0; i < count; i++)
{
char buf[256];
MIDIEndpointRef endpoint = MIDIGetSource(i); MIDIEndpointRef endpoint = MIDIGetSource(i);
CFStringRef name; CFStringRef name;
char buf[256];
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name); OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
if (err == noErr) { if (err == noErr)
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8) && string_is_equal(input, buf)) { {
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)
&& string_is_equal(input, buf))
{
err = MIDIPortConnectSource(d->input_port, endpoint, NULL); err = MIDIPortConnectSource(d->input_port, endpoint, NULL);
CFRelease(name); CFRelease(name);
if (err == noErr) { if (err == noErr)
{
d->input_endpoint = endpoint; d->input_endpoint = endpoint;
RARCH_LOG("[MIDI] Input endpoint set to %s.\n", buf); RARCH_LOG("[MIDI] Input endpoint set to %s.\n", buf);
return true; return true;
} else {
RARCH_WARN("[MIDI] Failed to connect input endpoint: %d.\n", err);
return false;
} }
RARCH_WARN("[MIDI] Failed to connect input endpoint: %d.\n", err);
return false;
} }
CFRelease(name); CFRelease(name);
} }
@ -239,31 +280,38 @@ static bool coremidi_set_input(void *p, const char *input) {
return false; return false;
} }
/// Set the output device /* Set the output device */
static bool coremidi_set_output(void *p, const char *output) { static bool coremidi_set_output(void *p, const char *output)
{
ItemCount i, count;
coremidi_t *d = (coremidi_t *)p; coremidi_t *d = (coremidi_t *)p;
if (!d || !d->output_port) { if (!d || !d->output_port)
{
RARCH_WARN("[MIDI] Output port not initialized.\n"); RARCH_WARN("[MIDI] Output port not initialized.\n");
return false; return false;
} }
// If output is NULL or "Off", just return success /* If output is NULL or "Off", just return success */
if (!output || string_is_equal(output, "Off")) { if (!output || string_is_equal(output, "Off"))
{
RARCH_LOG("[MIDI] Output set to Off.\n"); RARCH_LOG("[MIDI] Output set to Off.\n");
d->output_endpoint = 0; d->output_endpoint = 0;
return true; return true;
} }
// Find the output endpoint by name /* Find the output endpoint by name */
ItemCount count = MIDIGetNumberOfDestinations(); count = MIDIGetNumberOfDestinations();
for (ItemCount i = 0; i < count; i++) { for (i = 0; i < count; i++)
{
char buf[256];
MIDIEndpointRef endpoint = MIDIGetDestination(i); MIDIEndpointRef endpoint = MIDIGetDestination(i);
CFStringRef name; CFStringRef name;
char buf[256];
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name); OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
if (err == noErr) { if (err == noErr)
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8) && string_is_equal(output, buf)) { {
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)
&& string_is_equal(output, buf))
{
d->output_endpoint = endpoint; d->output_endpoint = endpoint;
RARCH_LOG("[MIDI] Output endpoint set to %s.\n", buf); RARCH_LOG("[MIDI] Output endpoint set to %s.\n", buf);
CFRelease(name); CFRelease(name);
@ -277,9 +325,10 @@ static bool coremidi_set_output(void *p, const char *output) {
return false; return false;
} }
/// Read from the queue /* Read from the queue */
static bool coremidi_queue_read(coremidi_queue_t *q, midi_event_t *ev) { static bool coremidi_queue_read(coremidi_queue_t *q, midi_event_t *ev)
if (q->read_index == q->write_index) // Queue empty {
if (q->read_index == q->write_index) /* Queue empty */
return false; return false;
memcpy(ev, &q->events[q->read_index], sizeof(*ev)); memcpy(ev, &q->events[q->read_index], sizeof(*ev));
@ -287,62 +336,72 @@ static bool coremidi_queue_read(coremidi_queue_t *q, midi_event_t *ev) {
return true; return true;
} }
/// Read a MIDI event /* Read a MIDI event */
static bool coremidi_read(void *p, midi_event_t *event) { static bool coremidi_read(void *p, midi_event_t *event)
{
int result;
coremidi_t *d = (coremidi_t *)p; coremidi_t *d = (coremidi_t *)p;
if (!d || !event) { if (!d || !event)
{
RARCH_WARN("[MIDI] Invalid parameters in coremidi_read.\n"); RARCH_WARN("[MIDI] Invalid parameters in coremidi_read.\n");
return false; return false;
} }
if (!d->input_port || !d->input_endpoint) { if (!d->input_port || !d->input_endpoint)
{
RARCH_WARN("[MIDI] Input not configured.\n"); RARCH_WARN("[MIDI] Input not configured.\n");
return false; return false;
} }
int result = coremidi_queue_read(&d->input_queue, event); result = coremidi_queue_read(&d->input_queue, event);
// #if DEBUG #if DEBUG
RARCH_LOG("[MIDI] Input queue read result: %d.\n", result); RARCH_LOG("[MIDI] Input queue read result: %d.\n", result);
// #endif #endif
return result; return result;
} }
/// Write a MIDI event /* Write a MIDI event */
static bool coremidi_write(void *p, const midi_event_t *event) { static bool coremidi_write(void *p, const midi_event_t *event)
{
coremidi_t *d = (coremidi_t *)p; coremidi_t *d = (coremidi_t *)p;
if (!d || !event) { if (!d || !event)
{
RARCH_WARN("[MIDI] Invalid parameters in coremidi_write.\n"); RARCH_WARN("[MIDI] Invalid parameters in coremidi_write.\n");
return false; return false;
} }
if (!d->output_port || !d->output_endpoint) { if (!d->output_port || !d->output_endpoint)
{
RARCH_WARN("[MIDI] Output not configured.\n"); RARCH_WARN("[MIDI] Output not configured.\n");
return false; return false;
} }
// Validate event data /* Validate event data */
if (!event->data || event->data_size == 0 || event->data_size > 65535) { if (!event->data || event->data_size == 0 || event->data_size > 65535)
{
RARCH_WARN("[MIDI] Invalid event data in coremidi_write.\n"); RARCH_WARN("[MIDI] Invalid event data in coremidi_write.\n");
return false; return false;
} }
// Create a MIDIPacketList with sufficient buffer size /* Create a MIDIPacketList with sufficient buffer size */
char packetListBuffer[sizeof(MIDIPacketList) + sizeof(MIDIPacket) + event->data_size]; char packetListBuffer[sizeof(MIDIPacketList) + sizeof(MIDIPacket) + event->data_size];
MIDIPacketList *packetList = (MIDIPacketList *)packetListBuffer; MIDIPacketList *packetList = (MIDIPacketList *)packetListBuffer;
MIDIPacket *packet = MIDIPacketListInit(packetList); MIDIPacket *packet = MIDIPacketListInit(packetList);
// Add the event to the packet list /* Add the event to the packet list */
packet = MIDIPacketListAdd(packetList, sizeof(packetListBuffer), packet, 0, event->data_size, event->data); if (!(packet = MIDIPacketListAdd(packetList, sizeof(packetListBuffer),
if (!packet) { packet, 0, event->data_size, event->data)))
{
RARCH_WARN("[MIDI] Failed to create MIDIPacketList.\n"); RARCH_WARN("[MIDI] Failed to create MIDIPacketList.\n");
return false; return false;
} }
// Send the packet /* Send the packet */
OSStatus err = MIDISend(d->output_port, d->output_endpoint, packetList); OSStatus err = MIDISend(d->output_port, d->output_endpoint, packetList);
if (err != noErr) { if (err != noErr)
{
RARCH_WARN("[MIDI] MIDISend failed: %d.\n", err); RARCH_WARN("[MIDI] MIDISend failed: %d.\n", err);
return false; return false;
} }
@ -350,16 +409,19 @@ static bool coremidi_write(void *p, const midi_event_t *event) {
return true; return true;
} }
/// Flush the output buffer /* Flush the output buffer */
static bool coremidi_flush(void *p) { static bool coremidi_flush(void *p)
{
coremidi_t *d = (coremidi_t *)p; coremidi_t *d = (coremidi_t *)p;
if (!d) { if (!d)
{
RARCH_WARN("[MIDI] Invalid parameters in coremidi_flush.\n"); RARCH_WARN("[MIDI] Invalid parameters in coremidi_flush.\n");
return false; return false;
} }
if (!d->output_port || !d->output_endpoint) { if (!d->output_port || !d->output_endpoint)
{
RARCH_WARN("[MIDI] Output not configured.\n"); RARCH_WARN("[MIDI] Output not configured.\n");
return false; return false;
} }
@ -367,38 +429,43 @@ static bool coremidi_flush(void *p) {
return true; return true;
} }
/// Free resources and cleanup /* Free resources and cleanup */
static void coremidi_free(void *p) { static void coremidi_free(void *p)
{
coremidi_t *d = (coremidi_t *)p; coremidi_t *d = (coremidi_t *)p;
if (!d) { if (!d)
{
RARCH_WARN("[MIDI] Invalid parameters in coremidi_free.\n"); RARCH_WARN("[MIDI] Invalid parameters in coremidi_free.\n");
return; return;
} }
// Clean up MIDI resources /* Clean up MIDI resources */
if (d->input_port) { if (d->input_port)
{
RARCH_LOG("[MIDI] Disconnecting input port...\n"); RARCH_LOG("[MIDI] Disconnecting input port...\n");
MIDIPortDisconnectSource(d->input_port, d->input_endpoint); MIDIPortDisconnectSource(d->input_port, d->input_endpoint);
MIDIPortDispose(d->input_port); MIDIPortDispose(d->input_port);
} }
if (d->output_port) { if (d->output_port)
{
RARCH_LOG("[MIDI] Disconnecting output port...\n"); RARCH_LOG("[MIDI] Disconnecting output port...\n");
MIDIPortDisconnectSource(d->output_port, d->output_endpoint); MIDIPortDisconnectSource(d->output_port, d->output_endpoint);
MIDIPortDispose(d->output_port); MIDIPortDispose(d->output_port);
} }
if (d->client) { if (d->client)
{
RARCH_LOG("[MIDI] Disposing of CoreMIDI client...\n"); RARCH_LOG("[MIDI] Disposing of CoreMIDI client...\n");
MIDIClientDispose(d->client); MIDIClientDispose(d->client);
} }
// Free the driver instance /* Free the driver instance */
free(d); free(d);
} }
/// CoreMIDI driver API /* CoreMIDI driver API */
midi_driver_t midi_coremidi = { midi_driver_t midi_coremidi = {
.ident = "coremidi", .ident = "coremidi",
.init = coremidi_init, .init = coremidi_init,

View File

@ -246,7 +246,7 @@ static bool ui_browser_window_win32_core(
ui_browser_window_state_t *state, bool save) ui_browser_window_state_t *state, bool save)
{ {
OPENFILENAME ofn; OPENFILENAME ofn;
bool okay = true; bool ret = true;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr(); video_driver_state_t *video_st = video_state_get_ptr();
bool video_fullscreen = settings->bools.video_fullscreen; bool video_fullscreen = settings->bools.video_fullscreen;
@ -288,9 +288,9 @@ static bool ui_browser_window_win32_core(
} }
if (!save && !GetOpenFileName(&ofn)) if (!save && !GetOpenFileName(&ofn))
okay = false; ret = false;
if (save && !GetSaveFileName(&ofn)) if (save && !GetSaveFileName(&ofn))
okay = false; ret = false;
/* Full screen: Hide mouse after the file dialog */ /* Full screen: Hide mouse after the file dialog */
if (video_fullscreen) if (video_fullscreen)
@ -300,7 +300,7 @@ static bool ui_browser_window_win32_core(
video_st->poke->show_mouse(video_st->data, false); video_st->poke->show_mouse(video_st->data, false);
} }
return okay; return ret;
} }
static bool ui_browser_window_win32_open(ui_browser_window_state_t *state) static bool ui_browser_window_win32_open(ui_browser_window_state_t *state)