command-line utility to translate between Mackie HUI and Open Sound Control
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 4 Jahren
vor 4 Jahren
vor 4 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. void midi_in_dispatch (void * arg, unsigned char * m);
  14. typedef struct {
  15. snd_rawmidi_t* midiin;
  16. snd_rawmidi_t* midiout;
  17. unsigned char hui_in_zone;
  18. } housicIO;
  19. int main(int argc, char *argv[]) {
  20. int status;
  21. int mode = SND_RAWMIDI_SYNC;
  22. pthread_t midiinthread;
  23. housicIO IOs = {NULL,NULL,0};
  24. // snd_rawmidi_t* midiin = NULL;
  25. const char* portname = "virtual";
  26. if ((status = snd_rawmidi_open(&IOs.midiin, NULL, portname, mode)) < 0) {
  27. alsa_error("Problem opening MIDI input: %s", snd_strerror(status));
  28. exit(1);
  29. }
  30. status = pthread_create(&midiinthread, NULL, midiinfunction, &IOs);
  31. pthread_join(midiinthread, NULL);
  32. //snd_rawmidi_close(midiin);
  33. //midiin=NULL;
  34. return 0;
  35. }
  36. //////////////////////////////
  37. //
  38. // midiinfunction -- Thread function which waits around until a MIDI
  39. // input byte arrives and then react correspondingly
  40. //
  41. void *midiinfunction(void *arg) {
  42. housicIO* IOs = (housicIO*)arg;
  43. snd_rawmidi_t* midiin = IOs->midiin;
  44. int status;
  45. int i = 0;
  46. char buffer[3];
  47. unsigned char message[3];
  48. while (1) {
  49. if ((status = snd_rawmidi_read(midiin, buffer, 3)) < 0) {
  50. alsa_error("Problem reading MIDI input: %s", snd_strerror(status));
  51. }
  52. // in case of MIDI running status, value bytes need to not override status byte
  53. for (i=1; i<=status;i++) {
  54. message[3-i] = (unsigned char) buffer[status-i];
  55. }
  56. midi_in_dispatch(IOs,message);
  57. fflush(stdout);
  58. }
  59. }
  60. //////////////////////////////
  61. //
  62. // midi_in_dispatch -- Thread function which waits around until a MIDI
  63. // input byte arrives and then react correspondingly
  64. //
  65. void midi_in_dispatch(void *arg, unsigned char *m) {
  66. housicIO* IOs = (housicIO*)arg;
  67. if (m[0] == 0xb0) {
  68. // received a CC message on MIDIchannel 1
  69. if (m[1] == 0x0f) {
  70. // received a zone select
  71. IOs->hui_in_zone = m[2];
  72. }
  73. }
  74. }
  75. //////////////////////////////
  76. //
  77. // error -- print error message
  78. //
  79. void alsa_error(const char *format, ...) {
  80. va_list ap;
  81. va_start(ap, format);
  82. vfprintf(stderr, format, ap);
  83. va_end(ap);
  84. putc('\n', stderr);
  85. }