Support compilation with (old) SLV2, or (new) Lilv and (optionally) Suil.
[ardour.git] / libs / ardour / ardour / lv2_plugin.h
1
2 /*
3     Copyright (C) 2008-2011 Paul Davis
4     Author: David Robillard
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22 #ifndef __ardour_lv2_plugin_h__
23 #define __ardour_lv2_plugin_h__
24
25 #include <set>
26 #include <string>
27 #include <vector>
28
29 #include <dlfcn.h>
30
31 #include "pbd/stateful.h"
32
33 #include <jack/types.h>
34
35 #include "ardour/plugin.h"
36 #include "ardour/uri_map.h"
37
38 namespace ARDOUR {
39
40 class AudioEngine;
41 class Session;
42
43 class LV2Plugin : public ARDOUR::Plugin
44 {
45   public:
46         LV2Plugin (ARDOUR::AudioEngine& engine,
47                    ARDOUR::Session&     session,
48                    void*                c_plugin,
49                    framecnt_t           sample_rate);
50         LV2Plugin (const LV2Plugin &);
51         ~LV2Plugin ();
52
53         std::string unique_id () const;
54         const char* uri () const;
55         const char* label () const;
56         const char* name () const;
57         const char* maker () const;
58
59         uint32_t   num_ports () const;
60         uint32_t   parameter_count () const;
61         float      default_value (uint32_t port);
62         framecnt_t signal_latency () const;
63         void       set_parameter (uint32_t port, float val);
64         float      get_parameter (uint32_t port) const;
65         int        get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
66         uint32_t   nth_parameter (uint32_t port, bool& ok) const;
67
68         const void* extension_data (const char* uri) const;
69
70         void* c_plugin();
71         void* c_ui();
72         void* c_ui_type();
73
74         bool is_external_ui () const;
75
76         const char* port_symbol (uint32_t port) const;
77
78         const LV2_Feature* const* features () { return _features; }
79
80         std::set<Evoral::Parameter> automatable () const;
81
82         void activate ();
83         void deactivate ();
84         void cleanup ();
85
86         int set_block_size (pframes_t /*nframes*/) { return 0; }
87
88         int connect_and_run (BufferSet& bufs,
89                              ChanMapping in, ChanMapping out,
90                              pframes_t nframes, framecnt_t offset);
91
92         std::string describe_parameter (Evoral::Parameter);
93         std::string state_node_name () const { return "lv2"; }
94
95         void print_parameter (uint32_t param,
96                               char*    buf,
97                               uint32_t len) const;
98
99         bool parameter_is_audio (uint32_t) const;
100         bool parameter_is_control (uint32_t) const;
101         bool parameter_is_midi (uint32_t) const;
102         bool parameter_is_input (uint32_t) const;
103         bool parameter_is_output (uint32_t) const;
104         bool parameter_is_toggled (uint32_t) const;
105
106         boost::shared_ptr<Plugin::ScalePoints>
107         get_scale_points(uint32_t port_index) const;
108                 
109         static uint32_t midi_event_type () { return _midi_event_type; }
110
111         void set_insert_info(const PluginInsert* insert);
112
113         int      set_state (const XMLNode& node, int version);
114         bool     save_preset (std::string uri);
115         void     remove_preset (std::string uri);
116         bool     load_preset (PresetRecord);
117         std::string current_preset () const;
118
119         bool has_editor () const;
120
121   private:
122         struct Impl;
123         Impl*             _impl;
124         void*             _module;
125         LV2_Feature**     _features;
126         framecnt_t        _sample_rate;
127         float*            _control_data;
128         float*            _shadow_data;
129         float*            _defaults;
130         float*            _latency_control_port;
131         bool              _was_activated;
132         bool              _supports_persist;
133         std::vector<bool> _port_is_input;
134
135         std::map<std::string,uint32_t> _port_indices;
136
137         PBD::ID _insert_id;
138
139         typedef struct {
140                 const void* (*extension_data) (const char* uri);
141         } LV2_DataAccess;
142
143         LV2_DataAccess _data_access_extension_data;
144         LV2_Feature    _data_access_feature;
145         LV2_Feature    _instance_access_feature;
146         LV2_Feature    _path_support_feature;
147         LV2_Feature    _new_file_support_feature;
148         LV2_Feature    _persist_feature;
149
150         static URIMap   _uri_map;
151         static uint32_t _midi_event_type;
152
153         static int lv2_persist_store_callback (void*       host_data,
154                                                uint32_t    key,
155                                                const void* value,
156                                                size_t      size,
157                                                uint32_t    type,
158                                                uint32_t    flags);
159         static const void* lv2_persist_retrieve_callback (void*     host_data,
160                                                           uint32_t  key,
161                                                           size_t*   size,
162                                                           uint32_t* type,
163                                                           uint32_t* flags);
164         static char* lv2_files_abstract_path (void*       host_data,
165                                               const char* absolute_path);
166         static char* lv2_files_absolute_path (void*       host_data,
167                                               const char* abstract_path);
168         static char* lv2_files_new_file_path (void*       host_data,
169                                               const char* relative_path);
170
171         void init (void* c_plugin, framecnt_t rate);
172         void run (pframes_t nsamples);
173
174         void latency_compute_run ();
175         std::string do_save_preset (std::string);
176         void do_remove_preset (std::string);
177         void find_presets ();
178         void add_state (XMLNode *) const;
179 };
180
181
182 class LV2PluginInfo : public PluginInfo {
183 public:
184         LV2PluginInfo (void* c_plugin);
185         ~LV2PluginInfo ();
186
187         static PluginInfoList* discover ();
188
189         PluginPtr load (Session& session);
190
191         void* _c_plugin;
192 };
193
194 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
195
196 } // namespace ARDOUR
197
198 #endif /* __ardour_lv2_plugin_h__ */