Path: blob/master/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiIn.c
41152 views
/*1* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425//#define USE_ERROR26//#define USE_TRACE2728#if USE_PLATFORM_MIDI_IN == TRUE2930#include "PLATFORM_API_MacOSX_MidiUtils.h"3132char* MIDI_IN_GetErrorStr(INT32 err) {33return (char *) MIDI_Utils_GetErrorMsg((int) err);34}353637INT32 MIDI_IN_GetNumDevices() {38return MIDI_Utils_GetNumDevices(MIDI_IN);39}404142INT32 MIDI_IN_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength) {43return MIDI_Utils_GetDeviceName(MIDI_IN, deviceID, name, nameLength);44}454647INT32 MIDI_IN_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength) {48return MIDI_Utils_GetDeviceVendor(MIDI_IN, deviceID, name, nameLength);49}505152INT32 MIDI_IN_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength) {53return MIDI_Utils_GetDeviceDescription(MIDI_IN, deviceID, name, nameLength);54}555657INT32 MIDI_IN_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength) {58return MIDI_Utils_GetDeviceVersion(MIDI_IN, deviceID, name, nameLength);59}606162INT32 MIDI_IN_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle) {63TRACE0("MIDI_IN_OpenDevice\n");64return65MIDI_Utils_OpenDevice(MIDI_IN, deviceID, (MacMidiDeviceHandle**) handle,66MIDI_IN_MESSAGE_QUEUE_SIZE,67MIDI_IN_LONG_QUEUE_SIZE,68MIDI_IN_LONG_MESSAGE_SIZE);69}707172INT32 MIDI_IN_CloseDevice(MidiDeviceHandle* handle) {73TRACE0("MIDI_IN_CloseDevice\n");74return MIDI_Utils_CloseDevice((MacMidiDeviceHandle*) handle);75}767778INT32 MIDI_IN_StartDevice(MidiDeviceHandle* handle) {79TRACE0("MIDI_IN_StartDevice\n");80return MIDI_Utils_StartDevice((MacMidiDeviceHandle*) handle);81}828384INT32 MIDI_IN_StopDevice(MidiDeviceHandle* handle) {85TRACE0("MIDI_IN_StopDevice\n");86return MIDI_Utils_StopDevice((MacMidiDeviceHandle*) handle);87}8889INT64 MIDI_IN_GetTimeStamp(MidiDeviceHandle* handle) {90return MIDI_Utils_GetTimeStamp((MacMidiDeviceHandle*) handle);91}929394/* read the next message from the queue */95MidiMessage* MIDI_IN_GetMessage(MidiDeviceHandle* handle) {96if (handle == NULL) {97return NULL;98}99while (handle->queue != NULL && handle->platformData != NULL) {100MidiMessage* msg = MIDI_QueueRead(handle->queue);101if (msg != NULL) {102//fprintf(stdout, "GetMessage returns index %d\n", msg->data.l.index); fflush(stdout);103return msg;104}105TRACE0("MIDI_IN_GetMessage: before waiting\n");106handle->isWaiting = TRUE;107MIDI_WaitOnConditionVariable(handle->platformData, handle->queue->lock);108handle->isWaiting = FALSE;109TRACE0("MIDI_IN_GetMessage: waiting finished\n");110}111return NULL;112}113114115void MIDI_IN_ReleaseMessage(MidiDeviceHandle* handle, MidiMessage* msg) {116if (handle == NULL || handle->queue == NULL) {117return;118}119MIDI_QueueRemove(handle->queue, TRUE /*onlyLocked*/);120}121122#endif /* USE_PLATFORM_MIDI_IN */123124125