blob: 2cd061cc5be06fc95c4a380f1a996469151f9291 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#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()
{
recover();
}
Config::~Config()
{
persist();
}
void Config::recover()
{
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;
}
}
void Config::persist()
{
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;
}
|