condense reused code

This commit is contained in:
2026-06-10 20:51:25 -05:00
parent 8eb5a619ad
commit 38dee08ab7
2 changed files with 11 additions and 13 deletions

View File

@@ -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()
});
}

View File

@@ -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;
};