Skip to content

Commit

Permalink
added ability to open viewers on any viewer node or derivative
Browse files Browse the repository at this point in the history
Fixes olive-editor#1362

Also fixes some other bugs that impeded this from working.
  • Loading branch information
itsmattkc committed Apr 12, 2021
1 parent 17f40cf commit c03c197
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 85 deletions.
8 changes: 5 additions & 3 deletions app/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ void Core::CreateNewSequence()
// Create new sequence
Sequence* new_sequence = CreateNewSequenceForProject(active_project);

// Set all defaults for the sequence
new_sequence->set_default_parameters();

SequenceDialog sd(new_sequence, SequenceDialog::kNew, main_window_);

// Make sure SequenceDialog doesn't make an undo command for editing the sequence, since we make an undo command for
Expand Down Expand Up @@ -1091,6 +1088,11 @@ void Core::OpenRecoveryProject(const QString &filename)
OpenProjectInternal(filename, true);
}

void Core::OpenNodeInViewer(ViewerOutput *viewer)
{
main_window_->OpenNodeInViewer(viewer);
}

void Core::CheckForAutoRecoveries()
{
QFile autorecovery_index(GetAutoRecoveryIndexFilename());
Expand Down
2 changes: 2 additions & 0 deletions app/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ class Core : public QObject

void OpenRecoveryProject(const QString& filename);

void OpenNodeInViewer(ViewerOutput* viewer);

static const uint kProjectVersion;

public slots:
Expand Down
2 changes: 2 additions & 0 deletions app/node/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void NodeGraph::childEvent(QChildEvent *event)
connect(node, &Node::ValueChanged, this, &NodeGraph::ValueChanged);

emit NodeAdded(node);
emit node->AddedToGraph(this);

} else if (event->type() == QEvent::ChildRemoved) {

Expand All @@ -72,6 +73,7 @@ void NodeGraph::childEvent(QChildEvent *event)
disconnect(node, &Node::ValueChanged, this, &NodeGraph::ValueChanged);

emit NodeRemoved(node);
emit node->RemovedFromGraph(this);

}
}
Expand Down
4 changes: 4 additions & 0 deletions app/node/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,10 @@ class Node : public QObject

void InputDataTypeChanged(const QString& id, NodeValue::Type type);

void AddedToGraph(NodeGraph* graph);

void RemovedFromGraph(NodeGraph* graph);

private:
class ArrayInsertCommand : public UndoCommand
{
Expand Down
16 changes: 9 additions & 7 deletions app/node/output/track/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ class Track : public Node

static Type TypeFromString(const QString& s)
{
if (s.at(1) == ':') {
if (s.at(0) == 'v') {
// Video stream
return Track::kVideo;
} else if (s.at(0) == 'a') {
// Audio stream
return Track::kAudio;
if (s.size() >= 3) {
if (s.at(1) == ':') {
if (s.at(0) == 'v') {
// Video stream
return Track::kVideo;
} else if (s.at(0) == 'a') {
// Audio stream
return Track::kAudio;
}
}
}

Expand Down
60 changes: 31 additions & 29 deletions app/node/output/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ViewerOutput::ViewerOutput(bool create_default_streams) :
if (create_default_streams) {
AddStream(Track::kVideo, QVariant());
AddStream(Track::kAudio, QVariant());
set_default_parameters();
}
}

Expand Down Expand Up @@ -302,39 +303,19 @@ void ViewerOutput::Retranslate()

void ViewerOutput::VerifyLength()
{
NodeTraverser traverser;

rational video_length, audio_length, subtitle_length;

{
video_length = GetCustomLength(Track::kVideo);

if (video_length.isNull() && IsInputConnected(kTextureInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kTextureInput), TimeRange(0, 0));
video_length = t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}

if (cache_enabled_) {
video_frame_cache_.SetLength(video_length);
}
video_length = VerifyLengthInternal(Track::kVideo);
if (cache_enabled_) {
video_frame_cache_.SetLength(video_length);
}

{
audio_length = GetCustomLength(Track::kAudio);

if (audio_length.isNull() && IsInputConnected(kSamplesInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kSamplesInput), TimeRange(0, 0));
audio_length = t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}

if (cache_enabled_) {
audio_playback_cache_.SetLength(audio_length);
}
audio_length = VerifyLengthInternal(Track::kAudio);
if (cache_enabled_) {
audio_playback_cache_.SetLength(audio_length);
}

{
subtitle_length = GetCustomLength(Track::kSubtitle);
}
subtitle_length = VerifyLengthInternal(Track::kSubtitle);

rational real_length = qMax(subtitle_length, qMax(video_length, audio_length));

Expand Down Expand Up @@ -362,9 +343,30 @@ void ViewerOutput::InputDisconnectedEvent(const QString &input, int element, con
super::InputDisconnectedEvent(input, element, output);
}

rational ViewerOutput::GetCustomLength(Track::Type type) const
rational ViewerOutput::VerifyLengthInternal(Track::Type type) const
{
Q_UNUSED(type)
NodeTraverser traverser;

switch (type) {
case Track::kVideo:
if (IsInputConnected(kTextureInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kTextureInput), TimeRange(0, 0));
qDebug() << "Got video length:" << t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
return t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}
break;
case Track::kAudio:
if (IsInputConnected(kSamplesInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kSamplesInput), TimeRange(0, 0));
return t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}
break;
case Track::kNone:
case Track::kSubtitle:
case Track::kCount:
break;
}

return rational();
}

Expand Down
2 changes: 1 addition & 1 deletion app/node/output/viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public slots:

virtual void InputDisconnectedEvent(const QString &input, int element, const NodeOutput &output) override;

virtual rational GetCustomLength(Track::Type type) const;
virtual rational VerifyLengthInternal(Track::Type type) const;

virtual void ShiftVideoEvent(const rational &from, const rational &to);

Expand Down
4 changes: 2 additions & 2 deletions app/node/project/footage/footage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void Footage::InputValueChangedEvent(const QString &input, int element)
}
}

