9#include "dsp/parameter.h"
10#include "dsp/port_all.h"
11#include "dsp/port_span.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"
16#include "plugins/plugin_slot.h"
18namespace zrythm::plugins
33 int programIndex READ programIndex WRITE setProgramIndex NOTIFY
47 instantiationStatusChanged)
51 Z_DISABLE_COPY_MOVE (
Plugin)
76 int programIndex ()
const {
return program_index_.value_or (-1); }
77 void setProgramIndex (
int index)
79 if (program_index_.value_or (-1) == index)
84 program_index_.emplace (index);
88 program_index_.reset ();
110 return std::get<dsp::ProcessorParameter *> (
111 dependencies ().param_registry_.find_by_id_or_throw (
bypass_id_.value ()));
115 return std::get<dsp::ProcessorParameter *> (
116 dependencies ().param_registry_.find_by_id_or_throw (
gain_id_.value ()));
119 bool uiVisible ()
const {
return visible_; }
120 void setUiVisible (
bool visible)
122 if (visible == visible_)
137 return instantiation_status_;
155 return *configuration ()->descr_;
159 return configuration ()->
descr_->name_;
163 return configuration ()->
descr_->protocol_;
180 void custom_prepare_for_processing (
182 units::sample_rate_t sample_rate,
189 void custom_release_resources () final;
193 fs::path get_state_directory ()
const
197 type_safe::get (get_uuid ())
198 .toString (QUuid::WithoutBraces)
207 const auto * bypass = bypassParameter ();
208 return !bypass->range ().is_toggled (bypass->currentValue ());
211 bool currently_enabled_rt () const noexcept [[clang::nonblocking]]
213 const auto * bypass = bypass_param_rt_;
214 return !bypass->range ().is_toggled (bypass->currentValue ());
231 virtual void save_state (std::optional<fs::path> abs_state_dir) = 0;
238 virtual void load_state (std::optional<fs::path> abs_state_dir) = 0;
241 virtual void prepare_for_processing_impl (
242 units::sample_rate_t sample_rate,
247 virtual void release_resources_impl () { }
257 [[gnu::hot]]
virtual void process_passthrough_impl (
269 void init_param_caches ();
296 static constexpr auto kSettingKey =
"setting"sv;
297 static constexpr auto kProgramIndexKey =
"programIndex"sv;
298 static constexpr auto kVisibleKey =
"visible"sv;
299 friend void to_json (nlohmann::json &j,
const Plugin &p)
301 to_json (j,
static_cast<const UuidIdentifiableObject &
> (p));
303 j[kSettingKey] = p.configuration_;
304 j[kProgramIndexKey] = p.program_index_;
305 j[kVisibleKey] = p.visible_;
307 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_;
349 std::unique_ptr<PluginConfiguration> configuration_;
354 std::optional<int> program_index_;
359 bool visible_ =
false;
364 bool set_configuration_called_{};
372using PluginVariant = std::variant<JucePlugin, ClapPlugin, InternalPluginBase>;
373using PluginPtrVariant = to_pointer_variant<PluginVariant>;
377using PluginRegistry = utils::OwningObjectRegistry<PluginPtrVariant, Plugin>;
378using PluginUuidReference = utils::UuidReference<PluginRegistry>;
380using PluginHostWindowFactory =
381 std::function<std::unique_ptr<plugins::IPluginHostWindow> (
Plugin &)>;
385DEFINE_UUID_HASH_SPECIALIZATION (zrythm::plugins::Plugin::Uuid)
388from_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.
std::optional< dsp::ProcessorParameter::Uuid > gain_id_
Zrythm-provided plugin gain parameter.
virtual void load_state(std::optional< fs::path > abs_state_dir)=0
Load the state from the default directory or from abs_state_dir if given.
Plugin(ProcessorBaseDependencies dependencies, StateDirectoryParentPathProvider state_path_provider, QObject *parent)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
void custom_process_block(EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport) noexcept final
Custom processor logic after processing all owned parameters.
int programIndex() const
Returns the current program index, or -1 if no program exists.
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...
Q_SIGNAL void uiVisibleChanged(bool visible)
Implementations should listen to this and show/hide the plugin UI accordingly.
virtual void save_state(std::optional< fs::path > abs_state_dir)=0
Saves the state inside the standard state directory.
@ Pending
Instantiation underway.
@ Successful
Instantiation successful.
@ Failed
Instantiation failed.
std::optional< dsp::ProcessorParameter::Uuid > bypass_id_
Bypass toggle parameter,.
std::function< fs::path()> StateDirectoryParentPathProvider
Returns the parent path where the plugin should save its state directory in (or load it).
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.
StateDirectoryParentPathProvider state_dir_parent_path_provider_
Plugins should create a state directory with their UUID as the directory name under the path provided...
Q_SIGNAL void programIndexChanged(int index)
Implementations should attach to this and set the program.
Q_SIGNAL void configurationChanged(PluginConfiguration *configuration)
Emitted when the configuration is set on the plugin.
void set_configuration(const PluginConfiguration &setting)
Sets the plugin setting 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.
uint32_t nframes_t
Frame count.
Common struct to pass around during processing to avoid repeating the data in function arguments.