Bonjour,

Alors voilà, j'ai un clavier qui sort un signal MIDI. Je le connecte à l'ordinateur via un adaptateur USB et j'aimerais récupérer certaines info de ce signal (les Note ON, Note OFF). Alors je cherche à connaitre les fonctions permettant de traiter le signal MIDI en C.

J'ai bien vu ces fonctions sur le site http://msdn.microsoft.com/en-us/subs...(v=vs.85).aspx
mais j'avoue que mon niveau n'est pas assez bon et je ne comprend pas comment les utiliser.

J'ai trouvé sur le net un code en cpp qui affiche le signal MIDI dans une fenetre console. Il marche très bien
Comme je ne connait pas le cpp, je l'ai converti en C (voir ci-dessous) et ca marche bien. Le problème c'est que je ne comprend pas tout. Est-ce que quelqu'un peut m'aider à dechiffrer ce code?
Notament j'aimerais comprendre comment fonctionne la fonction midiInOpen:
result = midiInOpen(&inHandle, 0, (DWORD)midiCallback, 0, CALLBACK_FUNCTION);

et les notations:
MIDIINCAPS mic;
HMIDIIN inHandle;

J'utilise CodeBlocks
Merci d'avance!


Code:
#include <windows.h>
#include <stdio.h>
#include <mmsystem.h>
#include <stdlib.h>
#include <conio.h>      /* include for kbhit() and getch() functions */

void CALLBACK midiCallback(HMIDIIN handle, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
     switch ( uMsg )
    {
    case MIM_OPEN:
         printf("-----OPENED.-----\n");
         break;
    case MIM_CLOSE:
         printf("-----EVERYTHING IS CLOSING.-----\n");
         break;
    case MIM_DATA:
         printf("-----APPARENTLY THERE IS DATA.-----\n");         //I'm hoping to see this line...
         break;
    case MIM_LONGDATA:
         printf("-----LONGDATA'D.-----\n");
         break;
    case MIM_ERROR:
         printf("-----ERROR.-----\n");
         break;
    case MIM_LONGERROR:
         printf("-----LONGERROR.  EVEN WORSE.-----\n");
         break;
    }
     printf("dwInstance is %d\n", dwInstance);
     printf("Handle is %d\n", handle);
     printf("dwParam1 is %d\n" , dwParam1 ); //dwParam1 is the bytes of the MIDI Message packed into an unsigned long
     printf("dwParam2 is %d\n", dwParam2); //dwParam2 is the timestamp of key press
     printf("uMsg is %d\n" ,uMsg );
     printf("-------\n" );

}


void MidiThing()
{
    int iNumDevs=0;
    unsigned long i=0;
    MIDIINCAPS     mic;         
    HMIDIIN      inHandle;          
    int result=3;
    int ckey;            // storage for the current keyboard key being pressed

    iNumDevs = midiInGetNumDevs();  /* Get the number of MIDI In devices in this computer */
    printf("Nombre de midi connecte %d \n", iNumDevs);

    /* Go through all of those devices, displaying their names */
    for (i = 0; i < iNumDevs; i++)
    {
       /* Get info about the next device */
        if (!midiInGetDevCaps(i, &mic, sizeof(MIDIINCAPS)))                  
        {
             /* Display its Device ID and name */
            printf("Device ID #%d: %s\r\n", i, mic.szPname);
        }
    }

     printf("These are the only available devices...?\n\n");

    // Open the default MIDI In device.
    result = midiInOpen(&inHandle, 0, (DWORD)midiCallback, 0, CALLBACK_FUNCTION);            

       if (result==1)
        {
           printf("There was an error opening the default MIDI In device!\r\n");
        }
        else if (result==0)
        {
            midiInStart(inHandle);                   
            printf("\nmidiInStart has been called." );
        }

     printf("The unsigned long, result, value was %d\n\n" , result);

     printf( "%d is MIM_OPEN's value \n",MIM_OPEN );
     printf(  "%d is MIM_CLOSE's value \n",MIM_CLOSE );
     printf(  "%d is MIM_DATA's value \n\n",MIM_DATA);

    printf("Press \"q\" to quit.\n");
       while (1)
       {
          if (kbhit())
          {
             ckey = getch();
             if (ckey == 'q')
                 {
                 printf("Stopped. \n\n" );

                 break;
                 }
           }
       }

     midiInStop(inHandle);
     midiInReset(inHandle);
     midiInClose(inHandle);

     printf("Lines are done twice because midiCallback is called when midiInClose is called...? \n");
     printf("%d was the MIDIIN handle \n", inHandle);
     printf("Stuff's closed now.\n\n");
}


int main(int argc, char *argv[])
{
    MidiThing();
    system("PAUSE");
    return 0;
}