rational Footage::GetCustomLength(Track::Type type) const
rational Footage::VerifyLengthInternal(Track::Type type) const
{
if (type == Track::kVideo) {
VideoParams first_stream = GetFirstEnabledVideoStream();
Expand All @@ -196,7 +196,7 @@ rational Footage::GetCustomLength(Track::Type type) const
}
}

return super::GetCustomLength(type);
return super::VerifyLengthInternal(type);
}

QString Footage::GetColorspaceToUse(const VideoParams &params) const
Expand Down
4 changes: 2 additions & 2 deletions app/node/project/footage/footage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Footage : public ViewerOutput

virtual QString Name() const override
{
return tr("Footage");
return tr("Media");
}

virtual QString id() const override
Expand Down Expand Up @@ -195,7 +195,7 @@ class Footage : public ViewerOutput

virtual void InputValueChangedEvent(const QString &input, int element) override;

virtual rational GetCustomLength(Track::Type type) const override;
virtual rational VerifyLengthInternal(Track::Type type) const override;

private:
QString GetColorspaceToUse(const VideoParams& params) const;
Expand Down
6 changes: 0 additions & 6 deletions app/node/project/projectviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,6 @@ void ProjectViewModel::ConnectItem(Node *n)
connect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::FolderBeginRemoveItem);
connect(f, &Folder::EndRemoveItem, this, &ProjectViewModel::FolderEndRemoveItem);

connect(f, &Folder::BeginInsertItem, this, &ProjectViewModel::ItemAdded);
connect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::ItemRemoved);

foreach (Node* c, f->children()) {
ConnectItem(c);
}
Expand All @@ -450,9 +447,6 @@ void ProjectViewModel::DisconnectItem(Node *n)
disconnect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::FolderBeginRemoveItem);
disconnect(f, &Folder::EndRemoveItem, this, &ProjectViewModel::FolderEndRemoveItem);

disconnect(f, &Folder::BeginInsertItem, this, &ProjectViewModel::ItemAdded);
disconnect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::ItemRemoved);

foreach (Node* c, f->children()) {
DisconnectItem(c);
}
Expand Down
5 changes: 0 additions & 5 deletions app/node/project/projectviewmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ class ProjectViewModel : public QAbstractItemModel
*/
QModelIndex CreateIndexFromItem(Node *item, int column = 0);

signals:
void ItemAdded(Node* node);

void ItemRemoved(Node* node);

