Add backend-API to reset plugin tags
[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         void set_tags (ARDOUR::PluginType type, std::string unique_id, std::string tags, bool factory, bool force = false);
89         void reset_tags (PluginInfoPtr const&);
90         std::string get_tags_as_string (PluginInfoPtr const&) const;
91         std::vector<std::string> get_tags (PluginInfoPtr const&) const;
92         std::vector<std::string> get_all_tags (bool favorites_only) const;
93
94         /** plugins were added to or removed from one of the PluginInfoLists */
95         PBD::Signal0<void> PluginListChanged;
96
97         /** Plugin Hidden/Favorite status changed */
98         PBD::Signal3<void, ARDOUR::PluginType, std::string, PluginStatusType> PluginStatusesChanged; //PluginType t, string id, string tag
99
100         PBD::Signal3<void, ARDOUR::PluginType, std::string, std::string> PluginTagsChanged; //PluginType t, string id, string tag
101
102 private:
103
104         struct PluginTag {
105             ARDOUR::PluginType type;
106             std::string unique_id;
107             std::string tags;
108                         bool user_set;
109
110             PluginTag (ARDOUR::PluginType t, std::string id, std::string s, bool user_set)
111             : type (t), unique_id (id), tags (s), user_set (user_set) {}
112
113             bool operator== (PluginTag const& other) const {
114                     return other.type == type && other.unique_id == unique_id;
115             }
116
117             bool operator< (PluginTag const& other) const {
118                     if (other.type < type) {
119                             return true;
120                     } else if (other.type == type && other.unique_id < unique_id) {
121                             return true;
122                     }
123                     return false;
124             }
125         };
126
127         typedef std::set<PluginTag> PluginTagList;
128         PluginTagList ptags;
129
130         std::string sanitize_tag (const std::string) const;
131
132         struct PluginStatus {
133             ARDOUR::PluginType type;
134             std::string unique_id;
135             PluginStatusType status;
136
137             PluginStatus (ARDOUR::PluginType t, std::string id, PluginStatusType s = Normal)
138             : type (t), unique_id (id), status (s) {}
139
140             bool operator==(const PluginStatus& other) const {
141                     return other.type == type && other.unique_id == unique_id;
142             }
143
144             bool operator<(const PluginStatus& other) const {
145                     if (other.type < type) {
146                             return true;
147                     } else if (other.type == type && other.unique_id < unique_id) {
148                             return true;
149                     }
150                     return false;
151             }
152         };
153         typedef std::set<PluginStatus> PluginStatusList;
154         PluginStatusList statuses;
155
156         ARDOUR::PluginInfoList  _empty_plugin_info;
157         ARDOUR::PluginInfoList* _windows_vst_plugin_info;
158         ARDOUR::PluginInfoList* _lxvst_plugin_info;
159         ARDOUR::PluginInfoList* _mac_vst_plugin_info;
160         ARDOUR::PluginInfoList* _ladspa_plugin_info;
161         ARDOUR::PluginInfoList* _lv2_plugin_info;
162         ARDOUR::PluginInfoList* _au_plugin_info;
163         ARDOUR::PluginInfoList* _lua_plugin_info;
164
165         std::map<uint32_t, std::string> rdf_type;
166
167         std::string windows_vst_path;
168         std::string lxvst_path;
169
170         bool _cancel_scan;
171         bool _cancel_timeout;
172
173         void ladspa_refresh ();
174         void lua_refresh ();
175         void lua_refresh_cb ();
176         void windows_vst_refresh (bool cache_only = false);
177         void mac_vst_refresh (bool cache_only = false);
178         void lxvst_refresh (bool cache_only = false);
179
180         void add_lrdf_data (const std::string &path);
181         void add_ladspa_presets ();
182         void add_windows_vst_presets ();
183         void add_mac_vst_presets ();
184         void add_lxvst_presets ();
185         void add_presets (std::string domain);
186
187         void au_refresh (bool cache_only = false);
188
189         void lv2_refresh ();
190
191         int windows_vst_discover_from_path (std::string path, bool cache_only = false);
192         int windows_vst_discover (std::string path, bool cache_only = false);
193
194         int mac_vst_discover_from_path (std::string path, bool cache_only = false);
195         int mac_vst_discover (std::string path, bool cache_only = false);
196
197         int lxvst_discover_from_path (std::string path, bool cache_only = false);
198         int lxvst_discover (std::string path, bool cache_only = false);
199
200         int ladspa_discover (std::string path);
201
202         std::string get_ladspa_category (uint32_t id);
203         std::vector<uint32_t> ladspa_plugin_whitelist;
204
205         PBD::ScopedConnection lua_refresh_connection;
206         Glib::Threads::Mutex _lock;
207
208         static PluginManager* _instance; // singleton
209         PluginManager ();
210 };
211
212 } /* namespace ARDOUR */
213
214 #endif /* __ardour_plugin_manager_h__ */
215