|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
#include <alsa/asoundlib.h> |
|
|
#include <alsa/asoundlib.h> |
|
|
|
|
|
#include <pthread.h> /* for threading */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// function declarations: |
|
|
// function declarations: |
|
|
void alsa_error(const char *format, ...); |
|
|
|
|
|
|
|
|
void alsa_error (const char *format, ...); |
|
|
|
|
|
void* midiinfunction (void * arg); |
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
int main(int argc, char *argv[]) { |
|
|
int status; |
|
|
int status; |
|
|
int mode = SND_RAWMIDI_SYNC; |
|
|
int mode = SND_RAWMIDI_SYNC; |
|
|
|
|
|
pthread_t midiinthread; |
|
|
snd_rawmidi_t* midiin = NULL; |
|
|
snd_rawmidi_t* midiin = NULL; |
|
|
const char* portname = "virtual"; |
|
|
const char* portname = "virtual"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
status = pthread_create(&midiinthread, NULL, midiinfunction, midiin); |
|
|
|
|
|
|
|
|
|
|
|
pthread_join(midiinthread, NULL); |
|
|
|
|
|
|
|
|
|
|
|
snd_rawmidi_close(midiin); |
|
|
|
|
|
midiin=NULL; |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////// |
|
|
|
|
|
// |
|
|
|
|
|
// midiinfunction -- Thread function which waits around until a MIDI |
|
|
|
|
|
// input byte arrives and then react correspondingly |
|
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
|
|
void *midiinfunction(void *arg) { |
|
|
|
|
|
snd_rawmidi_t* midiin = (snd_rawmidi_t*)arg; |
|
|
|
|
|
int status; |
|
|
int i = 0; |
|
|
int i = 0; |
|
|
char buffer[3]; |
|
|
char buffer[3]; |
|
|
unsigned char message[3]; |
|
|
unsigned char message[3]; |
|
|
|
|
|
|
|
|
printf("%d: %x %x %x\n", status, message[0], message[1], message[2]); |
|
|
printf("%d: %x %x %x\n", status, message[0], message[1], message[2]); |
|
|
fflush(stdout); |
|
|
fflush(stdout); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
snd_rawmidi_close(midiin); |
|
|
|
|
|
midiin=NULL; |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|