41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
|
|
#include "KeyboardController.hpp"
|
|
|
|
#include <iostream>
|
|
// #include <yaml-cpp/yaml.h>
|
|
#include <filesystem>
|
|
|
|
KeyboardController::KeyboardController(QObject* parent) : QObject(parent) {
|
|
|
|
}
|
|
|
|
KeyboardController::KeyboardController(ConfigService* config, LoggerService* logger, NoteQueue* queue) : config_(config), logger_(logger), queue_(queue) {
|
|
|
|
// load keymap from config service
|
|
if(!(config->getConfig<KeymapParams, KeymapConfig>("KeyboardController", "Main", &configuration_))) {
|
|
logger_->log("Keyboard", LogFlag::Error, "Failed to get logger configuration fom config service");
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
void KeyboardController::keyDownEvent(int key, int modifiers, const QString& text) {
|
|
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({
|
|
type,
|
|
it->second,
|
|
defaultVelocity_,
|
|
std::chrono::high_resolution_clock::now()
|
|
});
|
|
} |