preliminary support for multiple timeline sections

This commit is contained in:
itsmattkc
2019-10-05 07:33:27 +10:00
parent ea4f6f43c4
commit 3411e45774
26 changed files with 897 additions and 363 deletions
+5 -3
View File
@@ -20,8 +20,6 @@
#include "graph.h"
#include "common/qobjectlistcast.h"
NodeGraph::NodeGraph()
{
@@ -38,6 +36,8 @@ void NodeGraph::AddNode(Node *node)
connect(node, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
connect(node, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
node_children_.append(node);
emit NodeAdded(node);
}
@@ -71,6 +71,8 @@ void NodeGraph::TakeNode(Node *node, QObject* new_parent)
node->setParent(new_parent);
node_children_.removeAll(node);
emit NodeRemoved(node);
}
@@ -91,7 +93,7 @@ QList<Node *> NodeGraph::TakeNodeWithItsDependencies(Node *node, QObject *new_pa
QList<Node *> NodeGraph::nodes()
{
return static_qobjectlist_cast<Node>(children());
return node_children_;
}
bool NodeGraph::ContainsNode(Node *n)
+1
View File
@@ -107,6 +107,7 @@ signals:
void EdgeRemoved(NodeEdgePtr edge);
private:
QList<Node*> node_children_;
};
#endif // NODEGRAPH_H
+17 -43
View File
@@ -22,8 +22,6 @@
#include <QDebug>
#include "common/qobjectlistcast.h"
Node::Node() :
last_processed_time_(-1),
can_be_deleted_(true)
@@ -56,6 +54,7 @@ void Node::AddParameter(NodeParam *param)
Q_ASSERT(!HasParamWithID(param->id()));
param->setParent(this);
params_.append(param);
connect(param, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
connect(param, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
@@ -69,6 +68,7 @@ void Node::AddParameter(NodeParam *param)
void Node::RemoveParameter(NodeParam *param)
{
params_.removeAll(param);
delete param;
}
@@ -83,10 +83,8 @@ void Node::InvalidateCache(const rational &start_range, const rational &end_rang
void Node::SendInvalidateCache(const rational &start_range, const rational &end_range)
{
QList<NodeParam *> params = parameters();
// Loop through all parameters (there should be no children that are not NodeParams)
foreach (NodeParam* param, params) {
foreach (NodeParam* param, params_) {
// If the Node is an output, relay the signal to any Nodes that are connected to it
if (param->type() == NodeParam::kOutput) {
@@ -117,8 +115,8 @@ void Node::CopyInputs(Node *source, Node *destination)
{
Q_ASSERT(source->id() == destination->id());
QList<NodeParam*> src_param = source->parameters();
QList<NodeParam*> dst_param = destination->parameters();
const QList<NodeParam*>& src_param = source->params_;
const QList<NodeParam*>& dst_param = destination->params_;
for (int i=0;i<src_param.size();i++) {
if (src_param.at(i)->type() == NodeParam::kInput) {
@@ -174,10 +172,8 @@ void Node::ClearCachedValuesInParameters(const rational &start_range, const rati
Q_UNUSED(start_range)
Q_UNUSED(end_range)
QList<NodeParam *> params = parameters();
// Loop through all parameters and clear cached values
foreach (NodeParam* param, params) {
foreach (NodeParam* param, params_) {
//if (param->LastRequestedTime() >= start_range && param->LastRequestedTime() <= end_range) {
param->ClearCachedValue();
//}
@@ -195,19 +191,9 @@ QVariant Node::Run(NodeOutput* output, const rational& time)
return v;
}
NodeParam *Node::ParamAt(int index)
const QList<NodeParam *>& Node::parameters()
{
return static_cast<NodeParam*>(children().at(index));
}
QList<NodeParam *> Node::parameters()
{
return static_qobjectlist_cast<NodeParam>(children());
}
int Node::ParameterCount()
{
return children().size();
return params_;
}
int Node::IndexOfParameter(NodeParam *param)
@@ -224,9 +210,7 @@ int Node::IndexOfParameter(NodeParam *param)
* dependencies.
*/
void GetDependenciesInternal(Node* n, QList<Node*>& list, bool traverse) {
QList<NodeParam*> params = n->parameters();
foreach (NodeParam* p, params) {
foreach (NodeParam* p, n->parameters()) {
if (p->type() == NodeParam::kInput) {
Node* connected = static_cast<NodeInput*>(p)->get_connected_node();
@@ -256,7 +240,7 @@ QList<Node *> Node::GetExclusiveDependencies()
// Filter out any dependencies that are used elsewhere
for (int i=0;i<deps.size();i++) {
QList<NodeParam*> params = deps.at(i)->parameters();
QList<NodeParam*> params = deps.at(i)->params_;
// See if any of this Node's outputs are used outside of this dep list
for (int j=0;j<params.size();j++) {
@@ -298,10 +282,9 @@ QList<NodeDependency> Node::RunDependencies(NodeOutput *output, const rational &
{
Q_UNUSED(output)
QList<NodeParam*> params = parameters();
QList<NodeDependency> run_deps;
foreach (NodeParam* p, params) {
foreach (NodeParam* p, params_) {
if (p->type() == NodeParam::kInput) {
NodeInput* input = static_cast<NodeInput*>(p);
@@ -321,9 +304,7 @@ QList<NodeDependency> Node::RunDependencies(NodeOutput *output, const rational &
bool Node::OutputsTo(Node *n)
{
QList<NodeParam*> params = parameters();
foreach (NodeParam* param, params) {
foreach (NodeParam* param, params_) {
if (param->type() == NodeParam::kOutput) {
QVector<NodeEdgePtr> edges = param->edges();
@@ -360,10 +341,8 @@ bool Node::HasConnectedOutputs()
void Node::DisconnectAll()
{
QList<NodeParam*> param = parameters();
for (int i=0;i<param.size();i++) {
param.at(i)->DisconnectAll();
foreach (NodeParam* param, params_) {
param->DisconnectAll();
}
}
@@ -373,8 +352,7 @@ void Node::Hash(QCryptographicHash *hash, NodeOutput* from, const rational &time
hash->addData(id().toUtf8());
// Add each value
QList<NodeParam*> params = parameters();
foreach (NodeParam* param, params) {
foreach (NodeParam* param, params_) {
if (param->type() == NodeParam::kInput
&& !param->IsConnected()
&& static_cast<NodeInput*>(param)->dependent()) {
@@ -400,9 +378,7 @@ QVariant Node::PtrToValue(void *ptr)
bool Node::HasParamWithID(const QString &id)
{
QList<NodeParam*> params = parameters();
foreach (NodeParam* p, params)
foreach (NodeParam* p, params_)
{
if (p->id() == id)
{
@@ -415,9 +391,7 @@ bool Node::HasParamWithID(const QString &id)
bool Node::HasParamOfType(NodeParam::Type type, bool must_be_connected)
{
QList<NodeParam*> params = parameters();
foreach (NodeParam* p, params) {
foreach (NodeParam* p, params_) {
if (p->type() == type
&& (p->IsConnected() || !must_be_connected)) {
return true;
+3 -11
View File
@@ -95,20 +95,10 @@ public:
*/
virtual void Retranslate();
/**
* @brief Return the parameter at a given index
*/
NodeParam* ParamAt(int index);
/**
* @brief Return a list of NodeParams
*/
QList<NodeParam*> parameters();
/**
* @brief Return the current number of parameters
*/
int ParameterCount();
const QList<NodeParam*>& parameters();
/**
* @brief Return the index of a parameter
@@ -307,6 +297,8 @@ private:
bool HasParamOfType(NodeParam::Type type, bool must_be_connected);
QList<NodeParam *> params_;
/**
* @brief The last timecode Process() was called with
*/
+2
View File
@@ -18,5 +18,7 @@ set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/output/timeline/timeline.h
node/output/timeline/timeline.cpp
node/output/timeline/tracklist.h
node/output/timeline/tracklist.cpp
PARENT_SCOPE
)
+35 -187
View File
@@ -22,27 +22,31 @@
#include <QDebug>
#include "node/blend/alphaover/alphaover.h"
#include "node/block/gap/gap.h"
#include "node/graph.h"
#include "panel/timeline/timeline.h"
TimelineOutput::TimelineOutput()
{
video_track_input_ = new NodeInput("video_track_in");
video_track_input_->add_data_input(NodeParam::kTrack);
AddParameter(video_track_input_);
// Create TrackList instances
track_inputs_.resize(kTrackTypeCount);
track_lists_.resize(kTrackTypeCount);
audio_track_input_ = new NodeInput("audio_track_in");
audio_track_input_->add_data_input(NodeParam::kTrack);
AddParameter(audio_track_input_);
for (int i=0;i<kTrackTypeCount;i++) {
// Create track input
NodeInput* track_input = new NodeInput(QString("track_in_%1").arg(i));
track_input->add_data_input(NodeParam::kTrack);
AddParameter(track_input);
track_inputs_[i] = track_input;
TrackList* list = new TrackList(this, track_input);
track_lists_[i] = list;
connect(list, SIGNAL(TrackListChanged()), this, SLOT(UpdateTrackCache()));
}
length_output_ = new NodeOutput("length_out");
length_output_->set_data_type(NodeParam::kRational);
AddParameter(length_output_);
connect(this, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackConnectionAdded(NodeEdgePtr)));
connect(this, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackConnectionRemoved(NodeEdgePtr)));
}
QString TimelineOutput::Name()
@@ -65,14 +69,9 @@ QString TimelineOutput::Description()
return tr("Node for communicating between a Timeline panel and the node graph.");
}
const rational &TimelineOutput::Timebase()
QVector<TrackOutput *> TimelineOutput::Tracks()
{
return timebase_;
}
NodeInput *TimelineOutput::track_input()
{
return video_track_input_;
return track_cache_;
}
NodeOutput *TimelineOutput::length_output()
@@ -80,201 +79,50 @@ NodeOutput *TimelineOutput::length_output()
return length_output_;
}
const QVector<TrackOutput *> &TimelineOutput::Tracks()
{
return track_cache_;
}
TrackOutput *TimelineOutput::TrackAt(int index)
{
return track_cache_.at(index);
}
QVariant TimelineOutput::Value(NodeOutput *output, const rational &time)
{
if (output == length_output_) {
Q_UNUSED(time)
return QVariant::fromValue(TimelineLength());
return QVariant::fromValue(timeline_length());
}
return 0;
}
rational TimelineOutput::TimelineLength()
void TimelineOutput::UpdateTrackCache()
{
track_cache_.clear();
foreach (TrackList* list, track_lists_) {
track_cache_.append(list->Tracks());
}
}
rational TimelineOutput::timeline_length()
{
rational length = 0;
foreach (TrackOutput* track, track_cache_) {
length = qMax(length, track->in());
foreach (TrackList* list, track_lists_) {
length = qMax(list->TrackListLength(), length);
}
return length;
}
TrackOutput *TimelineOutput::attached_track()
{
return ValueToPtr<TrackOutput>(video_track_input_->get_value(0));
}
void TimelineOutput::AttachTrack(TrackOutput *track)
{
TrackOutput* current_track = track;
// Traverse through Tracks caching and connecting them
while (current_track != nullptr) {
connect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr)));
connect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr)));
connect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
connect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
current_track->SetIndex(track_cache_.size());
track_cache_.append(current_track);
// This function must be called after the track is added to track_cache_, since it uses track_cache_ to determine
// the track's index
emit TrackAdded(current_track);
current_track = current_track->next_track();
}
}
void TimelineOutput::DetachTrack(TrackOutput *track)
{
TrackOutput* current_track = track;
// Traverse through Tracks uncaching and disconnecting them
while (current_track != nullptr) {
emit TrackRemoved(current_track);
current_track->SetIndex(-1);
disconnect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr)));
disconnect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr)));
disconnect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
disconnect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
track_cache_.removeAll(current_track);
current_track = current_track->next_track();
}
}
void TimelineOutput::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
emit TimebaseChanged(timebase_);
}
void TimelineOutput::AddTrack()
{
TrackOutput* track = new TrackOutput();
static_cast<NodeGraph*>(parent())->AddNode(track);
if (track_cache_.isEmpty()) {
// Connect this track directly to this output
NodeParam::ConnectEdge(track->track_output(), track_input());
} else {
TrackOutput* current_last_track = track_cache_.last();
// Connect this track to the current last track
NodeParam::ConnectEdge(track->track_output(), current_last_track->track_input());
// FIXME: Test code only
AlphaOverBlend* blend = new AlphaOverBlend();
static_cast<NodeGraph*>(parent())->AddNode(blend);
NodeParam::ConnectEdge(track->texture_output(), blend->blend_input());
NodeParam::ConnectEdge(current_last_track->texture_output(), blend->base_input());
NodeParam::ConnectEdge(blend->texture_output(), current_last_track->texture_output()->edges().first()->input());
// End test code
foreach (TrackList* list, track_lists_) {
list->SetTimebase(timebase);
}
}
void TimelineOutput::RemoveTrack()
NodeInput *TimelineOutput::track_input(TimelineOutput::TrackType type)
{
if (track_cache_.isEmpty()) {
return;
}
TrackOutput* track = track_cache_.last();
static_cast<NodeGraph*>(parent())->TakeNode(track);
delete track;
return track_inputs_.at(type);
}
TrackOutput *TimelineOutput::TrackFromBlock(Block *block)
TrackList *TimelineOutput::track_list(TimelineOutput::TrackType type)
{
Block* n = block;
// Find last valid block in Sequence and assume its a track
while (n->next() != nullptr) {
n = n->next();
}
// Downside of this approach is the usage of dynamic_cast, alternative would be looping through all known tracks and
// seeing if the contain the Block, but this seems slower
return dynamic_cast<TrackOutput*>(n);
}
void TimelineOutput::TrackConnectionAdded(NodeEdgePtr edge)
{
if (edge->input() != track_input()) {
return;
}
AttachTrack(attached_track());
// FIXME: Is this necessary?
emit TimebaseChanged(timebase_);
}
void TimelineOutput::TrackConnectionRemoved(NodeEdgePtr edge)
{
if (edge->input() != track_input()) {
return;
}
DetachTrack(ValueToPtr<TrackOutput>(edge->output()->get_value(0)));
emit TimelineCleared();
}
void TimelineOutput::TrackAddedBlock(Block *block)
{
emit BlockAdded(block, static_cast<TrackOutput*>(sender())->Index());
}
void TimelineOutput::TrackRemovedBlock(Block *block)
{
emit BlockRemoved(block);
}
void TimelineOutput::TrackEdgeAdded(NodeEdgePtr edge)
{
// Assume this signal was sent from a TrackOutput
TrackOutput* track = static_cast<TrackOutput*>(sender());
// If this edge pertains to the track's track input, all the tracks just added need attaching
if (edge->input() == track->track_input()) {
TrackOutput* added_track = ValueToPtr<TrackOutput>(edge->output()->get_value(0));
AttachTrack(added_track);
}
}
void TimelineOutput::TrackEdgeRemoved(NodeEdgePtr edge)
{
// Assume this signal was sent from a TrackOutput
TrackOutput* track = static_cast<TrackOutput*>(sender());
// If this edge pertains to the track's track input, all the tracks just added need attaching
if (edge->input() == track->track_input()) {
TrackOutput* added_track = ValueToPtr<TrackOutput>(edge->output()->get_value(0));
DetachTrack(added_track);
}
return track_lists_.at(type);
}
+17 -71
View File
@@ -24,6 +24,7 @@
#include "common/timelinecommon.h"
#include "node/block/block.h"
#include "node/output/track/track.h"
#include "tracklist.h"
/**
* @brief Node that represents the end of the Timeline as well as a time traversal Node
@@ -33,9 +34,11 @@ class TimelineOutput : public Node
Q_OBJECT
public:
enum TrackType {
kVideo,
kAudio,
kSubtitle
kTrackTypeNone = -1,
kTrackTypeVideo,
kTrackTypeAudio,
kTrackTypeSubtitle,
kTrackTypeCount
};
TimelineOutput();
@@ -45,91 +48,34 @@ public:
virtual QString Category() override;
virtual QString Description() override;
const rational& Timebase();
void SetTimebase(const rational& timebase);
QVector<TrackOutput*> Tracks();
NodeInput* track_input();
NodeInput* track_input(TrackType type);
TrackList* track_list(TrackType type);
NodeOutput* length_output();
const QVector<TrackOutput*>& Tracks();
rational timeline_length();
TrackOutput* TrackAt(int index);
void AddTrack();
void RemoveTrack();
rational TimelineLength();
public slots:
/**
* @brief Slot for when the track connection is added
*/
void TrackConnectionAdded(NodeEdgePtr edge);
/**
* @brief Slot for when the track connection is removed
*/
void TrackConnectionRemoved(NodeEdgePtr edge);
/**
* @brief Slot for when a connected Track has added a Block so we can update the UI
*/
void TrackAddedBlock(Block* block);
/**
* @brief Slot for when a connected Track has added a Block so we can update the UI
*/
void TrackRemovedBlock(Block* block);
/**
* @brief Slot for when an attached Track has an edge added
*/
void TrackEdgeAdded(NodeEdgePtr edge);
/**
* @brief Slot for when an attached Track has an edge added
*/
void TrackEdgeRemoved(NodeEdgePtr edge);
void SetTimebase(const rational &timebase);
signals:
void TimebaseChanged(const rational &timebase);
void TimelineCleared();
void BlockAdded(Block* block, int index);
void BlockRemoved(Block* block);
void TrackAdded(TrackOutput* track);
void TrackRemoved(TrackOutput* track);
protected:
virtual QVariant Value(NodeOutput* output, const rational& time) override;
private:
TrackOutput* attached_track();
QVector<NodeInput*> track_inputs_;
void AttachTrack(TrackOutput *track);
QVector<TrackList*> track_lists_;
void DetachTrack(TrackOutput* track);
static TrackOutput* TrackFromBlock(Block* block);
NodeInput* video_track_input_;
NodeInput* audio_track_input_;
QVector<TrackOutput*> track_cache_;
NodeOutput* length_output_;
/**
* @brief A cache of connected Tracks
*/
QVector<TrackOutput*> track_cache_;
rational timebase_;
private slots:
void UpdateTrackCache();
};
+219
View File
@@ -0,0 +1,219 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "tracklist.h"
#include "node/blend/alphaover/alphaover.h"
#include "node/graph.h"
#include "timeline.h"
TrackList::TrackList(TimelineOutput* parent, NodeInput *track_input) :
QObject(parent),
track_input_(track_input)
{
connect(parent, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackConnectionAdded(NodeEdgePtr)));
connect(parent, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackConnectionRemoved(NodeEdgePtr)));
}
TrackOutput *TrackList::attached_track()
{
return Node::ValueToPtr<TrackOutput>(track_input_->get_value(0));
}
void TrackList::AttachTrack(TrackOutput *track)
{
TrackOutput* current_track = track;
// Traverse through Tracks caching and connecting them
while (current_track != nullptr) {
connect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr)));
connect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr)));
connect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
connect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
current_track->SetIndex(track_cache_.size());
track_cache_.append(current_track);
emit TrackListChanged();
// This function must be called after the track is added to track_cache_, since it uses track_cache_ to determine
// the track's index
emit TrackAdded(current_track);
current_track = current_track->next_track();
}
}
void TrackList::DetachTrack(TrackOutput *track)
{
TrackOutput* current_track = track;
// Traverse through Tracks uncaching and disconnecting them
while (current_track != nullptr) {
emit TrackRemoved(current_track);
current_track->SetIndex(-1);
disconnect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr)));
disconnect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr)));
disconnect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
disconnect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
track_cache_.removeAll(current_track);
emit TrackListChanged();
current_track = current_track->next_track();
}
}
void TrackList::TrackAddedBlock(Block *block)
{
emit BlockAdded(block, static_cast<TrackOutput*>(sender())->Index());
}
void TrackList::TrackRemovedBlock(Block *block)
{
emit BlockRemoved(block);
}
const QVector<TrackOutput *> &TrackList::Tracks()
{
return track_cache_;
}
TrackOutput *TrackList::TrackAt(int index)
{
return track_cache_.at(index);
}
rational TrackList::TrackListLength()
{
rational length = 0;
foreach (TrackOutput* track, track_cache_) {
length = qMax(length, track->in());
}
return length;
}
rational TrackList::TimelineLength()
{
return static_cast<TimelineOutput*>(parent())->timeline_length();
}
const rational &TrackList::Timebase()
{
return timebase_;
}
void TrackList::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
emit TimebaseChanged(timebase_);
}
void TrackList::AddTrack()
{
TrackOutput* track = new TrackOutput();
static_cast<NodeGraph*>(parent())->AddNode(track);
if (track_cache_.isEmpty()) {
// Connect this track directly to this output
NodeParam::ConnectEdge(track->track_output(), track_input_);
} else {
TrackOutput* current_last_track = track_cache_.last();
// Connect this track to the current last track
NodeParam::ConnectEdge(track->track_output(), current_last_track->track_input());
// FIXME: Test code only
AlphaOverBlend* blend = new AlphaOverBlend();
static_cast<NodeGraph*>(parent())->AddNode(blend);
NodeParam::ConnectEdge(track->texture_output(), blend->blend_input());
NodeParam::ConnectEdge(current_last_track->texture_output(), blend->base_input());
NodeParam::ConnectEdge(blend->texture_output(), current_last_track->texture_output()->edges().first()->input());
// End test code
}
}
void TrackList::RemoveTrack()
{
if (track_cache_.isEmpty()) {
return;
}
TrackOutput* track = track_cache_.last();
static_cast<NodeGraph*>(parent())->TakeNode(track);
delete track;
}
void TrackList::TrackConnectionAdded(NodeEdgePtr edge)
{
if (edge->input() != track_input_) {
return;
}
AttachTrack(attached_track());
// FIXME: Is this necessary?
emit TimebaseChanged(timebase_);
}
void TrackList::TrackConnectionRemoved(NodeEdgePtr edge)
{
if (edge->input() != track_input_) {
return;
}
DetachTrack(Node::ValueToPtr<TrackOutput>(edge->output()->get_value(0)));
emit TimelineCleared();
}
void TrackList::TrackEdgeAdded(NodeEdgePtr edge)
{
// Assume this signal was sent from a TrackOutput
TrackOutput* track = static_cast<TrackOutput*>(sender());
// If this edge pertains to the track's track input, all the tracks just added need attaching
if (edge->input() == track->track_input()) {
TrackOutput* added_track = Node::ValueToPtr<TrackOutput>(edge->output()->get_value(0));
AttachTrack(added_track);
}
}
void TrackList::TrackEdgeRemoved(NodeEdgePtr edge)
{
// Assume this signal was sent from a TrackOutput
TrackOutput* track = static_cast<TrackOutput*>(sender());
// If this edge pertains to the track's track input, all the tracks just added need attaching
if (edge->input() == track->track_input()) {
TrackOutput* added_track = Node::ValueToPtr<TrackOutput>(edge->output()->get_value(0));
DetachTrack(added_track);
}
}
+113
View File
@@ -0,0 +1,113 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef TRACKLIST_H
#define TRACKLIST_H
#include <QObject>
#include "node/output/track/track.h"
class TimelineOutput;
class TrackList : public QObject {
Q_OBJECT
public:
TrackList(TimelineOutput *parent, NodeInput* track_input);
TrackOutput* attached_track();
void AttachTrack(TrackOutput *track);
void DetachTrack(TrackOutput* track);
const QVector<TrackOutput*>& Tracks();
TrackOutput* TrackAt(int index);
void AddTrack();
void RemoveTrack();
rational TrackListLength();
rational TimelineLength();
const rational& Timebase();
void SetTimebase(const rational& timebase);
public slots:/**
* @brief Slot for when the track connection is added
*/
void TrackConnectionAdded(NodeEdgePtr edge);
/**
* @brief Slot for when the track connection is removed
*/
void TrackConnectionRemoved(NodeEdgePtr edge);
/**
* @brief Slot for when a connected Track has added a Block so we can update the UI
*/
void TrackAddedBlock(Block* block);
/**
* @brief Slot for when a connected Track has added a Block so we can update the UI
*/
void TrackRemovedBlock(Block* block);
/**
* @brief Slot for when an attached Track has an edge added
*/
void TrackEdgeAdded(NodeEdgePtr edge);
/**
* @brief Slot for when an attached Track has an edge added
*/
void TrackEdgeRemoved(NodeEdgePtr edge);
signals:
void BlockAdded(Block* block, int index);
void BlockRemoved(Block* block);
void TrackAdded(TrackOutput* track);
void TrackRemoved(TrackOutput* track);
void TrackListChanged();
void TimelineCleared();
void TimebaseChanged(const rational &timebase);
private:
/**
* @brief A cache of connected Tracks
*/
QVector<TrackOutput*> track_cache_;
rational timebase_;
NodeInput* track_input_;
};
#endif // TRACKLIST_H
+14
View File
@@ -405,3 +405,17 @@ void TrackOutput::ReplaceBlock(Block *old, Block *replace)
InvalidateCache(replace->in(), replace->out());
}
TrackOutput *TrackOutput::TrackFromBlock(Block *block)
{
Block* n = block;
// Find last valid block in Sequence and assume its a track
while (n->next() != nullptr) {
n = n->next();
}
// Downside of this approach is the usage of dynamic_cast, alternative would be looping through all known tracks and
// seeing if the contain the Block, but this seems slower
return dynamic_cast<TrackOutput*>(n);
}
+2
View File
@@ -160,6 +160,8 @@ private:
*/
void ValidateCurrentBlock(const rational& time);
static TrackOutput* TrackFromBlock(Block* block);
QVector<Block*> block_cache_;
Block* current_block_;
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/output/tracklist/tracklist.h
node/output/tracklist/tracklist.cpp
PARENT_SCOPE
)
+256
View File
@@ -0,0 +1,256 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "tracklist.h"
#include <QDebug>
#include "node/blend/alphaover/alphaover.h"
#include "node/block/gap/gap.h"
#include "node/graph.h"
#include "panel/timeline/timeline.h"
TrackListOutput::TrackListOutput()
{
track_input_ = new NodeInput("track_in");
track_input_->add_data_input(NodeParam::kTrack);
AddParameter(track_input_);
connect(this, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackConnectionAdded(NodeEdgePtr)));
connect(this, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackConnectionRemoved(NodeEdgePtr)));
}
QString TrackListOutput::Name()
{
return tr("Track List");
}
QString TrackListOutput::id()
{
return "org.olivevideoeditor.Olive.tracklist";
}
QString TrackListOutput::Category()
{
return tr("Output");
}
QString TrackListOutput::Description()
{
return tr("Node for collecting Tracks of the same type.");
}
const rational &TrackListOutput::Timebase()
{
return timebase_;
}
NodeInput *TrackListOutput::track_input()
{
return track_input_;
}
const QVector<TrackOutput *> &TrackListOutput::Tracks()
{
return track_cache_;
}
TrackOutput *TrackListOutput::TrackAt(int index)
{
return track_cache_.at(index);
}
rational TrackListOutput::TimelineLength()
{
rational length = 0;
foreach (TrackOutput* track, track_cache_) {
length = qMax(length, track->in());
}
return length;
}
TrackOutput *TrackListOutput::attached_track()
{
return ValueToPtr<TrackOutput>(track_input_->get_value(0));
}
void TrackListOutput::AttachTrack(TrackOutput *track)
{
TrackOutput* current_track = track;
// Traverse through Tracks caching and connecting them
while (current_track != nullptr) {
connect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr)));
connect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr)));
connect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
connect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
current_track->SetIndex(track_cache_.size());
track_cache_.append(current_track);
// This function must be called after the track is added to track_cache_, since it uses track_cache_ to determine
// the track's index
emit TrackAdded(current_track);
current_track = current_track->next_track();
}
}
void TrackListOutput::DetachTrack(TrackOutput *track)
{
TrackOutput* current_track = track;
// Traverse through Tracks uncaching and disconnecting them
while (current_track != nullptr) {
emit TrackRemoved(current_track);
current_track->SetIndex(-1);
disconnect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr)));
disconnect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr)));
disconnect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
disconnect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
track_cache_.removeAll(current_track);
current_track = current_track->next_track();
}
}
void TrackListOutput::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
emit TimebaseChanged(timebase_);
}
void TrackListOutput::AddTrack()
{
TrackOutput* track = new TrackOutput();
static_cast<NodeGraph*>(parent())->AddNode(track);
if (track_cache_.isEmpty()) {
// Connect this track directly to this output
NodeParam::ConnectEdge(track->track_output(), track_input());
} else {
TrackOutput* current_last_track = track_cache_.last();
// Connect this track to the current last track
NodeParam::ConnectEdge(track->track_output(), current_last_track->track_input());
// FIXME: Test code only
AlphaOverBlend* blend = new AlphaOverBlend();
static_cast<NodeGraph*>(parent())->AddNode(blend);
NodeParam::ConnectEdge(track->texture_output(), blend->blend_input());
NodeParam::ConnectEdge(current_last_track->texture_output(), blend->base_input());
NodeParam::ConnectEdge(blend->texture_output(), current_last_track->texture_output()->edges().first()->input());
// End test code
}
}
void TrackListOutput::RemoveTrack()
{
if (track_cache_.isEmpty()) {
return;
}
TrackOutput* track = track_cache_.last();
static_cast<NodeGraph*>(parent())->TakeNode(track);
delete track;
}
TrackOutput *TrackListOutput::TrackFromBlock(Block *block)
{
Block* n = block;
// Find last valid block in Sequence and assume its a track
while (n->next() != nullptr) {
n = n->next();
}
// Downside of this approach is the usage of dynamic_cast, alternative would be looping through all known tracks and
// seeing if the contain the Block, but this seems slower
return dynamic_cast<TrackOutput*>(n);
}
void TrackListOutput::TrackConnectionAdded(NodeEdgePtr edge)
{
if (edge->input() != track_input()) {
return;
}
AttachTrack(attached_track());
// FIXME: Is this necessary?
emit TimebaseChanged(timebase_);
}
void TrackListOutput::TrackConnectionRemoved(NodeEdgePtr edge)
{
if (edge->input() != track_input()) {
return;
}
DetachTrack(ValueToPtr<TrackOutput>(edge->output()->get_value(0)));
emit TimelineCleared();
}
void TrackListOutput::TrackAddedBlock(Block *block)
{
emit BlockAdded(block, static_cast<TrackOutput*>(sender())->Index());
}
void TrackListOutput::TrackRemovedBlock(Block *block)
{
emit BlockRemoved(block);
}
void TrackListOutput::TrackEdgeAdded(NodeEdgePtr edge)
{
// Assume this signal was sent from a TrackOutput
TrackOutput* track = static_cast<TrackOutput*>(sender());
// If this edge pertains to the track's track input, all the tracks just added need attaching
if (edge->input() == track->track_input()) {
TrackOutput* added_track = ValueToPtr<TrackOutput>(edge->output()->get_value(0));
AttachTrack(added_track);
}
}
void TrackListOutput::TrackEdgeRemoved(NodeEdgePtr edge)
{
// Assume this signal was sent from a TrackOutput
TrackOutput* track = static_cast<TrackOutput*>(sender());
// If this edge pertains to the track's track input, all the tracks just added need attaching
if (edge->input() == track->track_input()) {
TrackOutput* added_track = ValueToPtr<TrackOutput>(edge->output()->get_value(0));
DetachTrack(added_track);
}
}
+130
View File
@@ -0,0 +1,130 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef TRACKLISTOUTPUT_H
#define TRACKLISTOUTPUT_H
#include "common/timelinecommon.h"
#include "node/block/block.h"
#include "node/output/track/track.h"
/**
* @brief Node that represents a collection of Tracks of a certain type
*/
class TrackListOutput : public Node
{
Q_OBJECT
public:
enum TrackType {
kNone = -1,
kVideo,
kAudio,
kSubtitle
};
TrackListOutput();
virtual QString Name() override;
virtual QString id() override;
virtual QString Category() override;
virtual QString Description() override;
const rational& Timebase();
void SetTimebase(const rational& timebase);
NodeInput* track_input();
const QVector<TrackOutput*>& Tracks();
TrackOutput* TrackAt(int index);
void AddTrack();
void RemoveTrack();
rational TimelineLength();
public slots:
/**
* @brief Slot for when the track connection is added
*/
void TrackConnectionAdded(NodeEdgePtr edge);
/**
* @brief Slot for when the track connection is removed
*/
void TrackConnectionRemoved(NodeEdgePtr edge);
/**
* @brief Slot for when a connected Track has added a Block so we can update the UI
*/
void TrackAddedBlock(Block* block);
/**
* @brief Slot for when a connected Track has added a Block so we can update the UI
*/
void TrackRemovedBlock(Block* block);
/**
* @brief Slot for when an attached Track has an edge added
*/
void TrackEdgeAdded(NodeEdgePtr edge);
/**
* @brief Slot for when an attached Track has an edge added
*/
void TrackEdgeRemoved(NodeEdgePtr edge);
signals:
void TimebaseChanged(const rational &timebase);
void TimelineCleared();
void BlockAdded(Block* block, int index);
void BlockRemoved(Block* block);
void TrackAdded(TrackOutput* track);
void TrackRemoved(TrackOutput* track);
protected:
private:
TrackOutput* attached_track();
void AttachTrack(TrackOutput *track);
void DetachTrack(TrackOutput* track);
static TrackOutput* TrackFromBlock(Block* block);
NodeInput* track_input_;
/**
* @brief A cache of connected Tracks
*/
QVector<TrackOutput*> track_cache_;
rational timebase_;
};
#endif // TRACKLISTOUTPUT_H