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
53namespace zrythm::plugins
54{
55
56//==============================================================================
57
58using ProtocolPluginPathsProvider =
59 std::function<std::unique_ptr<utils::FilePathList> (Protocol::ProtocolType)>;
60
62
63// can't use QObject in nested classes so we put it in a namespace
64namespace scanner_private
65{
72class Worker final : public QObject
73{
74 Q_OBJECT
75
76public:
82
83public:
90 Q_SLOT void process ();
91
95 void requestStop ();
96
103 Q_SIGNAL void finished ();
104
105private:
106 PluginScanManager &scanner_;
107 std::atomic<bool> should_stop_{ false };
108};
109} // namespace scanner_private
110
111//==============================================================================
112
129class PluginScanManager final : public QObject
130{
131 Q_OBJECT
132 QML_ELEMENT
133 Q_PROPERTY (
134 QString currentlyScanningPlugin READ getCurrentlyScanningPlugin NOTIFY
136 QML_UNCREATABLE ("")
137
138 Z_DISABLE_COPY_MOVE (PluginScanManager)
139
140public:
153 explicit PluginScanManager (
154 std::shared_ptr<juce::KnownPluginList> known_plugins,
155 std::shared_ptr<juce::AudioPluginFormatManager> format_manager,
156 ProtocolPluginPathsProvider plugin_paths_provider,
157 QObject * parent = nullptr);
158
159 ~PluginScanManager () override;
160
164 Q_INVOKABLE void requestStop ();
165
166 friend class scanner_private::Worker;
167
171 Q_INVOKABLE void beginScan ();
172
176 QString getCurrentlyScanningPlugin () const;
177
182 Q_SIGNAL void scanningFinished ();
183
190 // Q_SIGNAL void pluginsAdded ();
191
197 Q_SIGNAL void currentlyScanningPluginChanged (const QString &plugin);
198
202 // auto get_scanned_plugins () const { return known_plugin_list_; }
203
204private:
205 void scan_for_plugins ();
206
207 void set_currently_scanning_plugin (const QString &plugin);
208
214 Q_SLOT void scan_finished ();
215
216private:
217 std::shared_ptr<juce::KnownPluginList> known_plugin_list_;
218 ProtocolPluginPathsProvider plugin_paths_provider_;
219 std::shared_ptr<juce::AudioPluginFormatManager> format_manager_;
220
221 mutable QMutex currently_scanning_plugin_mutex_;
222 QString currently_scanning_plugin_;
223
224 // Temporaries
227};
228
229} // 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