Skip to content

Commit

Permalink
Merge branch 'test_merge' into test_edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Oct 22, 2023
2 parents d5fdb50 + 8e82e92 commit 30eb1e7
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 127 deletions.
127 changes: 63 additions & 64 deletions mrv2/lib/mrvEdit/mrvEditCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace fs = std::filesystem;
#include "mrvDraw/Annotation.h"

#include "mrvNetwork/mrvTCP.h"
#include "mrvNetwork/mrvInsertData.h"
#include "mrvNetwork/mrvMoveData.h"

#include "mrvPanels/mrvPanelsCallbacks.h"

Expand Down Expand Up @@ -1257,7 +1257,7 @@ namespace mrv
refresh_file_cache_cb(nullptr, ui);
}

void shiftAnnotations(
void moveAnnotations(
const otime::TimeRange& range, const otime::RationalTime& insertTime,
const bool previous, ViewerUI* ui)
{
Expand All @@ -1268,33 +1268,26 @@ namespace mrv
if (!player)
return;

// First, deep copy the annotations.
const auto& originalAnnotations = player->getAllAnnotations();
auto annotations = deepCopyAnnotations(originalAnnotations);

// Then, adjust the annotations within the range.
std::set<std::shared_ptr<draw::Annotation>> skipAnnotations;
for (auto& annotation : annotations)
for (auto annotation : annotations)
{
if (annotation->allFrames)
continue;

if (range.contains(annotation->time))
{
auto offset = annotation->time - range.start_time();
if (previous)
{
annotation->time =
insertTime + offset - range.end_time_exclusive();
}
else
{
annotation->time = insertTime + offset;
}
annotation->time = insertTime + offset;
skipAnnotations.insert(annotation);
}
}

// Finally, shift the annotations.
// Finally, move the annotations.
if (previous)
{
for (auto annotation : annotations)
Expand All @@ -1314,7 +1307,7 @@ namespace mrv
else
{
auto endTime = range.end_time_exclusive();
for (auto& annotation : annotations)
for (auto annotation : annotations)
{
if (annotation->allFrames)
continue;
Expand Down Expand Up @@ -1833,8 +1826,8 @@ namespace mrv
tcp->unlock();
}

void edit_insert_clip_annotations(
const std::vector<mrv::InsertData>& inserts, ViewerUI* ui)
void edit_move_clip_annotations(
const std::vector<mrv::MoveData>& moves, ViewerUI* ui)
{
auto player = ui->uiView->getTimelinePlayer();
if (!player)
Expand All @@ -1852,131 +1845,137 @@ namespace mrv

const auto& stack = timeline->tracks();
const auto& tracks = stack->children();
for (const auto& insert : inserts)
for (const auto& move : moves)
{
const int oldIndex = insert.oldIndex;
const int oldTrackIndex = insert.oldTrackIndex;
if (oldIndex < 0 || oldTrackIndex < 0 || insert.trackIndex < 0 ||
insert.trackIndex >= tracks.size())
if (move.fromTrack < 0 || move.fromTrack >= tracks.size() ||
move.toTrack < 0 || move.toTrack >= tracks.size())
continue;

if (auto track = otio::dynamic_retainer_cast<otio::Track>(
stack->children()[oldTrackIndex]))
stack->children()[move.fromTrack]))
{
if (track->kind() != otio::Track::Kind::video)
continue;
}

int insertIndex = insert.insertIndex;
if (oldTrackIndex == insert.trackIndex && oldIndex < insertIndex)
int toIndex = move.toIndex;
if (move.fromTrack == move.toTrack && move.fromIndex < toIndex)
{
--insertIndex;
--toIndex;
}

if (auto track = otio::dynamic_retainer_cast<otio::Track>(
tracks[oldTrackIndex]))
tracks[move.fromTrack]))
{
auto child = track->children()[oldIndex];
auto child = track->children()[move.fromIndex];
auto item = otio::dynamic_retainer_cast<otio::Item>(child);
if (!item)
continue;

auto oldRange = item->trimmed_range_in_parent().value();
auto fromRange = item->trimmed_range_in_parent().value();

if (auto track = otio::dynamic_retainer_cast<otio::Track>(
tracks[insert.trackIndex]))
tracks[move.toTrack]))
{
auto child = track->children()[insertIndex];
auto child = track->children()[toIndex];
auto item = otio::dynamic_retainer_cast<otio::Item>(child);
if (!item)
continue;

auto insertRange = item->trimmed_range_in_parent().value();
auto toRange = item->trimmed_range_in_parent().value();

otime::RationalTime insertTime;
bool previous = insertIndex > oldIndex;
bool previous = toIndex > move.fromIndex;
if (previous)
{
insertTime = insertRange.end_time_exclusive();
insertTime =
toRange.end_time_exclusive() - fromRange.duration();
}
else
{
insertTime = insertRange.start_time();
insertTime = toRange.start_time();
}

//
// Shift annotations
//
shiftAnnotations(oldRange, insertTime, previous, ui);
// std::cerr << "---------------------------------------"
// << std::endl;
// std::cerr << "IS PREV: " << previous << std::endl;
// std::cerr << " FROM: " << move.fromIndex << " "
// << fromRange << std::endl;
// std::cerr << " TO: " << move.toIndex
// << " RANGE: " << toRange << std::endl;
// std::cerr << "CORR.TO: " << toIndex << " RANGE: " <<
// toRange
// << std::endl;
// std::cerr << " PREV: " << previousRange << std::endl;
// std::cerr << " TO: " << insertTime << std::endl;
moveAnnotations(fromRange, insertTime, previous, ui);
}
}
}

