openMSX
MidiInCoreMIDI.hh
Go to the documentation of this file.
1 #ifndef MIDIINCOREMIDI_HH
2 #define MIDIINCOREMIDI_HH
3 
4 #if defined(__APPLE__)
5 
6 #include "MidiInDevice.hh"
7 #include "EventListener.hh"
8 #include "openmsx.hh"
9 #include "serialize_meta.hh"
10 #include "circular_buffer.hh"
11 #include <CoreMIDI/MIDIServices.h>
12 #include <mutex>
13 
14 namespace openmsx {
15 
16 class EventDistributor;
17 class Scheduler;
18 class PluggingController;
19 
22 class MidiInCoreMIDI final : public MidiInDevice, private EventListener
23 {
24 public:
25  static void registerAll(EventDistributor& eventDistributor,
26  Scheduler& scheduler, PluggingController& controller);
27 
31  explicit MidiInCoreMIDI(EventDistributor& eventDistributor_,
32  Scheduler& scheduler_, MIDIEndpointRef endpoint);
33  ~MidiInCoreMIDI();
34 
35  // Pluggable
36  void plugHelper(Connector& connector, EmuTime::param time) override;
37  void unplugHelper(EmuTime::param time) override;
38  [[nodiscard]] const std::string& getName() const override;
39  [[nodiscard]] std::string_view getDescription() const override;
40 
41  // MidiInDevice
42  void signal(EmuTime::param time) override;
43 
44  template<typename Archive>
45  void serialize(Archive& ar, unsigned version);
46 
47 
48 private:
49  // EventListener
50  int signalEvent(const std::shared_ptr<const Event>& event) override;
51 
52  static void sendPacketList(const MIDIPacketList *pktlist,
53  void *readProcRefCon, void *srcConnRefCon);
54  void sendPacketList(const MIDIPacketList *pktlist, void *srcConnRefCon);
55 
56 private:
57  EventDistributor& eventDistributor;
58  Scheduler& scheduler;
59  cb_queue<byte> queue;
60  std::mutex mutex; // to protect queue
61 
62  MIDIClientRef client;
63  MIDIPortRef port;
64  MIDIEndpointRef endpoint;
65 
66  std::string name;
67 };
68 
74 class MidiInCoreMIDIVirtual final : public MidiInDevice, private EventListener
75 {
76 public:
77  explicit MidiInCoreMIDIVirtual(EventDistributor& eventDistributor_,
78  Scheduler& scheduler_);
79  ~MidiInCoreMIDIVirtual();
80 
81  // Pluggable
82  void plugHelper(Connector& connector, EmuTime::param time) override;
83  void unplugHelper(EmuTime::param time) override;
84  const std::string& getName() const override;
85  std::string_view getDescription() const override;
86 
87  // MidiInDevice
88  void signal(EmuTime::param time) override;
89 
90  template<typename Archive>
91  void serialize(Archive& ar, unsigned version);
92 
93 private:
94  // EventListener
95  int signalEvent(const std::shared_ptr<const Event>& event) override;
96 
97  static void sendPacketList(const MIDIPacketList *pktlist,
98  void *readProcRefCon, void *srcConnRefCon);
99  void sendPacketList(const MIDIPacketList *pktlist, void *srcConnRefCon);
100 
101  EventDistributor& eventDistributor;
102  Scheduler& scheduler;
103  cb_queue<byte> queue;
104  std::mutex mutex; // to protect queue
105 
106  MIDIClientRef client;
107  MIDIEndpointRef endpoint;
108 };
109 
110 } // namespace openmsx
111 
112 #endif // defined(__APPLE__)
113 #endif // MIDIINCOREMIDI_HH
openmsx.hh
serialize_meta.hh
EventListener.hh
MidiInDevice.hh
cb_queue< byte >
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:742
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:132
openmsx::serialize
void serialize(Archive &ar, T &t, unsigned version)
Definition: serialize_core.hh:41
circular_buffer.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::Connector
Connector
Definition: Connector.cc:83