diff --git a/include/ChunkReader.h b/include/ChunkReader.h
index 55002b11..118be6e8 100644
--- a/include/ChunkReader.h
+++ b/include/ChunkReader.h
@@ -149,6 +149,12 @@ namespace openshot
/// @param requested_frame The frame number you want to retrieve
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed, ChunkNotFound);
+ /// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+
/// Open the reader. This is required before you can access frames or data from the reader.
void Open() throw(InvalidFile);
};
diff --git a/include/Clip.h b/include/Clip.h
index 57eb7a50..d35bce77 100644
--- a/include/Clip.h
+++ b/include/Clip.h
@@ -34,51 +34,26 @@
#endif
#include
+#include
+#include "JuceLibraryCode/JuceHeader.h"
+#include "AudioResampler.h"
#include "ClipBase.h"
#include "Color.h"
+#include "Enums.h"
#include "FFmpegReader.h"
#include "FrameRate.h"
#include "FrameMapper.h"
#include "ImageReader.h"
+#include "TextReader.h"
+#include "ChunkReader.h"
#include "KeyFrame.h"
-#include "JuceLibraryCode/JuceHeader.h"
-#include "AudioResampler.h"
+#include "ReaderBase.h"
using namespace std;
using namespace openshot;
namespace openshot {
- /// This enumeration determines how clips are aligned to their parent container.
- enum GravityType
- {
- GRAVITY_TOP_LEFT, ///< Align clip to the top left of its parent
- GRAVITY_TOP, ///< Align clip to the top center of its parent
- GRAVITY_TOP_RIGHT, ///< Align clip to the top right of its parent
- GRAVITY_LEFT, ///< Align clip to the left of its parent (middle aligned)
- GRAVITY_CENTER, ///< Align clip to the center of its parent (middle aligned)
- GRAVITY_RIGHT, ///< Align clip to the right of its parent (middle aligned)
- GRAVITY_BOTTOM_LEFT, ///< Align clip to the bottom left of its parent
- GRAVITY_BOTTOM, ///< Align clip to the bottom center of its parent
- GRAVITY_BOTTOM_RIGHT ///< Align clip to the bottom right of its parent
- };
-
- /// This enumeration determines how clips are scaled to fit their parent container.
- enum ScaleType
- {
- SCALE_CROP, ///< Scale the clip until both height and width fill the canvas (cropping the overlap)
- SCALE_FIT, ///< Scale the clip until either height or width fills the canvas (with no cropping)
- SCALE_STRETCH, ///< Scale the clip until both height and width fill the canvas (distort to fit)
- SCALE_NONE ///< Do not scale the clip
- };
-
- /// This enumeration determines what parent a clip should be aligned to.
- enum AnchorType
- {
- ANCHOR_CANVAS, ///< Anchor the clip to the canvas
- ANCHOR_VIEWPORT ///< Anchor the clip to the viewport (which can be moved / animated around the canvas)
- };
-
/**
* @brief This class represents a clip (used to arrange readers on the timeline)
*
@@ -122,7 +97,7 @@ namespace openshot {
AudioSampleBuffer *audio_cache;
// File Reader object
- ReaderBase* file_reader;
+ ReaderBase* reader;
/// Adjust frame number minimum value
int adjust_frame_number_minimum(int frame_number);
@@ -172,7 +147,7 @@ namespace openshot {
/// @brief Set the current reader
/// @param reader The reader to be used by this clip
- void Reader(ReaderBase* reader);
+ void Reader(ReaderBase* new_reader);
/// Get the current reader
ReaderBase* Reader() throw(ReaderClosed);
@@ -182,8 +157,10 @@ namespace openshot {
void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video)
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
/// Waveform property
bool Waveform() { return waveform; } ///< Get the waveform property of this clip
diff --git a/include/ClipBase.h b/include/ClipBase.h
index 7d0df0bf..e6c33361 100644
--- a/include/ClipBase.h
+++ b/include/ClipBase.h
@@ -76,10 +76,10 @@ namespace openshot {
void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video)
/// Get and Set JSON methods
- string Json(); ///< Generate JSON string of this object
+ virtual string Json() = 0; ///< Generate JSON string of this object
+ virtual void SetJson(string value) throw(InvalidJSON) = 0; ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
diff --git a/include/Color.h b/include/Color.h
index 916deeb6..ae52439e 100644
--- a/include/Color.h
+++ b/include/Color.h
@@ -46,8 +46,8 @@ namespace openshot {
/// Get and Set JSON methods
string Json(); ///< Generate JSON string of this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
diff --git a/include/Coordinate.h b/include/Coordinate.h
index 207aedfa..8ac1f1ed 100644
--- a/include/Coordinate.h
+++ b/include/Coordinate.h
@@ -93,8 +93,8 @@ namespace openshot {
/// Get and Set JSON methods
string Json(); ///< Generate JSON string of this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
}
diff --git a/include/DecklinkReader.h b/include/DecklinkReader.h
index c0b6b74f..552fc110 100644
--- a/include/DecklinkReader.h
+++ b/include/DecklinkReader.h
@@ -108,6 +108,12 @@ namespace openshot
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed);
unsigned long GetCurrentFrameNumber();
+ /// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+
/// Open device and video stream - which is called by the constructor automatically
void Open() throw(DecklinkError);
};
diff --git a/include/DummyReader.h b/include/DummyReader.h
index a7cd0aec..a94f840d 100644
--- a/include/DummyReader.h
+++ b/include/DummyReader.h
@@ -78,6 +78,12 @@ namespace openshot
/// @param requested_frame The frame number that is requested.
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed);
+ /// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+
/// Open File - which is called by the constructor automatically
void Open() throw(InvalidFile);
};
diff --git a/include/EffectBase.h b/include/EffectBase.h
index e9633da3..02cc801f 100644
--- a/include/EffectBase.h
+++ b/include/EffectBase.h
@@ -90,9 +90,9 @@ namespace openshot
/// Get and Set JSON methods
string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
/// Get the order that this effect should be executed.
int Order() { return order; }
diff --git a/include/Enums.h b/include/Enums.h
new file mode 100644
index 00000000..218738f1
--- /dev/null
+++ b/include/Enums.h
@@ -0,0 +1,65 @@
+/**
+ * @file
+ * @brief Header file for TextReader class
+ * @author Jonathan Thomas
+ *
+ * @section LICENSE
+ *
+ * Copyright (c) 2008-2013 OpenShot Studios, LLC
+ * (http://www.openshotstudios.com). This file is part of
+ * OpenShot Library (http://www.openshot.org), an open-source project
+ * dedicated to delivering high quality video editing and animation solutions
+ * to the world.
+ *
+ * OpenShot Library 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.
+ *
+ * OpenShot Library 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 OpenShot Library. If not, see .
+ */
+
+#ifndef OPENSHOT_ENUMS_H
+#define OPENSHOT_ENUMS_H
+
+
+namespace openshot
+{
+ /// This enumeration determines how clips are aligned to their parent container.
+ enum GravityType
+ {
+ GRAVITY_TOP_LEFT, ///< Align clip to the top left of its parent
+ GRAVITY_TOP, ///< Align clip to the top center of its parent
+ GRAVITY_TOP_RIGHT, ///< Align clip to the top right of its parent
+ GRAVITY_LEFT, ///< Align clip to the left of its parent (middle aligned)
+ GRAVITY_CENTER, ///< Align clip to the center of its parent (middle aligned)
+ GRAVITY_RIGHT, ///< Align clip to the right of its parent (middle aligned)
+ GRAVITY_BOTTOM_LEFT, ///< Align clip to the bottom left of its parent
+ GRAVITY_BOTTOM, ///< Align clip to the bottom center of its parent
+ GRAVITY_BOTTOM_RIGHT ///< Align clip to the bottom right of its parent
+ };
+
+ /// This enumeration determines how clips are scaled to fit their parent container.
+ enum ScaleType
+ {
+ SCALE_CROP, ///< Scale the clip until both height and width fill the canvas (cropping the overlap)
+ SCALE_FIT, ///< Scale the clip until either height or width fills the canvas (with no cropping)
+ SCALE_STRETCH, ///< Scale the clip until both height and width fill the canvas (distort to fit)
+ SCALE_NONE ///< Do not scale the clip
+ };
+
+ /// This enumeration determines what parent a clip should be aligned to.
+ enum AnchorType
+ {
+ ANCHOR_CANVAS, ///< Anchor the clip to the canvas
+ ANCHOR_VIEWPORT ///< Anchor the clip to the viewport (which can be moved / animated around the canvas)
+ };
+
+}
+#endif
diff --git a/include/FFmpegReader.h b/include/FFmpegReader.h
index 77506b80..d608b3e8 100644
--- a/include/FFmpegReader.h
+++ b/include/FFmpegReader.h
@@ -239,8 +239,10 @@ namespace openshot
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed, TooManySeeks);
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
/// Open File - which is called by the constructor automatically
void Open() throw(InvalidFile, NoStreamsFound, InvalidCodec);
diff --git a/include/FrameMapper.h b/include/FrameMapper.h
index 19b4ca4f..0f1a1824 100644
--- a/include/FrameMapper.h
+++ b/include/FrameMapper.h
@@ -171,6 +171,12 @@ namespace openshot
/// @param requested_frame The frame number that is requested.
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed);
+ /// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+
/// Get the target framerate
Framerate TargetFPS() { return target; };
diff --git a/include/ImageReader.h b/include/ImageReader.h
index 0e59d256..4ca62797 100644
--- a/include/ImageReader.h
+++ b/include/ImageReader.h
@@ -88,8 +88,10 @@ namespace openshot
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed);
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
/// Open File - which is called by the constructor automatically
void Open() throw(InvalidFile);
diff --git a/include/KeyFrame.h b/include/KeyFrame.h
index 23dbb087..65c4e020 100644
--- a/include/KeyFrame.h
+++ b/include/KeyFrame.h
@@ -137,8 +137,8 @@ namespace openshot {
/// Get and Set JSON methods
string Json(); ///< Generate JSON string of this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
/**
* @brief Calculate all of the values for this keyframe.
diff --git a/include/OpenShot.h b/include/OpenShot.h
index f837bc13..033536d6 100644
--- a/include/OpenShot.h
+++ b/include/OpenShot.h
@@ -106,6 +106,7 @@
#endif
#include "DummyReader.h"
#include "EffectBase.h"
+#include "Enums.h"
#include "Exceptions.h"
#include "ReaderBase.h"
#include "WriterBase.h"
diff --git a/include/Point.h b/include/Point.h
index c4c57216..962f0d0f 100644
--- a/include/Point.h
+++ b/include/Point.h
@@ -117,8 +117,8 @@ namespace openshot
/// Get and Set JSON methods
string Json(); ///< Generate JSON string of this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
diff --git a/include/ReaderBase.h b/include/ReaderBase.h
index 7e52eab6..578a09eb 100644
--- a/include/ReaderBase.h
+++ b/include/ReaderBase.h
@@ -31,6 +31,7 @@
#include
#include
#include
+#include
#include "Fraction.h"
#include "Frame.h"
#include "Json.h"
@@ -105,10 +106,10 @@ namespace openshot
void InitFileInfo();
/// Get and Set JSON methods
- string Json(); ///< Generate JSON string of this object
+ virtual string Json() = 0; ///< Generate JSON string of this object
+ virtual void SetJson(string value) throw(InvalidJSON) = 0; ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
/// Open the reader (and start consuming resources, such as images or video files)
virtual void Open() = 0;
diff --git a/include/TextReader.h b/include/TextReader.h
index 25fcb4b1..c5d63139 100644
--- a/include/TextReader.h
+++ b/include/TextReader.h
@@ -38,7 +38,7 @@
#include
#include "Magick++.h"
#include "Cache.h"
-#include "Clip.h"
+#include "Enums.h"
#include "Exceptions.h"
using namespace std;
@@ -97,7 +97,10 @@ namespace openshot
public:
- /// @brief Constructor for TextReader.
+ /// Default constructor (blank text)
+ TextReader();
+
+ /// @brief Constructor for TextReader with all parameters.
/// @param width The width of the requested openshot::Frame (not the size of the text)
/// @param height The height of the requested openshot::Frame (not the size of the text)
/// @param x_offset The number of pixels to offset the text on the X axis (horizontal)
@@ -121,8 +124,10 @@ namespace openshot
tr1::shared_ptr GetFrame(int requested_frame) throw(ReaderClosed);
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
/// Open Reader - which is called by the constructor automatically
void Open();
diff --git a/include/Timeline.h b/include/Timeline.h
index 9c931af6..030ea234 100644
--- a/include/Timeline.h
+++ b/include/Timeline.h
@@ -228,6 +228,12 @@ namespace openshot {
// Background color
Color color; /// GetFrame(tr1::shared_ptr frame, int frame_number);
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
}
diff --git a/include/effects/Deinterlace.h b/include/effects/Deinterlace.h
index 549f02d3..2de4ebdc 100644
--- a/include/effects/Deinterlace.h
+++ b/include/effects/Deinterlace.h
@@ -76,8 +76,10 @@ namespace openshot
tr1::shared_ptr GetFrame(tr1::shared_ptr frame, int frame_number);
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
}
diff --git a/include/effects/Mask.h b/include/effects/Mask.h
index b6a9046a..b21fd1c2 100644
--- a/include/effects/Mask.h
+++ b/include/effects/Mask.h
@@ -89,8 +89,10 @@ namespace openshot
tr1::shared_ptr GetFrame(tr1::shared_ptr frame, int frame_number);
/// Get and Set JSON methods
+ string Json(); ///< Generate JSON string of this object
+ void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
- void Json(Json::Value root); ///< Load Json::JsonValue into this object
+ void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
};
}
diff --git a/src/ChunkReader.cpp b/src/ChunkReader.cpp
index 154948b4..e3d65afc 100644
--- a/src/ChunkReader.cpp
+++ b/src/ChunkReader.cpp
@@ -251,4 +251,68 @@ tr1::shared_ptr ChunkReader::GetFrame(int requested_frame) throw(ReaderCl
return last_frame;
}
+// Generate JSON string of this object
+string ChunkReader::Json() {
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
+// Generate Json::JsonValue for this object
+Json::Value ChunkReader::JsonValue() {
+
+ // Create root json object
+ Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "ChunkReader";
+ root["path"] = path;
+ root["chunk_size"] = chunk_size;
+ root["chunk_version"] = version;
+
+ // return JsonValue
+ return root;
+}
+
+// Load JSON string into this object
+void ChunkReader::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
+// Load Json::JsonValue into this object
+void ChunkReader::SetJsonValue(Json::Value root) throw(InvalidFile) {
+
+ // Set parent data
+ ReaderBase::SetJsonValue(root);
+
+ // Set data from Json (if key is found)
+ if (root["path"] != Json::nullValue)
+ path = root["path"].asString();
+ if (root["chunk_size"] != Json::nullValue)
+ chunk_size = root["chunk_size"].asInt();
+ if (root["chunk_version"] != Json::nullValue)
+ version = (ChunkVersion) root["chunk_version"].asInt();
+
+ // Re-Open path, and re-init everything (if needed)
+ if (is_open)
+ {
+ Close();
+ Open();
+ }
+}
diff --git a/src/Clip.cpp b/src/Clip.cpp
index 96b0569d..a02335a1 100644
--- a/src/Clip.cpp
+++ b/src/Clip.cpp
@@ -81,7 +81,7 @@ void Clip::init_settings()
perspective_c4_y = Keyframe(-1.0);
// Default pointers
- file_reader = NULL;
+ reader = NULL;
resampler = NULL;
audio_cache = NULL;
}
@@ -94,14 +94,11 @@ Clip::Clip()
}
// Constructor with reader
-Clip::Clip(ReaderBase* reader)
+Clip::Clip(ReaderBase* reader) : reader(reader)
{
// Init all default settings
init_settings();
- // set reader pointer
- file_reader = reader;
-
// Open and Close the reader (to set the duration of the clip)
Open();
Close();
@@ -124,25 +121,25 @@ Clip::Clip(string path)
try
{
// Open common video format
- file_reader = new FFmpegReader(path);
+ reader = new FFmpegReader(path);
cout << "READER FOUND: FFmpegReader" << endl;
} catch(...) { }
}
// If no video found, try each reader
- if (!file_reader)
+ if (!reader)
{
try
{
// Try an image reader
- file_reader = new ImageReader(path);
+ reader = new ImageReader(path);
cout << "READER FOUND: ImageReader" << endl;
} catch(...) {
try
{
// Try a video reader
- file_reader = new FFmpegReader(path);
+ reader = new FFmpegReader(path);
cout << "READER FOUND: FFmpegReader" << endl;
} catch(BaseException ex) {
@@ -156,17 +153,17 @@ Clip::Clip(string path)
}
/// Set the current reader
-void Clip::Reader(ReaderBase* reader)
+void Clip::Reader(ReaderBase* new_reader)
{
// set reader pointer
- file_reader = reader;
+ reader = new_reader;
}
/// Get the current reader
ReaderBase* Clip::Reader() throw(ReaderClosed)
{
- if (file_reader)
- return file_reader;
+ if (reader)
+ return reader;
else
// Throw error if reader not initialized
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.", "");
@@ -175,14 +172,14 @@ ReaderBase* Clip::Reader() throw(ReaderClosed)
// Open the internal reader
void Clip::Open() throw(InvalidFile, ReaderClosed)
{
- if (file_reader)
+ if (reader)
{
// Open the reader
- file_reader->Open();
+ reader->Open();
// Set some clip properties from the file reader
if (end == 0.0)
- End(file_reader->info.duration);
+ End(reader->info.duration);
}
else
// Throw error if reader not initialized
@@ -192,8 +189,8 @@ void Clip::Open() throw(InvalidFile, ReaderClosed)
// Close the internal reader
void Clip::Close() throw(ReaderClosed)
{
- if (file_reader)
- file_reader->Close();
+ if (reader)
+ reader->Close();
else
// Throw error if reader not initialized
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.", "");
@@ -207,9 +204,9 @@ float Clip::End() throw(ReaderClosed)
{
// Determine the FPS fo this clip
float fps = 24.0;
- if (file_reader)
+ if (reader)
// file reader
- fps = file_reader->info.fps.ToFloat();
+ fps = reader->info.fps.ToFloat();
else
// Throw error if reader not initialized
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.", "");
@@ -224,7 +221,7 @@ float Clip::End() throw(ReaderClosed)
// Get an openshot::Frame object for a specific frame number of this reader.
tr1::shared_ptr Clip::GetFrame(int requested_frame) throw(ReaderClosed)
{
- if (file_reader)
+ if (reader)
{
// Adjust out of bounds frame number
requested_frame = adjust_frame_number_minimum(requested_frame);
@@ -235,7 +232,7 @@ tr1::shared_ptr Clip::GetFrame(int requested_frame) throw(ReaderClosed)
new_frame_number = time.GetInt(requested_frame);
// Now that we have re-mapped what frame number is needed, go and get the frame pointer
- tr1::shared_ptr frame = file_reader->GetFrame(new_frame_number);
+ tr1::shared_ptr frame = reader->GetFrame(new_frame_number);
// Get time mapped frame number (used to increase speed, change direction, etc...)
tr1::shared_ptr new_frame = get_time_mapped_frame(frame, requested_frame);
@@ -287,7 +284,7 @@ void Clip::reverse_buffer(juce::AudioSampleBuffer* buffer)
tr1::shared_ptr Clip::get_time_mapped_frame(tr1::shared_ptr frame, int frame_number) throw(ReaderClosed)
{
// Check for valid reader
- if (!file_reader)
+ if (!reader)
// Throw error if reader not initialized
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.", "");
@@ -305,20 +302,20 @@ tr1::shared_ptr Clip::get_time_mapped_frame(tr1::shared_ptr frame,
int new_frame_number = time.GetInt(frame_number);
// Create a new frame
- int samples_in_frame = GetSamplesPerFrame(new_frame_number, file_reader->info.fps);
+ int samples_in_frame = GetSamplesPerFrame(new_frame_number, reader->info.fps);
new_frame = tr1::shared_ptr(new Frame(new_frame_number, 1, 1, "#000000", samples_in_frame, frame->GetAudioChannelsCount()));
// Copy the image from the new frame
- new_frame->AddImage(file_reader->GetFrame(new_frame_number)->GetImage());
+ new_frame->AddImage(reader->GetFrame(new_frame_number)->GetImage());
// Get delta (difference in previous Y value)
int delta = int(round(time.GetDelta(frame_number)));
// Init audio vars
- int sample_rate = file_reader->GetFrame(new_frame_number)->GetAudioSamplesRate();
- int channels = file_reader->info.channels;
- int number_of_samples = file_reader->GetFrame(new_frame_number)->GetAudioSamplesCount();
+ int sample_rate = reader->GetFrame(new_frame_number)->GetAudioSamplesRate();
+ int channels = reader->info.channels;
+ int number_of_samples = reader->GetFrame(new_frame_number)->GetAudioSamplesCount();
// Determine if we are speeding up or slowing down
if (time.GetRepeatFraction(frame_number).den > 1)
@@ -336,7 +333,7 @@ tr1::shared_ptr Clip::get_time_mapped_frame(tr1::shared_ptr frame,
// Loop through channels, and get audio samples
for (int channel = 0; channel < channels; channel++)
// Get the audio samples for this channel
- samples->addFrom(channel, 0, file_reader->GetFrame(new_frame_number)->GetAudioSamples(channel), number_of_samples, 1.0f);
+ samples->addFrom(channel, 0, reader->GetFrame(new_frame_number)->GetAudioSamples(channel), number_of_samples, 1.0f);
// Reverse the samples (if needed)
if (!time.IsIncreasing(frame_number))
@@ -383,7 +380,7 @@ tr1::shared_ptr Clip::get_time_mapped_frame(tr1::shared_ptr frame,
//int next_unique_frame = time.GetInt(frame_number + (time.GetRepeatFraction(frame_number).den - time.GetRepeatFraction(frame_number).num) + 1);
//if (next_unique_frame != new_frame_number)
// // Overlay the next frame on top of this frame (to create a smoother slow motion effect)
- // new_frame->AddImage(file_reader->GetFrame(next_unique_frame)->GetImage(), float(time.GetRepeatFraction(frame_number).num) / float(time.GetRepeatFraction(frame_number).den));
+ // new_frame->AddImage(reader->GetFrame(next_unique_frame)->GetImage(), float(time.GetRepeatFraction(frame_number).num) / float(time.GetRepeatFraction(frame_number).den));
}
else if (abs(delta) > 1 && abs(delta) < 100)
@@ -399,12 +396,12 @@ tr1::shared_ptr Clip::get_time_mapped_frame(tr1::shared_ptr frame,
for (int delta_frame = new_frame_number - (delta - 1); delta_frame <= new_frame_number; delta_frame++)
{
// buffer to hold detal samples
- int number_of_delta_samples = file_reader->GetFrame(delta_frame)->GetAudioSamplesCount();
+ int number_of_delta_samples = reader->GetFrame(delta_frame)->GetAudioSamplesCount();
AudioSampleBuffer* delta_samples = new juce::AudioSampleBuffer(channels, number_of_delta_samples);
delta_samples->clear();
for (int channel = 0; channel < channels; channel++)
- delta_samples->addFrom(channel, 0, file_reader->GetFrame(delta_frame)->GetAudioSamples(channel), number_of_delta_samples, 1.0f);
+ delta_samples->addFrom(channel, 0, reader->GetFrame(delta_frame)->GetAudioSamples(channel), number_of_delta_samples, 1.0f);
// Reverse the samples (if needed)
if (!time.IsIncreasing(frame_number))
@@ -429,12 +426,12 @@ tr1::shared_ptr Clip::get_time_mapped_frame(tr1::shared_ptr frame,
for (int delta_frame = new_frame_number - (delta + 1); delta_frame >= new_frame_number; delta_frame--)
{
// buffer to hold delta samples
- int number_of_delta_samples = file_reader->GetFrame(delta_frame)->GetAudioSamplesCount();
+ int number_of_delta_samples = reader->GetFrame(delta_frame)->GetAudioSamplesCount();
AudioSampleBuffer* delta_samples = new juce::AudioSampleBuffer(channels, number_of_delta_samples);
delta_samples->clear();
for (int channel = 0; channel < channels; channel++)
- delta_samples->addFrom(channel, 0, file_reader->GetFrame(delta_frame)->GetAudioSamples(channel), number_of_delta_samples, 1.0f);
+ delta_samples->addFrom(channel, 0, reader->GetFrame(delta_frame)->GetAudioSamples(channel), number_of_delta_samples, 1.0f);
// Reverse the samples (if needed)
if (!time.IsIncreasing(frame_number))
@@ -521,14 +518,14 @@ int Clip::adjust_frame_number_minimum(int frame_number)
int Clip::GetSamplesPerFrame(int frame_number, Fraction rate) throw(ReaderClosed)
{
// Check for valid reader
- if (!file_reader)
+ if (!reader)
// Throw error if reader not initialized
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.", "");
// Get the total # of samples for the previous frame, and the current frame (rounded)
double fps = rate.Reciprocal().ToDouble();
- double previous_samples = round((file_reader->info.sample_rate * fps) * (frame_number - 1));
- double total_samples = round((file_reader->info.sample_rate * fps) * frame_number);
+ double previous_samples = round((reader->info.sample_rate * fps) * (frame_number - 1));
+ double total_samples = round((reader->info.sample_rate * fps) * frame_number);
// Subtract the previous frame's total samples with this frame's total samples. Not all sample rates can
// be evenly divided into frames, so each frame can have have different # of samples.
@@ -536,6 +533,13 @@ int Clip::GetSamplesPerFrame(int frame_number, Fraction rate) throw(ReaderClosed
return samples_per_frame;
}
+// Generate JSON string of this object
+string Clip::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
// Generate Json::JsonValue for this object
Json::Value Clip::JsonValue() {
@@ -545,16 +549,41 @@ Json::Value Clip::JsonValue() {
root["scale"] = scale;
root["anchor"] = anchor;
root["waveform"] = waveform;
+ if (reader)
+ root["reader"] = reader->JsonValue();
// return JsonValue
return root;
}
+// Load JSON string into this object
+void Clip::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void Clip::Json(Json::Value root) {
+void Clip::SetJsonValue(Json::Value root) {
// Set parent data
- ClipBase::Json(root);
+ ClipBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["gravity"] != Json::nullValue)
@@ -565,4 +594,37 @@ void Clip::Json(Json::Value root) {
anchor = (AnchorType) root["anchor"].asInt();
if (root["waveform"] != Json::nullValue)
waveform = root["waveform"].asBool();
+ if (root["reader"] != Json::nullValue) // does Json contain a reader?
+ {
+ if (root["reader"]["type"] != Json::nullValue) // does the reader Json contain a 'type'?
+ {
+ // Close previous reader (if any)
+ if (reader)
+ reader->Close();
+
+ // Create new reader (and load properties)
+ string type = root["reader"]["type"].asString();
+
+ if (type == "FFmpegReader") {
+
+ // Create new reader
+ reader = new FFmpegReader(root["reader"]["path"].asString());
+ reader->SetJsonValue(root["reader"]);
+
+ } else if (type == "ImageReader") {
+
+ // Create new reader
+ reader = new ImageReader(root["reader"]["path"].asString());
+ reader->SetJsonValue(root["reader"]);
+
+ } else if (type == "TextReader") {
+
+ // Create new reader
+ reader = new TextReader();
+ reader->SetJsonValue(root["reader"]);
+ }
+
+ //TextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color)
+ }
+ }
}
diff --git a/src/ClipBase.cpp b/src/ClipBase.cpp
index 0ca2d177..53d8f742 100644
--- a/src/ClipBase.cpp
+++ b/src/ClipBase.cpp
@@ -29,13 +29,6 @@
using namespace openshot;
-// Generate JSON string of this object
-string ClipBase::Json() {
-
- // Return formatted string
- return JsonValue().toStyledString();
-}
-
// Generate Json::JsonValue for this object
Json::Value ClipBase::JsonValue() {
@@ -50,31 +43,8 @@ Json::Value ClipBase::JsonValue() {
return root;
}
-// Load JSON string into this object
-void ClipBase::Json(string value) throw(InvalidJSON) {
-
- // Parse JSON string into JSON objects
- Json::Value root;
- Json::Reader reader;
- bool success = reader.parse( value, root );
- if (!success)
- // Raise exception
- throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
-
- try
- {
- // Set all values that match
- Json(root);
- }
- catch (exception e)
- {
- // Error parsing JSON (or missing keys)
- throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
- }
-}
-
// Load Json::JsonValue into this object
-void ClipBase::Json(Json::Value root) {
+void ClipBase::SetJsonValue(Json::Value root) {
// Set data from Json (if key is found)
if (root["position"] != Json::nullValue)
diff --git a/src/Color.cpp b/src/Color.cpp
index 2a208b29..c0cd5bad 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -50,7 +50,7 @@ Json::Value Color::JsonValue() {
}
// Load JSON string into this object
-void Color::Json(string value) throw(InvalidJSON) {
+void Color::SetJson(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
@@ -63,7 +63,7 @@ void Color::Json(string value) throw(InvalidJSON) {
try
{
// Set all values that match
- Json(root);
+ SetJsonValue(root);
}
catch (exception e)
{
@@ -73,13 +73,13 @@ void Color::Json(string value) throw(InvalidJSON) {
}
// Load Json::JsonValue into this object
-void Color::Json(Json::Value root) {
+void Color::SetJsonValue(Json::Value root) {
// Set data from Json (if key is found)
if (root["red"] != Json::nullValue)
- red.Json(root["red"]);
+ red.SetJsonValue(root["red"]);
if (root["green"] != Json::nullValue)
- green.Json(root["green"]);
+ green.SetJsonValue(root["green"]);
if (root["blue"] != Json::nullValue)
- blue.Json(root["blue"]);
+ blue.SetJsonValue(root["blue"]);
}
diff --git a/src/Coordinate.cpp b/src/Coordinate.cpp
index edd812dc..612eff67 100644
--- a/src/Coordinate.cpp
+++ b/src/Coordinate.cpp
@@ -66,7 +66,7 @@ Json::Value Coordinate::JsonValue() {
}
// Load JSON string into this object
-void Coordinate::Json(string value) throw(InvalidJSON) {
+void Coordinate::SetJson(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
@@ -79,7 +79,7 @@ void Coordinate::Json(string value) throw(InvalidJSON) {
try
{
// Set all values that match
- Json(root);
+ SetJsonValue(root);
}
catch (exception e)
{
@@ -89,7 +89,7 @@ void Coordinate::Json(string value) throw(InvalidJSON) {
}
// Load Json::JsonValue into this object
-void Coordinate::Json(Json::Value root) {
+void Coordinate::SetJsonValue(Json::Value root) {
// Set data from Json (if key is found)
if (root["X"] != Json::nullValue)
diff --git a/src/DecklinkReader.cpp b/src/DecklinkReader.cpp
index 85985ff5..8c791006 100644
--- a/src/DecklinkReader.cpp
+++ b/src/DecklinkReader.cpp
@@ -245,3 +245,57 @@ tr1::shared_ptr DecklinkReader::GetFrame(int requested_frame) throw(Reade
}
+// Generate JSON string of this object
+string DecklinkReader::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
+// Generate Json::JsonValue for this object
+Json::Value DecklinkReader::JsonValue() {
+
+ // Create root json object
+ Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "DecklinkReader";
+
+ // return JsonValue
+ return root;
+}
+
+// Load JSON string into this object
+void DecklinkReader::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
+// Load Json::JsonValue into this object
+void DecklinkReader::SetJsonValue(Json::Value root) throw(InvalidFile) {
+
+ // Set parent data
+ ReaderBase::SetJsonValue(root);
+
+ // Re-Open path, and re-init everything (if needed)
+ if (is_open)
+ {
+ Close();
+ Open();
+ }
+}
diff --git a/src/DummyReader.cpp b/src/DummyReader.cpp
index a5d024b3..c110c395 100644
--- a/src/DummyReader.cpp
+++ b/src/DummyReader.cpp
@@ -116,4 +116,51 @@ tr1::shared_ptr DummyReader::GetFrame(int requested_frame) throw(ReaderCl
throw InvalidFile("No frame could be created from this type of file.", "dummy");
}
+// Generate JSON string of this object
+string DummyReader::Json() {
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
+// Generate Json::JsonValue for this object
+Json::Value DummyReader::JsonValue() {
+
+ // Create root json object
+ Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "DummyReader";
+
+ // return JsonValue
+ return root;
+}
+
+// Load JSON string into this object
+void DummyReader::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
+// Load Json::JsonValue into this object
+void DummyReader::SetJsonValue(Json::Value root) throw(InvalidFile) {
+
+ // Set parent data
+ ReaderBase::SetJsonValue(root);
+
+}
diff --git a/src/EffectBase.cpp b/src/EffectBase.cpp
index 119cff62..3bd163be 100644
--- a/src/EffectBase.cpp
+++ b/src/EffectBase.cpp
@@ -77,7 +77,7 @@ Json::Value EffectBase::JsonValue() {
}
// Load JSON string into this object
-void EffectBase::Json(string value) throw(InvalidJSON) {
+void EffectBase::SetJson(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
@@ -90,7 +90,7 @@ void EffectBase::Json(string value) throw(InvalidJSON) {
try
{
// Set all values that match
- Json(root);
+ SetJsonValue(root);
}
catch (exception e)
{
@@ -100,10 +100,10 @@ void EffectBase::Json(string value) throw(InvalidJSON) {
}
// Load Json::JsonValue into this object
-void EffectBase::Json(Json::Value root) {
+void EffectBase::SetJsonValue(Json::Value root) {
// Set parent data
- ClipBase::Json(root);
+ ClipBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["order"] != Json::nullValue)
diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp
index d38a16e9..39f6c718 100644
--- a/src/FFmpegReader.cpp
+++ b/src/FFmpegReader.cpp
@@ -1554,28 +1554,62 @@ int FFmpegReader::GetSmallestAudioFrame()
return smallest_frame;
}
+// Generate JSON string of this object
+string FFmpegReader::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
// Generate Json::JsonValue for this object
Json::Value FFmpegReader::JsonValue() {
// Create root json object
Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "FFmpegReader";
root["path"] = path;
// return JsonValue
return root;
}
+// Load JSON string into this object
+void FFmpegReader::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void FFmpegReader::Json(Json::Value root) throw(InvalidFile) {
+void FFmpegReader::SetJsonValue(Json::Value root) throw(InvalidFile) {
// Set parent data
- ReaderBase::Json(root);
+ ReaderBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["path"] != Json::nullValue)
path = root["path"].asString();
- // Open path, and re-init everything
- Close();
- Open();
+ // Re-Open path, and re-init everything (if needed)
+ if (is_open)
+ {
+ Close();
+ Open();
+ }
}
diff --git a/src/FrameMapper.cpp b/src/FrameMapper.cpp
index 8444a20e..0b04ae61 100644
--- a/src/FrameMapper.cpp
+++ b/src/FrameMapper.cpp
@@ -437,3 +437,59 @@ void FrameMapper::Close()
if (reader)
reader->Close();
}
+
+
+// Generate JSON string of this object
+string FrameMapper::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
+// Generate Json::JsonValue for this object
+Json::Value FrameMapper::JsonValue() {
+
+ // Create root json object
+ Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "FrameMapper";
+
+ // return JsonValue
+ return root;
+}
+
+// Load JSON string into this object
+void FrameMapper::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
+// Load Json::JsonValue into this object
+void FrameMapper::SetJsonValue(Json::Value root) throw(InvalidFile) {
+
+ // Set parent data
+ ReaderBase::SetJsonValue(root);
+
+ // Re-Open path, and re-init everything (if needed)
+ if (reader) {
+
+ Close();
+ Open();
+ }
+}
diff --git a/src/ImageReader.cpp b/src/ImageReader.cpp
index d773ade8..5269c183 100644
--- a/src/ImageReader.cpp
+++ b/src/ImageReader.cpp
@@ -122,29 +122,62 @@ tr1::shared_ptr ImageReader::GetFrame(int requested_frame) throw(ReaderCl
return image_frame;
}
+// Generate JSON string of this object
+string ImageReader::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
// Generate Json::JsonValue for this object
Json::Value ImageReader::JsonValue() {
// Create root json object
Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "ImageReader";
root["path"] = path;
// return JsonValue
return root;
}
+// Load JSON string into this object
+void ImageReader::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void ImageReader::Json(Json::Value root) throw(InvalidFile) {
+void ImageReader::SetJsonValue(Json::Value root) throw(InvalidFile) {
// Set parent data
- ReaderBase::Json(root);
+ ReaderBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["path"] != Json::nullValue)
path = root["path"].asString();
- // Open path, and re-init everything
- Close();
- Open();
+ // Re-Open path, and re-init everything (if needed)
+ if (is_open)
+ {
+ Close();
+ Open();
+ }
}
diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp
index 1f1f1580..9949b0bf 100644
--- a/src/KeyFrame.cpp
+++ b/src/KeyFrame.cpp
@@ -264,7 +264,7 @@ Json::Value Keyframe::JsonValue() {
}
// Load JSON string into this object
-void Keyframe::Json(string value) throw(InvalidJSON) {
+void Keyframe::SetJson(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
@@ -277,7 +277,7 @@ void Keyframe::Json(string value) throw(InvalidJSON) {
try
{
// Set all values that match
- Json(root);
+ SetJsonValue(root);
}
catch (exception e)
{
@@ -287,7 +287,7 @@ void Keyframe::Json(string value) throw(InvalidJSON) {
}
// Load Json::JsonValue into this object
-void Keyframe::Json(Json::Value root) {
+void Keyframe::SetJsonValue(Json::Value root) {
// mark as dirty
needs_update = true;
@@ -305,7 +305,7 @@ void Keyframe::Json(Json::Value root) {
Point p;
// Load Json into Point
- p.Json(existing_point);
+ p.SetJsonValue(existing_point);
// Add Point to Keyframe
AddPoint(p);
diff --git a/src/Main.cpp b/src/Main.cpp
index 8ea8a68d..335a8d39 100644
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -41,13 +41,13 @@ using namespace tr1;
int main(int argc, char* argv[])
{
- Color c;
- std::string a;
- a = "{\"blue\":{\"Auto_Handle_Percentage\":0.4000000059604645,\"Points\":[]},\"red\":{\"Auto_Handle_Percentage\":0.4000000059604645,\"Points\":[{\"co\":{\"X\":0,\"Y\":243,\"delta\":0,\"increasing\":true,\"repeated\":{\"den\":1,\"num\":1}},\"handle_left\":{\"X\":0,\"Y\":243,\"delta\":0,\"increasing\":true,\"repeated\":{\"den\":1,\"num\":1}},\"handle_right\":{\"X\":0,\"Y\":243,\"delta\":0,\"increasing\":true,\"repeated\":{\"den\":1,\"num\":1}},\"handle_type\":0,\"interpolation\":0}]}}";
- c.Json(a);
+ FFmpegReader r2("/home/jonathan/Videos/sintel_trailer-720p.mp4");
+ r2.Open();
+ cout << r2.Json() << endl;
+ r2.SetJson("{\"acodec\":\"\",\"audio_bit_rate\":0,\"audio_stream_index\":-1,\"audio_timebase\":{\"den\":1,\"num\":1},\"channels\":0,\"display_ratio\":{\"den\":9,\"num\":16},\"duration\":10.03333377838135,\"file_size\":\"208835074\",\"fps\":{\"den\":1,\"num\":30},\"has_audio\":false,\"has_video\":true,\"height\":1080,\"interlaced_frame\":false,\"path\":\"/home/jonathan/Videos/space_undulation_hd.mov\",\"pixel_format\":13,\"pixel_ratio\":{\"den\":72,\"num\":72},\"sample_rate\":0,\"top_field_first\":false,\"type\":\"FFmpegReader\",\"vcodec\":\"mjpeg\",\"video_bit_rate\":166513021,\"video_length\":\"301\",\"video_stream_index\":0,\"video_timebase\":{\"den\":30,\"num\":1},\"width\":1920}");
+ return 0;
+
-// FFmpegReader r2("/home/jonathan/Videos/sintel_trailer-720p.mp4");
-// r2.Open();
// SDLPlayer p;
// p.Reader(&r2);
// p.Play();
diff --git a/src/Point.cpp b/src/Point.cpp
index fe371b8e..e3008238 100644
--- a/src/Point.cpp
+++ b/src/Point.cpp
@@ -116,7 +116,7 @@ Json::Value Point::JsonValue() {
}
// Load JSON string into this object
-void Point::Json(string value) throw(InvalidJSON) {
+void Point::SetJson(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
@@ -129,7 +129,7 @@ void Point::Json(string value) throw(InvalidJSON) {
try
{
// Set all values that match
- Json(root);
+ SetJsonValue(root);
}
catch (exception e)
{
@@ -139,14 +139,14 @@ void Point::Json(string value) throw(InvalidJSON) {
}
// Load Json::JsonValue into this object
-void Point::Json(Json::Value root) {
+void Point::SetJsonValue(Json::Value root) {
if (root["co"] != Json::nullValue)
- co.Json(root["co"]); // update coordinate
+ co.SetJsonValue(root["co"]); // update coordinate
if (root["handle_left"] != Json::nullValue)
- handle_left.Json(root["handle_left"]); // update coordinate
+ handle_left.SetJsonValue(root["handle_left"]); // update coordinate
if (root["handle_right"] != Json::nullValue)
- handle_right.Json(root["handle_right"]); // update coordinate
+ handle_right.SetJsonValue(root["handle_right"]); // update coordinate
if (root["interpolation"] != Json::nullValue)
interpolation = (InterpolationType) root["interpolation"].asInt();
if (root["handle_type"] != Json::nullValue)
diff --git a/src/ReaderBase.cpp b/src/ReaderBase.cpp
index 5a257a7e..cebad87c 100644
--- a/src/ReaderBase.cpp
+++ b/src/ReaderBase.cpp
@@ -95,13 +95,6 @@ void ReaderBase::DisplayInfo() {
cout << "----------------------------" << endl;
}
-// Generate JSON string of this object
-string ReaderBase::Json() {
-
- // Return formatted string
- return JsonValue().toStyledString();
-}
-
// Generate Json::JsonValue for this object
Json::Value ReaderBase::JsonValue() {
@@ -149,31 +142,8 @@ Json::Value ReaderBase::JsonValue() {
return root;
}
-// Load JSON string into this object
-void ReaderBase::Json(string value) throw(InvalidJSON) {
-
- // Parse JSON string into JSON objects
- Json::Value root;
- Json::Reader reader;
- bool success = reader.parse( value, root );
- if (!success)
- // Raise exception
- throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
-
- try
- {
- // Set all values that match
- Json(root);
- }
- catch (exception e)
- {
- // Error parsing JSON (or missing keys)
- throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
- }
-}
-
// Load Json::JsonValue into this object
-void ReaderBase::Json(Json::Value root) {
+void ReaderBase::SetJsonValue(Json::Value root) {
// Set data from Json (if key is found)
if (root["has_video"] != Json::nullValue)
@@ -183,7 +153,7 @@ void ReaderBase::Json(Json::Value root) {
if (root["duration"] != Json::nullValue)
info.duration = root["duration"].asDouble();
if (root["file_size"] != Json::nullValue)
- info.file_size = (long long) root["file_size"].asUInt();
+ info.file_size = atoll(root["file_size"].asString().c_str());
if (root["height"] != Json::nullValue)
info.height = root["height"].asInt();
if (root["width"] != Json::nullValue)
@@ -207,7 +177,7 @@ void ReaderBase::Json(Json::Value root) {
if (root["vcodec"] != Json::nullValue)
info.vcodec = root["vcodec"].asString();
if (root["video_length"] != Json::nullValue)
- info.video_length = (long int) root["video_length"].asUInt();
+ info.video_length = atoll(root["video_length"].asString().c_str());
if (root["video_stream_index"] != Json::nullValue)
info.video_stream_index = root["video_stream_index"].asInt();
if (root["video_timebase"] != Json::nullValue) {
diff --git a/src/TextReader.cpp b/src/TextReader.cpp
index 4e0146eb..81c87240 100644
--- a/src/TextReader.cpp
+++ b/src/TextReader.cpp
@@ -29,6 +29,17 @@
using namespace openshot;
+/// Default constructor (blank text)
+TextReader::TextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), size(10.0), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) {
+
+ // Init FileInfo struct (clear all values)
+ InitFileInfo();
+
+ // Open and Close the reader, to populate it's attributes (such as height, width, etc...)
+ Open();
+ Close();
+}
+
TextReader::TextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color)
: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
{
@@ -157,11 +168,19 @@ tr1::shared_ptr TextReader::GetFrame(int requested_frame) throw(ReaderClo
}
+// Generate JSON string of this object
+string TextReader::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
// Generate Json::JsonValue for this object
Json::Value TextReader::JsonValue() {
// Create root json object
Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "TextReader";
root["width"] = width;
root["height"] = height;
root["x_offset"] = x_offset;
@@ -177,11 +196,34 @@ Json::Value TextReader::JsonValue() {
return root;
}
+// Load JSON string into this object
+void TextReader::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void TextReader::Json(Json::Value root) throw(InvalidFile) {
+void TextReader::SetJsonValue(Json::Value root) throw(InvalidFile) {
// Set parent data
- ReaderBase::Json(root);
+ ReaderBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["width"] != Json::nullValue)
@@ -205,7 +247,10 @@ void TextReader::Json(Json::Value root) throw(InvalidFile) {
if (root["gravity"] != Json::nullValue)
gravity = (GravityType) root["gravity"].asInt();
- // Open path, and re-init everything
- Close();
- Open();
+ // Re-Open path, and re-init everything (if needed)
+ if (is_open)
+ {
+ Close();
+ Open();
+ }
}
diff --git a/src/Timeline.cpp b/src/Timeline.cpp
index a51be1d7..503adb5c 100644
--- a/src/Timeline.cpp
+++ b/src/Timeline.cpp
@@ -532,3 +532,53 @@ tr1::shared_ptr Timeline::GetFrame(int requested_frame) throw(ReaderClose
return final_cache.GetFrame(requested_frame);
}
}
+
+
+// Generate JSON string of this object
+string Timeline::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
+// Generate Json::JsonValue for this object
+Json::Value Timeline::JsonValue() {
+
+ // Create root json object
+ Json::Value root = ReaderBase::JsonValue(); // get parent properties
+ root["type"] = "Timeline";
+
+ // return JsonValue
+ return root;
+}
+
+// Load JSON string into this object
+void Timeline::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
+// Load Json::JsonValue into this object
+void Timeline::SetJsonValue(Json::Value root) throw(InvalidFile) {
+
+ // Set parent data
+ ReaderBase::SetJsonValue(root);
+
+}
diff --git a/src/WriterBase.cpp b/src/WriterBase.cpp
index de38e3f6..08a28342 100644
--- a/src/WriterBase.cpp
+++ b/src/WriterBase.cpp
@@ -183,7 +183,7 @@ Json::Value WriterBase::JsonValue() {
}
// Load JSON string into this object
-void WriterBase::Json(string value) throw(InvalidJSON) {
+void WriterBase::SetJson(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
@@ -196,7 +196,7 @@ void WriterBase::Json(string value) throw(InvalidJSON) {
try
{
// Set all values that match
- Json(root);
+ SetJsonValue(root);
}
catch (exception e)
{
@@ -206,7 +206,7 @@ void WriterBase::Json(string value) throw(InvalidJSON) {
}
// Load Json::JsonValue into this object
-void WriterBase::Json(Json::Value root) {
+void WriterBase::SetJsonValue(Json::Value root) {
// Set data from Json (if key is found)
if (root["has_video"] != Json::nullValue)
diff --git a/src/effects/ChromaKey.cpp b/src/effects/ChromaKey.cpp
index 1f1670ec..86c7b5b7 100644
--- a/src/effects/ChromaKey.cpp
+++ b/src/effects/ChromaKey.cpp
@@ -56,6 +56,13 @@ tr1::shared_ptr ChromaKey::GetFrame(tr1::shared_ptr frame, int fra
return frame;
}
+// Generate JSON string of this object
+string ChromaKey::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
// Generate Json::JsonValue for this object
Json::Value ChromaKey::JsonValue() {
@@ -68,15 +75,38 @@ Json::Value ChromaKey::JsonValue() {
return root;
}
+// Load JSON string into this object
+void ChromaKey::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void ChromaKey::Json(Json::Value root) {
+void ChromaKey::SetJsonValue(Json::Value root) {
// Set parent data
- EffectBase::Json(root);
+ EffectBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["color"] != Json::nullValue)
- color.Json(root["color"]);
+ color.SetJsonValue(root["color"]);
if (root["fuzz"] != Json::nullValue)
- fuzz.Json(root["fuzz"]);
+ fuzz.SetJsonValue(root["fuzz"]);
}
diff --git a/src/effects/Deinterlace.cpp b/src/effects/Deinterlace.cpp
index 632de9c0..1fb8ca5d 100644
--- a/src/effects/Deinterlace.cpp
+++ b/src/effects/Deinterlace.cpp
@@ -66,6 +66,13 @@ tr1::shared_ptr Deinterlace::GetFrame(tr1::shared_ptr frame, int f
return frame;
}
+// Generate JSON string of this object
+string Deinterlace::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
// Generate Json::JsonValue for this object
Json::Value Deinterlace::JsonValue() {
@@ -77,11 +84,34 @@ Json::Value Deinterlace::JsonValue() {
return root;
}
+// Load JSON string into this object
+void Deinterlace::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void Deinterlace::Json(Json::Value root) {
+void Deinterlace::SetJsonValue(Json::Value root) {
// Set parent data
- EffectBase::Json(root);
+ EffectBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["isOdd"] != Json::nullValue)
diff --git a/src/effects/Mask.cpp b/src/effects/Mask.cpp
index 470dc29b..24f13e4c 100644
--- a/src/effects/Mask.cpp
+++ b/src/effects/Mask.cpp
@@ -122,6 +122,13 @@ tr1::shared_ptr Mask::GetFrame(tr1::shared_ptr frame, int frame_nu
return frame;
}
+// Generate JSON string of this object
+string Mask::Json() {
+
+ // Return formatted string
+ return JsonValue().toStyledString();
+}
+
// Generate Json::JsonValue for this object
Json::Value Mask::JsonValue() {
@@ -135,16 +142,39 @@ Json::Value Mask::JsonValue() {
return root;
}
+// Load JSON string into this object
+void Mask::SetJson(string value) throw(InvalidJSON) {
+
+ // Parse JSON string into JSON objects
+ Json::Value root;
+ Json::Reader reader;
+ bool success = reader.parse( value, root );
+ if (!success)
+ // Raise exception
+ throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
+
+ try
+ {
+ // Set all values that match
+ SetJsonValue(root);
+ }
+ catch (exception e)
+ {
+ // Error parsing JSON (or missing keys)
+ throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
+ }
+}
+
// Load Json::JsonValue into this object
-void Mask::Json(Json::Value root) {
+void Mask::SetJsonValue(Json::Value root) {
// Set parent data
- EffectBase::Json(root);
+ EffectBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (root["brightness"] != Json::nullValue)
- brightness.Json(root["brightness"]);
+ brightness.SetJsonValue(root["brightness"]);
if (root["contrast"] != Json::nullValue)
- contrast.Json(root["contrast"]);
+ contrast.SetJsonValue(root["contrast"]);
}
diff --git a/tests/ReaderBase_Tests.cpp b/tests/ReaderBase_Tests.cpp
index a85c62c1..5d6832dc 100644
--- a/tests/ReaderBase_Tests.cpp
+++ b/tests/ReaderBase_Tests.cpp
@@ -43,6 +43,8 @@ TEST(ReaderBase_Derived_Class)
tr1::shared_ptr GetFrame(int number) { tr1::shared_ptr f(new Frame()); return f; }
void Close() { };
void Open() { };
+ string Json() { };
+ void SetJson(string value) throw(InvalidJSON) { };
};
// Create an instance of the derived class