Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_descriptor_list.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "plugins/plugin_descriptor.h"
7#include "utils/debouncer.h"
8
9#include <QAbstractListModel>
10#include <QtQmlIntegration/qqmlintegration.h>
11
12namespace zrythm::plugins::discovery
13{
14
15class PluginDescriptorList : public QAbstractListModel
16{
17 Q_OBJECT
18 QML_ELEMENT
19 QML_UNCREATABLE ("")
20
21 // TODO: move this somewhere else as a general util that allows using a lambda
22 // for juce callback listeners
23 class KnownPluginListChangeListener final : public juce::ChangeListener
24 {
25 public:
26 using CallbackFunc = std::function<void (juce::ChangeBroadcaster *)>;
27
28 KnownPluginListChangeListener (CallbackFunc callback);
29
30 private:
31 void changeListenerCallback (juce::ChangeBroadcaster * source) override
32 {
33 callback_ (source);
34 }
35
36 private:
37 CallbackFunc callback_;
38 };
39
40public:
41 explicit PluginDescriptorList (
42 std::shared_ptr<juce::KnownPluginList> known_plugin_list,
43 QObject * parent = nullptr);
44
45 enum PluginDescriptorRole
46 {
47 DescriptorRole = Qt::UserRole + 1,
48 DescriptorNameRole,
49 };
50
51 QHash<int, QByteArray> roleNames () const override;
52
53 QModelIndex
54 index (int row, int column, const QModelIndex &parent = QModelIndex ())
55 const override;
56
57 QModelIndex parent (const QModelIndex &child) const override;
58
59 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
60
61 int columnCount (const QModelIndex &parent = QModelIndex ()) const override;
62
63 QVariant
64 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
65
66 void reset_model ();
67
68private:
70 void update_cache ();
71
74 void schedule_update_cache ();
75
76private:
77 KnownPluginListChangeListener known_plugin_list_change_listener_;
78 std::shared_ptr<juce::KnownPluginList> known_plugin_list_;
79 std::vector<utils::QObjectUniquePtr<PluginDescriptor>> cached_descriptors_;
81};
82}
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38