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
21namespace openmsx {
22
23class EventDistributor;
24class Scheduler;
25class PluggingController;
26
27class MidiInWindows final : public MidiInDevice, private EventListener
28{
29public:
32 static void registerAll(EventDistributor& eventDistributor,
33 Scheduler& scheduler,
34 PluggingController& controller);
35
36 MidiInWindows(EventDistributor& eventDistributor, Scheduler& scheduler,
37 unsigned num);
38 ~MidiInWindows() override;
39
40 // Pluggable
41 void plugHelper(Connector& connector, EmuTime::param time) override;
42 void unplugHelper(EmuTime::param time) override;
43 [[nodiscard]] std::string_view getName() const override;
44 [[nodiscard]] std::string_view 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
52private:
53 void run();
54
55 // EventListener
56 int signalEvent(const Event& event) override;
57
58 void procShortMsg(long unsigned param);
59 void procLongMsg(LPMIDIHDR p);
60
61private:
62 EventDistributor& eventDistributor;
63 Scheduler& scheduler;
64 std::thread thread;
65 std::mutex devIdxMutex;
66 std::condition_variable devIdxCond;
67 unsigned devIdx;
68 std::mutex threadIdMutex;
69 std::condition_variable threadIdCond;
70 DWORD threadId;
71 cb_queue<byte> queue;
72 std::mutex queueMutex;
73 std::string name;
74 std::string desc;
75};
76
77} // namespace openmsx
78
79#endif // defined(_WIN32)
80#endif // MIDIINWINDOWS_HH
This implements a queue on top of circular_buffer (not part of boost).
This file implemented 3 utility functions:
Definition Autofire.cc:11
void serialize(Archive &ar, T &t, unsigned version)