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__
27 #include "ardour/plugin.h"
28 #include "ardour/uri_map.h"
29 #include "ardour/worker.h"
30 #include "pbd/ringbuffer.h"
34 // a callback function for lilv_state_new_from_instance(). friend of LV2Plugin
35 // so we can pass an LV2Plugin* in user_data and access its private members.
36 const void* lv2plugin_get_port_value(const char* port_symbol,
44 class LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
47 LV2Plugin (ARDOUR::AudioEngine& engine,
48 ARDOUR::Session& session,
50 framecnt_t sample_rate);
51 LV2Plugin (const LV2Plugin &);
54 std::string unique_id () const;
55 const char* uri () const;
56 const char* label () const;
57 const char* name () const;
58 const char* maker () const;
60 uint32_t num_ports () const;
61 uint32_t parameter_count () const;
62 float default_value (uint32_t port);
63 framecnt_t signal_latency () const;
64 void set_parameter (uint32_t port, float val);
65 float get_parameter (uint32_t port) const;
66 std::string get_docs() const;
67 std::string get_parameter_docs(uint32_t which) const;
68 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
69 uint32_t nth_parameter (uint32_t port, bool& ok) const;
71 const void* extension_data (const char* uri) const;
73 const void* c_plugin();
75 const void* c_ui_type();
77 bool is_external_ui () const;
78 bool ui_is_resizable () const;
80 const char* port_symbol (uint32_t port) const;
81 uint32_t port_index (const char* symbol) const;
83 const LV2_Feature* const* features () { return _features; }
85 std::set<Evoral::Parameter> automatable () const;
91 int set_block_size (pframes_t /*nframes*/) { return 0; }
93 int connect_and_run (BufferSet& bufs,
94 ChanMapping in, ChanMapping out,
95 pframes_t nframes, framecnt_t offset);
97 std::string describe_parameter (Evoral::Parameter);
98 std::string state_node_name () const { return "lv2"; }
100 void print_parameter (uint32_t param,
104 bool parameter_is_audio (uint32_t) const;
105 bool parameter_is_control (uint32_t) const;
106 bool parameter_is_event (uint32_t) const;
107 bool parameter_is_input (uint32_t) const;
108 bool parameter_is_output (uint32_t) const;
109 bool parameter_is_toggled (uint32_t) const;
111 boost::shared_ptr<Plugin::ScalePoints>
112 get_scale_points(uint32_t port_index) const;
114 void set_insert_info(const PluginInsert* insert);
116 int set_state (const XMLNode& node, int version);
117 bool save_preset (std::string uri);
118 void remove_preset (std::string uri);
119 bool load_preset (PresetRecord);
120 std::string current_preset () const;
122 bool has_editor () const;
123 bool has_message_output () const;
125 bool write_from_ui(uint32_t index,
128 const uint8_t* body);
130 typedef void UIMessageSink(void* controller,
136 void enable_ui_emmission();
137 void emit_to_ui(void* controller, UIMessageSink sink);
139 Worker* worker() { return _worker; }
141 int work(uint32_t size, const void* data);
142 int work_response(uint32_t size, const void* data);
144 static URIMap _uri_map;
149 uint32_t atom_Sequence;
150 uint32_t atom_eventTransfer;
153 uint32_t log_Warning;
154 uint32_t midi_MidiEvent;
155 uint32_t time_Position;
157 uint32_t time_barBeat;
158 uint32_t time_beatUnit;
159 uint32_t time_beatsPerBar;
160 uint32_t time_beatsPerMinute;
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
186 friend const void* lv2plugin_get_port_value(const char* port_symbol,
192 PORT_INPUT = 1, ///< Input port
193 PORT_OUTPUT = 1 << 1, ///< Output port
194 PORT_AUDIO = 1 << 2, ///< Audio (buffer of float)
195 PORT_CONTROL = 1 << 3, ///< Control (single float)
196 PORT_EVENT = 1 << 4, ///< Old event API event port
197 PORT_SEQUENCE = 1 << 5, ///< New atom API event port
198 PORT_MIDI = 1 << 6, ///< Event port understands MIDI
199 PORT_POSITION = 1 << 7 ///< Event port understands position
202 typedef unsigned PortFlags;
204 std::vector<PortFlags> _port_flags;
205 std::vector<size_t> _port_minimumSize;
206 std::map<std::string,uint32_t> _port_indices;
208 /// Message send to/from UI via ports
215 bool write_to_ui(uint32_t index,
218 const uint8_t* body);
220 bool write_to(RingBuffer<uint8_t>* dest,
224 const uint8_t* body);
226 // Created on demand so the space is only consumed if necessary
227 RingBuffer<uint8_t>* _to_ui;
228 RingBuffer<uint8_t>* _from_ui;
231 const void* (*extension_data) (const char* uri);
234 LV2_DataAccess _data_access_extension_data;
235 LV2_Feature _data_access_feature;
236 LV2_Feature _instance_access_feature;
237 LV2_Feature _make_path_feature;
238 LV2_Feature _log_feature;
239 LV2_Feature _work_schedule_feature;
240 LV2_Feature _options_feature;
241 LV2_Feature _def_state_feature;
243 // Options passed to plugin
244 int32_t _block_length;
247 mutable unsigned _state_version;
250 bool _has_state_interface;
252 const std::string plugin_dir () const;
253 const std::string scratch_dir () const;
254 const std::string file_dir () const;
255 const std::string state_dir (unsigned num) const;
257 static char* lv2_state_make_path (void* host_data,
260 void init (const void* c_plugin, framecnt_t rate);
261 void allocate_atom_event_buffers ();
262 void run (pframes_t nsamples);
264 void latency_compute_run ();
265 std::string do_save_preset (std::string);
266 void do_remove_preset (std::string);
267 void find_presets ();
268 void add_state (XMLNode *) const;
272 class LV2PluginInfo : public PluginInfo {
274 LV2PluginInfo (const void* c_plugin);
277 static PluginInfoList* discover ();
279 PluginPtr load (Session& session);
281 const void* _c_plugin;
284 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
286 } // namespace ARDOUR
288 #endif /* __ardour_lv2_plugin_h__ */