1/* 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26#if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE) 27 28#include "PlatformMidi.h" // JavaSound header for platform midi support. 29#include <CoreMIDI/CoreMIDI.h> // Umbrella header for the CoreMIDI framework. 30#include <CoreAudio/CoreAudio.h> // This provides access to the host's time base and translations to nanoseconds. 31#include <CoreFoundation/CoreFoundation.h> // CFDataRef. 32 33/* for memcpy */ 34#include <string.h> 35/* for malloc */ 36#include <stdlib.h> 37/* for usleep */ 38#include <unistd.h> 39 40#ifdef USE_ERROR 41#include <stdio.h> 42#endif 43 44#define MIDI_ERROR_NONE MIDI_SUCCESS 45 46#ifdef USE_ERROR 47#define MIDI_CHECK_ERROR { if (err != MIDI_ERROR_NONE) MIDI_Utils_PrintError(err); } 48#else 49#define MIDI_CHECK_ERROR 50#endif 51 52typedef struct { 53 MidiDeviceHandle h; /* the real handle (must be the first field!) */ 54 int direction; /* direction of the endpoint */ 55 int deviceID; /* logical index (0 .. numEndpoints-1) */ 56 int isStarted; /* whether device is "started" */ 57 MIDIPortRef port; /* input or output port associated with the endpoint */ 58 CFMutableDataRef readingSysExData; /* Non-Null: in the middle of reading SysEx data; Null: otherwise */ 59} MacMidiDeviceHandle; 60 61extern const char* MIDI_Utils_GetErrorMsg(int err); 62extern void MIDI_Utils_PrintError(int err); 63 64// A MIDI endpoint represents a source or a destination for a standard 16-channel MIDI data stream. 65enum { 66 MIDI_IN = 0, // source 67 MIDI_OUT = 1 // destination 68}; 69 70// The parameter "direction" is either MIDI_IN or MIDI_OUT. 71// Declarations of functions required by the JavaSound MIDI Porting layer. 72 73extern INT32 MIDI_Utils_GetNumDevices(int direction); 74extern INT32 MIDI_Utils_GetDeviceName(int direction, INT32 deviceID, char *name, UINT32 nameLength); 75extern INT32 MIDI_Utils_GetDeviceVendor(int direction, INT32 deviceID, char *name, UINT32 nameLength); 76extern INT32 MIDI_Utils_GetDeviceDescription(int direction, INT32 deviceID, char *name, UINT32 nameLength); 77extern INT32 MIDI_Utils_GetDeviceVersion(int direction, INT32 deviceID, char *name, UINT32 nameLength); 78extern INT32 MIDI_Utils_OpenDevice(int direction, INT32 deviceID, MacMidiDeviceHandle** handle, 79 int num_msgs, int num_long_msgs, 80 size_t lm_size); 81extern INT32 MIDI_Utils_CloseDevice(MacMidiDeviceHandle* handle); 82extern INT32 MIDI_Utils_StartDevice(MacMidiDeviceHandle* handle); 83extern INT32 MIDI_Utils_StopDevice(MacMidiDeviceHandle* handle); 84extern INT64 MIDI_Utils_GetTimeStamp(MacMidiDeviceHandle* handle); 85 86// Mac OS X port for locking and synchronization. 87 88extern void* MIDI_CreateConditionVariable(); 89extern void MIDI_DestroyConditionVariable(void* cond); 90extern void MIDI_WaitOnConditionVariable(void* cond, void* lock); 91extern void MIDI_SignalConditionVariable(void* cond); 92 93#endif // USE_PLATFORM_MIDI_IN || USE_PLATFORM_MIDI_OUT 94