-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml_to_patch.cc
63 lines (43 loc) · 1.59 KB
/
yaml_to_patch.cc
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
#include "yaml_to_patch.hh"
#include "ryml/ryml_init.hh"
#include "ryml/ryml_serial.hh"
namespace MetaModule
{
bool yaml_raw_to_patch(char *yaml, size_t size, PatchData &pd) {
RymlInit::init_once();
ryml::Tree tree = ryml::parse_in_place(ryml::substr(yaml, size));
if (tree.num_children(0) == 0)
return false;
ryml::ConstNodeRef root = tree.rootref();
if (!root.has_child("PatchData"))
return false;
ryml::ConstNodeRef patchdata = root["PatchData"];
if (!patchdata.has_child("patch_name"))
return false;
patchdata["patch_name"] >> pd.patch_name;
if (patchdata.has_child("description"))
patchdata["description"] >> pd.description;
patchdata["module_slugs"] >> pd.module_slugs;
patchdata["int_cables"] >> pd.int_cables;
patchdata["mapped_ins"] >> pd.mapped_ins;
patchdata["mapped_outs"] >> pd.mapped_outs;
patchdata["static_knobs"] >> pd.static_knobs;
patchdata["mapped_knobs"] >> pd.knob_sets;
if (patchdata.has_child("midi_maps"))
patchdata["midi_maps"] >> pd.midi_maps;
if (patchdata.has_child("midi_poly_num"))
patchdata["midi_poly_num"] >> pd.midi_poly_num;
if (patchdata.has_child("mapped_lights"))
patchdata["mapped_lights"] >> pd.mapped_lights;
// Check for VCV Module State data
if (patchdata.has_child("vcvModuleStates"))
patchdata["vcvModuleStates"] >> pd.module_states;
return true;
}
bool yaml_raw_to_patch(std::span<char> yaml, PatchData &pd) {
return yaml_raw_to_patch(yaml.data(), yaml.size_bytes(), pd);
}
bool yaml_string_to_patch(std::string yaml, PatchData &pd) {
return yaml_raw_to_patch(yaml.data(), yaml.size(), pd);
}
} // namespace MetaModule