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
14namespace openmsx {
15
16class EventDistributor;
17class Scheduler;
18class PluggingController;
19
22class MidiInCoreMIDI final : public MidiInDevice, private EventListener
23{
24public:
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]] std::string_view 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
48private:
49 // EventListener
50 bool signalEvent(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
56private:
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
74class MidiInCoreMIDIVirtual final : public MidiInDevice, private EventListener
75{
76public:
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 std::string_view 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
93private:
94 // EventListener
95 bool signalEvent(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
This implements a queue on top of circular_buffer (not part of boost).
This file implemented 3 utility functions:
Definition Autofire.cc:11
void serialize(Archive &ar, T &t, unsigned version)