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
12#include <juce_audio_processors/juce_audio_processors.h>
13
14namespace zrythm::plugins::discovery
15{
16
17class PluginDescriptorList : public QAbstractListModel
18{
19 Q_OBJECT
20 QML_ELEMENT
21 QML_UNCREATABLE ("")
22
23 // TODO: move this somewhere else as a general util that allows using a lambda
24 // for juce callback listeners
25 class KnownPluginListChangeListener final : public juce::ChangeListener
26 {
27 public:
28 using CallbackFunc = std::function<void (juce::ChangeBroadcaster *)>;
29
30 KnownPluginListChangeListener (CallbackFunc callback);
31
32 private:
33 void changeListenerCallback (juce::ChangeBroadcaster * source) override
34 {
35 callback_ (source);
36 }
37
38 private:
39 CallbackFunc callback_;
40 };
41
42public:
43 explicit PluginDescriptorList (
44 std::shared_ptr<juce::KnownPluginList> known_plugin_list,
45 QObject * parent = nullptr);
46
47 enum PluginDescriptorRole
48 {
49 DescriptorRole = Qt::UserRole + 1,
50 DescriptorNameRole,
51 };
52
53 QHash<int, QByteArray> roleNames () const override;
54
55 QModelIndex
56 index (int row, int column, const QModelIndex &parent = QModelIndex ())
57 const override;
58
59 QModelIndex parent (const QModelIndex &child) const override;
60
61 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
62
63 int columnCount (const QModelIndex &parent = QModelIndex ()) const override;
64
65 QVariant
66 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
67
68 void reset_model ();
69
70private:
72 void update_cache ();
73
76 void schedule_update_cache ();
77
78private:
79 KnownPluginListChangeListener known_plugin_list_change_listener_;
80 std::shared_ptr<juce::KnownPluginList> known_plugin_list_;
81 std::vector<utils::QObjectUniquePtr<PluginDescriptor>> cached_descriptors_;
83};
84}
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36