/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*****************************************************************************/
/*
** Native functions for interfacing Java with the native implementation
** of PlatformMidi.h's functions.
*/
/*****************************************************************************/
#define USE_ERROR
#define USE_TRACE
#include <jni.h>
/* for memcpy */
#include <string.h>
#include "SoundDefs.h"
#include "PlatformMidi.h"
#include "com_sun_media_sound_MidiInDevice.h"
#if USE_PLATFORM_MIDI_IN == TRUE
#endif
/* $$mp 2003-08-28:
So far, the return value (err) hasn't been taken into account.
Now, it is also expected to be MIDI_SUCCESS (0).
This works for Linux, but has to be checked on other platforms.
It would be better to settle on one method of signaling error:
either returned error codes or a NULL handle. If the latter is used,
the return value should be removed from the signature of
MIDI_IN_OpenDevice.
*/
// if we didn't get a valid handle, throw a MidiUnavailableException
deviceHandle = NULL;
ERROR0("Java_com_sun_media_sound_MidiInDevice_nOpen: ");
} else {
TRACE0("< Java_com_sun_media_sound_MidiInDevice_nOpen succeeded\n");
}
}
TRACE0("> Java_com_sun_media_sound_MidiInDevice_nClose.\n");
#if USE_PLATFORM_MIDI_IN == TRUE
#endif
TRACE0("< Java_com_sun_media_sound_MidiInDevice_nClose succeeded\n");
}
TRACE0("> Java_com_sun_media_sound_MidiInDevice_nStart.\n");
#if USE_PLATFORM_MIDI_IN == TRUE
#endif
if (err != MIDI_SUCCESS) {
ERROR0("Java_com_sun_media_sound_MidiInDevice_nStart: ");
} else {
TRACE0("< Java_com_sun_media_sound_MidiInDevice_nStart succeeded\n");
}
}
TRACE0("> Java_com_sun_media_sound_MidiInDevice_nStop.\n");
#if USE_PLATFORM_MIDI_IN == TRUE
// stop the device and remove all queued events for this device handle
#endif
TRACE0("< Java_com_sun_media_sound_MidiInDevice_nStop succeeded\n");
}
Java_com_sun_media_sound_MidiInDevice_nGetTimeStamp(JNIEnv* e, jobject thisObj, jlong deviceHandle) {
TRACE0("Java_com_sun_media_sound_MidiInDevice_nGetTimeStamp.\n");
#if USE_PLATFORM_MIDI_IN == TRUE
#endif
/* Handle error codes. */
if (ret < -1) {
ERROR1("Java_com_sun_media_sound_MidiInDevice_nGetTimeStamp: MIDI_IN_GetTimeStamp returned %lld\n", ret);
ret = -1;
}
return ret;
}
Java_com_sun_media_sound_MidiInDevice_nGetMessages(JNIEnv* e, jobject thisObj, jlong deviceHandle) {
#if USE_PLATFORM_MIDI_IN == TRUE
#endif
TRACE0("> Java_com_sun_media_sound_MidiInDevice_nGetMessages\n");
#if USE_PLATFORM_MIDI_IN == TRUE
if (!thisObj) {
ERROR0("MidiInDevice: Java_com_sun_media_sound_MidiInDevice_nGetMessages: thisObj is NULL\n");
return;
}
ERROR0("MidiInDevice: Java_com_sun_media_sound_MidiInDevice_nGetMessages: javaClass is NULL\n");
return;
}
}
if (callbackShortMessageMethodID == NULL) {
// save the callbackShortMessage callback method id.
// this is valid as long as the class is not unloaded.
if (callbackShortMessageMethodID == 0) {
ERROR0("MidiInDevice: Java_com_sun_media_sound_MidiInDevice_nGetMessages: callbackShortMessageMethodID is 0\n");
return;
}
}
if (callbackLongMessageMethodID == NULL) {
// save the callbackLongMessage callback method id.
// this is valid as long as the class is not unloaded.
if (callbackLongMessageMethodID == 0) {
ERROR0("MidiInDevice: Java_com_sun_media_sound_MidiInDevice_nGetMessages: callbackLongMessageMethodID is 0\n");
return;
}
}
}
case SHORT_MESSAGE: {
TRACE0("Java_com_sun_media_sound_MidiInDevice_nGetMessages: got SHORT_MESSAGE\n");
// now we can put this message object back in the queue
// and notify Java space
break;
}
case LONG_MESSAGE: {
int isSXCont = 0;
TRACE0("Java_com_sun_media_sound_MidiInDevice_nGetMessages: got LONG_MESSAGE\n");
// this is a continued sys ex message
// need to prepend 0xF7
isSXCont = 1;
}
if (!jData) {
ERROR0("Java_com_sun_media_sound_MidiInDevice_nGetMessages: cannot create long byte array.\n");
break;
}
if (!data) {
ERROR0("MidiInDevice: Java_com_sun_media_sound_MidiInDevice_nGetMessages: array data is NULL\n");
break;
}
// finally copy the long message
// now we can put this message object back in the queue
// if this is a patched continued sys ex message, prepend 0xF7
if (isSXCont) {
*data = 0xF7;
}
// commit the byte array
// release local reference to array: not needed anymore.
(*e)->DeleteLocalRef(e, jData);
break;
}
default:
// put this message object back in the queue
ERROR1("Java_com_sun_media_sound_MidiInDevice_nGetMessages: got unsupported message, type %d\n", pMessage->type);
break;
} // switch
}
#endif // USE_PLATFORM_MIDI_IN
TRACE0("< Java_com_sun_media_sound_MidiInDevice_nGetMessages returning\n");
}