10#include "dsp/parameter.h"
11#include "dsp/port_all.h"
12#include "dsp/processor_base.h"
13#include "plugins/iplugin_host_window.h"
14#include "plugins/plugin_configuration.h"
15#include "plugins/plugin_descriptor.h"
17#include "utils/registry_utils.h"
18#include "utils/variant_helpers.h"
22namespace zrythm::plugins
47 int programIndex READ programIndex WRITE setProgramIndex NOTIFY
61 instantiationStatusChanged)
65 Q_DISABLE_COPY_MOVE (
Plugin)
84 int programIndex ()
const {
return program_index_.value_or (-1); }
85 void setProgramIndex (
int index)
87 if (program_index_.value_or (-1) == index)
92 program_index_.emplace (index);
96 program_index_.reset ();
107 PluginConfiguration * configuration ()
const {
return configuration_.get (); }
124 bool generateNewPluginPortsAndParams);
129 bool uiVisible ()
const {
return visible_; }
130 void setUiVisible (
bool visible)
132 if (visible == visible_)
147 return instantiation_status_;
165 return *configuration ()->descr_;
169 return configuration ()->
descr_->name_;
173 return configuration ()->
descr_->protocol_;
194 void custom_prepare_for_processing (
196 units::sample_rate_t sample_rate,
197 units::sample_u32_t max_block_length)
final;
202 const dsp::TempoMap &tempo_map)
noexcept final;
204 void custom_release_resources () final;
213 const auto * bypass = bypassParameter ();
214 return !bypass->range ().isToggled (bypass->currentValue ());
217 bool currently_enabled_rt () const noexcept [[clang::nonblocking]]
219 const auto * bypass = bypass_param_rt_;
220 return !bypass->range ().isToggled (bypass->currentValue ());
240 void load_state (
const std::string &base64_state);
251 virtual void prepare_for_processing_impl (
252 units::sample_rate_t sample_rate,
253 units::sample_u32_t max_block_length) { };
258 virtual void release_resources_impl () { }
268 [[gnu::hot]]
virtual void process_passthrough_impl (
271 const dsp::TempoMap &tempo_map)
noexcept;
273 virtual std::string save_state_impl ()
const = 0;
274 virtual void load_state_impl (
const std::string &base64_state) = 0;
284 void init_param_caches ();
308 static constexpr auto kConfigurationKey =
"configuration"sv;
309 static constexpr auto kProgramIndexKey =
"programIndex"sv;
310 static constexpr auto kProtocolKey =
"protocol"sv;
311 static constexpr auto kVisibleKey =
"visible"sv;
312 friend void to_json (nlohmann::json &j,
const Plugin &p);
313 friend void from_json (
const nlohmann::json &j,
Plugin &p);
330 std::optional<dsp::ProcessorParameter::Uuid>
bypass_id_;
335 std::optional<dsp::ProcessorParameter::Uuid>
gain_id_;
338 std::vector<dsp::AudioPort *> audio_in_ports_;
339 std::vector<dsp::AudioPort *> audio_out_ports_;
340 std::vector<dsp::CVPort *> cv_in_ports_;
376 pending_value (other.pending_value.load (std::memory_order_relaxed))
379 Entry &operator= (Entry &&other)
noexcept
385 other.pending_value.load (std::memory_order_relaxed),
386 std::memory_order_relaxed);
395 void prepare (
size_t count) {
entries.resize (count); }
404 std::unique_ptr<PluginConfiguration> configuration_;
409 std::optional<int> program_index_;
414 bool visible_ =
false;
419 bool set_configuration_called_{};
426 utils::QObjectUniquePtr<QTimer> param_flush_timer_;
434using PluginVariant = std::variant<JucePlugin, ClapPlugin, InternalPluginBase>;
437using PluginUuidReference = utils::TypedUuidReference<Plugin>;
439using PluginHostWindowFactory =
440 std::function<std::unique_ptr<plugins::IPluginHostWindow> (
Plugin &)>;
444DEFINE_UUID_HASH_SPECIALIZATION (zrythm::plugins::Plugin::Uuid)
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(utils::IObjectRegistry ®istry, QObject *parent)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
void custom_process_block(dsp::graph::ProcessBlockInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept final
Custom processor logic after processing all owned parameters.
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...
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.
Abstract interface for a UUID-keyed object registry.
Lightweight UTF-8 string wrapper with safe conversions.
CRTP base that adds a typed UUID strong-typedef to a class hierarchy.
typename to_pointer_variant_impl< Variant >::type to_pointer_variant
Converts a variant to a variant of pointers.
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_.