Optimize automation-event process splitting
[ardour.git] / libs / ardour / ardour / plugin_manager.h
1 /*
2     Copyright (C) 2000-2007 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_plugin_manager_h__
21 #define __ardour_plugin_manager_h__
22
23 #ifdef WAF_BUILD
24 #include "libardour-config.h"
25 #endif
26
27 #include <list>
28 #include <map>
29 #include <string>
30 #include <set>
31 #include <boost/utility.hpp>
32
33 #include "ardour/libardour_visibility.h"
34 #include "ardour/types.h"
35 #include "ardour/plugin.h"
36
37 namespace ARDOUR {
38
39 class Plugin;
40
41 class LIBARDOUR_API PluginManager : public boost::noncopyable {
42 public:
43         static PluginManager& instance();
44         static std::string scanner_bin_path;
45
46         ~PluginManager ();
47
48         const ARDOUR::PluginInfoList& windows_vst_plugin_info ();
49         const ARDOUR::PluginInfoList& lxvst_plugin_info ();
50         const ARDOUR::PluginInfoList& mac_vst_plugin_info ();
51         const ARDOUR::PluginInfoList& ladspa_plugin_info ();
52         const ARDOUR::PluginInfoList& lv2_plugin_info ();
53         const ARDOUR::PluginInfoList& au_plugin_info ();
54         const ARDOUR::PluginInfoList& lua_plugin_info ();
55
56         void refresh (bool cache_only = false);
57         void cancel_plugin_scan();
58         void cancel_plugin_timeout();
59         void clear_vst_cache ();
60         void clear_vst_blacklist ();
61         void clear_au_cache ();
62         void clear_au_blacklist ();
63
64         const std::string get_default_windows_vst_path() const { return windows_vst_path; }
65         const std::string get_default_lxvst_path() const { return lxvst_path; }
66
67         /* always return LXVST for any VST subtype */
68         static PluginType to_generic_vst (PluginType);
69
70         bool cancelled () { return _cancel_scan; }
71         bool no_timeout () { return _cancel_timeout; }
72
73         enum PluginStatusType {
74                 Normal = 0,
75                 Favorite,
76                 Hidden
77         };
78
79         std::string user_plugin_metadata_dir () const;
80         void load_statuses ();
81         void save_statuses ();
82         void set_status (ARDOUR::PluginType type, std::string unique_id, PluginStatusType status);
83         PluginStatusType get_status (const PluginInfoPtr&) const;
84
85         void load_tags ();
86         void save_tags ();
87
88         bool load_plugin_order_file (XMLNode &n) const;  //returns TRUE if the passed-in node has valid info
89         void save_plugin_order_file (XMLNode &elem) const;
90
91         enum TagType {
92                 FromPlug,           //tag info is being set from plugin metadata
93                 FromFactoryFile,    // ... from the factory metadata file
94                 FromUserFile,       // ... from the user's config data
95                 FromGui             // ... from the UI, in realtime: will emit a signal so ui can show "sanitized" string as it is generated
96         };
97         void set_tags (ARDOUR::PluginType type, std::string unique_id, std::string tags, std::string name, TagType tagtype);
98         void reset_tags (PluginInfoPtr const&);
99         std::string get_tags_as_string (PluginInfoPtr const&) const;
100         std::vector<std::string> get_tags (PluginInfoPtr const&) const;
101
102         enum TagFilter {
103                 All,
104                 OnlyFavorites,
105                 NoHidden
106         };
107         std::vector<std::string> get_all_tags (enum TagFilter) const;
108
109         /** plugins were added to or removed from one of the PluginInfoLists, OR the user has made changes to the status/tags */
110         PBD::Signal0<void> PluginListChanged;
111
112         /** A single plugin's Hidden/Favorite status changed */
113         PBD::Signal3<void, ARDOUR::PluginType, std::string, PluginStatusType> PluginStatusChanged; //PluginType t, string id, string tag
114
115         /** A single plugin's Tags status changed */
116         PBD::Signal3<void, ARDOUR::PluginType, std::string, std::string> PluginTagChanged; //PluginType t, string id, string tag
117
118 private:
119
120         struct PluginTag {
121             ARDOUR::PluginType type;
122             std::string unique_id;
123             std::string tags;
124             std::string name;
125                 TagType tagtype;
126
127             PluginTag (ARDOUR::PluginType t, std::string id, std::string tag, std::string n, TagType tt)
128             : type (t), unique_id (id), tags (tag), name(n), tagtype (tt) {}
129
130             bool operator== (PluginTag const& other) const {
131                     return other.type == type && other.unique_id == unique_id;
132             }
133
134             bool operator< (PluginTag const& other) const {
135                     if (other.type < type) {
136                             return true;
137                     } else if (other.type == type && other.unique_id < unique_id) {
138                             return true;
139                     }
140                     return false;
141             }
142         };
143
144         typedef std::set<PluginTag> PluginTagList;
145         PluginTagList ptags;
146
147         std::string sanitize_tag (const std::string) const;
148
149         struct PluginStatus {
150             ARDOUR::PluginType type;
151             std::string unique_id;
152             PluginStatusType status;
153
154             PluginStatus (ARDOUR::PluginType t, std::string id, PluginStatusType s = Normal)
155             : type (t), unique_id (id), status (s) {}
156
157             bool operator==(const PluginStatus& other) const {
158                     return other.type == type && other.unique_id == unique_id;
159             }
160
161             bool operator<(const PluginStatus& other) const {
162                     if (other.type < type) {
163                             return true;
164                     } else if (other.type == type && other.unique_id < unique_id) {
165                             return true;
166                     }
167                     return false;
168             }
169         };
170         typedef std::set<PluginStatus> PluginStatusList;
171         PluginStatusList statuses;
172
173         ARDOUR::PluginInfoList  _empty_plugin_info;
174         ARDOUR::PluginInfoList* _windows_vst_plugin_info;
175         ARDOUR::PluginInfoList* _lxvst_plugin_info;
176         ARDOUR::PluginInfoList* _mac_vst_plugin_info;
177         ARDOUR::PluginInfoList* _ladspa_plugin_info;
178         ARDOUR::PluginInfoList* _lv2_plugin_info;
179         ARDOUR::PluginInfoList* _au_plugin_info;
180         ARDOUR::PluginInfoList* _lua_plugin_info;
181
182         std::map<uint32_t, std::string> rdf_type;
183
184         std::string windows_vst_path;
185         std::string lxvst_path;
186
187         bool _cancel_scan;
188         bool _cancel_timeout;
189
190         void ladspa_refresh ();
191         void lua_refresh ();
192         void lua_refresh_cb ();
193         void windows_vst_refresh (bool cache_only = false);
194         void mac_vst_refresh (bool cache_only = false);
195         void lxvst_refresh (bool cache_only = false);
196
197         void add_lrdf_data (const std::string &path);
198         void add_ladspa_presets ();
199         void add_windows_vst_presets ();
200         void add_mac_vst_presets ();
201         void add_lxvst_presets ();
202         void add_presets (std::string domain);
203
204         void au_refresh (bool cache_only = false);
205
206         void lv2_refresh ();
207
208         int windows_vst_discover_from_path (std::string path, bool cache_only = false);
209         int windows_vst_discover (std::string path, bool cache_only = false);
210
211         int mac_vst_discover_from_path (std::string path, bool cache_only = false);
212         int mac_vst_discover (std::string path, bool cache_only = false);
213
214         int lxvst_discover_from_path (std::string path, bool cache_only = false);
215         int lxvst_discover (std::string path, bool cache_only = false);
216
217         int ladspa_discover (std::string path);
218
219         std::string get_ladspa_category (uint32_t id);
220         std::vector<uint32_t> ladspa_plugin_whitelist;
221
222         PBD::ScopedConnection lua_refresh_connection;
223         Glib::Threads::Mutex _lock;
224
225         static PluginManager* _instance; // singleton
226         PluginManager ();
227 };
228
229 } /* namespace ARDOUR */
230
231 #endif /* __ardour_plugin_manager_h__ */
232