* Change some variable naming conventions
* Make return control paths less dependent on variables
This commit is contained in:
parent
bca5cafaa6
commit
2dbb9f62d8
|
@ -288,6 +288,7 @@ int alsa_init_pcm(snd_pcm_t **pcm,
|
|||
snd_pcm_name(*pcm));
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (params)
|
||||
snd_pcm_hw_params_free(params);
|
||||
|
|
|
@ -118,19 +118,14 @@ static const char *wave_format_name(const WAVEFORMATEXTENSIBLE *format)
|
|||
|
||||
const char* wasapi_error(DWORD error)
|
||||
{
|
||||
static char error_message[256];
|
||||
|
||||
static char s[256];
|
||||
FormatMessage(
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS
|
||||
| FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
error,
|
||||
NULL, error,
|
||||
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
|
||||
error_message,
|
||||
sizeof(error_message) - 1,
|
||||
NULL);
|
||||
|
||||
return error_message;
|
||||
s, sizeof(s) - 1, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
static const char* wasapi_data_flow_name(EDataFlow data_flow)
|
||||
|
|
|
@ -1922,19 +1922,6 @@ static int pcm_avail_update(struct pcm *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.
|
||||
* @param pcm A PCM handle.
|
||||
* @param timeout The maximum amount of time to wait for, in terms of milliseconds.
|
||||
|
|
|
@ -631,16 +631,17 @@ static bool win32_drag_query_file(HWND hwnd, WPARAM wparam)
|
|||
if (DragQueryFileW((HDROP)wparam, 0xFFFFFFFF, NULL, 0))
|
||||
{
|
||||
wchar_t wszFilename[4096];
|
||||
bool okay = false;
|
||||
bool ret = false;
|
||||
char *szFilename = NULL;
|
||||
wszFilename[0] = L'\0';
|
||||
|
||||
DragQueryFileW((HDROP)wparam, 0, wszFilename, sizeof(wszFilename));
|
||||
szFilename = utf16_to_utf8_string_alloc(wszFilename);
|
||||
okay = win32_load_content_from_gui(szFilename);
|
||||
ret = win32_load_content_from_gui(szFilename);
|
||||
if (szFilename)
|
||||
free(szFilename);
|
||||
return okay;
|
||||
if (ret)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -148,8 +148,6 @@ static void ps3_end_camera(ps3_input_t *ps3)
|
|||
|
||||
static int ps3_setup_camera(ps3_input_t *ps3)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
cameraGetType(0, &ps3->type);
|
||||
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:
|
||||
cameraClose(0);
|
||||
error = 1;
|
||||
break;
|
||||
case CAMERA_ERRO_NO_DEVICE_FOUND:
|
||||
error = 1;
|
||||
break;
|
||||
return 1;
|
||||
case 0:
|
||||
ps3->camread.buffer = ps3->camInf.buffer;
|
||||
ps3->camread.version = 0x0100;
|
||||
ps3->cam_buf = (u8 *)(u64)ps3->camread.buffer;
|
||||
break;
|
||||
case CAMERA_ERRO_NO_DEVICE_FOUND:
|
||||
default:
|
||||
error = 1;
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
error = 1;
|
||||
return error;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -224,7 +224,7 @@ bool nested_list_add_item(nested_list_t *list,
|
|||
bool success = false;
|
||||
|
||||
if (!list || string_is_empty(address))
|
||||
goto end;
|
||||
return false;
|
||||
|
||||
/* If delim is NULL or address contains a single
|
||||
* token, then we are adding an item to the top
|
||||
|
@ -249,10 +249,10 @@ bool nested_list_add_item(nested_list_t *list,
|
|||
}
|
||||
else
|
||||
{
|
||||
size_t i;
|
||||
nested_list_t *current_list = list;
|
||||
nested_list_item_t *parent_item = NULL;
|
||||
nested_list_item_t *next_item = NULL;
|
||||
size_t i;
|
||||
|
||||
/* Loop over list item ids */
|
||||
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)
|
||||
{
|
||||
if (!list_item ||
|
||||
!list_item->children ||
|
||||
(RBUF_LEN(list_item->children->items) < 1))
|
||||
if ( !list_item
|
||||
|| !list_item->children
|
||||
|| (RBUF_LEN(list_item->children->items) < 1))
|
||||
return NULL;
|
||||
|
||||
return list_item->children;
|
||||
|
@ -504,7 +504,6 @@ const char *nested_list_item_get_id(nested_list_item_t *list_item)
|
|||
{
|
||||
if (!list_item)
|
||||
return NULL;
|
||||
|
||||
return list_item->id;
|
||||
}
|
||||
|
||||
|
|
|
@ -1044,17 +1044,15 @@ uint8_t task_get_flags(retro_task_t *task)
|
|||
|
||||
char* task_get_error(retro_task_t *task)
|
||||
{
|
||||
char *error = NULL;
|
||||
|
||||
char *s = NULL;
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(property_lock);
|
||||
#endif
|
||||
error = task->error;
|
||||
s = task->error;
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(property_lock);
|
||||
#endif
|
||||
|
||||
return error;
|
||||
return s;
|
||||
}
|
||||
|
||||
int8_t task_get_progress(retro_task_t *task)
|
||||
|
|
|
@ -23,25 +23,28 @@
|
|||
|
||||
#define CORE_MIDI_QUEUE_SIZE 1024
|
||||
|
||||
typedef struct {
|
||||
midi_event_t events[CORE_MIDI_QUEUE_SIZE]; ///< Event buffer
|
||||
int read_index; ///< Current read position
|
||||
int write_index; ///< Current write position
|
||||
typedef struct
|
||||
{
|
||||
midi_event_t events[CORE_MIDI_QUEUE_SIZE]; /* Event buffer */
|
||||
int read_index; /* Current read position */
|
||||
int write_index; /* Current write position */
|
||||
} coremidi_queue_t;
|
||||
|
||||
typedef struct {
|
||||
MIDIClientRef client; ///< CoreMIDI client
|
||||
MIDIPortRef input_port; ///< Input port for receiving MIDI data
|
||||
MIDIPortRef output_port; ///< Output port for sending MIDI data
|
||||
MIDIEndpointRef input_endpoint; ///< Selected input endpoint
|
||||
MIDIEndpointRef output_endpoint; ///< Selected output endpoint
|
||||
coremidi_queue_t input_queue; ///< Queue for incoming MIDI events
|
||||
typedef struct
|
||||
{
|
||||
MIDIClientRef client; /* CoreMIDI client */
|
||||
MIDIPortRef input_port; /* Input port for receiving MIDI data */
|
||||
MIDIPortRef output_port; /* Output port for sending MIDI data */
|
||||
MIDIEndpointRef input_endpoint; /* Selected input endpoint */
|
||||
MIDIEndpointRef output_endpoint; /* Selected output endpoint */
|
||||
coremidi_queue_t input_queue; /* Queue for incoming MIDI events */
|
||||
} coremidi_t;
|
||||
|
||||
/// Write to the queue
|
||||
static bool coremidi_queue_write(coremidi_queue_t *q, const midi_event_t *ev) {
|
||||
/* Write to the queue */
|
||||
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;
|
||||
if (next_write == q->read_index) // Queue full
|
||||
if (next_write == q->read_index) /* Queue full */
|
||||
return false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// MIDIReadProc callback function
|
||||
static void midi_read_callback(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) {
|
||||
/* MIDIReadProc callback function */
|
||||
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;
|
||||
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;
|
||||
size_t length = packet->length;
|
||||
size_t length = packet->length;
|
||||
const MIDITimeStamp timestamp = packet->timeStamp;
|
||||
|
||||
while (length > 0) {
|
||||
while (length > 0)
|
||||
{
|
||||
size_t msg_size = midi_driver_get_event_size(data[0]);
|
||||
if (msg_size == 0 || msg_size > length)
|
||||
break;
|
||||
|
||||
event.data = (uint8_t *)data;
|
||||
event.data_size = msg_size;
|
||||
event.data = (uint8_t*)data;
|
||||
event.data_size = msg_size;
|
||||
event.delta_time = (uint32_t)timestamp;
|
||||
|
||||
// Add to queue
|
||||
/* Add to queue */
|
||||
coremidi_queue_write(&d->input_queue, &event);
|
||||
|
||||
data += msg_size;
|
||||
data += 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
|
||||
static void *coremidi_init(const char *input, const char *output) {
|
||||
/* Initialize the CoreMIDI client and ports */
|
||||
static void *coremidi_init(const char *input, const char *output)
|
||||
{
|
||||
OSStatus err;
|
||||
coremidi_t *d = (coremidi_t *)calloc(1, sizeof(coremidi_t));
|
||||
if (!d) {
|
||||
if (!d)
|
||||
{
|
||||
RARCH_ERR("[MIDI] Out of memory.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSStatus err = MIDIClientCreate(CFSTR("RetroArch MIDI Client"), NULL, NULL, &d->client);
|
||||
if (err != noErr) {
|
||||
err = MIDIClientCreate(CFSTR("RetroArch MIDI Client"),
|
||||
NULL, NULL, &d->client);
|
||||
if (err != noErr)
|
||||
{
|
||||
RARCH_ERR("[MIDI] MIDIClientCreate failed: %d.\n", err);
|
||||
free(d);
|
||||
return NULL;
|
||||
} else {
|
||||
RARCH_LOG("[MIDI] CoreMIDI client created successfully.\n");
|
||||
}
|
||||
|
||||
// Create input port if specified
|
||||
if (input) {
|
||||
err = MIDIInputPortCreate(d->client, CFSTR("Input Port"), midi_read_callback, d, &d->input_port);
|
||||
if (err != noErr) {
|
||||
RARCH_LOG("[MIDI] CoreMIDI client created successfully.\n");
|
||||
|
||||
/* Create input port if specified */
|
||||
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);
|
||||
MIDIClientDispose(d->client);
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
RARCH_LOG("[MIDI] CoreMIDI input port created successfully.\n");
|
||||
}
|
||||
|
||||
// Create output port if specified
|
||||
if (output) {
|
||||
err = MIDIOutputPortCreate(d->client, CFSTR("Output Port"), &d->output_port);
|
||||
if (err != noErr) {
|
||||
/* Create output port if specified */
|
||||
if (output)
|
||||
{
|
||||
err = MIDIOutputPortCreate(d->client,
|
||||
CFSTR("Output Port"), &d->output_port);
|
||||
if (err != noErr)
|
||||
{
|
||||
RARCH_ERR("[MIDI] MIDIOutputPortCreate failed: %d.\n", err);
|
||||
if (d->input_port)
|
||||
MIDIPortDispose(d->input_port);
|
||||
|
@ -122,36 +142,44 @@ static void *coremidi_init(const char *input, const char *output) {
|
|||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
RARCH_LOG("[MIDI] CoreMIDI output port created successfully.\n");
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/// Get available input devices
|
||||
static bool coremidi_get_avail_inputs(struct string_list *inputs) {
|
||||
/* Get available input devices */
|
||||
static bool coremidi_get_avail_inputs(struct string_list *inputs)
|
||||
{
|
||||
ItemCount count = MIDIGetNumberOfSources();
|
||||
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);
|
||||
CFStringRef name;
|
||||
char buf[256];
|
||||
|
||||
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
|
||||
if (err == noErr) {
|
||||
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)) {
|
||||
if (!string_list_append(inputs, buf, attr)) {
|
||||
if (err == noErr)
|
||||
{
|
||||
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);
|
||||
CFRelease(name);
|
||||
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);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/// Get available output devices
|
||||
static bool coremidi_get_avail_outputs(struct string_list *outputs) {
|
||||
/* Get available output devices */
|
||||
static bool coremidi_get_avail_outputs(struct string_list *outputs)
|
||||
{
|
||||
ItemCount count = MIDIGetNumberOfDestinations();
|
||||
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);
|
||||
CFStringRef name;
|
||||
char buf[256];
|
||||
|
||||
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
|
||||
if (err == noErr) {
|
||||
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)) {
|
||||
if (!string_list_append(outputs, buf, attr)) {
|
||||
if (err == noErr)
|
||||
{
|
||||
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);
|
||||
CFRelease(name);
|
||||
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);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/// Set the input device
|
||||
static bool coremidi_set_input(void *p, const char *input) {
|
||||
/* Set the input device */
|
||||
static bool coremidi_set_input(void *p, const char *input)
|
||||
{
|
||||
ItemCount count;
|
||||
coremidi_t *d = (coremidi_t *)p;
|
||||
if (!d || !d->input_port) {
|
||||
if (!d || !d->input_port)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Input port not initialized.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disconnect current input endpoint
|
||||
if (d->input_endpoint) {
|
||||
/* Disconnect current input endpoint */
|
||||
if (d->input_endpoint)
|
||||
{
|
||||
RARCH_LOG("[MIDI] Disconnecting current input endpoint.\n");
|
||||
MIDIPortDisconnectSource(d->input_port, d->input_endpoint);
|
||||
d->input_endpoint = 0;
|
||||
}
|
||||
|
||||
// If input is NULL or "Off", just return success
|
||||
if (!input || string_is_equal(input, "Off")) {
|
||||
/* If input is NULL or "Off", just return success */
|
||||
if (!input || string_is_equal(input, "Off"))
|
||||
{
|
||||
RARCH_LOG("[MIDI] Input set to Off.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Find the input endpoint by name
|
||||
ItemCount count = MIDIGetNumberOfSources();
|
||||
for (ItemCount i = 0; i < count; i++) {
|
||||
/* Find the input endpoint by name */
|
||||
count = MIDIGetNumberOfSources();
|
||||
for (ItemCount i = 0; i < count; i++)
|
||||
{
|
||||
char buf[256];
|
||||
MIDIEndpointRef endpoint = MIDIGetSource(i);
|
||||
CFStringRef name;
|
||||
char buf[256];
|
||||
|
||||
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
|
||||
if (err == noErr) {
|
||||
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8) && string_is_equal(input, buf)) {
|
||||
if (err == noErr)
|
||||
{
|
||||
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)
|
||||
&& string_is_equal(input, buf))
|
||||
{
|
||||
err = MIDIPortConnectSource(d->input_port, endpoint, NULL);
|
||||
CFRelease(name);
|
||||
if (err == noErr) {
|
||||
if (err == noErr)
|
||||
{
|
||||
d->input_endpoint = endpoint;
|
||||
RARCH_LOG("[MIDI] Input endpoint set to %s.\n", buf);
|
||||
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);
|
||||
}
|
||||
|
@ -239,31 +280,38 @@ static bool coremidi_set_input(void *p, const char *input) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/// Set the output device
|
||||
static bool coremidi_set_output(void *p, const char *output) {
|
||||
/* Set the output device */
|
||||
static bool coremidi_set_output(void *p, const char *output)
|
||||
{
|
||||
ItemCount i, count;
|
||||
coremidi_t *d = (coremidi_t *)p;
|
||||
if (!d || !d->output_port) {
|
||||
if (!d || !d->output_port)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Output port not initialized.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If output is NULL or "Off", just return success
|
||||
if (!output || string_is_equal(output, "Off")) {
|
||||
/* If output is NULL or "Off", just return success */
|
||||
if (!output || string_is_equal(output, "Off"))
|
||||
{
|
||||
RARCH_LOG("[MIDI] Output set to Off.\n");
|
||||
d->output_endpoint = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Find the output endpoint by name
|
||||
ItemCount count = MIDIGetNumberOfDestinations();
|
||||
for (ItemCount i = 0; i < count; i++) {
|
||||
/* Find the output endpoint by name */
|
||||
count = MIDIGetNumberOfDestinations();
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
char buf[256];
|
||||
MIDIEndpointRef endpoint = MIDIGetDestination(i);
|
||||
CFStringRef name;
|
||||
char buf[256];
|
||||
|
||||
OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyDisplayName, &name);
|
||||
if (err == noErr) {
|
||||
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8) && string_is_equal(output, buf)) {
|
||||
if (err == noErr)
|
||||
{
|
||||
if (CFStringGetCString(name, buf, sizeof(buf), kCFStringEncodingUTF8)
|
||||
&& string_is_equal(output, buf))
|
||||
{
|
||||
d->output_endpoint = endpoint;
|
||||
RARCH_LOG("[MIDI] Output endpoint set to %s.\n", buf);
|
||||
CFRelease(name);
|
||||
|
@ -277,9 +325,10 @@ static bool coremidi_set_output(void *p, const char *output) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/// Read from the queue
|
||||
static bool coremidi_queue_read(coremidi_queue_t *q, midi_event_t *ev) {
|
||||
if (q->read_index == q->write_index) // Queue empty
|
||||
/* Read from the queue */
|
||||
static bool coremidi_queue_read(coremidi_queue_t *q, midi_event_t *ev)
|
||||
{
|
||||
if (q->read_index == q->write_index) /* Queue empty */
|
||||
return false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// Read a MIDI event
|
||||
static bool coremidi_read(void *p, midi_event_t *event) {
|
||||
/* Read a MIDI event */
|
||||
static bool coremidi_read(void *p, midi_event_t *event)
|
||||
{
|
||||
int result;
|
||||
coremidi_t *d = (coremidi_t *)p;
|
||||
|
||||
if (!d || !event) {
|
||||
if (!d || !event)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Invalid parameters in coremidi_read.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!d->input_port || !d->input_endpoint) {
|
||||
if (!d->input_port || !d->input_endpoint)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Input not configured.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = coremidi_queue_read(&d->input_queue, event);
|
||||
// #if DEBUG
|
||||
result = coremidi_queue_read(&d->input_queue, event);
|
||||
#if DEBUG
|
||||
RARCH_LOG("[MIDI] Input queue read result: %d.\n", result);
|
||||
// #endif
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Write a MIDI event
|
||||
static bool coremidi_write(void *p, const midi_event_t *event) {
|
||||
/* Write a MIDI event */
|
||||
static bool coremidi_write(void *p, const midi_event_t *event)
|
||||
{
|
||||
coremidi_t *d = (coremidi_t *)p;
|
||||
|
||||
if (!d || !event) {
|
||||
if (!d || !event)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Invalid parameters in coremidi_write.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!d->output_port || !d->output_endpoint) {
|
||||
if (!d->output_port || !d->output_endpoint)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Output not configured.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate event data
|
||||
if (!event->data || event->data_size == 0 || event->data_size > 65535) {
|
||||
/* Validate event data */
|
||||
if (!event->data || event->data_size == 0 || event->data_size > 65535)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Invalid event data in coremidi_write.\n");
|
||||
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];
|
||||
MIDIPacketList *packetList = (MIDIPacketList *)packetListBuffer;
|
||||
MIDIPacket *packet = MIDIPacketListInit(packetList);
|
||||
|
||||
// Add the event to the packet list
|
||||
packet = MIDIPacketListAdd(packetList, sizeof(packetListBuffer), packet, 0, event->data_size, event->data);
|
||||
if (!packet) {
|
||||
/* Add the event to the packet list */
|
||||
if (!(packet = MIDIPacketListAdd(packetList, sizeof(packetListBuffer),
|
||||
packet, 0, event->data_size, event->data)))
|
||||
{
|
||||
RARCH_WARN("[MIDI] Failed to create MIDIPacketList.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send the packet
|
||||
/* Send the packet */
|
||||
OSStatus err = MIDISend(d->output_port, d->output_endpoint, packetList);
|
||||
if (err != noErr) {
|
||||
if (err != noErr)
|
||||
{
|
||||
RARCH_WARN("[MIDI] MIDISend failed: %d.\n", err);
|
||||
return false;
|
||||
}
|
||||
|
@ -350,16 +409,19 @@ static bool coremidi_write(void *p, const midi_event_t *event) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Flush the output buffer
|
||||
static bool coremidi_flush(void *p) {
|
||||
/* Flush the output buffer */
|
||||
static bool coremidi_flush(void *p)
|
||||
{
|
||||
coremidi_t *d = (coremidi_t *)p;
|
||||
|
||||
if (!d) {
|
||||
if (!d)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Invalid parameters in coremidi_flush.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!d->output_port || !d->output_endpoint) {
|
||||
if (!d->output_port || !d->output_endpoint)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Output not configured.\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -367,38 +429,43 @@ static bool coremidi_flush(void *p) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Free resources and cleanup
|
||||
static void coremidi_free(void *p) {
|
||||
/* Free resources and cleanup */
|
||||
static void coremidi_free(void *p)
|
||||
{
|
||||
coremidi_t *d = (coremidi_t *)p;
|
||||
|
||||
if (!d) {
|
||||
if (!d)
|
||||
{
|
||||
RARCH_WARN("[MIDI] Invalid parameters in coremidi_free.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up MIDI resources
|
||||
if (d->input_port) {
|
||||
/* Clean up MIDI resources */
|
||||
if (d->input_port)
|
||||
{
|
||||
RARCH_LOG("[MIDI] Disconnecting input port...\n");
|
||||
MIDIPortDisconnectSource(d->input_port, d->input_endpoint);
|
||||
MIDIPortDispose(d->input_port);
|
||||
}
|
||||
|
||||
if (d->output_port) {
|
||||
if (d->output_port)
|
||||
{
|
||||
RARCH_LOG("[MIDI] Disconnecting output port...\n");
|
||||
MIDIPortDisconnectSource(d->output_port, d->output_endpoint);
|
||||
MIDIPortDispose(d->output_port);
|
||||
}
|
||||
|
||||
if (d->client) {
|
||||
if (d->client)
|
||||
{
|
||||
RARCH_LOG("[MIDI] Disposing of CoreMIDI client...\n");
|
||||
MIDIClientDispose(d->client);
|
||||
}
|
||||
|
||||
// Free the driver instance
|
||||
/* Free the driver instance */
|
||||
free(d);
|
||||
}
|
||||
|
||||
/// CoreMIDI driver API
|
||||
/* CoreMIDI driver API */
|
||||
midi_driver_t midi_coremidi = {
|
||||
.ident = "coremidi",
|
||||
.init = coremidi_init,
|
||||
|
|
|
@ -246,7 +246,7 @@ static bool ui_browser_window_win32_core(
|
|||
ui_browser_window_state_t *state, bool save)
|
||||
{
|
||||
OPENFILENAME ofn;
|
||||
bool okay = true;
|
||||
bool ret = true;
|
||||
settings_t *settings = config_get_ptr();
|
||||
video_driver_state_t *video_st = video_state_get_ptr();
|
||||
bool video_fullscreen = settings->bools.video_fullscreen;
|
||||
|
@ -288,9 +288,9 @@ static bool ui_browser_window_win32_core(
|
|||
}
|
||||
|
||||
if (!save && !GetOpenFileName(&ofn))
|
||||
okay = false;
|
||||
ret = false;
|
||||
if (save && !GetSaveFileName(&ofn))
|
||||
okay = false;
|
||||
ret = false;
|
||||
|
||||
/* Full screen: Hide mouse after the file dialog */
|
||||
if (video_fullscreen)
|
||||
|
@ -300,7 +300,7 @@ static bool ui_browser_window_win32_core(
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue