command-line utility to translate between Mackie HUI and Open Sound Control
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.c 2.0KB

4 år sedan
4 år sedan
4 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }