1
- #pragma once
1
+ #pragma once
2
+
2
3
#define NOMINMAX
3
4
4
5
#include < atomic>
6
+ #include < array>
5
7
#include < memory>
6
- #include < vector>
7
8
#include < string>
8
9
#include < string_view>
9
- #include < array >
10
+ #include < vector >
10
11
11
12
// WinRT for MIDI
12
13
#include < winrt/Windows.Foundation.h>
13
- #include < winrt/Windows.Devices.Midi.h>
14
14
#include < winrt/Windows.Devices.Enumeration.h>
15
+ #include < winrt/Windows.Devices.Midi.h>
15
16
16
17
// Classic Windows
17
18
#include < windows.h>
22
23
struct PrecomputedKeyEvents ;
23
24
24
25
// --------------------------------------------------------------------------------
25
- // The MIDI2Key class: minimal overhead, no-latency approach for MIDI→QWERTY
26
+ // MIDI2Key: Pain and Suffering
26
27
// --------------------------------------------------------------------------------
27
28
class MIDI2Key {
28
29
public:
@@ -36,31 +37,30 @@ class MIDI2Key {
36
37
bool IsActive () const ;
37
38
void SetActive (bool active);
38
39
39
- int GetSelectedDevice () const ;
40
- int GetSelectedChannel () const ;
40
+ int GetSelectedDevice () const ;
41
+ int GetSelectedChannel () const ;
41
42
42
43
private:
43
44
void ProcessMidiMessage (winrt::Windows::Devices::Midi::IMidiMessage const & midiMessage);
44
45
45
46
// WinRT MIDI port
46
47
winrt::Windows::Devices::Midi::MidiInPort m_midiInPort{ nullptr };
47
- winrt::event_token m_messageToken;
48
+ winrt::event_token m_messageToken;
48
49
49
- int m_selectedDevice;
50
- int m_selectedChannel;
50
+ int m_selectedDevice;
51
+ int m_selectedChannel;
51
52
std::atomic<bool > m_isActive;
52
-
53
- // External pointer to your logic
54
- VirtualPianoPlayer* m_player;
53
+ VirtualPianoPlayer* m_player; // copy
55
54
56
55
// Key injection buffers
57
56
alignas (64 ) static INPUT m_velocityInputs[4 ];
58
57
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)
61
61
alignas (64 ) static std::atomic<int > modifierCounts[3 ];
62
62
63
- // For each note [0..127], track " is pressed?"
63
+ // For each note [0..127], track if it is pressed
64
64
alignas (64 ) std::array<std::atomic<bool >, 128 > pressed;
65
65
};
66
66
0 commit comments