Loading...
Searching...
No Matches
score-plugin-lv2/LV2/Library.hpp
1#pragma once
2#include <LV2/ApplicationPlugin.hpp>
3#include <LV2/EffectModel.hpp>
4#include <Library/LibraryInterface.hpp>
5#include <Library/ProcessesItemModel.hpp>
6
7#include <score/tools/Bind.hpp>
8
9#include <QCoreApplication>
10#include <QMap>
11#include <QPointer>
12
13namespace LV2
14{
16{
17 SCORE_CONCRETE("570f0b92-a091-47ff-a5c3-a585e07df2bf")
18
20 override
21 {
22 constexpr static const auto key = Metadata<ConcreteKey_k, LV2::Model>::get();
23
24 auto& plug = ctx.applicationPlugin<LV2::ApplicationPlugin>();
25
26 // Stage the whole database grouped by class; the model owns tree
27 // mutation and signals.
28 auto make_plugs = [&plug] {
30 for(const auto& info : plug.cachedDescriptors())
31 {
32 if(!info.valid)
33 continue;
34 QString category
35 = info.class_label.isEmpty() ? QStringLiteral("Other") : info.class_label;
36 auto it = categories.find(category);
37 if(it == categories.end())
38 it = categories.insert(
39 category, Library::StagedNode{{{{}, category, {}}, {}}, {}});
40 it->children.push_back(
41 Library::StagedNode{{{key, info.name, info.uri}, {}}, {}});
42 }
43
44 std::vector<Library::StagedNode> v;
45 v.reserve(categories.size());
46 for(auto& cat : categories) // QMap: already name-sorted
47 v.push_back(std::move(cat));
48 return v;
49 };
50
51 model.clearAnchorKey(key);
52 model.replaceChildren(key, make_plugs());
53
54 QObject::connect(
55 &plug, &LV2::ApplicationPlugin::descriptorsChanged, &model,
56 [model = QPointer{&model}, make_plugs] {
57 if(model)
58 model->replaceChildren(key, make_plugs());
59 });
60 }
61};
62}
Definition score-plugin-lv2/LV2/ApplicationPlugin.hpp:69
Definition score-plugin-lv2/LV2/Library.hpp:16
Definition LibraryInterface.hpp:26
Definition ProcessesItemModel.hpp:38
Definition ClipMode.hpp:10
Definition ProcessEntry.hpp:32
Static metadata implementation.
Definition lib/score/tools/Metadata.hpp:36
Specializes ApplicationContext with the QMainWindow.
Definition GUIApplicationContext.hpp:15