ui->uiTimeline->redraw();
}

void
edit_insert_clip(const std::vector<mrv::InsertData>& inserts, ViewerUI* ui)
void edit_move_clip(const std::vector<mrv::MoveData>& moves, ViewerUI* ui)
{
auto player = ui->uiView->getTimelinePlayer();
if (!player)
return;

std::vector<tl::timeline::InsertData> insertData;
std::vector<tl::timeline::MoveData> moveData;
const auto& timeline = player->getTimeline();
const auto& stack = timeline->tracks();
const auto& tracks = stack->children();
for (const auto& insert : inserts)
for (const auto& move : moves)
{
const int oldIndex = insert.oldIndex;
const int oldTrackIndex = insert.oldTrackIndex;

if (auto track = otio::dynamic_retainer_cast<otio::Track>(
tracks[oldTrackIndex]))
tracks[move.fromTrack]))
{
if (auto child = track->children()[oldIndex])
if (auto child = track->children()[move.fromIndex])
{
auto item = otio::dynamic_retainer_cast<otio::Item>(child);
if (!item)
continue;

timeline::InsertData data;
data.composable = child;
data.trackIndex = insert.trackIndex;
data.insertIndex = insert.insertIndex;
insertData.push_back(data);
timeline::MoveData data;
data.fromTrack = move.fromTrack;
data.fromIndex = move.fromIndex;
data.toTrack = move.toTrack;
data.toIndex = move.toIndex;
moveData.push_back(data);
}
}
}

auto otioTimeline = tl::timeline::insert(timeline, insertData);
auto otioTimeline = tl::timeline::move(timeline, moveData);
player->player()->getTimeline()->setTimeline(otioTimeline);

edit_insert_clip_annotations(inserts, ui);
edit_move_clip_annotations(moves, ui);
}

void edit_insert_clip_annotations(
const std::vector<tl::timeline::InsertData>& inserts, ViewerUI* ui)
void edit_move_clip_annotations(
const std::vector<tl::timeline::MoveData>& moves, ViewerUI* ui)
{
auto player = ui->uiView->getTimelinePlayer();
if (!player)
return;

// Convert tlRender data to mrv2's one.
std::vector<mrv::InsertData> networkInsertData;
for (const auto& insert : inserts)
std::vector<mrv::MoveData> networkMoveData;
for (const auto& move : moves)
{
const int oldIndex = getIndex(insert.composable);
const int oldTrackIndex = getIndex(insert.composable->parent());
InsertData networkInsert;
networkInsert.oldIndex = oldIndex;
networkInsert.oldTrackIndex = oldTrackIndex;
networkInsert.trackIndex = insert.trackIndex;
networkInsert.insertIndex = insert.insertIndex;
networkInsertData.push_back(networkInsert);
MoveData networkMove;
networkMove.fromIndex = move.fromIndex;
networkMove.fromTrack = move.fromTrack;
networkMove.toTrack = move.toTrack;
networkMove.toIndex = move.toIndex;
networkMoveData.push_back(networkMove);
}

edit_insert_clip_annotations(networkInsertData, ui);
edit_move_clip_annotations(networkMoveData, ui);
}