private:
/**
* @brief Retrieve the index of `item` in its parent
Expand Down
2 changes: 1 addition & 1 deletion app/node/project/sequence/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Sequence::Retranslate()
}
}

rational Sequence::GetCustomLength(Track::Type type) const
rational Sequence::VerifyLengthInternal(Track::Type type) const
{
if (!track_lists_.isEmpty()) {
switch (type) {
Expand Down
2 changes: 1 addition & 1 deletion app/node/project/sequence/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Sequence : public ViewerOutput

virtual void InputDisconnectedEvent(const QString &input, int element, const NodeOutput &output) override;

virtual rational GetCustomLength(Track::Type type) const override;
virtual rational VerifyLengthInternal(Track::Type type) const override;

signals:
void TrackAdded(Track* track);
Expand Down
22 changes: 17 additions & 5 deletions app/node/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,26 @@ NodeValueTable NodeValueTable::Merge(QList<NodeValueTable> tables)
NodeValueTable merged_table;

// Slipstreams all tables together
foreach (const NodeValueTable& t, tables) {
if (row >= t.Count()) {
continue;
while (true) {
bool all_merged = true;

foreach (const NodeValueTable& t, tables) {
if (row < t.Count()) {
all_merged = false;
} else {
continue;
}

int row_index = t.Count() - 1 - row;

merged_table.Prepend(t.at(row_index));
}

int row_index = t.Count() - 1 - row;
row++;

merged_table.Prepend(t.at(row_index));
if (all_merged) {
break;
}
}

return merged_table;
Expand Down
11 changes: 0 additions & 11 deletions app/panel/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ ProjectPanel::ProjectPanel(QWidget *parent) :
explorer_ = new ProjectExplorer(this);
layout->addWidget(explorer_);
connect(explorer_, &ProjectExplorer::DoubleClickedItem, this, &ProjectPanel::ItemDoubleClickSlot);
connect(explorer_, &ProjectExplorer::ItemRemoved, this, &ProjectPanel::ItemRemoved);

// Set toolbar's view to the explorer's view
toolbar->SetView(explorer_->view_type());
Expand Down Expand Up @@ -233,16 +232,6 @@ void ProjectPanel::SaveConnectedProject()
Core::instance()->SaveProject(this->project());
}

void ProjectPanel::ItemRemoved(Node *item)
{
// Open this footage in a FootageViewer
FootageViewerPanel* panel = PanelManager::instance()->MostRecentlyFocused<FootageViewerPanel>();

if (panel->GetConnectedViewer() == item) {
panel->DisconnectViewerNode();
}
}

QVector<ViewerOutput *> ProjectPanel::GetSelectedFootage() const
{
QVector<Node*> items = SelectedItems();
Expand Down
2 changes: 0 additions & 2 deletions app/panel/project/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ private slots:

void SaveConnectedProject();

void ItemRemoved(Node* item);

};

}
Expand Down
23 changes: 17 additions & 6 deletions app/panel/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ namespace olive {
ViewerPanel::ViewerPanel(const QString &object_name, QWidget *parent) :
ViewerPanelBase(object_name, parent)
{
// Set ViewerWidget as the central widget
ViewerWidget* vw = new ViewerWidget();
connect(vw, &ViewerWidget::RequestScopePanel, this, &ViewerPanel::CreateScopePanel);
SetTimeBasedWidget(vw);
Init();
}

// Set strings
Retranslate();
ViewerPanel::ViewerPanel(QWidget *parent) :
ViewerPanelBase(QStringLiteral("ViewerPanel"), parent)
{
Init();
}

void ViewerPanel::Retranslate()
Expand All @@ -41,4 +41,15 @@ void ViewerPanel::Retranslate()
SetTitle(tr("Viewer"));
}

void ViewerPanel::Init()
{
// Set ViewerWidget as the central widget
ViewerWidget* vw = new ViewerWidget();
connect(vw, &ViewerWidget::RequestScopePanel, this, &ViewerPanel::CreateScopePanel);
SetTimeBasedWidget(vw);

// Set strings
Retranslate();
}

}
4 changes: 4 additions & 0 deletions app/panel/viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ class ViewerPanel : public ViewerPanelBase {
Q_OBJECT
public:
ViewerPanel(const QString& object_name, QWidget* parent);
ViewerPanel(QWidget* parent);

protected:
virtual void Retranslate() override;

private:
void Init();

};

}
Expand Down
Loading

0 comments on commit c03c197

Please sign in to comment.