Adapted new json format changes

This commit is contained in:
2022-12-17 16:37:57 +01:00
parent b11488a334
commit a9fb3d4e52
3 changed files with 21 additions and 1 deletions

View File

@ -69,6 +69,20 @@ std::vector<int> parseIntVector(const QJsonValue &jsonValue)
return vector; return vector;
} }
std::vector<int> parseIntVectorIgnoreNulls(const QJsonValue &jsonValue)
{
if (!jsonValue.isArray())
throw std::runtime_error{"json value for int vector is not an array"};
std::vector<int> vector;
for (const auto &jsonValue : jsonValue.toArray())
if (!jsonValue.isNull())
vector.emplace_back(parseInt(jsonValue));
return vector;
}
presets::PresetsConfig parsePresetsConfig(const QJsonObject &jsonObj) presets::PresetsConfig parsePresetsConfig(const QJsonObject &jsonObj)
{ {
presets::PresetsConfig presetConfig; presets::PresetsConfig presetConfig;
@ -216,6 +230,8 @@ presets::Preset parsePreset(const QJsonValue &jsonValue)
preset.beatSchool = parseSequenceVectorMap(iter.value()); preset.beatSchool = parseSequenceVectorMap(iter.value());
else if (key == "easyPlay") else if (key == "easyPlay")
preset.easyPlay = parseSequenceVectorMap(iter.value()); preset.easyPlay = parseSequenceVectorMap(iter.value());
else if (key == "timestamp")
preset.timestamp = QDateTime::fromSecsSinceEpoch(iter.value().toDouble());
else if (key == "middleDescription") else if (key == "middleDescription")
{} {}
else else
@ -318,7 +334,7 @@ presets::Sequence parseSequence(const QJsonValue &jsonValue)
else if (key == "pads") else if (key == "pads")
sequence.pads = parseSequencePadVectorMap(iter.value()); sequence.pads = parseSequencePadVectorMap(iter.value());
else if (key == "embientPads") else if (key == "embientPads")
sequence.embientPads = parseIntVector(iter.value()); sequence.embientPads = parseIntVectorIgnoreNulls(iter.value());
else else
throw std::runtime_error{QString{"unknown key %0 for Sequence"}.arg(key).toStdString()}; throw std::runtime_error{QString{"unknown key %0 for Sequence"}.arg(key).toStdString()};
} }

View File

@ -15,6 +15,7 @@ std::vector<QString> parseStringVector(const QJsonValue &jsonValue);
int parseInt(const QJsonValue &jsonValue); int parseInt(const QJsonValue &jsonValue);
bool parseBool(const QJsonValue &jsonValue); bool parseBool(const QJsonValue &jsonValue);
std::vector<int> parseIntVector(const QJsonValue &jsonValue); std::vector<int> parseIntVector(const QJsonValue &jsonValue);
std::vector<int> parseIntVectorIgnoreNulls(const QJsonValue &jsonValue);
presets::PresetsConfig parsePresetsConfig(const QJsonObject &jsonObj); presets::PresetsConfig parsePresetsConfig(const QJsonObject &jsonObj);
std::vector<presets::Category> parseCategoryVector(const QJsonValue &jsonValue); std::vector<presets::Category> parseCategoryVector(const QJsonValue &jsonValue);

View File

@ -3,8 +3,10 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <optional> #include <optional>
#include <array>
#include <QString> #include <QString>
#include <QDateTime>
namespace presets namespace presets
{ {
@ -74,6 +76,7 @@ struct Preset
std::optional<std::array<presets::File, 24>> files; std::optional<std::array<presets::File, 24>> files;
std::optional<std::map<QString, std::vector<Sequence>>> beatSchool; std::optional<std::map<QString, std::vector<Sequence>>> beatSchool;
std::optional<std::map<QString, std::vector<Sequence>>> easyPlay; std::optional<std::map<QString, std::vector<Sequence>>> easyPlay;
std::optional<QDateTime> timestamp;
}; };
struct PresetsConfig struct PresetsConfig