openMSX
MidiOutLogger.cc
Go to the documentation of this file.
1#include "MidiOutLogger.hh"
2#include "PlugException.hh"
3#include "FileOperations.hh"
4#include "narrow.hh"
5#include "serialize.hh"
6
7namespace openmsx {
8
10 : logFilenameSetting(
11 commandController, "midi-out-logfilename",
12 "filename of the file where the MIDI output is logged to",
13 "/dev/midi")
14{
15}
16
18 EmuTime::param /*time*/)
19{
20 FileOperations::openOfStream(file, logFilenameSetting.getString());
21 if (file.fail()) {
22 file.clear();
23 throw PlugException("Error opening log file");
24 }
25}
26
27void MidiOutLogger::unplugHelper(EmuTime::param /*time*/)
28{
29 file.close();
30}
31
32std::string_view MidiOutLogger::getName() const
33{
34 return "midi-out-logger";
35}
36
37std::string_view MidiOutLogger::getDescription() const
38{
39 return "Midi output logger. Log all data that is sent to this "
40 "pluggable to a file. The filename is set with the "
41 "'midi-out-logfilename' setting.";
42}
43
44void MidiOutLogger::recvByte(byte value, EmuTime::param /*time*/)
45{
46 if (file.is_open()) {
47 file.put(narrow_cast<char>(value));
48 file.flush();
49 }
50}
51
52template<typename Archive>
53void MidiOutLogger::serialize(Archive& /*ar*/, unsigned /*version*/)
54{
55 // don't try to resume a previous logfile (see PrinterPortLogger)
56}
59
60} // namespace openmsx
Represents something you can plug devices into.
Definition Connector.hh:21
zstring_view getString() const noexcept
std::string_view getName() const override
Name used to identify this pluggable.
void plugHelper(Connector &connector, EmuTime::param time) override
MidiOutLogger(CommandController &commandController)
void unplugHelper(EmuTime::param time) override
void recvByte(byte value, EmuTime::param time) override
std::string_view getDescription() const override
Description for this pluggable.
void serialize(Archive &ar, unsigned version)
Thrown when a plug action fails.
void openOfStream(std::ofstream &stream, zstring_view filename)
Open an ofstream in a platform-independent manner.
This file implemented 3 utility functions:
Definition Autofire.cc:11
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)