1- #pragma once
1+ #pragma once
2+
23#define NOMINMAX
34
45#include < atomic>
6+ #include < array>
57#include < memory>
6- #include < vector>
78#include < string>
89#include < string_view>
9- #include < array >
10+ #include < vector >
1011
1112// WinRT for MIDI
1213#include < winrt/Windows.Foundation.h>
13- #include < winrt/Windows.Devices.Midi.h>
1414#include < winrt/Windows.Devices.Enumeration.h>
15+ #include < winrt/Windows.Devices.Midi.h>
1516
1617// Classic Windows
1718#include < windows.h>
2223struct PrecomputedKeyEvents ;
2324
2425// --------------------------------------------------------------------------------
25- // The MIDI2Key class: minimal overhead, no-latency approach for MIDI→QWERTY
26+ // MIDI2Key: Pain and Suffering
2627// --------------------------------------------------------------------------------
2728class MIDI2Key {
2829public:
@@ -36,31 +37,30 @@ class MIDI2Key {
3637 bool IsActive () const ;
3738 void SetActive (bool active);
3839
39- int GetSelectedDevice () const ;
40- int GetSelectedChannel () const ;
40+ int GetSelectedDevice () const ;
41+ int GetSelectedChannel () const ;
4142
4243private:
4344 void ProcessMidiMessage (winrt::Windows::Devices::Midi::IMidiMessage const & midiMessage);
4445
4546 // WinRT MIDI port
4647 winrt::Windows::Devices::Midi::MidiInPort m_midiInPort{ nullptr };
47- winrt::event_token m_messageToken;
48+ winrt::event_token m_messageToken;
4849
49- int m_selectedDevice;
50- int m_selectedChannel;
50+ int m_selectedDevice;
51+ int m_selectedChannel;
5152 std::atomic<bool > m_isActive;
52-
53- // External pointer to your logic
54- VirtualPianoPlayer* m_player;
53+ VirtualPianoPlayer* m_player; // copy
5554
5655 // Key injection buffers
5756 alignas (64 ) static INPUT m_velocityInputs[4 ];
5857 alignas (64 ) static INPUT m_sustainInput[2 ];
59- alignas (64 ) static char m_lastVelocityKey;
60- // Example: alt, ctrl, shift usage counters
58+ alignas (64 ) static char m_lastVelocityKey;
59+
60+ // Modifier usage counters (e.g., alt, ctrl, shift)
6161 alignas (64 ) static std::atomic<int > modifierCounts[3 ];
6262
63- // For each note [0..127], track " is pressed?"
63+ // For each note [0..127], track if it is pressed
6464 alignas (64 ) std::array<std::atomic<bool >, 128 > pressed;
6565};
6666
0 commit comments