2#include <Process/ProcessFactory.hpp>
3#include <Process/ProcessMimeSerialization.hpp>
5#include <Library/LibrarySettings.hpp>
7#include <score/application/ApplicationContext.hpp>
8#include <score/model/tree/TreeNode.hpp>
9#include <score/model/tree/TreeNodeItemModel.hpp>
10#include <score/tools/File.hpp>
11#include <score/tools/RecursiveWatch.hpp>
12#include <score/tools/std/Optional.hpp>
13#include <score/tools/std/StringHash.hpp>
15#include <ossia/detail/hash_map.hpp>
20#include <nano_observer.hpp>
21#include <score_plugin_library_export.h>
27struct GUIApplicationContext;
38SCORE_PLUGIN_LIBRARY_EXPORT
43 ,
public Nano::Observer
46 using QAbstractItemModel::beginInsertRows;
47 using QAbstractItemModel::endInsertRows;
49 using QAbstractItemModel::beginRemoveRows;
50 using QAbstractItemModel::endRemoveRows;
53 using QAbstractItemModel::beginResetModel;
54 using QAbstractItemModel::endResetModel;
59 QModelIndex find(
const Process::ProcessModelFactory::ConcreteKey& k);
65 int columnCount(
const QModelIndex& parent)
const override;
66 QVariant data(
const QModelIndex& index,
int role)
const override;
68 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const override;
69 Qt::ItemFlags flags(
const QModelIndex& index)
const override;
72 QStringList mimeTypes()
const override;
73 QMimeData* mimeData(
const QModelIndexList& indexes)
const override;
74 Qt::DropActions supportedDragActions()
const override;
92 std::string libraryFolderPath{};
93 std::string defaultPresetsPath{};
94 ossia::hash_map<QString, Library::ProcessNode*> categories;
97 std::string process_name,
const QModelIndex& idx,
102 SCORE_ASSERT(parent);
106 libraryFolderPath = libraryFolder.absolutePath().toStdString();
109 defaultPresetsPath =
"Presets/" + process_name;
114 SCORE_ASSERT(parent);
115 auto parentFolder = file.dir().dirName();
116 if(
auto it = categories.find(parentFolder); it != categories.end())
118 Library::addToLibrary(*it->second, std::move(pdata));
122 if(file.dir() == libraryFolder
123 || file.absolutePath().endsWith(defaultPresetsPath.c_str()))
125 Library::addToLibrary(*parent, std::move(pdata));
129 auto& category = Library::addToLibrary(
131 Library::addToLibrary(category, std::move(pdata));
132 categories[parentFolder] = &category;
139 SCORE_ASSERT(parent);
141 = QString::fromUtf8(file.parentDirName.data(), file.parentDirName.size());
142 if(
auto it = categories.find(parentFolder); it != categories.end())
144 Library::addToLibrary(*it->second, std::move(pdata));
148 if(file.absolutePath == libraryFolderPath
149 || file.absolutePath.ends_with(defaultPresetsPath))
151 Library::addToLibrary(*parent, std::move(pdata));
155 auto& category = Library::addToLibrary(
157 Library::addToLibrary(category, std::move(pdata));
158 categories[parentFolder] = &category;
172 std::function<std::optional<T>(std::string_view)> filter,
173 std::function<
void(std::string_view, T&&)> commit)
177 std::function<std::optional<T>(std::string_view)> filter;
178 std::function<void(std::string_view, T&&)> commit;
180 auto state = std::make_shared<State>(
State{std::move(filter), std::move(commit)});
182 return {.filter = [state = std::move(state)](std::string_view path)
183 -> std::function<
void()> {
184 auto result = state->filter(path);
188 return [commit = state->commit, p = std::string(path),
189 data = std::move(*result)]()
mutable { commit(p, std::move(data)); };
206W_REGISTER_ARGTYPE(std::optional<Library::ProcessData>)
Definition ProcessesItemModel.hpp:44
Definition LibrarySettings.hpp:46
Definition TreeNodeItemModel.hpp:38
Base class for plug-in interfaces.
Definition Interface.hpp:52
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:33
Base toolkit upon which the software is built.
Definition Application.cpp:113
Definition ProcessesItemModel.hpp:33
Definition ProcessesItemModel.hpp:89
Definition ProcessMimeSerialization.hpp:38
Used to access all the application-wide state and structures.
Definition ApplicationContext.hpp:25
Specializes ApplicationContext with the QMainWindow.
Definition GUIApplicationContext.hpp:15
Definition lib/score/tools/File.hpp:20
Definition RecursiveWatch.hpp:39