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 "pbd/ringbuffer.h"
36 class LV2Plugin : public ARDOUR::Plugin
39 LV2Plugin (ARDOUR::AudioEngine& engine,
40 ARDOUR::Session& session,
42 framecnt_t sample_rate);
43 LV2Plugin (const LV2Plugin &);
46 std::string unique_id () const;
47 const char* uri () const;
48 const char* label () const;
49 const char* name () const;
50 const char* maker () const;
52 uint32_t num_ports () const;
53 uint32_t parameter_count () const;
54 float default_value (uint32_t port);
55 framecnt_t signal_latency () const;
56 void set_parameter (uint32_t port, float val);
57 float get_parameter (uint32_t port) const;
58 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
59 uint32_t nth_parameter (uint32_t port, bool& ok) const;
61 const void* extension_data (const char* uri) const;
67 bool is_external_ui () const;
69 const char* port_symbol (uint32_t port) const;
71 const LV2_Feature* const* features () { return _features; }
73 std::set<Evoral::Parameter> automatable () const;
79 int set_block_size (pframes_t /*nframes*/) { return 0; }
81 int connect_and_run (BufferSet& bufs,
82 ChanMapping in, ChanMapping out,
83 pframes_t nframes, framecnt_t offset);
85 std::string describe_parameter (Evoral::Parameter);
86 std::string state_node_name () const { return "lv2"; }
88 void print_parameter (uint32_t param,
92 bool parameter_is_audio (uint32_t) const;
93 bool parameter_is_control (uint32_t) const;
94 bool parameter_is_event (uint32_t) const;
95 bool parameter_is_input (uint32_t) const;
96 bool parameter_is_output (uint32_t) const;
97 bool parameter_is_toggled (uint32_t) const;
99 boost::shared_ptr<Plugin::ScalePoints>
100 get_scale_points(uint32_t port_index) const;
102 /// Return the URID of midi:MidiEvent
103 static uint32_t midi_event_type (bool event_api) {
104 return event_api ? _midi_event_type_ev : _midi_event_type;
107 void set_insert_info(const PluginInsert* insert);
109 int set_state (const XMLNode& node, int version);
110 bool save_preset (std::string uri);
111 void remove_preset (std::string uri);
112 bool load_preset (PresetRecord);
113 std::string current_preset () const;
115 bool has_editor () const;
116 bool has_message_output () const;
118 uint32_t atom_eventTransfer() const;
120 void write_from_ui(uint32_t index, uint32_t protocol, uint32_t size, uint8_t* body);
122 typedef void UIMessageSink(void* controller,
128 void enable_ui_emmission();
129 void emit_to_ui(void* controller, UIMessageSink sink);
131 static URIMap _uri_map;
137 LV2_Feature** _features;
138 framecnt_t _sample_rate;
139 float* _control_data;
142 LV2_Evbuf** _ev_buffers;
143 float* _latency_control_port;
148 PORT_OUTPUT = 1 << 1,
150 PORT_CONTROL = 1 << 3,
152 PORT_MESSAGE = 1 << 5
155 typedef unsigned PortFlags;
157 std::vector<PortFlags> _port_flags;
158 std::map<std::string,uint32_t> _port_indices;
160 /// Message send to/from UI via ports
167 void write_to_ui(uint32_t index,
172 void write_to(RingBuffer<uint8_t>* dest,
178 // Created on demand so the space is only consumed if necessary
179 RingBuffer<uint8_t>* _to_ui;
180 RingBuffer<uint8_t>* _from_ui;
183 const void* (*extension_data) (const char* uri);
186 LV2_DataAccess _data_access_extension_data;
187 LV2_Feature _data_access_feature;
188 LV2_Feature _instance_access_feature;
189 LV2_Feature _make_path_feature;
191 mutable unsigned _state_version;
194 bool _has_state_interface;
196 static uint32_t _midi_event_type_ev;
197 static uint32_t _midi_event_type;
198 static uint32_t _sequence_type;
199 static uint32_t _event_transfer_type;
200 static uint32_t _state_path_type;
202 const std::string plugin_dir () const;
203 const std::string scratch_dir () const;
204 const std::string file_dir () const;
205 const std::string state_dir (unsigned num) const;
207 static char* lv2_state_make_path (void* host_data,
210 void init (void* c_plugin, framecnt_t rate);
211 void run (pframes_t nsamples);
213 void latency_compute_run ();
214 std::string do_save_preset (std::string);
215 void do_remove_preset (std::string);
216 void find_presets ();
217 void add_state (XMLNode *) const;
221 class LV2PluginInfo : public PluginInfo {
223 LV2PluginInfo (void* c_plugin);
226 static PluginInfoList* discover ();
228 PluginPtr load (Session& session);
233 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
235 } // namespace ARDOUR
237 #endif /* __ardour_lv2_plugin_h__ */