Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Sep 26, 2024
1 parent 4a62b99 commit 5714076
Show file tree
Hide file tree
Showing 56 changed files with 5,454 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(
LANGUAGES CXX C)

set(toucan_VIEW ON CACHE BOOL "Build viewer application")
set(toucan_EDIT ON CACHE BOOL "Build editor application")
set(toucan_EDIT OFF CACHE BOOL "Build editor application")

list(PREPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

Expand Down
52 changes: 49 additions & 3 deletions bin/toucan-edit/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

#include "App.h"

#include "Clip.h"
#include "Stack.h"
#include "Timeline.h"
#include "Track.h"

#include <dtk/ui/FileBrowser.h>
#include <dtk/ui/MessageDialog.h>
#include <dtk/core/CmdLine.h>

namespace toucan
Expand All @@ -30,13 +29,45 @@ namespace toucan
true)
});

context->getSystem<dtk::FileBrowserSystem>()->setNativeFileDialog(false);

_messageLog = std::make_shared<MessageLog>();

_timeUnitsModel = std::make_shared<TimeUnitsModel>();

std::vector<std::filesystem::path> searchPath;
const std::filesystem::path parentPath = std::filesystem::path(argv[0]).parent_path();
searchPath.push_back(parentPath);
#if defined(_WINDOWS)
searchPath.push_back(parentPath / ".." / ".." / "..");
#else // _WINDOWS
searchPath.push_back(parentPath / ".." / "..");
#endif // _WINDOWS
ImageEffectHostOptions hostOptions;
//hostOptions.log = _messageLog;
_host = std::make_shared<ImageEffectHost>(searchPath, hostOptions);

_documentsModel = std::make_shared<DocumentsModel>(context, _host);

_window = Window::create(
context,
std::dynamic_pointer_cast<App>(shared_from_this()),
"toucan-edit",
dtk::Size2I(1920, 1080));
addWindow(_window);

if (!_path.empty())
{
try
{
_documentsModel->open(_path);
}
catch (const std::exception& e)
{
_context->getSystem<dtk::MessageDialogSystem>()->message("ERROR", e.what(), _window);
}
}

_window->show();
}

Expand All @@ -51,4 +82,19 @@ namespace toucan
out->_init(context, argv);
return out;
}

const std::shared_ptr<TimeUnitsModel>& App::getTimeUnitsModel() const
{
return _timeUnitsModel;
}

const std::shared_ptr<ImageEffectHost>& App::getHost() const
{
return _host;
}

const std::shared_ptr<DocumentsModel>& App::getDocumentsModel() const
{
return _documentsModel;
}
}
10 changes: 10 additions & 0 deletions bin/toucan-edit/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include "DocumentsModel.h"
#include "TimeUnitsModel.h"
#include "Window.h"

#include <dtk/ui/App.h>
Expand All @@ -24,8 +26,16 @@ namespace toucan
const std::shared_ptr<dtk::Context>&,
std::vector<std::string>&);

const std::shared_ptr<TimeUnitsModel>& getTimeUnitsModel() const;
const std::shared_ptr<ImageEffectHost>& getHost() const;
const std::shared_ptr<DocumentsModel>& getDocumentsModel() const;

private:
std::shared_ptr<MessageLog> _messageLog;
std::string _path;
std::shared_ptr<TimeUnitsModel> _timeUnitsModel;
std::shared_ptr<ImageEffectHost> _host;
std::shared_ptr<DocumentsModel> _documentsModel;
std::shared_ptr<Window> _window;
};
}
Expand Down
156 changes: 156 additions & 0 deletions bin/toucan-edit/BottomBar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024 Darby Johnston
// All rights reserved.

#include "BottomBar.h"

#include "App.h"

