Skip to content

Commit 4a62b99

Browse files
committed
Refactoring
1 parent 1c93028 commit 4a62b99

28 files changed

+681
-7
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(
88
LANGUAGES CXX C)
99

1010
set(toucan_VIEW ON CACHE BOOL "Build viewer application")
11+
set(toucan_EDIT ON CACHE BOOL "Build editor application")
1112

1213
list(PREPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
1314

@@ -51,7 +52,7 @@ find_package(OpenColorIO)
5152
find_package(OpenImageIO)
5253
find_package(OTIO)
5354
find_package(OpenFX)
54-
if(toucan_VIEW)
55+
if(toucan_VIEW OR toucan_EDIT)
5556
find_package(dtk)
5657
endif()
5758

bin/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ add_subdirectory(toucan-render)
22
if(toucan_VIEW)
33
add_subdirectory(toucan-view)
44
endif()
5+
if(toucan_EDIT)
6+
add_subdirectory(toucan-edit)
7+
endif()

bin/toucan-edit/App.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#include "App.h"
6+
7+
#include "Clip.h"
8+
#include "Stack.h"
9+
#include "Timeline.h"
10+
#include "Track.h"
11+
12+
#include <dtk/core/CmdLine.h>
13+
14+
namespace toucan
15+
{
16+
void App::_init(
17+
const std::shared_ptr<dtk::Context>& context,
18+
std::vector<std::string>& argv)
19+
{
20+
dtk::App::_init(
21+
context,
22+
argv,
23+
"toucan-edit",
24+
"Toucan editor",
25+
{
26+
dtk::CmdLineValueArg<std::string>::create(
27+
_path,
28+
"input",
29+
"Input timeline.",
30+
true)
31+
});
32+
33+
_window = Window::create(
34+
context,
35+
std::dynamic_pointer_cast<App>(shared_from_this()),
36+
"toucan-edit",
37+
dtk::Size2I(1920, 1080));
38+
addWindow(_window);
39+
40+
_window->show();
41+
}
42+
43+
App::~App()
44+
{}
45+
46+
std::shared_ptr<App> App::create(
47+
const std::shared_ptr<dtk::Context>& context,
48+
std::vector<std::string>& argv)
49+
{
50+
auto out = std::shared_ptr<App>(new App);
51+
out->_init(context, argv);
52+
return out;
53+
}
54+
}

bin/toucan-edit/App.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#pragma once
6+
7+
#include "Window.h"
8+
9+
#include <dtk/ui/App.h>
10+
11+
namespace toucan
12+
{
13+
class App : public dtk::App
14+
{
15+
protected:
16+
void _init(
17+
const std::shared_ptr<dtk::Context>&,
18+
std::vector<std::string>&);
19+
20+
public:
21+
virtual ~App();
22+
23+
static std::shared_ptr<App> create(
24+
const std::shared_ptr<dtk::Context>&,
25+
std::vector<std::string>&);
26+
27+
private:
28+
std::string _path;
29+
std::shared_ptr<Window> _window;
30+
};
31+
}
32+

bin/toucan-edit/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set(HEADERS
2+
App.h
3+
Clip.h
4+
IContainer.h
5+
IItem.h
6+
Stack.h
7+
Timeline.h
8+
Track.h
9+
Window.h)
10+
11+
set(SOURCE
12+
App.cpp
13+
Clip.cpp
14+
IContainer.cpp
15+
IItem.cpp
16+
Stack.cpp
17+
Timeline.cpp
18+
Track.cpp
19+
Window.cpp
20+
main.cpp)
21+
22+
add_executable(toucan-edit ${HEADERS} ${SOURCE})
23+
target_link_libraries(toucan-edit toucan dtk::dtkUI)
24+
set_target_properties(toucan-edit PROPERTIES FOLDER bin)
25+
add_dependencies(toucan-edit ${TOUCAN_PLUGINS})
26+
27+
install(
28+
TARGETS toucan-edit
29+
RUNTIME DESTINATION bin)

bin/toucan-edit/Clip.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#include "Clip.h"
6+
7+
namespace toucan
8+
{
9+
}

bin/toucan-edit/Clip.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#pragma once
6+
7+
#include "IItem.h"
8+
9+
#include <vector>
10+
11+
namespace toucan
12+
{
13+
class Clip : public IItem
14+
{
15+
public:
16+
Clip();
17+
18+
virtual ~Clip();
19+
};
20+
}
21+

bin/toucan-edit/IContainer.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#include "IContainer.h"
6+
7+
namespace toucan
8+
{
9+
IContainer::IContainer()
10+
{}
11+
12+
IContainer::~IContainer()
13+
{}
14+
15+
const std::vector<std::shared_ptr<IItem> >& IContainer::getChildren() const
16+
{
17+
return _children;
18+
}
19+
20+
void IContainer::addChild(const std::shared_ptr<IItem>& child)
21+
{
22+
if (auto prev = child->_parent.lock())
23+
{
24+
const auto i = std::find(prev->_children.begin(), prev->_children.end(), child);
25+
if (i != prev->_children.end())
26+
{
27+
prev->_children.erase(i);
28+
}
29+
}
30+
child->_parent = std::dynamic_pointer_cast<IContainer>(shared_from_this());
31+
_children.push_back(child);
32+
}
33+
34+
void IContainer::removeChild(const std::shared_ptr<IItem>& child)
35+
{
36+
const auto i = std::find(_children.begin(), _children.end(), child);
37+
if (i != _children.end())
38+
{
39+
child->_parent.reset();
40+
_children.erase(i);
41+
}
42+
}
43+
}

bin/toucan-edit/IContainer.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#pragma once
6+
7+
#include "IItem.h"
8+
9+
#include <vector>
10+
11+
namespace toucan
12+
{
13+
class IContainer : public IItem
14+
{
15+
public:
16+
IContainer();
17+
18+
virtual ~IContainer() = 0;
19+
20+
const std::vector<std::shared_ptr<IItem> >& getChildren() const;
21+
void addChild(const std::shared_ptr<IItem>&);
22+
void removeChild(const std::shared_ptr<IItem>&);
23+
24+
private:
25+
std::vector<std::shared_ptr<IItem> > _children;
26+
};
27+
}
28+

bin/toucan-edit/IItem.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#include "IItem.h"
6+
7+
#include "IContainer.h"
8+
9+
namespace toucan
10+
{
11+
IItem::IItem()
12+
{}
13+
14+
IItem::~IItem()
15+
{}
16+
17+
const OTIO_NS::TimeRange& IItem::getRange() const
18+
{
19+
return _range;
20+
}
21+
22+
void IItem::setRange(const OTIO_NS::TimeRange& range)
23+
{
24+
_range = range;
25+
}
26+
27+
const std::weak_ptr<IContainer>& IItem::getParent() const
28+
{
29+
return _parent;
30+
}
31+
}

bin/toucan-edit/IItem.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#pragma once
6+
7+
#include <opentimelineio/anyDictionary.h>
8+
9+
#include <memory>
10+
11+
namespace toucan
12+
{
13+
class IContainer;
14+
15+
class IItem : public std::enable_shared_from_this<IItem>
16+
{
17+
public:
18+
IItem();
19+
20+
virtual ~IItem() = 0;
21+
22+
const OTIO_NS::TimeRange& getRange() const;
23+
void setRange(const OTIO_NS::TimeRange&);
24+
25+
const std::weak_ptr<IContainer>& getParent() const;
26+
27+
private:
28+
OTIO_NS::TimeRange _range;
29+
std::weak_ptr<IContainer> _parent;
30+
31+
friend class IContainer;
32+
};
33+
}
34+

bin/toucan-edit/Stack.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#include "Stack.h"
6+
7+
namespace toucan
8+
{
9+
Stack::Stack()
10+
{}
11+
12+
Stack::~Stack()
13+
{}
14+
}

bin/toucan-edit/Stack.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2024 Darby Johnston
3+
// All rights reserved.
4+
5+
#pragma once
6+
7+
#include "IContainer.h"
8+
9+
#include <vector>
10+
11+
namespace toucan
12+
{
13+
class Stack : public IContainer
14+
{
15+
public:
16+
Stack();
17+
18+
virtual ~Stack();
19+
};
20+
}
21+

0 commit comments

Comments
 (0)