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

@@ -13,24 +13,33 @@
void alsa_error (const char *format, ...);
void* midiinfunction (void * arg);

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

int main(int argc, char *argv[]) {
int status;
int mode = SND_RAWMIDI_SYNC;
pthread_t midiinthread;
snd_rawmidi_t* midiin = NULL;

housicIO IOs = {NULL,NULL};
// snd_rawmidi_t* midiin = NULL;
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));
exit(1);
}

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

snd_rawmidi_close(midiin);
midiin=NULL;
//snd_rawmidi_close(midiin);
//midiin=NULL;
return 0;
}
@@ -43,7 +52,8 @@ int main(int argc, char *argv[]) {
//

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 i = 0;
char buffer[3];

Loading…
Cancel
Save