OXYGENHUB
◆ main openmsx / src / serial / MidiOutDevice.hh
1.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MIDIOUTDEVICE_HH
2
#define MIDIOUTDEVICE_HH
3
4
#include "Pluggable.hh"
5
#include "SerialDataInterface.hh"
6
#include <vector>
7
8
9
namespace openmsx {
10
11
/** Pluggable that connects an MSX MIDI out port to a host MIDI device.
12
  * Implementations must override either recvByte(), if they can handle raw
13
  * data, or recvMessage(), if they handle MIDI messages.
14
  */
15
class MidiOutDevice : public Pluggable, public SerialDataInterface
16
{
17
public:
18
	/** The limit for the amount of data we'll put into one MIDI message.
19
	  * The value of 256 comes from the data limit for a MIDIPacket in CoreMIDI.
20
	  */
21
	static constexpr size_t MAX_MESSAGE_SIZE = 256;
22
23
	// Pluggable (part)
24
	[[nodiscard]] zstring_view getClass() const final;
25
26
	// SerialDataInterface (part)
27
	void recvByte(uint8_t value, EmuTime time) override;
28
	void setDataBits(DataBits bits) override;
29
	void setStopBits(StopBits bits) override;
30
	void setParityBit(bool enable, Parity parity) override;
31
32
protected:
33
	explicit MidiOutDevice() = default;
34
35
	/** Discard any buffered partial MIDI message.
36
	  */
37
	void clearBuffer();
38
39
	/** Called when a full MIDI message is ready to be sent.
40
	  * Implementations that can handle raw bytes can override recvByte()
41
	  * instead, in which case this method will not be called.
42
	  */
43
	virtual void recvMessage(
44
		const std::vector<uint8_t>& message, EmuTime time);
45
46
private:
47
	std::vector<uint8_t> buffer;
48
	bool isSysEx = false;
49
};
50
51
} // namespace openmsx
52
53
#endif