#include #include #include /* neccessario prime di includere mmsystem.h */ #include /* funzioni multimediale (per es. MIDI) per Windows */ /* compile and link using the Winmm.lib library !!! */ // struttura per trattenere i messaggi MIDI typedef union _MIDIMSG { unsigned long word; unsigned char data[4]; } MIDIMSG; int main(int argc, char** argv) { int ckey, notenumber; int notestate; // tracking di quando la nota è "on" / "off" int velocity = 100; // valore di parametro del MIDI note velocity int midiport; // seleziona la porta MIDI che deve esse aperta int rc; HMIDIOUT device; // Dispositivo MIDI di USCITA MIDIMSG message; message.data[0] = 0x90; // Messaggio MIDI note-on (due data bytes) message.data[1] = 60; // Messaggio MIDI note-on: Key number (60 = Do centrale) message.data[2] = 100; // Messaggio MIDI note-on: Key velocity (100 = f) message.data[3] = 0; // Parametro non utilizzato // Asegna il numero di porta MIDI (dalla tastiera o per default 0) if (argc < 2) midiport = 0; else midiport = atoi(argv[1]); printf("Ci sono attualmente %i dispositivi MIDI nel tuo sistema. \n", midiOutGetNumDevs()); printf("MIDI output attuale %i.\n", midiport); // Apre la porta MIDI di uscita rc = midiOutOpen(&device, midiport, 0, 0, CALLBACK_NULL); if (rc != MMSYSERR_NOERROR) { printf("Problema in apertura della USCITA MIDI. \n"); return 1; } printf("Premere tasto \"q\" per uscire.\n"); notestate = 0; // lo stato di partenza della nota è OFF // set program change to Hammond organ (Rock organ) message.data[0] = 0xC0; message.data[1] = 10; // other data values are not important midiOutShortMsg(device, message.word); message.data[0] = 0x90; // MIDI note-on message (requires to data bytes) // message.data[1] = 36; // MIDI note-on message: Key number (60 = middle C) for(;;) { // loop per l'evento //while( _kbhit() ) if (_kbhit()) { // se un tasto qualsiasi del computer è stato premuto... ckey = getch(); if (ckey == 'a') notenumber = 60; if (ckey == 's') notenumber = 62; if (ckey == 'd') notenumber = 64; if (ckey == 'f') notenumber = 65; if (ckey == 'g') notenumber = 67; // printf("Righe: %d, Parole: %d, Caratteri: %d\n", nl, nw, nc); if (notestate == 0) { // La nota è attualmente spenta, quindi adesso diventa ON message.data[2] = velocity; notestate = 1; printf("Nota accessa (ON).\n"); } else { // La nota è attualmente accessa, quindi adesso diventa OFF message.data[2] = 0; // Velocity 0 = Note off notestate = 0; printf("Nota spenta (OFF).\n"); } message.data[1] = notenumber; rc = midiOutShortMsg(device, message.word); //message.data[1] = 40; //rc = midiOutShortMsg(device, message.word); //message.data[1] = 43; //rc = midiOutShortMsg(device, message.word); if (rc != MMSYSERR_NOERROR) { printf("Warning: MIDI Output is not open.\n"); } if (ckey == 'q') break; } } // che cacchio fa questo ??? midiOutReset(device); // Rimuove qualsiasi dal dispositivo MIDI e chiude la porta di uscita MIDI midiOutClose(device); return 0; }