From a3cf7491437348d907c71f655a58a0a8273ce772 Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Fri, 2 Feb 2024 22:05:37 +0000 Subject: [PATCH] Clean up --- .../presets/src/presets_json_parser.cpp | 207 ------------------ .../presets/src/presets_message_type.h | 59 ----- .../src/selected_preset_message_type.h | 47 ---- frontend/lib/midi_mapping/model/models.dart | 16 -- test/.idea/misc.xml | 1 + 5 files changed, 1 insertion(+), 329 deletions(-) delete mode 100644 firmware/components/presets/src/presets_json_parser.cpp delete mode 100644 firmware/components/presets/src/presets_message_type.h delete mode 100644 firmware/components/presets/src/selected_preset_message_type.h diff --git a/firmware/components/presets/src/presets_json_parser.cpp b/firmware/components/presets/src/presets_json_parser.cpp deleted file mode 100644 index be3c30ed..00000000 --- a/firmware/components/presets/src/presets_json_parser.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2022 Barabas Raffai - * - * This file is part of ShrapnelDSP. - * - * ShrapnelDSP is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) - * any later version. - * - * ShrapnelDSP is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * ShrapnelDSP. If not, see . - */ - -#include "presets_json_parser.h" -#include "esp_log.h" -#include "presets.pb-c.h" -#include "presets_message_type.h" -#include -#include -#include - -namespace shrapnel::presets { - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - using base64_codec = cppcodec::base64_rfc4648; - if(!json.IsString()) - { - return std::nullopt; - } - - std::array buffer{}; - if(base64_codec::decoded_max_size(json.GetStringLength()) > buffer.size()) - { - return std::nullopt; - } - - size_t decoded_size = 0; - auto error = base64_codec::decode(buffer.data(), - buffer.size(), - json.GetString(), - json.GetStringLength(), - decoded_size); - - if(!std::holds_alternative(error)) - { - return std::nullopt; - } - - auto unpacked = - preset_parameters__unpack(nullptr, decoded_size, buffer.data()); - if(unpacked == nullptr) - { - return std::nullopt; - } - - auto out = ParametersData{ - .amp_gain = unpacked->amp_gain / 1000.f, - .amp_channel = unpacked->amp_channel / 1000.f, - .bass = unpacked->bass / 1000.f, - .middle = unpacked->middle / 1000.f, - .treble = unpacked->treble / 1000.f, - .contour = unpacked->contour / 1000.f, - .volume = unpacked->volume / 1000.f, - .noise_gate_threshold = unpacked->noise_gate_threshold / 1000.f, - .noise_gate_hysteresis = unpacked->noise_gate_hysteresis / 1000.f, - .noise_gate_attack = unpacked->noise_gate_attack / 1000.f, - .noise_gate_hold = unpacked->noise_gate_hold / 1000.f, - .noise_gate_release = unpacked->noise_gate_release / 1000.f, - .noise_gate_bypass = unpacked->noise_gate_bypass / 1000.f, - .chorus_rate = unpacked->chorus_rate / 1000.f, - .chorus_depth = unpacked->chorus_depth / 1000.f, - .chorus_mix = unpacked->chorus_mix / 1000.f, - .chorus_bypass = unpacked->chorus_bypass / 1000.f, - .wah_position = unpacked->wah_position / 1000.f, - .wah_vocal = unpacked->wah_vocal / 1000.f, - .wah_bypass = unpacked->wah_bypass / 1000.f, - }; - - preset_parameters__free_unpacked(unpacked, nullptr); - return out; -} - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - auto name = json.FindMember("name"); - if(name == json.MemberEnd() || !name->value.IsString()) - return std::nullopt; - - auto parameters_json = json.FindMember("parameters"); - if(parameters_json == json.MemberEnd()) - return std::nullopt; - auto parameters = from_json(parameters_json->value); - if(!parameters.has_value()) - return std::nullopt; - - return {{ - .name{name->value.GetString()}, - .parameters{*parameters}, - }}; -} - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - return Initialise(); -} - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - auto preset_json = json.FindMember("preset"); - if(preset_json == json.MemberEnd()) - return std::nullopt; - - auto preset = from_json(preset_json->value); - if(!preset.has_value()) - return std::nullopt; - - return {{.preset = *preset}}; -} - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - auto id_json = json.FindMember("id"); - if(id_json == json.MemberEnd()) - return std::nullopt; - if(!id_json->value.IsUint()) - return std::nullopt; - - auto preset_json = json.FindMember("preset"); - if(preset_json == json.MemberEnd()) - return std::nullopt; - auto preset = from_json(preset_json->value); - if(!preset.has_value()) - return std::nullopt; - - return {{.id{id_json->value.GetUint()}, .preset = *preset}}; -} - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - auto id_json = json.FindMember("id"); - if(id_json == json.MemberEnd()) - return std::nullopt; - - if(!id_json->value.IsUint()) - return std::nullopt; - - return {{.id{id_json->value.GetUint()}}}; -} - -template <> -std::optional from_json(const rapidjson::Value &json) -{ - constexpr char TAG[] = "PresetsApiMessage from_json"; - - auto message_type_member = json.FindMember("messageType"); - if(message_type_member == json.MemberEnd()) - { - ESP_LOGE(TAG, "messageType is missing"); - goto error; - } - - if(!message_type_member->value.IsString()) - { - ESP_LOGE(TAG, "messageType is not string"); - goto error; - } - - { - const etl::map()>, - 4> - lut{ - {get_message_type(), - [&] { return from_json(json); }}, - {get_message_type(), - [&] { return from_json(json); }}, - {get_message_type(), - [&] { return from_json(json); }}, - {get_message_type(), - [&] { return from_json(json); }}, - }; - - const char *message_type = message_type_member->value.GetString(); - if(auto f = lut.find(message_type); f != lut.end()) - { - return f->second(); - } - } - -error: - return std::nullopt; -} - -} // namespace shrapnel::presets diff --git a/firmware/components/presets/src/presets_message_type.h b/firmware/components/presets/src/presets_message_type.h deleted file mode 100644 index b5b02fcf..00000000 --- a/firmware/components/presets/src/presets_message_type.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* Copyright 2022 Barabas Raffai -* -* This file is part of ShrapnelDSP. -* -* ShrapnelDSP is free software: you can redistribute it and/or modify it under -* the terms of the GNU General Public License as published by the Free -* Software Foundation, either version 3 of the License, or (at your option) -* any later version. -* -* ShrapnelDSP is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* ShrapnelDSP. If not, see . -*/ - -#pragma once - -#include "presets_message_type.h" - -namespace shrapnel::presets { - -template -constexpr const char *get_message_type(); - -template <> -constexpr const char *get_message_type() -{ - return "Presets::initialise"; -} - -template <> -constexpr const char *get_message_type() -{ - return "Presets::create"; -} - -template <> -constexpr const char *get_message_type() -{ - return "Presets::notify"; -} - -template <> -constexpr const char *get_message_type() -{ - return "Presets::update"; -} - -template <> -constexpr const char *get_message_type() -{ - return "Presets::delete"; -} - -} // namespace shrapnel::presets diff --git a/firmware/components/presets/src/selected_preset_message_type.h b/firmware/components/presets/src/selected_preset_message_type.h deleted file mode 100644 index 717fa307..00000000 --- a/firmware/components/presets/src/selected_preset_message_type.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Copyright 2022 Barabas Raffai -* -* This file is part of ShrapnelDSP. -* -* ShrapnelDSP is free software: you can redistribute it and/or modify it under -* the terms of the GNU General Public License as published by the Free -* Software Foundation, either version 3 of the License, or (at your option) -* any later version. -* -* ShrapnelDSP is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* ShrapnelDSP. If not, see . -*/ - -#pragma once - -#include "selected_preset_api.h" - -namespace shrapnel::selected_preset { - -template -constexpr const char *get_message_type(); - -template <> -constexpr const char *get_message_type() -{ - return "SelectedPreset::read"; -} - -template <> -constexpr const char *get_message_type() -{ - return "SelectedPreset::notify"; -} - -template <> -constexpr const char *get_message_type() -{ - return "SelectedPreset::write"; -} - -} // namespace shrapnel::selected_preset diff --git a/frontend/lib/midi_mapping/model/models.dart b/frontend/lib/midi_mapping/model/models.dart index 64de9300..b2f401dd 100644 --- a/frontend/lib/midi_mapping/model/models.dart +++ b/frontend/lib/midi_mapping/model/models.dart @@ -69,22 +69,6 @@ sealed class MidiMapping with _$MidiMapping { const MidiMapping._(); } -/// Midi mapping that is encodable to JSON. Used to communicate between the -/// firmware and the frontend. -// TODO remove if not needed any more -@freezed -class MidiMappingDto with _$MidiMappingDto { - const factory MidiMappingDto({ - required int midiChannel, - required int ccNumber, - required String? parameterId, - required MidiMappingMode mode, - required int? presetId, - }) = _MidiMappingDto; - - const MidiMappingDto._(); -} - @freezed class MidiMappingEntry with _$MidiMappingEntry { const factory MidiMappingEntry({ diff --git a/test/.idea/misc.xml b/test/.idea/misc.xml index 4c018bce..048657bc 100644 --- a/test/.idea/misc.xml +++ b/test/.idea/misc.xml @@ -13,6 +13,7 @@ + \ No newline at end of file