EditMode editMode = EditMode::kTimeline;
Expand Down
8 changes: 4 additions & 4 deletions mrv2/lib/mrvEdit/mrvEditCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace mrv
class TimelinePlayer;
using otio::Timeline;

struct InsertData;
struct MoveData;

//@{
//! Store timeline in undo queue.
Expand All @@ -38,12 +38,12 @@ namespace mrv
bool edit_has_redo();

//! Handle insert of clip (used in shifting clips around in tlRender).
void edit_insert_clip_annotations(
const std::vector<tl::timeline::InsertData>& inserts, ViewerUI* ui);
void edit_move_clip_annotations(
const std::vector<tl::timeline::MoveData>& inserts, ViewerUI* ui);

//! Handle insert of clip annotations from network.
void
edit_insert_clip(const std::vector<mrv::InsertData>& inserts, ViewerUI* ui);
edit_move_clip(const std::vector<mrv::MoveData>& inserts, ViewerUI* ui);

//! Set the temporary EDL for a drag item callback.
void toOtioFile(TimelinePlayer*, ViewerUI* ui);
Expand Down
10 changes: 5 additions & 5 deletions mrv2/lib/mrvGL/mrvTimelineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ namespace mrv
p.timelineWidget->setFrameView(true);
p.timelineWidget->setScrollBarsVisible(false);
p.timelineWidget->setStopOnScrub(false);
p.timelineWidget->setInsertCallback(std::bind(
&mrv::TimelineWidget::insertCallback, this, std::placeholders::_1));
p.timelineWidget->setMoveCallback(std::bind(
&mrv::TimelineWidget::moveCallback, this, std::placeholders::_1));

p.eventLoop->addWidget(p.timelineWidget);
const float devicePixelRatio = pixels_per_unit();
Expand Down Expand Up @@ -1422,13 +1422,13 @@ namespace mrv
redraw();
}

void TimelineWidget::insertCallback(
const std::vector<tl::timeline::InsertData>& inserts)
void TimelineWidget::moveCallback(
const std::vector<tl::timeline::MoveData>& inserts)
{
TLRENDER_P();
edit_store_undo(p.player, p.ui);
edit_clear_redo(p.ui);
edit_insert_clip_annotations(inserts, p.ui);
edit_move_clip_annotations(inserts, p.ui);
}

void TimelineWidget::single_thumbnail(
Expand Down
2 changes: 1 addition & 1 deletion mrv2/lib/mrvGL/mrvTimelineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace mrv
int keyPressEvent(unsigned key, const int modifiers);
int keyReleaseEvent(unsigned key, const int modifiers);

void insertCallback(const std::vector<tl::timeline::InsertData>&);
void moveCallback(const std::vector<tl::timeline::MoveData>&);

protected:
void _initializeGL();
Expand Down
4 changes: 2 additions & 2 deletions mrv2/lib/mrvNetwork/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(HEADERS
mrvFilesModelItem.h
mrvFilePath.h
mrvImageOptions.h
mrvInsertData.h
mrvMoveData.h
mrvLUTOptions.h
mrvTCP.h
mrvTimelineItemOptions.h
Expand All @@ -24,7 +24,7 @@ set(SOURCES
mrvFilesModelItem.cpp
mrvFilePath.cpp
mrvImageOptions.cpp
mrvInsertData.cpp
mrvMoveData.cpp
mrvLUTOptions.cpp
mrvTCP.cpp
mrvTimelineItemOptions.cpp
Expand Down
2 changes: 1 addition & 1 deletion mrv2/lib/mrvNetwork/mrvCommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "mrvNetwork/mrvCommandInterpreter.h"
#include "mrvNetwork/mrvCompareOptions.h"
#include "mrvNetwork/mrvDisplayOptions.h"
#include "mrvNetwork/mrvInsertData.h"
#include "mrvNetwork/mrvMoveData.h"
#include "mrvNetwork/mrvImageOptions.h"
#include "mrvNetwork/mrvLUTOptions.h"
#include "mrvNetwork/mrvTimelineItemOptions.h"
Expand Down
26 changes: 0 additions & 26 deletions mrv2/lib/mrvNetwork/mrvInsertData.cpp

This file was deleted.

Loading

0 comments on commit 30eb1e7

Please sign in to comment.