command-line utility to translate between Mackie HUI and Open Sound Control
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3KB

  1. /*
  2. * Programmer: Dominik Schmidt-Philipp <schmidt-philipp@kulturteknologi.no>
  3. * Filename: main.c
  4. *
  5. * Dedicated to seleomlivet
  6. *
  7. */
  8. #include <alsa/asoundlib.h>
  9. // function declarations:
  10. void alsa_error(const char *format, ...);
  11. int main(int argc, char *argv[]) {
  12. int status;
  13. int mode = SND_RAWMIDI_SYNC;
  14. snd_rawmidi_t* midiin = NULL;
  15. const char* portname = "virtual";
  16. if ((status = snd_rawmidi_open(&midiin, NULL, portname, mode)) < 0) {
  17. alsa_error("Problem opening MIDI input: %s", snd_strerror(status));
  18. exit(1);
  19. }
  20. int i = 0;
  21. char buffer[3];
  22. unsigned char message[3];
  23. while (1) {
  24. if ((status = snd_rawmidi_read(midiin, buffer, 3)) < 0) {
  25. alsa_error("Problem reading MIDI input: %s", snd_strerror(status));
  26. }
  27. // in case of MIDI running status, value bytes need to not override status byte
  28. for (i=1; i<=status;i++) {
  29. message[3-i] = (unsigned char) buffer[status-i];
  30. }
  31. printf("%d: %x %x %x\n", status, message[0], message[1], message[2]);
  32. fflush(stdout);
  33. }
  34. snd_rawmidi_close(midiin);
  35. midiin=NULL;
  36. return 0;
  37. }
  38. //////////////////////////////
  39. //
  40. // error -- print error message
  41. //
  42. void alsa_error(const char *format, ...) {
  43. va_list ap;
  44. va_start(ap, format);
  45. vfprintf(stderr, format, ap);
  46. va_end(ap);
  47. putc('\n', stderr);
  48. }