|
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 //#define USE_ERROR |
|
27 //#define USE_TRACE |
|
28 |
|
29 #if USE_PLATFORM_MIDI_IN == TRUE |
|
30 |
|
31 #include "PLATFORM_API_MacOSX_MidiUtils.h" |
|
32 |
|
33 char* MIDI_IN_GetErrorStr(INT32 err) { |
|
34 return (char *) MIDI_Utils_GetErrorMsg((int) err); |
|
35 } |
|
36 |
|
37 |
|
38 INT32 MIDI_IN_GetNumDevices() { |
|
39 return MIDI_Utils_GetNumDevices(MIDI_IN); |
|
40 } |
|
41 |
|
42 |
|
43 INT32 MIDI_IN_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength) { |
|
44 return MIDI_Utils_GetDeviceName(MIDI_IN, deviceID, name, nameLength); |
|
45 } |
|
46 |
|
47 |
|
48 INT32 MIDI_IN_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength) { |
|
49 return MIDI_Utils_GetDeviceVendor(MIDI_IN, deviceID, name, nameLength); |
|
50 } |
|
51 |
|
52 |
|
53 INT32 MIDI_IN_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength) { |
|
54 return MIDI_Utils_GetDeviceDescription(MIDI_IN, deviceID, name, nameLength); |
|
55 } |
|
56 |
|
57 |
|
58 INT32 MIDI_IN_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength) { |
|
59 return MIDI_Utils_GetDeviceVersion(MIDI_IN, deviceID, name, nameLength); |
|
60 } |
|
61 |
|
62 |
|
63 INT32 MIDI_IN_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle) { |
|
64 TRACE0("MIDI_IN_OpenDevice\n"); |
|
65 return |
|
66 MIDI_Utils_OpenDevice(MIDI_IN, deviceID, (MacMidiDeviceHandle**) handle, |
|
67 MIDI_IN_MESSAGE_QUEUE_SIZE, |
|
68 MIDI_IN_LONG_QUEUE_SIZE, |
|
69 MIDI_IN_LONG_MESSAGE_SIZE); |
|
70 } |
|
71 |
|
72 |
|
73 INT32 MIDI_IN_CloseDevice(MidiDeviceHandle* handle) { |
|
74 TRACE0("MIDI_IN_CloseDevice\n"); |
|
75 return MIDI_Utils_CloseDevice((MacMidiDeviceHandle*) handle); |
|
76 } |
|
77 |
|
78 |
|
79 INT32 MIDI_IN_StartDevice(MidiDeviceHandle* handle) { |
|
80 TRACE0("MIDI_IN_StartDevice\n"); |
|
81 return MIDI_Utils_StartDevice((MacMidiDeviceHandle*) handle); |
|
82 } |
|
83 |
|
84 |
|
85 INT32 MIDI_IN_StopDevice(MidiDeviceHandle* handle) { |
|
86 TRACE0("MIDI_IN_StopDevice\n"); |
|
87 return MIDI_Utils_StopDevice((MacMidiDeviceHandle*) handle); |
|
88 } |
|
89 |
|
90 INT64 MIDI_IN_GetTimeStamp(MidiDeviceHandle* handle) { |
|
91 return MIDI_Utils_GetTimeStamp((MacMidiDeviceHandle*) handle); |
|
92 } |
|
93 |
|
94 |
|
95 /* read the next message from the queue */ |
|
96 MidiMessage* MIDI_IN_GetMessage(MidiDeviceHandle* handle) { |
|
97 if (handle == NULL) { |
|
98 return NULL; |
|
99 } |
|
100 while (handle->queue != NULL && handle->platformData != NULL) { |
|
101 MidiMessage* msg = MIDI_QueueRead(handle->queue); |
|
102 if (msg != NULL) { |
|
103 //fprintf(stdout, "GetMessage returns index %d\n", msg->data.l.index); fflush(stdout); |
|
104 return msg; |
|
105 } |
|
106 TRACE0("MIDI_IN_GetMessage: before waiting\n"); |
|
107 handle->isWaiting = TRUE; |
|
108 MIDI_WaitOnConditionVariable(handle->platformData, handle->queue->lock); |
|
109 handle->isWaiting = FALSE; |
|
110 TRACE0("MIDI_IN_GetMessage: waiting finished\n"); |
|
111 } |
|
112 return NULL; |
|
113 } |
|
114 |
|
115 |
|
116 void MIDI_IN_ReleaseMessage(MidiDeviceHandle* handle, MidiMessage* msg) { |
|
117 if (handle == NULL || handle->queue == NULL) { |
|
118 return; |
|
119 } |
|
120 MIDI_QueueRemove(handle->queue, TRUE /*onlyLocked*/); |
|
121 } |
|
122 |
|
123 #endif /* USE_PLATFORM_MIDI_IN */ |