Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
out_of_process_scanner.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 <QObject>
43#include <QtQmlIntegration/qqmlintegration.h>
44
45#include "juce_wrapper.h"
46
47namespace zrythm::plugins::discovery
48
49{
50
64class OutOfProcessPluginScanner final
65 : public QObject,
66 public juce::KnownPluginList::CustomScanner
67{
68 Q_OBJECT
69
70public:
71 OutOfProcessPluginScanner (QObject * parent = nullptr);
72 ~OutOfProcessPluginScanner () override;
73
74 bool findPluginTypesFor (
75 juce::AudioPluginFormat &format,
76 juce::OwnedArray<juce::PluginDescription> &result,
77 const juce::String &fileOrIdentifier) override;
78
82 Q_SIGNAL void scanCompleted ();
83
84private:
96 class SubprocessCoordinator final : private juce::ChildProcessCoordinator
97 {
98 public:
99 SubprocessCoordinator ();
100 ~SubprocessCoordinator () override;
101
102 enum class State
103 {
104 Timeout,
105 GotResult,
106 ConnectionLost,
107 };
108
109 struct Response
110 {
111 State state;
112 std::unique_ptr<juce::XmlElement> xml;
113 };
114
115 Response getResponse ();
116
117 using ChildProcessCoordinator::sendMessageToWorker;
118
119 private:
120 void handleMessageFromWorker (const juce::MemoryBlock &mb) override;
121
122 void handleConnectionLost () override;
123
124 std::mutex mutex;
125 std::condition_variable condvar;
126
127 std::unique_ptr<juce::XmlElement> pluginDescription;
128 bool connectionLost = false;
129 bool gotResult = false;
130
131 JUCE_DECLARE_NON_MOVEABLE (SubprocessCoordinator)
132 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubprocessCoordinator)
133 }; // class Superprocess
134
135 /* Scans for a plugin with format 'formatName' and ID 'fileOrIdentifier'
136 using a subprocess, and adds discovered plugin descriptions to 'result'.
137
138 Returns true on success.
139
140 Failure indicates that the subprocess is unrecoverable and should be
141 terminated.
142 */
143 bool add_plugin_descriptions (
144 juce::AudioPluginFormat &format,
145 const juce::String &file_or_identifier,
146 juce::OwnedArray<juce::PluginDescription> &result);
147
148 std::unique_ptr<SubprocessCoordinator> coordinator_;
149
150 JUCE_DECLARE_NON_MOVEABLE (OutOfProcessPluginScanner)
151 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OutOfProcessPluginScanner)
152};
153
154} // namespace zrythm::plugins::discovery
Q_SIGNAL void scanCompleted()
Used to let Qt know when the scan is done.