| 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& , |
| 20 |
EmuTime ) |
| 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 ) |
| 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 ) |
| 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& , unsigned ) |
| 56 |
{ |
| 57 |
|
| 58 |
} |
| 59 |
INSTANTIATE_SERIALIZE_METHODS(MidiOutLogger); |
| 60 |
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, MidiOutLogger, "MidiOutLogger"); |
| 61 |
|
| 62 |
} |