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.
21 #ifndef __ardour_lv2_plugin_h__
22 #define __ardour_lv2_plugin_h__
30 #include "pbd/stateful.h"
32 #include <jack/types.h>
33 #include <slv2/slv2.h>
35 #include "ardour/plugin.h"
36 #include "ardour/uri_map.h"
44 class LV2Plugin : public ARDOUR::Plugin
47 LV2Plugin (ARDOUR::AudioEngine& engine,
48 ARDOUR::Session& session,
49 ARDOUR::LV2World& world,
51 framecnt_t sample_rate);
52 LV2Plugin (const LV2Plugin &);
55 std::string unique_id () const;
57 const char* label () const { return slv2_value_as_string(_name); }
58 const char* name () const { return slv2_value_as_string(_name); }
59 const char* maker () const {
60 return _author ? slv2_value_as_string (_author) : "Unknown";
63 uint32_t parameter_count () const { return slv2_plugin_get_num_ports(_plugin); }
64 float default_value (uint32_t port);
65 framecnt_t signal_latency () const;
66 void set_parameter (uint32_t port, float val);
67 float get_parameter (uint32_t port) 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) {
72 return _instance->lv2_descriptor->extension_data (uri);
75 SLV2Plugin slv2_plugin () { return _plugin; }
76 SLV2UI slv2_ui () { return _ui; }
77 SLV2Port slv2_port (uint32_t i) { return slv2_plugin_get_port_by_index (_plugin, i); }
78 bool is_external_ui () const;
80 const char* port_symbol (uint32_t port) const;
82 const LV2_Feature* const* features () { return _features; }
84 std::set<Evoral::Parameter> automatable () const;
90 int set_block_size (pframes_t /*nframes*/) { return 0; }
92 int connect_and_run (BufferSet& bufs,
93 ChanMapping in, ChanMapping out,
94 pframes_t nframes, framecnt_t offset);
96 std::string describe_parameter (Evoral::Parameter);
97 std::string state_node_name () const { return "lv2"; }
99 void print_parameter (uint32_t param,
103 bool parameter_is_audio (uint32_t) const;
104 bool parameter_is_control (uint32_t) const;
105 bool parameter_is_midi (uint32_t) const;
106 bool parameter_is_input (uint32_t) const;
107 bool parameter_is_output (uint32_t) const;
108 bool parameter_is_toggled (uint32_t) const;
110 static uint32_t midi_event_type () { return _midi_event_type; }
112 int set_state (const XMLNode& node, int version);
113 bool save_preset (std::string uri);
114 void remove_preset (std::string uri);
115 bool load_preset (PresetRecord);
116 std::string current_preset () const;
118 bool has_editor () const;
123 LV2_Feature** _features;
128 SLV2Instance _instance;
129 framecnt_t _sample_rate;
130 float* _control_data;
133 float* _latency_control_port;
135 bool _supports_persist;
136 std::vector<bool> _port_is_input;
138 std::map<std::string,uint32_t> _port_indices;
141 const void* (*extension_data) (const char* uri);
144 LV2_DataAccess _data_access_extension_data;
145 LV2_Feature _data_access_feature;
146 LV2_Feature _instance_access_feature;
147 LV2_Feature _persist_feature;
149 static URIMap _uri_map;
150 static uint32_t _midi_event_type;
152 static int lv2_persist_store_callback (void* callback_data,
159 static const void* lv2_persist_retrieve_callback (void* callback_data,
165 void init (LV2World& world, SLV2Plugin plugin, framecnt_t rate);
166 void run (pframes_t nsamples);
168 void latency_compute_run ();
169 std::string do_save_preset (std::string);
170 void do_remove_preset (std::string);
171 void find_presets ();
172 void add_state (XMLNode *) const;
176 /** The SLV2World, and various cached (as symbols, fast) URIs.
178 * This object represents everything ardour 'knows' about LV2
179 * (ie understood extensions/features/etc)
187 SLV2Value input_class; ///< Input port
188 SLV2Value output_class; ///< Output port
189 SLV2Value audio_class; ///< Audio port
190 SLV2Value control_class; ///< Control port
191 SLV2Value event_class; ///< Event port
192 SLV2Value midi_class; ///< MIDI event
193 SLV2Value in_place_broken;
198 SLV2Value external_gui;
199 SLV2Value logarithmic;
203 class LV2PluginInfo : public PluginInfo {
205 LV2PluginInfo (void* slv2_world, void* slv2_plugin);
207 static PluginInfoList* discover (void* slv2_world);
209 PluginPtr load (Session& session);
215 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
217 } // namespace ARDOUR
219 #endif /* __ardour_lv2_plugin_h__ */