Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_scan_manager.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 * ---
7 *
8 * This file is part of the JUCE framework.
9 * Copyright (c) Raw Material Software Limited
10 *
11 * JUCE is an open source framework subject to commercial or open source
12 * licensing.
13 *
14 * By downloading, installing, or using the JUCE framework, or combining the
15 * JUCE framework with any other source code, object code, content or any other
16 * copyrightable work, you agree to the terms of the JUCE End User Licence
17 * Agreement, and all incorporated terms including the JUCE Privacy Policy and
18 * the JUCE Website Terms of Service, as applicable, which will bind you. If you
19 * do not agree to the terms of these agreements, we will not license the JUCE
20 * framework to you, and you must discontinue the installation or download
21 * process and cease use of the JUCE framework.
22 *
23 * JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
24 * JUCE Privacy Policy: https://juce.com/juce-privacy-policy
25 * JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
26 *
27 * Or:
28 *
29 * You may also use this code under the terms of the AGPLv3:
30 * https://www.gnu.org/licenses/agpl-3.0.en.html
31 *
32 * THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
33 * WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
34 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
35 * ---
36 * SPDX-FileCopyrightText: (c) Raw Material Software Limited
37 * SPDX-License-Identifier: AGPL-3.0-only
38 */
39
40#pragma once
41
42#include "plugins/plugin_protocol.h"
43#include "utils/file_path_list.h"
44#include "utils/qt.h"
45
46#include <QList>
47#include <QMutex>
48#include <QObject>
49#include <QString>
50#include <QThread>
51#include <QtQmlIntegration/qqmlintegration.h>
52
53#include <juce_audio_processors/juce_audio_processors.h>
54
55namespace zrythm::plugins
56{
57
58//==============================================================================
59
60using ProtocolPluginPathsProvider =
61 std::function<std::unique_ptr<utils::FilePathList> (Protocol::ProtocolType)>;
62
64
65// can't use QObject in nested classes so we put it in a namespace
66namespace scanner_private
67{
74class Worker final : public QObject
75{
76 Q_OBJECT
77
78public:
84
85public:
92 Q_SLOT void process ();
93
97 void requestStop ();
98
105 Q_SIGNAL void finished ();
106
107private:
108 PluginScanManager &scanner_;
109 std::atomic<bool> should_stop_{ false };
110};
111} // namespace scanner_private
112
113//==============================================================================
114
131class PluginScanManager final : public QObject
132{
133 Q_OBJECT
134 QML_ELEMENT
135 Q_PROPERTY (
136 QString currentlyScanningPlugin READ getCurrentlyScanningPlugin NOTIFY
138 QML_UNCREATABLE ("")
139
140 Q_DISABLE_COPY_MOVE (PluginScanManager)
141
142public:
155 explicit PluginScanManager (
156 std::shared_ptr<juce::KnownPluginList> known_plugins,
157 std::shared_ptr<juce::AudioPluginFormatManager> format_manager,
158 ProtocolPluginPathsProvider plugin_paths_provider,
159 QObject * parent = nullptr);
160
161 ~PluginScanManager () override;
162
166 Q_INVOKABLE void requestStop ();
167
168 friend class scanner_private::Worker;
169
173 Q_INVOKABLE void beginScan ();
174
178 QString getCurrentlyScanningPlugin () const;
179
184 Q_SIGNAL void scanningFinished ();
185
192 // Q_SIGNAL void pluginsAdded ();
193
199 Q_SIGNAL void currentlyScanningPluginChanged (const QString &plugin);
200
204 // auto get_scanned_plugins () const { return known_plugin_list_; }
205
206private:
207 void scan_for_plugins ();
208
209 void set_currently_scanning_plugin (const QString &plugin);
210
216 Q_SLOT void scan_finished ();
217
218private:
219 std::shared_ptr<juce::KnownPluginList> known_plugin_list_;
220 ProtocolPluginPathsProvider plugin_paths_provider_;
221 std::shared_ptr<juce::AudioPluginFormatManager> format_manager_;
222
223 mutable QMutex currently_scanning_plugin_mutex_;
224 QString currently_scanning_plugin_;
225
226 // Temporaries
229};
230
231} // namespace zrythm::plugins
Scans for plugins and manages the scanning process.
PluginScanManager(std::shared_ptr< juce::KnownPluginList > known_plugins, std::shared_ptr< juce::AudioPluginFormatManager > format_manager, ProtocolPluginPathsProvider plugin_paths_provider, QObject *parent=nullptr)
Constructs a PluginScanManager object.
Q_INVOKABLE void requestStop()
Request the worker thread to stop gracefully.
Q_INVOKABLE void beginScan()
To be called by QML to begin scanning.
Q_SIGNAL void scanningFinished()
Emitted after the scan has finished and after this instance has been moved to the main thread.
QString getCurrentlyScanningPlugin() const
Get the currently scanning plugin (property accessor).
Q_SIGNAL void currentlyScanningPluginChanged(const QString &plugin)
Emitted from the scan thread (not the main thread) when a new (not known) plugin is added to the list...
A worker thread for the PluginScanManager class.
void requestStop()
Request the worker to stop gracefully.
Q_SIGNAL void finished()
Emitted when the scanning process has finished.
Worker(PluginScanManager &scanner_)
Constructs a new Worker instance.
Q_SLOT void process()
Starts the plugin scanning process.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36