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.

midi.hpp 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "util.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 port = -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 getPortCount();
  26. std::string getPortName(int port);
  27. void openPort(int port);
  28. json_t *toJson();
  29. void fromJson(json_t *rootJ);
  30. };
  31. struct MidiInput : MidiIO {
  32. MidiInput();
  33. ~MidiInput();
  34. virtual void onMessage(const MidiMessage &message) {}
  35. };
  36. struct MidiInputQueue : MidiInput {
  37. std::queue<MidiMessage> messageQueue;
  38. void onMessage(const MidiMessage &message) override;
  39. };
  40. struct MidiOutput : MidiIO {
  41. MidiOutput();
  42. ~MidiOutput();
  43. };
  44. } // namespace rack