From 38dee08ab73bdfa2cf115207cf47787bf4ceb0f5 Mon Sep 17 00:00:00 2001 From: Bliblank Date: Wed, 10 Jun 2026 20:51:25 -0500 Subject: [PATCH] condense reused code --- src/synth/KeyboardController.cpp | 20 +++++++------------- src/synth/KeyboardController.hpp | 4 ++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/synth/KeyboardController.cpp b/src/synth/KeyboardController.cpp index d914cde..858375d 100644 --- a/src/synth/KeyboardController.cpp +++ b/src/synth/KeyboardController.cpp @@ -20,28 +20,22 @@ KeyboardController::KeyboardController(ConfigService* config, LoggerService* log } void KeyboardController::keyDownEvent(int key, int modifiers, const QString& text) { - - auto it = configuration_.keymap.find(key); - if (it == configuration_.keymap.end()) return; - - queue_->push({ - NoteEventType::NoteOn, - it->second, - 0.8f, - std::chrono::high_resolution_clock::now() - }); - + addEventToQueue(key, NoteEventType::NoteOn); } void KeyboardController::keyUpEvent(int key, int modifiers, const QString& text) { + addEventToQueue(key, NoteEventType::NoteOff); +} + +void KeyboardController::addEventToQueue(int key, NoteEventType type) { auto it = configuration_.keymap.find(key); if (it == configuration_.keymap.end()) return; queue_->push({ - NoteEventType::NoteOff, + type, it->second, - 0.8f, + defaultVelocity_, std::chrono::high_resolution_clock::now() }); } \ No newline at end of file diff --git a/src/synth/KeyboardController.hpp b/src/synth/KeyboardController.hpp index 4095481..8ff6ccf 100644 --- a/src/synth/KeyboardController.hpp +++ b/src/synth/KeyboardController.hpp @@ -25,6 +25,8 @@ public: private: + void addEventToQueue(int key, NoteEventType type); + NoteQueue* queue_; ConfigService* config_; LoggerService* logger_; @@ -32,4 +34,6 @@ private: // keymap is key -> midi note id KeymapConfig configuration_; + static constexpr float defaultVelocity_ = 0.8f; + };