openMSX
MidiInWindows.hh
Go to the documentation of this file.
1 #ifndef MIDIINWINDOWS_HH
2 #define MIDIINWINDOWS_HH
3 
4 #if defined(_WIN32)
5 
6 #ifndef WIN32_LEAN_AND_MEAN
7 #define WIN32_LEAN_AND_MEAN
8 #endif
9 
10 #include "openmsx.hh"
11 #include "MidiInDevice.hh"
12 #include "EventListener.hh"
13 #include "serialize_meta.hh"
14 #include "circular_buffer.hh"
15 #include <windows.h>
16 #include <mmsystem.h>
17 #include <mutex>
18 #include <condition_variable>
19 #include <thread>
20 
21 namespace openmsx {
22 
23 class EventDistributor;
24 class Scheduler;
25 class PluggingController;
26 
27 class MidiInWindows final : public MidiInDevice, private EventListener
28 {
29 public:
32  static void registerAll(EventDistributor& eventDistributor,
33  Scheduler& scheduler,
34  PluggingController& controller);
35 
36  MidiInWindows(EventDistributor& eventDistributor, Scheduler& scheduler,
37  unsigned num);
38  ~MidiInWindows();
39 
40  // Pluggable
41  void plugHelper(Connector& connector, EmuTime::param time) override;
42  void unplugHelper(EmuTime::param time) override;
43  const std::string& getName() const override;
44  string_ref getDescription() const override;
45 
46  // MidiInDevice
47  void signal(EmuTime::param time) override;
48 
49  template<typename Archive>
50  void serialize(Archive& ar, unsigned version);
51 
52 private:
53  void run();
54 
55  // EventListener
56  int signalEvent(const std::shared_ptr<const Event>& event) override;
57 
58  void procShortMsg(long unsigned param);
59  void procLongMsg(LPMIDIHDR p);
60 
61  EventDistributor& eventDistributor;
62  Scheduler& scheduler;
63  std::thread thread;
64  std::mutex devIdxMutex;
65  std::condition_variable devIdxCond;
66  unsigned devIdx;
67  std::mutex threadIdMutex;
68  std::condition_variable threadIdCond;
69  DWORD threadId;
70  cb_queue<byte> queue;
71  std::mutex queueMutex;
72  std::string name;
73  std::string desc;
74 };
75 
76 } // namespace openmsx
77 
78 #endif // defined(_WIN32)
79 #endif // MIDIINWINDOWS_HH
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
const EmuTime & param
Definition: EmuTime.hh:20
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
const string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:373
void serialize(Archive &ar, T &t, unsigned version)