openMSX
MidiOutWindows.cc
Go to the documentation of this file.
1 #if defined(_WIN32)
2 
3 #include "Midi_w32.hh"
4 #include "MidiOutWindows.hh"
5 #include "PluggingController.hh"
6 #include "PlugException.hh"
7 #include "serialize.hh"
8 #include "xrange.hh"
9 #include <memory>
10 
11 using std::string;
12 
13 namespace openmsx {
14 
15 void MidiOutWindows::registerAll(PluggingController& controller)
16 {
17  w32_midiOutInit();
18  for (auto i : xrange(w32_midiOutGetVFNsNum())) {
19  controller.registerPluggable(std::make_unique<MidiOutWindows>(i));
20  }
21 }
22 
23 
24 MidiOutWindows::MidiOutWindows(unsigned num)
25  : devidx(unsigned(-1))
26 {
27  name = w32_midiOutGetVFN(num);
28  desc = w32_midiOutGetRDN(num);
29 }
30 
31 MidiOutWindows::~MidiOutWindows()
32 {
33  //w32_midiOutClean(); // TODO
34 }
35 
36 void MidiOutWindows::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
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::param /*time*/)
45 {
46  if (devidx != unsigned(-1)) {
47  w32_midiOutClose(devidx);
48  devidx = unsigned(-1);
49  }
50 }
51 
52 std::string_view MidiOutWindows::getName() const
53 {
54  return name;
55 }
56 
57 std::string_view MidiOutWindows::getDescription() const
58 {
59  return desc;
60 }
61 
62 void MidiOutWindows::recvMessage(const std::vector<uint8_t>& message, EmuTime::param /*time*/)
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& /*ar*/, unsigned /*version*/)
71 {
72  // don't restore this after loadstate
73 }
74 INSTANTIATE_SERIALIZE_METHODS(MidiOutWindows);
75 REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, MidiOutWindows, "MidiOutWindows");
76 
77 } // namespace openmsx
78 
79 #endif // defined(_WIN32)
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:742
This file implemented 3 utility functions:
Definition: Autofire.cc:5
void serialize(Archive &ar, T &t, unsigned version)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)
constexpr auto xrange(T e)
Definition: xrange.hh:155