Check footage in use before deleteing

Initial very hacky implementation that checks if the footgae is in
use before deleting it and makes sure all refernences to it are
properly cleaned up.

Also added IsMedia() function to Node to simplify things a bit.
This commit is contained in:
Thomas Wilshaw
2020-09-28 14:33:53 +01:00
parent dac68cabc2
commit 7c7db5c933
9 changed files with 90 additions and 0 deletions
+5
View File
@@ -27,6 +27,11 @@ Node *AudioInput::copy() const
return new AudioInput();
}
Stream::Type AudioInput::type() const
{
return Stream::kAudio;
}
QString AudioInput::Name() const
{
return tr("Audio Input");
+2
View File
@@ -32,6 +32,8 @@ public:
virtual Node* copy() const override;
virtual Stream::Type type() const override;
virtual QString Name() const override;
virtual QString ShortName() const override;
virtual QString id() const override;
+5
View File
@@ -50,6 +50,11 @@ void MediaInput::SetFootage(StreamPtr f)
footage_input_->set_standard_value(QVariant::fromValue(f));
}
bool MediaInput::IsMedia() const
{
return true;
}
void MediaInput::Retranslate()
{
footage_input_->set_name(tr("Footage"));
+6
View File
@@ -23,6 +23,7 @@
#include "codec/decoder.h"
#include "node/node.h"
#include "project/item/footage/stream.h"
OLIVE_NAMESPACE_ENTER
@@ -35,11 +36,16 @@ class MediaInput : public Node
public:
MediaInput();
virtual Stream::Type type() const = 0;
virtual QList<CategoryID> Category() const override;
StreamPtr footage();
void SetFootage(StreamPtr f);
virtual bool IsMedia() const override;
virtual void Retranslate() override;
virtual NodeValueTable Value(NodeValueDatabase& value) const override;
+5
View File
@@ -36,6 +36,11 @@ Node *VideoInput::copy() const
return new VideoInput();
}
Stream::Type VideoInput::type() const
{
return Stream::kVideo;
}
QString VideoInput::Name() const
{
return tr("Video Input");
+2
View File
@@ -35,6 +35,8 @@ public:
virtual Node* copy() const override;
virtual Stream::Type type() const override;
virtual QString Name() const override;
virtual QString ShortName() const override;
virtual QString id() const override;
+5
View File
@@ -440,6 +440,11 @@ bool Node::IsTrack() const
return false;
}
bool Node::IsMedia() const
{
return false;
}
const QList<NodeParam *>& Node::parameters() const
{
return params_;
+9
View File
@@ -363,6 +363,15 @@ public:
*/
virtual bool IsTrack() const;
/**
* @brief Returns whether this Node is a "Media" type or not
*
* You shouldn't ever need to override this since all derivatives of Media will automatically have this set to true.
* It's just a more convenient way of checking than dynamic_casting.
*/
virtual bool IsMedia() const;
/**
* @brief The main processing function
*
@@ -558,6 +558,57 @@ void ProjectExplorer::DeleteSelected()
}
}
if (item_ptr->type() == Item::kFootage) {
// Get all sequences
QList<ItemPtr> sequences = model_.project()->get_items_of_type(Item::kSequence);
// If no sequences exist we don't need to do anything clever here
if (!sequences.isEmpty()) {
// Footage can contain multiple streams, all of which need to be dealt with
foreach (StreamPtr stream, static_cast<Footage*>(item_ptr.get())->streams()) {
// Check each sequence to see if it contains the footage in question
foreach (ItemPtr seq, sequences) {
Sequence* s = static_cast<Sequence*>(seq.get());
// Loop through nodes to find our Footage node
foreach (Node* node, s->nodes()) {
// Check if node is of the right type
if (node->IsMedia() && static_cast<MediaInput*>(node)->type() == stream.get()->type()) {
// Check the streams are the same
if (static_cast<MediaInput*>(node)->footage() == stream) {
// Loop through nodes and set any that point to the Footage node to null
foreach (Node* check_node, s->nodes()) {
// Skip itself
if (check_node == node) {
continue;
}
if (check_node->GetImmediateDependencies().contains(node)) {
QList<NodeInput*> inputs = check_node->GetInputsIncludingArrays();
foreach (NodeInput* input, inputs) {
foreach (NodeEdgePtr edge, input->edges()) {
Node* connected = edge->output()->parentNode();
if (connected == node) {
input->DisconnectEdge(edge);
}
}
}
}
}
static_cast<MediaInput*>(node)->SetFootage(nullptr);
break;
}
}
}
}
}
}
}
new ProjectViewModel::RemoveItemCommand(&model_, item_ptr, command);
}