Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
carla_native_plugin.h
1// SPDX-FileCopyrightText: © 2019-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "zrythm-config.h"
7
8#include <utility>
9#include <vector>
10
11#include "plugins/plugin.h"
12#include "utils/icloneable.h"
13#include "utils/types.h"
14
15#if HAVE_CARLA
16# include "carla_wrapper.h"
17#endif
18
19namespace zrythm::plugins
20{
21
22using CarlaPluginHandle = void *;
23
29
30constexpr auto CARLA_STATE_FILENAME = "state.carla"sv;
31
36{
37 CARLA_PLUGIN_NONE,
38 CARLA_PLUGIN_RACK,
39 CARLA_PLUGIN_PATCHBAY,
40 CARLA_PLUGIN_PATCHBAY16,
41 CARLA_PLUGIN_PATCHBAY32,
42 CARLA_PLUGIN_PATCHBAY64,
43};
44
45struct CarlaPatchbayPortInfo
46{
47 CarlaPatchbayPortInfo () = default;
48 CarlaPatchbayPortInfo (
49 unsigned int _plugin_id,
50 unsigned int _port_hints,
51 unsigned int _port_id,
52 std::string _port_name)
53 : plugin_id (_plugin_id), port_hints (_port_hints), port_id (_port_id),
54 port_name (std::move (_port_name))
55 {
56 }
57 unsigned int plugin_id = 0;
58 unsigned int port_hints = 0;
59 unsigned int port_id = 0;
60 std::string port_name;
61};
62
64{
65public:
72
76 ~CarlaNativePlugin () override;
77 Z_DISABLE_COPY_MOVE (CarlaNativePlugin)
78
79#if HAVE_CARLA
83 static std::unique_ptr<PluginDescriptor>
84 get_descriptor_from_cached (const CarlaCachedPluginInfo &info, PluginType type);
85#endif
86
87 void
88 save_state (bool is_backup, std::optional<std::filesystem::path> abs_state_dir)
89 override;
90
96 void load_state (std::optional<std::filesystem::path> abs_path);
97
98 void update_buffer_size_and_sample_rate ();
99
103 void open_custom_ui (bool show) override;
104
109
114
115 float get_param_value (uint32_t id);
116
122
123 void set_param_value (uint32_t id, float val);
124
125 void close () override;
126
127 static bool has_custom_ui (const PluginDescriptor &descr);
128
132
133 units::sample_u32_t get_single_playback_latency () const override;
134
142
143 friend void init_from (
145 const CarlaNativePlugin &other,
146 utils::ObjectCloneType clone_type);
147
148private:
149 friend void to_json (nlohmann::json &j, const CarlaNativePlugin &plugin)
150 {
151 to_json (j, static_cast<const Plugin &> (plugin));
152 }
153 friend void from_json (const nlohmann::json &j, CarlaNativePlugin &plugin)
154 {
155 from_json (j, static_cast<Plugin &> (plugin));
156 }
157
158 void populate_banks () override;
159
160 void set_selected_preset_from_index_impl (int idx) override;
161
162 void activate_impl (bool activate) override;
163
174 void instantiate_impl (bool loading, bool use_state_file) override;
175
179 [[gnu::hot]] void process_impl (EngineProcessTimeInfo time_nfo) override;
180
181 void cleanup_impl () override;
182
186 bool idle_cb ();
187
188 void create_ports (bool loading);
189
190public:
191#if HAVE_CARLA
192 NativePluginHandle native_plugin_handle_ = nullptr;
193 NativeHostDescriptor native_host_descriptor_ = {};
194 const NativePluginDescriptor * native_plugin_descriptor_ = nullptr;
195
196 CarlaHostHandle host_handle_ = nullptr;
197
198 NativeTimeInfo time_info_ = {};
199#endif
200
202 unsigned int carla_plugin_id_ = 0;
203
205 bool ports_created_ = false;
206
208 bool loading_state_ = false;
209
211 unsigned int audio_input_port_id_ = 0;
213 unsigned int audio_output_port_id_ = 0;
214
216 unsigned int cv_input_port_id_ = 0;
218 unsigned int cv_output_port_id_ = 0;
219
221 unsigned int midi_input_port_id_ = 0;
223 unsigned int midi_output_port_id_ = 0;
224
226 std::vector<CarlaPatchbayPortInfo> patchbay_port_info_;
227
240 // sigc::scoped_connection idle_connection_;
241
247 std::vector<std::vector<float>> zero_inbufs_;
248 std::vector<std::vector<float>> zero_outbufs_;
249 std::vector<const float *> inbufs_;
250 std::vector<float *> outbufs_;
251
252 unsigned int max_variant_audio_ins_ = 0;
253 unsigned int max_variant_audio_outs_ = 0;
254 unsigned int max_variant_cv_ins_ = 0;
255 unsigned int max_variant_cv_outs_ = 0;
256 unsigned int max_variant_midi_ins_ = 0;
257 unsigned int max_variant_midi_outs_ = 0;
258};
259
260} // namespace zrythm::plugins
MIDI port specifics.
Definition midi_port.h:22
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
Definition parameter.h:167
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
DSP processing plugin.
Definition plugin.h:46
Plugin(ProcessorBaseDependencies dependencies, QObject *parent)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
std::string save_state() const
Serializes the plugin's internal state to a base64-encoded string.
dsp::MidiPort * get_midi_out_port()
Returns the MIDI out port.
unsigned int cv_input_port_id_
Port ID of first cv input (for connecting inside patchbay).
units::sample_u32_t get_single_playback_latency() const override
Returns the latency in samples.
bool add_internal_plugin_from_descr(const PluginDescriptor &descr)
Adds the internal plugin from the given descriptor.
unsigned int midi_output_port_id_
Port ID of first midi output (for connecting inside patchbay).
unsigned int audio_output_port_id_
Port ID of first audio output (for connecting inside patchbay).
void set_param_value(uint32_t id, float val)
Called from port_set_control_value() to send the value to carla.
std::vector< std::vector< float > > zero_inbufs_
Idle callback for the plugin UI.
unsigned int midi_input_port_id_
Port ID of first midi input (for connecting inside patchbay).
dsp::ProcessorParameter * get_param_from_param_id(uint32_t id)
Returns the plugin Port corresponding to the given parameter.
unsigned int carla_plugin_id_
Plugin ID inside carla engine.
void open_custom_ui(bool show) override
Shows or hides the UI.
std::vector< CarlaPatchbayPortInfo > patchbay_port_info_
Used when connecting Carla's internal plugin to patchbay ports.
unsigned int cv_output_port_id_
Port ID of first cv output (for connecting inside patchbay).
CarlaNativePlugin(ProcessorBaseDependencies dependencies)
Creates/initializes a plugin using the given setting.
CarlaPluginType
The type of the Carla plugin.
void load_state(std::optional< std::filesystem::path > abs_path)
Loads the state from the given file or from its state file.
unsigned int audio_input_port_id_
Port ID of first audio input (for connecting inside patchbay).
~CarlaNativePlugin() override
Deactivates, cleanups and frees the instance.
bool ports_created_
Whether ports are already created or not.