浏览代码

move midi_read to own thread

master
父节点
当前提交
33f1323fea
共有 2 个文件被更改,包括 26 次插入7 次删除
  1. +1
    -1
      Makefile
  2. +25
    -6
      main.c

+ 1
- 1
Makefile 查看文件

@@ -4,7 +4,7 @@ exe = housic
src = $(wildcard *.c)
obj = $(src:.c=.o)

LDFLAGS = -lasound
LDFLAGS = -lasound -lpthread

$(exe): $(obj)
$(CC) -o $@ $^ $(LDFLAGS)

+ 25
- 6
main.c 查看文件

@@ -6,13 +6,17 @@
*
*/
#include <alsa/asoundlib.h>
#include <pthread.h> /* for threading */


// 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 status;
int mode = SND_RAWMIDI_SYNC;
pthread_t midiinthread;
snd_rawmidi_t* midiin = NULL;
const char* portname = "virtual";

@@ -21,6 +25,26 @@ int main(int argc, char *argv[]) {
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;
char buffer[3];
unsigned char message[3];
@@ -38,11 +62,6 @@ int main(int argc, char *argv[]) {
printf("%d: %x %x %x\n", status, message[0], message[1], message[2]);
fflush(stdout);
}

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



正在加载...
取消
保存