2 Copyright (C) 2008-2012 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_lv2_plugin_h__
21 #define __ardour_lv2_plugin_h__
26 #include <boost/enable_shared_from_this.hpp>
28 #include "ardour/plugin.h"
29 #include "ardour/uri_map.h"
30 #include "ardour/worker.h"
31 #include "pbd/ringbuffer.h"
33 #ifdef LV2_EXTENDED // -> needs to eventually go upstream to lv2plug.in
34 #include "ardour/lv2_extensions.h"
41 typedef struct LV2_Evbuf_Impl LV2_Evbuf;
45 // a callback function for lilv_state_new_from_instance(). friend of LV2Plugin
46 // so we can pass an LV2Plugin* in user_data and access its private members.
47 const void* lv2plugin_get_port_value(const char* port_symbol,
55 class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
58 LV2Plugin (ARDOUR::AudioEngine& engine,
59 ARDOUR::Session& session,
61 framecnt_t sample_rate);
62 LV2Plugin (const LV2Plugin &);
65 std::string unique_id () const;
66 const char* uri () const;
67 const char* label () const;
68 const char* name () const;
69 const char* maker () const;
71 uint32_t num_ports () const;
72 uint32_t parameter_count () const;
73 float default_value (uint32_t port);
74 framecnt_t signal_latency () const;
75 void set_parameter (uint32_t port, float val);
76 float get_parameter (uint32_t port) const;
77 std::string get_docs() const;
78 std::string get_parameter_docs(uint32_t which) const;
79 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
80 uint32_t nth_parameter (uint32_t port, bool& ok) const;
82 const void* extension_data (const char* uri) const;
84 const void* c_plugin();
86 const void* c_ui_type();
88 bool is_external_ui () const;
89 bool is_external_kx () const;
90 bool ui_is_resizable () const;
92 const char* port_symbol (uint32_t port) const;
93 uint32_t port_index (const char* symbol) const;
95 const LV2_Feature* const* features () { return _features; }
97 std::set<Evoral::Parameter> automatable () const;
98 virtual void set_automation_control (uint32_t, boost::shared_ptr<AutomationControl>);
104 int set_block_size (pframes_t);
105 bool requires_fixed_sized_buffers () const;
107 int connect_and_run (BufferSet& bufs,
108 ChanMapping in, ChanMapping out,
109 pframes_t nframes, framecnt_t offset);
111 std::string describe_parameter (Evoral::Parameter);
112 std::string state_node_name () const { return "lv2"; }
114 void print_parameter (uint32_t param,
118 bool parameter_is_audio (uint32_t) const;
119 bool parameter_is_control (uint32_t) const;
120 bool parameter_is_event (uint32_t) const;
121 bool parameter_is_input (uint32_t) const;
122 bool parameter_is_output (uint32_t) const;
123 bool parameter_is_toggled (uint32_t) const;
125 boost::shared_ptr<ScalePoints>
126 get_scale_points(uint32_t port_index) const;
128 void set_insert_id(PBD::ID id);
129 void set_state_dir (const std::string& d = "");
131 int set_state (const XMLNode& node, int version);
132 bool save_preset (std::string uri);
133 void remove_preset (std::string uri);
134 bool load_preset (PresetRecord);
135 std::string current_preset () const;
137 bool has_editor () const;
138 bool has_message_output () const;
140 bool write_from_ui(uint32_t index,
143 const uint8_t* body);
145 typedef void UIMessageSink(void* controller,
151 void enable_ui_emission();
152 void emit_to_ui(void* controller, UIMessageSink sink);
154 Worker* worker() { return _worker; }
156 URIMap& uri_map() { return _uri_map; }
157 const URIMap& uri_map() const { return _uri_map; }
159 int work(uint32_t size, const void* data);
160 int work_response(uint32_t size, const void* data);
162 void set_property(uint32_t key, const Variant& value);
163 const PropertyDescriptors& get_supported_properties() const { return _property_descriptors; }
164 const ParameterDescriptor& get_property_descriptor(uint32_t id) const;
165 void announce_property_values();
171 LV2_Feature** _features;
173 framecnt_t _sample_rate;
174 float* _control_data;
177 LV2_Evbuf** _ev_buffers;
178 LV2_Evbuf** _atom_ev_buffers;
179 float* _bpm_control_port; ///< Special input set by ardour
180 float* _freewheel_control_port; ///< Special input set by ardour
181 float* _latency_control_port; ///< Special output set by ardour
182 framepos_t _next_cycle_start; ///< Expected start frame of next run cycle
183 double _next_cycle_speed; ///< Expected start frame of next run cycle
185 std::string _plugin_state_dir;
186 uint32_t _patch_port_in_index;
187 uint32_t _patch_port_out_index;
189 bool _no_sample_accurate_ctrl;
190 bool _can_write_automation;
192 friend const void* lv2plugin_get_port_value(const char* port_symbol,
198 PORT_INPUT = 1, ///< Input port
199 PORT_OUTPUT = 1 << 1, ///< Output port
200 PORT_AUDIO = 1 << 2, ///< Audio (buffer of float)
201 PORT_CONTROL = 1 << 3, ///< Control (single float)
202 PORT_EVENT = 1 << 4, ///< Old event API event port
203 PORT_SEQUENCE = 1 << 5, ///< New atom API event port
204 PORT_MIDI = 1 << 6, ///< Event port understands MIDI
205 PORT_POSITION = 1 << 7, ///< Event port understands position
206 PORT_PATCHMSG = 1 << 8, ///< Event port supports patch:Message
207 PORT_AUTOCTRL = 1 << 9, ///< Event port supports auto:AutomationControl
208 PORT_CTRLED = 1 << 10 ///< Port prop auto:AutomationControlled (can be self controlled)
211 typedef unsigned PortFlags;
213 std::vector<PortFlags> _port_flags;
214 std::vector<size_t> _port_minimumSize;
215 std::map<std::string,uint32_t> _port_indices;
217 PropertyDescriptors _property_descriptors;
219 struct AutomationCtrl {
220 AutomationCtrl (const AutomationCtrl &other)
222 , guard (other.guard)
225 AutomationCtrl (boost::shared_ptr<ARDOUR::AutomationControl> c)
229 boost::shared_ptr<ARDOUR::AutomationControl> ac;
233 typedef boost::shared_ptr<AutomationCtrl> AutomationCtrlPtr;
234 typedef std::map<uint32_t, AutomationCtrlPtr> AutomationCtrlMap;
235 AutomationCtrlMap _ctrl_map;
236 AutomationCtrlPtr get_automation_control (uint32_t);
238 /// Message send to/from UI via ports
245 bool write_to_ui(uint32_t index,
248 const uint8_t* body);
250 bool write_to(RingBuffer<uint8_t>* dest,
254 const uint8_t* body);
256 // Created on demand so the space is only consumed if necessary
257 RingBuffer<uint8_t>* _to_ui;
258 RingBuffer<uint8_t>* _from_ui;
261 const void* (*extension_data) (const char* uri);
264 LV2_DataAccess _data_access_extension_data;
265 LV2_Feature _data_access_feature;
266 LV2_Feature _instance_access_feature;
267 LV2_Feature _make_path_feature;
268 LV2_Feature _log_feature;
269 LV2_Feature _work_schedule_feature;
270 LV2_Feature _options_feature;
271 LV2_Feature _def_state_feature;
273 // Options passed to plugin
276 mutable unsigned _state_version;
279 bool _has_state_interface;
281 const std::string plugin_dir () const;
282 const std::string scratch_dir () const;
283 const std::string file_dir () const;
284 const std::string state_dir (unsigned num) const;
286 static char* lv2_state_make_path (void* host_data,
289 void init (const void* c_plugin, framecnt_t rate);
290 void allocate_atom_event_buffers ();
291 void run (pframes_t nsamples);
293 void load_supported_properties(PropertyDescriptors& descs);
295 void latency_compute_run ();
296 std::string do_save_preset (std::string);
297 void do_remove_preset (std::string);
298 void find_presets ();
299 void add_state (XMLNode *) const;
303 class LIBARDOUR_API LV2PluginInfo : public PluginInfo , public boost::enable_shared_from_this<ARDOUR::LV2PluginInfo> {
305 LV2PluginInfo (const char* plugin_uri);
308 static PluginInfoList* discover ();
310 PluginPtr load (Session& session);
311 std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
312 virtual bool in_category (const std::string &c) const;
313 virtual bool is_instrument() const;
318 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
320 } // namespace ARDOUR
322 #endif /* __ardour_lv2_plugin_h__ */