Skip to content

Commit

Permalink
Merge branch 'darby_edit_original' into test_edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Sep 19, 2023
2 parents ee7f342 + a63e66b commit 96771f5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 156 deletions.
65 changes: 0 additions & 65 deletions lib/tlTimeline/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,71 +70,6 @@ namespace tl
}
}

otio::SerializableObject::Retainer<otio::Clip> getAssociatedClip(
const otio::SerializableObject::Retainer<otio::Clip>& clip)
{
otio::SerializableObject::Retainer<otio::Clip> out;
const auto timeRangeOpt = clip->trimmed_range_in_parent();
if (timeRangeOpt.has_value())
{
const otime::TimeRange timeRange = timeRangeOpt.value();
if (auto track = dynamic_cast<otio::Track*>(clip->parent()))
{
if (otio::Track::Kind::video == track->kind())
{
if (auto nextTrack = otio::dynamic_retainer_cast<otio::Track>(getNextSibling(track)))
{
if (otio::Track::Kind::audio == nextTrack->kind())
{
for (const auto& child : nextTrack->children())
{
if (auto audioClip = otio::dynamic_retainer_cast<otio::Clip>(child))
{
const auto audioTimeRangeOpt = audioClip->trimmed_range_in_parent();
if (audioTimeRangeOpt.has_value())
{
const otime::TimeRange audioTimeRange = audioTimeRangeOpt.value();
if (audioTimeRange == timeRange)
{
out = audioClip;
break;
}
}
}
}
}
}
}
else if (otio::Track::Kind::audio == track->kind())
{
if (auto prevTrack = otio::dynamic_retainer_cast<otio::Track>(getPrevSibling(track)))
{
if (otio::Track::Kind::video == prevTrack->kind())
{
for (const auto& child : prevTrack->children())
{
if (auto videoClip = otio::dynamic_retainer_cast<otio::Clip>(child))
{
const auto videoTimeRangeOpt = videoClip->trimmed_range_in_parent();
if (videoTimeRangeOpt.has_value())
{
const otime::TimeRange videoTimeRange = videoTimeRangeOpt.value();
if (videoTimeRange == timeRange)
{
out = videoClip;
break;
}
}
}
}
}
}
}
}
}
return out;
}

otio::SerializableObject::Retainer<otio::Timeline> insert(
const otio::SerializableObject::Retainer<otio::Timeline>& timeline,
const std::vector<InsertData>& inserts)
Expand Down
4 changes: 0 additions & 4 deletions lib/tlTimeline/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ namespace tl
{
namespace timeline
{
//! Find an associated audio or video clip on an adjacent track.
otio::SerializableObject::Retainer<otio::Clip> getAssociatedClip(
const otio::SerializableObject::Retainer<otio::Clip>&);

//! Insert data.
struct InsertData
{
Expand Down
59 changes: 30 additions & 29 deletions lib/tlTimelineUI/TimelineItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace tl
{
int index = -1;
int track = -1;
math::Box2i geometry;
math::Box2i mouse;
math::Box2i draw;
};
struct MouseData
Expand All @@ -105,7 +105,10 @@ namespace tl
int& index,
int& trackIndex) const;

std::vector<MouseItemDropTarget> getDropTargets(int index, int track);
std::vector<MouseItemDropTarget> getDropTargets(
const math::Box2i& geometry,
int index,
int track);
};

void TimelineItem::_init(
Expand Down Expand Up @@ -400,23 +403,19 @@ namespace tl
math::Box2i(g.min.x, y, g.w(), h),
event.style->getColorRole(ui::ColorRole::Border));

_drawInOutPoints(drawRect, event);
_drawTimeTicks(drawRect, event);
_drawCacheInfo(drawRect, event);
_drawCurrentTime(drawRect, event);

if (p.mouse.currentDropTarget >= 0 &&
p.mouse.currentDropTarget < p.mouse.dropTargets.size())
{
const auto& dt = p.mouse.dropTargets[p.mouse.currentDropTarget];
event.render->drawMesh(
ui::border(dt.draw, p.size.border),
math::Vector2i(),
event.style->getColorRole(ui::ColorRole::Border));
event.render->drawRect(
dt.draw.margin(-p.size.border),
dt.draw,
event.style->getColorRole(ui::ColorRole::Green));
}

_drawInOutPoints(drawRect, event);
_drawTimeTicks(drawRect, event);
_drawCacheInfo(drawRect, event);
_drawCurrentTime(drawRect, event);
}

