OXYGENHUB
◆ main openmsx / src / serial / MidiOutLogger.cc
1.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "MidiOutLogger.hh"
2
3
#include "FileOperations.hh"
4
#include "PlugException.hh"
5
#include "serialize.hh"
6
7
#include "narrow.hh"
8
9
namespace openmsx {
10
11
MidiOutLogger::MidiOutLogger(CommandController& commandController)
12
	: logFilenameSetting(
13
		commandController, "midi-out-logfilename",
14
		"filename of the file where the MIDI output is logged to",
15
		"/dev/midi")
16
{
17
}
18
19
void MidiOutLogger::plugHelper(Connector& /*connector*/,
20
                               EmuTime /*time*/)
21
{
22
	FileOperations::openOfStream(file, logFilenameSetting.getString());
23
	if (file.fail()) {
24
		file.clear();
25
		throw PlugException("Error opening log file");
26
	}
27
}
28
29
void MidiOutLogger::unplugHelper(EmuTime /*time*/)
30
{
31
	file.close();
32
}
33
34
zstring_view MidiOutLogger::getName() const
35
{
36
	return "midi-out-logger";
37
}
38
39
zstring_view MidiOutLogger::getDescription() const
40
{
41
	return "Midi output logger. Log all data that is sent to this "
42
	       "pluggable to a file. The filename is set with the "
43
	       "'midi-out-logfilename' setting.";
44
}
45
46
void MidiOutLogger::recvByte(uint8_t value, EmuTime /*time*/)
47
{
48
	if (file.is_open()) {
49
		file.put(narrow_cast<char>(value));
50
		file.flush();
51
	}
52
}
53
54
template<typename Archive>
55
void MidiOutLogger::serialize(Archive& /*ar*/, unsigned /*version*/)
56
{
57
	// don't try to resume a previous logfile (see PrinterPortLogger)
58
}
59
INSTANTIATE_SERIALIZE_METHODS(MidiOutLogger);
60
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, MidiOutLogger, "MidiOutLogger");
61
62
} // namespace openmsx