condense reused code
This commit is contained in:
@@ -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()
|
||||
});
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user