openMSX
MidiOutLogger.cc
Go to the documentation of this file.
1 #include "MidiOutLogger.hh"
2 #include "PlugException.hh"
3 #include "FilenameSetting.hh"
4 #include "FileOperations.hh"
5 #include "serialize.hh"
6 #include "memory.hh"
7 
8 namespace openmsx {
9 
11  : logFilenameSetting(make_unique<FilenameSetting>(
12  commandController, "midi-out-logfilename",
13  "filename of the file where the MIDI output is logged to",
14  "/dev/midi"))
15 {
16 }
17 
19 {
20 }
21 
23  EmuTime::param /*time*/)
24 {
25  FileOperations::openofstream(file, logFilenameSetting->getValue());
26  if (file.fail()) {
27  file.clear();
28  throw PlugException("Error opening log file");
29  }
30 }
31 
33 {
34  file.close();
35 }
36 
37 const std::string& MidiOutLogger::getName() const
38 {
39  static const std::string name("midi-out-logger");
40  return name;
41 }
42 
44 {
45  return "Midi output logger. Log all data that is sent to this "
46  "pluggable to a file. The filename is set with the "
47  "'midi-out-logfilename' setting.";
48 }
49 
51 {
52  if (file.is_open()) {
53  file.put(value);
54  file.flush();
55  }
56 }
57 
58 template<typename Archive>
59 void MidiOutLogger::serialize(Archive& /*ar*/, unsigned /*version*/)
60 {
61  // don't try to resume a previous logfile (see PrinterPortLogger)
62 }
65 
66 } // namespace openmsx