| 1 |
#ifdef _WIN32 |
| 2 |
|
| 3 |
#include "MidiOutWindows.hh" |
| 4 |
|
| 5 |
#include "Midi_w32.hh" |
| 6 |
#include "PluggingController.hh" |
| 7 |
#include "PlugException.hh" |
| 8 |
#include "serialize.hh" |
| 9 |
|
| 10 |
#include "xrange.hh" |
| 11 |
|
| 12 |
#include <memory> |
| 13 |
|
| 14 |
namespace openmsx { |
| 15 |
|
| 16 |
void MidiOutWindows::registerAll(PluggingController& controller) |
| 17 |
{ |
| 18 |
w32_midiOutInit(); |
| 19 |
for (auto i : xrange(w32_midiOutGetVFNsNum())) { |
| 20 |
controller.registerPluggable(std::make_unique<MidiOutWindows>(i)); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
MidiOutWindows::MidiOutWindows(unsigned num) |
| 26 |
{ |
| 27 |
name = w32_midiOutGetVFN(num); |
| 28 |
desc = w32_midiOutGetRDN(num); |
| 29 |
} |
| 30 |
|
| 31 |
MidiOutWindows::~MidiOutWindows() |
| 32 |
{ |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
void MidiOutWindows::plugHelper(Connector& , EmuTime ) |
| 37 |
{ |
| 38 |
devIdx = w32_midiOutOpen(name.c_str()); |
| 39 |
if (devIdx == unsigned(-1)) { |
| 40 |
throw PlugException("Failed to open " + name); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
void MidiOutWindows::unplugHelper(EmuTime ) |
| 45 |
{ |
| 46 |
if (devIdx != unsigned(-1)) { |
| 47 |
w32_midiOutClose(devIdx); |
| 48 |
devIdx = unsigned(-1); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
zstring_view MidiOutWindows::getName() const |
| 53 |
{ |
| 54 |
return name; |
| 55 |
} |
| 56 |
|
| 57 |
zstring_view MidiOutWindows::getDescription() const |
| 58 |
{ |
| 59 |
return desc; |
| 60 |
} |
| 61 |
|
| 62 |
void MidiOutWindows::recvMessage(const std::vector<uint8_t>& message, EmuTime ) |
| 63 |
{ |
| 64 |
if (devIdx != unsigned(-1)) { |
| 65 |
w32_midiOutMsg(message.size(), message.data(), devIdx); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
template<typename Archive> |
| 70 |
void MidiOutWindows::serialize(Archive& , unsigned ) |
| 71 |
{ |
| 72 |
|
| 73 |
} |
| 74 |
INSTANTIATE_SERIALIZE_METHODS(MidiOutWindows); |
| 75 |
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, MidiOutWindows, "MidiOutWindows"); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
#endif |