Browse Source

make midiin device pointer live in a struct

master
parent
commit
b343e4040a
1 changed files with 16 additions and 6 deletions
  1. +16
    -6
      main.c

+ 16
- 6
main.c View File

void alsa_error (const char *format, ...); void alsa_error (const char *format, ...);
void* midiinfunction (void * arg); void* midiinfunction (void * arg);


typedef struct {
snd_rawmidi_t* midiin;
snd_rawmidi_t* midiout;
} housicIO;

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; pthread_t midiinthread;
snd_rawmidi_t* midiin = NULL;

housicIO IOs = {NULL,NULL};
// snd_rawmidi_t* midiin = NULL;
const char* portname = "virtual"; const char* portname = "virtual";


if ((status = snd_rawmidi_open(&midiin, NULL, portname, mode)) < 0) {
if ((status = snd_rawmidi_open(&IOs.midiin, NULL, portname, mode)) < 0) {
alsa_error("Problem opening MIDI input: %s", snd_strerror(status)); alsa_error("Problem opening MIDI input: %s", snd_strerror(status));
exit(1); exit(1);
} }


status = pthread_create(&midiinthread, NULL, midiinfunction, midiin);
status = pthread_create(&midiinthread, NULL, midiinfunction, &IOs);
pthread_join(midiinthread, NULL); pthread_join(midiinthread, NULL);


snd_rawmidi_close(midiin);
midiin=NULL;
//snd_rawmidi_close(midiin);
//midiin=NULL;
return 0; return 0;
} }
// //


void *midiinfunction(void *arg) { void *midiinfunction(void *arg) {
snd_rawmidi_t* midiin = (snd_rawmidi_t*)arg;
housicIO* IOs = (housicIO*)arg;
snd_rawmidi_t* midiin = IOs->midiin;
int status; int status;
int i = 0; int i = 0;
char buffer[3]; char buffer[3];

Loading…
Cancel
Save