Skip to content

Commit 22bf6ed

Browse files
committed
Enhance Json data handling
- Parsing from string to Json::Value is now done by utility function openshot::stringToJson() in Json.cpp, all SetJson() methods call it. - Expand use of const member functions and args where appropriate. - Use std::to_string() to format int/float values as strings. - Correct mentions of nonexistent Json::JsonValue type in docstrings
1 parent a1158ee commit 22bf6ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+483
-945
lines changed

include/CacheBase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ namespace openshot {
110110

111111
/// Get and Set JSON methods
112112
virtual std::string Json() = 0; ///< Generate JSON string of this object
113-
virtual void SetJson(std::string value) = 0; ///< Load JSON string into this object
114-
virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
115-
virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue into this object
113+
virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object
114+
virtual Json::Value JsonValue() = 0; ///< Generate Json::Value for this object
115+
virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object
116116
virtual ~CacheBase() = default;
117117

118118
};

include/CacheDisk.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ namespace openshot {
129129

130130
/// Get and Set JSON methods
131131
std::string Json(); ///< Generate JSON string of this object
132-
void SetJson(std::string value); ///< Load JSON string into this object
133-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
134-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
132+
void SetJson(const std::string value); ///< Load JSON string into this object
133+
Json::Value JsonValue(); ///< Generate Json::Value for this object
134+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
135135
};
136136

137137
}

include/CacheMemory.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ namespace openshot {
111111

112112
/// Get and Set JSON methods
113113
std::string Json(); ///< Generate JSON string of this object
114-
void SetJson(std::string value); ///< Load JSON string into this object
115-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
116-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
114+
void SetJson(const std::string value); ///< Load JSON string into this object
115+
Json::Value JsonValue(); ///< Generate Json::Value for this object
116+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
117117
};
118118

119119
}

include/ChunkReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ namespace openshot
157157
std::string Name() { return "ChunkReader"; };
158158

159159
/// Get and Set JSON methods
160-
std::string Json(); ///< Generate JSON string of this object
161-
void SetJson(std::string value); ///< Load JSON string into this object
162-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
163-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
160+
std::string Json() const override; ///< Generate JSON string of this object
161+
void SetJson(const std::string value); ///< Load JSON string into this object
162+
Json::Value JsonValue() const override; ///< Generate Json::Value for this object
163+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
164164

165165
/// Open the reader. This is required before you can access frames or data from the reader.
166166
void Open();

include/Clip.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,18 @@ namespace openshot {
192192
openshot::ReaderBase* Reader();
193193

194194
/// Override End() method
195-
float End(); ///< Get end position (in seconds) of clip (trim end of video), which can be affected by the time curve.
195+
float End() const; ///< Get end position (in seconds) of clip (trim end of video), which can be affected by the time curve.
196196
void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video)
197197

198198
/// Get and Set JSON methods
199-
std::string Json(); ///< Generate JSON string of this object
200-
void SetJson(std::string value); ///< Load JSON string into this object
201-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
202-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
199+
std::string Json() const override; ///< Generate JSON string of this object
200+
void SetJson(const std::string value); ///< Load JSON string into this object
201+
Json::Value JsonValue() const override; ///< Generate Json::Value for this object
202+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
203203

204204
/// Get all properties for a specific frame (perfect for a UI to display the current state
205205
/// of all properties at any time)
206-
std::string PropertiesJSON(int64_t requested_frame);
206+
std::string PropertiesJSON(int64_t requested_frame) const override;
207207

208208
/// @brief Remove an effect from the clip
209209
/// @param effect Remove an effect from the clip.

include/ClipBase.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ namespace openshot {
6161
std::string previous_properties; ///< This string contains the previous JSON properties
6262

6363
/// Generate JSON for a property
64-
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, Keyframe* keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame);
64+
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe* keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const;
6565

6666
/// Generate JSON choice for a property (dropdown properties)
67-
Json::Value add_property_choice_json(std::string name, int value, int selected_value);
67+
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const;
6868

6969
public:
7070

