command-line utility to translate between Mackie HUI and Open Sound Control
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.c 1.8KB

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