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{
24 name = w32_midiOutGetVFN(num);
25 desc = w32_midiOutGetRDN(num);
26}
27
28MidiOutWindows::~MidiOutWindows()
29{
30 //w32_midiOutClean(); // TODO
31}
32
33void MidiOutWindows::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
34{
35 devIdx = w32_midiOutOpen(name.c_str());
36 if (devIdx == unsigned(-1)) {
37 throw PlugException("Failed to open " + name);
38 }
39}
40
41void MidiOutWindows::unplugHelper(EmuTime::param /*time*/)
42{
43 if (devIdx != unsigned(-1)) {
44 w32_midiOutClose(devIdx);
45 devIdx = unsigned(-1);
46 }
47}
48
49std::string_view MidiOutWindows::getName() const
50{
51 return name;
52}
53
54std::string_view MidiOutWindows::getDescription() const
55{
56 return desc;
57}
58
59void MidiOutWindows::recvMessage(const std::vector<uint8_t>& message, EmuTime::param /*time*/)
60{
61 if (devIdx != unsigned(-1)) {
62 w32_midiOutMsg(message.size(), message.data(), devIdx);
63 }
64}
65
66template<typename Archive>
67void MidiOutWindows::serialize(Archive& /*ar*/, unsigned /*version*/)
68{
69 // don't restore this after loadstate
70}
71INSTANTIATE_SERIALIZE_METHODS(MidiOutWindows);
72REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, MidiOutWindows, "MidiOutWindows");
73
74} // namespace openmsx
75
76#endif // defined(_WIN32)
This file implemented 3 utility functions:
Definition Autofire.cc:11
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)
constexpr auto xrange(T e)
Definition xrange.hh:132