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"
37 typedef struct LV2_Evbuf_Impl LV2_Evbuf;
41 // a callback function for lilv_state_new_from_instance(). friend of LV2Plugin
42 // so we can pass an LV2Plugin* in user_data and access its private members.
43 const void* lv2plugin_get_port_value(const char* port_symbol,
51 class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
54 LV2Plugin (ARDOUR::AudioEngine& engine,
55 ARDOUR::Session& session,
57 framecnt_t sample_rate);
58 LV2Plugin (const LV2Plugin &);
61 std::string unique_id () const;
62 const char* uri () const;
63 const char* label () const;
64 const char* name () const;
65 const char* maker () const;
67 uint32_t num_ports () const;
68 uint32_t parameter_count () const;
69 float default_value (uint32_t port);
70 framecnt_t signal_latency () const;
71 void set_parameter (uint32_t port, float val);
72 float get_parameter (uint32_t port) const;
73 std::string get_docs() const;
74 std::string get_parameter_docs(uint32_t which) const;
75 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
76 uint32_t nth_parameter (uint32_t port, bool& ok) const;
78 const void* extension_data (const char* uri) const;
80 const void* c_plugin();
82 const void* c_ui_type();
84 bool is_external_ui () const;
85 bool is_external_kx () const;
86 bool ui_is_resizable () const;
88 const char* port_symbol (uint32_t port) const;
89 uint32_t port_index (const char* symbol) const;
91 const LV2_Feature* const* features () { return _features; }
93 std::set<Evoral::Parameter> automatable () const;
99 int set_block_size (pframes_t /*nframes*/) { return 0; }
101 int connect_and_run (BufferSet& bufs,
102 ChanMapping in, ChanMapping out,
103 pframes_t nframes, framecnt_t offset);
105 std::string describe_parameter (Evoral::Parameter);
106 std::string state_node_name () const { return "lv2"; }
108 void print_parameter (uint32_t param,
112 bool parameter_is_audio (uint32_t) const;
113 bool parameter_is_control (uint32_t) const;
114 bool parameter_is_event (uint32_t) const;
115 bool parameter_is_input (uint32_t) const;
116 bool parameter_is_output (uint32_t) const;
117 bool parameter_is_toggled (uint32_t) const;
119 boost::shared_ptr<Plugin::ScalePoints>
120 get_scale_points(uint32_t port_index) const;
122 void set_insert_info(const PluginInsert* insert);
124 int set_state (const XMLNode& node, int version);
125 bool save_preset (std::string uri);
126 void remove_preset (std::string uri);
127 bool load_preset (PresetRecord);
128 std::string current_preset () const;
130 bool has_editor () const;
131 bool has_message_output () const;
133 bool write_from_ui(uint32_t index,
136 const uint8_t* body);
138 typedef void UIMessageSink(void* controller,
144 void enable_ui_emission();
145 void emit_to_ui(void* controller, UIMessageSink sink);
147 Worker* worker() { return _worker; }
149 int work(uint32_t size, const void* data);
150 int work_response(uint32_t size, const void* data);
152 void set_property(uint32_t key, const Variant& value);
153 void get_supported_properties(std::vector<ParameterDescriptor>& descs);
154 void announce_property_values();
156 static URIMap _uri_map;
161 uint32_t atom_Sequence;
162 uint32_t atom_eventTransfer;
165 uint32_t atom_Object;
168 uint32_t log_Warning;
169 uint32_t midi_MidiEvent;
170 uint32_t time_Position;
172 uint32_t time_barBeat;
173 uint32_t time_beatUnit;
174 uint32_t time_beatsPerBar;
175 uint32_t time_beatsPerMinute;
180 uint32_t patch_property;
181 uint32_t patch_value;
190 LV2_Feature** _features;
192 framecnt_t _sample_rate;
193 float* _control_data;
196 LV2_Evbuf** _ev_buffers;
197 LV2_Evbuf** _atom_ev_buffers;
198 float* _bpm_control_port; ///< Special input set by ardour
199 float* _freewheel_control_port; ///< Special input set by ardour
200 float* _latency_control_port; ///< Special output set by ardour
201 framepos_t _next_cycle_start; ///< Expected start frame of next run cycle
202 double _next_cycle_speed; ///< Expected start frame of next run cycle
204 uint32_t _patch_port_in_index;
205 uint32_t _patch_port_out_index;
207 friend const void* lv2plugin_get_port_value(const char* port_symbol,
213 PORT_INPUT = 1, ///< Input port
214 PORT_OUTPUT = 1 << 1, ///< Output port
215 PORT_AUDIO = 1 << 2, ///< Audio (buffer of float)
216 PORT_CONTROL = 1 << 3, ///< Control (single float)
217 PORT_EVENT = 1 << 4, ///< Old event API event port
218 PORT_SEQUENCE = 1 << 5, ///< New atom API event port
219 PORT_MIDI = 1 << 6, ///< Event port understands MIDI
220 PORT_POSITION = 1 << 7, ///< Event port understands position
221 PORT_PATCHMSG = 1 << 8 ///< Event port supports patch:Message
224 typedef unsigned PortFlags;
226 std::vector<PortFlags> _port_flags;
227 std::vector<size_t> _port_minimumSize;
228 std::map<std::string,uint32_t> _port_indices;
230 /// Message send to/from UI via ports
237 bool write_to_ui(uint32_t index,
240 const uint8_t* body);
242 bool write_to(RingBuffer<uint8_t>* dest,
246 const uint8_t* body);
248 // Created on demand so the space is only consumed if necessary
249 RingBuffer<uint8_t>* _to_ui;
250 RingBuffer<uint8_t>* _from_ui;
253 const void* (*extension_data) (const char* uri);
256 LV2_DataAccess _data_access_extension_data;
257 LV2_Feature _data_access_feature;
258 LV2_Feature _instance_access_feature;
259 LV2_Feature _make_path_feature;
260 LV2_Feature _log_feature;
261 LV2_Feature _work_schedule_feature;
262 LV2_Feature _options_feature;
263 LV2_Feature _def_state_feature;
265 // Options passed to plugin
266 int32_t _block_length;
269 mutable unsigned _state_version;
272 bool _has_state_interface;
274 const std::string plugin_dir () const;
275 const std::string scratch_dir () const;
276 const std::string file_dir () const;
277 const std::string state_dir (unsigned num) const;
279 static char* lv2_state_make_path (void* host_data,
282 void init (const void* c_plugin, framecnt_t rate);
283 void allocate_atom_event_buffers ();
284 void run (pframes_t nsamples);
286 void latency_compute_run ();
287 std::string do_save_preset (std::string);
288 void do_remove_preset (std::string);
289 void find_presets ();
290 void add_state (XMLNode *) const;
294 class LIBARDOUR_API LV2PluginInfo : public PluginInfo , public boost::enable_shared_from_this<ARDOUR::LV2PluginInfo> {
296 LV2PluginInfo (const char* plugin_uri);
299 static PluginInfoList* discover ();
301 PluginPtr load (Session& session);
306 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
308 } // namespace ARDOUR
310 #endif /* __ardour_lv2_plugin_h__ */