change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+261 -221
View File
@@ -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;
}
}