add config integration for keymap and logger

This commit is contained in:
2026-06-09 22:39:38 -05:00
parent 30b06e077c
commit 7231d948bc
7 changed files with 437 additions and 81 deletions

View File

@@ -5,37 +5,14 @@
// #include <yaml-cpp/yaml.h>
#include <filesystem>
KeyboardController::KeyboardController(NoteQueue& queue, ConfigService* config) : queue_(queue), config_(config) {
KeyboardController::KeyboardController(ConfigService* config, LoggerService* logger, NoteQueue* queue) : config_(config), logger_(logger), queue_(queue) {
// load keymap from config file
std::string filepath = "config/keymap.yaml";
filepath = std::filesystem::absolute(filepath).string();
// YAML::Node file;
try {
// file = YAML::LoadFile(filepath);
} catch(const std::exception& e) {
std::cerr << e.what() << std::endl;
// load keymap from config service
if(!(config->getConfig<KeymapConfig>("KeyboardController", "Main", &configuration_))) {
logger_->log("Keyboard", LogFlag::Error, "Failed to get logger configuration fom config service");
return;
}
// YAML::Node keymapNode = file["keymap"]; // node for string to string mappings
// YAML::Node notesNode = file["notes"]; // string to midi int mappings
// YAML::Node keysNode = file["keys"]; // string to qt key id mappings
// for each element in the keymap
// for (const auto& entry : keymapNode) {
// std::string keyString = entry.first.as<std::string>();
// std::string noteString = entry.second.as<std::string>();
// // match the strings to ints
// uint8_t noteValue = notesNode[noteString].as<uint8_t>();
// uint32_t keyValue = keysNode[keyString].as<uint32_t>();
// // insert into map
// keymap_.emplace(keyValue, noteValue);
// }
}
void KeyboardController::handleKeyPress(QKeyEvent* e) {
@@ -44,7 +21,7 @@ void KeyboardController::handleKeyPress(QKeyEvent* e) {
auto it = keymap_.find(e->key());
if (it == keymap_.end()) return;
queue_.push({
queue_->push({
NoteEventType::NoteOn,
it->second,
0.8f,
@@ -58,7 +35,7 @@ void KeyboardController::handleKeyRelease(QKeyEvent* e) {
auto it = keymap_.find(e->key());
if (it == keymap_.end()) return;
queue_.push({
queue_->push({
NoteEventType::NoteOff,
it->second,
0.8f,