openMSX
MidiOutWindows.cc
Go to the documentation of this file.
1#if defined(_WIN32)
2
3#include "Midi_w32.hh"
4#include "MidiOutWindows.hh"
6#include "PlugException.hh"
7#include "serialize.hh"
8#include "xrange.hh"
9#include <memory>
10
11namespace openmsx {
12
13void MidiOutWindows::registerAll(PluggingController& controller)
14{
15 w32_midiOutInit();
16 for (auto i : xrange(w32_midiOutGetVFNsNum())) {
17 controller.registerPluggable(std::make_unique<MidiOutWindows>(i));
18 }
19}
20
21
22MidiOutWindows::MidiOutWindows(unsigned num)
23 : devIdx(unsigned(-1))
24{
25 name = w32_midiOutGetVFN(num);
26 desc = w32_midiOutGetRDN(num);
27}
28
29MidiOutWindows::~MidiOutWindows()
30{
31 //w32_midiOutClean(); // TODO
32}
33
34void MidiOutWindows::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
35{
36 devIdx = w32_midiOutOpen(name.c_str());
37 if (devIdx == unsigned(-1)) {
38 throw PlugException("Failed to open " + name);
39 }
40}
41
42void MidiOutWindows::unplugHelper(EmuTime::param /*time*/)
43{
44 if (devIdx != unsigned(-1)) {
45 w32_midiOutClose(devIdx);
46 devIdx = unsigned(-1);
47 }
48}
49
50std::string_view MidiOutWindows::getName() const
51{
52 return name;
53}
54
55std::string_view MidiOutWindows::getDescription() const
56{
57 return desc;
58}
59
60void MidiOutWindows::recvMessage(const std::vector<uint8_t>& message, EmuTime::param /*time*/)
61{
62 if (devIdx != unsigned(-1)) {
63 w32_midiOutMsg(message.size(), message.data(), devIdx);
64 }
65}
66
67template<typename Archive>
68void MidiOutWindows::serialize(Archive& /*ar*/, unsigned /*version*/)
69{
70 // don't restore this after loadstate
71}
72INSTANTIATE_SERIALIZE_METHODS(MidiOutWindows);
73REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, MidiOutWindows, "MidiOutWindows");
74
75} // namespace openmsx
76
77#endif // defined(_WIN32)
This file implemented 3 utility functions:
Definition Autofire.cc:9
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)
constexpr auto xrange(T e)
Definition xrange.hh:132