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 <QObject>
48#include <QString>
49#include <QtQmlIntegration>
50
51namespace zrythm::plugins
52{
53
54//==============================================================================
55
56using ProtocolPluginPathsProvider =
57 std::function<std::unique_ptr<utils::FilePathList> (Protocol::ProtocolType)>;
58
60
61// can't use QObject in nested classes so we put it in a namespace
62namespace scanner_private
63{
70class Worker final : public QObject
71{
72 Q_OBJECT
73
74public:
80
81public:
88 Q_SLOT void process ();
89
93 void requestStop ();
94
101 Q_SIGNAL void finished ();
102
103private:
104 PluginScanManager &scanner_;
105 std::atomic<bool> should_stop_{ false };
106};
107} // namespace scanner_private
108
109//==============================================================================
110
127class PluginScanManager final : public QObject
128{
129 Q_OBJECT
130 QML_ELEMENT
131 Q_PROPERTY (
132 QString currentlyScanningPlugin READ getCurrentlyScanningPlugin NOTIFY
134 QML_UNCREATABLE ("")
135
136 Z_DISABLE_COPY_MOVE (PluginScanManager)
137
138public:
151 explicit PluginScanManager (
152 std::shared_ptr<juce::KnownPluginList> known_plugins,
153 std::shared_ptr<juce::AudioPluginFormatManager> format_manager,
154 ProtocolPluginPathsProvider plugin_paths_provider,
155 QObject * parent = nullptr);
156
157 ~PluginScanManager () override;
158
162 Q_INVOKABLE void requestStop ();
163
164 friend class scanner_private::Worker;
165
169 Q_INVOKABLE void beginScan ();
170
174 QString getCurrentlyScanningPlugin () const;
175
180 Q_SIGNAL void scanningFinished ();
181
188 // Q_SIGNAL void pluginsAdded ();
189
195 Q_SIGNAL void currentlyScanningPluginChanged (const QString &plugin);
196
200 // auto get_scanned_plugins () const { return known_plugin_list_; }
201
202private:
203 void scan_for_plugins ();
204
205 void set_currently_scanning_plugin (const QString &plugin);
206
212 Q_SLOT void scan_finished ();
213
214private:
215 std::shared_ptr<juce::KnownPluginList> known_plugin_list_;
216 ProtocolPluginPathsProvider plugin_paths_provider_;
217 std::shared_ptr<juce::AudioPluginFormatManager> format_manager_;
218
219 mutable QMutex currently_scanning_plugin_mutex_;
220 QString currently_scanning_plugin_;
221
222 // Temporaries
225};
226
227} // 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:38