src/java.desktop/windows/native/libjsound/PLATFORM_API_WinOS_MidiOut.c
author aivanov
Wed, 30 Oct 2019 14:08:07 +0000
changeset 58859 3fc5905f2bec
parent 52161 f1b6c4079be0
permissions -rw-r--r--
8232724: Remove indirection with calling JNU_NewStringPlatform Reviewed-by: dholmes, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 13678
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#define USE_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define USE_TRACE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "PLATFORM_API_WinOS_Util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
47191
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
    31
/* include to prevent charset problem */
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
    32
#include "PLATFORM_API_WinOS_Charset_Util.h"
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
    33
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#if USE_PLATFORM_MIDI_OUT == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#ifdef USE_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <stdio.h>
13678
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    39
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    40
/* Use THIS_FILE when it is available. */
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    41
#ifndef THIS_FILE
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    42
    #define THIS_FILE __FILE__
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    43
#endif
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define MIDIOUT_CHECK_ERROR  { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        if (err != MMSYSERR_NOERROR) \
13678
5c8001201f98 7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents: 5506
diff changeset
    47
            ERROR3("MIDI OUT Error in %s:%d : %s\n", THIS_FILE, __LINE__, MIDI_OUT_GetErrorStr((INT32) err)); \
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define MIDIOUT_CHECK_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/* *************************** MidiOutDeviceProvider implementation *********************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* not thread safe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static char winMidiOutErrMsg[WIN_MAX_ERROR_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
char* MIDI_OUT_GetErrorStr(INT32 err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    winMidiOutErrMsg[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    midiOutGetErrorText((MMRESULT) err, winMidiOutErrMsg, WIN_MAX_ERROR_LEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    return winMidiOutErrMsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
INT32 MIDI_OUT_GetNumDevices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // add one for the MIDI_MAPPER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // we want to return it first so it'll be the default, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // decrement each deviceID for these methods....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    return (INT32) (midiOutGetNumDevs() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
47191
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
    72
INT32 getMidiOutCaps(INT32 deviceID, MIDIOUTCAPSW* caps, INT32* err) {
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
    73
    UINT_PTR id;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if (deviceID == 0) {
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
    75
        id = MIDI_MAPPER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    } else {
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
    77
        id = (UINT_PTR)(deviceID-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
    79
    (*err) = (INT32) midiOutGetDevCapsW(id, caps, sizeof(MIDIOUTCAPSW));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    return ((*err) == MMSYSERR_NOERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
INT32 MIDI_OUT_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength) {
47191
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
    85
    MIDIOUTCAPSW midiOutCaps;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    INT32 err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
    88
    memset(&midiOutCaps, 0, sizeof(midiOutCaps));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    if (getMidiOutCaps(deviceID, &midiOutCaps, &err)) {
47191
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
    90
        UnicodeToUTF8AndCopy(name, midiOutCaps.szPname, nameLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return MIDI_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
INT32 MIDI_OUT_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    return MIDI_NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
INT32 MIDI_OUT_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength) {
47191
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
   104
    MIDIOUTCAPSW midiOutCaps;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    char *desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    INT32 err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
   108
    memset(&midiOutCaps, 0, sizeof(midiOutCaps));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (getMidiOutCaps(deviceID, &midiOutCaps, &err)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int tech = (int)midiOutCaps.wTechnology;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        switch(tech) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        case MOD_MIDIPORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            desc = "External MIDI Port";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        case MOD_SQSYNTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            desc = "Internal square wave synthesizer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        case MOD_FMSYNTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            desc = "Internal FM synthesizer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        case MOD_SYNTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            desc = "Internal synthesizer (generic)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        case MOD_MAPPER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            desc = "Windows MIDI_MAPPER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        case 7 /* MOD_SWSYNTH*/:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            desc = "Internal software synthesizer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return MIDI_NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        strncpy(name, desc, nameLength-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        name[nameLength-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return MIDI_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
INT32 MIDI_OUT_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength) {
47191
8c95ea7056b7 8177951: Charset problem when the name of the sound device contains Chinese character
serb
parents: 25859
diff changeset
   142
    MIDIOUTCAPSW midiOutCaps;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    INT32 err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
52161
f1b6c4079be0 8200648: Make midi code more sound
prr
parents: 47216
diff changeset
   145
    memset(&midiOutCaps, 0, sizeof(midiOutCaps));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    if (getMidiOutCaps(deviceID, &midiOutCaps, &err) && nameLength>7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        sprintf(name, "%d.%d", (midiOutCaps.vDriverVersion & 0xFF00) >> 8, midiOutCaps.vDriverVersion & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return MIDI_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
/* *************************** MidiOutDevice implementation ***************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
INT32 unprepareLongBuffers(MidiDeviceHandle* handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    SysExQueue* sysex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    MMRESULT err = MMSYSERR_NOERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    if (!handle || !handle->deviceHandle || !handle->longBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        ERROR0("MIDI_OUT_unprepareLongBuffers: handle, deviceHandle, or longBuffers == NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return MIDI_INVALID_HANDLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    sysex = (SysExQueue*) handle->longBuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    for (i = 0; i<sysex->count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        MIDIHDR* hdr = &(sysex->header[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (hdr->dwFlags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            err = midiOutUnprepareHeader((HMIDIOUT) handle->deviceHandle, hdr, sizeof(MIDIHDR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
INT32 freeLongBuffer(MIDIHDR* hdr, HMIDIOUT deviceHandle, INT32 minToLeaveData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    MMRESULT err = MMSYSERR_NOERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    if (!hdr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        ERROR0("MIDI_OUT_freeLongBuffer: hdr == NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return MIDI_INVALID_HANDLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (hdr->dwFlags && deviceHandle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        err = midiOutUnprepareHeader(deviceHandle, hdr, sizeof(MIDIHDR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if (hdr->lpData && (((INT32) hdr->dwBufferLength) < minToLeaveData || minToLeaveData < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        free(hdr->lpData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        hdr->lpData=NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        hdr->dwBufferLength=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    hdr->dwBytesRecorded=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    hdr->dwFlags=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
INT32 freeLongBuffers(MidiDeviceHandle* handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    SysExQueue* sysex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    MMRESULT err = MMSYSERR_NOERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    if (!handle || !handle->longBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        ERROR0("MIDI_OUT_freeLongBuffers: handle or longBuffers == NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return MIDI_INVALID_HANDLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    sysex = (SysExQueue*) handle->longBuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    for (i = 0; i<sysex->count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        err = freeLongBuffer(&(sysex->header[i]), (HMIDIOUT) handle->deviceHandle, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
INT32 MIDI_OUT_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    MMRESULT err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    TRACE1(">> MIDI_OUT_OpenDevice: deviceID: %d\n", deviceID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    if (deviceID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        deviceID = MIDI_MAPPER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        deviceID--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
#ifdef USE_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    setvbuf(stdout, NULL, (int)_IONBF, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    setvbuf(stderr, NULL, (int)_IONBF, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    (*handle) = (MidiDeviceHandle*) malloc(sizeof(MidiDeviceHandle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (!(*handle)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        ERROR0("ERROR: MIDI_OUT_OpenDevice: out of memory\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return MIDI_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    memset(*handle, 0, sizeof(MidiDeviceHandle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    // create long buffer queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (!MIDI_WinCreateEmptyLongBufferQueue(*handle, MIDI_OUT_LONG_QUEUE_SIZE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        ERROR0("ERROR: MIDI_OUT_OpenDevice: could not create long Buffers\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        free(*handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        (*handle) = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return MIDI_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    // create notification event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    (*handle)->platformData = (void*) CreateEvent(NULL, FALSE /*manual reset*/, FALSE /*signaled*/, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (!(*handle)->platformData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        ERROR0("ERROR: MIDI_OUT_StartDevice: could not create event\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        MIDI_WinDestroyLongBufferQueue(*handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        free(*handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        (*handle) = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return MIDI_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    // finally open the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    err = midiOutOpen((HMIDIOUT*) &((*handle)->deviceHandle), deviceID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                      (UINT_PTR) (*handle)->platformData, (UINT_PTR) (*handle), CALLBACK_EVENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    if ((err != MMSYSERR_NOERROR) || (!(*handle)->deviceHandle)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        /* some devices return non zero, but no error! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (midiOutShortMsg((HMIDIOUT) ((*handle)->deviceHandle),0) == MMSYSERR_INVALHANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            CloseHandle((HANDLE) (*handle)->platformData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            MIDI_WinDestroyLongBufferQueue(*handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            free(*handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            (*handle) = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    //$$fb enable high resolution time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    timeBeginPeriod(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    MIDI_SetStartTime(*handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    TRACE0("<< MIDI_OUT_OpenDevice: succeeded\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return MIDI_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
INT32 MIDI_OUT_CloseDevice(MidiDeviceHandle* handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    MMRESULT err = MMSYSERR_NOERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    HANDLE event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    TRACE0("> MIDI_OUT_CloseDevice\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    if (!handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        ERROR0("ERROR: MIDI_OUT_StopDevice: handle is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return MIDI_INVALID_HANDLE; // failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    // encourage MIDI_OUT_SendLongMessage to return soon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    event = handle->platformData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    handle->platformData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    if (event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        SetEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        ERROR0("ERROR: MIDI_OUT_StopDevice: event is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if (handle->deviceHandle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        //$$fb disable high resolution time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        timeEndPeriod(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        err = midiOutReset((HMIDIOUT) handle->deviceHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        ERROR0("ERROR: MIDI_OUT_CloseDevice: deviceHandle is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    // issue a "SUSTAIN OFF" message to each MIDI channel, 0 to 15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    // "CONTROL CHANGE" is 176, "SUSTAIN CONTROLLER" is 64, and the value is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    // $$fb 2002-04-04: It is responsability of the application developer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    // leave the device in a consistent state. So I put this in comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
      for (channel = 0; channel < 16; channel++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      MIDI_OUT_SendShortMessage(deviceHandle, (unsigned char)(176 + channel), (unsigned char)64, (unsigned char)0, (UINT32)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    if (event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // wait until MIDI_OUT_SendLongMessage has finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        while (handle->isWaiting) Sleep(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    unprepareLongBuffers(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    if (handle->deviceHandle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        err = midiOutClose((HMIDIOUT) handle->deviceHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        handle->deviceHandle = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    freeLongBuffers(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        CloseHandle(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    MIDI_WinDestroyLongBufferQueue(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    free(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    TRACE0("< MIDI_OUT_CloseDevice\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
/* return time stamp in microseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
INT64 MIDI_OUT_GetTimeStamp(MidiDeviceHandle* handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    return MIDI_GetTimeStamp(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
INT32 MIDI_OUT_SendShortMessage(MidiDeviceHandle* handle, UINT32 packedMsg, UINT32 timestamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    MMRESULT err = MMSYSERR_NOERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    TRACE2("> MIDI_OUT_SendShortMessage %x, time: %d\n", packedMsg, timestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    if (!handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        ERROR0("ERROR: MIDI_OUT_SendShortMessage: handle is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return MIDI_INVALID_HANDLE; // failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    err = midiOutShortMsg((HMIDIOUT) handle->deviceHandle, packedMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    TRACE0("< MIDI_OUT_SendShortMessage\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
INT32 MIDI_OUT_SendLongMessage(MidiDeviceHandle* handle, UBYTE* data, UINT32 size, UINT32 timestamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    MMRESULT err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    SysExQueue* sysex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    MIDIHDR* hdr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    INT32 remainingSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    TRACE2("> MIDI_OUT_SendLongMessage size %d, time: %d\n", size, timestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    if (!handle || !data || !handle->longBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        ERROR0("< ERROR: MIDI_OUT_SendLongMessage: handle, data, or longBuffers is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return MIDI_INVALID_HANDLE; // failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    if (size == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return MIDI_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    sysex = (SysExQueue*) handle->longBuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    remainingSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    // send in chunks of 512 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    size = 512;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    while (remainingSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (remainingSize < (INT32) size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            size = (UINT32) remainingSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        while (!hdr && handle->platformData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            /* find a non-queued header */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            for (i = 0; i < sysex->count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                hdr = &(sysex->header[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                if ((hdr->dwFlags & MHDR_DONE) || (hdr->dwFlags == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                hdr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            /* wait for a buffer to free up */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if (!hdr && handle->platformData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                DWORD res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                TRACE0(" Need to wait for free buffer\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                handle->isWaiting = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                res = WaitForSingleObject((HANDLE) handle->platformData, 700);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                handle->isWaiting = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                if (res == WAIT_TIMEOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    // break out back to Java if no buffer freed up after 700 milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    TRACE0("-> TIMEOUT. Need to go back to Java\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (!hdr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            // no free buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            return MIDI_NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        TRACE2("-> sending %d bytes with buffer index=%d\n", (int) size, (int) hdr->dwUser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        freeLongBuffer(hdr, handle->deviceHandle, (INT32) size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (hdr->lpData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            hdr->lpData = malloc(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            hdr->dwBufferLength = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        hdr->dwBytesRecorded = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        memcpy(hdr->lpData, data, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        err = midiOutPrepareHeader((HMIDIOUT) handle->deviceHandle, hdr, sizeof(MIDIHDR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (err != MMSYSERR_NOERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            freeLongBuffer(hdr, handle->deviceHandle, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        err = midiOutLongMsg((HMIDIOUT) handle->deviceHandle, hdr, sizeof(MIDIHDR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (err != MMSYSERR_NOERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            freeLongBuffer(hdr, handle->deviceHandle, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            ERROR0("ERROR: MIDI_OUT_SendLongMessage: midiOutLongMsg returned error:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            MIDIOUT_CHECK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            return (INT32) err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        remainingSize -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        data += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    TRACE0("< MIDI_OUT_SendLongMessage success\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    return MIDI_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
#endif // USE_PLATFORM_MIDI_OUT