2012-10-03 01:55:24 -05:00
|
|
|
#include "../include/Timeline.h"
|
|
|
|
|
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
|
|
|
|
// Default Constructor for the timeline (which sets the canvas width and height)
|
2012-10-05 17:05:33 -05:00
|
|
|
Timeline::Timeline(int width, int height, Framerate fps) :
|
|
|
|
|
width(width), height(height), fps(fps)
|
2012-10-03 01:55:24 -05:00
|
|
|
{
|
|
|
|
|
// Init viewport size (curve based, because it can be animated)
|
|
|
|
|
viewport_scale = Keyframe(100.0);
|
|
|
|
|
viewport_x = Keyframe(0.0);
|
|
|
|
|
viewport_y = Keyframe(0.0);
|
2012-10-05 01:58:27 -05:00
|
|
|
}
|
|
|
|
|
|
2012-10-05 17:05:33 -05:00
|
|
|
// Add an openshot::Clip to the timeline
|
|
|
|
|
void Timeline::AddClip(Clip* clip)
|
|
|
|
|
{
|
|
|
|
|
// Add clip to list
|
|
|
|
|
clips.push_back(clip);
|
|
|
|
|
|
|
|
|
|
// Sort clips
|
|
|
|
|
SortClips();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate time of a frame number, based on a framerate
|
|
|
|
|
float Timeline::calculate_time(int number, Framerate rate)
|
|
|
|
|
{
|
|
|
|
|
// Get float version of fps fraction
|
|
|
|
|
float raw_fps = rate.GetFPS();
|
|
|
|
|
|
|
|
|
|
// Return the time (in seconds) of this frame
|
|
|
|
|
return float(number - 1) / raw_fps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort clips by position on the timeline
|
|
|
|
|
void Timeline::SortClips()
|
|
|
|
|
{
|
|
|
|
|
// sort clips
|
|
|
|
|
clips.sort(compare_clip_pointers());
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 16:22:18 -05:00
|
|
|
// Close the reader (and any resources it was consuming)
|
|
|
|
|
void Timeline::Close()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open the reader (and start consuming resources)
|
|
|
|
|
void Timeline::Open()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 01:58:27 -05:00
|
|
|
// Get an openshot::Frame object for a specific frame number of this reader.
|
2012-10-09 01:45:34 -05:00
|
|
|
Frame* Timeline::GetFrame(int requested_frame) throw(ReaderClosed)
|
2012-10-05 01:58:27 -05:00
|
|
|
{
|
2012-10-05 17:05:33 -05:00
|
|
|
// Adjust out of bounds frame number
|
|
|
|
|
if (requested_frame < 1)
|
|
|
|
|
requested_frame = 1;
|
|
|
|
|
|
|
|
|
|
// Calculate time of frame
|
|
|
|
|
float requested_time = calculate_time(requested_frame, fps);
|
|
|
|
|
|
|
|
|
|
// Find Clips at this time
|
|
|
|
|
list<Clip*>::iterator clip_itr;
|
|
|
|
|
for (clip_itr=clips.begin(); clip_itr != clips.end(); ++clip_itr)
|
|
|
|
|
{
|
|
|
|
|
// Get clip object from the iterator
|
|
|
|
|
Clip *clip = (*clip_itr);
|
|
|
|
|
|
|
|
|
|
cout << clip->Position() << endl;
|
|
|
|
|
}
|
2012-10-03 01:55:24 -05:00
|
|
|
|
|
|
|
|
}
|