Ardour  9.0-pre0-582-g084a23a80d
plugin_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2013 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2014-2021 Robin Gareus <robin@gareus.org>
7  * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #pragma once
25 
26 #ifdef WAF_BUILD
27 #include "libardour-config.h"
28 #endif
29 
30 #include <list>
31 #include <map>
32 #include <string>
33 #include <set>
34 
36 #include "ardour/types.h"
37 #include "ardour/plugin.h"
39 
40 #ifdef AUDIOUNIT_SUPPORT
41 class CAComponentDescription;
42 #endif
43 
44 namespace PBD {
45  class Searchpath;
46 }
47 
48 namespace ARDOUR {
49 
50 class Plugin;
51 
52 #ifdef VST3_SUPPORT
53 struct VST3Info;
54 #endif
55 
56 #if (defined WINDOWS_VST_SUPPORT || defined MACVST_SUPPORT || defined LXVST_SUPPORT)
57 struct VST2Info;
58 #endif
59 
60 #ifdef AUDIOUNIT_SUPPORT
61 struct AUv2Info;
62 struct AUv2DescStr;
63 #endif
64 
65 
67 public:
69  static std::string auv2_scanner_bin_path;
70  static std::string vst2_scanner_bin_path;
71  static std::string vst3_scanner_bin_path;
72 
73  PluginManager (const PluginManager&) = delete;
74  PluginManager& operator= (const PluginManager&) = delete;
76 
85 
86  void refresh (bool cache_only = false);
87 
88  void cancel_scan_all ();
89  void cancel_scan_one ();
93 
94  void clear_vst_cache ();
96  void clear_au_cache ();
100 
101  const std::string get_default_windows_vst_path() const { return windows_vst_path; }
102  const std::string get_default_lxvst_path() const { return lxvst_path; }
103 
104  static uint32_t cache_version ();
105  bool cache_valid () const;
106 
107  void scan_log (std::vector<std::shared_ptr<PluginScanLogEntry> >&) const;
109 
110  bool whitelist (ARDOUR::PluginType, std::string const&, bool force);
111  void blacklist (ARDOUR::PluginType, std::string const&);
112  static std::string cache_file (ARDOUR::PluginType, std::string const&);
113 
114  bool rescan_plugin (ARDOUR::PluginType, std::string const&, size_t num = 0, size_t den = 1);
115  void rescan_faulty ();
116 
117  /* always return LXVST for any VST subtype */
119 
120  /* format plugin type to human readable name
121  * @param short use at most 4 chars (useful for ctrl-surface displays)
122  */
123  static std::string plugin_type_name (const PluginType, bool short_name = true);
124 
125  bool cancelled () const { return _cancel_scan_all || _cancel_scan_one; }
126 
127  void reset_stats ();
129  bool stats (PluginInfoPtr const&, int64_t& lru, uint64_t& use_count) const;
130  void save_stats ();
131 
133  Normal = 0,
136  Concealed
137  };
138 
139  std::string user_plugin_metadata_dir () const;
140  void save_statuses ();
141  void set_status (ARDOUR::PluginType type, std::string const& unique_id, PluginStatusType status);
143 
144  void save_tags ();
145 
146  std::string dump_untagged_plugins ();
147 
148  bool load_plugin_order_file (XMLNode &n) const; //returns TRUE if the passed-in node has valid info
149  void save_plugin_order_file (XMLNode &elem) const;
150 
151  enum TagType {
152  FromPlug, //tag info is being set from plugin metadata
153  FromFactoryFile, // ... from the factory metadata file
154  FromUserFile, // ... from the user's config data
155  FromGui // ... from the UI, in realtime: will emit a signal so ui can show "sanitized" string as it is generated
156  };
157  void set_tags (ARDOUR::PluginType type, std::string unique_id, std::string tags, std::string name, TagType tagtype);
158  void reset_tags (PluginInfoPtr const&);
159  std::string get_tags_as_string (PluginInfoPtr const&) const;
160  std::vector<std::string> get_tags (PluginInfoPtr const&) const;
161 
162  enum TagFilter {
165  NoHidden
166  };
167  std::vector<std::string> get_all_tags (enum TagFilter) const;
168 
173 
176 
179 
181  PBD::Signal<void(ARDOUR::PluginType, std::string, PluginStatusType)> PluginStatusChanged; //PluginType t, string id, string tag
182 
184  PBD::Signal<void(ARDOUR::PluginType, std::string, std::string)> PluginTagChanged; //PluginType t, string id, string tag
185 
186 private:
187  typedef std::shared_ptr<PluginScanLogEntry> PSLEPtr;
188 
189  struct PSLEPtrSort {
190  bool operator() (PSLEPtr const& a, PSLEPtr const& b) const {
191  return *a < *b;
192  }
193  };
194 
195  typedef std::set<PSLEPtr, PSLEPtrSort> PluginScanLog;
197 
198  PSLEPtr scan_log_entry (PluginType const type, std::string const& path) {
199  PSLEPtr psl = PSLEPtr (new PluginScanLogEntry (type, path));
200  PluginScanLog::iterator i = _plugin_scan_log.find (psl);
201  if (i == _plugin_scan_log.end ()) {
202  _plugin_scan_log.insert (psl);
203  i = _plugin_scan_log.find (psl);
204  }
205  return *i;
206  }
207 
208  struct PluginTag {
210  std::string const unique_id;
211  std::string const name;
212  std::string tags;
214 
215  PluginTag (ARDOUR::PluginType t, std::string const& id, std::string const& tag, std::string const& n, TagType tt)
216  : type (t), unique_id (id), name(n), tags (tag), tagtype (tt) {}
217 
218  bool operator== (PluginTag const& other) const {
219  return other.type == type && other.unique_id == unique_id;
220  }
221 
222  bool operator< (PluginTag const& other) const {
223  if (other.type == type) {
224  return other.unique_id < unique_id;
225  }
226  return other.type < type;
227  }
228  };
229 
230  struct PluginStatus {
232  std::string const unique_id;
234 
235  PluginStatus (ARDOUR::PluginType t, std::string const& id, PluginStatusType s = Normal)
236  : type (t), unique_id (id), status (s) {}
237 
238  bool operator==(const PluginStatus& other) const {
239  return other.type == type && other.unique_id == unique_id;
240  }
241 
242  bool operator<(const PluginStatus& other) const {
243  if (other.type == type) {
244  return other.unique_id < unique_id;
245  }
246  return other.type < type;
247  }
248  };
249 
250  struct PluginStats {
252  std::string const unique_id;
253  int64_t lru;
254  uint64_t use_count;
255 
256  PluginStats (ARDOUR::PluginType t, std::string const& id, int64_t lru = 0, uint64_t use_count = 0)
257  : type (t), unique_id (id), lru (lru), use_count (use_count) {}
258 
259  bool operator==(const PluginStats& other) const {
260  return other.type == type && other.unique_id == unique_id;
261  }
262 
263  bool operator<(const PluginStats& other) const {
264  if (other.type == type) {
265  return other.unique_id < unique_id;
266  }
267  return other.type < type;
268  }
269  };
270 
271  typedef std::set<PluginTag> PluginTagList;
273  PluginTagList ftags; /* factory-file defaults */
274 
275  typedef std::set<PluginStatus> PluginStatusList;
277 
278  typedef std::set<PluginStats> PluginStatsList;
280 
290 
291  std::map<uint32_t, std::string> rdf_type;
292 
293  std::string windows_vst_path;
294  std::string lxvst_path;
295 
301 
302  void reset_scan_cancel_state (bool single = false);
303 
305 
306  bool no_timeout () const { return _cancel_scan_timeout_one || _cancel_scan_timeout_all; }
307 
310 
312 
314 
315  void load_statuses ();
316  void load_tags ();
317  void load_stats ();
318 
319  void load_scanlog ();
320  void save_scanlog ();
321 
322  std::string sanitize_tag (const std::string) const;
323 
324  void ladspa_refresh ();
325  void lua_refresh ();
326  void lua_refresh_cb ();
327  void windows_vst_refresh (bool cache_only);
328  void mac_vst_refresh (bool cache_only);
329  void lxvst_refresh (bool cache_only);
330  void vst3_refresh (bool cache_only);
331 
333  void add_lrdf_presets (std::string domain);
334 
335 #ifdef AUDIOUNIT_SUPPORT
336  void au_refresh (bool cache_only = false);
337  void auv2_plugin (CAComponentDescription const&, AUv2Info const&);
338  int auv2_discover (AUv2DescStr const&, bool);
339  bool run_auv2_scanner_app (CAComponentDescription const&, AUv2DescStr const&, PSLEPtr) const;
340 #endif
341 
342  void lv2_plugin (std::string const&, PluginScanLogEntry::PluginScanResult, std::string const&, bool);
343  void lv2_refresh ();
344 
345  int windows_vst_discover_from_path (std::string path, bool cache_only = false);
346  int mac_vst_discover_from_path (std::string path, std::set<std::string>&, bool cache_only = false);
347  int lxvst_discover_from_path (std::string path, bool cache_only = false);
348 #if (defined WINDOWS_VST_SUPPORT || defined MACVST_SUPPORT || defined LXVST_SUPPORT)
349  bool vst2_plugin (std::string const& module_path, ARDOUR::PluginType, VST2Info const&);
350  bool run_vst2_scanner_app (std::string bundle_path, PSLEPtr) const;
351  int vst2_discover (std::string path, ARDOUR::PluginType, bool cache_only = false);
352 #endif
353 
354  int vst3_discover_from_path (std::string const& path, bool cache_only = false);
355  int vst3_discover (std::string const& path, bool cache_only = false);
356 #ifdef VST3_SUPPORT
357  void vst3_plugin (std::string const&, std::string const&, VST3Info const&);
358  bool run_vst3_scanner_app (std::string bundle_path, PSLEPtr) const;
359 #endif
360 
361  int ladspa_discover (std::string path);
362 
363  std::string get_ladspa_category (uint32_t id);
364  std::vector<uint32_t> ladspa_plugin_whitelist;
365 
367  Glib::Threads::Mutex _lock;
368 
369  static PluginManager* _instance; // singleton
371 };
372 
373 } /* namespace ARDOUR */
374 
375 
std::set< PluginStatus > PluginStatusList
void detect_type_ambiguities(ARDOUR::PluginInfoList &)
const ARDOUR::PluginInfoList & au_plugin_info()
std::string get_ladspa_category(uint32_t id)
int ladspa_discover(std::string path)
bool whitelist(ARDOUR::PluginType, std::string const &, bool force)
int lxvst_discover_from_path(std::string path, bool cache_only=false)
std::set< PluginStats > PluginStatsList
void get_all_plugins(PluginInfoList &) const
static std::string vst2_scanner_bin_path
bool stats(PluginInfoPtr const &, int64_t &lru, uint64_t &use_count) const
const ARDOUR::PluginInfoList & vst3_plugin_info()
std::vector< std::string > get_tags(PluginInfoPtr const &) const
ARDOUR::PluginInfoList * _lua_plugin_info
static std::string vst3_scanner_bin_path
const ARDOUR::PluginInfoList & lxvst_plugin_info()
int windows_vst_discover_from_path(std::string path, bool cache_only=false)
void windows_vst_refresh(bool cache_only)
void add_lrdf_data(PBD::Searchpath const &)
ARDOUR::PluginInfoList * _au_plugin_info
static std::string cache_file(ARDOUR::PluginType, std::string const &)
PBD::ScopedConnection lua_refresh_connection
void add_lrdf_presets(std::string domain)
int vst2_discover(std::string path, ARDOUR::PluginType, bool cache_only=false)
void reset_scan_cancel_state(bool single=false)
void set_tags(ARDOUR::PluginType type, std::string unique_id, std::string tags, std::string name, TagType tagtype)
PluginStatusType get_status(const PluginInfoPtr &) const
ARDOUR::PluginInfoList * _vst3_plugin_info
Glib::Threads::Mutex _lock
const ARDOUR::PluginInfoList & windows_vst_plugin_info()
const ARDOUR::PluginInfoList & ladspa_plugin_info()
bool run_vst2_scanner_app(std::string bundle_path, PSLEPtr) const
void set_status(ARDOUR::PluginType type, std::string const &unique_id, PluginStatusType status)
const ARDOUR::PluginInfoList & mac_vst_plugin_info()
bool cache_valid() const
static std::string plugin_type_name(const PluginType, bool short_name=true)
void refresh(bool cache_only=false)
std::string sanitize_tag(const std::string) const
PluginManager(const PluginManager &)=delete
ARDOUR::PluginInfoList * _mac_vst_plugin_info
bool vst2_plugin(std::string const &module_path, ARDOUR::PluginType, VST2Info const &)
std::string get_tags_as_string(PluginInfoPtr const &) const
void lxvst_refresh(bool cache_only)
const ARDOUR::PluginInfoList & lv2_plugin_info()
void scan_log(std::vector< std::shared_ptr< PluginScanLogEntry > > &) const
std::set< PluginTag > PluginTagList
static PluginManager * _instance
static PluginManager & instance()
int mac_vst_discover_from_path(std::string path, std::set< std::string > &, bool cache_only=false)
static std::string auv2_scanner_bin_path
PSLEPtr scan_log_entry(PluginType const type, std::string const &path)
const std::string get_default_windows_vst_path() const
std::string user_plugin_metadata_dir() const
std::shared_ptr< PluginScanLogEntry > PSLEPtr
ARDOUR::PluginInfoList * _lxvst_plugin_info
static uint32_t cache_version()
PBD::Signal< void()> PluginListChanged
void blacklist(ARDOUR::PluginType, std::string const &)
PBD::Signal< void()> PluginStatsChanged
ARDOUR::PluginInfoList * _ladspa_plugin_info
PBD::Signal< void(ARDOUR::PluginType, std::string, PluginStatusType)> PluginStatusChanged
void lv2_plugin(std::string const &, PluginScanLogEntry::PluginScanResult, std::string const &, bool)
std::vector< uint32_t > ladspa_plugin_whitelist
bool load_plugin_order_file(XMLNode &n) const
void save_plugin_order_file(XMLNode &elem) const
void reset_tags(PluginInfoPtr const &)
void mac_vst_refresh(bool cache_only)
int vst3_discover_from_path(std::string const &path, bool cache_only=false)
void detect_name_ambiguities(ARDOUR::PluginInfoList *)
std::set< PSLEPtr, PSLEPtrSort > PluginScanLog
PluginScanLog _plugin_scan_log
ARDOUR::PluginInfoList * _windows_vst_plugin_info
std::vector< std::string > get_all_tags(enum TagFilter) const
const ARDOUR::PluginInfoList & lua_plugin_info()
PluginStatsList statistics
const std::string get_default_lxvst_path() const
std::map< uint32_t, std::string > rdf_type
void vst3_refresh(bool cache_only)
bool rescan_plugin(ARDOUR::PluginType, std::string const &, size_t num=0, size_t den=1)
int vst3_discover(std::string const &path, bool cache_only=false)
PBD::Signal< void()> PluginScanLogChanged
void conceal_duplicates(ARDOUR::PluginInfoList *, ARDOUR::PluginInfoList *)
ARDOUR::PluginInfoList * _lv2_plugin_info
PluginStatusList statuses
static PluginType to_generic_vst(const PluginType)
std::string windows_vst_path
PBD::Signal< void(ARDOUR::PluginType, std::string, std::string)> PluginTagChanged
void stats_use_plugin(PluginInfoPtr const &)
std::string dump_untagged_plugins()
ARDOUR::PluginInfoList _empty_plugin_info
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
PBD::PropertyDescriptor< std::string > tags
std::list< PluginInfoPtr > PluginInfoList
Definition: plugin.h:66
std::shared_ptr< PluginInfo > PluginInfoPtr
Definition: plugin.h:65
Definition: axis_view.h:42
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
PluginStats(ARDOUR::PluginType t, std::string const &id, int64_t lru=0, uint64_t use_count=0)
bool operator==(const PluginStats &other) const
bool operator<(const PluginStats &other) const
bool operator==(const PluginStatus &other) const
bool operator<(const PluginStatus &other) const
PluginStatus(ARDOUR::PluginType t, std::string const &id, PluginStatusType s=Normal)
PluginTag(ARDOUR::PluginType t, std::string const &id, std::string const &tag, std::string const &n, TagType tt)