Ardour  8.12
plugin_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __gtkardour_plugin_utils_h__
20 #define __gtkardour_plugin_utils_h__
21 
22 #include <list>
23 #include <string>
24 
25 #include "pbd/match.h"
26 
27 #include "ardour/plugin.h"
28 #include "ardour/plugin_manager.h"
29 #include "ardour/utils.h"
30 
32 {
33 
34 inline static void
35 setup_search_string (std::string& searchstr)
36 {
37  transform (searchstr.begin (), searchstr.end (), searchstr.begin (), ::toupper);
38 }
39 
41 public:
43  {
44  std::list<std::string>::const_iterator aiter = std::find (_user.begin (), _user.end (), (*a).unique_id);
45  std::list<std::string>::const_iterator biter = std::find (_user.begin (), _user.end (), (*b).unique_id);
46  if (aiter != _user.end () && biter != _user.end ()) {
47  return std::distance (_user.begin (), aiter) < std::distance (_user.begin (), biter);
48  }
49  if (aiter != _user.end ()) {
50  return true;
51  }
52  if (biter != _user.end ()) {
53  return false;
54  }
55  return ARDOUR::cmp_nocase ((*a).name, (*b).name) == -1;
56  }
57 
58  PluginUIOrderSorter (std::list<std::string> user)
59  : _user (user)
60  { }
61 
62 private:
63  std::list<std::string> _user;
64 };
65 
68  {
69  int cmp = ARDOUR::cmp_nocase_utf8 (a->name, b->name);
70  if (cmp == 0) {
71  /* identical name, compare type */
72  return a->type < b->type;
73  } else {
74  return cmp < 0;
75  }
76  }
77 };
78 
81  {
83 
84  int64_t lru_a, lru_b;
85  uint64_t use_a, use_b;
86  bool stats_a, stats_b;
87 
88  stats_a = manager.stats (a, lru_a, use_a);
89  stats_b = manager.stats (b, lru_b, use_b);
90 
91  if (stats_a && stats_b) {
92  return lru_a > lru_b;
93  }
94  if (stats_a) {
95  return true;
96  }
97  if (stats_b) {
98  return false;
99  }
100  return ARDOUR::cmp_nocase ((*a).name, (*b).name) == -1;
101  }
103  : manager (ARDOUR::PluginManager::instance ())
104  { }
105 
106 private:
108 };
109 
112  {
114 
115  int64_t lru_a, lru_b;
116  uint64_t use_a, use_b;
117  bool stats_a, stats_b;
118 
119  stats_a = manager.stats (a, lru_a, use_a);
120  stats_b = manager.stats (b, lru_b, use_b);
121 
122  if (stats_a && stats_b) {
123  return use_a > use_b;
124  }
125  if (stats_a) {
126  return true;
127  }
128  if (stats_b) {
129  return false;
130  }
131  return ARDOUR::cmp_nocase ((*a).name, (*b).name) == -1;
132  }
134  : manager (ARDOUR::PluginManager::instance ())
135  { }
136 
137 private:
139 };
140 
141 } // namespace ARDOUR_PLUGIN_UTILS
142 #endif
bool stats(PluginInfoPtr const &, int64_t &lru, uint64_t &use_count) const
static PluginManager & instance()
static void setup_search_string(std::string &searchstr)
Definition: plugin_utils.h:35
int cmp_nocase_utf8(const std::string &s1, const std::string &s2)
int cmp_nocase(const std::string &s, const std::string &s2)
std::shared_ptr< PluginInfo > PluginInfoPtr
Definition: plugin.h:66
DebugBits PluginManager
Definition: plugin.h:542
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:67
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:111
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:80
PluginUIOrderSorter(std::list< std::string > user)
Definition: plugin_utils.h:58
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:42