/* Prima di compilare aggiungere a LINK: Winmm.lib !!! */ #include #include #include #include #include /* neccessario prime di includere mmsystem.h */ #include /* funzioni multimediale (per es. MIDI) per Windows */ // struttura per trattenere i messaggi MIDI typedef union _MIDIMSG // è una definizione creata dall'utente { unsigned long word; unsigned char data[4]; } MIDIMSG; int main(int argc, char** argv) { int str_num; int velocity = 100; // valore di parametro del MIDI note velocity int midiport; // seleziona la porta MIDI che deve esse aperta int rc; float del; // per ritardo note_off int kboard = 0; // per ritardo note_off 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("Inserire numero di strumento: "); scanf("%d", &str_num); printf("Inserire durata nota in secondi: "); scanf("%f", &del); // set program change message.data[0] = 0xC0; message.data[1] = str_num; // 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) int indice,nota,i,serie[12]; srand( (unsigned)time( NULL ) );//inizializzazione seme numeri casuali indice=0; printf("\n"); printf("PREMERE TASTO \"i\" PER INTERROMPERE ED USCIRE \n\n"); do { do { nota=rand()%12+60;// genera numero casuale tra 0 e 11 for(i=0;i