Lines Matching refs:handle

265 static void processMessagesForPacket(const MIDIPacket* packet, MacMidiDeviceHandle* handle) {
305 if (handle->readingSysExData) {
306 CFDataAppendBytes(handle->readingSysExData, &byte, 1);
330 if (handle->readingSysExData /* && (byte == 0xF7) */) {
332 const UInt8* bytes = CFDataGetBytePtr(handle->readingSysExData);
333 CFIndex size = CFDataGetLength(handle->readingSysExData);
334 MIDI_QueueAddLong(handle->h.queue,
340 CFRelease(handle->readingSysExData);
341 handle->readingSysExData = NULL;
368 handle->readingSysExData = CFDataCreateMutable(NULL, 0);
399 // This can't happen, but handle it anyway.
409 MIDI_QueueAddShort(handle->h.queue, packedMsg, (INT64) (AudioConvertHostTimeToNanos(ts) + 500) / 1000, TRUE);
417 MacMidiDeviceHandle* handle = (MacMidiDeviceHandle*) connRefCon;
421 processMessagesForPacket(packet, handle);
426 if (handle) {
427 MIDI_SignalConditionVariable(handle->h.platformData);
459 INT32 MIDI_Utils_OpenDevice(int direction, INT32 deviceID, MacMidiDeviceHandle** handle,
470 (*handle) = (MacMidiDeviceHandle*) malloc(sizeof(MacMidiDeviceHandle));
471 if (!(*handle)) {
475 memset(*handle, 0, sizeof(MacMidiDeviceHandle));
481 (*handle)->h.queue = MIDI_CreateQueue(num_msgs);
482 (*handle)->h.platformData = MIDI_CreateConditionVariable();
483 if (!(*handle)->h.queue || !(*handle)->h.platformData) {
485 free(*handle);
486 (*handle) = NULL;
490 (*handle)->port = inPort;
493 (*handle)->port = outPort;
498 free(*handle);
501 (*handle)->h.deviceHandle = (void*) (intptr_t) endpoint;
502 (*handle)->h.startTime = getCurrentTimeInNanos();
503 (*handle)->direction = direction;
504 (*handle)->deviceID = deviceID;
511 INT32 MIDI_Utils_CloseDevice(MacMidiDeviceHandle* handle) {
513 bool midiIn = (handle->direction == MIDI_IN);
516 if (!handle) {
517 ERROR0("< ERROR: MIDI_Utils_CloseDevice: handle is NULL\n");
520 if (!handle->h.deviceHandle) {
521 ERROR0("< ERROR: MIDI_Utils_CloseDevice: native handle is NULL\n");
524 handle->isStarted = FALSE;
525 handle->h.deviceHandle = NULL;
528 if (handle->h.queue != NULL) {
529 MidiMessageQueue* queue = handle->h.queue;
530 handle->h.queue = NULL;
533 if (handle->h.platformData) {
534 MIDI_DestroyConditionVariable(handle->h.platformData);
537 free(handle);
544 INT32 MIDI_Utils_StartDevice(MacMidiDeviceHandle* handle) {
547 if (!handle || !handle->h.deviceHandle) {
548 ERROR0("ERROR: MIDI_Utils_StartDevice: handle or native is NULL\n");
553 MIDI_QueueClear(handle->h.queue);
555 if (!handle->isStarted) {
557 handle->isStarted = TRUE;
559 if (handle->direction == MIDI_IN) {
560 // The handle->h.platformData field contains the (pthread_cond_t*)
565 // Similarly, handle->h.queue is used in the CoreMDID's callback
568 err = MIDIPortConnectSource(inPort, (MIDIEndpointRef) (intptr_t) (handle->h.deviceHandle), (void*) handle);
569 } else if (handle->direction == MIDI_OUT) {
571 err = MIDIFlushOutput((MIDIEndpointRef) (intptr_t) handle->h.deviceHandle);
580 INT32 MIDI_Utils_StopDevice(MacMidiDeviceHandle* handle) {
583 if (!handle || !handle->h.deviceHandle) {
584 ERROR0("ERROR: MIDI_Utils_StopDevice: handle or native handle is NULL\n");
588 if (handle->isStarted) {
590 handle->isStarted = FALSE;
592 if (handle->direction == MIDI_IN) {
593 err = MIDIPortDisconnectSource(inPort, (MIDIEndpointRef) (intptr_t) (handle->h.deviceHandle));
594 } else if (handle->direction == MIDI_OUT) {
596 err = MIDIFlushOutput((MIDIEndpointRef) (intptr_t) handle->h.deviceHandle);
605 INT64 MIDI_Utils_GetTimeStamp(MacMidiDeviceHandle* handle) {
607 if (!handle || !handle->h.deviceHandle) {
608 ERROR0("ERROR: MIDI_Utils_GetTimeStamp: handle or native handle is NULL\n");
612 UInt64 delta = getCurrentTimeInNanos() - handle->h.startTime;
623 /* For MidiDeviceHandle* handle, the mutex reference is stored as handle-> */
624 /* queue->lock while the condition variabale reference is stored as handle */