| 1 |
#ifndef MIDIINWINDOWS_HH |
| 2 |
#define MIDIINWINDOWS_HH |
| 3 |
|
| 4 |
#ifdef _WIN32 |
| 5 |
|
| 6 |
#ifndef WIN32_LEAN_AND_MEAN |
| 7 |
#define WIN32_LEAN_AND_MEAN |
| 8 |
#endif |
| 9 |
|
| 10 |
#include "MidiInDevice.hh" |
| 11 |
#include "EventListener.hh" |
| 12 |
#include "serialize_meta.hh" |
| 13 |
#include "circular_buffer.hh" |
| 14 |
#include <windows.h> |
| 15 |
#include <mmsystem.h> |
| 16 |
|
| 17 |
#include <cstdint> |
| 18 |
#include <latch> |
| 19 |
#include <mutex> |
| 20 |
#include <optional> |
| 21 |
#include <thread> |
| 22 |
|
| 23 |
namespace openmsx { |
| 24 |
|
| 25 |
class EventDistributor; |
| 26 |
class Scheduler; |
| 27 |
class PluggingController; |
| 28 |
|
| 29 |
class MidiInWindows final : public MidiInDevice, private EventListener |
| 30 |
{ |
| 31 |
public: |
| 32 |
|
| 33 |
|
| 34 |
static void registerAll(EventDistributor& eventDistributor, |
| 35 |
Scheduler& scheduler, |
| 36 |
PluggingController& controller); |
| 37 |
|
| 38 |
MidiInWindows(EventDistributor& eventDistributor, Scheduler& scheduler, |
| 39 |
unsigned num); |
| 40 |
~MidiInWindows() override; |
| 41 |
|
| 42 |
|
| 43 |
void plugHelper(Connector& connector, EmuTime time) override; |
| 44 |
void unplugHelper(EmuTime time) override; |
| 45 |
[[nodiscard]] zstring_view getName() const override; |
| 46 |
[[nodiscard]] zstring_view getDescription() const override; |
| 47 |
|
| 48 |
|
| 49 |
void signal(EmuTime time) override; |
| 50 |
|
| 51 |
template<typename Archive> |
| 52 |
void serialize(Archive& ar, unsigned version); |
| 53 |
|
| 54 |
private: |
| 55 |
void run(); |
| 56 |
|
| 57 |
|
| 58 |
bool signalEvent(const Event& event) override; |
| 59 |
|
| 60 |
void procShortMsg(long unsigned param); |
| 61 |
void procLongMsg(LPMIDIHDR p); |
| 62 |
|
| 63 |
private: |
| 64 |
EventDistributor& eventDistributor; |
| 65 |
Scheduler& scheduler; |
| 66 |
std::thread thread; |
| 67 |
std::optional<std::latch> threadIdLatch; |
| 68 |
std::optional<std::latch> devIdxLatch; |
| 69 |
unsigned devIdx = unsigned(-1); |
| 70 |
DWORD threadId; |
| 71 |
cb_queue<uint8_t> queue; |
| 72 |
std::mutex queueMutex; |
| 73 |
std::string name; |
| 74 |
std::string desc; |
| 75 |
}; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
#endif |
| 80 |
#endif |