Skip to content

Commit

Permalink
Add file settings
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Mar 6, 2025
1 parent cb5f8a3 commit f32887a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion etc/SuperBuild/cmake/Modules/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 "517f1919215d0d58e750a60e42fc2a772b2f2d33")
set(dtk_GIT_TAG "200b49039ab98bba3b58defabffad9e62f6c21e0")

set(dtk-deps_ARGS
-Ddtk_API=${dtk_API}
Expand Down
2 changes: 1 addition & 1 deletion etc/SuperBuild/cmake/Modules/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 "517f1919215d0d58e750a60e42fc2a772b2f2d33")
set(dtk_GIT_TAG "200b49039ab98bba3b58defabffad9e62f6c21e0")

set(dtk_DEPS dtk-deps)
set(dtk_ARGS
Expand Down
2 changes: 1 addition & 1 deletion lib/tlPlayApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ namespace tl

p.timeUnitsModel = TimeUnitsModel::create(_context, p.settings);

p.filesModel = FilesModel::create(_context);
p.filesModel = FilesModel::create(_context, p.settings);

p.recentFilesModel = RecentFilesModel::create(_context, p.settings);

Expand Down
31 changes: 23 additions & 8 deletions lib/tlPlayApp/Models/FilesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <tlPlayApp/Models/FilesModel.h>

#include <dtk/ui/Settings.h>
#include <dtk/core/Math.h>

namespace tl
Expand All @@ -12,7 +13,7 @@ namespace tl
{
struct FilesModel::Private
{
std::weak_ptr<dtk::Context> context;
std::shared_ptr<dtk::Settings> settings;
std::shared_ptr<dtk::ObservableList<std::shared_ptr<FilesModelItem> > > files;
std::shared_ptr<dtk::ObservableValue<std::shared_ptr<FilesModelItem> > > a;
std::shared_ptr<dtk::ObservableValue<int> > aIndex;
Expand All @@ -24,11 +25,13 @@ namespace tl
std::shared_ptr<dtk::ObservableValue<timeline::CompareTime> > compareTime;
};

void FilesModel::_init(const std::shared_ptr<dtk::Context>& context)
void FilesModel::_init(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<dtk::Settings>& settings)
{
DTK_P();

p.context = context;
p.settings = settings;

p.files = dtk::ObservableList<std::shared_ptr<FilesModelItem> >::create();
p.a = dtk::ObservableValue<std::shared_ptr<FilesModelItem> >::create();
Expand All @@ -37,21 +40,33 @@ namespace tl
p.bIndexes = dtk::ObservableList<int>::create();
p.active = dtk::ObservableList<std::shared_ptr<FilesModelItem> >::create();
p.layers = dtk::ObservableList<int>::create();
p.compareOptions = dtk::ObservableValue<timeline::CompareOptions>::create();
p.compareTime = dtk::ObservableValue<timeline::CompareTime>::create();
timeline::CompareOptions compareOptions;
p.settings->getT("Files/CompareOptions", compareOptions);
p.compareOptions = dtk::ObservableValue<timeline::CompareOptions>::create(compareOptions);
std::string s;
p.settings->get("Files/CompareTime", s);
timeline::CompareTime compareTime = timeline::CompareTime::First;
from_string(s, compareTime);
p.compareTime = dtk::ObservableValue<timeline::CompareTime>::create(compareTime);
}

FilesModel::FilesModel() :
_p(new Private)
{}

FilesModel::~FilesModel()
{}
{
DTK_P();
p.settings->setT("Files/CompareOptions", p.compareOptions->get());
p.settings->set("Files/CompareTime", to_string(p.compareTime->get()));
}

std::shared_ptr<FilesModel> FilesModel::create(const std::shared_ptr<dtk::Context>& context)
std::shared_ptr<FilesModel> FilesModel::create(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<dtk::Settings>& settings)
{
auto out = std::shared_ptr<FilesModel>(new FilesModel);
out->_init(context);
out->_init(context, settings);
return out;
}

Expand Down
9 changes: 7 additions & 2 deletions lib/tlPlayApp/Models/FilesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace dtk
{
class Context;
class Settings;
}

namespace tl
Expand All @@ -38,15 +39,19 @@ namespace tl
DTK_NON_COPYABLE(FilesModel);

protected:
void _init(const std::shared_ptr<dtk::Context>&);
void _init(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<dtk::Settings>&);

FilesModel();

public:
~FilesModel();

//! Create a new model.
static std::shared_ptr<FilesModel> create(const std::shared_ptr<dtk::Context>&);
static std::shared_ptr<FilesModel> create(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<dtk::Settings>&);

//! Get the files.
const std::vector<std::shared_ptr<FilesModelItem> >& getFiles() const;
Expand Down
16 changes: 16 additions & 0 deletions lib/tlTimeline/CompareOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,21 @@ namespace tl
}
return out;
}

void to_json(nlohmann::json& json, const CompareOptions& in)
{
json["compare"] = to_string(in.compare);
json["wipeCenter"] = in.wipeCenter;
json["wipeRotation"] = in.wipeRotation;
json["overlay"] = in.overlay;
}

void from_json(const nlohmann::json& json, CompareOptions& out)
{
from_string(json.at("compare").get<std::string>(), out.compare);
json.at("wipeCenter").get_to(out.wipeCenter);
json.at("wipeRotation").get_to(out.wipeRotation);
json.at("overlay").get_to(out.overlay);
}
}
}
9 changes: 9 additions & 0 deletions lib/tlTimeline/CompareOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,14 @@ namespace tl
const OTIO_NS::TimeRange& sourceTimeRange,
const OTIO_NS::TimeRange& compareTimeRange,
CompareTime);

//! \name Serialize
///@{

void to_json(nlohmann::json&, const CompareOptions&);

void from_json(const nlohmann::json&, CompareOptions&);

///@}
}
}

0 comments on commit f32887a

Please sign in to comment.