10#include "dsp/parameter.h"
11#include "dsp/port_all.h"
12#include "dsp/port_span.h"
13#include "dsp/processor_base.h"
14#include "plugins/iplugin_host_window.h"
15#include "plugins/plugin_configuration.h"
16#include "plugins/plugin_descriptor.h"
21namespace zrythm::plugins
49 int programIndex READ programIndex WRITE setProgramIndex NOTIFY
63 instantiationStatusChanged)
67 Q_DISABLE_COPY_MOVE (
Plugin)
86 int programIndex ()
const {
return program_index_.value_or (-1); }
87 void setProgramIndex (
int index)
89 if (program_index_.value_or (-1) == index)
94 program_index_.emplace (index);
98 program_index_.reset ();
109 PluginConfiguration * configuration ()
const {
return configuration_.get (); }
126 bool generateNewPluginPortsAndParams);
130 return std::get<dsp::ProcessorParameter *> (
131 dependencies ().param_registry_.find_by_id_or_throw (
bypass_id_.value ()));
135 return std::get<dsp::ProcessorParameter *> (
136 dependencies ().param_registry_.find_by_id_or_throw (
gain_id_.value ()));
139 bool uiVisible ()
const {
return visible_; }
140 void setUiVisible (
bool visible)
142 if (visible == visible_)
157 return instantiation_status_;
175 return *configuration ()->descr_;
179 return configuration ()->
descr_->name_;
183 return configuration ()->
descr_->protocol_;
204 void custom_prepare_for_processing (
206 units::sample_rate_t sample_rate,
207 units::sample_u32_t max_block_length)
final;
212 const dsp::TempoMap &tempo_map)
noexcept final;
214 void custom_release_resources () final;
223 const auto * bypass = bypassParameter ();
224 return !bypass->range ().is_toggled (bypass->currentValue ());
227 bool currently_enabled_rt () const noexcept [[clang::nonblocking]]
229 const auto * bypass = bypass_param_rt_;
230 return !bypass->range ().is_toggled (bypass->currentValue ());
250 void load_state (
const std::string &base64_state);
261 virtual void prepare_for_processing_impl (
262 units::sample_rate_t sample_rate,
263 units::sample_u32_t max_block_length) { };
268 virtual void release_resources_impl () { }
278 [[gnu::hot]]
virtual void process_passthrough_impl (
281 const dsp::TempoMap &tempo_map)
noexcept;
283 virtual std::string save_state_impl ()
const = 0;
284 virtual void load_state_impl (
const std::string &base64_state) = 0;
294 void init_param_caches ();
318 static constexpr auto kConfigurationKey =
"configuration"sv;
319 static constexpr auto kProgramIndexKey =
"programIndex"sv;
320 static constexpr auto kProtocolKey =
"protocol"sv;
321 static constexpr auto kVisibleKey =
"visible"sv;
322 friend void to_json (nlohmann::json &j,
const Plugin &p);
323 friend void from_json (
const nlohmann::json &j,
Plugin &p);
340 std::optional<dsp::ProcessorParameter::Uuid>
bypass_id_;
345 std::optional<dsp::ProcessorParameter::Uuid>
gain_id_;
348 std::vector<dsp::AudioPort *> audio_in_ports_;
349 std::vector<dsp::AudioPort *> audio_out_ports_;
350 std::vector<dsp::CVPort *> cv_in_ports_;
386 pending_value (other.pending_value.load (std::memory_order_relaxed))
389 Entry &operator= (Entry &&other)
noexcept
395 other.pending_value.load (std::memory_order_relaxed),
396 std::memory_order_relaxed);
405 void prepare (
size_t count) {
entries.resize (count); }
414 std::unique_ptr<PluginConfiguration> configuration_;
419 std::optional<int> program_index_;
424 bool visible_ =
false;
429 bool set_configuration_called_{};
436 utils::QObjectUniquePtr<QTimer> param_flush_timer_;
444using PluginVariant = std::variant<JucePlugin, ClapPlugin, InternalPluginBase>;
445using PluginPtrVariant = to_pointer_variant<PluginVariant>;
449using PluginRegistry = utils::OwningObjectRegistry<PluginPtrVariant, Plugin>;
450using PluginUuidReference = utils::UuidReference<PluginRegistry>;
452using PluginHostWindowFactory =
453 std::function<std::unique_ptr<plugins::IPluginHostWindow> (
Plugin &)>;
457DEFINE_UUID_HASH_SPECIALIZATION (zrythm::plugins::Plugin::Uuid)
460from_json (
const nlohmann::json &j, zrythm::plugins::PluginRegistry ®istry);
A base class for processors in the DSP graph.
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
Represents a node in a DSP graph.
CLAP-based plugin host implementation.
A base class for internal plugins.
JUCE-based plugin host implementation.
Configuration for instantiating a plugin descriptor.
std::unique_ptr< zrythm::plugins::PluginDescriptor > descr_
The descriptor of the plugin this setting is for.
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
bool instantiation_failed_
Set to true if instantiation failed and the plugin will be treated as disabled.
Plugin(ProcessorBaseDependencies dependencies, QObject *parent)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
std::optional< dsp::ProcessorParameter::Uuid > gain_id_
Zrythm-provided plugin gain parameter.
int programIndex() const
Returns the current program index, or -1 if no program exists.
std::string save_state() const
Serializes the plugin's internal state to a base64-encoded string.
bool currently_enabled() const
Returns whether the plugin is enabled (not bypassed).
dsp::ProcessorParameterUuidReference generate_default_gain_param() const
To be called by implementations to generate the default gain parameter if the plugin does not provide...
void load_state(const std::string &base64_state)
Queues a previously saved state to be applied to the plugin.
Q_SIGNAL void uiVisibleChanged(bool visible)
Implementations should listen to this and show/hide the plugin UI accordingly.
@ Pending
Instantiation underway.
@ Successful
Instantiation successful.
@ Failed
Instantiation failed.
Q_SIGNAL void configurationChanged(PluginConfiguration *configuration, bool generateNewPluginPortsAndParams)
Emitted when the configuration is set on the plugin.
std::optional< dsp::ProcessorParameter::Uuid > bypass_id_
Bypass toggle parameter,.
dsp::ProcessorParameterUuidReference generate_default_bypass_param() const
To be called by implementations to generate the default bypass parameter if the plugin does not provi...
void custom_process_block(dsp::graph::EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept final
Custom processor logic after processing all owned parameters.
Q_SIGNAL void instantiationFinished(bool successful, const QString &error)
To be emitted by implementations when instantiation finished.
Q_SIGNAL void programIndexChanged(int index)
Implementations should attach to this and set the program.
void flush_plugin_values()
Flushes plugin-reported parameter values to Zrythm params.
void set_configuration(const PluginConfiguration &setting)
Sets the plugin configuration to use.
ProtocolType
Plugin protocol.
Lightweight UTF-8 string wrapper with safe conversions.
Base class for objects that need to be uniquely identified by UUID.
Common struct to pass around during processing to avoid repeating the data in function arguments.
std::atomic< float > pending_value
Cross-thread bridge: audio thread stores normalized value with release ordering; main thread exchange...
float last_from_plugin
One-shot feedback guard: set when the plugin reports a value.
Per-parameter state for bidirectional plugin sync.
std::vector< Entry > entries
Parallel to ProcessorBase's live_params_.