uco
11-19-2006, 12:08 PM
I'm writting a program for the GT-8 and I'm a bit lost...
This code runs fine except on midiOutClose() garbage is send to midi device!? When I run it without midiOutClose() the sysex message is send as it should be, but the mididevice is not closed correctly.... and garbage is sent after the message seems to be random midi...
I'm out in the dark....
Follow code depends on: winmm.lib
Source:
#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
void PrintMidiOutErrorMsg(unsigned long err)
{
#define BUFFERSIZE 128
WCHAR errMsg[BUFFERSIZE];
if (!(err = midiOutGetErrorText(err, &errMsg[0], BUFFERSIZE)))
{
printf("%s\r\n", &errMsg[0]);
}
else if (err == MMSYSERR_BADERRNUM)
{
printf("Strange error number returned!\r\n");
}
else
{
printf("Specified pointer is invalid!\r\n");
}
}
int main()
{
HMIDIOUT handle;
MIDIHDR midiHdr;
UINT err;
const BYTE sysEx[] = {0xF0, 0x41, 0x00, 0x00, 0x00, 0x06, 0x12, 0x0D, 0x00, 0x12, 0x00,
0x53, 0x79, 0x73, 0x65, 0x78, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x47, 0xF7};
int i;
if (!(err = midiOutOpen(&handle, (UINT)5, 0, 0, CALLBACK_NULL)))
{
err = 0;
midiHdr.lpData = (LPSTR) sysEx;
midiHdr.dwBufferLength = (DWORD) sizeof(sysEx);
midiHdr.dwFlags = 0;
err = midiOutPrepareHeader(handle, &midiHdr, sizeof(MIDIHDR));
if (!err)
{
cout << "Sending system exclusive MIDI message (Sysex):" << endl;
cout << "sysEx value: " << endl;
for(i=0;i<sizeof(sysEx);i++)
{
printf ("%X ",sysEx[i]);
}
cout << "sysEx size: " << sizeof(sysEx) << " Bytes" << endl;
err = midiOutLongMsg(handle, &midiHdr, sizeof(MIDIHDR));
if (err)
{
PrintMidiOutErrorMsg(err);
}
while (MIDIERR_STILLPLAYING == midiOutUnprepareHeader(handle, &midiHdr, sizeof(MIDIHDR)))
{
Sleep(1000);
}
}
else
{
PrintMidiOutErrorMsg(err);
}
midiOutClose(handle);
}
else
{
printf("Error opening default MIDI Out device!\r\n");
PrintMidiOutErrorMsg(err);
}
printf("\r\n");
system("PAUSE");
return 0;
}
Message sent:
0000B84D 2 4 F0 Buffer: 17 Bytes System Exclusive
SYSX: F0 41 00 00 00 06 11 0D 00 00 00 00 00 1F 00 55 F7
What follows is send on the call of midiOutClose():
00012B2F 2 4 B0 40 00 1 --- CC: Pedal (Sustain)
00012B2F 2 4 B1 40 00 2 --- CC: Pedal (Sustain)
00012B30 2 4 B2 40 00 3 --- CC: Pedal (Sustain)
00012B30 2 4 B3 40 00 4 --- CC: Pedal (Sustain)
00012B30 2 4 B4 40 00 5 --- CC: Pedal (Sustain)
00012B30 2 4 B5 40 00 6 --- CC: Pedal (Sustain)
00012B30 2 4 B6 40 00 7 --- CC: Pedal (Sustain)
00012B31 2 4 B7 40 00 8 --- CC: Pedal (Sustain)
00012B32 2 4 B8 40 00 9 --- CC: Pedal (Sustain)
00012B32 2 4 B9 40 00 10 --- CC: Pedal (Sustain)
00012B32 2 4 BA 40 00 11 --- CC: Pedal (Sustain)
00012B33 2 4 BB 40 00 12 --- CC: Pedal (Sustain)
00012B33 2 4 BC 40 00 13 --- CC: Pedal (Sustain)
00012B33 2 4 BD 40 00 14 --- CC: Pedal (Sustain)
00012B33 2 4 BE 40 00 15 --- CC: Pedal (Sustain)
00012B34 2 4 BF 40 00 16 --- CC: Pedal (Sustain)
This code runs fine except on midiOutClose() garbage is send to midi device!? When I run it without midiOutClose() the sysex message is send as it should be, but the mididevice is not closed correctly.... and garbage is sent after the message seems to be random midi...
I'm out in the dark....
Follow code depends on: winmm.lib
Source:
#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
void PrintMidiOutErrorMsg(unsigned long err)
{
#define BUFFERSIZE 128
WCHAR errMsg[BUFFERSIZE];
if (!(err = midiOutGetErrorText(err, &errMsg[0], BUFFERSIZE)))
{
printf("%s\r\n", &errMsg[0]);
}
else if (err == MMSYSERR_BADERRNUM)
{
printf("Strange error number returned!\r\n");
}
else
{
printf("Specified pointer is invalid!\r\n");
}
}
int main()
{
HMIDIOUT handle;
MIDIHDR midiHdr;
UINT err;
const BYTE sysEx[] = {0xF0, 0x41, 0x00, 0x00, 0x00, 0x06, 0x12, 0x0D, 0x00, 0x12, 0x00,
0x53, 0x79, 0x73, 0x65, 0x78, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x47, 0xF7};
int i;
if (!(err = midiOutOpen(&handle, (UINT)5, 0, 0, CALLBACK_NULL)))
{
err = 0;
midiHdr.lpData = (LPSTR) sysEx;
midiHdr.dwBufferLength = (DWORD) sizeof(sysEx);
midiHdr.dwFlags = 0;
err = midiOutPrepareHeader(handle, &midiHdr, sizeof(MIDIHDR));
if (!err)
{
cout << "Sending system exclusive MIDI message (Sysex):" << endl;
cout << "sysEx value: " << endl;
for(i=0;i<sizeof(sysEx);i++)
{
printf ("%X ",sysEx[i]);
}
cout << "sysEx size: " << sizeof(sysEx) << " Bytes" << endl;
err = midiOutLongMsg(handle, &midiHdr, sizeof(MIDIHDR));
if (err)
{
PrintMidiOutErrorMsg(err);
}
while (MIDIERR_STILLPLAYING == midiOutUnprepareHeader(handle, &midiHdr, sizeof(MIDIHDR)))
{
Sleep(1000);
}
}
else
{
PrintMidiOutErrorMsg(err);
}
midiOutClose(handle);
}
else
{
printf("Error opening default MIDI Out device!\r\n");
PrintMidiOutErrorMsg(err);
}
printf("\r\n");
system("PAUSE");
return 0;
}
Message sent:
0000B84D 2 4 F0 Buffer: 17 Bytes System Exclusive
SYSX: F0 41 00 00 00 06 11 0D 00 00 00 00 00 1F 00 55 F7
What follows is send on the call of midiOutClose():
00012B2F 2 4 B0 40 00 1 --- CC: Pedal (Sustain)
00012B2F 2 4 B1 40 00 2 --- CC: Pedal (Sustain)
00012B30 2 4 B2 40 00 3 --- CC: Pedal (Sustain)
00012B30 2 4 B3 40 00 4 --- CC: Pedal (Sustain)
00012B30 2 4 B4 40 00 5 --- CC: Pedal (Sustain)
00012B30 2 4 B5 40 00 6 --- CC: Pedal (Sustain)
00012B30 2 4 B6 40 00 7 --- CC: Pedal (Sustain)
00012B31 2 4 B7 40 00 8 --- CC: Pedal (Sustain)
00012B32 2 4 B8 40 00 9 --- CC: Pedal (Sustain)
00012B32 2 4 B9 40 00 10 --- CC: Pedal (Sustain)
00012B32 2 4 BA 40 00 11 --- CC: Pedal (Sustain)
00012B33 2 4 BB 40 00 12 --- CC: Pedal (Sustain)
00012B33 2 4 BC 40 00 13 --- CC: Pedal (Sustain)
00012B33 2 4 BD 40 00 14 --- CC: Pedal (Sustain)
00012B33 2 4 BE 40 00 15 --- CC: Pedal (Sustain)
00012B34 2 4 BF 40 00 16 --- CC: Pedal (Sustain)