2 Copyright (C) 2008-2011 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"
37 class LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
40 LV2Plugin (ARDOUR::AudioEngine& engine,
41 ARDOUR::Session& session,
43 framecnt_t sample_rate);
44 LV2Plugin (const LV2Plugin &);
47 std::string unique_id () const;
48 const char* uri () const;
49 const char* label () const;
50 const char* name () const;
51 const char* maker () const;
53 uint32_t num_ports () const;
54 uint32_t parameter_count () const;
55 float default_value (uint32_t port);
56 framecnt_t signal_latency () const;
57 void set_parameter (uint32_t port, float val);
58 float get_parameter (uint32_t port) const;
59 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
60 uint32_t nth_parameter (uint32_t port, bool& ok) const;
62 const void* extension_data (const char* uri) const;
68 bool is_external_ui () const;
69 bool ui_is_resizable () const;
71 const char* port_symbol (uint32_t port) const;
73 const LV2_Feature* const* features () { return _features; }
75 std::set<Evoral::Parameter> automatable () const;
81 int set_block_size (pframes_t /*nframes*/) { return 0; }
83 int connect_and_run (BufferSet& bufs,
84 ChanMapping in, ChanMapping out,
85 pframes_t nframes, framecnt_t offset);
87 std::string describe_parameter (Evoral::Parameter);
88 std::string state_node_name () const { return "lv2"; }
90 void print_parameter (uint32_t param,
94 bool parameter_is_audio (uint32_t) const;
95 bool parameter_is_control (uint32_t) const;
96 bool parameter_is_event (uint32_t) const;
97 bool parameter_is_input (uint32_t) const;
98 bool parameter_is_output (uint32_t) const;
99 bool parameter_is_toggled (uint32_t) const;
101 boost::shared_ptr<Plugin::ScalePoints>
102 get_scale_points(uint32_t port_index) const;
104 /// Return the URID of midi:MidiEvent
105 static uint32_t midi_event_type (bool event_api) {
106 return event_api ? _midi_event_type_ev : _midi_event_type;
109 void set_insert_info(const PluginInsert* insert);
111 int set_state (const XMLNode& node, int version);
112 bool save_preset (std::string uri);
113 void remove_preset (std::string uri);
114 bool load_preset (PresetRecord);
115 std::string current_preset () const;
117 bool has_editor () const;
118 bool has_message_output () const;
120 uint32_t atom_eventTransfer() const;
122 void write_from_ui(uint32_t index, uint32_t protocol, uint32_t size, uint8_t* body);
124 typedef void UIMessageSink(void* controller,
130 void enable_ui_emmission();
131 void emit_to_ui(void* controller, UIMessageSink sink);
133 Worker* worker() { return _worker; }
135 void work(uint32_t size, const void* data);
136 void work_response(uint32_t size, const void* data);
138 static URIMap _uri_map;
140 static uint32_t _midi_event_type_ev;
141 static uint32_t _midi_event_type;
142 static uint32_t _chunk_type;
143 static uint32_t _sequence_type;
144 static uint32_t _event_transfer_type;
145 static uint32_t _path_type;
151 LV2_Feature** _features;
153 framecnt_t _sample_rate;
154 float* _control_data;
157 LV2_Evbuf** _ev_buffers;
158 float* _latency_control_port;
163 PORT_OUTPUT = 1 << 1,
165 PORT_CONTROL = 1 << 3,
167 PORT_MESSAGE = 1 << 5
170 typedef unsigned PortFlags;
172 std::vector<PortFlags> _port_flags;
173 std::map<std::string,uint32_t> _port_indices;
175 /// Message send to/from UI via ports
182 void write_to_ui(uint32_t index,
187 void write_to(RingBuffer<uint8_t>* dest,
193 // Created on demand so the space is only consumed if necessary
194 RingBuffer<uint8_t>* _to_ui;
195 RingBuffer<uint8_t>* _from_ui;
198 const void* (*extension_data) (const char* uri);
201 LV2_DataAccess _data_access_extension_data;
202 LV2_Feature _data_access_feature;
203 LV2_Feature _instance_access_feature;
204 LV2_Feature _make_path_feature;
205 LV2_Feature _work_schedule_feature;
207 mutable unsigned _state_version;
210 bool _has_state_interface;
212 const std::string plugin_dir () const;
213 const std::string scratch_dir () const;
214 const std::string file_dir () const;
215 const std::string state_dir (unsigned num) const;
217 static char* lv2_state_make_path (void* host_data,
220 void init (void* c_plugin, framecnt_t rate);
221 void run (pframes_t nsamples);
223 void latency_compute_run ();
224 std::string do_save_preset (std::string);
225 void do_remove_preset (std::string);
226 void find_presets ();
227 void add_state (XMLNode *) const;
231 class LV2PluginInfo : public PluginInfo {
233 LV2PluginInfo (void* c_plugin);
236 static PluginInfoList* discover ();
238 PluginPtr load (Session& session);
243 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
245 } // namespace ARDOUR
247 #endif /* __ardour_lv2_plugin_h__ */