forked from Zephkek/MIDIPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.hpp
More file actions
149 lines (123 loc) · 4.77 KB
/
config.hpp
File metadata and controls
149 lines (123 loc) · 4.77 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma once
#include <string>
#include <map>
#include <stdexcept>
#include <filesystem>
#include <optional>
#include "json.hpp"
namespace midi {
// Forward declarations
class ConfigException : public std::runtime_error {
public:
explicit ConfigException(const std::string& message) : std::runtime_error(message) {}
};
enum class VelocityCurveType {
LinearCoarse = 0,
LinearFine = 1,
ImprovedLowVolume = 2,
Logarithmic = 3,
Exponential = 4,
Custom = 5
};
enum class NoteHandlingMode {
FIFO,
LIFO,
NoHandling
};
// Configuration structures
struct VolumeSettings {
int MIN_VOLUME = 10;
int MAX_VOLUME = 200;
int INITIAL_VOLUME = 100;
int VOLUME_STEP = 10;
int ADJUSTMENT_INTERVAL_MS = 50;
void validate() const;
};
struct LegitModeSettings {
bool ENABLED = false;
double TIMING_VARIATION = 0.1;
double NOTE_SKIP_CHANCE = 0.02;
double EXTRA_DELAY_CHANCE = 0.05;
double EXTRA_DELAY_MIN = 0.05;
double EXTRA_DELAY_MAX = 0.2;
void validate() const;
};
struct AutoTranspose {
bool ENABLED = false;
std::string TRANSPOSE_UP_KEY = "VK_UP"; // Default to Up Arrow
std::string TRANSPOSE_DOWN_KEY = "VK_DOWN"; // Default to Down Arrow
void validate() const;
};
struct UISettings {
bool alwaysOnTop = false;
};
struct MIDISettings {
bool FILTER_DRUMS = true;
void validate() const;
};
struct HotkeySettings {
std::string SUSTAIN_KEY = "VK_SPACE";
std::string VOLUME_UP_KEY = "VK_RIGHT";
std::string VOLUME_DOWN_KEY = "VK_LEFT";
std::string PLAY_PAUSE_KEY = "VK_F1"; // Added default for play/pause
std::string REWIND_KEY = "VK_F2"; // Added default for rewind
std::string SKIP_KEY = "VK_F3"; // Added default for skip
std::string EMERGENCY_EXIT_KEY = "VK_F4"; // Added default for emergency exit
void validate() const;
};
struct CustomVelocityCurve {
std::string name;
std::array<int, 32> velocityValues;
};
// Modify PlaybackSettings
struct PlaybackSettings {
VelocityCurveType velocityCurve = VelocityCurveType::LinearCoarse;
NoteHandlingMode noteHandlingMode = NoteHandlingMode::LIFO;
std::vector<CustomVelocityCurve> customVelocityCurves;
void validate() const;
};
class Config {
public:
MIDISettings midi;
PlaybackSettings playback;
VolumeSettings volume;
LegitModeSettings legit_mode;
AutoTranspose auto_transpose;
HotkeySettings hotkeys;
UISettings ui;
std::map<std::string, std::map<std::string, std::string>> key_mappings;
std::map<std::string, std::string> controls;
std::vector<std::string> playlistFiles;
static Config& getInstance();
void loadFromFile(const std::filesystem::path& path);
void saveToFile(const std::filesystem::path& path) const;
void validate() const;
void setDefaults();
// Conversion methods made public and static
static NoteHandlingMode stringToNoteHandlingMode(const std::string& mode);
static std::string noteHandlingModeToString(NoteHandlingMode mode);
// Delete copy constructor and assignment operator
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;
private:
Config() = default;
void validateKeyMappings() const;
};
// JSON conversion functions declarations
void to_json(nlohmann::json& j, const VolumeSettings& v);
void from_json(const nlohmann::json& j, VolumeSettings& v);
void to_json(nlohmann::json& j, const LegitModeSettings& l);
void from_json(const nlohmann::json& j, LegitModeSettings& l);
void to_json(nlohmann::json& j, const AutoTranspose& l);
void from_json(const nlohmann::json& j, AutoTranspose& l);
void to_json(nlohmann::json& j, const MIDISettings& m);
void from_json(const nlohmann::json& j, MIDISettings& m);
void to_json(nlohmann::json& j, const HotkeySettings& h);
void from_json(const nlohmann::json& j, HotkeySettings& h);
void to_json(nlohmann::json& j, const PlaybackSettings& p);
void from_json(const nlohmann::json& j, PlaybackSettings& p);
void to_json(nlohmann::json& j, const Config& c);
void from_json(const nlohmann::json& j, Config& c);
void to_json(nlohmann::json& j, const UISettings& ui);
void from_json(const nlohmann::json& j, UISettings& ui);
} // namespace midi