summaryrefslogtreecommitdiffhomepage
path: root/config.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-03 20:17:26 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-03 20:17:26 +0100
commit6bf4770e950299da92952f2965cccf86a903fc9f (patch)
tree9854c706f0fc8104f1f85fe0f6ff58b56661a5a6 /config.cpp
parent81ef3f08215a62d469c49762ccd492cb806150c4 (diff)
Added config
Diffstat (limited to 'config.cpp')
-rw-r--r--config.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/config.cpp b/config.cpp
index a2c980f..b6460f2 100644
--- a/config.cpp
+++ b/config.cpp
@@ -1,4 +1,82 @@
#include "config.h"
+#include "log.h"
+
+#include <libreichwein/file.h>
+#include <libreichwein/stringhelper.h>
+
+#include <fmt/format.h>
+
+#include <string>
+
const char *device = "default"; // playback device
+std::string config_filename = "click.cfg";
+
+Config::Config()
+{
+ try {
+ // presets / defaults
+ m_midi_channel = CLICK_CHANNEL;
+ m_midi_note = CLICK_NOTE;
+ m_bpm = default_bpm;
+
+ std::string config = Reichwein::File::getFile(config_filename);
+
+ std::vector<std::string> lines = Reichwein::Stringhelper::split(config, "\n");
+
+ for (const auto& i: lines) {
+ if (i.starts_with("midi_channel=")) {
+ m_midi_channel = stoul(i.substr(13));
+ }
+ if (i.starts_with("midi_note=")) {
+ m_midi_note = stoul(i.substr(10));
+ }
+ if (i.starts_with("bpm=")) {
+ m_bpm = stoul(i.substr(4));
+ }
+ }
+ } catch (const std::exception& ex) {
+ log_cout << "Config not found. Setting config to defaults." << std::endl;
+ }
+}
+
+Config::~Config()
+{
+ std::string config = fmt::format("midi_channel={}\n", m_midi_channel) +
+ fmt::format("midi_note={}\n", m_midi_note) +
+ fmt::format("bpm={}\n", m_bpm);
+
+ Reichwein::File::setFile(config_filename, config);
+}
+
+int Config::get_midi_channel()
+{
+ return m_midi_channel;
+}
+
+void Config::set_midi_channel(int channel)
+{
+ m_midi_channel = channel;
+}
+
+int Config::get_midi_note()
+{
+ return m_midi_note;
+}
+
+void Config::set_midi_note(int note)
+{
+ m_midi_note = note;
+}
+
+int Config::get_bpm()
+{
+ return m_bpm;
+}
+
+void Config::set_bpm(int bpm)
+{
+ m_bpm = bpm;
+}
+