Bläddra i källkod

basic rawmidi_read

master
förälder
incheckning
59672c70d9
2 ändrade filer med 50 tillägg och 1 borttagningar
  1. +1
    -1
      Makefile
  2. +49
    -0
      main.c

+ 1
- 1
Makefile Visa fil

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

LDFLAGS =
LDFLAGS = -lasound

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

+ 49
- 0
main.c Visa fil

@@ -5,7 +5,56 @@
* Dedicated to seleomlivet
*
*/
#include <alsa/asoundlib.h>

// function declarations:
void alsa_error(const char *format, ...);

int main(int argc, char *argv[]) {
int status;
int mode = SND_RAWMIDI_SYNC;
snd_rawmidi_t* midiin = NULL;
const char* portname = "virtual";

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

int i = 0;
char buffer[3];
unsigned char message[3];

while (1) {
if ((status = snd_rawmidi_read(midiin, buffer, 3)) < 0) {
alsa_error("Problem reading MIDI input: %s", snd_strerror(status));
}

// in case of MIDI running status, value bytes need to not override status byte
for (i=1; i<=status;i++) {
message[3-i] = (unsigned char) buffer[status-i];
}

printf("%d: %x %x %x\n", status, message[0], message[1], message[2]);
fflush(stdout);
}

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


//////////////////////////////
//
// error -- print error message
//

void alsa_error(const char *format, ...) {
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
putc('\n', stderr);
}

Laddar…
Avbryt
Spara