Path: blob/master/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiUtils.h
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#if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE)2627#include "PlatformMidi.h" // JavaSound header for platform midi support.28#include <CoreMIDI/CoreMIDI.h> // Umbrella header for the CoreMIDI framework.29#include <CoreAudio/CoreAudio.h> // This provides access to the host's time base and translations to nanoseconds.30#include <CoreFoundation/CoreFoundation.h> // CFDataRef.3132/* for memcpy */33#include <string.h>34/* for malloc */35#include <stdlib.h>36/* for usleep */37#include <unistd.h>3839#ifdef USE_ERROR40#include <stdio.h>41#endif4243#define MIDI_ERROR_NONE MIDI_SUCCESS4445#ifdef USE_ERROR46#define MIDI_CHECK_ERROR { if (err != MIDI_ERROR_NONE) MIDI_Utils_PrintError(err); }47#else48#define MIDI_CHECK_ERROR49#endif5051typedef struct {52MidiDeviceHandle h; /* the real handle (must be the first field!) */53int direction; /* direction of the endpoint */54int deviceID; /* logical index (0 .. numEndpoints-1) */55int isStarted; /* whether device is "started" */56MIDIPortRef port; /* input or output port associated with the endpoint */57CFMutableDataRef readingSysExData; /* Non-Null: in the middle of reading SysEx data; Null: otherwise */58} MacMidiDeviceHandle;5960extern const char* MIDI_Utils_GetErrorMsg(int err);61extern void MIDI_Utils_PrintError(int err);6263// A MIDI endpoint represents a source or a destination for a standard 16-channel MIDI data stream.64enum {65MIDI_IN = 0, // source66MIDI_OUT = 1 // destination67};6869// The parameter "direction" is either MIDI_IN or MIDI_OUT.70// Declarations of functions required by the JavaSound MIDI Porting layer.7172extern INT32 MIDI_Utils_GetNumDevices(int direction);73extern INT32 MIDI_Utils_GetDeviceName(int direction, INT32 deviceID, char *name, UINT32 nameLength);74extern INT32 MIDI_Utils_GetDeviceVendor(int direction, INT32 deviceID, char *name, UINT32 nameLength);75extern INT32 MIDI_Utils_GetDeviceDescription(int direction, INT32 deviceID, char *name, UINT32 nameLength);76extern INT32 MIDI_Utils_GetDeviceVersion(int direction, INT32 deviceID, char *name, UINT32 nameLength);77extern INT32 MIDI_Utils_OpenDevice(int direction, INT32 deviceID, MacMidiDeviceHandle** handle,78int num_msgs, int num_long_msgs,79size_t lm_size);80extern INT32 MIDI_Utils_CloseDevice(MacMidiDeviceHandle* handle);81extern INT32 MIDI_Utils_StartDevice(MacMidiDeviceHandle* handle);82extern INT32 MIDI_Utils_StopDevice(MacMidiDeviceHandle* handle);83extern INT64 MIDI_Utils_GetTimeStamp(MacMidiDeviceHandle* handle);8485// Mac OS X port for locking and synchronization.8687extern void* MIDI_CreateConditionVariable();88extern void MIDI_DestroyConditionVariable(void* cond);89extern void MIDI_WaitOnConditionVariable(void* cond, void* lock);90extern void MIDI_SignalConditionVariable(void* cond);9192#endif // USE_PLATFORM_MIDI_IN || USE_PLATFORM_MIDI_OUT939495