You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Added new clip method that returns all properties for a given frame in JSON.
This commit is contained in:
@@ -102,6 +102,9 @@ namespace openshot {
|
||||
/// Adjust frame number minimum value
|
||||
int adjust_frame_number_minimum(int frame_number);
|
||||
|
||||
/// Generate JSON for a property
|
||||
Json::Value add_property_json(string name, float value, string type, string memo, bool contains_point, float min_value, float max_value, bool readonly);
|
||||
|
||||
/// Get file extension
|
||||
string get_file_extension(string path);
|
||||
|
||||
@@ -159,6 +162,9 @@ namespace openshot {
|
||||
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
||||
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
|
||||
|
||||
/// Get all properties for a specific frame
|
||||
string PropertiesJSON(int requested_frame);
|
||||
|
||||
/// Waveform property
|
||||
bool Waveform() { return waveform; } ///< Get the waveform property of this clip
|
||||
void Waveform(bool value) { waveform = value; } ///< Set the waveform property of this clip
|
||||
|
||||
@@ -107,6 +107,9 @@ namespace openshot {
|
||||
/// Add a new point on the key-frame, with a specific interpolation type
|
||||
void AddPoint(float x, float y, InterpolationType interpolate);
|
||||
|
||||
/// Does this keyframe contain a specific point
|
||||
bool Contains(Point p);
|
||||
|
||||
/// Set the handles, used for smooth curves. The handles are based on the surrounding points.
|
||||
void SetHandles(Point current);
|
||||
|
||||
|
||||
51
src/Clip.cpp
51
src/Clip.cpp
@@ -522,6 +522,57 @@ string Clip::Json() {
|
||||
return JsonValue().toStyledString();
|
||||
}
|
||||
|
||||
// Get all properties for a specific frame
|
||||
string Clip::PropertiesJSON(int requested_frame) {
|
||||
|
||||
// Requested Point
|
||||
Point requested_point(requested_frame, requested_frame);
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), false, -1, -1, true);
|
||||
root["position"] = add_property_json("Position", Position(), "int", "", false, 0, 1000 * 60 * 30, false);
|
||||
root["layer"] = add_property_json("Layer", Layer(), "int", "", false, 0, 1000, false);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", false, 0, 1000 * 60 * 30, false);
|
||||
root["end"] = add_property_json("End", End(), "float", "", false, 0, 1000 * 60 * 30, false);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", false, 0, 1000 * 60 * 30, false);
|
||||
root["gravity"] = add_property_json("Gravity", gravity, "int", "", false, -1, -1, false);
|
||||
root["scale"] = add_property_json("Scale", scale, "int", "", false, -1, -1, false);
|
||||
root["anchor"] = add_property_json("Anchor", anchor, "int", "", false, -1, -1, false);
|
||||
root["waveform"] = add_property_json("Waveform", waveform, "int", "", false, -1, -1, false);
|
||||
|
||||
// Keyframes
|
||||
root["location_x"] = add_property_json("Location X", location_x.GetValue(requested_frame), "float", "", location_x.Contains(requested_point), -10000, 10000, false);
|
||||
root["location_y"] = add_property_json("Location Y", location_y.GetValue(requested_frame), "float", "", location_y.Contains(requested_point), -10000, 10000, false);
|
||||
root["scale_x"] = add_property_json("Scale X", scale_x.GetValue(requested_frame), "float", "", scale_x.Contains(requested_point), 0.0, 100.0, false);
|
||||
root["scale_y"] = add_property_json("Scale Y", scale_y.GetValue(requested_frame), "float", "", scale_y.Contains(requested_point), 0.0, 100.0, false);
|
||||
root["alpha"] = add_property_json("Alpha", alpha.GetValue(requested_frame), "float", "", alpha.Contains(requested_point), 0.0, 1.0, false);
|
||||
root["rotation"] = add_property_json("Rotation", rotation.GetValue(requested_frame), "float", "", rotation.Contains(requested_point), -10000, 10000, false);
|
||||
root["volume"] = add_property_json("Volume", volume.GetValue(requested_frame), "float", "", volume.Contains(requested_point), 0.0, 1.0, false);
|
||||
root["time"] = add_property_json("Time", time.GetValue(requested_frame), "float", "", time.Contains(requested_point), 0.0, 1000 * 60 * 30, false);
|
||||
|
||||
// Return formatted string
|
||||
return root.toStyledString();
|
||||
}
|
||||
|
||||
// Generate JSON for a property
|
||||
Json::Value Clip::add_property_json(string name, float value, string type, string memo, bool contains_point, float min_value, float max_value, bool readonly) {
|
||||
|
||||
// Create JSON Object
|
||||
Json::Value prop = Json::Value(Json::objectValue);
|
||||
prop["name"] = name;
|
||||
prop["value"] = value;
|
||||
prop["memo"] = memo;
|
||||
prop["type"] = value;
|
||||
prop["min"] = min_value;
|
||||
prop["max"] = max_value;
|
||||
prop["keyframe"] = contains_point;
|
||||
prop["readonly"] = max_value;
|
||||
|
||||
// return JsonValue
|
||||
return prop;
|
||||
}
|
||||
|
||||
// Generate Json::JsonValue for this object
|
||||
Json::Value Clip::JsonValue() {
|
||||
|
||||
|
||||
@@ -171,6 +171,24 @@ int Keyframe::FindIndex(Point p) throw(OutOfBoundsPoint) {
|
||||
throw OutOfBoundsPoint("Invalid point requested", -1, Points.size());
|
||||
}
|
||||
|
||||
// Determine if point already exists
|
||||
bool Keyframe::Contains(Point p) {
|
||||
// loop through points, and find a matching coordinate
|
||||
for (int x = 0; x < Points.size(); x++) {
|
||||
// Get each point
|
||||
Point existing_point = Points[x];
|
||||
|
||||
// find a match
|
||||
if (p.co.X == existing_point.co.X) {
|
||||
// Remove the matching point, and break out of loop
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// no matching point found
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the value at a specific index
|
||||
float Keyframe::GetValue(int index)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user