Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Darby Johnston <[email protected]>
  • Loading branch information
darbyjohnston committed Nov 10, 2024
1 parent d91cfc4 commit 66b35d3
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 62 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The project currently consists of:
Current limitations:
* Audio is not yet supported
* Nested timelines are not yet supported
* Outputting movie files currently relies on the FFmpeg command line program
* Exporting movie files currently relies on the FFmpeg command line program
(see below: FFmpeg Encoding)

Toucan relies on the following libraries:
Expand Down Expand Up @@ -93,7 +93,7 @@ Multiple effects on clips, tracks, and stacks:

FFmpeg Encoding
===============
Toucan can output rendered images directly to FFmpeg for encoding. The
Toucan can send rendered images directly to FFmpeg for encoding. The
images are piped to FFmpeg without incurring the overhead of disk I/O.

Example command line for piping images to FFmpeg:
Expand Down
4 changes: 4 additions & 0 deletions bin/toucan-view/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "toucanView/App.h"

#include <dtk/core/Context.h>

#include <iostream>

DTK_MAIN()
{
try
Expand Down
7 changes: 6 additions & 1 deletion lib/toucanView/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include "App.h"

#include "DocumentsModel.h"
#include "MainWindow.h"
#include "TimeUnitsModel.h"
#include "WindowModel.h"

#include <dtk/ui/DialogSystem.h>
#include <dtk/ui/FileBrowser.h>
#include <dtk/ui/MessageDialog.h>
Expand Down Expand Up @@ -50,7 +55,7 @@ namespace toucan

_windowModel = std::make_shared<WindowModel>();

_window = Window::create(
_window = MainWindow::create(
context,
std::dynamic_pointer_cast<App>(shared_from_this()),
"toucan-view",
Expand Down
14 changes: 8 additions & 6 deletions lib/toucanView/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

#pragma once

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

#include <dtk/ui/App.h>

namespace toucan
{
class DocumentsModel;
class ImageEffectHost;
class MainWindow;
class MessageLog;
class TimeUnitsModel;
class WindowModel;

class App : public dtk::App
{
protected:
Expand All @@ -38,7 +40,7 @@ namespace toucan
std::shared_ptr<ImageEffectHost> _host;
std::shared_ptr<DocumentsModel> _documentsModel;
std::shared_ptr<WindowModel> _windowModel;
std::shared_ptr<Window> _window;
std::shared_ptr<MainWindow> _window;
};
}

4 changes: 2 additions & 2 deletions lib/toucanView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(HEADERS
IItem.h
IToolWidget.h
JSONTool.h
MainWindow.h
MenuBar.h
PlaybackBar.h
PlaybackModel.h
Expand All @@ -25,7 +26,6 @@ set(HEADERS
TrackItem.h
ViewModel.h
Viewport.h
Window.h
WindowModel.h)

set(SOURCE
Expand All @@ -41,6 +41,7 @@ set(SOURCE
IItem.cpp
IToolWidget.cpp
JSONTool.cpp
MainWindow.cpp
MenuBar.cpp
PlaybackBar.cpp
PlaybackModel.cpp
Expand All @@ -55,7 +56,6 @@ set(SOURCE
TrackItem.cpp
ViewModel.cpp
Viewport.cpp
Window.cpp
WindowModel.cpp)

add_library(toucanView ${HEADERS} ${SOURCE})
Expand Down
2 changes: 0 additions & 2 deletions lib/toucanView/DocumentTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma once

#include "WindowModel.h"

#include <dtk/ui/RowLayout.h>

namespace toucan
Expand Down
2 changes: 2 additions & 0 deletions lib/toucanView/DocumentsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "PlaybackModel.h"

#include <toucan/ImageEffectHost.h>

#include <dtk/core/Math.h>

namespace toucan
Expand Down
5 changes: 3 additions & 2 deletions lib/toucanView/DocumentsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

#include "Document.h"

#include <toucan/ImageEffectHost.h>

#include <dtk/core/Context.h>
#include <dtk/core/ObservableList.h>
#include <dtk/core/ObservableValue.h>

namespace toucan
{
class Document;
class ImageEffectHost;

class DocumentsModel : public std::enable_shared_from_this<DocumentsModel>
{
public:
Expand Down
2 changes: 1 addition & 1 deletion lib/toucanView/GraphTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "GraphTool.h"

#include "App.h"
#include "Document.h"
#include "DocumentsModel.h"

#include <dtk/ui/Spacer.h>

Expand Down
2 changes: 2 additions & 0 deletions lib/toucanView/JSONTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "JSONTool.h"

#include "App.h"
#include "DocumentsModel.h"
#include "SelectionModel.h"

#include <dtk/ui/Divider.h>
#include <dtk/ui/Label.h>
Expand Down
4 changes: 3 additions & 1 deletion lib/toucanView/JSONTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#pragma once

#include "IToolWidget.h"
#include "SelectionModel.h"

#include <dtk/ui/Bellows.h>
#include <dtk/ui/RowLayout.h>
#include <dtk/ui/ScrollWidget.h>
#include <dtk/core/ObservableList.h>

#include <opentimelineio/item.h>

namespace toucan
{
Expand Down
41 changes: 24 additions & 17 deletions lib/toucanView/Window.cpp → lib/toucanView/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the toucan project.

#include "Window.h"
#include "MainWindow.h"

#include "App.h"
#include "DocumentTab.h"
#include "DocumentsModel.h"
#include "ExportTool.h"
#include "GraphTool.h"
#include "JSONTool.h"
Expand All @@ -19,7 +20,7 @@

namespace toucan
{
void Window::_init(
void MainWindow::_init(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::string& name,
Expand All @@ -35,19 +36,18 @@ namespace toucan
_menuBar = MenuBar::create(
context,
app,
std::dynamic_pointer_cast<Window>(shared_from_this()),
std::dynamic_pointer_cast<MainWindow>(shared_from_this()),
_layout);
dtk::Divider::create(context, dtk::Orientation::Vertical, _layout);

_toolBar = ToolBar::create(
context,
app,
std::dynamic_pointer_cast<Window>(shared_from_this()),
std::dynamic_pointer_cast<MainWindow>(shared_from_this()),
_menuBar->getActions(),
_layout);
_toolBarDivider = dtk::Divider::create(context, dtk::Orientation::Vertical, _layout);


_vSplitter = dtk::Splitter::create(context, dtk::Orientation::Vertical, _layout);
_vSplitter->setSplit({ .7F, .3F });
_vSplitter->setStretch(dtk::Stretch::Expanding);
Expand All @@ -69,7 +69,11 @@ namespace toucan

_bottomLayout = dtk::VerticalLayout::create(context, _vSplitter);
_bottomLayout->setSpacingRole(dtk::SizeRole::None);

_playbackBar = PlaybackBar::create(context, app, _bottomLayout);

_bottomDivider = dtk::Divider::create(context, dtk::Orientation::Vertical, _bottomLayout);

_timelineWidget = TimelineWidget::create(context, app, _bottomLayout);
_timelineWidget->setVStretch(dtk::Stretch::Expanding);

Expand Down Expand Up @@ -146,11 +150,14 @@ namespace toucan
auto i = value.find(WindowControl::ToolBar);
_toolBar->setVisible(i->second);
_toolBarDivider->setVisible(i->second);
i = value.find(WindowControl::TimelineWidget);
_timelineWidget->setVisible(i->second);
auto j = value.find(WindowControl::PlaybackBar);
_playbackBar->setVisible(j->second);

i = value.find(WindowControl::PlaybackBar);
_playbackBar->setVisible(i->second);
auto j = value.find(WindowControl::TimelineWidget);
_timelineWidget->setVisible(j->second);
_bottomLayout->setVisible(i->second || j->second);
_bottomDivider->setVisible(i->second && j->second);

i = value.find(WindowControl::Tools);
_toolWidget->setVisible(i->second);
});
Expand All @@ -163,43 +170,43 @@ namespace toucan
});
}

Window::~Window()
MainWindow::~MainWindow()
{}

std::shared_ptr<Window> Window::create(
std::shared_ptr<MainWindow> MainWindow::create(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::string& name,
const dtk::Size2I& size)
{
auto out = std::shared_ptr<Window>(new Window);
auto out = std::shared_ptr<MainWindow>(new MainWindow);
out->_init(context, app, name, size);
return out;
}

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

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

void Window::keyPressEvent(dtk::KeyEvent& event)
void MainWindow::keyPressEvent(dtk::KeyEvent& event)
{
event.accept = _menuBar->shortcut(event.key, event.modifiers);
}

void Window::keyReleaseEvent(dtk::KeyEvent& event)
void MainWindow::keyReleaseEvent(dtk::KeyEvent& event)
{
event.accept = true;
}

void Window::_drop(const std::vector<std::string>& value)
void MainWindow::_drop(const std::vector<std::string>& value)
{
if (auto context = getContext())
{
Expand Down
7 changes: 4 additions & 3 deletions lib/toucanView/Window.h → lib/toucanView/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace toucan
class TimelineWidget;
class ToolBar;

class Window : public dtk::Window
class MainWindow : public dtk::Window
{
protected:
void _init(
Expand All @@ -33,9 +33,9 @@ namespace toucan
const dtk::Size2I&);

public:
virtual ~Window();
virtual ~MainWindow();

static std::shared_ptr<Window> create(
static std::shared_ptr<MainWindow> create(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const std::string& name,
Expand Down Expand Up @@ -65,6 +65,7 @@ namespace toucan
std::vector<std::shared_ptr<IToolWidget> > _toolWidgets;
std::shared_ptr<dtk::VerticalLayout> _bottomLayout;
std::shared_ptr<PlaybackBar> _playbackBar;
std::shared_ptr<dtk::Divider> _bottomDivider;
std::shared_ptr<TimelineWidget> _timelineWidget;

std::shared_ptr<dtk::ListObserver<std::shared_ptr<Document> > > _documentsObserver;
Expand Down
20 changes: 6 additions & 14 deletions lib/toucanView/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "MenuBar.h"

#include "App.h"
#include "DocumentsModel.h"
#include "MainWindow.h"
#include "SelectionModel.h"
#include "ViewModel.h"

Expand All @@ -18,7 +20,7 @@ namespace toucan
void MenuBar::_init(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<Window>& window,
const std::shared_ptr<MainWindow>& window,
const std::shared_ptr<dtk::IWidget>& parent)
{
dtk::MenuBar::_init(context, parent);
Expand Down Expand Up @@ -82,7 +84,7 @@ namespace toucan
std::shared_ptr<MenuBar> MenuBar::create(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<Window>& window,
const std::shared_ptr<MainWindow>& window,
const std::shared_ptr<dtk::IWidget>& parent)
{
auto out = std::shared_ptr<MenuBar>(new MenuBar);
Expand Down Expand Up @@ -183,16 +185,6 @@ namespace toucan

_menus["File"]->addDivider();

_actions["File/Export"] = std::make_shared<dtk::Action>(
"Export",
dtk::Key::T,
static_cast<int>(dtk::KeyModifier::Control),
[this] {
});
_menus["File"]->addItem(_actions["File/Export"]);

_menus["File"]->addDivider();

_actions["File/Exit"] = std::make_shared<dtk::Action>(
"Exit",
dtk::Key::Q,
Expand Down Expand Up @@ -433,12 +425,12 @@ namespace toucan
void MenuBar::_windowMenuInit(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<Window>& window)
const std::shared_ptr<MainWindow>& window)
{
_menus["Window"] = dtk::Menu::create(context);
addMenu("Window", _menus["Window"]);

std::weak_ptr<Window> windowWeak(window);
std::weak_ptr<MainWindow> windowWeak(window);
_actions["Window/FullScreen"] = std::make_shared<dtk::Action>(
"Full Screen",
"WindowFullScreen",
Expand Down
Loading

0 comments on commit 66b35d3

Please sign in to comment.