change: change code style to Linux style except indent.
This commit is contained in:
+194
-178
@@ -28,258 +28,274 @@
|
||||
#include "node/nodeundo.h"
|
||||
#include "node/project/footage/footage.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectImportTask::ProjectImportTask(Folder *folder, const QStringList &filenames) :
|
||||
command_(nullptr),
|
||||
folder_(folder)
|
||||
namespace olive
|
||||
{
|
||||
foreach (const QString& f, filenames) {
|
||||
filenames_.append(QFileInfo(f));
|
||||
}
|
||||
|
||||
file_count_ = Core::CountFilesInFileList(filenames_);
|
||||
ProjectImportTask::ProjectImportTask(Folder *folder,
|
||||
const QStringList &filenames)
|
||||
: command_(nullptr)
|
||||
, folder_(folder)
|
||||
{
|
||||
foreach (const QString &f, filenames) {
|
||||
filenames_.append(QFileInfo(f));
|
||||
}
|
||||
|
||||
SetTitle(tr("Importing %n file(s)", nullptr, file_count_));
|
||||
file_count_ = Core::CountFilesInFileList(filenames_);
|
||||
|
||||
SetTitle(tr("Importing %n file(s)", nullptr, file_count_));
|
||||
}
|
||||
|
||||
const int &ProjectImportTask::GetFileCount() const
|
||||
{
|
||||
return file_count_;
|
||||
return file_count_;
|
||||
}
|
||||
|
||||
bool ProjectImportTask::Run()
|
||||
{
|
||||
command_ = new MultiUndoCommand();
|
||||
command_ = new MultiUndoCommand();
|
||||
|
||||
int imported = 0;
|
||||
int imported = 0;
|
||||
|
||||
Import(folder_, filenames_, imported, command_);
|
||||
Import(folder_, filenames_, imported, command_);
|
||||
|
||||
if (IsCancelled()) {
|
||||
delete command_;
|
||||
command_ = nullptr;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
if (IsCancelled()) {
|
||||
delete command_;
|
||||
command_ = nullptr;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectImportTask::Import(Folder *folder, QFileInfoList import, int &counter, MultiUndoCommand* parent_command)
|
||||
void ProjectImportTask::Import(Folder *folder, QFileInfoList import,
|
||||
int &counter, MultiUndoCommand *parent_command)
|
||||
{
|
||||
for (int i=0; i<import.size(); i++) {
|
||||
if (IsCancelled()) {
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < import.size(); i++) {
|
||||
if (IsCancelled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const QFileInfo& file_info = import.at(i);
|
||||
const QFileInfo &file_info = import.at(i);
|
||||
|
||||
// Check if this file is a directory
|
||||
if (file_info.isDir()) {
|
||||
// Check if this file is a directory
|
||||
if (file_info.isDir()) {
|
||||
// QDir::entryList only returns filenames, we can use entryInfoList() to get full paths
|
||||
QFileInfoList entry_list =
|
||||
QDir(file_info.absoluteFilePath()).entryInfoList();
|
||||
|
||||
// QDir::entryList only returns filenames, we can use entryInfoList() to get full paths
|
||||
QFileInfoList entry_list = QDir(file_info.absoluteFilePath()).entryInfoList();
|
||||
// Strip out "." and ".." (for some reason QDir::NoDotAndDotDot doesn't work with entryInfoList, so we have to
|
||||
// check manually)
|
||||
for (int j = 0; j < entry_list.size(); j++) {
|
||||
if (entry_list.at(j).fileName() == QStringLiteral(".") ||
|
||||
entry_list.at(j).fileName() == QStringLiteral("..")) {
|
||||
entry_list.removeAt(j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
// Strip out "." and ".." (for some reason QDir::NoDotAndDotDot doesn't work with entryInfoList, so we have to
|
||||
// check manually)
|
||||
for (int j=0;j<entry_list.size();j++) {
|
||||
if (entry_list.at(j).fileName() == QStringLiteral(".")
|
||||
|| entry_list.at(j).fileName() == QStringLiteral("..")) {
|
||||
entry_list.removeAt(j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
// Only proceed if the empty actually has files in it
|
||||
if (!entry_list.isEmpty()) {
|
||||
// Create a folder corresponding to the directory
|
||||
Folder *f = new Folder();
|
||||
|
||||
// Only proceed if the empty actually has files in it
|
||||
if (!entry_list.isEmpty()) {
|
||||
// Create a folder corresponding to the directory
|
||||
Folder* f = new Folder();
|
||||
f->SetLabel(file_info.fileName());
|
||||
|
||||
f->SetLabel(file_info.fileName());
|
||||
// Create undoable command that adds the items to the model
|
||||
AddItemToFolder(folder, f, parent_command);
|
||||
|
||||
// Create undoable command that adds the items to the model
|
||||
AddItemToFolder(folder, f, parent_command);
|
||||
// Recursively follow this path
|
||||
Import(f, entry_list, counter, parent_command);
|
||||
}
|
||||
|
||||
// Recursively follow this path
|
||||
Import(f, entry_list, counter, parent_command);
|
||||
}
|
||||
} else {
|
||||
Footage *footage = new Footage();
|
||||
|
||||
} else {
|
||||
footage->SetCancelPointer(this->GetCancelAtom());
|
||||
|
||||
Footage* footage = new Footage();
|
||||
footage->set_filename(file_info.absoluteFilePath());
|
||||
footage->SetLabel(file_info.fileName());
|
||||
|
||||
footage->SetCancelPointer(this->GetCancelAtom());
|
||||
footage->SetCancelPointer(nullptr);
|
||||
|
||||
footage->set_filename(file_info.absoluteFilePath());
|
||||
footage->SetLabel(file_info.fileName());
|
||||
if (footage->IsValid()) {
|
||||
// See if this footage is an image sequence
|
||||
ValidateImageSequence(footage, import, i);
|
||||
|
||||
footage->SetCancelPointer(nullptr);
|
||||
// Create undoable command that adds the items to the model
|
||||
AddItemToFolder(folder, footage, parent_command);
|
||||
|
||||
if (footage->IsValid()) {
|
||||
// See if this footage is an image sequence
|
||||
ValidateImageSequence(footage, import, i);
|
||||
// Add to vector
|
||||
imported_footage_.push_back(footage);
|
||||
} else {
|
||||
// Add to list so we can tell the user about it later
|
||||
invalid_files_.append(file_info.absoluteFilePath());
|
||||
|
||||
// Create undoable command that adds the items to the model
|
||||
AddItemToFolder(folder, footage, parent_command);
|
||||
delete footage;
|
||||
}
|
||||
|
||||
// Add to vector
|
||||
imported_footage_.push_back(footage);
|
||||
} else {
|
||||
// Add to list so we can tell the user about it later
|
||||
invalid_files_.append(file_info.absoluteFilePath());
|
||||
counter++;
|
||||
|
||||
delete footage;
|
||||
}
|
||||
|
||||
counter++;
|
||||
|
||||
emit ProgressChanged(static_cast<double>(counter) / static_cast<double>(file_count_));
|
||||
|
||||
}
|
||||
}
|
||||
emit ProgressChanged(static_cast<double>(counter) /
|
||||
static_cast<double>(file_count_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectImportTask::ValidateImageSequence(Footage *footage, QFileInfoList& info_list, int index)
|
||||
void ProjectImportTask::ValidateImageSequence(Footage *footage,
|
||||
QFileInfoList &info_list,
|
||||
int index)
|
||||
{
|
||||
// Heuristically determine whether this file is part of an image sequence or not
|
||||
//
|
||||
// By this point we've established that video contains a single still image stream. Now we'll
|
||||
// see if it ends with numbers.
|
||||
if (Decoder::GetImageSequenceDigitCount(footage->filename()) > 0
|
||||
&& !image_sequence_ignore_files_.contains(footage->filename())
|
||||
&& footage->InputArraySize(Footage::kVideoParamsInput)) {
|
||||
VideoParams video_stream = footage->GetVideoParams(0);
|
||||
QSize dim(video_stream.width(), video_stream.height());
|
||||
// Heuristically determine whether this file is part of an image sequence or not
|
||||
//
|
||||
// By this point we've established that video contains a single still image stream. Now we'll
|
||||
// see if it ends with numbers.
|
||||
if (Decoder::GetImageSequenceDigitCount(footage->filename()) > 0 &&
|
||||
!image_sequence_ignore_files_.contains(footage->filename()) &&
|
||||
footage->InputArraySize(Footage::kVideoParamsInput)) {
|
||||
VideoParams video_stream = footage->GetVideoParams(0);
|
||||
QSize dim(video_stream.width(), video_stream.height());
|
||||
|
||||
int64_t ind = Decoder::GetImageSequenceIndex(footage->filename());
|
||||
int64_t ind = Decoder::GetImageSequenceIndex(footage->filename());
|
||||
|
||||
// Check if files around exist around it with that follow a sequence
|
||||
QString previous_img_fn = Decoder::TransformImageSequenceFileName(footage->filename(), ind - 1);
|
||||
QString next_img_fn = Decoder::TransformImageSequenceFileName(footage->filename(), ind + 1);
|
||||
// Check if files around exist around it with that follow a sequence
|
||||
QString previous_img_fn = Decoder::TransformImageSequenceFileName(
|
||||
footage->filename(), ind - 1);
|
||||
QString next_img_fn = Decoder::TransformImageSequenceFileName(
|
||||
footage->filename(), ind + 1);
|
||||
|
||||
Footage* previous_file = new Footage(previous_img_fn);
|
||||
Footage* next_file = new Footage(next_img_fn);
|
||||
Footage *previous_file = new Footage(previous_img_fn);
|
||||
Footage *next_file = new Footage(next_img_fn);
|
||||
|
||||
// Finally see if these files have the same dimensions
|
||||
if ((previous_file->IsValid() && CompareStillImageSize(previous_file, dim))
|
||||
|| (next_file->IsValid() && CompareStillImageSize(next_file, dim))) {
|
||||
// By this point, we've established this file is a still image with a number at the end of
|
||||
// the filename surrounded by adjacent numbers. It could be a still image! But let's ask the
|
||||
// user just in case...
|
||||
bool is_sequence;
|
||||
// Finally see if these files have the same dimensions
|
||||
if ((previous_file->IsValid() &&
|
||||
CompareStillImageSize(previous_file, dim)) ||
|
||||
(next_file->IsValid() && CompareStillImageSize(next_file, dim))) {
|
||||
// By this point, we've established this file is a still image with a number at the end of
|
||||
// the filename surrounded by adjacent numbers. It could be a still image! But let's ask the
|
||||
// user just in case...
|
||||
bool is_sequence;
|
||||
|
||||
QMetaObject::invokeMethod(Core::instance(),
|
||||
"ConfirmImageSequence",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, is_sequence),
|
||||
Q_ARG(QString, footage->filename()));
|
||||
QMetaObject::invokeMethod(Core::instance(), "ConfirmImageSequence",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, is_sequence),
|
||||
Q_ARG(QString, footage->filename()));
|
||||
|
||||
int64_t seq_index = Decoder::GetImageSequenceIndex(footage->filename());
|
||||
int64_t seq_index =
|
||||
Decoder::GetImageSequenceIndex(footage->filename());
|
||||
|
||||
// Heuristic to find the first and last images (users can always override this later in
|
||||
// FootagePropertiesDialog)
|
||||
int64_t start_index = GetImageSequenceLimit(footage->filename(), seq_index, false);
|
||||
int64_t end_index = GetImageSequenceLimit(footage->filename(), seq_index, true);
|
||||
// Heuristic to find the first and last images (users can always override this later in
|
||||
// FootagePropertiesDialog)
|
||||
int64_t start_index =
|
||||
GetImageSequenceLimit(footage->filename(), seq_index, false);
|
||||
int64_t end_index =
|
||||
GetImageSequenceLimit(footage->filename(), seq_index, true);
|
||||
|
||||
// Depending on the user's choice, either remove them from the list or don't ask for the
|
||||
// remainders
|
||||
for (int64_t j=start_index; j<=end_index; j++) {
|
||||
QString entry_fn = Decoder::TransformImageSequenceFileName(footage->filename(), j);
|
||||
// Depending on the user's choice, either remove them from the list or don't ask for the
|
||||
// remainders
|
||||
for (int64_t j = start_index; j <= end_index; j++) {
|
||||
QString entry_fn = Decoder::TransformImageSequenceFileName(
|
||||
footage->filename(), j);
|
||||
|
||||
if (is_sequence) {
|
||||
// If this is part of the sequence we're importing here, remove it
|
||||
for (int i=index+1; i<info_list.size(); i++) {
|
||||
if (info_list.at(i).absoluteFilePath() == entry_fn) {
|
||||
if (is_sequence) {
|
||||
info_list.removeAt(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
image_sequence_ignore_files_.append(entry_fn);
|
||||
}
|
||||
}
|
||||
if (is_sequence) {
|
||||
// If this is part of the sequence we're importing here, remove it
|
||||
for (int i = index + 1; i < info_list.size(); i++) {
|
||||
if (info_list.at(i).absoluteFilePath() == entry_fn) {
|
||||
if (is_sequence) {
|
||||
info_list.removeAt(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
image_sequence_ignore_files_.append(entry_fn);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_sequence) {
|
||||
// User has confirmed it is a still image, let's set it accordingly.
|
||||
video_stream.set_video_type(VideoParams::kVideoTypeImageSequence);
|
||||
if (is_sequence) {
|
||||
// User has confirmed it is a still image, let's set it accordingly.
|
||||
video_stream.set_video_type(
|
||||
VideoParams::kVideoTypeImageSequence);
|
||||
|
||||
rational default_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
|
||||
video_stream.set_time_base(default_timebase);
|
||||
video_stream.set_frame_rate(default_timebase.flipped());
|
||||
rational default_timebase =
|
||||
OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
|
||||
video_stream.set_time_base(default_timebase);
|
||||
video_stream.set_frame_rate(default_timebase.flipped());
|
||||
|
||||
video_stream.set_start_time(start_index);
|
||||
video_stream.set_duration(end_index - start_index + 1);
|
||||
video_stream.set_start_time(start_index);
|
||||
video_stream.set_duration(end_index - start_index + 1);
|
||||
|
||||
footage->SetVideoParams(video_stream, 0);
|
||||
}
|
||||
}
|
||||
footage->SetVideoParams(video_stream, 0);
|
||||
}
|
||||
}
|
||||
|
||||
delete previous_file;
|
||||
delete next_file;
|
||||
}
|
||||
delete previous_file;
|
||||
delete next_file;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectImportTask::AddItemToFolder(Folder *folder, Node *item, MultiUndoCommand *command)
|
||||
void ProjectImportTask::AddItemToFolder(Folder *folder, Node *item,
|
||||
MultiUndoCommand *command)
|
||||
{
|
||||
// Create undoable command that adds the items to the model
|
||||
Project* project = folder_->project();
|
||||
// Create undoable command that adds the items to the model
|
||||
Project *project = folder_->project();
|
||||
|
||||
NodeAddCommand* nac = new NodeAddCommand(project, item);
|
||||
nac->PushToThread(project->thread());
|
||||
command->add_child(nac);
|
||||
NodeAddCommand *nac = new NodeAddCommand(project, item);
|
||||
nac->PushToThread(project->thread());
|
||||
command->add_child(nac);
|
||||
|
||||
command->add_child(new FolderAddChild(folder, item));
|
||||
command->add_child(new FolderAddChild(folder, item));
|
||||
}
|
||||
|
||||
bool ProjectImportTask::ItemIsStillImageFootageOnly(Footage* footage)
|
||||
bool ProjectImportTask::ItemIsStillImageFootageOnly(Footage *footage)
|
||||
{
|
||||
if (footage->GetTotalStreamCount() != 1) {
|
||||
// Footage with more than one stream (usually video+audio) most likely isn't an image sequence
|
||||
return false;
|
||||
}
|
||||
if (footage->GetTotalStreamCount() != 1) {
|
||||
// Footage with more than one stream (usually video+audio) most likely isn't an image sequence
|
||||
return false;
|
||||
}
|
||||
|
||||
VideoParams vp = footage->GetVideoParams(0);
|
||||
VideoParams vp = footage->GetVideoParams(0);
|
||||
|
||||
// Footage must be valid and video stream must be a still image to be an image sequence
|
||||
return vp.is_valid() && vp.video_type() == VideoParams::kVideoTypeStill;
|
||||
// Footage must be valid and video stream must be a still image to be an image sequence
|
||||
return vp.is_valid() && vp.video_type() == VideoParams::kVideoTypeStill;
|
||||
}
|
||||
|
||||
bool ProjectImportTask::CompareStillImageSize(Footage* footage, const QSize &sz)
|
||||
bool ProjectImportTask::CompareStillImageSize(Footage *footage, const QSize &sz)
|
||||
{
|
||||
if (!ItemIsStillImageFootageOnly(footage)) {
|
||||
return false;
|
||||
}
|
||||
if (!ItemIsStillImageFootageOnly(footage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VideoParams stream = footage->GetVideoParams(0);
|
||||
VideoParams stream = footage->GetVideoParams(0);
|
||||
|
||||
return stream.width() == sz.width() && stream.height() == sz.height();
|
||||
return stream.width() == sz.width() && stream.height() == sz.height();
|
||||
}
|
||||
|
||||
int64_t ProjectImportTask::GetImageSequenceLimit(const QString& start_fn, int64_t start, bool up)
|
||||
int64_t ProjectImportTask::GetImageSequenceLimit(const QString &start_fn,
|
||||
int64_t start, bool up)
|
||||
{
|
||||
QString test_filename;
|
||||
int test_index;
|
||||
QString test_filename;
|
||||
int test_index;
|
||||
|
||||
forever {
|
||||
if (up) {
|
||||
test_index = start + 1;
|
||||
} else {
|
||||
test_index = start - 1;
|
||||
}
|
||||
forever
|
||||
{
|
||||
if (up) {
|
||||
test_index = start + 1;
|
||||
} else {
|
||||
test_index = start - 1;
|
||||
}
|
||||
|
||||
test_filename = Decoder::TransformImageSequenceFileName(start_fn, test_index);
|
||||
test_filename =
|
||||
Decoder::TransformImageSequenceFileName(start_fn, test_index);
|
||||
|
||||
if (!QFileInfo::exists(test_filename)) {
|
||||
// Reached end of index
|
||||
break;
|
||||
}
|
||||
if (!QFileInfo::exists(test_filename)) {
|
||||
// Reached end of index
|
||||
break;
|
||||
}
|
||||
|
||||
start = test_index;
|
||||
}
|
||||
start = test_index;
|
||||
}
|
||||
|
||||
return start;
|
||||
return start;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,63 +28,68 @@
|
||||
#include "task/task.h"
|
||||
#include "widget/projectexplorer/projectviewmodel.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ProjectImportTask : public Task
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class ProjectImportTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectImportTask(Folder* folder, const QStringList& filenames);
|
||||
ProjectImportTask(Folder *folder, const QStringList &filenames);
|
||||
|
||||
const int& GetFileCount() const;
|
||||
const int &GetFileCount() const;
|
||||
|
||||
MultiUndoCommand* GetCommand() const
|
||||
{
|
||||
return command_;
|
||||
}
|
||||
MultiUndoCommand *GetCommand() const
|
||||
{
|
||||
return command_;
|
||||
}
|
||||
|
||||
const QStringList& GetInvalidFiles() const
|
||||
{
|
||||
return invalid_files_;
|
||||
}
|
||||
const QStringList &GetInvalidFiles() const
|
||||
{
|
||||
return invalid_files_;
|
||||
}
|
||||
|
||||
bool HasInvalidFiles() const
|
||||
{
|
||||
return !invalid_files_.isEmpty();
|
||||
}
|
||||
bool HasInvalidFiles() const
|
||||
{
|
||||
return !invalid_files_.isEmpty();
|
||||
}
|
||||
|
||||
const QVector<Footage*> &GetImportedFootage() const { return imported_footage_; }
|
||||
const QVector<Footage *> &GetImportedFootage() const
|
||||
{
|
||||
return imported_footage_;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool Run() override;
|
||||
virtual bool Run() override;
|
||||
|
||||
private:
|
||||
void Import(Folder* folder, QFileInfoList import, int& counter, MultiUndoCommand *parent_command);
|
||||
void Import(Folder *folder, QFileInfoList import, int &counter,
|
||||
MultiUndoCommand *parent_command);
|
||||
|
||||
void ValidateImageSequence(Footage *footage, QFileInfoList &info_list, int index);
|
||||
void ValidateImageSequence(Footage *footage, QFileInfoList &info_list,
|
||||
int index);
|
||||
|
||||
void AddItemToFolder(Folder* folder, Node* item, MultiUndoCommand* command);
|
||||
void AddItemToFolder(Folder *folder, Node *item, MultiUndoCommand *command);
|
||||
|
||||
static bool ItemIsStillImageFootageOnly(Footage *footage);
|
||||
static bool ItemIsStillImageFootageOnly(Footage *footage);
|
||||
|
||||
static bool CompareStillImageSize(Footage *footage, const QSize& sz);
|
||||
static bool CompareStillImageSize(Footage *footage, const QSize &sz);
|
||||
|
||||
static int64_t GetImageSequenceLimit(const QString &start_fn, int64_t start, bool up);
|
||||
static int64_t GetImageSequenceLimit(const QString &start_fn, int64_t start,
|
||||
bool up);
|
||||
|
||||
MultiUndoCommand* command_;
|
||||
MultiUndoCommand *command_;
|
||||
|
||||
Folder* folder_;
|
||||
Folder *folder_;
|
||||
|
||||
QFileInfoList filenames_;
|
||||
QFileInfoList filenames_;
|
||||
|
||||
int file_count_;
|
||||
int file_count_;
|
||||
|
||||
QStringList invalid_files_;
|
||||
QStringList invalid_files_;
|
||||
|
||||
QList<QString> image_sequence_ignore_files_;
|
||||
|
||||
QVector<Footage*> imported_footage_;
|
||||
QList<QString> image_sequence_ignore_files_;
|
||||
|
||||
QVector<Footage *> imported_footage_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -25,29 +25,33 @@
|
||||
#include <QListWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectImportErrorDialog::ProjectImportErrorDialog(const QStringList& filenames, QWidget* parent) :
|
||||
QDialog(parent)
|
||||
namespace olive
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
|
||||
setWindowTitle(tr("Import Error"));
|
||||
ProjectImportErrorDialog::ProjectImportErrorDialog(const QStringList &filenames,
|
||||
QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(new QLabel(tr("The following files failed to import. Olive likely does not "
|
||||
"support their formats.")));
|
||||
setWindowTitle(tr("Import Error"));
|
||||
|
||||
QListWidget* list_widget = new QListWidget();
|
||||
foreach (const QString& s, filenames) {
|
||||
list_widget->addItem(s);
|
||||
}
|
||||
layout->addWidget(list_widget);
|
||||
layout->addWidget(new QLabel(
|
||||
tr("The following files failed to import. Olive likely does not "
|
||||
"support their formats.")));
|
||||
|
||||
QDialogButtonBox* buttons = new QDialogButtonBox();
|
||||
buttons->setStandardButtons(QDialogButtonBox::Ok);
|
||||
buttons->setCenterButtons(true);
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &ProjectImportErrorDialog::accept);
|
||||
layout->addWidget(buttons);
|
||||
QListWidget *list_widget = new QListWidget();
|
||||
foreach (const QString &s, filenames) {
|
||||
list_widget->addItem(s);
|
||||
}
|
||||
layout->addWidget(list_widget);
|
||||
|
||||
QDialogButtonBox *buttons = new QDialogButtonBox();
|
||||
buttons->setStandardButtons(QDialogButtonBox::Ok);
|
||||
buttons->setCenterButtons(true);
|
||||
connect(buttons, &QDialogButtonBox::accepted, this,
|
||||
&ProjectImportErrorDialog::accept);
|
||||
layout->addWidget(buttons);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ProjectImportErrorDialog : public QDialog
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectImportErrorDialog(const QStringList& filenames, QWidget* parent = nullptr);
|
||||
|
||||
class ProjectImportErrorDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectImportErrorDialog(const QStringList &filenames,
|
||||
QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,58 +24,65 @@
|
||||
|
||||
#include "node/project/serializer/serializer.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectLoadTask::ProjectLoadTask(const QString &filename) :
|
||||
ProjectLoadBaseTask(filename)
|
||||
ProjectLoadTask::ProjectLoadTask(const QString &filename)
|
||||
: ProjectLoadBaseTask(filename)
|
||||
{
|
||||
}
|
||||
|
||||
bool ProjectLoadTask::Run()
|
||||
{
|
||||
project_ = new Project();
|
||||
project_ = new Project();
|
||||
|
||||
project_->set_filename(GetFilename());
|
||||
project_->set_filename(GetFilename());
|
||||
|
||||
ProjectSerializer::Result result = ProjectSerializer::Load(project_, GetFilename(), ProjectSerializer::kProject);
|
||||
ProjectSerializer::Result result = ProjectSerializer::Load(
|
||||
project_, GetFilename(), ProjectSerializer::kProject);
|
||||
|
||||
layout_ = result.GetLoadData().layout;
|
||||
layout_ = result.GetLoadData().layout;
|
||||
|
||||
switch (result.code()) {
|
||||
case ProjectSerializer::kSuccess:
|
||||
break;
|
||||
case ProjectSerializer::kProjectTooOld:
|
||||
SetError(tr("This project is from a version of Olive that is no longer supported in this version."));
|
||||
break;
|
||||
case ProjectSerializer::kProjectTooNew:
|
||||
SetError(tr("This project is from a newer version of Olive and cannot be opened in this version."));
|
||||
break;
|
||||
case ProjectSerializer::kUnknownVersion:
|
||||
SetError(tr("Failed to determine project version."));
|
||||
break;
|
||||
case ProjectSerializer::kFileError:
|
||||
SetError(tr("Failed to read file \"%1\" for reading.").arg(GetFilename()));
|
||||
break;
|
||||
case ProjectSerializer::kXmlError:
|
||||
SetError(tr("Failed to read XML document. File may be corrupt. Error was: %1").arg(result.GetDetails()));
|
||||
break;
|
||||
case ProjectSerializer::kNoData:
|
||||
SetError(tr("Failed to find any data to parse."));
|
||||
break;
|
||||
switch (result.code()) {
|
||||
case ProjectSerializer::kSuccess:
|
||||
break;
|
||||
case ProjectSerializer::kProjectTooOld:
|
||||
SetError(tr(
|
||||
"This project is from a version of Olive that is no longer supported in this version."));
|
||||
break;
|
||||
case ProjectSerializer::kProjectTooNew:
|
||||
SetError(tr(
|
||||
"This project is from a newer version of Olive and cannot be opened in this version."));
|
||||
break;
|
||||
case ProjectSerializer::kUnknownVersion:
|
||||
SetError(tr("Failed to determine project version."));
|
||||
break;
|
||||
case ProjectSerializer::kFileError:
|
||||
SetError(
|
||||
tr("Failed to read file \"%1\" for reading.").arg(GetFilename()));
|
||||
break;
|
||||
case ProjectSerializer::kXmlError:
|
||||
SetError(
|
||||
tr("Failed to read XML document. File may be corrupt. Error was: %1")
|
||||
.arg(result.GetDetails()));
|
||||
break;
|
||||
case ProjectSerializer::kNoData:
|
||||
SetError(tr("Failed to find any data to parse."));
|
||||
break;
|
||||
|
||||
// Errors that should never be thrown by a load
|
||||
case ProjectSerializer::kOverwriteError:
|
||||
SetError(tr("Unknown error."));
|
||||
break;
|
||||
}
|
||||
// Errors that should never be thrown by a load
|
||||
case ProjectSerializer::kOverwriteError:
|
||||
SetError(tr("Unknown error."));
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == ProjectSerializer::kSuccess) {
|
||||
project_->moveToThread(qApp->thread());
|
||||
return true;
|
||||
} else {
|
||||
delete project_;
|
||||
return false;
|
||||
}
|
||||
if (result == ProjectSerializer::kSuccess) {
|
||||
project_->moveToThread(qApp->thread());
|
||||
return true;
|
||||
} else {
|
||||
delete project_;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,17 +24,16 @@
|
||||
#include "loadbasetask.h"
|
||||
#include "window/mainwindow/mainwindowlayoutinfo.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ProjectLoadTask : public ProjectLoadBaseTask
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class ProjectLoadTask : public ProjectLoadBaseTask {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectLoadTask(const QString& filename);
|
||||
ProjectLoadTask(const QString &filename);
|
||||
|
||||
protected:
|
||||
virtual bool Run() override;
|
||||
|
||||
virtual bool Run() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
|
||||
#include "loadbasetask.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectLoadBaseTask::ProjectLoadBaseTask(const QString &filename) :
|
||||
project_(nullptr),
|
||||
filename_(filename)
|
||||
namespace olive
|
||||
{
|
||||
SetTitle(tr("Loading '%1'").arg(filename));
|
||||
|
||||
ProjectLoadBaseTask::ProjectLoadBaseTask(const QString &filename)
|
||||
: project_(nullptr)
|
||||
, filename_(filename)
|
||||
{
|
||||
SetTitle(tr("Loading '%1'").arg(filename));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,37 +24,36 @@
|
||||
#include "node/project.h"
|
||||
#include "task/task.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ProjectLoadBaseTask : public Task
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class ProjectLoadBaseTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectLoadBaseTask(const QString& filename);
|
||||
ProjectLoadBaseTask(const QString &filename);
|
||||
|
||||
Project* GetLoadedProject() const
|
||||
{
|
||||
return project_;
|
||||
}
|
||||
Project *GetLoadedProject() const
|
||||
{
|
||||
return project_;
|
||||
}
|
||||
|
||||
const QString& GetFilename() const
|
||||
{
|
||||
return filename_;
|
||||
}
|
||||
const QString &GetFilename() const
|
||||
{
|
||||
return filename_;
|
||||
}
|
||||
|
||||
const MainWindowLayoutInfo &GetLoadedLayout() const
|
||||
{
|
||||
return layout_;
|
||||
}
|
||||
const MainWindowLayoutInfo &GetLoadedLayout() const
|
||||
{
|
||||
return layout_;
|
||||
}
|
||||
|
||||
protected:
|
||||
Project* project_;
|
||||
Project *project_;
|
||||
|
||||
MainWindowLayoutInfo layout_;
|
||||
MainWindowLayoutInfo layout_;
|
||||
|
||||
private:
|
||||
QString filename_;
|
||||
|
||||
QString filename_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -47,287 +47,327 @@
|
||||
#include "timeline/timelineundogeneral.h"
|
||||
#include "window/mainwindow/mainwindowundo.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
LoadOTIOTask::LoadOTIOTask(const QString& s) :
|
||||
ProjectLoadBaseTask(s)
|
||||
LoadOTIOTask::LoadOTIOTask(const QString &s)
|
||||
: ProjectLoadBaseTask(s)
|
||||
{
|
||||
}
|
||||
|
||||
bool LoadOTIOTask::Run()
|
||||
{
|
||||
OTIO::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
auto root = OTIO::SerializableObjectWithMetadata::from_json_file(GetFilename().toStdString(), &es);
|
||||
auto root = OTIO::SerializableObjectWithMetadata::from_json_file(
|
||||
GetFilename().toStdString(), &es);
|
||||
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
SetError(tr("Failed to load OpenTimelineIO from file \"%1\" \n\nOpenTimelineIO Error:\n\n%2")
|
||||
.arg(GetFilename(), QString::fromStdString(es.full_description)));
|
||||
return false;
|
||||
}
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
SetError(
|
||||
tr("Failed to load OpenTimelineIO from file \"%1\" \n\nOpenTimelineIO Error:\n\n%2")
|
||||
.arg(GetFilename(),
|
||||
QString::fromStdString(es.full_description)));
|
||||
return false;
|
||||
}
|
||||
|
||||
project_ = new Project();
|
||||
project_->Initialize();
|
||||
project_->set_modified(true);
|
||||
project_ = new Project();
|
||||
project_->Initialize();
|
||||
project_->set_modified(true);
|
||||
|
||||
std::vector<OTIO::Timeline*> timelines;
|
||||
std::vector<OTIO::Timeline *> timelines;
|
||||
|
||||
if (root->schema_name() == "SerializableCollection") {
|
||||
// This is a number of timelines
|
||||
std::vector<OTIO::SerializableObject::Retainer<OTIO::SerializableObject>>& root_children = static_cast<OTIO::SerializableCollection*>(root)->children();
|
||||
if (root->schema_name() == "SerializableCollection") {
|
||||
// This is a number of timelines
|
||||
std::vector<OTIO::SerializableObject::Retainer<OTIO::SerializableObject>>
|
||||
&root_children =
|
||||
static_cast<OTIO::SerializableCollection *>(root)->children();
|
||||
|
||||
timelines.resize(root_children.size());
|
||||
for (size_t j=0; j<root_children.size(); j++) {
|
||||
timelines[j] = static_cast<OTIO::Timeline*>(root_children[j].value);
|
||||
}
|
||||
} else if (root->schema_name() == "Timeline") {
|
||||
// This is a single timeline
|
||||
timelines.push_back(static_cast<OTIO::Timeline*>(root));
|
||||
} else {
|
||||
// Unknown root, we don't know what to do with this
|
||||
SetError(tr("Unknown OpenTimelineIO root element"));
|
||||
return false;
|
||||
}
|
||||
timelines.resize(root_children.size());
|
||||
for (size_t j = 0; j < root_children.size(); j++) {
|
||||
timelines[j] =
|
||||
static_cast<OTIO::Timeline *>(root_children[j].value);
|
||||
}
|
||||
} else if (root->schema_name() == "Timeline") {
|
||||
// This is a single timeline
|
||||
timelines.push_back(static_cast<OTIO::Timeline *>(root));
|
||||
} else {
|
||||
// Unknown root, we don't know what to do with this
|
||||
SetError(tr("Unknown OpenTimelineIO root element"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Keep track of imported footage
|
||||
QMap<QString, Footage*> imported_footage;
|
||||
QMap<OTIO::Timeline*, Sequence*> timeline_sequnce_map;
|
||||
// Keep track of imported footage
|
||||
QMap<QString, Footage *> imported_footage;
|
||||
QMap<OTIO::Timeline *, Sequence *> timeline_sequnce_map;
|
||||
|
||||
// Variables used for loading bar
|
||||
float number_of_clips = 0;
|
||||
float clips_done = 0;
|
||||
// Variables used for loading bar
|
||||
float number_of_clips = 0;
|
||||
float clips_done = 0;
|
||||
|
||||
// Generate a list of sequences with the same names as the timelines.
|
||||
// Assumes each timeline has a unique name.
|
||||
int unnamed_sequence_count = 0;
|
||||
foreach (auto timeline, timelines) {
|
||||
Sequence* sequence = new Sequence();
|
||||
if (!timeline->name().empty()) {
|
||||
sequence->SetLabel(QString::fromStdString(timeline->name()));
|
||||
} else {
|
||||
// If the otio timeline does not provide a name, create a default one here
|
||||
unnamed_sequence_count++;
|
||||
QString label = tr("Sequence %1").arg(unnamed_sequence_count);
|
||||
sequence->SetLabel(QString::fromStdString(label.toStdString()));
|
||||
}
|
||||
// Set default params incase they aren't edited.
|
||||
sequence->set_default_parameters();
|
||||
timeline_sequnce_map.insert(timeline, sequence);
|
||||
// Generate a list of sequences with the same names as the timelines.
|
||||
// Assumes each timeline has a unique name.
|
||||
int unnamed_sequence_count = 0;
|
||||
foreach (auto timeline, timelines) {
|
||||
Sequence *sequence = new Sequence();
|
||||
if (!timeline->name().empty()) {
|
||||
sequence->SetLabel(QString::fromStdString(timeline->name()));
|
||||
} else {
|
||||
// If the otio timeline does not provide a name, create a default one here
|
||||
unnamed_sequence_count++;
|
||||
QString label = tr("Sequence %1").arg(unnamed_sequence_count);
|
||||
sequence->SetLabel(QString::fromStdString(label.toStdString()));
|
||||
}
|
||||
// Set default params incase they aren't edited.
|
||||
sequence->set_default_parameters();
|
||||
timeline_sequnce_map.insert(timeline, sequence);
|
||||
|
||||
// Get number of clips for loading bar
|
||||
foreach (auto track, timeline->tracks()->children()) {
|
||||
auto otio_track = static_cast<OTIO::Track*>(track.value);
|
||||
number_of_clips += otio_track->children().size();
|
||||
}
|
||||
}
|
||||
// Get number of clips for loading bar
|
||||
foreach (auto track, timeline->tracks()->children()) {
|
||||
auto otio_track = static_cast<OTIO::Track *>(track.value);
|
||||
number_of_clips += otio_track->children().size();
|
||||
}
|
||||
}
|
||||
|
||||
// Dialog has to be called from the main thread so we pass the list of sequences here.
|
||||
bool accepted = false;
|
||||
QMetaObject::invokeMethod(Core::instance(),
|
||||
"DialogImportOTIOShow",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, accepted),
|
||||
Q_ARG(QList<Sequence*>,timeline_sequnce_map.values()));
|
||||
// Dialog has to be called from the main thread so we pass the list of sequences here.
|
||||
bool accepted = false;
|
||||
QMetaObject::invokeMethod(
|
||||
Core::instance(), "DialogImportOTIOShow", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, accepted),
|
||||
Q_ARG(QList<Sequence *>, timeline_sequnce_map.values()));
|
||||
|
||||
if (!accepted) {
|
||||
// Cancel to indicate to caller that this task did not complete and to simply dispose of it
|
||||
Cancel();
|
||||
qDeleteAll(timeline_sequnce_map); // Clear sequences
|
||||
return true;
|
||||
}
|
||||
if (!accepted) {
|
||||
// Cancel to indicate to caller that this task did not complete and to simply dispose of it
|
||||
Cancel();
|
||||
qDeleteAll(timeline_sequnce_map); // Clear sequences
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (auto timeline, timeline_sequnce_map.keys()) {
|
||||
Sequence* sequence = timeline_sequnce_map.value(timeline);
|
||||
sequence->setParent(project_);
|
||||
FolderAddChild(project_->root(), sequence).redo_now();
|
||||
foreach (auto timeline, timeline_sequnce_map.keys()) {
|
||||
Sequence *sequence = timeline_sequnce_map.value(timeline);
|
||||
sequence->setParent(project_);
|
||||
FolderAddChild(project_->root(), sequence).redo_now();
|
||||
|
||||
// Create a folder for this sequence's footage
|
||||
Folder* sequence_footage = new Folder();
|
||||
sequence_footage->SetLabel(QString::fromStdString(timeline->name()));
|
||||
sequence_footage->setParent(project_);
|
||||
FolderAddChild(project_->root(), sequence_footage).redo_now();
|
||||
// Create a folder for this sequence's footage
|
||||
Folder *sequence_footage = new Folder();
|
||||
sequence_footage->SetLabel(QString::fromStdString(timeline->name()));
|
||||
sequence_footage->setParent(project_);
|
||||
FolderAddChild(project_->root(), sequence_footage).redo_now();
|
||||
|
||||
// Iterate through tracks
|
||||
for (auto c : timeline->tracks()->children()) {
|
||||
auto otio_track = static_cast<OTIO::Track*>(c.value);
|
||||
// Iterate through tracks
|
||||
for (auto c : timeline->tracks()->children()) {
|
||||
auto otio_track = static_cast<OTIO::Track *>(c.value);
|
||||
|
||||
// Create a new track
|
||||
Track* track = nullptr;
|
||||
// Create a new track
|
||||
Track *track = nullptr;
|
||||
|
||||
// Determine what kind of track it is
|
||||
if (otio_track->kind() == "Video" || otio_track->kind() == "Audio") {
|
||||
Track::Type type;
|
||||
// Determine what kind of track it is
|
||||
if (otio_track->kind() == "Video" ||
|
||||
otio_track->kind() == "Audio") {
|
||||
Track::Type type;
|
||||
|
||||
if (otio_track->kind() == "Video") {
|
||||
type = Track::kVideo;
|
||||
} else {
|
||||
type = Track::kAudio;
|
||||
}
|
||||
if (otio_track->kind() == "Video") {
|
||||
type = Track::kVideo;
|
||||
} else {
|
||||
type = Track::kAudio;
|
||||
}
|
||||
|
||||
// Create track
|
||||
TimelineAddTrackCommand t(sequence->track_list(type));
|
||||
t.redo_now();
|
||||
track = t.track();
|
||||
} else {
|
||||
qWarning() << "Found unknown track type:" << otio_track->kind().c_str();
|
||||
continue;
|
||||
}
|
||||
// Create track
|
||||
TimelineAddTrackCommand t(sequence->track_list(type));
|
||||
t.redo_now();
|
||||
track = t.track();
|
||||
} else {
|
||||
qWarning() << "Found unknown track type:"
|
||||
<< otio_track->kind().c_str();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get clips from track
|
||||
auto clip_map = otio_track->children();
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
SetError(tr("Failed to load clip"));
|
||||
return false;
|
||||
}
|
||||
// Get clips from track
|
||||
auto clip_map = otio_track->children();
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
SetError(tr("Failed to load clip"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Block* previous_block = nullptr;
|
||||
bool prev_block_transition = false;
|
||||
Block *previous_block = nullptr;
|
||||
bool prev_block_transition = false;
|
||||
|
||||
for (auto otio_block_retainer : clip_map) {
|
||||
for (auto otio_block_retainer : clip_map) {
|
||||
auto otio_block = otio_block_retainer.value;
|
||||
|
||||
auto otio_block = otio_block_retainer.value;
|
||||
Block *block = nullptr;
|
||||
|
||||
Block* block = nullptr;
|
||||
if (otio_block->schema_name() == "Clip") {
|
||||
block = new ClipBlock();
|
||||
|
||||
if (otio_block->schema_name() == "Clip") {
|
||||
} else if (otio_block->schema_name() == "Gap") {
|
||||
block = new GapBlock();
|
||||
|
||||
block = new ClipBlock();
|
||||
} else if (otio_block->schema_name() == "Transition") {
|
||||
// Todo: Look into OTIO supported transitions and add them to Olive
|
||||
block = new CrossDissolveTransition();
|
||||
|
||||
} else if (otio_block->schema_name() == "Gap") {
|
||||
} else {
|
||||
// We don't know what this is yet, just create a gap for now so that *something* is there
|
||||
qWarning() << "Found unknown block type:"
|
||||
<< otio_block->schema_name().c_str();
|
||||
block = new GapBlock();
|
||||
}
|
||||
|
||||
block = new GapBlock();
|
||||
block->setParent(project_);
|
||||
block->SetLabel(QString::fromStdString(otio_block->name()));
|
||||
|
||||
} else if (otio_block->schema_name() == "Transition") {
|
||||
track->AppendBlock(block);
|
||||
|
||||
// Todo: Look into OTIO supported transitions and add them to Olive
|
||||
block = new CrossDissolveTransition();
|
||||
rational start_time;
|
||||
rational duration;
|
||||
|
||||
} else {
|
||||
if (otio_block->schema_name() == "Clip" ||
|
||||
otio_block->schema_name() == "Gap") {
|
||||
start_time = rational::fromDouble(
|
||||
static_cast<OTIO::Item *>(otio_block)
|
||||
->source_range()
|
||||
->start_time()
|
||||
.to_seconds());
|
||||
duration = rational::fromDouble(
|
||||
static_cast<OTIO::Item *>(otio_block)
|
||||
->source_range()
|
||||
->duration()
|
||||
.to_seconds());
|
||||
|
||||
// We don't know what this is yet, just create a gap for now so that *something* is there
|
||||
qWarning() << "Found unknown block type:" << otio_block->schema_name().c_str();
|
||||
block = new GapBlock();
|
||||
}
|
||||
if (otio_block->schema_name() == "Clip") {
|
||||
static_cast<ClipBlock *>(block)->set_media_in(
|
||||
start_time);
|
||||
}
|
||||
block->set_length_and_media_out(duration);
|
||||
}
|
||||
|
||||
block->setParent(project_);
|
||||
block->SetLabel(QString::fromStdString(otio_block->name()));
|
||||
// If the previous block was a transition, connect the current block to it
|
||||
if (prev_block_transition) {
|
||||
TransitionBlock *previous_transition_block =
|
||||
static_cast<TransitionBlock *>(previous_block);
|
||||
Node::ConnectEdge(
|
||||
block, NodeInput(previous_transition_block,
|
||||
TransitionBlock::kInBlockInput));
|
||||
prev_block_transition = false;
|
||||
}
|
||||
|
||||
track->AppendBlock(block);
|
||||
if (otio_block->schema_name() == "Transition") {
|
||||
TransitionBlock *transition_block =
|
||||
static_cast<TransitionBlock *>(block);
|
||||
OTIO::Transition *otio_block_transition =
|
||||
static_cast<OTIO::Transition *>(otio_block);
|
||||
|
||||
rational start_time;
|
||||
rational duration;
|
||||
// Set how far the transition eats into the previous clip
|
||||
transition_block->set_offsets_and_length(
|
||||
rational::fromRationalTime(
|
||||
otio_block_transition->in_offset()),
|
||||
rational::fromRationalTime(
|
||||
otio_block_transition->out_offset()));
|
||||
|
||||
if (otio_block->schema_name() == "Clip" || otio_block->schema_name() == "Gap") {
|
||||
start_time =
|
||||
rational::fromDouble(static_cast<OTIO::Item*>(otio_block)->source_range()->start_time().to_seconds());
|
||||
duration =
|
||||
rational::fromDouble(static_cast<OTIO::Item*>(otio_block)->source_range()->duration().to_seconds());
|
||||
if (previous_block) {
|
||||
Node::ConnectEdge(
|
||||
previous_block,
|
||||
NodeInput(transition_block,
|
||||
TransitionBlock::kOutBlockInput));
|
||||
}
|
||||
prev_block_transition = true;
|
||||
|
||||
if (otio_block->schema_name() == "Clip") {
|
||||
static_cast<ClipBlock*>(block)->set_media_in(start_time);
|
||||
}
|
||||
block->set_length_and_media_out(duration);
|
||||
}
|
||||
// Add nodes to the graph and set up contexts
|
||||
block->setParent(sequence->parent());
|
||||
|
||||
// If the previous block was a transition, connect the current block to it
|
||||
if (prev_block_transition) {
|
||||
TransitionBlock* previous_transition_block = static_cast<TransitionBlock*>(previous_block);
|
||||
Node::ConnectEdge(block, NodeInput(previous_transition_block, TransitionBlock::kInBlockInput));
|
||||
prev_block_transition = false;
|
||||
}
|
||||
// Position transition in its own context
|
||||
block->SetNodePositionInContext(block, QPointF(0, 0));
|
||||
}
|
||||
|
||||
if (otio_block->schema_name() == "Transition") {
|
||||
TransitionBlock* transition_block = static_cast<TransitionBlock*>(block);
|
||||
OTIO::Transition* otio_block_transition = static_cast<OTIO::Transition*>(otio_block);
|
||||
if (otio_block->schema_name() == "Gap") {
|
||||
// Add nodes to the graph and set up contexts
|
||||
block->setParent(sequence->parent());
|
||||
|
||||
// Set how far the transition eats into the previous clip
|
||||
transition_block->set_offsets_and_length(rational::fromRationalTime(otio_block_transition->in_offset()), rational::fromRationalTime(otio_block_transition->out_offset()));
|
||||
// Position transition in its own context
|
||||
block->SetNodePositionInContext(block, QPointF(0, 0));
|
||||
}
|
||||
|
||||
if (previous_block) {
|
||||
Node::ConnectEdge(previous_block, NodeInput(transition_block, TransitionBlock::kOutBlockInput));
|
||||
}
|
||||
prev_block_transition = true;
|
||||
// Update this after it's used but before any continue statements
|
||||
previous_block = block;
|
||||
|
||||
// Add nodes to the graph and set up contexts
|
||||
block->setParent(sequence->parent());
|
||||
if (otio_block->schema_name() == "Clip") {
|
||||
auto otio_clip = static_cast<OTIO::Clip *>(otio_block);
|
||||
if (!otio_clip->media_reference()) {
|
||||
continue;
|
||||
}
|
||||
if (otio_clip->media_reference()->schema_name() ==
|
||||
"ExternalReference") {
|
||||
// Link footage
|
||||
QString footage_url = QString::fromStdString(
|
||||
static_cast<OTIO::ExternalReference *>(
|
||||
otio_clip->media_reference())
|
||||
->target_url());
|
||||
|
||||
// Position transition in its own context
|
||||
block->SetNodePositionInContext(block, QPointF(0, 0));
|
||||
}
|
||||
Footage *probed_item;
|
||||
|
||||
if (otio_block->schema_name() == "Gap") {
|
||||
// Add nodes to the graph and set up contexts
|
||||
block->setParent(sequence->parent());
|
||||
if (imported_footage.contains(footage_url)) {
|
||||
probed_item = imported_footage.value(footage_url);
|
||||
} else {
|
||||
probed_item = new Footage(footage_url);
|
||||
imported_footage.insert(footage_url, probed_item);
|
||||
probed_item->setParent(project_);
|
||||
|
||||
// Position transition in its own context
|
||||
block->SetNodePositionInContext(block, QPointF(0, 0));
|
||||
}
|
||||
QFileInfo info(probed_item->filename());
|
||||
probed_item->SetLabel(info.fileName());
|
||||
|
||||
// Update this after it's used but before any continue statements
|
||||
previous_block = block;
|
||||
FolderAddChild add(sequence_footage, probed_item);
|
||||
add.redo_now();
|
||||
}
|
||||
|
||||
if (otio_block->schema_name() == "Clip") {
|
||||
auto otio_clip = static_cast<OTIO::Clip*>(otio_block);
|
||||
if (!otio_clip->media_reference()) {
|
||||
continue;
|
||||
}
|
||||
if (otio_clip->media_reference()->schema_name() == "ExternalReference") {
|
||||
// Link footage
|
||||
QString footage_url = QString::fromStdString(static_cast<OTIO::ExternalReference*>(otio_clip->media_reference())->target_url());
|
||||
// Add nodes to the graph and set up contexts
|
||||
block->setParent(sequence->parent());
|
||||
|
||||
Footage* probed_item;
|
||||
// Position clip in its own context
|
||||
block->SetNodePositionInContext(block, QPointF(0, 0));
|
||||
|
||||
if (imported_footage.contains(footage_url)) {
|
||||
probed_item = imported_footage.value(footage_url);
|
||||
} else {
|
||||
probed_item = new Footage(footage_url);
|
||||
imported_footage.insert(footage_url, probed_item);
|
||||
probed_item->setParent(project_);
|
||||
// Position footage in its context
|
||||
block->SetNodePositionInContext(probed_item,
|
||||
QPointF(-2, 0));
|
||||
|
||||
if (track->type() == Track::kVideo) {
|
||||
TransformDistortNode *transform =
|
||||
new TransformDistortNode();
|
||||
transform->setParent(sequence->parent());
|
||||
|
||||
QFileInfo info(probed_item->filename());
|
||||
probed_item->SetLabel(info.fileName());
|
||||
Node::ConnectEdge(
|
||||
probed_item,
|
||||
NodeInput(transform,
|
||||
TransformDistortNode::kTextureInput));
|
||||
Node::ConnectEdge(transform,
|
||||
NodeInput(block,
|
||||
ClipBlock::kBufferIn));
|
||||
block->SetNodePositionInContext(transform,
|
||||
QPointF(-1, 0));
|
||||
} else {
|
||||
VolumeNode *volume_node = new VolumeNode();
|
||||
volume_node->setParent(sequence->parent());
|
||||
|
||||
FolderAddChild add(sequence_footage, probed_item);
|
||||
add.redo_now();
|
||||
}
|
||||
Node::ConnectEdge(
|
||||
probed_item,
|
||||
NodeInput(volume_node,
|
||||
VolumeNode::kSamplesInput));
|
||||
Node::ConnectEdge(volume_node,
|
||||
NodeInput(block,
|
||||
ClipBlock::kBufferIn));
|
||||
block->SetNodePositionInContext(volume_node,
|
||||
QPointF(-1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
clips_done++;
|
||||
emit ProgressChanged(clips_done / number_of_clips);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add nodes to the graph and set up contexts
|
||||
block->setParent(sequence->parent());
|
||||
project_->moveToThread(qApp->thread());
|
||||
|
||||
// Position clip in its own context
|
||||
block->SetNodePositionInContext(block, QPointF(0, 0));
|
||||
|
||||
// Position footage in its context
|
||||
block->SetNodePositionInContext(probed_item, QPointF(-2, 0));
|
||||
|
||||
|
||||
if (track->type() == Track::kVideo) {
|
||||
TransformDistortNode* transform = new TransformDistortNode();
|
||||
transform->setParent(sequence->parent());
|
||||
|
||||
Node::ConnectEdge(probed_item, NodeInput(transform, TransformDistortNode::kTextureInput));
|
||||
Node::ConnectEdge(transform, NodeInput(block, ClipBlock::kBufferIn));
|
||||
block->SetNodePositionInContext(transform, QPointF(-1, 0));
|
||||
} else {
|
||||
VolumeNode* volume_node = new VolumeNode();
|
||||
volume_node->setParent(sequence->parent());
|
||||
|
||||
Node::ConnectEdge(probed_item, NodeInput(volume_node, VolumeNode::kSamplesInput));
|
||||
Node::ConnectEdge(volume_node, NodeInput(block, ClipBlock::kBufferIn));
|
||||
block->SetNodePositionInContext(volume_node, QPointF(-1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
clips_done++;
|
||||
emit ProgressChanged(clips_done / number_of_clips);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project_->moveToThread(qApp->thread());
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,17 +27,16 @@
|
||||
#include "node/project.h"
|
||||
#include "task/project/load/loadbasetask.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class LoadOTIOTask : public ProjectLoadBaseTask
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class LoadOTIOTask : public ProjectLoadBaseTask {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LoadOTIOTask(const QString& filename);
|
||||
LoadOTIOTask(const QString &filename);
|
||||
|
||||
protected:
|
||||
virtual bool Run() override;
|
||||
|
||||
virtual bool Run() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -28,55 +28,61 @@
|
||||
#include "core.h"
|
||||
#include "node/project/serializer/serializer.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ProjectSaveTask::ProjectSaveTask(Project *project, bool use_compression) :
|
||||
project_(project),
|
||||
use_compression_(use_compression)
|
||||
namespace olive
|
||||
{
|
||||
SetTitle(tr("Saving '%1'").arg(project->filename()));
|
||||
|
||||
ProjectSaveTask::ProjectSaveTask(Project *project, bool use_compression)
|
||||
: project_(project)
|
||||
, use_compression_(use_compression)
|
||||
{
|
||||
SetTitle(tr("Saving '%1'").arg(project->filename()));
|
||||
}
|
||||
|
||||
bool ProjectSaveTask::Run()
|
||||
{
|
||||
QString using_filename = override_filename_.isEmpty() ? project_->filename() : override_filename_;
|
||||
QString using_filename = override_filename_.isEmpty() ?
|
||||
project_->filename() :
|
||||
override_filename_;
|
||||
|
||||
ProjectSerializer::SaveData data(ProjectSerializer::kProject);
|
||||
ProjectSerializer::SaveData data(ProjectSerializer::kProject);
|
||||
|
||||
data.SetFilename(using_filename);
|
||||
data.SetProject(project_);
|
||||
data.SetLayout(layout_);
|
||||
data.SetFilename(using_filename);
|
||||
data.SetProject(project_);
|
||||
data.SetLayout(layout_);
|
||||
|
||||
ProjectSerializer::Result result = ProjectSerializer::Save(data, use_compression_);
|
||||
ProjectSerializer::Result result =
|
||||
ProjectSerializer::Save(data, use_compression_);
|
||||
|
||||
bool success = false;
|
||||
bool success = false;
|
||||
|
||||
switch (result.code()) {
|
||||
case ProjectSerializer::kSuccess:
|
||||
success = true;
|
||||
break;
|
||||
case ProjectSerializer::kXmlError:
|
||||
SetError(tr("Failed to write XML data."));
|
||||
break;
|
||||
case ProjectSerializer::kFileError:
|
||||
SetError(tr("Failed to open file \"%1\" for writing.").arg(result.GetDetails()));
|
||||
break;
|
||||
case ProjectSerializer::kOverwriteError:
|
||||
SetError(tr("Failed to overwrite \"%1\". Project has been saved as \"%2\" instead.")
|
||||
.arg(using_filename, result.GetDetails()));
|
||||
success = true;
|
||||
break;
|
||||
switch (result.code()) {
|
||||
case ProjectSerializer::kSuccess:
|
||||
success = true;
|
||||
break;
|
||||
case ProjectSerializer::kXmlError:
|
||||
SetError(tr("Failed to write XML data."));
|
||||
break;
|
||||
case ProjectSerializer::kFileError:
|
||||
SetError(tr("Failed to open file \"%1\" for writing.")
|
||||
.arg(result.GetDetails()));
|
||||
break;
|
||||
case ProjectSerializer::kOverwriteError:
|
||||
SetError(
|
||||
tr("Failed to overwrite \"%1\". Project has been saved as \"%2\" instead.")
|
||||
.arg(using_filename, result.GetDetails()));
|
||||
success = true;
|
||||
break;
|
||||
|
||||
// Errors that should never be thrown by a save
|
||||
case ProjectSerializer::kProjectTooNew:
|
||||
case ProjectSerializer::kProjectTooOld:
|
||||
case ProjectSerializer::kUnknownVersion:
|
||||
case ProjectSerializer::kNoData:
|
||||
SetError(tr("Unknown error."));
|
||||
break;
|
||||
}
|
||||
// Errors that should never be thrown by a save
|
||||
case ProjectSerializer::kProjectTooNew:
|
||||
case ProjectSerializer::kProjectTooOld:
|
||||
case ProjectSerializer::kUnknownVersion:
|
||||
case ProjectSerializer::kNoData:
|
||||
SetError(tr("Unknown error."));
|
||||
break;
|
||||
}
|
||||
|
||||
return success;
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,41 +24,40 @@
|
||||
#include "node/project.h"
|
||||
#include "task/task.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ProjectSaveTask : public Task
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class ProjectSaveTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectSaveTask(Project* project, bool use_compression);
|
||||
ProjectSaveTask(Project *project, bool use_compression);
|
||||
|
||||
Project* GetProject() const
|
||||
{
|
||||
return project_;
|
||||
}
|
||||
Project *GetProject() const
|
||||
{
|
||||
return project_;
|
||||
}
|
||||
|
||||
void SetOverrideFilename(const QString& filename)
|
||||
{
|
||||
override_filename_ = filename;
|
||||
}
|
||||
void SetOverrideFilename(const QString &filename)
|
||||
{
|
||||
override_filename_ = filename;
|
||||
}
|
||||
|
||||
void SetLayout(const MainWindowLayoutInfo &layout)
|
||||
{
|
||||
layout_ = layout;
|
||||
}
|
||||
void SetLayout(const MainWindowLayoutInfo &layout)
|
||||
{
|
||||
layout_ = layout;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool Run() override;
|
||||
virtual bool Run() override;
|
||||
|
||||
private:
|
||||
Project* project_;
|
||||
Project *project_;
|
||||
|
||||
QString override_filename_;
|
||||
QString override_filename_;
|
||||
|
||||
bool use_compression_;
|
||||
|
||||
MainWindowLayoutInfo layout_;
|
||||
bool use_compression_;
|
||||
|
||||
MainWindowLayoutInfo layout_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -34,213 +34,242 @@
|
||||
#include "node/block/transition/transition.h"
|
||||
#include "node/project/footage/footage.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
SaveOTIOTask::SaveOTIOTask(Project *project) :
|
||||
project_(project)
|
||||
namespace olive
|
||||
{
|
||||
SetTitle(tr("Exporting project to OpenTimelineIO"));
|
||||
|
||||
SaveOTIOTask::SaveOTIOTask(Project *project)
|
||||
: project_(project)
|
||||
{
|
||||
SetTitle(tr("Exporting project to OpenTimelineIO"));
|
||||
}
|
||||
|
||||
bool SaveOTIOTask::Run()
|
||||
{
|
||||
QVector<Sequence*> sequences = project_->root()->ListChildrenOfType<Sequence>();
|
||||
QVector<Sequence *> sequences =
|
||||
project_->root()->ListChildrenOfType<Sequence>();
|
||||
|
||||
if (sequences.isEmpty()) {
|
||||
SetError(tr("Project contains no sequences to export."));
|
||||
return false;
|
||||
}
|
||||
if (sequences.isEmpty()) {
|
||||
SetError(tr("Project contains no sequences to export."));
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<OTIO::SerializableObject*> serialized;
|
||||
std::vector<OTIO::SerializableObject *> serialized;
|
||||
|
||||
foreach (Sequence* seq, sequences) {
|
||||
auto otio_timeline = SerializeTimeline(seq);
|
||||
foreach (Sequence *seq, sequences) {
|
||||
auto otio_timeline = SerializeTimeline(seq);
|
||||
|
||||
if (otio_timeline) {
|
||||
// Append to list
|
||||
serialized.push_back(otio_timeline);
|
||||
} else {
|
||||
// Delete all existing timelines
|
||||
foreach (auto s, serialized) {
|
||||
s->possibly_delete();
|
||||
}
|
||||
if (otio_timeline) {
|
||||
// Append to list
|
||||
serialized.push_back(otio_timeline);
|
||||
} else {
|
||||
// Delete all existing timelines
|
||||
foreach (auto s, serialized) {
|
||||
s->possibly_delete();
|
||||
}
|
||||
|
||||
// Error out of function
|
||||
SetError(tr("Failed to serialize sequence \"%1\"").arg(seq->GetLabel()));
|
||||
// Error out of function
|
||||
SetError(
|
||||
tr("Failed to serialize sequence \"%1\"").arg(seq->GetLabel()));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
OTIO::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
if (serialized.size() == 1) {
|
||||
// Serialize timeline on its own
|
||||
auto t = serialized.front();
|
||||
t->to_json_file(project_->filename().toStdString(), &es);
|
||||
t->possibly_delete();
|
||||
} else {
|
||||
// Serialize all into a SerializableCollection
|
||||
auto collection = new OTIO::SerializableCollection("Sequences", serialized);
|
||||
collection->to_json_file(project_->filename().toStdString(), &es);
|
||||
collection->possibly_delete();
|
||||
if (serialized.size() == 1) {
|
||||
// Serialize timeline on its own
|
||||
auto t = serialized.front();
|
||||
t->to_json_file(project_->filename().toStdString(), &es);
|
||||
t->possibly_delete();
|
||||
} else {
|
||||
// Serialize all into a SerializableCollection
|
||||
auto collection =
|
||||
new OTIO::SerializableCollection("Sequences", serialized);
|
||||
collection->to_json_file(project_->filename().toStdString(), &es);
|
||||
collection->possibly_delete();
|
||||
|
||||
// Delete all existing timelines
|
||||
foreach (auto s, serialized) {
|
||||
s->possibly_delete();
|
||||
}
|
||||
}
|
||||
// Delete all existing timelines
|
||||
foreach (auto s, serialized) {
|
||||
s->possibly_delete();
|
||||
}
|
||||
}
|
||||
|
||||
return (es.outcome == OTIO::ErrorStatus::Outcome::OK);
|
||||
return (es.outcome == OTIO::ErrorStatus::Outcome::OK);
|
||||
}
|
||||
|
||||
OTIO::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequence)
|
||||
{
|
||||
auto otio_timeline = new OTIO::Timeline(sequence->GetLabel().toStdString());
|
||||
// Retainers clean themselves up when the final user is removed
|
||||
OTIO::Timeline::Retainer<OTIO::Timeline>* timeline_retainer = new OTIO::Timeline::Retainer<OTIO::Timeline>(otio_timeline);
|
||||
// Suppress unused variable warning
|
||||
Q_UNUSED(timeline_retainer);
|
||||
auto otio_timeline = new OTIO::Timeline(sequence->GetLabel().toStdString());
|
||||
// Retainers clean themselves up when the final user is removed
|
||||
OTIO::Timeline::Retainer<OTIO::Timeline> *timeline_retainer =
|
||||
new OTIO::Timeline::Retainer<OTIO::Timeline>(otio_timeline);
|
||||
// Suppress unused variable warning
|
||||
Q_UNUSED(timeline_retainer);
|
||||
|
||||
double rate = sequence->GetVideoParams().frame_rate().toDouble();
|
||||
if (qIsNaN(rate)) {
|
||||
return nullptr;
|
||||
}
|
||||
double rate = sequence->GetVideoParams().frame_rate().toDouble();
|
||||
if (qIsNaN(rate)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SerializeTrackList(sequence->track_list(Track::kVideo), otio_timeline, rate)
|
||||
|| !SerializeTrackList(sequence->track_list(Track::kAudio), otio_timeline, rate)) {
|
||||
otio_timeline->possibly_delete();
|
||||
return nullptr;
|
||||
}
|
||||
if (!SerializeTrackList(sequence->track_list(Track::kVideo), otio_timeline,
|
||||
rate) ||
|
||||
!SerializeTrackList(sequence->track_list(Track::kAudio), otio_timeline,
|
||||
rate)) {
|
||||
otio_timeline->possibly_delete();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return otio_timeline;
|
||||
return otio_timeline;
|
||||
}
|
||||
|
||||
OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track, double sequence_rate, rational max_track_length)
|
||||
OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track, double sequence_rate,
|
||||
rational max_track_length)
|
||||
{
|
||||
auto otio_track = new OTIO::Track();
|
||||
auto otio_track = new OTIO::Track();
|
||||
|
||||
OTIO::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
switch (track->type()) {
|
||||
case Track::kVideo:
|
||||
otio_track->set_kind("Video");
|
||||
break;
|
||||
case Track::kAudio:
|
||||
otio_track->set_kind("Audio");
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Don't know OTIO track kind for native type" << track->type();
|
||||
goto fail;
|
||||
}
|
||||
switch (track->type()) {
|
||||
case Track::kVideo:
|
||||
otio_track->set_kind("Video");
|
||||
break;
|
||||
case Track::kAudio:
|
||||
otio_track->set_kind("Audio");
|
||||
break;
|
||||
default:
|
||||
qWarning()
|
||||
<< "Don't know OTIO track kind for native type" << track->type();
|
||||
goto fail;
|
||||
}
|
||||
|
||||
foreach (Block* block, track->Blocks()) {
|
||||
OTIO::Composable* otio_block = nullptr;
|
||||
foreach (Block *block, track->Blocks()) {
|
||||
OTIO::Composable *otio_block = nullptr;
|
||||
|
||||
if (dynamic_cast<ClipBlock*>(block)) {
|
||||
auto otio_clip = new OTIO::Clip(block->GetLabel().toStdString());
|
||||
if (dynamic_cast<ClipBlock *>(block)) {
|
||||
auto otio_clip = new OTIO::Clip(block->GetLabel().toStdString());
|
||||
|
||||
otio_clip->set_source_range(OTIO::TimeRange(block->in().toRationalTime(sequence_rate),
|
||||
block->length().toRationalTime(sequence_rate)));
|
||||
otio_clip->set_source_range(
|
||||
OTIO::TimeRange(block->in().toRationalTime(sequence_rate),
|
||||
block->length().toRationalTime(sequence_rate)));
|
||||
|
||||
QVector<Footage*> media_nodes = block->FindInputNodes<Footage>();
|
||||
if (!media_nodes.isEmpty()) {
|
||||
QVector<Footage *> media_nodes = block->FindInputNodes<Footage>();
|
||||
if (!media_nodes.isEmpty()) {
|
||||
OTIO::TimeRange available_range;
|
||||
if (otio_track->kind().compare("Video") == 0) {
|
||||
// OTIO ExternalReference uses the source clips frame rate (or sample rate) as opposed to
|
||||
// the sequences rate
|
||||
double source_frame_rate = static_cast<ClipBlock *>(block)
|
||||
->connected_viewer()
|
||||
->GetVideoParams()
|
||||
.frame_rate()
|
||||
.toDouble();
|
||||
available_range = OTIO::TimeRange(
|
||||
OTIO::RationalTime(0, source_frame_rate),
|
||||
OTIO::RationalTime(
|
||||
media_nodes.first()->GetVideoParams().duration(),
|
||||
source_frame_rate));
|
||||
} else if (otio_track->kind().compare("Audio") == 0) {
|
||||
available_range = OTIO::TimeRange(
|
||||
OTIO::RationalTime(
|
||||
0,
|
||||
media_nodes.first()->GetAudioParams().sample_rate()),
|
||||
OTIO::RationalTime(
|
||||
media_nodes.first()->GetAudioParams().duration(),
|
||||
media_nodes.first()->GetAudioParams().sample_rate()));
|
||||
}
|
||||
auto media_ref = new OTIO::ExternalReference(
|
||||
media_nodes.first()->filename().toStdString(),
|
||||
available_range);
|
||||
otio_clip->set_media_reference(media_ref);
|
||||
}
|
||||
|
||||
OTIO::TimeRange available_range;
|
||||
if (otio_track->kind().compare("Video") == 0) {
|
||||
// OTIO ExternalReference uses the source clips frame rate (or sample rate) as opposed to
|
||||
// the sequences rate
|
||||
double source_frame_rate = static_cast<ClipBlock*>(block)->connected_viewer()->GetVideoParams().frame_rate().toDouble();
|
||||
available_range = OTIO::TimeRange(OTIO::RationalTime(0, source_frame_rate),
|
||||
OTIO::RationalTime(media_nodes.first()->GetVideoParams().duration(),
|
||||
source_frame_rate));
|
||||
} else if (otio_track->kind().compare("Audio") == 0) {
|
||||
available_range = OTIO::TimeRange(OTIO::RationalTime(0, media_nodes.first()->GetAudioParams().sample_rate()),
|
||||
OTIO::RationalTime(media_nodes.first()->GetAudioParams().duration(),
|
||||
media_nodes.first()->GetAudioParams().sample_rate()));
|
||||
}
|
||||
auto media_ref = new OTIO::ExternalReference(media_nodes.first()->filename().toStdString(), available_range);
|
||||
otio_clip->set_media_reference(media_ref);
|
||||
}
|
||||
otio_block = otio_clip;
|
||||
} else if (dynamic_cast<GapBlock *>(block)) {
|
||||
otio_block =
|
||||
new OTIO::Gap(OTIO::TimeRange(block->in().toRationalTime(),
|
||||
block->length().toRationalTime()),
|
||||
block->GetLabel().toStdString());
|
||||
} else if (dynamic_cast<TransitionBlock *>(block)) {
|
||||
auto otio_transition =
|
||||
new OTIO::Transition(block->GetLabel().toStdString());
|
||||
|
||||
otio_block = otio_clip;
|
||||
} else if (dynamic_cast<GapBlock*>(block)) {
|
||||
otio_block = new OTIO::Gap(OTIO::TimeRange(block->in().toRationalTime(),
|
||||
block->length().toRationalTime()),
|
||||
block->GetLabel().toStdString()
|
||||
);
|
||||
} else if (dynamic_cast<TransitionBlock*>(block)) {
|
||||
auto otio_transition = new OTIO::Transition(block->GetLabel().toStdString());
|
||||
TransitionBlock *our_transition =
|
||||
static_cast<TransitionBlock *>(block);
|
||||
|
||||
TransitionBlock* our_transition = static_cast<TransitionBlock*>(block);
|
||||
otio_transition->set_in_offset(
|
||||
our_transition->in_offset().toRationalTime());
|
||||
otio_transition->set_out_offset(
|
||||
our_transition->out_offset().toRationalTime());
|
||||
|
||||
otio_transition->set_in_offset(our_transition->in_offset().toRationalTime());
|
||||
otio_transition->set_out_offset(our_transition->out_offset().toRationalTime());
|
||||
otio_block = new OTIO::Transition();
|
||||
}
|
||||
|
||||
otio_block = new OTIO::Transition();
|
||||
}
|
||||
if (!otio_block) {
|
||||
// We shouldn't ever get here, but catch without crashing if we ever do
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!otio_block) {
|
||||
// We shouldn't ever get here, but catch without crashing if we ever do
|
||||
goto fail;
|
||||
}
|
||||
otio_track->append_child(otio_block, &es);
|
||||
|
||||
otio_track->append_child(otio_block, &es);
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
// All OTIO tracks must have the same duration so we add a Gap to fill the remaining time
|
||||
if (otio_track->duration(&es).to_seconds() < max_track_length.toDouble()) {
|
||||
double time_left = max_track_length.toDouble() -
|
||||
otio_track->duration(&es).to_seconds();
|
||||
|
||||
// All OTIO tracks must have the same duration so we add a Gap to fill the remaining time
|
||||
if (otio_track->duration(&es).to_seconds() < max_track_length.toDouble()) {
|
||||
double time_left = max_track_length.toDouble() - otio_track->duration(&es).to_seconds();
|
||||
OTIO::Gap *gap = new OTIO::Gap(OTIO::TimeRange(
|
||||
otio_track->duration(&es), OTIO::RationalTime(time_left, 1.0)));
|
||||
otio_track->append_child(gap, &es);
|
||||
|
||||
OTIO::Gap* gap = new OTIO::Gap(OTIO::TimeRange(otio_track->duration(&es),
|
||||
OTIO::RationalTime(time_left, 1.0)));
|
||||
otio_track->append_child(gap, &es);
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return otio_track;
|
||||
return otio_track;
|
||||
|
||||
fail:
|
||||
otio_track->possibly_delete();
|
||||
otio_track->possibly_delete();
|
||||
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SaveOTIOTask::SerializeTrackList(TrackList *list, OTIO::Timeline* otio_timeline, double sequence_rate)
|
||||
bool SaveOTIOTask::SerializeTrackList(TrackList *list,
|
||||
OTIO::Timeline *otio_timeline,
|
||||
double sequence_rate)
|
||||
{
|
||||
OTIO::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
rational max_track_length = RATIONAL_MIN;
|
||||
rational max_track_length = RATIONAL_MIN;
|
||||
|
||||
foreach (Track* track, list->GetTracks()) {
|
||||
if (track->track_length() > max_track_length) {
|
||||
max_track_length = track->track_length();
|
||||
}
|
||||
}
|
||||
foreach (Track *track, list->GetTracks()) {
|
||||
if (track->track_length() > max_track_length) {
|
||||
max_track_length = track->track_length();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Track* track, list->GetTracks()) {
|
||||
auto otio_track = SerializeTrack(track, sequence_rate, max_track_length);
|
||||
foreach (Track *track, list->GetTracks()) {
|
||||
auto otio_track =
|
||||
SerializeTrack(track, sequence_rate, max_track_length);
|
||||
|
||||
if (!otio_track) {
|
||||
return false;
|
||||
}
|
||||
if (!otio_track) {
|
||||
return false;
|
||||
}
|
||||
|
||||
otio_timeline->tracks()->append_child(otio_track, &es);
|
||||
otio_timeline->tracks()->append_child(otio_track, &es);
|
||||
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
otio_track->possibly_delete();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
|
||||
otio_track->possibly_delete();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,26 +30,27 @@
|
||||
#include "node/project.h"
|
||||
#include "task/task.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SaveOTIOTask : public Task
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class SaveOTIOTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SaveOTIOTask(Project* project);
|
||||
SaveOTIOTask(Project *project);
|
||||
|
||||
protected:
|
||||
virtual bool Run() override;
|
||||
virtual bool Run() override;
|
||||
|
||||
private:
|
||||
OTIO::Timeline* SerializeTimeline(Sequence* sequence);
|
||||
OTIO::Timeline *SerializeTimeline(Sequence *sequence);
|
||||
|
||||
OTIO::Track* SerializeTrack(Track* track, double sequence_rate, rational max_track_length);
|
||||
OTIO::Track *SerializeTrack(Track *track, double sequence_rate,
|
||||
rational max_track_length);
|
||||
|
||||
bool SerializeTrackList(TrackList* list, OTIO::Timeline *otio_timeline, double sequence_rate);
|
||||
|
||||
Project* project_;
|
||||
bool SerializeTrackList(TrackList *list, OTIO::Timeline *otio_timeline,
|
||||
double sequence_rate);
|
||||
|
||||
Project *project_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user