Link to home
Start Free TrialLog in
Avatar of TomMahieu
TomMahieu

asked on

MIDI Sysex Programming Question...

I am trying to write a Windows program to communicate with a MIDI device that is connected to my PC.  However, I can't seem to get my program talking to the device.  I am new to MIDI programming and I haven't been able to find a good example.  

For now, I just want to send a Sysex message to the MIDI device and get a response back.  I have been trying this using these functions:

midiOutGetNumDevs()
midiOutGetDevCaps()
midiOutOpen()
midiInOpen()
midiInStart()

but I haven't really gotten anywhere.  Note I don't want to receive any midi audio from the device - I just want to send a request message to it and get a response.  For now, I would prefer to use CALLBACK functions.

I believe the following is what I need to send to the device:

F0 7E <chan> 06 01 F7 System inquiry message

<chan> can be 7F (all devices) and the device documentation says it will respond.  I have more sysex information on the device, but I am not sure if that is needed to solve this question.  If so, let me know and I will post as much as needed.

I *believe* that I should be using midi output device 2 and midi input device 0.
Avatar of ShaunWilde
ShaunWilde

have you looked at the MIDImon sample in the msdn ?
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TomMahieu

ASKER

I've taken a look at the MIDImon sample, but I haven't been able to successfully extract what I am trying to do.  I was looking for someone to point me in the right direction with a code snippet of "here is what you have to do" and leave out all of the things that are not necessary.
OK, if this helps, here is basically what I am currently doing that does not work.  Anybody see what is wrong?  Everything?  ;)

void CALLBACK MidiOutProc(HMIDIOUT hmo,      
                          UINT wMsg,        
                          DWORD dwInstance,  
                          DWORD dwParam1,    
                          DWORD dwParam2)
{
    DWORD temp = dwParam1;
}
 

void CALLBACK MidiInProc(HMIDIIN hMidiIn,  
                         UINT wMsg,        
                         DWORD dwInstance,
                         DWORD dwParam1,  
                         DWORD dwParam2)
{
    DWORD temp = dwParam1;
}


void OutputSystemExclusiveMessage(void)
{
    HMIDIOUT    outHandle;
    HMIDIIN     inHandle;
    MIDIHDR     midiHdr;
    UINT        err;
    char          sysEx[] = {0xF0, 0x7E, 0x01, 0x06, 0x01, 0x07};

    DWORD outRetVal = 0;
    DWORD inRetVal = 0;
    DWORD inStartRetVal = 0;

    outRetVal = midiOutOpen(&outHandle, 2, (DWORD)MidiOutProc, 23, CALLBACK_FUNCTION);
    inRetVal = midiInOpen(&inHandle, 0, (DWORD)MidiInProc, 34, CALLBACK_FUNCTION);

    if ((MMSYSERR_NOERROR != inRetVal) || (MMSYSERR_NOERROR != outRetVal))
    {
        cout << "ERROR!" << endl;
    }
    else
    {
        inStartRetVal = midiInStart(inHandle);
    }

    if (MMSYSERR_NOERROR == inStartRetVal)
    {
        midiHdr.lpData = (char *)&sysEx[0];
        midiHdr.dwBufferLength = sizeof(sysEx);
        midiHdr.dwBytesRecorded  = sizeof(sysEx);
        midiHdr.dwFlags = 0;

        err = midiOutPrepareHeader(outHandle,  &midiHdr, sizeof(MIDIHDR));
        if (!err)
        {
            err = midiOutLongMsg(outHandle, &midiHdr, sizeof(MIDIHDR));
            if (err)
            {
                char   errMsg[120];

                midiOutGetErrorText(err, &errMsg[0], 120);
                printf("Error: %s\r\n", &errMsg[0]);
            }

            while (MIDIERR_STILLPLAYING == midiOutUnprepareHeader(outHandle, &midiHdr, sizeof(MIDIHDR)))
            {              
            }
        }

        midiOutClose(outHandle);

    }
}
In next article
http://www.salleurl.edu/~si04990/documents/lowmidi.htm
I see working code ~ same as your's. Check out differences
and you 'll easy find problems.
Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20178896.html
https://www.experts-exchange.com/questions/Q.20180095.html




PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
Thanks for returning and finalizing your question.  Anytime you choose to grade less than an A, please comment as to why.  This helps all involved, including others who may visit this question at a later time for help.  Some experts look at grading history before deciding to help someone, so that also may have an impact to you and how quickly your future questions are answered.

The points to you are always the same, but the points granted the expert depend upon the grade.  Using 100 points as an example.  100 at A = 400 ... 100 at B = 300 .... 100 at C = 200, so it also has a point impact to the experts.  

If the grade chosen was in error, let me know, and I can correct this.

EE Moderator