Path: blob/master/src/java.desktop/share/native/libjsound/MidiOutDevice.c
41152 views
/*1* Copyright (c) 1999, 2020, 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/*****************************************************************************/26/*27** Native functions for interfacing Java with the native implementation28** of PlatformMidi.h's functions.29*/30/*****************************************************************************/3132#define USE_ERROR33#define USE_TRACE343536#include <jni.h>37#include "SoundDefs.h"38#include "PlatformMidi.h"39#include "Utilities.h"40#include "com_sun_media_sound_MidiOutDevice.h"414243// NATIVE METHODS444546JNIEXPORT jlong JNICALL47Java_com_sun_media_sound_MidiOutDevice_nOpen(JNIEnv* e, jobject thisObj, jint index) {4849void* deviceHandle = NULL;50INT32 err = MIDI_NOT_SUPPORTED;5152TRACE1("Java_com_sun_media_sound_MidiOutDevice_nOpen: index: %d\n", index);5354#if USE_PLATFORM_MIDI_OUT == TRUE55err = MIDI_OUT_OpenDevice((INT32) index, (MidiDeviceHandle**) (&deviceHandle));56#endif5758// if we didn't get a valid handle, throw a MidiUnavailableException59if (!deviceHandle) {60ERROR0("Java_com_sun_media_sound_MidiOutDevice_nOpen:");61ThrowJavaMessageException(e, JAVA_MIDI_PACKAGE_NAME"/MidiUnavailableException",62MIDI_OUT_InternalGetErrorString(err));63} else {64TRACE0("Java_com_sun_media_sound_MidiOutDevice_nOpen succeeded\n");65}66return (jlong) (INT_PTR) deviceHandle;67}686970JNIEXPORT void JNICALL71Java_com_sun_media_sound_MidiOutDevice_nClose(JNIEnv* e, jobject thisObj, jlong deviceHandle) {7273TRACE0("Java_com_sun_media_sound_MidiOutDevice_nClose.\n");7475#if USE_PLATFORM_MIDI_OUT == TRUE76MIDI_OUT_CloseDevice((MidiDeviceHandle*) (UINT_PTR) deviceHandle);77#endif7879TRACE0("Java_com_sun_media_sound_MidiOutDevice_nClose succeeded\n");80}818283JNIEXPORT jlong JNICALL84Java_com_sun_media_sound_MidiOutDevice_nGetTimeStamp(JNIEnv* e, jobject thisObj, jlong deviceHandle) {8586jlong ret = -1;8788TRACE0("Java_com_sun_media_sound_MidiOutDevice_nGetTimeStamp.\n");8990#if USE_PLATFORM_MIDI_OUT == TRUE91ret = (jlong) MIDI_OUT_GetTimeStamp((MidiDeviceHandle*) (UINT_PTR) deviceHandle);92#endif9394/* Handle error codes. */95if (ret < -1) {96ERROR1("Java_com_sun_media_sound_MidiOutDevice_nGetTimeStamp: MIDI_IN_GetTimeStamp returned %lld\n", ret);97ret = -1;98}99return ret;100}101102103JNIEXPORT void JNICALL104Java_com_sun_media_sound_MidiOutDevice_nSendShortMessage(JNIEnv* e, jobject thisObj, jlong deviceHandle,105jint packedMsg, jlong timeStamp) {106107TRACE0("Java_com_sun_media_sound_MidiOutDevice_nSendShortMessage.\n");108109#if USE_PLATFORM_MIDI_OUT == TRUE110MIDI_OUT_SendShortMessage((MidiDeviceHandle*) (UINT_PTR) deviceHandle,111(UINT32) packedMsg, (UINT32)timeStamp);112#endif113114TRACE0("Java_com_sun_media_sound_MidiOutDevice_nSendShortMessage succeeded\n");115}116117118JNIEXPORT void JNICALL119Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage(JNIEnv* e, jobject thisObj, jlong deviceHandle,120jbyteArray jData, jint size, jlong timeStamp) {121#if USE_PLATFORM_MIDI_OUT == TRUE122UBYTE* data;123#endif124125TRACE0("Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage.\n");126127#if USE_PLATFORM_MIDI_OUT == TRUE128data = (UBYTE*) ((*e)->GetByteArrayElements(e, jData, NULL));129if (!data) {130ERROR0("MidiOutDevice: Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage: could not get array elements\n");131return;132}133/* "continuation" sysex messages start with F7 (instead of F0), but134are sent without the F7. */135if (data[0] == 0xF7 && size > 1) {136data++;137size--;138}139MIDI_OUT_SendLongMessage((MidiDeviceHandle*) (UINT_PTR) deviceHandle, data,140(UINT32) size, (UINT32)timeStamp);141// release the byte array142(*e)->ReleaseByteArrayElements(e, jData, (jbyte*) data, JNI_ABORT);143#endif144145TRACE0("Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage succeeded\n");146}147148149