namespace toucan
{
void BottomBar::_init(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<dtk::IWidget>& parent)
{
dtk::IWidget::_init(context, "toucan::BottomBar", parent);

_layout = dtk::HorizontalLayout::create(context, shared_from_this());
_layout->setMarginRole(dtk::SizeRole::MarginInside);
_layout->setSpacingRole(dtk::SizeRole::SpacingSmall);

_playbackButtons = PlaybackButtons::create(context, _layout);

_frameButtons = FrameButtons::create(context, _layout);

_timeEdit = TimeEdit::create(context, app->getTimeUnitsModel(), _layout);
_timeEdit->setTooltip("Current time");

_durationLabel = TimeLabel::create(context, app->getTimeUnitsModel(), _layout);
_durationLabel->setTooltip("Timeline duration");

_frameButtons->setCallback(
[this](FrameAction value)
{
if (_document)
{
_document->getPlaybackModel()->frameAction(value);
}
});

_playbackButtons->setCallback(
[this](Playback value)
{
if (_document)
{
_document->getPlaybackModel()->setPlayback(value);
}
});

_timeEdit->setCallback(
[this](const OTIO_NS::RationalTime& value)
{
if (_document)
{
_document->getPlaybackModel()->setCurrentTime(value);
}
});

_documentObserver = dtk::ValueObserver<std::shared_ptr<Document> >::create(
app->getDocumentsModel()->observeCurrent(),
[this](const std::shared_ptr<Document>& document)
{
_document = document;
if (document)
{
_timeRangeObserver = dtk::ValueObserver<OTIO_NS::TimeRange>::create(
document->getPlaybackModel()->observeTimeRange(),
[this](const OTIO_NS::TimeRange& value)
{
_timeRange = value;
_timeRangeUpdate();
});

_currentTimeObserver = dtk::ValueObserver<OTIO_NS::RationalTime>::create(
document->getPlaybackModel()->observeCurrentTime(),
[this](const OTIO_NS::RationalTime& value)
{
_currentTime = value;
_currentTimeUpdate();
});

_playbackObserver = dtk::ValueObserver<Playback>::create(
document->getPlaybackModel()->observePlayback(),
[this](Playback value)
{
_playback = value;
_playbackUpdate();
});
}
else
{
_timeRange = OTIO_NS::TimeRange();
_currentTime = OTIO_NS::RationalTime();
_playback = Playback::Stop;

_timeRangeUpdate();
_currentTimeUpdate();
_playbackUpdate();

_timeRangeObserver.reset();
_currentTimeObserver.reset();
_playbackObserver.reset();
}

_frameButtons->setEnabled(document.get());
_playbackButtons->setEnabled(document.get());
_timeEdit->setEnabled(document.get());
_durationLabel->setEnabled(document.get());
});
}

BottomBar::~BottomBar()
{}

std::shared_ptr<BottomBar> BottomBar::create(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<dtk::IWidget>& parent)
{
auto out = std::shared_ptr<BottomBar>(new BottomBar);
out->_init(context, app, parent);
return out;
}

void BottomBar::setGeometry(const dtk::Box2I& value)
{
IWidget::setGeometry(value);
_layout->setGeometry(value);
}

void BottomBar::sizeHintEvent(const dtk::SizeHintEvent& event)
{
IWidget::sizeHintEvent(event);
_setSizeHint(_layout->getSizeHint());
}

void BottomBar::_timelineUpdate()
{}

void BottomBar::_timeRangeUpdate()
{
_timeEdit->setTimeRange(_timeRange);

_durationLabel->setTime(_timeRange.duration());
}

void BottomBar::_currentTimeUpdate()
{
_timeEdit->setTime(_currentTime);
}

void BottomBar::_playbackUpdate()
{
_playbackButtons->setPlayback(_playback);
}
}
59 changes: 59 additions & 0 deletions bin/toucan-edit/BottomBar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024 Darby Johnston
// All rights reserved.

#pragma once

#include "TimeWidgets.h"

#include <dtk/ui/RowLayout.h>
#include <dtk/ui/ToolButton.h>

namespace toucan
{
class App;
class Document;

class BottomBar : public dtk::IWidget
{
protected:
void _init(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const std::shared_ptr<IWidget>& parent);

public:
virtual ~BottomBar();

static std::shared_ptr<BottomBar> create(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const std::shared_ptr<IWidget>& parent = nullptr);

void setGeometry(const dtk::Box2I&) override;
void sizeHintEvent(const dtk::SizeHintEvent&) override;

private:
void _timelineUpdate();
void _timeRangeUpdate();
void _currentTimeUpdate();
void _playbackUpdate();

std::shared_ptr<Document> _document;
OTIO_NS::TimeRange _timeRange;
OTIO_NS::RationalTime _currentTime;
Playback _playback = Playback::Stop;

std::shared_ptr<dtk::HorizontalLayout> _layout;
std::shared_ptr<FrameButtons> _frameButtons;
std::shared_ptr<PlaybackButtons> _playbackButtons;
std::shared_ptr<TimeEdit> _timeEdit;
std::shared_ptr<TimeLabel> _durationLabel;

std::shared_ptr<dtk::ValueObserver<std::shared_ptr<Document> > > _documentObserver;
std::shared_ptr<dtk::ValueObserver<OTIO_NS::TimeRange> > _timeRangeObserver;
std::shared_ptr<dtk::ValueObserver<OTIO_NS::RationalTime> > _currentTimeObserver;
std::shared_ptr<dtk::ValueObserver<Playback> > _playbackObserver;
};
}

42 changes: 42 additions & 0 deletions bin/toucan-edit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,63 @@
set(HEADERS
App.h
BottomBar.h
Clip.h
ClipWidget.h
Document.h
DocumentsModel.h
DocumentTab.h
Gap.h
GapWidget.h
IContainer.h
IItem.h
IItemWidget.h
ImageGraph.h
MenuBar.h
PlaybackModel.h
SelectionModel.h
Stack.h
StackWidget.h
ThumbnailGenerator.h
Timeline.h
TimelineView.h
TimelineWidget.h
TimeUnitsModel.h
TimeWidgets.h
Track.h
TrackWidget.h
Viewport.h
ViewModel.h
Window.h)

set(SOURCE
App.cpp
BottomBar.cpp
Clip.cpp
ClipWidget.cpp
Document.cpp
DocumentsModel.cpp
DocumentTab.cpp
Gap.cpp
GapWidget.cpp
IContainer.cpp
IItem.cpp
IItemWidget.cpp
ImageGraph.cpp
MenuBar.cpp
PlaybackModel.cpp
SelectionModel.cpp
Stack.cpp
StackWidget.cpp
ThumbnailGenerator.cpp
Timeline.cpp
TimelineView.cpp
TimelineWidget.cpp
TimeUnitsModel.cpp
TimeWidgets.cpp
Track.cpp
TrackWidget.cpp
Viewport.cpp
ViewModel.cpp
Window.cpp
main.cpp)

Expand Down
Loading

0 comments on commit 5714076

Please sign in to comment.