Notation
ci / checks (push) Successful in 38m51s

This commit is contained in:
khodowany
2026-09-05 16:18:34 -05:00
parent 6da21a2deb
commit ca285d63d4
6 changed files with 1463 additions and 238 deletions
+34 -2
View File
@@ -169,8 +169,9 @@ auto parse_note(boost::json::value const& value) -> std::expected<vamp_zero::sco
auto lyric = optional_string_value(**object, "lyric", {});
auto tie_to_next = optional_bool_value(**object, "tie_to_next", false);
auto tie_from_previous = optional_bool_value(**object, "tie_from_previous", false);
if (!id || !kind || !hidden || !duration || !display || !notehead || !chord || !lyric || !tie_to_next || !tie_from_previous) {
return std::unexpected(!id ? id.error() : (!kind ? kind.error() : (!hidden ? hidden.error() : (!duration ? duration.error() : (!display ? display.error() : (!notehead ? notehead.error() : (!chord ? chord.error() : (!lyric ? lyric.error() : (!tie_to_next ? tie_to_next.error() : tie_from_previous.error())))))))));
auto tuplet_id = optional_string_value(**object, "tuplet_id", {});
if (!id || !kind || !hidden || !duration || !display || !notehead || !chord || !lyric || !tie_to_next || !tie_from_previous || !tuplet_id) {
return std::unexpected(!id ? id.error() : (!kind ? kind.error() : (!hidden ? hidden.error() : (!duration ? duration.error() : (!display ? display.error() : (!notehead ? notehead.error() : (!chord ? chord.error() : (!lyric ? lyric.error() : (!tie_to_next ? tie_to_next.error() : (!tie_from_previous ? tie_from_previous.error() : tuplet_id.error()))))))))));
}
auto note = vamp_zero::score_note{
.id = std::move(*id),
@@ -183,6 +184,7 @@ auto parse_note(boost::json::value const& value) -> std::expected<vamp_zero::sco
.lyric = std::move(*lyric),
.tie_to_next = *tie_to_next,
.tie_from_previous = *tie_from_previous,
.tuplet_id = std::move(*tuplet_id),
};
if (auto found = (*object)->find("pitches"); found != (*object)->end()) {
if (!found->value().is_array()) {
@@ -199,6 +201,24 @@ auto parse_note(boost::json::value const& value) -> std::expected<vamp_zero::sco
return note;
}
auto parse_tuplet(boost::json::value const& value) -> std::expected<vamp_zero::score_tuplet, modulus::error> {
auto object = require_object(value, "tuplet");
if (!object) {
return std::unexpected(object.error());
}
auto id = required_string(**object, "id");
auto note_count = optional_int64_value(**object, "note_count", 0);
auto space_count = optional_int64_value(**object, "space_count", 0);
if (!id || !note_count || !space_count) {
return std::unexpected(!id ? id.error() : (!note_count ? note_count.error() : space_count.error()));
}
return vamp_zero::score_tuplet{
.id = std::move(*id),
.note_count = static_cast<std::int32_t>(*note_count),
.space_count = static_cast<std::int32_t>(*space_count),
};
}
auto parse_measure(boost::json::value const& value) -> std::expected<vamp_zero::score_measure, modulus::error> {
auto object = require_object(value, "measure");
if (!object) {
@@ -237,6 +257,18 @@ auto parse_measure(boost::json::value const& value) -> std::expected<vamp_zero::
}
measure.notes.push_back(std::move(*note));
}
if (auto tuplets_value = (*voice)->find("tuplets"); tuplets_value != (*voice)->end()) {
if (!tuplets_value->value().is_array()) {
return std::unexpected(invalid("tuplets must be an array"));
}
for (auto const& tuplet_value : tuplets_value->value().as_array()) {
auto tuplet = parse_tuplet(tuplet_value);
if (!tuplet) {
return std::unexpected(tuplet.error());
}
measure.tuplets.push_back(std::move(*tuplet));
}
}
}
return measure;
}