improved replace media and made it undoable

This commit is contained in:
itsmattkc
2018-08-07 09:42:08 +10:00
parent ef8b30e7ea
commit 2a6906a70a
12 changed files with 125 additions and 85 deletions
+8
View File
@@ -26,6 +26,7 @@ Clip::Clip(Sequence* s) :
opening_transition(NULL),
closing_transition(NULL),
pkt(new AVPacket()),
replaced(false),
texture(NULL)
{
reset();
@@ -106,6 +107,13 @@ void Clip::reset_audio() {
}
void Clip::refresh() {
// validates media if it was replaced
if (replaced && media_type == MEDIA_TYPE_FOOTAGE) {
Media* m = static_cast<Media*>(media);
media_stream = (track < 0) ? m->video_tracks.at(0)->file_index : m->audio_tracks.at(0)->file_index;
}
replaced = false;
// reinitializes all effects... just in case
for (int i=0;i<effects.size();i++) {
effects.at(i)->init();
+1
View File
@@ -82,6 +82,7 @@ struct Clip
bool reached_end;
bool open;
bool finished_opening;
bool replaced;
// caching functions
bool multithreaded;
+44
View File
@@ -13,6 +13,8 @@
#include "playback/playback.h"
#include "ui/sourcetable.h"
#include "effects/effects.h"
#include "io/media.h"
#include "playback/cacher.h"
QUndoStack undo_stack;
@@ -506,3 +508,45 @@ void CheckboxCommand::redo() {
box->setChecked(checked);
}
}
ReplaceMediaCommand::ReplaceMediaCommand(QTreeWidgetItem* i, QString s) :
item(i),
new_filename(s),
old_project_changed(project_changed)
{
media = get_footage_from_tree(item);
old_filename = media->url;
}
void ReplaceMediaCommand::replace(QString& filename) {
// close any clips currently using this media
QVector<Sequence*> all_sequences = panel_project->list_all_project_sequences();
for (int i=0;i<all_sequences.size();i++) {
Sequence* s = all_sequences.at(i);
for (int j=0;j<s->clip_count();j++) {
Clip* c = s->get_clip(j);
if (c != NULL && c->media == media && c->open) {
close_clip(c);
c->cacher->wait();
c->replaced = true;
}
}
}
// replace media
QStringList files;
files.append(filename);
panel_project->process_file_list(false, files, NULL, item);
}
void ReplaceMediaCommand::undo() {
replace(old_filename);
project_changed = old_project_changed;
}
void ReplaceMediaCommand::redo() {
replace(new_filename);
project_changed = true;
}
+15
View File
@@ -5,6 +5,7 @@ class QTreeWidgetItem;
class QCheckBox;
struct Clip;
struct Sequence;
struct Media;
#include <QUndoStack>
#include <QUndoCommand>
@@ -115,4 +116,18 @@ private:
bool done;
};
class ReplaceMediaCommand : public QUndoCommand {
public:
ReplaceMediaCommand(QTreeWidgetItem*, QString);
void undo();
void redo();
private:
QTreeWidgetItem *item;
QString old_filename;
QString new_filename;
bool old_project_changed;
Media* media;
void replace(QString& filename);
};
#endif // UNDO_H