Path: blob/master/src/java.desktop/share/native/libjsound/PlatformMidi.h
41152 views
/*1* Copyright (c) 1999, 2013, 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#ifndef PLATFORM_MIDI_INCLUDED26#define PLATFORM_MIDI_INCLUDED272829#include "SoundDefs.h"30#include "Configure.h" // put flags for debug msgs etc. here31#include "Utilities.h"323334/* do we need the queue ? */35#if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE)36#if X_PLATFORM == X_WINDOWS || X_PLATFORM == X_MACOSX37#define USE_MIDI_QUEUE TRUE38#endif39#endif4041/* *********************** MIDI TYPES (for all platforms) ******************************* */4243/* return value for functions to denote successful completion */44#define MIDI_SUCCESS 045/* code if function is not supported */46#define MIDI_NOT_SUPPORTED -1111147/* return code for invalid handle */48#define MIDI_INVALID_DEVICEID -1111249/* return code for invalid handle */50#define MIDI_INVALID_HANDLE -1111351/* return code for invalid argument */52#define MIDI_INVALID_ARGUMENT -1111453/* return code for out of memory */54#define MIDI_OUT_OF_MEMORY -111155556// MIDI message types57typedef enum {58SHORT_MESSAGE = 0,59LONG_MESSAGE = 160} MidiMessageType;6162// MIDI message object63typedef struct tag_MidiMessage {64INT64 timestamp; // in microseconds65INT32 locked; // TRUE when event is currently being read66MidiMessageType type;67union {68struct {69// platform-endianness packed message:70// status | data1<<8 | data2<<1671UINT32 packedMsg;72} s; // short message73struct {74UINT32 size;75// this buffer is read only. It must not be freed.76UBYTE* data;77INT32 index; // sysex buffer number78} l; // long message79} data;80} MidiMessage;8182/* error handling. Implemented in PlatformMidi.c */83char* MIDI_IN_InternalGetErrorString(INT32 err);84char* MIDI_OUT_InternalGetErrorString(INT32 err);858687#if USE_MIDI_QUEUE == TRUE88/*89* Native MIDI message circular buffer90*/91typedef struct tag_MidiQueue {92void* lock;93INT32 size;94INT32 capacity;95INT32 readIndex;96INT32 writeIndex;97MidiMessage queue[1];98} MidiMessageQueue;99#endif100101// device handle, to be created and filled in MIDI_IN_OpenDevice() and MIDI_OUT_OpenDevice()102typedef struct tag_MidiDeviceHandle {103void* deviceHandle; // handle to the device104void* longBuffers; // contains platform-specific data for long buffers, e.g. list of MIDIHDR105void* platformData; // contains platform specific data, e.g. an Event object106INT32 isWaiting; // if TRUE, then waiting for new events107INT64 startTime; // start time108#if USE_MIDI_QUEUE == TRUE109MidiMessageQueue* queue; // may be NULL if no queue is used110#endif111} MidiDeviceHandle;112113114#if USE_MIDI_QUEUE == TRUE115116/*117* Native Locking support118*/119void* MIDI_CreateLock();120void MIDI_DestroyLock(void* lock);121122/* Blocks until this lock can be gotten.123* Nop if lock is NULL */124void MIDI_Lock(void* lock);125126/* Releases this lock */127void MIDI_Unlock(void* lock);128129MidiMessageQueue* MIDI_CreateQueue(int capacity);130void MIDI_DestroyQueue(MidiMessageQueue* queue);131// if overwrite is true, oldest messages will be overwritten when the queue is full132// returns true, if message has been added133int MIDI_QueueAddShort(MidiMessageQueue* queue, UINT32 packedMsg, INT64 timestamp, int overwrite);134int MIDI_QueueAddLong(MidiMessageQueue* queue, UBYTE* data, UINT32 size,135INT32 sysexIndex, INT64 timestamp, int overwrite);136137// returns NULL if no messages in queue.138MidiMessage* MIDI_QueueRead(MidiMessageQueue* queue);139// message will be removed from queue.140void MIDI_QueueRemove(MidiMessageQueue* queue, INT32 onlyLocked);141void MIDI_QueueClear(MidiMessageQueue* queue);142143#endif /* USE_MIDI_QUEUE */144145146/*147* Platform MIDI IN support.148* deviceId: device-by-number149* deviceHandle: native device handle150*/151152#if USE_PLATFORM_MIDI_IN == TRUE153154// number of messages to be buffered155#define MIDI_IN_MESSAGE_QUEUE_SIZE 64156// number of sysex to be buffered157#define MIDI_IN_LONG_QUEUE_SIZE 20158// maximum number of bytes in one sys ex message159#define MIDI_IN_LONG_MESSAGE_SIZE 1024160161162/*163* Return an error message for the error code164*/165char* MIDI_IN_GetErrorStr(INT32 err);166167168/*169* Get the number of MIDI IN devices on the system.170*/171INT32 MIDI_IN_GetNumDevices();172173/*174* Get the name of the device with this id175* Returns MIDI_SUCCESS or an error code176*/177INT32 MIDI_IN_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength);178179/*180* Get the vendor of the device with this id181* Returns MIDI_SUCCESS or an error code182*/183INT32 MIDI_IN_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength);184185/*186* Get the description of the device with this id187* Returns MIDI_SUCCESS or an error code188*/189INT32 MIDI_IN_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength);190191/*192* Get the version of the device with this id193* Returns MIDI_SUCCESS or an error code194*/195INT32 MIDI_IN_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength);196197/*198* Open the device with this id.199* Returns a device handle in handle*.200* Returns MIDI_SUCCESS or an error code201*/202INT32 MIDI_IN_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle);203204/*205* Close the device handle.206* Returns MIDI_SUCCESS or an error code207*/208INT32 MIDI_IN_CloseDevice(MidiDeviceHandle* handle);209210/*211* Start the device with this handle.212* Returns MIDI_SUCCESS or an error code213*/214INT32 MIDI_IN_StartDevice(MidiDeviceHandle* handle);215216/*217* Stop the device with this handle.218* Returns MIDI_SUCCESS or an error code219*/220INT32 MIDI_IN_StopDevice(MidiDeviceHandle* handle);221222/*223* Return the current time stamp in microseconds.224* If not supported, or problem occurred, returns -1225*/226INT64 MIDI_IN_GetTimeStamp(MidiDeviceHandle* handle);227228/*229* Get the next message from the queue.230* This call blocks until the device is stopped231* or a message is received.232* The returned message is READ ONLY.233* The message will be returned into the message234* queue by calling MIDI_IN_ReleaseMessage.235*/236MidiMessage* MIDI_IN_GetMessage(MidiDeviceHandle* handle);237238/*239* Put a message, which was taken240* out of the queue, back into the queue.241*/242void MIDI_IN_ReleaseMessage(MidiDeviceHandle* handle, MidiMessage* msg);243244#endif // USE_PLATFORM_MIDI_IN245246247/*248* Platform MIDI OUT support.249* deviceId: device-by-number250* deviceHandle: native device handle251*/252253#if USE_PLATFORM_MIDI_OUT == TRUE254255// number of messages to be buffered256#define MIDI_OUT_MESSAGE_QUEUE_SIZE 32257// number of sysex to be buffered258#define MIDI_OUT_LONG_QUEUE_SIZE 16259// maximum number of bytes in one sys ex message260#define MIDI_OUT_LONG_MESSAGE_SIZE 1024261262/*263* Return an error message for the error code264*/265char* MIDI_OUT_GetErrorStr(INT32 err);266267268/*269* Get the number of MIDI OUT devices on the system.270*/271INT32 MIDI_OUT_GetNumDevices();272273/*274* Get the name of the device with this id275* Returns MIDI_SUCCESS or an error code276*/277INT32 MIDI_OUT_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength);278279/*280* Get the vendor of the device with this id281* Returns MIDI_SUCCESS or an error code282*/283INT32 MIDI_OUT_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength);284285/*286* Get the description of the device with this id287* Returns MIDI_SUCCESS or an error code288*/289INT32 MIDI_OUT_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength);290291/*292* Get the version of the device with this id293* Returns MIDI_SUCCESS or an error code294*/295INT32 MIDI_OUT_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength);296297/*298* Open the device with this id.299* Returns a device handle in handle*.300* Returns MIDI_SUCCESS or an error code301*/302INT32 MIDI_OUT_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle);303304/*305* Close the device handle.306* Returns MIDI_SUCCESS or an error code307*/308INT32 MIDI_OUT_CloseDevice(MidiDeviceHandle* handle);309310/*311* Return the current time stamp in microseconds (the time since the device312* was opened).313* If not supported, or problem occurred, returns -1314*/315INT64 MIDI_OUT_GetTimeStamp(MidiDeviceHandle* handle);316317/*318* Send a short message to the hardware.319* packedMsg: (status | data1<<8 | data2<<16) in platform-endianness320* Timestamp is in microseconds.321* Returns MIDI_SUCCESS or an error code322*/323INT32 MIDI_OUT_SendShortMessage(MidiDeviceHandle* handle, UINT32 packedMsg, UINT32 timestamp);324325/*326* Send a long message to the hardware. Timestamp is in microseconds.327* This blocks until a slot to send a message is free.328* Returns MIDI_SUCCESS or an error code329*/330INT32 MIDI_OUT_SendLongMessage(MidiDeviceHandle* handle, UBYTE* data, UINT32 size, UINT32 timestamp);331332#endif // USE_PLATFORM_MIDI_OUT333334#endif // PLATFORM_MIDI_INCLUDED335336337