openMSX
MidiOutLogger.cc
Go to the documentation of this file.
1 #include "MidiOutLogger.hh"
2 #include "PlugException.hh"
3 #include "FileOperations.hh"
4 #include "serialize.hh"
5 
6 namespace openmsx {
7 
9  : logFilenameSetting(
10  commandController, "midi-out-logfilename",
11  "filename of the file where the MIDI output is logged to",
12  "/dev/midi")
13 {
14 }
15 
17  EmuTime::param /*time*/)
18 {
19  FileOperations::openofstream(file, logFilenameSetting.getString());
20  if (file.fail()) {
21  file.clear();
22  throw PlugException("Error opening log file");
23  }
24 }
25 
26 void MidiOutLogger::unplugHelper(EmuTime::param /*time*/)
27 {
28  file.close();
29 }
30 
31 std::string_view MidiOutLogger::getName() const
32 {
33  return "midi-out-logger";
34 }
35 
36 std::string_view MidiOutLogger::getDescription() const
37 {
38  return "Midi output logger. Log all data that is sent to this "
39  "pluggable to a file. The filename is set with the "
40  "'midi-out-logfilename' setting.";
41 }
42 
43 void MidiOutLogger::recvByte(byte value, EmuTime::param /*time*/)
44 {
45  if (file.is_open()) {
46  file.put(value);
47  file.flush();
48  }
49 }
50 
51 template<typename Archive>
52 void MidiOutLogger::serialize(Archive& /*ar*/, unsigned /*version*/)
53 {
54  // don't try to resume a previous logfile (see PrinterPortLogger)
55 }
58 
59 } // 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)
Definition: MidiOutLogger.cc:8
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:5
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983