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) {
|
void KeyboardController::keyDownEvent(int key, int modifiers, const QString& text) {
|
||||||
|
addEventToQueue(key, NoteEventType::NoteOn);
|
||||||
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()
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardController::keyUpEvent(int key, int modifiers, const QString& text) {
|
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);
|
auto it = configuration_.keymap.find(key);
|
||||||
if (it == configuration_.keymap.end()) return;
|
if (it == configuration_.keymap.end()) return;
|
||||||
|
|
||||||
queue_->push({
|
queue_->push({
|
||||||
NoteEventType::NoteOff,
|
type,
|
||||||
it->second,
|
it->second,
|
||||||
0.8f,
|
defaultVelocity_,
|
||||||
std::chrono::high_resolution_clock::now()
|
std::chrono::high_resolution_clock::now()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void addEventToQueue(int key, NoteEventType type);
|
||||||
|
|
||||||
NoteQueue* queue_;
|
NoteQueue* queue_;
|
||||||
ConfigService* config_;
|
ConfigService* config_;
|
||||||
LoggerService* logger_;
|
LoggerService* logger_;
|
||||||
@@ -32,4 +34,6 @@ private:
|
|||||||
// keymap is key -> midi note id
|
// keymap is key -> midi note id
|
||||||
KeymapConfig configuration_;
|
KeymapConfig configuration_;
|
||||||
|
|
||||||
|
static constexpr float defaultVelocity_ = 0.8f;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user