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 <memory>
9 
10 using std::string;
11 
12 namespace openmsx {
13 
14 void MidiOutWindows::registerAll(PluggingController& controller)
15 {
16  w32_midiOutInit();
17  unsigned devnum = w32_midiOutGetVFNsNum();
18  for (unsigned i = 0; i < devnum; ++i) {
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 const string& 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)
serialize.hh
PlugException.hh
PluggingController.hh
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:742
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:982
Midi_w32.hh
openmsx::serialize
void serialize(Archive &ar, T &t, unsigned version)
Definition: serialize_core.hh:41
MidiOutWindows.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::REGISTER_POLYMORPHIC_INITIALIZER
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
openmsx::Connector
Connector
Definition: Connector.cc:83