command-line utility to translate between Mackie HUI and Open Sound Control
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

90 linhas
2.0KB

  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. #include <pthread.h> /* for threading */
  10. // function declarations:
  11. void alsa_error (const char *format, ...);
  12. void* midiinfunction (void * arg);
  13. typedef struct {
  14. snd_rawmidi_t* midiin;
  15. snd_rawmidi_t* midiout;
  16. } housicIO;
  17. int main(int argc, char *argv[]) {
  18. int status;
  19. int mode = SND_RAWMIDI_SYNC;
  20. pthread_t midiinthread;
  21. housicIO IOs = {NULL,NULL};
  22. // snd_rawmidi_t* midiin = NULL;
  23. const char* portname = "virtual";
  24. if ((status = snd_rawmidi_open(&IOs.midiin, NULL, portname, mode)) < 0) {
  25. alsa_error("Problem opening MIDI input: %s", snd_strerror(status));
  26. exit(1);
  27. }
  28. status = pthread_create(&midiinthread, NULL, midiinfunction, &IOs);
  29. pthread_join(midiinthread, NULL);
  30. //snd_rawmidi_close(midiin);
  31. //midiin=NULL;
  32. return 0;
  33. }
  34. //////////////////////////////
  35. //
  36. // midiinfunction -- Thread function which waits around until a MIDI
  37. // input byte arrives and then react correspondingly
  38. //
  39. void *midiinfunction(void *arg) {
  40. housicIO* IOs = (housicIO*)arg;
  41. snd_rawmidi_t* midiin = IOs->midiin;
  42. int status;
  43. int i = 0;
  44. char buffer[3];
  45. unsigned char message[3];
  46. while (1) {
  47. if ((status = snd_rawmidi_read(midiin, buffer, 3)) < 0) {
  48. alsa_error("Problem reading MIDI input: %s", snd_strerror(status));
  49. }
  50. // in case of MIDI running status, value bytes need to not override status byte
  51. for (i=1; i<=status;i++) {
  52. message[3-i] = (unsigned char) buffer[status-i];
  53. }
  54. printf("%d: %x %x %x\n", status, message[0], message[1], message[2]);
  55. fflush(stdout);
  56. }
  57. }
  58. //////////////////////////////
  59. //
  60. // error -- print error message
  61. //
  62. void alsa_error(const char *format, ...) {
  63. va_list ap;
  64. va_start(ap, format);
  65. vfprintf(stderr, format, ap);
  66. va_end(ap);
  67. putc('\n', stderr);
  68. }