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.

67 lines
1.2KB

  1. #pragma once
  2. #include "util/common.hpp"
  3. #include <queue>
  4. #include <vector>
  5. #include <jansson.h>
  6. #pragma GCC diagnostic push
  7. #pragma GCC diagnostic ignored "-Wsuggest-override"
  8. #include "rtmidi/RtMidi.h"
  9. #pragma GCC diagnostic pop
  10. namespace rack {
  11. struct MidiMessage {
  12. double time;
  13. std::vector<uint8_t> data;
  14. };
  15. struct MidiIO {
  16. int device = -1;
  17. /* For MIDI output, the channel to output messages.
  18. For MIDI input, the channel to filter.
  19. Set to -1 to allow all MIDI channels (for input).
  20. Zero indexed.
  21. */
  22. int channel = -1;
  23. RtMidi *rtMidi = NULL;
  24. virtual ~MidiIO() {}
  25. int getDeviceCount();
  26. std::string getDeviceName(int device);
  27. void openDevice(int device);
  28. /** Returns whether the audio stream is open and running */
  29. bool isActive();
  30. json_t *toJson();
  31. void fromJson(json_t *rootJ);
  32. };
  33. struct MidiInput : MidiIO {
  34. RtMidiIn *rtMidiIn = NULL;
  35. MidiInput();
  36. ~MidiInput();
  37. virtual void onMessage(const MidiMessage &message) {}
  38. };
  39. struct MidiInputQueue : MidiInput {
  40. std::queue<MidiMessage> messageQueue;
  41. void onMessage(const MidiMessage &message) override;
  42. };
  43. struct MidiOutput : MidiIO {
  44. RtMidiOut *rtMidiOut = NULL;
  45. MidiOutput();
  46. ~MidiOutput();
  47. };
  48. } // namespace rack