From c5bf0cb9b0fa5e4074996406a0664cac31bbbbaa Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 24 May 2023 17:27:03 -0500 Subject: [PATCH] Refactor base JSON properties into EffectBase - to reduce duplication in code --- src/EffectBase.cpp | 19 +++++++++++++++++++ src/EffectBase.h | 6 +++++- src/effects/Mask.cpp | 11 ++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/EffectBase.cpp b/src/EffectBase.cpp index 1e78a472..dd57e8bb 100644 --- a/src/EffectBase.cpp +++ b/src/EffectBase.cpp @@ -175,6 +175,25 @@ Json::Value EffectBase::JsonInfo() const { return root; } +// Get all properties for a specific frame +Json::Value EffectBase::BasePropertiesJSON(int64_t requested_frame) const { + // Generate JSON properties list + Json::Value root; + root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame); + root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame); + root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame); + root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame); + root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame); + root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame); + root["apply_before_clip"] = add_property_json("Apply Before Clip Keyframes", info.apply_before_clip, "int", "", NULL, 0, 1, false, requested_frame); + + // Add replace_image choices (dropdown style) + root["apply_before_clip"]["choices"].append(add_property_choice_json("Yes", true, info.apply_before_clip)); + root["apply_before_clip"]["choices"].append(add_property_choice_json("No", false, info.apply_before_clip)); + + return root; +} + /// Parent clip object of this reader (which can be unparented and NULL) openshot::ClipBase* EffectBase::ParentClip() { return clip; diff --git a/src/EffectBase.h b/src/EffectBase.h index 93ea0ba3..fb39d62b 100644 --- a/src/EffectBase.h +++ b/src/EffectBase.h @@ -106,7 +106,11 @@ namespace openshot return; }; - Json::Value JsonInfo() const; ///< Generate JSON object of meta data / info + /// Generate JSON object of meta data / info + Json::Value JsonInfo() const; + + /// Generate JSON object of base properties (recommended to be used by all effects) + Json::Value BasePropertiesJSON(int64_t requested_frame) const; /// Get the order that this effect should be executed. int Order() const { return order; } diff --git a/src/effects/Mask.cpp b/src/effects/Mask.cpp index abaed8b0..28e998d8 100644 --- a/src/effects/Mask.cpp +++ b/src/effects/Mask.cpp @@ -255,17 +255,10 @@ void Mask::SetJsonValue(const Json::Value root) { std::string Mask::PropertiesJSON(int64_t requested_frame) const { // Generate JSON properties list - Json::Value root; - root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame); - root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame); - root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame); - root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame); - root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame); - root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame); - root["replace_image"] = add_property_json("Replace Image", replace_image, "int", "", NULL, 0, 1, false, requested_frame); - root["apply_before_clip"] = add_property_json("Apply Before Clip Keyframes", info.apply_before_clip, "int", "", NULL, 0, 1, false, requested_frame); + Json::Value root = BasePropertiesJSON(requested_frame); // Add replace_image choices (dropdown style) + root["replace_image"] = add_property_json("Replace Image", replace_image, "int", "", NULL, 0, 1, false, requested_frame); root["replace_image"]["choices"].append(add_property_choice_json("Yes", true, replace_image)); root["replace_image"]["choices"].append(add_property_choice_json("No", false, replace_image));