@@ -78,12 +78,12 @@ namespace openshot {
7878
bool operator>= ( ClipBase& a) { return (Position() >= a.Position()); }
7979

8080
/// Get basic properties
81-
std::string Id() { return id; } ///< Get the Id of this clip object
82-
float Position() { return position; } ///< Get position on timeline (in seconds)
83-
int Layer() { return layer; } ///< Get layer of clip on timeline (lower number is covered by higher numbers)
84-
float Start() { return start; } ///< Get start position (in seconds) of clip (trim start of video)
85-
float End() { return end; } ///< Get end position (in seconds) of clip (trim end of video)
86-
float Duration() { return end - start; } ///< Get the length of this clip (in seconds)
81+
std::string Id() const { return id; } ///< Get the Id of this clip object
82+
float Position() const { return position; } ///< Get position on timeline (in seconds)
83+
int Layer() const { return layer; } ///< Get layer of clip on timeline (lower number is covered by higher numbers)
84+
float Start() const { return start; } ///< Get start position (in seconds) of clip (trim start of video)
85+
float End() const { return end; } ///< Get end position (in seconds) of clip (trim end of video)
86+
float Duration() const { return end - start; } ///< Get the length of this clip (in seconds)
8787

8888
/// Set basic properties
8989
void Id(std::string value) { id = value; } ///> Set the Id of this clip object
@@ -93,14 +93,14 @@ namespace openshot {
9393
void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video)
9494

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

101101
/// Get all properties for a specific frame (perfect for a UI to display the current state
102102
/// of all properties at any time)
103-
virtual std::string PropertiesJSON(int64_t requested_frame) = 0;
103+
virtual std::string PropertiesJSON(int64_t requested_frame) const = 0;
104104

105105
virtual ~ClipBase() = default;
106106
};

include/Color.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ namespace openshot {
6969
static long GetDistance(long R1, long G1, long B1, long R2, long G2, long B2);
7070

7171
/// Get and Set JSON methods
72-
std::string Json(); ///< Generate JSON string of this object
73-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
74-
void SetJson(std::string value); ///< Load JSON string into this object
75-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
72+
std::string Json() const; ///< Generate JSON string of this object
73+
Json::Value JsonValue() const; ///< Generate Json::Value for this object
74+
void SetJson(const std::string value); ///< Load JSON string into this object
75+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
7676
};
7777

7878

include/Coordinate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ namespace openshot {
6666
Coordinate(double x, double y);
6767

6868
/// Get and Set JSON methods
69-
std::string Json(); ///< Generate JSON string of this object
70-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
71-
void SetJson(std::string value); ///< Load JSON string into this object
72-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
69+
std::string Json() const; ///< Generate JSON string of this object
70+
Json::Value JsonValue() const; ///< Generate Json::Value for this object
71+
void SetJson(const std::string value); ///< Load JSON string into this object
72+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
7373
};
7474

7575
}

include/DecklinkReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ namespace openshot
118118
std::string Name() { return "DecklinkReader"; };
119119

120120
/// Get and Set JSON methods
121-
std::string Json(); ///< Generate JSON string of this object
122-
void SetJson(std::string value); ///< Load JSON string into this object
123-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
124-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
121+
std::string Json() const override; ///< Generate JSON string of this object
122+
void SetJson(const std::string value); ///< Load JSON string into this object
123+
Json::Value JsonValue() const; ///< Generate Json::Value for this object
124+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
125125

126126
/// Open device and video stream - which is called by the constructor automatically
127127
void Open();

include/DummyReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ namespace openshot
8787
std::string Name() { return "DummyReader"; };
8888

8989
/// Get and Set JSON methods
90-
std::string Json(); ///< Generate JSON string of this object
91-
void SetJson(std::string value); ///< Load JSON string into this object
92-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
93-
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
90+
std::string Json() const override; ///< Generate JSON string of this object
91+
void SetJson(const std::string value); ///< Load JSON string into this object
92+
Json::Value JsonValue() const override; ///< Generate Json::Value for this object
93+
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
9494

9595
/// Open File - which is called by the constructor automatically
9696
void Open();

0 commit comments

Comments
 (0)