OXYGENHUB
◆ main openmsx / src / serial / MidiOutCoreMIDI.hh
2.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MIDIOUTCOREMIDI_HH
2
#define MIDIOUTCOREMIDI_HH
3
4
#ifdef __APPLE__
5
6
#include "MidiOutDevice.hh"
7
#include <CoreMIDI/MIDIServices.h>
8
9
#include <vector>
10
11
namespace openmsx {
12
13
class PluggingController;
14
15
/** Puts MIDI messages into a MIDIPacketList.
16
  */
17
class MidiOutMessageBuffer : public MidiOutDevice
18
{
19
protected:
20
	virtual OSStatus sendPacketList(MIDIPacketList *myPacketList) = 0;
21
22
private:
23
	void recvMessage(
24
			const std::vector<uint8_t>& message, EmuTime time) override;
25
};
26
27
/** Sends MIDI events to an existing CoreMIDI destination.
28
  */
29
class MidiOutCoreMIDI final : public MidiOutMessageBuffer
30
{
31
public:
32
	static void registerAll(PluggingController& controller);
33
34
	/** Public for the sake of make_unique<>() - not intended for actual
35
	  * public use.
36
	  */
37
	explicit MidiOutCoreMIDI(MIDIEndpointRef endpoint);
38
39
	// Pluggable
40
	void plugHelper(Connector& connector, EmuTime time) override;
41
	void unplugHelper(EmuTime time) override;
42
	[[nodiscard]] zstring_view getName() const override;
43
	[[nodiscard]] zstring_view getDescription() const override;
44
45
	// MidiOutMessageBuffer
46
	OSStatus sendPacketList(MIDIPacketList *myPacketList) override;
47
48
	template<typename Archive>
49
	void serialize(Archive& ar, unsigned version);
50
51
private:
52
	MIDIClientRef client;
53
	MIDIPortRef port;
54
	MIDIEndpointRef endpoint;
55
56
	std::string name;
57
};
58
59
/** Sends MIDI events from a newly created CoreMIDI virtual source.
60
  * This class acts as a MIDI input, unlike the other class that sends events
61
  * to a MIDI output. It is similar to using an IAC bus, but doesn't require
62
  * prior configuration to work.
63
  */
64
class MidiOutCoreMIDIVirtual final : public MidiOutMessageBuffer
65
{
66
public:
67
	explicit MidiOutCoreMIDIVirtual();
68
69
	// Pluggable
70
	void plugHelper(Connector& connector, EmuTime time) override;
71
	void unplugHelper(EmuTime time) override;
72
	[[nodiscard]] zstring_view getName() const override;
73
	[[nodiscard]] zstring_view getDescription() const override;
74
75
	// MidiOutMessageBuffer
76
	OSStatus sendPacketList(MIDIPacketList *myPacketList) override;
77
78
	template<typename Archive>
79
	void serialize(Archive& ar, unsigned version);
80
81
private:
82
	MIDIClientRef client;
83
	MIDIEndpointRef endpoint;
84
};
85
86
} // namespace openmsx
87
88
#endif // defined(__APPLE__)
89
#endif // MIDIOUTCOREMIDI_HH