-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.cpp
More file actions
150 lines (140 loc) · 3.53 KB
/
Copy pathplugin.cpp
File metadata and controls
150 lines (140 loc) · 3.53 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
150
#include "plugin.hpp"
Plugin *pluginInstance;
void init(Plugin *p)
{
pluginInstance = p;
p->addModel(modelSimplexandhold);
p->addModel(modelBlank6hp);
p->addModel(modelPolyrand);
p->addModel(modelNoize);
p->addModel(modelSteps);
p->addModel(modelFibb);
p->addModel(modelOctsclr);
p->addModel(modelShift);
p->addModel(modelMlt);
p->addModel(modelMath);
p->addModel(modelLogic);
p->addModel(modelProbablynot);
p->addModel(modelPolyplay);
p->addModel(modelLights);
p->addModel(modelSlips);
p->addModel(modelTurnt);
p->addModel(modelSlipspander);
p->addModel(modelNos);
p->addModel(modelLucc);
p->addModel(modelPolyshuffle);
p->addModel(modelPolycounter);
settings_load();
}
void destroy()
{
settings_save();
}
bool use_global_contrast[MODULES_LEN] = {
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true};
float global_contrast = CONTRAST_MAX;
float module_contrast[MODULES_LEN] = {
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX,
CONTRAST_MAX};
void settings_save()
{
json_t *rootJ = settingsToJson();
std::string path = asset::user("alefsbits.json");
FILE *file = fopen(path.c_str(), "w");
if (file)
{
json_dumpf(rootJ, file, JSON_INDENT(2) | JSON_REAL_PRECISION(9));
fclose(file);
}
json_decref(rootJ);
}
void settings_load()
{
std::string path = asset::user("alefsbits.json");
FILE *file = fopen(path.c_str(), "r");
if (file)
{
json_error_t error;
json_t *rootJ = json_loadf(file, 0, &error);
if (rootJ)
{
settingsFromJson(rootJ);
json_decref(rootJ);
}
else
{
WARN("alefsbits.json: %s", error.text);
}
fclose(file);
}
}
json_t *settingsToJson()
{
json_t *rootJ = json_object();
json_object_set_new(rootJ, "global_contrast", json_real(global_contrast));
json_t *use_global_contrastJ = json_array();
for (int i = 0; i < MODULES_LEN; i++)
{
json_array_insert_new(use_global_contrastJ, i, json_boolean(use_global_contrast[i]));
}
json_object_set_new(rootJ, "use_global_contrast", use_global_contrastJ);
json_t *module_contrastJ = json_array();
for (int i = 0; i < MODULES_LEN; i++)
{
json_array_insert_new(module_contrastJ, i, json_real(module_contrast[i]));
}
json_object_set_new(rootJ, "module_contrast", module_contrastJ);
return rootJ;
}
void settingsFromJson(json_t *rootJ)
{
json_t *global_contrastJ = json_object_get(rootJ, "global_contrast");
if (global_contrastJ)
{
global_contrast = json_number_value(global_contrastJ);
}
json_t *use_global_contrastJ = json_object_get(rootJ, "use_global_contrast");
if (use_global_contrastJ)
{
for (int i = 0; i < MODULES_LEN; i++)
{
json_t *use_global_contrastJ_i = json_array_get(use_global_contrastJ, i);
if (use_global_contrastJ_i)
{
use_global_contrast[i] = json_boolean_value(use_global_contrastJ_i);
}
}
}
json_t *module_contrastJ = json_object_get(rootJ, "module_contrast");
if (module_contrastJ)
{
for (int i = 0; i < MODULES_LEN; i++)
{
json_t *module_contrastJ_i = json_array_get(module_contrastJ, i);
if (module_contrastJ_i)
{
module_contrast[i] = json_number_value(module_contrastJ_i);
}
}
}
}