void TimelineItem::mouseMoveEvent(ui::MouseMoveEvent& event)
Expand All @@ -443,7 +442,7 @@ namespace tl
int dropTarget = -1;
for (size_t i = 0; i < p.mouse.dropTargets.size(); ++i)
{
if (p.mouse.dropTargets[i].geometry.contains(event.pos))
if (p.mouse.dropTargets[i].mouse.contains(event.pos))
{
dropTarget = i;
break;
Expand Down Expand Up @@ -492,7 +491,7 @@ namespace tl
p.mouse.mode = Private::MouseMode::Item;
p.mouse.items.push_back(
std::make_shared<Private::MouseItemData>(item, j, i));
p.mouse.dropTargets = p.getDropTargets(j, i);
p.mouse.dropTargets = p.getDropTargets(g, j, i);
moveToFront(item);
if (_options.editAssociatedClips)
{
Expand Down Expand Up @@ -663,7 +662,6 @@ namespace tl
{
TLRENDER_P();

const int handle = event.style->getSizeRole(ui::SizeRole::Handle, event.displayScale);
const math::Box2i& g = _geometry;

const std::string labelMax = _data->timeUnitsModel->getLabel(_timeRange.duration());
Expand All @@ -673,7 +671,7 @@ namespace tl
const int w = _sizeHint.w;
const float duration = _timeRange.duration().rescaled_to(1.0).value();
const int frameTick = 1.0 / _timeRange.duration().value() * w;
if (frameTick >= handle)
if (frameTick >= p.size.handle)
{
geom::TriangleMesh2 mesh;
size_t i = 1;
Expand Down Expand Up @@ -1030,7 +1028,10 @@ namespace tl
return out;
}

std::vector<TimelineItem::Private::MouseItemDropTarget> TimelineItem::Private::getDropTargets(int index, int trackIndex)
std::vector<TimelineItem::Private::MouseItemDropTarget> TimelineItem::Private::getDropTargets(
const math::Box2i& geometry,
int index,
int trackIndex)
{
std::vector<MouseItemDropTarget> out;
if (trackIndex >= 0 && trackIndex < tracks.size())
Expand All @@ -1051,33 +1052,33 @@ namespace tl
MouseItemDropTarget dt;
dt.index = i;
dt.track = trackIndex;
dt.geometry = math::Box2i(
g.min.x - g.h() / 2,
g.min.y,
g.h(),
g.h());
dt.draw = math::Box2i(
dt.mouse = math::Box2i(
g.min.x - size.handle,
g.min.y,
size.handle * 2,
g.h());
dt.draw = math::Box2i(
g.min.x - size.border * 2,
size.scrollPos.y + geometry.min.y,
size.border * 4,
geometry.h());
out.push_back(dt);
}
if (!track.items.empty() && index < (track.items.size() - 1))
{
MouseItemDropTarget dt;
dt.index = i;
dt.track = trackIndex;
dt.geometry = math::Box2i(
g.max.x - g.h() / 2,
g.min.y,
g.h(),
g.h());
dt.draw = math::Box2i(
dt.mouse = math::Box2i(
g.max.x - size.handle,
g.min.y,
size.handle * 2,
g.h());
dt.draw = math::Box2i(
g.max.x - size.border * 2,
size.scrollPos.y + geometry.min.y,
size.border * 4,
geometry.h());
out.push_back(dt);
}
}
Expand Down
57 changes: 0 additions & 57 deletions tests/tlTimelineTest/EditTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace tl
void EditTest::run()
{
_insert();
_util();
}

void EditTest::_insert()
Expand Down Expand Up @@ -239,61 +238,5 @@ namespace tl
TLRENDER_ASSERT("Video 0" == getChild(otioTimeline3, 0, 0)->name());
}
}

void EditTest::_util()
{
{
otio::SerializableObject::Retainer<otio::Timeline> otioTimeline(new otio::Timeline);
auto otioTrack = new otio::Track("Video", otio::nullopt, otio::Track::Kind::video);
otioTimeline->tracks()->append_child(otioTrack);
otioTrack->append_child(new otio::Clip(
"Video",
nullptr,
otime::TimeRange(
otime::RationalTime(0.0, 24.0),
otime::RationalTime(24.0, 24.0))));
otioTrack = new otio::Track(
"Audio",
otio::nullopt,
otio::Track::Kind::audio);
otioTimeline->tracks()->append_child(otioTrack);
otioTrack->append_child(new otio::Clip(
"Audio",
nullptr,
otime::TimeRange(
otime::RationalTime(0.0, 48000.0),
otime::RationalTime(48000.0, 48000.0))));

TLRENDER_ASSERT(
timeline::getAssociatedClip(getClip(otioTimeline, 0, 0)).value ==
getClip(otioTimeline, 1, 0).value);
}
{
otio::SerializableObject::Retainer<otio::Timeline> otioTimeline(new otio::Timeline);
auto otioTrack = new otio::Track("Video", otio::nullopt, otio::Track::Kind::video);
otioTimeline->tracks()->append_child(otioTrack);
otioTrack->append_child(new otio::Clip(
"Video",
nullptr,
otime::TimeRange(
otime::RationalTime(0.0, 24.0),
otime::RationalTime(24.0, 24.0))));
otioTrack = new otio::Track(
"Audio",
otio::nullopt,
otio::Track::Kind::audio);
otioTimeline->tracks()->append_child(otioTrack);
otioTrack->append_child(new otio::Clip(
"Audio",
nullptr,
otime::TimeRange(
otime::RationalTime(0.0, 48000.0),
otime::RationalTime(2 * 48000.0, 48000.0))));

TLRENDER_ASSERT(
timeline::getAssociatedClip(getClip(otioTimeline, 0, 0)).value !=
getClip(otioTimeline, 1, 0).value);
}
}
}
}
1 change: 0 additions & 1 deletion tests/tlTimelineTest/EditTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace tl

private:
void _insert();
void _util();
};
}
}

0 comments on commit 96771f5

Please sign in to comment.