Skip to content

Commit

Permalink
EffectBase: Fix JSON signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Jun 5, 2021
1 parent 5df3f8a commit c04ce9d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
38 changes: 21 additions & 17 deletions src/EffectBase.cpp
Expand Up @@ -29,6 +29,7 @@
*/

#include "EffectBase.h"

#include "Exceptions.h"
#include "Timeline.h"

Expand Down Expand Up @@ -106,7 +107,7 @@ Json::Value EffectBase::JsonValue() const {
}

// Load JSON string into this object
void EffectBase::SetJson(std::string value) {
void EffectBase::SetJson(const std::string value) {

// Parse JSON string into JSON objects
try
Expand All @@ -123,7 +124,7 @@ void EffectBase::SetJson(std::string value) {
}

// Load Json::Value into this object
void EffectBase::SetJsonValue(Json::Value root) {
void EffectBase::SetJsonValue(const Json::Value root) {

if (ParentTimeline()){
// Get parent timeline
Expand All @@ -133,34 +134,37 @@ void EffectBase::SetJsonValue(Json::Value root) {
std::list<EffectBase*> effects = parentTimeline->ClipEffects();

// TODO: Fix recursive call for Object Detection

// // Loop through the effects and check if we have a child effect linked to this effect
for (auto const& effect : effects){
// Set the properties of all effects which parentEffect points to this
if ((effect->info.parent_effect_id == this->Id()) && (effect->Id() != this->Id()))
effect->SetJsonValue(root);
effect->SetJsonValue(root);
}
}

// Set this effect properties with the parent effect properties (except the id and parent_effect_id)
Json::Value my_root;
if (parentEffect){
root = parentEffect->JsonValue();
root["id"] = this->Id();
root["parent_effect_id"] = this->info.parent_effect_id;
}
my_root = parentEffect->JsonValue();
my_root["id"] = this->Id();
my_root["parent_effect_id"] = this->info.parent_effect_id;
} else {
my_root = root;
}

// Set parent data
ClipBase::SetJsonValue(root);
ClipBase::SetJsonValue(my_root);

// Set data from Json (if key is found)
if (!root["order"].isNull())
Order(root["order"].asInt());
if (!my_root["order"].isNull())
Order(my_root["order"].asInt());

if (!root["parent_effect_id"].isNull()){
info.parent_effect_id = root["parent_effect_id"].asString();
if (!my_root["parent_effect_id"].isNull()){
info.parent_effect_id = my_root["parent_effect_id"].asString();
if (info.parent_effect_id.size() > 0 && info.parent_effect_id != "" && parentEffect == NULL)
SetParentEffect(info.parent_effect_id);
else
else
parentEffect = NULL;
}
}
Expand Down Expand Up @@ -192,7 +196,7 @@ void EffectBase::ParentClip(openshot::ClipBase* new_clip) {

// Set the parent effect from which this properties will be set to
void EffectBase::SetParentEffect(std::string parentEffect_id) {

// Get parent Timeline
Timeline* parentTimeline = (Timeline *) ParentTimeline();

Expand All @@ -210,7 +214,7 @@ void EffectBase::SetParentEffect(std::string parentEffect_id) {
EffectJSON["id"] = this->Id();
EffectJSON["parent_effect_id"] = this->info.parent_effect_id;
this->SetJsonValue(EffectJSON);
}
}
}
return;
}
Expand All @@ -221,4 +225,4 @@ std::string EffectBase::ParentClipId() const{
return clip->Id();
else
return "";
}
}
11 changes: 6 additions & 5 deletions src/EffectBase.h
Expand Up @@ -111,13 +111,13 @@ namespace openshot
virtual std::string GetVisibleObjects(int64_t frame_number) const {return {}; };

// Get and Set JSON methods
virtual std::string Json() const = 0; ///< Generate JSON string of this object
virtual void SetJson(std::string value) = 0; ///< Load JSON string into this object
virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object
virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::Value into this object
virtual std::string Json() const; ///< Generate JSON string of this object
virtual void SetJson(const std::string value); ///< Load JSON string into this object
virtual Json::Value JsonValue() const; ///< Generate Json::Value for this object
virtual void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object

virtual std::string Json(int64_t requested_frame) const{
return {};
return "";
};
virtual void SetJson(int64_t requested_frame, const std::string value) {
return;
Expand All @@ -130,6 +130,7 @@ namespace openshot

/// Set the order that this effect should be executed.
void Order(int new_order) { order = new_order; }

virtual ~EffectBase() = default;
};

Expand Down

0 comments on commit c04ce9d

Please sign in to comment.