From b2f0cb564a296653c83b0a64c0f9a3de0a2f0d5e Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 6 Jan 2025 00:15:32 +0100 Subject: Implement touchpad --- UI.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'UI.cpp') diff --git a/UI.cpp b/UI.cpp index 5d304b0..2dab410 100644 --- a/UI.cpp +++ b/UI.cpp @@ -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() -- cgit v1.2.3