timeline hierarchical length signalling
This commit is contained in:
@@ -42,6 +42,7 @@ TimelineOutput::TimelineOutput()
|
||||
TrackList* list = new TrackList(this, track_input);
|
||||
track_lists_[i] = list;
|
||||
connect(list, SIGNAL(TrackListChanged()), this, SLOT(UpdateTrackCache()));
|
||||
connect(list, SIGNAL(LengthChanged(const rational &)), this, SLOT(UpdateLength(const rational &)));
|
||||
}
|
||||
|
||||
length_output_ = new NodeOutput("length_out");
|
||||
@@ -79,12 +80,17 @@ NodeOutput *TimelineOutput::length_output()
|
||||
return length_output_;
|
||||
}
|
||||
|
||||
const rational &TimelineOutput::timeline_length()
|
||||
{
|
||||
return length_;
|
||||
}
|
||||
|
||||
QVariant TimelineOutput::Value(NodeOutput *output, const rational &time)
|
||||
{
|
||||
if (output == length_output_) {
|
||||
Q_UNUSED(time)
|
||||
|
||||
return QVariant::fromValue(timeline_length());
|
||||
return QVariant::fromValue(length_);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -99,15 +105,33 @@ void TimelineOutput::UpdateTrackCache()
|
||||
}
|
||||
}
|
||||
|
||||
rational TimelineOutput::timeline_length()
|
||||
void TimelineOutput::UpdateLength(const rational &length)
|
||||
{
|
||||
rational length = 0;
|
||||
qDebug() << "Updating length! Received value:" << length;
|
||||
|
||||
foreach (TrackList* list, track_lists_) {
|
||||
length = qMax(list->TrackListLength(), length);
|
||||
// If this length is equal, no-op
|
||||
if (length == length_) {
|
||||
return;
|
||||
}
|
||||
|
||||
return length;
|
||||
// If this length is greater, this must be the new total length
|
||||
if (length > length_) {
|
||||
length_ = length;
|
||||
emit LengthChanged(length_);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, the new length is shorter and we'll have to manually determine what the new max length is
|
||||
rational new_length = 0;
|
||||
|
||||
foreach (TrackList* list, track_lists_) {
|
||||
new_length = qMax(new_length, list->TrackLength());
|
||||
}
|
||||
|
||||
if (new_length != length_) {
|
||||
length_ = new_length;
|
||||
emit LengthChanged(length_);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineOutput::SetTimebase(const rational &timebase)
|
||||
|
||||
@@ -56,11 +56,12 @@ public:
|
||||
|
||||
NodeOutput* length_output();
|
||||
|
||||
rational timeline_length();
|
||||
const rational& timeline_length();
|
||||
|
||||
void SetTimebase(const rational &timebase);
|
||||
|
||||
signals:
|
||||
void LengthChanged(const rational& length);
|
||||
|
||||
protected:
|
||||
virtual QVariant Value(NodeOutput* output, const rational& time) override;
|
||||
@@ -74,9 +75,13 @@ private:
|
||||
|
||||
NodeOutput* length_output_;
|
||||
|
||||
rational length_;
|
||||
|
||||
private slots:
|
||||
void UpdateTrackCache();
|
||||
|
||||
void UpdateLength(const rational &length);
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEOUTPUT_H
|
||||
|
||||
@@ -46,6 +46,7 @@ void TrackList::AttachTrack(TrackOutput *track)
|
||||
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*)));
|
||||
connect(current_track, SIGNAL(Refreshed()), this, SLOT(UpdateTotalLength()));
|
||||
|
||||
current_track->SetIndex(track_cache_.size());
|
||||
|
||||
@@ -58,6 +59,8 @@ void TrackList::AttachTrack(TrackOutput *track)
|
||||
|
||||
current_track = current_track->next_track();
|
||||
}
|
||||
|
||||
UpdateTotalLength();
|
||||
}
|
||||
|
||||
void TrackList::DetachTrack(TrackOutput *track)
|
||||
@@ -74,12 +77,15 @@ void TrackList::DetachTrack(TrackOutput *track)
|
||||
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*)));
|
||||
disconnect(current_track, SIGNAL(Refreshed()), this, SLOT(UpdateTotalLength()));
|
||||
|
||||
track_cache_.removeAll(current_track);
|
||||
emit TrackListChanged();
|
||||
|
||||
current_track = current_track->next_track();
|
||||
}
|
||||
|
||||
UpdateTotalLength();
|
||||
}
|
||||
|
||||
void TrackList::TrackAddedBlock(Block *block)
|
||||
@@ -102,22 +108,6 @@ 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_;
|
||||
@@ -130,6 +120,11 @@ void TrackList::SetTimebase(const rational &timebase)
|
||||
emit TimebaseChanged(timebase_);
|
||||
}
|
||||
|
||||
const rational &TrackList::TrackLength()
|
||||
{
|
||||
return total_length_;
|
||||
}
|
||||
|
||||
void TrackList::AddTrack()
|
||||
{
|
||||
TrackOutput* track = new TrackOutput();
|
||||
@@ -223,3 +218,14 @@ NodeGraph *TrackList::GetParentGraph()
|
||||
{
|
||||
return static_cast<NodeGraph*>(parent()->parent());
|
||||
}
|
||||
|
||||
void TrackList::UpdateTotalLength()
|
||||
{
|
||||
total_length_ = 0;
|
||||
|
||||
foreach (TrackOutput* track, track_cache_) {
|
||||
total_length_ = qMax(total_length_, track->in());
|
||||
}
|
||||
|
||||
emit LengthChanged(total_length_);
|
||||
}
|
||||
|
||||
@@ -47,14 +47,12 @@ public:
|
||||
|
||||
void RemoveTrack();
|
||||
|
||||
rational TrackListLength();
|
||||
|
||||
rational TimelineLength();
|
||||
|
||||
const rational& Timebase();
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
const rational& TrackLength();
|
||||
|
||||
public slots:/**
|
||||
* @brief Slot for when the track connection is added
|
||||
*/
|
||||
@@ -100,6 +98,8 @@ signals:
|
||||
|
||||
void TimebaseChanged(const rational &timebase);
|
||||
|
||||
void LengthChanged(const rational &length);
|
||||
|
||||
private:
|
||||
NodeGraph* GetParentGraph();
|
||||
|
||||
@@ -111,6 +111,11 @@ private:
|
||||
rational timebase_;
|
||||
|
||||
NodeInput* track_input_;
|
||||
|
||||
rational total_length_;
|
||||
|
||||
private slots:
|
||||
void UpdateTotalLength();
|
||||
};
|
||||
|
||||
#endif // TRACKLIST_H
|
||||
|
||||
Reference in New Issue
Block a user