diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-06 00:15:32 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-06 00:15:32 +0100 |
commit | b2f0cb564a296653c83b0a64c0f9a3de0a2f0d5e (patch) | |
tree | 5085292872631bc317afe29a71c1bb9d25fe2a78 /UI.cpp | |
parent | 7c40af4b4950a69e67c26ebb3c5568cbfbc3dda9 (diff) |
Implement touchpad
Diffstat (limited to 'UI.cpp')
-rw-r--r-- | UI.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -61,16 +61,16 @@ UI::UI(Config& config): m_active_sensing_timestamp{}, m_midi_timestamp{}, m_note_bpm{}, - m_clock_bpm{} + m_clock_bpm{}, + m_touchpad{} { } bool UI::key_available() { struct pollfd fds{}; - int ret; fds.fd = 0; // stdin fds.events = POLLIN; - ret = poll(&fds, 1, 0); + int ret = poll(&fds, 1, 0); if (ret == 0) return false; else if (ret == 1) @@ -179,6 +179,7 @@ void UI::draw() void UI::handle_input() { + // handle console key if (key_available()) { char c; std::cin >> c; @@ -206,6 +207,20 @@ void UI::handle_input() log_cout << fmt::format("Unknown key: {}", c) << std::endl; } } + + // handle touchpad + if (m_touchpad.is_valid() && m_touchpad.event_available()) { + input_event ev = m_touchpad.get_event(); + + if (m_touchpad.event_is_button1(ev)) { + m_config.set_mode((m_config.get_mode() + 1) % 3); + } else if (m_touchpad.event_is_button2(ev)) { + if (!m_midi_monitor.empty()) { + m_config.set_midi_channel(m_midi_monitor.front().first); + m_config.set_midi_note(m_midi_monitor.front().second); + } + } + } } void UI::count_main_loops() |