2013-09-11 17:32:40 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Source file for Clip class
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) 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
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-11 17:32:40 -05:00
|
|
|
*/
|
|
|
|
|
|
2020-10-18 07:43:37 -04:00
|
|
|
#include "Clip.h"
|
|
|
|
|
#include "FFmpegReader.h"
|
|
|
|
|
#include "FrameMapper.h"
|
2019-01-19 02:18:52 -06:00
|
|
|
#ifdef USE_IMAGEMAGICK
|
2020-10-18 07:43:37 -04:00
|
|
|
#include "ImageReader.h"
|
|
|
|
|
#include "TextReader.h"
|
2019-01-19 02:18:52 -06:00
|
|
|
#endif
|
2020-10-18 07:43:37 -04:00
|
|
|
#include "QtImageReader.h"
|
|
|
|
|
#include "ChunkReader.h"
|
|
|
|
|
#include "DummyReader.h"
|
|
|
|
|
#include "Timeline.h"
|
2020-12-22 21:32:36 -03:00
|
|
|
#include "effects/Tracker.h"
|
2012-10-03 01:55:24 -05:00
|
|
|
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
// Init default settings for a clip
|
|
|
|
|
void Clip::init_settings()
|
2012-10-03 01:55:24 -05:00
|
|
|
{
|
|
|
|
|
// Init clip settings
|
2012-10-04 15:07:29 -05:00
|
|
|
Position(0.0);
|
|
|
|
|
Layer(0);
|
|
|
|
|
Start(0.0);
|
|
|
|
|
End(0.0);
|
2012-10-04 16:07:58 -05:00
|
|
|
gravity = GRAVITY_CENTER;
|
|
|
|
|
scale = SCALE_FIT;
|
|
|
|
|
anchor = ANCHOR_CANVAS;
|
2017-03-15 02:06:53 -05:00
|
|
|
display = FRAME_DISPLAY_NONE;
|
2018-06-27 01:35:38 -05:00
|
|
|
mixing = VOLUME_MIX_NONE;
|
2012-11-29 16:32:48 -06:00
|
|
|
waveform = false;
|
2015-02-17 00:21:57 -06:00
|
|
|
previous_properties = "";
|
2020-12-22 21:32:36 -03:00
|
|
|
attached_id = "";
|
2012-10-03 01:55:24 -05:00
|
|
|
|
|
|
|
|
// Init scale curves
|
2012-11-08 18:02:20 -06:00
|
|
|
scale_x = Keyframe(1.0);
|
|
|
|
|
scale_y = Keyframe(1.0);
|
2012-10-03 01:55:24 -05:00
|
|
|
|
|
|
|
|
// Init location curves
|
|
|
|
|
location_x = Keyframe(0.0);
|
|
|
|
|
location_y = Keyframe(0.0);
|
|
|
|
|
|
2018-02-03 01:57:18 -06:00
|
|
|
// Init alpha
|
2016-01-16 21:53:07 -06:00
|
|
|
alpha = Keyframe(1.0);
|
2018-02-03 01:57:18 -06:00
|
|
|
|
2012-10-03 01:55:24 -05:00
|
|
|
// Init time & volume
|
2017-07-19 16:05:07 -05:00
|
|
|
time = Keyframe(1.0);
|
2012-11-29 16:32:48 -06:00
|
|
|
volume = Keyframe(1.0);
|
2012-10-03 01:55:24 -05:00
|
|
|
|
2012-11-29 23:11:50 -06:00
|
|
|
// Init audio waveform color
|
2015-06-01 00:20:14 -07:00
|
|
|
wave_color = Color((unsigned char)0, (unsigned char)123, (unsigned char)255, (unsigned char)255);
|
2012-11-29 23:11:50 -06:00
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
// Init shear and perspective curves
|
|
|
|
|
shear_x = Keyframe(0.0);
|
|
|
|
|
shear_y = Keyframe(0.0);
|
2020-04-13 16:55:29 -05:00
|
|
|
origin_x = Keyframe(0.5);
|
|
|
|
|
origin_y = Keyframe(0.5);
|
2012-10-04 01:34:45 -05:00
|
|
|
perspective_c1_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c1_y = Keyframe(-1.0);
|
|
|
|
|
perspective_c2_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c2_y = Keyframe(-1.0);
|
|
|
|
|
perspective_c3_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c3_y = Keyframe(-1.0);
|
|
|
|
|
perspective_c4_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c4_y = Keyframe(-1.0);
|
2012-10-04 16:07:58 -05:00
|
|
|
|
2016-04-24 15:37:47 -05:00
|
|
|
// Init audio channel filter and mappings
|
|
|
|
|
channel_filter = Keyframe(-1.0);
|
|
|
|
|
channel_mapping = Keyframe(-1.0);
|
|
|
|
|
|
|
|
|
|
// Init audio and video overrides
|
|
|
|
|
has_audio = Keyframe(-1.0);
|
|
|
|
|
has_video = Keyframe(-1.0);
|
2020-08-26 22:47:31 -05:00
|
|
|
|
2020-10-13 14:55:25 -05:00
|
|
|
// Init reader info struct and cache size
|
|
|
|
|
init_reader_settings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Init reader info details
|
|
|
|
|
void Clip::init_reader_settings() {
|
|
|
|
|
if (reader) {
|
|
|
|
|
// Init rotation (if any)
|
|
|
|
|
init_reader_rotation();
|
|
|
|
|
|
|
|
|
|
// Initialize info struct
|
|
|
|
|
info = reader->info;
|
|
|
|
|
|
|
|
|
|
// Initialize Clip cache
|
|
|
|
|
cache.SetMaxBytesFromInfo(OPEN_MP_NUM_PROCESSORS * 2, info.width, info.height, info.sample_rate, info.channels);
|
|
|
|
|
}
|
2012-10-04 01:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
2018-02-03 01:57:18 -06:00
|
|
|
// Init reader's rotation (if any)
|
|
|
|
|
void Clip::init_reader_rotation() {
|
|
|
|
|
// Only init rotation from reader when needed
|
2019-11-19 23:43:28 +01:00
|
|
|
if (rotation.GetCount() > 1)
|
2018-02-03 01:57:18 -06:00
|
|
|
// Do nothing if more than 1 rotation Point
|
|
|
|
|
return;
|
2019-11-19 23:43:28 +01:00
|
|
|
else if (rotation.GetCount() == 1 && rotation.GetValue(1) != 0.0)
|
2018-02-03 01:57:18 -06:00
|
|
|
// Do nothing if 1 Point, and it's not the default value
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Init rotation
|
|
|
|
|
if (reader && reader->info.metadata.count("rotate") > 0) {
|
|
|
|
|
// Use reader metadata rotation (if any)
|
|
|
|
|
// This is typical with cell phone videos filmed in different orientations
|
|
|
|
|
try {
|
|
|
|
|
float rotate_metadata = strtof(reader->info.metadata["rotate"].c_str(), 0);
|
|
|
|
|
rotation = Keyframe(rotate_metadata);
|
2019-07-03 12:58:02 -04:00
|
|
|
} catch (const std::exception& e) {}
|
2018-02-03 01:57:18 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// Default no rotation
|
|
|
|
|
rotation = Keyframe(0.0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
// Default Constructor for a clip
|
2020-08-26 13:12:42 -05:00
|
|
|
Clip::Clip() : resampler(NULL), reader(NULL), allocated_reader(NULL), is_open(false)
|
2012-10-04 01:34:45 -05:00
|
|
|
{
|
|
|
|
|
// Init all default settings
|
|
|
|
|
init_settings();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 01:45:34 -05:00
|
|
|
// Constructor with reader
|
2020-08-26 13:12:42 -05:00
|
|
|
Clip::Clip(ReaderBase* new_reader) : resampler(NULL), reader(new_reader), allocated_reader(NULL), is_open(false)
|
2012-10-09 01:45:34 -05:00
|
|
|
{
|
2018-02-03 01:57:18 -06:00
|
|
|
// Init all default settings
|
|
|
|
|
init_settings();
|
|
|
|
|
|
2012-12-07 01:05:48 -06:00
|
|
|
// Open and Close the reader (to set the duration of the clip)
|
|
|
|
|
Open();
|
|
|
|
|
Close();
|
2015-02-07 18:06:11 -06:00
|
|
|
|
2020-05-19 19:57:06 +10:00
|
|
|
// Update duration and set parent
|
|
|
|
|
if (reader) {
|
|
|
|
|
End(reader->info.duration);
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader->ParentClip(this);
|
2020-10-23 01:35:46 -05:00
|
|
|
// Init reader info struct and cache size
|
|
|
|
|
init_reader_settings();
|
2020-05-16 18:55:34 +10:00
|
|
|
}
|
2012-10-09 01:45:34 -05:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
// Constructor with filepath
|
2020-08-26 13:12:42 -05:00
|
|
|
Clip::Clip(std::string path) : resampler(NULL), reader(NULL), allocated_reader(NULL), is_open(false)
|
2012-10-04 01:34:45 -05:00
|
|
|
{
|
|
|
|
|
// Init all default settings
|
|
|
|
|
init_settings();
|
|
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// Get file extension (and convert to lower case)
|
2019-08-04 23:08:19 -04:00
|
|
|
std::string ext = get_file_extension(path);
|
2020-03-09 16:49:06 -05:00
|
|
|
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
2012-10-04 01:34:45 -05:00
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// Determine if common video formats
|
2012-10-09 01:45:34 -05:00
|
|
|
if (ext=="avi" || ext=="mov" || ext=="mkv" || ext=="mpg" || ext=="mpeg" || ext=="mp3" || ext=="mp4" || ext=="mts" ||
|
|
|
|
|
ext=="ogg" || ext=="wav" || ext=="wmv" || ext=="webm" || ext=="vob")
|
2012-10-04 18:02:46 -05:00
|
|
|
{
|
2012-10-04 01:34:45 -05:00
|
|
|
try
|
|
|
|
|
{
|
2012-10-04 18:02:46 -05:00
|
|
|
// Open common video format
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::FFmpegReader(path);
|
2014-01-05 23:12:56 -06:00
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
} catch(...) { }
|
|
|
|
|
}
|
2020-03-09 16:49:06 -05:00
|
|
|
if (ext=="osp")
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Open common video format
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::Timeline(path, true);
|
2020-03-09 16:49:06 -05:00
|
|
|
|
|
|
|
|
} catch(...) { }
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// If no video found, try each reader
|
2013-12-07 21:09:55 -06:00
|
|
|
if (!reader)
|
2012-10-04 18:02:46 -05:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Try an image reader
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::QtImageReader(path);
|
2012-10-04 18:02:46 -05:00
|
|
|
|
|
|
|
|
} catch(...) {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Try a video reader
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::FFmpegReader(path);
|
2012-10-04 18:02:46 -05:00
|
|
|
|
2014-02-18 23:25:28 -06:00
|
|
|
} catch(...) { }
|
2012-10-04 01:34:45 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 19:57:06 +10:00
|
|
|
// Update duration and set parent
|
2015-06-01 00:20:14 -07:00
|
|
|
if (reader) {
|
2015-02-11 21:59:13 -06:00
|
|
|
End(reader->info.duration);
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader->ParentClip(this);
|
2019-05-09 10:51:40 -07:00
|
|
|
allocated_reader = reader;
|
2020-10-13 14:55:25 -05:00
|
|
|
// Init reader info struct and cache size
|
2020-10-23 01:35:46 -05:00
|
|
|
init_reader_settings();
|
|
|
|
|
}
|
2015-06-01 00:20:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
|
Clip::~Clip()
|
|
|
|
|
{
|
|
|
|
|
// Delete the reader if clip created it
|
2019-05-09 10:51:40 -07:00
|
|
|
if (allocated_reader) {
|
|
|
|
|
delete allocated_reader;
|
|
|
|
|
allocated_reader = NULL;
|
2015-06-01 00:20:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close the resampler
|
|
|
|
|
if (resampler) {
|
|
|
|
|
delete resampler;
|
|
|
|
|
resampler = NULL;
|
|
|
|
|
}
|
2012-10-09 01:45:34 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-22 21:32:36 -03:00
|
|
|
// Attach clip to bounding box
|
|
|
|
|
void Clip::AttachToTracker(std::string tracked_id)
|
|
|
|
|
{
|
|
|
|
|
// Search for the tracked object on the timeline
|
|
|
|
|
Timeline *parentTimeline = (Timeline *) ParentTimeline();
|
|
|
|
|
|
|
|
|
|
// Create a smart pointer to the tracked object from the timeline
|
|
|
|
|
std::shared_ptr<openshot::KeyframeBase> trackedObject = parentTimeline->GetTrackedObject(tracked_id);
|
|
|
|
|
|
|
|
|
|
// Check for valid tracked object
|
|
|
|
|
if (trackedObject){
|
|
|
|
|
SetAttachedObject(trackedObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the pointer to the trackedObject this clip is attached to
|
|
|
|
|
void Clip::SetAttachedObject(std::shared_ptr<openshot::KeyframeBase> trackedObject){
|
|
|
|
|
attachedObject = trackedObject;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 01:45:34 -05:00
|
|
|
/// Set the current reader
|
2013-12-07 21:09:55 -06:00
|
|
|
void Clip::Reader(ReaderBase* new_reader)
|
2012-10-09 01:45:34 -05:00
|
|
|
{
|
|
|
|
|
// set reader pointer
|
2013-12-07 21:09:55 -06:00
|
|
|
reader = new_reader;
|
2018-02-03 01:57:18 -06:00
|
|
|
|
2019-01-19 02:18:52 -06:00
|
|
|
// set parent
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader->ParentClip(this);
|
2019-01-19 02:18:52 -06:00
|
|
|
|
2020-10-13 14:55:25 -05:00
|
|
|
// Init reader info struct and cache size
|
|
|
|
|
init_reader_settings();
|
2012-10-09 01:45:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the current reader
|
2017-10-26 18:44:35 -05:00
|
|
|
ReaderBase* Clip::Reader()
|
2012-10-09 01:45:34 -05:00
|
|
|
{
|
2013-12-07 21:09:55 -06:00
|
|
|
if (reader)
|
|
|
|
|
return reader;
|
2013-09-28 22:00:52 -05:00
|
|
|
else
|
|
|
|
|
// Throw error if reader not initialized
|
2019-08-27 15:47:39 -04:00
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
2012-10-04 16:07:58 -05:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 16:22:18 -05:00
|
|
|
// Open the internal reader
|
2017-10-26 18:44:35 -05:00
|
|
|
void Clip::Open()
|
2012-10-08 16:22:18 -05:00
|
|
|
{
|
2013-12-07 21:09:55 -06:00
|
|
|
if (reader)
|
2012-10-09 01:45:34 -05:00
|
|
|
{
|
|
|
|
|
// Open the reader
|
2013-12-07 21:09:55 -06:00
|
|
|
reader->Open();
|
2020-08-26 13:12:42 -05:00
|
|
|
is_open = true;
|
|
|
|
|
|
|
|
|
|
// Copy Reader info to Clip
|
|
|
|
|
info = reader->info;
|
2012-10-09 01:45:34 -05:00
|
|
|
|
|
|
|
|
// Set some clip properties from the file reader
|
2012-12-07 01:05:48 -06:00
|
|
|
if (end == 0.0)
|
2013-12-07 21:09:55 -06:00
|
|
|
End(reader->info.duration);
|
2012-10-09 01:45:34 -05:00
|
|
|
}
|
2013-09-28 22:00:52 -05:00
|
|
|
else
|
|
|
|
|
// Throw error if reader not initialized
|
2019-08-27 15:47:39 -04:00
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
2012-10-08 16:22:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close the internal reader
|
2017-10-26 18:44:35 -05:00
|
|
|
void Clip::Close()
|
2012-10-08 16:22:18 -05:00
|
|
|
{
|
2020-08-26 13:12:42 -05:00
|
|
|
is_open = false;
|
2014-07-25 23:32:12 -05:00
|
|
|
if (reader) {
|
2019-07-03 14:14:02 -04:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::Close");
|
2016-04-24 15:37:47 -05:00
|
|
|
|
2015-02-07 18:06:11 -06:00
|
|
|
// Close the reader
|
2013-12-07 21:09:55 -06:00
|
|
|
reader->Close();
|
2014-07-25 23:32:12 -05:00
|
|
|
}
|
2013-09-28 22:00:52 -05:00
|
|
|
else
|
|
|
|
|
// Throw error if reader not initialized
|
2019-08-27 15:47:39 -04:00
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
2012-10-08 16:22:18 -05:00
|
|
|
}
|
|
|
|
|
|
2012-10-14 02:36:05 -05:00
|
|
|
// Get end position of clip (trim end of video), which can be affected by the time curve.
|
2019-12-27 08:51:51 -05:00
|
|
|
float Clip::End() const
|
2012-10-14 02:36:05 -05:00
|
|
|
{
|
2019-03-14 09:26:56 -07:00
|
|
|
// if a time curve is present, use its length
|
2019-11-19 23:43:28 +01:00
|
|
|
if (time.GetCount() > 1)
|
2012-11-08 04:35:21 -06:00
|
|
|
{
|
|
|
|
|
// Determine the FPS fo this clip
|
|
|
|
|
float fps = 24.0;
|
2013-12-07 21:09:55 -06:00
|
|
|
if (reader)
|
2012-11-08 04:35:21 -06:00
|
|
|
// file reader
|
2013-12-07 21:09:55 -06:00
|
|
|
fps = reader->info.fps.ToFloat();
|
2013-09-28 22:00:52 -05:00
|
|
|
else
|
|
|
|
|
// Throw error if reader not initialized
|
2019-08-27 15:47:39 -04:00
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
2012-11-08 04:35:21 -06:00
|
|
|
|
2012-10-21 05:29:29 -05:00
|
|
|
return float(time.GetLength()) / fps;
|
2012-11-08 04:35:21 -06:00
|
|
|
}
|
2012-10-14 02:36:05 -05:00
|
|
|
else
|
|
|
|
|
// just use the duration (as detected by the reader)
|
|
|
|
|
return end;
|
|
|
|
|
}
|
|
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
// Create an openshot::Frame object for a specific frame number of this reader.
|
|
|
|
|
std::shared_ptr<Frame> Clip::GetFrame(int64_t frame_number)
|
2012-10-08 16:22:18 -05:00
|
|
|
{
|
2020-08-26 13:12:42 -05:00
|
|
|
// Check for open reader (or throw exception)
|
|
|
|
|
if (!is_open)
|
2020-10-20 12:42:00 -05:00
|
|
|
throw ReaderClosed("The Clip is closed. Call Open() before calling this method.");
|
2020-08-26 13:12:42 -05:00
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
if (reader)
|
2013-09-28 22:00:52 -05:00
|
|
|
{
|
|
|
|
|
// Adjust out of bounds frame number
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
frame_number = adjust_frame_number_minimum(frame_number);
|
2012-10-08 16:22:18 -05:00
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
// Get the original frame and pass it to GetFrame overload
|
|
|
|
|
std::shared_ptr<Frame> original_frame = GetOrCreateFrame(frame_number);
|
|
|
|
|
return GetFrame(original_frame, frame_number);
|
2020-08-26 17:05:50 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// Throw error if reader not initialized
|
|
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
|
|
|
|
}
|
|
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
// Use an existing openshot::Frame object and draw this Clip's frame onto it
|
|
|
|
|
std::shared_ptr<Frame> Clip::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
|
2020-08-26 17:05:50 -05:00
|
|
|
{
|
|
|
|
|
// Check for open reader (or throw exception)
|
|
|
|
|
if (!is_open)
|
2020-10-20 12:42:00 -05:00
|
|
|
throw ReaderClosed("The Clip is closed. Call Open() before calling this method.");
|
2020-08-26 17:05:50 -05:00
|
|
|
|
|
|
|
|
if (reader)
|
|
|
|
|
{
|
|
|
|
|
// Adjust out of bounds frame number
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
frame_number = adjust_frame_number_minimum(frame_number);
|
2020-08-26 17:05:50 -05:00
|
|
|
|
2020-08-26 22:47:31 -05:00
|
|
|
// Check the cache for this frame
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
std::shared_ptr<Frame> cached_frame = cache.GetFrame(frame_number);
|
2020-08-26 22:47:31 -05:00
|
|
|
if (cached_frame) {
|
|
|
|
|
// Debug output
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::GetFrame", "returned cached frame", frame_number);
|
2020-08-26 22:47:31 -05:00
|
|
|
|
|
|
|
|
// Return the cached frame
|
|
|
|
|
return cached_frame;
|
|
|
|
|
}
|
2012-10-08 16:22:18 -05:00
|
|
|
|
2016-04-24 15:37:47 -05:00
|
|
|
// Adjust has_video and has_audio overrides
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
int enabled_audio = has_audio.GetInt(frame_number);
|
2016-04-24 15:37:47 -05:00
|
|
|
if (enabled_audio == -1 && reader && reader->info.has_audio)
|
|
|
|
|
enabled_audio = 1;
|
|
|
|
|
else if (enabled_audio == -1 && reader && !reader->info.has_audio)
|
|
|
|
|
enabled_audio = 0;
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
int enabled_video = has_video.GetInt(frame_number);
|
2016-04-24 15:37:47 -05:00
|
|
|
if (enabled_video == -1 && reader && reader->info.has_video)
|
|
|
|
|
enabled_video = 1;
|
|
|
|
|
else if (enabled_video == -1 && reader && !reader->info.has_audio)
|
|
|
|
|
enabled_video = 0;
|
|
|
|
|
|
2013-09-28 22:00:52 -05:00
|
|
|
// Is a time map detected
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
int64_t new_frame_number = frame_number;
|
|
|
|
|
int64_t time_mapped_number = adjust_frame_number_minimum(time.GetLong(frame_number));
|
2019-11-19 23:43:28 +01:00
|
|
|
if (time.GetLength() > 1)
|
|
|
|
|
new_frame_number = time_mapped_number;
|
2012-10-10 15:21:33 -05:00
|
|
|
|
2013-09-28 22:00:52 -05:00
|
|
|
// Now that we have re-mapped what frame number is needed, go and get the frame pointer
|
2017-11-11 17:16:56 -06:00
|
|
|
std::shared_ptr<Frame> original_frame;
|
|
|
|
|
original_frame = GetOrCreateFrame(new_frame_number);
|
2015-03-14 01:36:13 -05:00
|
|
|
|
|
|
|
|
// Copy the image from the odd field
|
2016-04-24 15:37:47 -05:00
|
|
|
if (enabled_video)
|
2020-08-20 16:50:12 -04:00
|
|
|
frame->AddImage(std::make_shared<QImage>(*original_frame->GetImage()));
|
2015-03-14 01:36:13 -05:00
|
|
|
|
|
|
|
|
// Loop through each channel, add audio
|
2016-04-24 15:37:47 -05:00
|
|
|
if (enabled_audio && reader->info.has_audio)
|
2016-01-09 15:50:53 -06:00
|
|
|
for (int channel = 0; channel < original_frame->GetAudioChannelsCount(); channel++)
|
|
|
|
|
frame->AddAudio(true, channel, 0, original_frame->GetAudioSamples(channel), original_frame->GetAudioSamplesCount(), 1.0);
|
2015-03-14 01:36:13 -05:00
|
|
|
|
2013-09-28 22:00:52 -05:00
|
|
|
// Get time mapped frame number (used to increase speed, change direction, etc...)
|
2020-08-26 17:05:50 -05:00
|
|
|
// TODO: Handle variable # of samples, since this resamples audio for different speeds (only when time curve is set)
|
2020-10-19 17:42:12 -04:00
|
|
|
get_time_mapped_frame(frame, new_frame_number);
|
2012-10-10 02:36:53 -05:00
|
|
|
|
2020-08-26 17:05:50 -05:00
|
|
|
// Adjust # of samples to match requested (the interaction with time curves will make this tricky)
|
|
|
|
|
// TODO: Implement move samples to/from next frame
|
2012-10-10 02:36:53 -05:00
|
|
|
|
2015-03-14 01:36:13 -05:00
|
|
|
// Apply effects to the frame (if any)
|
2019-03-06 15:35:03 -06:00
|
|
|
apply_effects(frame);
|
2015-03-14 01:36:13 -05:00
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
// Determine size of image (from Timeline or Reader)
|
|
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
|
|
|
|
if (timeline) {
|
|
|
|
|
// Use timeline size (if available)
|
|
|
|
|
width = timeline->preview_width;
|
|
|
|
|
height = timeline->preview_height;
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback to clip size
|
|
|
|
|
width = reader->info.width;
|
|
|
|
|
height = reader->info.height;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 13:12:42 -05:00
|
|
|
// Apply keyframe / transforms
|
2020-08-26 17:05:50 -05:00
|
|
|
apply_keyframes(frame, width, height);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
2020-08-26 22:47:31 -05:00
|
|
|
// Cache frame
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
cache.Add(frame);
|
2020-08-26 22:47:31 -05:00
|
|
|
|
2013-09-28 22:00:52 -05:00
|
|
|
// Return processed 'frame'
|
2019-03-06 15:35:03 -06:00
|
|
|
return frame;
|
2013-09-28 22:00:52 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// Throw error if reader not initialized
|
2019-08-27 15:47:39 -04:00
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
2012-10-08 16:22:18 -05:00
|
|
|
}
|
|
|
|
|
|
2020-09-01 22:53:46 -04:00
|
|
|
// Look up an effect by ID
|
|
|
|
|
openshot::EffectBase* Clip::GetEffect(const std::string& id)
|
|
|
|
|
{
|
|
|
|
|
// Find the matching effect (if any)
|
|
|
|
|
for (const auto& effect : effects) {
|
|
|
|
|
if (effect->Id() == id) {
|
|
|
|
|
return effect;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// Get file extension
|
2019-08-04 23:08:19 -04:00
|
|
|
std::string Clip::get_file_extension(std::string path)
|
2012-10-04 18:02:46 -05:00
|
|
|
{
|
|
|
|
|
// return last part of path
|
|
|
|
|
return path.substr(path.find_last_of(".") + 1);
|
|
|
|
|
}
|
2012-10-10 02:36:53 -05:00
|
|
|
|
2012-10-21 05:29:29 -05:00
|
|
|
// Reverse an audio buffer
|
|
|
|
|
void Clip::reverse_buffer(juce::AudioSampleBuffer* buffer)
|
2012-10-10 02:36:53 -05:00
|
|
|
{
|
2012-10-21 05:29:29 -05:00
|
|
|
int number_of_samples = buffer->getNumSamples();
|
|
|
|
|
int channels = buffer->getNumChannels();
|
|
|
|
|
|
|
|
|
|
// Reverse array (create new buffer to hold the reversed version)
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::AudioSampleBuffer *reversed = new juce::AudioSampleBuffer(channels, number_of_samples);
|
2012-10-21 05:29:29 -05:00
|
|
|
reversed->clear();
|
|
|
|
|
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
{
|
|
|
|
|
int n=0;
|
|
|
|
|
for (int s = number_of_samples - 1; s >= 0; s--, n++)
|
2015-02-05 00:11:55 -06:00
|
|
|
reversed->getWritePointer(channel)[n] = buffer->getWritePointer(channel)[s];
|
2012-10-21 05:29:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy the samples back to the original array
|
|
|
|
|
buffer->clear();
|
|
|
|
|
// Loop through channels, and get audio samples
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
// Get the audio samples for this channel
|
2015-02-05 00:11:55 -06:00
|
|
|
buffer->addFrom(channel, 0, reversed->getReadPointer(channel), number_of_samples, 1.0f);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
|
|
|
|
delete reversed;
|
|
|
|
|
reversed = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adjust the audio and image of a time mapped frame
|
2019-03-06 15:35:03 -06:00
|
|
|
void Clip::get_time_mapped_frame(std::shared_ptr<Frame> frame, int64_t frame_number)
|
2012-10-21 05:29:29 -05:00
|
|
|
{
|
2013-09-28 22:00:52 -05:00
|
|
|
// Check for valid reader
|
2013-12-07 21:09:55 -06:00
|
|
|
if (!reader)
|
2013-09-28 22:00:52 -05:00
|
|
|
// Throw error if reader not initialized
|
2019-08-27 15:47:39 -04:00
|
|
|
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
|
2013-09-28 22:00:52 -05:00
|
|
|
|
2012-10-10 02:36:53 -05:00
|
|
|
// Check for a valid time map curve
|
2019-11-19 23:43:28 +01:00
|
|
|
if (time.GetLength() > 1)
|
2012-10-10 02:36:53 -05:00
|
|
|
{
|
2019-10-27 03:56:13 -04:00
|
|
|
const GenericScopedLock<juce::CriticalSection> lock(getFrameCriticalSection);
|
2015-12-28 02:41:32 -06:00
|
|
|
|
2012-10-21 05:29:29 -05:00
|
|
|
// create buffer and resampler
|
|
|
|
|
juce::AudioSampleBuffer *samples = NULL;
|
2012-10-19 01:49:48 -05:00
|
|
|
if (!resampler)
|
|
|
|
|
resampler = new AudioResampler();
|
2012-10-10 02:36:53 -05:00
|
|
|
|
2012-10-19 01:49:48 -05:00
|
|
|
// Get new frame number
|
2019-03-06 15:35:03 -06:00
|
|
|
int new_frame_number = frame->number;
|
2012-10-21 05:29:29 -05:00
|
|
|
|
|
|
|
|
// Get delta (difference in previous Y value)
|
|
|
|
|
int delta = int(round(time.GetDelta(frame_number)));
|
|
|
|
|
|
|
|
|
|
// Init audio vars
|
2013-12-07 21:09:55 -06:00
|
|
|
int channels = reader->info.channels;
|
2015-12-28 02:41:32 -06:00
|
|
|
int number_of_samples = GetOrCreateFrame(new_frame_number)->GetAudioSamplesCount();
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Only resample audio if needed
|
|
|
|
|
if (reader->info.has_audio) {
|
|
|
|
|
// Determine if we are speeding up or slowing down
|
|
|
|
|
if (time.GetRepeatFraction(frame_number).den > 1) {
|
|
|
|
|
// SLOWING DOWN AUDIO
|
|
|
|
|
// Resample data, and return new buffer pointer
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::AudioSampleBuffer *resampled_buffer = NULL;
|
2012-10-21 17:51:37 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// SLOW DOWN audio (split audio)
|
|
|
|
|
samples = new juce::AudioSampleBuffer(channels, number_of_samples);
|
2015-12-28 02:41:32 -06:00
|
|
|
samples->clear();
|
|
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// 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, GetOrCreateFrame(new_frame_number)->GetAudioSamples(channel),
|
|
|
|
|
number_of_samples, 1.0f);
|
2012-10-19 01:49:48 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Reverse the samples (if needed)
|
|
|
|
|
if (!time.IsIncreasing(frame_number))
|
|
|
|
|
reverse_buffer(samples);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Resample audio to be X times slower (where X is the denominator of the repeat fraction)
|
|
|
|
|
resampler->SetBuffer(samples, 1.0 / time.GetRepeatFraction(frame_number).den);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Resample the data (since it's the 1st slice)
|
|
|
|
|
resampled_buffer = resampler->GetResampledBuffer();
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Just take the samples we need for the requested frame
|
|
|
|
|
int start = (number_of_samples * (time.GetRepeatFraction(frame_number).num - 1));
|
|
|
|
|
if (start > 0)
|
|
|
|
|
start -= 1;
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
// Add new (slower) samples, to the frame object
|
2019-03-06 15:35:03 -06:00
|
|
|
frame->AddAudio(true, channel, 0, resampled_buffer->getReadPointer(channel, start),
|
2015-12-31 04:17:54 -06:00
|
|
|
number_of_samples, 1.0f);
|
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
resampled_buffer = NULL;
|
2012-10-21 05:29:29 -05:00
|
|
|
|
|
|
|
|
}
|
2015-12-31 04:17:54 -06:00
|
|
|
else if (abs(delta) > 1 && abs(delta) < 100) {
|
|
|
|
|
int start = 0;
|
|
|
|
|
if (delta > 0) {
|
|
|
|
|
// SPEED UP (multiple frames of audio), as long as it's not more than X frames
|
|
|
|
|
int total_delta_samples = 0;
|
|
|
|
|
for (int delta_frame = new_frame_number - (delta - 1);
|
|
|
|
|
delta_frame <= new_frame_number; delta_frame++)
|
|
|
|
|
total_delta_samples += Frame::GetSamplesPerFrame(delta_frame, reader->info.fps,
|
|
|
|
|
reader->info.sample_rate,
|
|
|
|
|
reader->info.channels);
|
2015-12-28 02:41:32 -06:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Allocate a new sample buffer for these delta frames
|
|
|
|
|
samples = new juce::AudioSampleBuffer(channels, total_delta_samples);
|
|
|
|
|
samples->clear();
|
|
|
|
|
|
|
|
|
|
// Loop through each frame in this delta
|
|
|
|
|
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 = GetOrCreateFrame(delta_frame)->GetAudioSamplesCount();
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::AudioSampleBuffer *delta_samples = new juce::AudioSampleBuffer(channels,
|
2015-12-31 04:17:54 -06:00
|
|
|
number_of_delta_samples);
|
|
|
|
|
delta_samples->clear();
|
|
|
|
|
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
delta_samples->addFrom(channel, 0, GetOrCreateFrame(delta_frame)->GetAudioSamples(channel),
|
|
|
|
|
number_of_delta_samples, 1.0f);
|
|
|
|
|
|
|
|
|
|
// Reverse the samples (if needed)
|
|
|
|
|
if (!time.IsIncreasing(frame_number))
|
|
|
|
|
reverse_buffer(delta_samples);
|
|
|
|
|
|
|
|
|
|
// Copy the samples to
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
// Get the audio samples for this channel
|
|
|
|
|
samples->addFrom(channel, start, delta_samples->getReadPointer(channel),
|
|
|
|
|
number_of_delta_samples, 1.0f);
|
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
delete delta_samples;
|
|
|
|
|
delta_samples = NULL;
|
|
|
|
|
|
|
|
|
|
// Increment start position
|
|
|
|
|
start += number_of_delta_samples;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// SPEED UP (multiple frames of audio), as long as it's not more than X frames
|
|
|
|
|
int total_delta_samples = 0;
|
|
|
|
|
for (int delta_frame = new_frame_number - (delta + 1);
|
|
|
|
|
delta_frame >= new_frame_number; delta_frame--)
|
|
|
|
|
total_delta_samples += Frame::GetSamplesPerFrame(delta_frame, reader->info.fps,
|
|
|
|
|
reader->info.sample_rate,
|
|
|
|
|
reader->info.channels);
|
|
|
|
|
|
|
|
|
|
// Allocate a new sample buffer for these delta frames
|
|
|
|
|
samples = new juce::AudioSampleBuffer(channels, total_delta_samples);
|
|
|
|
|
samples->clear();
|
|
|
|
|
|
|
|
|
|
// Loop through each frame in this delta
|
|
|
|
|
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 = GetOrCreateFrame(delta_frame)->GetAudioSamplesCount();
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::AudioSampleBuffer *delta_samples = new juce::AudioSampleBuffer(channels,
|
2015-12-31 04:17:54 -06:00
|
|
|
number_of_delta_samples);
|
|
|
|
|
delta_samples->clear();
|
|
|
|
|
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
delta_samples->addFrom(channel, 0, GetOrCreateFrame(delta_frame)->GetAudioSamples(channel),
|
|
|
|
|
number_of_delta_samples, 1.0f);
|
|
|
|
|
|
|
|
|
|
// Reverse the samples (if needed)
|
|
|
|
|
if (!time.IsIncreasing(frame_number))
|
|
|
|
|
reverse_buffer(delta_samples);
|
|
|
|
|
|
|
|
|
|
// Copy the samples to
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
// Get the audio samples for this channel
|
|
|
|
|
samples->addFrom(channel, start, delta_samples->getReadPointer(channel),
|
|
|
|
|
number_of_delta_samples, 1.0f);
|
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
delete delta_samples;
|
|
|
|
|
delta_samples = NULL;
|
|
|
|
|
|
|
|
|
|
// Increment start position
|
|
|
|
|
start += number_of_delta_samples;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resample audio to be X times faster (where X is the delta of the repeat fraction)
|
|
|
|
|
resampler->SetBuffer(samples, float(start) / float(number_of_samples));
|
|
|
|
|
|
|
|
|
|
// Resample data, and return new buffer pointer
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::AudioSampleBuffer *buffer = resampler->GetResampledBuffer();
|
2015-12-31 04:17:54 -06:00
|
|
|
|
|
|
|
|
// Add the newly resized audio samples to the current frame
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
|
|
|
|
// Add new (slower) samples, to the frame object
|
2019-03-06 15:35:03 -06:00
|
|
|
frame->AddAudio(true, channel, 0, buffer->getReadPointer(channel), number_of_samples, 1.0f);
|
2015-12-31 04:17:54 -06:00
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
buffer = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Use the samples on this frame (but maybe reverse them if needed)
|
|
|
|
|
samples = new juce::AudioSampleBuffer(channels, number_of_samples);
|
2015-12-28 02:41:32 -06:00
|
|
|
samples->clear();
|
|
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// 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, frame->GetAudioSamples(channel), number_of_samples, 1.0f);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// reverse the samples
|
|
|
|
|
if (!time.IsIncreasing(frame_number))
|
|
|
|
|
reverse_buffer(samples);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
// Add reversed samples to the frame object
|
|
|
|
|
for (int channel = 0; channel < channels; channel++)
|
2019-03-06 15:35:03 -06:00
|
|
|
frame->AddAudio(true, channel, 0, samples->getReadPointer(channel), number_of_samples, 1.0f);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-31 04:17:54 -06:00
|
|
|
delete samples;
|
|
|
|
|
samples = NULL;
|
2012-10-21 05:29:29 -05:00
|
|
|
}
|
2019-03-06 15:35:03 -06:00
|
|
|
}
|
2012-10-10 02:36:53 -05:00
|
|
|
}
|
|
|
|
|
|
2012-10-10 15:21:33 -05:00
|
|
|
// Adjust frame number minimum value
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t Clip::adjust_frame_number_minimum(int64_t frame_number)
|
2012-10-10 15:21:33 -05:00
|
|
|
{
|
|
|
|
|
// Never return a frame number 0 or below
|
|
|
|
|
if (frame_number < 1)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return frame_number;
|
|
|
|
|
|
|
|
|
|
}
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-12-28 02:41:32 -06:00
|
|
|
// Get or generate a blank frame
|
2017-09-28 16:03:01 -05:00
|
|
|
std::shared_ptr<Frame> Clip::GetOrCreateFrame(int64_t number)
|
2015-12-28 02:41:32 -06:00
|
|
|
{
|
|
|
|
|
try {
|
2016-04-24 15:37:47 -05:00
|
|
|
// Debug output
|
2020-08-26 17:05:50 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::GetOrCreateFrame (from reader)", "number", number);
|
2016-04-24 15:37:47 -05:00
|
|
|
|
2015-12-28 02:41:32 -06:00
|
|
|
// Attempt to get a frame (but this could fail if a reader has just been closed)
|
2020-10-20 12:42:00 -05:00
|
|
|
auto reader_frame = reader->GetFrame(number);
|
2015-12-28 02:41:32 -06:00
|
|
|
|
|
|
|
|
// Return real frame
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
if (reader_frame) {
|
|
|
|
|
// Create a new copy of reader frame
|
|
|
|
|
// This allows a clip to modify the pixels and audio of this frame without
|
|
|
|
|
// changing the underlying reader's frame data
|
|
|
|
|
//std::shared_ptr<Frame> reader_copy(new Frame(number, 1, 1, "#000000", reader_frame->GetAudioSamplesCount(), reader_frame->GetAudioChannelsCount()));
|
2020-10-20 12:42:00 -05:00
|
|
|
auto reader_copy = std::make_shared<Frame>(*reader_frame.get());
|
|
|
|
|
reader_copy->SampleRate(reader_frame->SampleRate());
|
|
|
|
|
reader_copy->ChannelsLayout(reader_frame->ChannelsLayout());
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
return reader_copy;
|
|
|
|
|
}
|
2015-12-28 02:41:32 -06:00
|
|
|
|
|
|
|
|
} catch (const ReaderClosed & e) {
|
|
|
|
|
// ...
|
|
|
|
|
} catch (const OutOfBoundsFrame & e) {
|
|
|
|
|
// ...
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 17:05:50 -05:00
|
|
|
// Estimate # of samples needed for this frame
|
|
|
|
|
int estimated_samples_in_frame = Frame::GetSamplesPerFrame(number, reader->info.fps, reader->info.sample_rate, reader->info.channels);
|
|
|
|
|
|
2016-04-24 15:37:47 -05:00
|
|
|
// Debug output
|
2020-08-26 17:05:50 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::GetOrCreateFrame (create blank)", "number", number, "estimated_samples_in_frame", estimated_samples_in_frame);
|
2016-04-24 15:37:47 -05:00
|
|
|
|
2015-12-28 02:41:32 -06:00
|
|
|
// Create blank frame
|
2020-10-20 12:42:00 -05:00
|
|
|
auto new_frame = std::make_shared<Frame>(
|
|
|
|
|
number, reader->info.width, reader->info.height,
|
|
|
|
|
"#000000", estimated_samples_in_frame, reader->info.channels);
|
2015-12-28 02:41:32 -06:00
|
|
|
new_frame->SampleRate(reader->info.sample_rate);
|
|
|
|
|
new_frame->ChannelsLayout(reader->info.channel_layout);
|
2020-08-26 17:05:50 -05:00
|
|
|
new_frame->AddAudioSilence(estimated_samples_in_frame);
|
2015-12-28 02:41:32 -06:00
|
|
|
return new_frame;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
// Generate JSON string of this object
|
2019-12-27 08:51:51 -05:00
|
|
|
std::string Clip::Json() const {
|
2013-12-07 21:09:55 -06:00
|
|
|
|
|
|
|
|
// Return formatted string
|
|
|
|
|
return JsonValue().toStyledString();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 22:41:42 -06:00
|
|
|
// Get all properties for a specific frame
|
2019-12-27 08:51:51 -05:00
|
|
|
std::string Clip::PropertiesJSON(int64_t requested_frame) const {
|
2015-02-09 22:41:42 -06:00
|
|
|
|
|
|
|
|
// Generate JSON properties list
|
|
|
|
|
Json::Value root;
|
2016-10-19 02:19:07 -05:00
|
|
|
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["gravity"] = add_property_json("Gravity", gravity, "int", "", NULL, 0, 8, false, requested_frame);
|
|
|
|
|
root["scale"] = add_property_json("Scale", scale, "int", "", NULL, 0, 3, false, requested_frame);
|
2017-03-15 02:06:53 -05:00
|
|
|
root["display"] = add_property_json("Frame Number", display, "int", "", NULL, 0, 3, false, requested_frame);
|
2018-06-27 01:35:38 -05:00
|
|
|
root["mixing"] = add_property_json("Volume Mixing", mixing, "int", "", NULL, 0, 2, false, requested_frame);
|
2016-10-19 02:19:07 -05:00
|
|
|
root["waveform"] = add_property_json("Waveform", waveform, "int", "", NULL, 0, 1, false, requested_frame);
|
2021-01-14 15:45:28 -03:00
|
|
|
if (!attached_id.empty()) {
|
|
|
|
|
root["attached_id"] = add_property_json("Attached ID", 0.0, "string", attached_id, NULL, -1, -1, false, requested_frame);
|
|
|
|
|
} else {
|
|
|
|
|
root["attached_id"] = add_property_json("Attached ID", 0.0, "string", "None", NULL, -1, -1, false, requested_frame);
|
2020-12-22 21:32:36 -03:00
|
|
|
}
|
2015-10-02 18:22:10 -05:00
|
|
|
// Add gravity choices (dropdown style)
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Top Left", GRAVITY_TOP_LEFT, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Top Center", GRAVITY_TOP, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Top Right", GRAVITY_TOP_RIGHT, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Left", GRAVITY_LEFT, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Center", GRAVITY_CENTER, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Right", GRAVITY_RIGHT, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Bottom Left", GRAVITY_BOTTOM_LEFT, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Bottom Center", GRAVITY_BOTTOM, gravity));
|
|
|
|
|
root["gravity"]["choices"].append(add_property_choice_json("Bottom Right", GRAVITY_BOTTOM_RIGHT, gravity));
|
|
|
|
|
|
|
|
|
|
// Add scale choices (dropdown style)
|
|
|
|
|
root["scale"]["choices"].append(add_property_choice_json("Crop", SCALE_CROP, scale));
|
|
|
|
|
root["scale"]["choices"].append(add_property_choice_json("Best Fit", SCALE_FIT, scale));
|
|
|
|
|
root["scale"]["choices"].append(add_property_choice_json("Stretch", SCALE_STRETCH, scale));
|
|
|
|
|
root["scale"]["choices"].append(add_property_choice_json("None", SCALE_NONE, scale));
|
|
|
|
|
|
2017-03-15 02:06:53 -05:00
|
|
|
// Add frame number display choices (dropdown style)
|
|
|
|
|
root["display"]["choices"].append(add_property_choice_json("None", FRAME_DISPLAY_NONE, display));
|
|
|
|
|
root["display"]["choices"].append(add_property_choice_json("Clip", FRAME_DISPLAY_CLIP, display));
|
|
|
|
|
root["display"]["choices"].append(add_property_choice_json("Timeline", FRAME_DISPLAY_TIMELINE, display));
|
|
|
|
|
root["display"]["choices"].append(add_property_choice_json("Both", FRAME_DISPLAY_BOTH, display));
|
|
|
|
|
|
2018-06-27 01:35:38 -05:00
|
|
|
// Add volume mixing choices (dropdown style)
|
|
|
|
|
root["mixing"]["choices"].append(add_property_choice_json("None", VOLUME_MIX_NONE, mixing));
|
|
|
|
|
root["mixing"]["choices"].append(add_property_choice_json("Average", VOLUME_MIX_AVERAGE, mixing));
|
|
|
|
|
root["mixing"]["choices"].append(add_property_choice_json("Reduce", VOLUME_MIX_REDUCE, mixing));
|
|
|
|
|
|
2015-10-02 18:22:10 -05:00
|
|
|
// Add waveform choices (dropdown style)
|
|
|
|
|
root["waveform"]["choices"].append(add_property_choice_json("Yes", true, waveform));
|
|
|
|
|
root["waveform"]["choices"].append(add_property_choice_json("No", false, waveform));
|
|
|
|
|
|
2015-02-09 22:41:42 -06:00
|
|
|
// Keyframes
|
2016-10-19 02:19:07 -05:00
|
|
|
root["location_x"] = add_property_json("Location X", location_x.GetValue(requested_frame), "float", "", &location_x, -1.0, 1.0, false, requested_frame);
|
|
|
|
|
root["location_y"] = add_property_json("Location Y", location_y.GetValue(requested_frame), "float", "", &location_y, -1.0, 1.0, false, requested_frame);
|
|
|
|
|
root["scale_x"] = add_property_json("Scale X", scale_x.GetValue(requested_frame), "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
|
|
|
|
|
root["scale_y"] = add_property_json("Scale Y", scale_y.GetValue(requested_frame), "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
|
|
|
|
|
root["alpha"] = add_property_json("Alpha", alpha.GetValue(requested_frame), "float", "", &alpha, 0.0, 1.0, false, requested_frame);
|
|
|
|
|
root["shear_x"] = add_property_json("Shear X", shear_x.GetValue(requested_frame), "float", "", &shear_x, -1.0, 1.0, false, requested_frame);
|
|
|
|
|
root["shear_y"] = add_property_json("Shear Y", shear_y.GetValue(requested_frame), "float", "", &shear_y, -1.0, 1.0, false, requested_frame);
|
|
|
|
|
root["rotation"] = add_property_json("Rotation", rotation.GetValue(requested_frame), "float", "", &rotation, -360, 360, false, requested_frame);
|
2020-04-13 16:55:29 -05:00
|
|
|
root["origin_x"] = add_property_json("Origin X", origin_x.GetValue(requested_frame), "float", "", &origin_x, 0.0, 1.0, false, requested_frame);
|
|
|
|
|
root["origin_y"] = add_property_json("Origin Y", origin_y.GetValue(requested_frame), "float", "", &origin_y, 0.0, 1.0, false, requested_frame);
|
2016-10-19 02:19:07 -05:00
|
|
|
root["volume"] = add_property_json("Volume", volume.GetValue(requested_frame), "float", "", &volume, 0.0, 1.0, false, requested_frame);
|
|
|
|
|
root["time"] = add_property_json("Time", time.GetValue(requested_frame), "float", "", &time, 0.0, 30 * 60 * 60 * 48, false, requested_frame);
|
|
|
|
|
root["channel_filter"] = add_property_json("Channel Filter", channel_filter.GetValue(requested_frame), "int", "", &channel_filter, -1, 10, false, requested_frame);
|
|
|
|
|
root["channel_mapping"] = add_property_json("Channel Mapping", channel_mapping.GetValue(requested_frame), "int", "", &channel_mapping, -1, 10, false, requested_frame);
|
|
|
|
|
root["has_audio"] = add_property_json("Enable Audio", has_audio.GetValue(requested_frame), "int", "", &has_audio, -1, 1.0, false, requested_frame);
|
|
|
|
|
root["has_video"] = add_property_json("Enable Video", has_video.GetValue(requested_frame), "int", "", &has_video, -1, 1.0, false, requested_frame);
|
2015-02-09 22:41:42 -06:00
|
|
|
|
2019-07-26 19:27:15 -04:00
|
|
|
// Add enable audio/video choices (dropdown style)
|
|
|
|
|
root["has_audio"]["choices"].append(add_property_choice_json("Auto", -1, has_audio.GetValue(requested_frame)));
|
|
|
|
|
root["has_audio"]["choices"].append(add_property_choice_json("Off", 0, has_audio.GetValue(requested_frame)));
|
|
|
|
|
root["has_audio"]["choices"].append(add_property_choice_json("On", 1, has_audio.GetValue(requested_frame)));
|
|
|
|
|
root["has_video"]["choices"].append(add_property_choice_json("Auto", -1, has_video.GetValue(requested_frame)));
|
|
|
|
|
root["has_video"]["choices"].append(add_property_choice_json("Off", 0, has_video.GetValue(requested_frame)));
|
|
|
|
|
root["has_video"]["choices"].append(add_property_choice_json("On", 1, has_video.GetValue(requested_frame)));
|
|
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
root["wave_color"] = add_property_json("Wave Color", 0.0, "color", "", &wave_color.red, 0, 255, false, requested_frame);
|
|
|
|
|
root["wave_color"]["red"] = add_property_json("Red", wave_color.red.GetValue(requested_frame), "float", "", &wave_color.red, 0, 255, false, requested_frame);
|
|
|
|
|
root["wave_color"]["blue"] = add_property_json("Blue", wave_color.blue.GetValue(requested_frame), "float", "", &wave_color.blue, 0, 255, false, requested_frame);
|
|
|
|
|
root["wave_color"]["green"] = add_property_json("Green", wave_color.green.GetValue(requested_frame), "float", "", &wave_color.green, 0, 255, false, requested_frame);
|
2015-11-25 23:54:10 -06:00
|
|
|
|
|
|
|
|
|
2015-02-09 22:41:42 -06:00
|
|
|
// Return formatted string
|
|
|
|
|
return root.toStyledString();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 08:51:51 -05:00
|
|
|
// Generate Json::Value for this object
|
|
|
|
|
Json::Value Clip::JsonValue() const {
|
2013-12-06 00:40:26 -06:00
|
|
|
|
2013-12-03 00:13:25 -06:00
|
|
|
// Create root json object
|
2013-12-06 00:40:26 -06:00
|
|
|
Json::Value root = ClipBase::JsonValue(); // get parent properties
|
2020-12-22 21:32:36 -03:00
|
|
|
root["attached_id"] = attached_id;
|
2013-12-03 00:13:25 -06:00
|
|
|
root["gravity"] = gravity;
|
|
|
|
|
root["scale"] = scale;
|
|
|
|
|
root["anchor"] = anchor;
|
2017-03-15 02:06:53 -05:00
|
|
|
root["display"] = display;
|
2018-06-27 01:35:38 -05:00
|
|
|
root["mixing"] = mixing;
|
2013-12-03 00:13:25 -06:00
|
|
|
root["waveform"] = waveform;
|
2014-01-04 19:04:21 -06:00
|
|
|
root["scale_x"] = scale_x.JsonValue();
|
|
|
|
|
root["scale_y"] = scale_y.JsonValue();
|
|
|
|
|
root["location_x"] = location_x.JsonValue();
|
|
|
|
|
root["location_y"] = location_y.JsonValue();
|
|
|
|
|
root["alpha"] = alpha.JsonValue();
|
|
|
|
|
root["rotation"] = rotation.JsonValue();
|
|
|
|
|
root["time"] = time.JsonValue();
|
|
|
|
|
root["volume"] = volume.JsonValue();
|
|
|
|
|
root["wave_color"] = wave_color.JsonValue();
|
|
|
|
|
root["shear_x"] = shear_x.JsonValue();
|
|
|
|
|
root["shear_y"] = shear_y.JsonValue();
|
2020-04-13 16:55:29 -05:00
|
|
|
root["origin_x"] = origin_x.JsonValue();
|
|
|
|
|
root["origin_y"] = origin_y.JsonValue();
|
2016-04-24 15:37:47 -05:00
|
|
|
root["channel_filter"] = channel_filter.JsonValue();
|
|
|
|
|
root["channel_mapping"] = channel_mapping.JsonValue();
|
|
|
|
|
root["has_audio"] = has_audio.JsonValue();
|
|
|
|
|
root["has_video"] = has_video.JsonValue();
|
2014-01-04 19:04:21 -06:00
|
|
|
root["perspective_c1_x"] = perspective_c1_x.JsonValue();
|
|
|
|
|
root["perspective_c1_y"] = perspective_c1_y.JsonValue();
|
|
|
|
|
root["perspective_c2_x"] = perspective_c2_x.JsonValue();
|
|
|
|
|
root["perspective_c2_y"] = perspective_c2_y.JsonValue();
|
|
|
|
|
root["perspective_c3_x"] = perspective_c3_x.JsonValue();
|
|
|
|
|
root["perspective_c3_y"] = perspective_c3_y.JsonValue();
|
|
|
|
|
root["perspective_c4_x"] = perspective_c4_x.JsonValue();
|
|
|
|
|
root["perspective_c4_y"] = perspective_c4_y.JsonValue();
|
|
|
|
|
|
2015-03-14 01:36:13 -05:00
|
|
|
// Add array of effects
|
|
|
|
|
root["effects"] = Json::Value(Json::arrayValue);
|
|
|
|
|
|
|
|
|
|
// loop through effects
|
2019-12-27 01:01:48 -05:00
|
|
|
for (auto existing_effect : effects)
|
2015-03-14 01:36:13 -05:00
|
|
|
{
|
|
|
|
|
root["effects"].append(existing_effect->JsonValue());
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
if (reader)
|
|
|
|
|
root["reader"] = reader->JsonValue();
|
2020-03-09 16:49:06 -05:00
|
|
|
else
|
|
|
|
|
root["reader"] = Json::Value(Json::objectValue);
|
2013-12-03 00:13:25 -06:00
|
|
|
|
2013-12-06 00:40:26 -06:00
|
|
|
// return JsonValue
|
|
|
|
|
return root;
|
2013-12-03 00:13:25 -06:00
|
|
|
}
|
|
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
// Load JSON string into this object
|
2019-12-27 08:51:51 -05:00
|
|
|
void Clip::SetJson(const std::string value) {
|
2013-12-07 21:09:55 -06:00
|
|
|
|
|
|
|
|
// Parse JSON string into JSON objects
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-12-27 08:51:51 -05:00
|
|
|
const Json::Value root = openshot::stringToJson(value);
|
2013-12-07 21:09:55 -06:00
|
|
|
// Set all values that match
|
|
|
|
|
SetJsonValue(root);
|
|
|
|
|
}
|
2019-07-03 12:58:02 -04:00
|
|
|
catch (const std::exception& e)
|
2013-12-07 21:09:55 -06:00
|
|
|
{
|
|
|
|
|
// Error parsing JSON (or missing keys)
|
2019-08-27 15:47:39 -04:00
|
|
|
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
|
2013-12-07 21:09:55 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 08:51:51 -05:00
|
|
|
// Load Json::Value into this object
|
|
|
|
|
void Clip::SetJsonValue(const Json::Value root) {
|
2013-12-06 00:40:26 -06:00
|
|
|
|
|
|
|
|
// Set parent data
|
2013-12-07 21:09:55 -06:00
|
|
|
ClipBase::SetJsonValue(root);
|
2013-12-06 00:40:26 -06:00
|
|
|
|
2020-08-26 22:47:31 -05:00
|
|
|
// Clear cache
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
cache.Clear();
|
2020-08-26 22:47:31 -05:00
|
|
|
|
2013-12-06 00:40:26 -06:00
|
|
|
// Set data from Json (if key is found)
|
2020-12-22 21:32:36 -03:00
|
|
|
if (!root["attached_id"].isNull())
|
|
|
|
|
attached_id = root["attached_id"].asString();
|
2021-01-14 15:52:49 -03:00
|
|
|
if (attached_id.size() > 0 && attached_id != "None"){
|
2020-12-22 21:32:36 -03:00
|
|
|
AttachToTracker(attached_id);
|
2021-01-14 15:52:49 -03:00
|
|
|
} else{
|
|
|
|
|
attachedObject = nullptr;
|
2020-12-22 21:32:36 -03:00
|
|
|
}
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["gravity"].isNull())
|
2013-12-06 00:40:26 -06:00
|
|
|
gravity = (GravityType) root["gravity"].asInt();
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["scale"].isNull())
|
2013-12-06 00:40:26 -06:00
|
|
|
scale = (ScaleType) root["scale"].asInt();
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["anchor"].isNull())
|
2013-12-06 00:40:26 -06:00
|
|
|
anchor = (AnchorType) root["anchor"].asInt();
|
2017-03-15 02:06:53 -05:00
|
|
|
if (!root["display"].isNull())
|
|
|
|
|
display = (FrameDisplayType) root["display"].asInt();
|
2018-06-27 01:35:38 -05:00
|
|
|
if (!root["mixing"].isNull())
|
|
|
|
|
mixing = (VolumeMixType) root["mixing"].asInt();
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["waveform"].isNull())
|
2013-12-06 00:40:26 -06:00
|
|
|
waveform = root["waveform"].asBool();
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["scale_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
scale_x.SetJsonValue(root["scale_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["scale_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
scale_y.SetJsonValue(root["scale_y"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["location_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
location_x.SetJsonValue(root["location_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["location_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
location_y.SetJsonValue(root["location_y"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["alpha"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
alpha.SetJsonValue(root["alpha"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["rotation"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
rotation.SetJsonValue(root["rotation"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["time"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
time.SetJsonValue(root["time"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["volume"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
volume.SetJsonValue(root["volume"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["wave_color"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
wave_color.SetJsonValue(root["wave_color"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["shear_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
shear_x.SetJsonValue(root["shear_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["shear_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
shear_y.SetJsonValue(root["shear_y"]);
|
2020-04-13 16:55:29 -05:00
|
|
|
if (!root["origin_x"].isNull())
|
|
|
|
|
origin_x.SetJsonValue(root["origin_x"]);
|
|
|
|
|
if (!root["origin_y"].isNull())
|
|
|
|
|
origin_y.SetJsonValue(root["origin_y"]);
|
2016-04-24 15:37:47 -05:00
|
|
|
if (!root["channel_filter"].isNull())
|
|
|
|
|
channel_filter.SetJsonValue(root["channel_filter"]);
|
|
|
|
|
if (!root["channel_mapping"].isNull())
|
|
|
|
|
channel_mapping.SetJsonValue(root["channel_mapping"]);
|
|
|
|
|
if (!root["has_audio"].isNull())
|
|
|
|
|
has_audio.SetJsonValue(root["has_audio"]);
|
|
|
|
|
if (!root["has_video"].isNull())
|
|
|
|
|
has_video.SetJsonValue(root["has_video"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c1_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c1_x.SetJsonValue(root["perspective_c1_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c1_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c1_y.SetJsonValue(root["perspective_c1_y"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c2_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c2_x.SetJsonValue(root["perspective_c2_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c2_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c2_y.SetJsonValue(root["perspective_c2_y"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c3_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c3_x.SetJsonValue(root["perspective_c3_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c3_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c3_y.SetJsonValue(root["perspective_c3_y"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c4_x"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c4_x.SetJsonValue(root["perspective_c4_x"]);
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["perspective_c4_y"].isNull())
|
2014-01-04 19:04:21 -06:00
|
|
|
perspective_c4_y.SetJsonValue(root["perspective_c4_y"]);
|
2015-03-14 01:36:13 -05:00
|
|
|
if (!root["effects"].isNull()) {
|
2015-08-06 20:01:34 -05:00
|
|
|
|
2015-03-14 01:36:13 -05:00
|
|
|
// Clear existing effects
|
|
|
|
|
effects.clear();
|
|
|
|
|
|
|
|
|
|
// loop through effects
|
2019-12-27 01:01:48 -05:00
|
|
|
for (const auto existing_effect : root["effects"]) {
|
2015-03-14 01:36:13 -05:00
|
|
|
// Create Effect
|
|
|
|
|
EffectBase *e = NULL;
|
2016-08-16 22:40:51 -05:00
|
|
|
if (!existing_effect["type"].isNull()) {
|
2015-11-09 00:12:21 -06:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Create instance of effect
|
|
|
|
|
if ( (e = EffectInfo().CreateEffect(existing_effect["type"].asString()))) {
|
|
|
|
|
|
|
|
|
|
// Load Json into Effect
|
|
|
|
|
e->SetJsonValue(existing_effect);
|
2015-08-16 22:58:07 -05:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Add Effect to Timeline
|
|
|
|
|
AddEffect(e);
|
2018-09-11 00:40:31 -05:00
|
|
|
}
|
2016-08-16 22:40:51 -05:00
|
|
|
}
|
2015-03-14 01:36:13 -05:00
|
|
|
}
|
|
|
|
|
}
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["reader"].isNull()) // does Json contain a reader?
|
2013-12-07 21:09:55 -06:00
|
|
|
{
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["reader"]["type"].isNull()) // does the reader Json contain a 'type'?
|
2013-12-07 21:09:55 -06:00
|
|
|
{
|
|
|
|
|
// Close previous reader (if any)
|
2013-12-18 21:55:43 -06:00
|
|
|
bool already_open = false;
|
2013-12-07 21:09:55 -06:00
|
|
|
if (reader)
|
2013-12-18 21:55:43 -06:00
|
|
|
{
|
|
|
|
|
// Track if reader was open
|
|
|
|
|
already_open = reader->IsOpen();
|
|
|
|
|
|
|
|
|
|
// Close and delete existing reader (if any)
|
2013-12-07 21:09:55 -06:00
|
|
|
reader->Close();
|
2013-12-18 21:55:43 -06:00
|
|
|
delete reader;
|
|
|
|
|
reader = NULL;
|
|
|
|
|
}
|
2013-12-07 21:09:55 -06:00
|
|
|
|
|
|
|
|
// Create new reader (and load properties)
|
2019-08-04 23:08:19 -04:00
|
|
|
std::string type = root["reader"]["type"].asString();
|
2013-12-07 21:09:55 -06:00
|
|
|
|
|
|
|
|
if (type == "FFmpegReader") {
|
|
|
|
|
|
|
|
|
|
// Create new reader
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::FFmpegReader(root["reader"]["path"].asString(), false);
|
2013-12-07 21:09:55 -06:00
|
|
|
reader->SetJsonValue(root["reader"]);
|
|
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
} else if (type == "QtImageReader") {
|
|
|
|
|
|
|
|
|
|
// Create new reader
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::QtImageReader(root["reader"]["path"].asString(), false);
|
2015-06-01 00:20:14 -07:00
|
|
|
reader->SetJsonValue(root["reader"]);
|
|
|
|
|
|
2016-02-23 00:27:03 -06:00
|
|
|
#ifdef USE_IMAGEMAGICK
|
2013-12-07 21:09:55 -06:00
|
|
|
} else if (type == "ImageReader") {
|
|
|
|
|
|
|
|
|
|
// Create new reader
|
2016-09-16 17:43:26 -05:00
|
|
|
reader = new ImageReader(root["reader"]["path"].asString(), false);
|
2013-12-07 21:09:55 -06:00
|
|
|
reader->SetJsonValue(root["reader"]);
|
|
|
|
|
|
|
|
|
|
} else if (type == "TextReader") {
|
|
|
|
|
|
|
|
|
|
// Create new reader
|
|
|
|
|
reader = new TextReader();
|
|
|
|
|
reader->SetJsonValue(root["reader"]);
|
2016-02-23 00:27:03 -06:00
|
|
|
#endif
|
2013-12-18 21:55:43 -06:00
|
|
|
|
|
|
|
|
} else if (type == "ChunkReader") {
|
|
|
|
|
|
|
|
|
|
// Create new reader
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::ChunkReader(root["reader"]["path"].asString(), (ChunkVersion) root["reader"]["chunk_version"].asInt());
|
2013-12-18 21:55:43 -06:00
|
|
|
reader->SetJsonValue(root["reader"]);
|
2014-01-05 22:37:11 -06:00
|
|
|
|
|
|
|
|
} else if (type == "DummyReader") {
|
|
|
|
|
|
|
|
|
|
// Create new reader
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::DummyReader();
|
2014-01-05 22:37:11 -06:00
|
|
|
reader->SetJsonValue(root["reader"]);
|
2020-03-09 16:49:06 -05:00
|
|
|
|
|
|
|
|
} else if (type == "Timeline") {
|
|
|
|
|
|
|
|
|
|
// Create new reader (always load from file again)
|
|
|
|
|
// This prevents FrameMappers from being loaded on accident
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader = new openshot::Timeline(root["reader"]["path"].asString(), true);
|
2013-12-07 21:09:55 -06:00
|
|
|
}
|
|
|
|
|
|
2019-01-19 02:18:52 -06:00
|
|
|
// mark as managed reader and set parent
|
|
|
|
|
if (reader) {
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
reader->ParentClip(this);
|
2019-05-09 10:51:40 -07:00
|
|
|
allocated_reader = reader;
|
2019-01-19 02:18:52 -06:00
|
|
|
}
|
2015-06-01 00:20:14 -07:00
|
|
|
|
2013-12-18 21:55:43 -06:00
|
|
|
// Re-Open reader (if needed)
|
|
|
|
|
if (already_open)
|
|
|
|
|
reader->Open();
|
|
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
}
|
|
|
|
|
}
|
2013-12-06 00:40:26 -06:00
|
|
|
}
|
2015-03-14 01:36:13 -05:00
|
|
|
|
|
|
|
|
// Sort effects by order
|
|
|
|
|
void Clip::sort_effects()
|
|
|
|
|
{
|
|
|
|
|
// sort clips
|
|
|
|
|
effects.sort(CompareClipEffects());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add an effect to the clip
|
|
|
|
|
void Clip::AddEffect(EffectBase* effect)
|
|
|
|
|
{
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
// Set parent clip pointer
|
|
|
|
|
effect->ParentClip(this);
|
|
|
|
|
|
2015-03-14 01:36:13 -05:00
|
|
|
// Add effect to list
|
|
|
|
|
effects.push_back(effect);
|
|
|
|
|
|
|
|
|
|
// Sort effects
|
|
|
|
|
sort_effects();
|
2020-08-26 22:47:31 -05:00
|
|
|
|
2020-12-22 21:32:36 -03:00
|
|
|
// Add Tracker to Timeline
|
|
|
|
|
if (effect->info.class_name == "Tracker"){
|
|
|
|
|
|
|
|
|
|
Timeline* parentTimeline = (Timeline *) ParentTimeline();
|
|
|
|
|
|
|
|
|
|
// Downcast effect as Tracker
|
|
|
|
|
Tracker* tracker = (Tracker *) effect;
|
|
|
|
|
|
|
|
|
|
// Get tracked data from the Tracker effect
|
|
|
|
|
std::shared_ptr<openshot::KeyFrameBBox> trackedData = tracker->trackedData;
|
|
|
|
|
|
|
|
|
|
// Add tracked data to the timeline
|
|
|
|
|
parentTimeline->AddTrackedObject(trackedData);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:47:31 -05:00
|
|
|
// Clear cache
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
cache.Clear();
|
2015-03-14 01:36:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove an effect from the clip
|
|
|
|
|
void Clip::RemoveEffect(EffectBase* effect)
|
|
|
|
|
{
|
|
|
|
|
effects.remove(effect);
|
2020-08-26 22:47:31 -05:00
|
|
|
|
|
|
|
|
// Clear cache
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
cache.Clear();
|
2015-03-14 01:36:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply effects to the source frame (if any)
|
2020-08-26 22:47:31 -05:00
|
|
|
void Clip::apply_effects(std::shared_ptr<Frame> frame)
|
2015-03-14 01:36:13 -05:00
|
|
|
{
|
|
|
|
|
// Find Effects at this position and layer
|
2019-12-27 01:01:48 -05:00
|
|
|
for (auto effect : effects)
|
2015-03-14 01:36:13 -05:00
|
|
|
{
|
|
|
|
|
// Apply the effect to this frame
|
|
|
|
|
frame = effect->GetFrame(frame, frame->number);
|
|
|
|
|
|
|
|
|
|
} // end effect loop
|
|
|
|
|
}
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Compare 2 floating point numbers for equality
|
|
|
|
|
bool Clip::isEqual(double a, double b)
|
|
|
|
|
{
|
|
|
|
|
return fabs(a - b) < 0.000001;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apply keyframes to the source frame (if any)
|
2020-08-26 22:47:31 -05:00
|
|
|
void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
|
2020-08-26 13:12:42 -05:00
|
|
|
{
|
|
|
|
|
// Get actual frame image data
|
|
|
|
|
std::shared_ptr<QImage> source_image = frame->GetImage();
|
|
|
|
|
|
|
|
|
|
/* REPLACE IMAGE WITH WAVEFORM IMAGE (IF NEEDED) */
|
|
|
|
|
if (Waveform())
|
|
|
|
|
{
|
|
|
|
|
// Debug output
|
|
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Generate Waveform Image)", "frame->number", frame->number, "Waveform()", Waveform());
|
|
|
|
|
|
|
|
|
|
// Get the color of the waveform
|
|
|
|
|
int red = wave_color.red.GetInt(frame->number);
|
|
|
|
|
int green = wave_color.green.GetInt(frame->number);
|
|
|
|
|
int blue = wave_color.blue.GetInt(frame->number);
|
|
|
|
|
int alpha = wave_color.alpha.GetInt(frame->number);
|
|
|
|
|
|
|
|
|
|
// Generate Waveform Dynamically (the size of the timeline)
|
2020-08-26 17:05:50 -05:00
|
|
|
source_image = frame->GetWaveform(width, height, red, green, blue, alpha);
|
2020-08-26 13:12:42 -05:00
|
|
|
frame->AddImage(std::shared_ptr<QImage>(source_image));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ALPHA & OPACITY */
|
|
|
|
|
if (alpha.GetValue(frame->number) != 1.0)
|
|
|
|
|
{
|
|
|
|
|
float alpha_value = alpha.GetValue(frame->number);
|
|
|
|
|
|
|
|
|
|
// Get source image's pixels
|
2020-10-16 18:04:10 -05:00
|
|
|
unsigned char *pixels = source_image->bits();
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Loop through pixels
|
|
|
|
|
for (int pixel = 0, byte_index=0; pixel < source_image->width() * source_image->height(); pixel++, byte_index+=4)
|
|
|
|
|
{
|
2020-10-14 14:19:26 -05:00
|
|
|
// Apply alpha to pixel values (since we use a premultiplied value, we must
|
|
|
|
|
// multiply the alpha with all colors).
|
|
|
|
|
pixels[byte_index + 0] *= alpha_value;
|
|
|
|
|
pixels[byte_index + 1] *= alpha_value;
|
|
|
|
|
pixels[byte_index + 2] *= alpha_value;
|
2020-08-26 13:12:42 -05:00
|
|
|
pixels[byte_index + 3] *= alpha_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug output
|
|
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Set Alpha & Opacity)", "alpha_value", alpha_value, "frame->number", frame->number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* RESIZE SOURCE IMAGE - based on scale type */
|
|
|
|
|
QSize source_size = source_image->size();
|
|
|
|
|
switch (scale)
|
|
|
|
|
{
|
|
|
|
|
case (SCALE_FIT): {
|
2020-08-26 17:05:50 -05:00
|
|
|
source_size.scale(width, height, Qt::KeepAspectRatio);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Debug output
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Scale: SCALE_FIT)", "frame->number", frame->number, "source_width", source_size.width(), "source_height", source_size.height());
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case (SCALE_STRETCH): {
|
2020-08-26 17:05:50 -05:00
|
|
|
source_size.scale(width, height, Qt::IgnoreAspectRatio);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Debug output
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Scale: SCALE_STRETCH)", "frame->number", frame->number, "source_width", source_size.width(), "source_height", source_size.height());
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case (SCALE_CROP): {
|
2020-10-20 12:42:00 -05:00
|
|
|
source_size.scale(width, height, Qt::KeepAspectRatioByExpanding);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Debug output
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Scale: SCALE_CROP)", "frame->number", frame->number, "source_width", source_size.width(), "source_height", source_size.height());
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case (SCALE_NONE): {
|
|
|
|
|
// Calculate ratio of source size to project size
|
|
|
|
|
// Even with no scaling, previews need to be adjusted correctly
|
|
|
|
|
// (otherwise NONE scaling draws the frame image outside of the preview)
|
2020-08-26 17:05:50 -05:00
|
|
|
float source_width_ratio = source_size.width() / float(width);
|
|
|
|
|
float source_height_ratio = source_size.height() / float(height);
|
|
|
|
|
source_size.scale(width * source_width_ratio, height * source_height_ratio, Qt::KeepAspectRatio);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Debug output
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Scale: SCALE_NONE)", "frame->number", frame->number, "source_width", source_size.width(), "source_height", source_size.height());
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-14 16:03:22 -03:00
|
|
|
|
|
|
|
|
// Initialize bounding-box values
|
|
|
|
|
float box_cx = 0.0;
|
|
|
|
|
float box_cy = 0.0;
|
|
|
|
|
float box_sx = 0.0;
|
|
|
|
|
float box_sy = 0.0;
|
|
|
|
|
float box_r = 0.0;
|
2020-08-26 13:12:42 -05:00
|
|
|
|
2020-12-22 21:32:36 -03:00
|
|
|
/* TRANSFORM CLIP TO ATTACHED OBJECT'S POSITION AND DIMENSION */
|
|
|
|
|
if (attachedObject){
|
2021-01-14 16:03:22 -03:00
|
|
|
// Convert Clip's frame position to Timeline's frame position
|
|
|
|
|
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
|
|
|
|
|
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
|
|
|
|
|
double timeline_frame_number = frame->number + clip_start_position - clip_start_frame;
|
2020-12-22 21:32:36 -03:00
|
|
|
|
2021-01-14 16:03:22 -03:00
|
|
|
// Access the KeyframeBBox properties
|
|
|
|
|
std::map<std::string, float> boxValues = attachedObject->GetBoxValues(timeline_frame_number);
|
|
|
|
|
|
|
|
|
|
// Get the bounding-box values and correct them by the clip's reference system
|
|
|
|
|
box_cx = boxValues["cx"] - 0.5;
|
|
|
|
|
box_cy = boxValues["cy"] - 0.5;
|
|
|
|
|
box_sx = boxValues["w"]*boxValues["sx"]*2.0;
|
|
|
|
|
box_sy = boxValues["h"]*boxValues["sy"];
|
|
|
|
|
box_r = boxValues["r"];
|
2020-12-22 21:32:36 -03:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 13:12:42 -05:00
|
|
|
/* GRAVITY LOCATION - Initialize X & Y to the correct values (before applying location curves) */
|
|
|
|
|
float x = 0.0; // left
|
|
|
|
|
float y = 0.0; // top
|
|
|
|
|
|
|
|
|
|
// Adjust size for scale x and scale y
|
|
|
|
|
float sx = scale_x.GetValue(frame->number); // percentage X scale
|
|
|
|
|
float sy = scale_y.GetValue(frame->number); // percentage Y scale
|
2021-01-14 16:03:22 -03:00
|
|
|
// Change clip's scale to bounding-box scale
|
|
|
|
|
if(box_sx > 0.0 && box_sy > 0.0){
|
|
|
|
|
sx = box_sx;
|
|
|
|
|
sy = box_sy;
|
|
|
|
|
}
|
2020-08-26 13:12:42 -05:00
|
|
|
float scaled_source_width = source_size.width() * sx;
|
|
|
|
|
float scaled_source_height = source_size.height() * sy;
|
2021-01-14 16:03:22 -03:00
|
|
|
|
2020-08-26 13:12:42 -05:00
|
|
|
switch (gravity)
|
|
|
|
|
{
|
|
|
|
|
case (GRAVITY_TOP_LEFT):
|
|
|
|
|
// This is only here to prevent unused-enum warnings
|
|
|
|
|
break;
|
|
|
|
|
case (GRAVITY_TOP):
|
2020-08-26 17:05:50 -05:00
|
|
|
x = (width - scaled_source_width) / 2.0; // center
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_TOP_RIGHT):
|
2020-08-26 17:05:50 -05:00
|
|
|
x = width - scaled_source_width; // right
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_LEFT):
|
2020-08-26 17:05:50 -05:00
|
|
|
y = (height - scaled_source_height) / 2.0; // center
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_CENTER):
|
2020-08-26 17:05:50 -05:00
|
|
|
x = (width - scaled_source_width) / 2.0; // center
|
|
|
|
|
y = (height - scaled_source_height) / 2.0; // center
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_RIGHT):
|
2020-08-26 17:05:50 -05:00
|
|
|
x = width - scaled_source_width; // right
|
|
|
|
|
y = (height - scaled_source_height) / 2.0; // center
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_BOTTOM_LEFT):
|
2020-08-26 17:05:50 -05:00
|
|
|
y = (height - scaled_source_height); // bottom
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_BOTTOM):
|
2020-08-26 17:05:50 -05:00
|
|
|
x = (width - scaled_source_width) / 2.0; // center
|
|
|
|
|
y = (height - scaled_source_height); // bottom
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
case (GRAVITY_BOTTOM_RIGHT):
|
2020-08-26 17:05:50 -05:00
|
|
|
x = width - scaled_source_width; // right
|
|
|
|
|
y = (height - scaled_source_height); // bottom
|
2020-08-26 13:12:42 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug output
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Gravity)", "frame->number", frame->number, "source_clip->gravity", gravity, "scaled_source_width", scaled_source_width, "scaled_source_height", scaled_source_height);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
2020-12-22 21:32:36 -03:00
|
|
|
QTransform transform;
|
|
|
|
|
|
2020-08-26 13:12:42 -05:00
|
|
|
/* LOCATION, ROTATION, AND SCALE */
|
2021-01-14 16:03:22 -03:00
|
|
|
float r = rotation.GetValue(frame->number) + box_r; // rotate in degrees
|
|
|
|
|
x += (width * (location_x.GetValue(frame->number) + box_cx)); // move in percentage of final width
|
|
|
|
|
y += (height * (location_y.GetValue(frame->number) + box_cy)); // move in percentage of final height
|
2020-08-26 13:12:42 -05:00
|
|
|
float shear_x_value = shear_x.GetValue(frame->number);
|
|
|
|
|
float shear_y_value = shear_y.GetValue(frame->number);
|
|
|
|
|
float origin_x_value = origin_x.GetValue(frame->number);
|
|
|
|
|
float origin_y_value = origin_y.GetValue(frame->number);
|
|
|
|
|
|
|
|
|
|
// Transform source image (if needed)
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Build QTransform - if needed)", "frame->number", frame->number, "x", x, "y", y, "r", r, "sx", sx, "sy", sy);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
if (!isEqual(x, 0) || !isEqual(y, 0)) {
|
|
|
|
|
// TRANSLATE/MOVE CLIP
|
|
|
|
|
transform.translate(x, y);
|
2020-12-22 21:32:36 -03:00
|
|
|
}
|
2020-08-26 13:12:42 -05:00
|
|
|
if (!isEqual(r, 0) || !isEqual(shear_x_value, 0) || !isEqual(shear_y_value, 0)) {
|
|
|
|
|
// ROTATE CLIP (around origin_x, origin_y)
|
|
|
|
|
float origin_x_offset = (scaled_source_width * origin_x_value);
|
|
|
|
|
float origin_y_offset = (scaled_source_height * origin_y_value);
|
|
|
|
|
transform.translate(origin_x_offset, origin_y_offset);
|
|
|
|
|
transform.rotate(r);
|
|
|
|
|
transform.shear(shear_x_value, shear_y_value);
|
|
|
|
|
transform.translate(-origin_x_offset,-origin_y_offset);
|
|
|
|
|
}
|
|
|
|
|
// SCALE CLIP (if needed)
|
|
|
|
|
float source_width_scale = (float(source_size.width()) / float(source_image->width())) * sx;
|
|
|
|
|
float source_height_scale = (float(source_size.height()) / float(source_image->height())) * sy;
|
|
|
|
|
if (!isEqual(source_width_scale, 1.0) || !isEqual(source_height_scale, 1.0)) {
|
|
|
|
|
transform.scale(source_width_scale, source_height_scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug output
|
2020-10-20 13:03:10 -05:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Transform: Composite Image Layer: Prepare)", "frame->number", frame->number);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
/* COMPOSITE SOURCE IMAGE (LAYER) ONTO FINAL IMAGE */
|
2020-10-20 12:42:00 -05:00
|
|
|
auto new_image = std::make_shared<QImage>(QSize(width, height), source_image->format());
|
2020-08-26 13:12:42 -05:00
|
|
|
new_image->fill(QColor(QString::fromStdString("#00000000")));
|
|
|
|
|
|
|
|
|
|
// Load timeline's new frame image into a QPainter
|
|
|
|
|
QPainter painter(new_image.get());
|
|
|
|
|
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);
|
|
|
|
|
|
2020-10-20 13:03:10 -05:00
|
|
|
// Apply transform (translate, rotate, scale)
|
|
|
|
|
painter.setTransform(transform);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
|
|
|
|
// Composite a new layer onto the image
|
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
2020-08-26 22:47:31 -05:00
|
|
|
painter.drawImage(0, 0, *source_image);
|
2020-08-26 13:12:42 -05:00
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
if (timeline) {
|
|
|
|
|
Timeline *t = (Timeline *) timeline;
|
2020-08-26 13:12:42 -05:00
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
// Draw frame #'s on top of image (if needed)
|
|
|
|
|
if (display != FRAME_DISPLAY_NONE) {
|
|
|
|
|
std::stringstream frame_number_str;
|
|
|
|
|
switch (display) {
|
|
|
|
|
case (FRAME_DISPLAY_NONE):
|
|
|
|
|
// This is only here to prevent unused-enum warnings
|
|
|
|
|
break;
|
2020-08-26 13:12:42 -05:00
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
case (FRAME_DISPLAY_CLIP):
|
|
|
|
|
frame_number_str << frame->number;
|
|
|
|
|
break;
|
2020-08-26 13:12:42 -05:00
|
|
|
|
Large refactor of Timeline, TimelineBase, ClipBase, and Clip, to allow a Clip access to the parent timeline instance (if available), and thus, certain properties (preview size, timeline FPS, etc...). This allows for a simpler rendering of Clip keyframes (during the Clip::GetFrame method), and a simpler Timeline class, that can change the preview window size dynamically and no longer requires a Singleton Settings class.
- Also removed "crop" from Clip class, as it was never implmeneted correctly, and we have a fully functional "crop" effect when needed
- Added caching to Clip class, to optimize previewing of cached frames (much faster than previous)
2020-10-04 16:59:21 -05:00
|
|
|
case (FRAME_DISPLAY_TIMELINE):
|
|
|
|
|
frame_number_str << (position * t->info.fps.ToFloat()) + frame->number;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (FRAME_DISPLAY_BOTH):
|
|
|
|
|
frame_number_str << (position * t->info.fps.ToFloat()) + frame->number << " (" << frame->number << ")";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw frame number on top of image
|
|
|
|
|
painter.setPen(QColor("#ffffff"));
|
|
|
|
|
painter.drawText(20, 20, QString(frame_number_str.str().c_str()));
|
2020-08-26 13:12:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter.end();
|
|
|
|
|
|
|
|
|
|
// Add new QImage to frame
|
|
|
|
|
frame->AddImage(new_image);
|
2015-03-14 01:36:13 -05:00
|
|
|
}
|