Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Darby Johnston <[email protected]>
  • Loading branch information
darbyjohnston committed Nov 12, 2024
1 parent 2a91753 commit 777aaa8
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Builddtk-deps.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(ExternalProject)

set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git")
set(dtk_GIT_TAG "d3fb154f63d96f3f3d8bb6b650c4165049767824")
set(dtk_GIT_TAG "fe708a58fda5dc65141e492ae5fa24b199ff3edc")

set(dtk-deps_ARGS
${toucan_EXTERNAL_PROJECT_ARGS}
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Builddtk.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(ExternalProject)

set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git")
set(dtk_GIT_TAG "d3fb154f63d96f3f3d8bb6b650c4165049767824")
set(dtk_GIT_TAG "fe708a58fda5dc65141e492ae5fa24b199ff3edc")

set(dtk_DEPS dtk-deps)
set(dtk_ARGS
Expand Down
5 changes: 3 additions & 2 deletions lib/toucan/Comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ namespace toucan
}
const auto& fgSpec = fg.spec();
const auto& bgSpec = bg.spec();
if (fgSpec.width != bgSpec.width ||
fgSpec.height != bgSpec.height)
if (bgSpec.width > 0 &&
bgSpec.height > 0 &&
(fgSpec.width != bgSpec.width || fgSpec.height != bgSpec.height))
{
fg = OIIO::ImageBufAlgo::resize(
fg,
Expand Down
26 changes: 19 additions & 7 deletions lib/toucan/ImageGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace toucan
{
if (auto track = OTIO_NS::dynamic_retainer_cast<OTIO_NS::Track>(i))
{
if (track->kind() == OTIO_NS::Track::Kind::video)
if (track->kind() == OTIO_NS::Track::Kind::video && !track->find_clips().empty())
{
// Process this track.
auto trackNode = _track(host, time - _globalStartTime, track);
Expand Down Expand Up @@ -279,18 +279,33 @@ namespace toucan
{
std::shared_ptr<IImageNode> out;

OTIO_NS::RationalTime timeOffset =
trimmedRangeInParent.start_time() -
item->trimmed_range().start_time();

if (auto clip = OTIO_NS::dynamic_retainer_cast<OTIO_NS::Clip>(item))
{
// Get the media reference.
if (auto externalRef = dynamic_cast<OTIO_NS::ExternalReference*>(clip->media_reference()))
{
if (!_loadCache.get(externalRef, out))
std::shared_ptr<ReadNode> read;
if (!_loadCache.get(externalRef, read))
{
const std::filesystem::path path = _getMediaPath(externalRef->target_url());
auto read = std::make_shared<ReadNode>(path);
out = read;
read = std::make_shared<ReadNode>(path);
_loadCache.add(externalRef, read);
}
out = read;

//! \bug Workaround for when the available range does not match
//! the range in the media.
const OTIO_NS::TimeRange& timeRange = read->getTimeRange();
const auto availableOpt = externalRef->available_range();
if (availableOpt.has_value() &&
!availableOpt.value().start_time().strictly_equal(timeRange.start_time()))
{
timeOffset += availableOpt.value().start_time() - timeRange.start_time();
}
}
else if (auto sequenceRef = dynamic_cast<OTIO_NS::ImageSequenceReference*>(clip->media_reference()))
{
Expand Down Expand Up @@ -325,9 +340,6 @@ namespace toucan
}
if (out)
{
const OTIO_NS::RationalTime timeOffset =
trimmedRangeInParent.start_time() -
item->trimmed_range().start_time();
out->setTimeOffset(timeOffset);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/toucan/ImageGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace toucan
{
class ReadNode;

//! Image graph options.
struct ImageGraphOptions
{
Expand Down Expand Up @@ -67,6 +69,6 @@ namespace toucan
OTIO_NS::RationalTime _globalStartTime;
ImageGraphOptions _options;
IMATH_NAMESPACE::V2i _imageSize = IMATH_NAMESPACE::V2i(0, 0);
dtk::LRUCache<OTIO_NS::MediaReference*, std::shared_ptr<IImageNode> > _loadCache;
dtk::LRUCache<OTIO_NS::MediaReference*, std::shared_ptr<ReadNode> > _loadCache;
};
}
5 changes: 5 additions & 0 deletions lib/toucan/Read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ namespace toucan
}
}

const OTIO_NS::TimeRange& ReadNode::getTimeRange() const
{
return _timeRange;
}

std::string ReadNode::getLabel() const
{
std::stringstream ss;
Expand Down
2 changes: 2 additions & 0 deletions lib/toucan/Read.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace toucan
const std::vector<std::shared_ptr<IImageNode> >& = {});

virtual ~ReadNode();

const OTIO_NS::TimeRange& getTimeRange() const;

std::string getLabel() const override;

Expand Down
23 changes: 22 additions & 1 deletion lib/toucanView/TimeUnitsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,33 @@ namespace toucan
_timeUnits->setIfChanged(value);
}

OTIO_NS::RationalTime TimeUnitsModel::getTime(const std::string& text, double rate) const
{
OTIO_NS::RationalTime out;
switch (_timeUnits->get())
{
case TimeUnits::Timecode:
out = OTIO_NS::RationalTime::from_timecode(text, rate);
break;
case TimeUnits::Frames:
out = OTIO_NS::RationalTime::from_frames(std::atof(text.c_str()), rate);
break;
case TimeUnits::Seconds:
out = OTIO_NS::RationalTime::from_seconds(std::atof(text.c_str()), rate);
break;
default: break;
}
return out;
}

std::string TimeUnitsModel::getLabel(const OTIO_NS::RationalTime& time) const
{
std::string out;
switch (_timeUnits->get())
{
case TimeUnits::Timecode: out = time.to_timecode(); break;
case TimeUnits::Timecode:
out = time.to_timecode();
break;
case TimeUnits::Frames:
{
std::stringstream ss;
Expand Down
1 change: 1 addition & 0 deletions lib/toucanView/TimeUnitsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace toucan
std::shared_ptr<dtk::IObservableValue<TimeUnits> > observeTimeUnits() const;
void setTimeUnits(TimeUnits);

OTIO_NS::RationalTime getTime(const std::string&, double rate) const;
std::string getLabel(const OTIO_NS::RationalTime&) const;

private:
Expand Down
3 changes: 1 addition & 2 deletions lib/toucanView/TimeWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ namespace toucan
{
if (_callback)
{
const auto time = OTIO_NS::RationalTime::from_timecode(text, _time.rate());
_callback(time);
_callback(_timeUnitsModel->getTime(text, _time.rate()));
}
});

Expand Down
4 changes: 4 additions & 0 deletions lib/toucanView/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ namespace toucan
{
_buttons["File/Close"]->setEnabled(_documentsSize > 0);
_buttons["File/CloseAll"]->setEnabled(_documentsSize > 0);
_buttons["View/ZoomIn"]->setEnabled(_documentsSize > 0);
_buttons["View/ZoomOut"]->setEnabled(_documentsSize > 0);
_buttons["View/ZoomReset"]->setEnabled(_documentsSize > 0);
_buttons["View/Frame"]->setEnabled(_documentsSize > 0);

if (_document)
{
Expand Down

0 comments on commit 777aaa8

Please sign in to comment.