/*
* 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.
*/
#define USE_ERROR
#define USE_TRACE
#include "PLATFORM_API_WinOS_Util.h"
#if USE_PLATFORM_MIDI_OUT == TRUE
#ifdef USE_ERROR
#include <stdio.h>
#define MIDIOUT_CHECK_ERROR { \
if (err != MMSYSERR_NOERROR) \
}
#else
#define MIDIOUT_CHECK_ERROR
#endif
/* *************************** MidiOutDeviceProvider implementation *********************************** */
/* not thread safe */
winMidiOutErrMsg[0] = 0;
return winMidiOutErrMsg;
}
// add one for the MIDI_MAPPER
// we want to return it first so it'll be the default, so we
// decrement each deviceID for these methods....
}
if (deviceID == 0) {
} else {
deviceID--;
}
return ((*err) == MMSYSERR_NOERROR);
}
return MIDI_SUCCESS;
}
return err;
}
return MIDI_NOT_SUPPORTED;
}
char *desc;
switch(tech) {
case MOD_MIDIPORT:
desc = "External MIDI Port";
break;
case MOD_SQSYNTH:
desc = "Internal square wave synthesizer";
break;
case MOD_FMSYNTH:
desc = "Internal FM synthesizer";
break;
case MOD_SYNTH:
desc = "Internal synthesizer (generic)";
break;
case MOD_MAPPER:
desc = "Windows MIDI_MAPPER";
break;
case 7 /* MOD_SWSYNTH*/:
desc = "Internal software synthesizer";
break;
default:
return MIDI_NOT_SUPPORTED;
}
return MIDI_SUCCESS;
}
return err;
}
sprintf(name, "%d.%d", (midiOutCaps.vDriverVersion & 0xFF00) >> 8, midiOutCaps.vDriverVersion & 0xFF);
return MIDI_SUCCESS;
}
return err;
}
/* *************************** MidiOutDevice implementation ***************************************** */
int i;
ERROR0("MIDI_OUT_unprepareLongBuffers: handle, deviceHandle, or longBuffers == NULL\n");
return MIDI_INVALID_HANDLE;
}
}
}
}
if (!hdr) {
ERROR0("MIDI_OUT_freeLongBuffer: hdr == NULL\n");
return MIDI_INVALID_HANDLE;
}
}
hdr->dwBufferLength=0;
}
hdr->dwBytesRecorded=0;
}
int i;
ERROR0("MIDI_OUT_freeLongBuffers: handle or longBuffers == NULL\n");
return MIDI_INVALID_HANDLE;
}
}
}
if (deviceID == 0) {
} else {
deviceID--;
}
#ifdef USE_ERROR
#endif
if (!(*handle)) {
ERROR0("ERROR: MIDI_OUT_OpenDevice: out of memory\n");
return MIDI_OUT_OF_MEMORY;
}
// create long buffer queue
ERROR0("ERROR: MIDI_OUT_OpenDevice: could not create long Buffers\n");
return MIDI_OUT_OF_MEMORY;
}
// create notification event
(*handle)->platformData = (void*) CreateEvent(NULL, FALSE /*manual reset*/, FALSE /*signaled*/, NULL);
if (!(*handle)->platformData) {
ERROR0("ERROR: MIDI_OUT_StartDevice: could not create event\n");
return MIDI_OUT_OF_MEMORY;
}
// finally open the device
/* some devices return non zero, but no error! */
}
}
//$$fb enable high resolution time
timeBeginPeriod(1);
TRACE0("<< MIDI_OUT_OpenDevice: succeeded\n");
return MIDI_SUCCESS;
}
TRACE0("> MIDI_OUT_CloseDevice\n");
if (!handle) {
ERROR0("ERROR: MIDI_OUT_StopDevice: handle is NULL\n");
return MIDI_INVALID_HANDLE; // failure
}
// encourage MIDI_OUT_SendLongMessage to return soon
if (event) {
} else {
ERROR0("ERROR: MIDI_OUT_StopDevice: event is NULL\n");
}
if (handle->deviceHandle) {
//$$fb disable high resolution time
timeEndPeriod(1);
} else {
ERROR0("ERROR: MIDI_OUT_CloseDevice: deviceHandle is NULL\n");
}
// issue a "SUSTAIN OFF" message to each MIDI channel, 0 to 15.
// "CONTROL CHANGE" is 176, "SUSTAIN CONTROLLER" is 64, and the value is 0.
// $$fb 2002-04-04: It is responsability of the application developer to
// leave the device in a consistent state. So I put this in comments
/*
for (channel = 0; channel < 16; channel++)
MIDI_OUT_SendShortMessage(deviceHandle, (unsigned char)(176 + channel), (unsigned char)64, (unsigned char)0, (UINT32)-1);
*/
if (event) {
// wait until MIDI_OUT_SendLongMessage has finished
}
if (handle->deviceHandle) {
}
if (event) {
}
TRACE0("< MIDI_OUT_CloseDevice\n");
}
/* return time stamp in microseconds */
return MIDI_GetTimeStamp(handle);
}
if (!handle) {
ERROR0("ERROR: MIDI_OUT_SendShortMessage: handle is NULL\n");
return MIDI_INVALID_HANDLE; // failure
}
TRACE0("< MIDI_OUT_SendShortMessage\n");
}
INT32 MIDI_OUT_SendLongMessage(MidiDeviceHandle* handle, UBYTE* data, UINT32 size, UINT32 timestamp) {
int i;
ERROR0("< ERROR: MIDI_OUT_SendLongMessage: handle, data, or longBuffers is NULL\n");
return MIDI_INVALID_HANDLE; // failure
}
if (size == 0) {
return MIDI_SUCCESS;
}
// send in chunks of 512 bytes
size = 512;
while (remainingSize > 0) {
}
/* find a non-queued header */
break;
}
}
/* wait for a buffer to free up */
TRACE0(" Need to wait for free buffer\n");
if (res == WAIT_TIMEOUT) {
// break out back to Java if no buffer freed up after 700 milliseconds
TRACE0("-> TIMEOUT. Need to go back to Java\n");
break;
}
}
}
if (!hdr) {
// no free buffer
return MIDI_NOT_SUPPORTED;
}
}
if (err != MMSYSERR_NOERROR) {
}
if (err != MMSYSERR_NOERROR) {
ERROR0("ERROR: MIDI_OUT_SendLongMessage: midiOutLongMsg returned error:\n");
}
remainingSize -= size;
}
TRACE0("< MIDI_OUT_SendLongMessage success\n");
return MIDI_SUCCESS;
}
#endif // USE_PLATFORM_MIDI_OUT