Completely localist use of SLV2 to lv2_plugin.cc and lv2_plugin_ui.cc.
[ardour.git] / libs / ardour / ardour / lv2_plugin.h
1 /*
2     Copyright (C) 2008-2011 Paul Davis
3     Author: David Robillard
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __ardour_lv2_plugin_h__
22 #define __ardour_lv2_plugin_h__
23
24 #include <set>
25 #include <string>
26 #include <vector>
27
28 #include <dlfcn.h>
29
30 #include "pbd/stateful.h"
31
32 #include <jack/types.h>
33
34 #include "ardour/plugin.h"
35 #include "ardour/uri_map.h"
36
37 namespace ARDOUR {
38
39 class AudioEngine;
40 class Session;
41
42 class LV2Plugin : public ARDOUR::Plugin
43 {
44   public:
45         LV2Plugin (ARDOUR::AudioEngine& engine,
46                    ARDOUR::Session&     session,
47                    void*                c_plugin,
48                    framecnt_t           sample_rate);
49         LV2Plugin (const LV2Plugin &);
50         ~LV2Plugin ();
51
52         std::string unique_id () const;
53         const char* uri () const;
54         const char* label () const;
55         const char* name () const;
56         const char* maker () const;
57
58         uint32_t   num_ports () const;
59         uint32_t   parameter_count () const;
60         float      default_value (uint32_t port);
61         framecnt_t signal_latency () const;
62         void       set_parameter (uint32_t port, float val);
63         float      get_parameter (uint32_t port) const;
64         int        get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
65         uint32_t   nth_parameter (uint32_t port, bool& ok) const;
66
67         const void* extension_data (const char* uri);
68
69         void* c_plugin();
70         void* c_ui();
71
72         bool is_external_ui () const;
73
74         const char* port_symbol (uint32_t port) const;
75
76         const LV2_Feature* const* features () { return _features; }
77
78         std::set<Evoral::Parameter> automatable () const;
79
80         void activate ();
81         void deactivate ();
82         void cleanup ();
83
84         int set_block_size (pframes_t /*nframes*/) { return 0; }
85
86         int connect_and_run (BufferSet& bufs,
87                              ChanMapping in, ChanMapping out,
88                              pframes_t nframes, framecnt_t offset);
89
90         std::string describe_parameter (Evoral::Parameter);
91         std::string state_node_name () const { return "lv2"; }
92
93         void print_parameter (uint32_t param,
94                               char*    buf,
95                               uint32_t len) const;
96
97         bool parameter_is_audio (uint32_t) const;
98         bool parameter_is_control (uint32_t) const;
99         bool parameter_is_midi (uint32_t) const;
100         bool parameter_is_input (uint32_t) const;
101         bool parameter_is_output (uint32_t) const;
102         bool parameter_is_toggled (uint32_t) const;
103
104         boost::shared_ptr<Plugin::ScalePoints>
105         get_scale_points(uint32_t port_index) const;
106                 
107         static uint32_t midi_event_type () { return _midi_event_type; }
108
109         void set_insert_info(const PluginInsert* insert);
110
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;
116
117         bool has_editor () const;
118
119   private:
120         struct Impl;
121         Impl*             _impl;
122         void*             _module;
123         LV2_Feature**     _features;
124         framecnt_t        _sample_rate;
125         float*            _control_data;
126         float*            _shadow_data;
127         float*            _defaults;
128         float*            _latency_control_port;
129         bool              _was_activated;
130         bool              _supports_persist;
131         std::vector<bool> _port_is_input;
132
133         std::map<std::string,uint32_t> _port_indices;
134
135         PBD::ID _insert_id;
136
137         typedef struct {
138                 const void* (*extension_data) (const char* uri);
139         } LV2_DataAccess;
140
141         LV2_DataAccess _data_access_extension_data;
142         LV2_Feature    _data_access_feature;
143         LV2_Feature    _instance_access_feature;
144         LV2_Feature    _path_support_feature;
145         LV2_Feature    _new_file_support_feature;
146         LV2_Feature    _persist_feature;
147
148         static URIMap   _uri_map;
149         static uint32_t _midi_event_type;
150
151         static int lv2_persist_store_callback (void*       host_data,
152                                                uint32_t    key,
153                                                const void* value,
154                                                size_t      size,
155                                                uint32_t    type,
156                                                uint32_t    flags);
157         static const void* lv2_persist_retrieve_callback (void*     host_data,
158                                                           uint32_t  key,
159                                                           size_t*   size,
160                                                           uint32_t* type,
161                                                           uint32_t* flags);
162         static char* lv2_files_abstract_path (void*       host_data,
163                                               const char* absolute_path);
164         static char* lv2_files_absolute_path (void*       host_data,
165                                               const char* abstract_path);
166         static char* lv2_files_new_file_path (void*       host_data,
167                                               const char* relative_path);
168
169         void init (void* c_plugin, framecnt_t rate);
170         void run (pframes_t nsamples);
171
172         void latency_compute_run ();
173         std::string do_save_preset (std::string);
174         void do_remove_preset (std::string);
175         void find_presets ();
176         void add_state (XMLNode *) const;
177 };
178
179
180 class LV2PluginInfo : public PluginInfo {
181 public:
182         LV2PluginInfo (void* c_plugin);
183         ~LV2PluginInfo ();
184
185         static PluginInfoList* discover ();
186
187         PluginPtr load (Session& session);
188
189         void* _c_plugin;
190 };
191
192 typedef boost::shared_ptr<LV2PluginInfo> LV2PluginInfoPtr;
193
194 } // namespace ARDOUR
195
196 #endif /* __ardour_lv2_plugin_h__ */