Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
20 
21 #include <list>
22 #include <string>
23 
24 #include "pbd/match.h"
25 
26 #include "ardour/plugin.h"
27 #include "ardour/plugin_manager.h"
28 #include "ardour/utils.h"
29 
31 {
32 
33 inline static void
34 setup_search_string (std::string& searchstr)
35 {
36  transform (searchstr.begin (), searchstr.end (), searchstr.begin (), ::toupper);
37 }
38 
40 public:
42  {
43  std::list<std::string>::const_iterator aiter = std::find (_user.begin (), _user.end (), (*a).unique_id);
44  std::list<std::string>::const_iterator biter = std::find (_user.begin (), _user.end (), (*b).unique_id);
45  if (aiter != _user.end () && biter != _user.end ()) {
46  return std::distance (_user.begin (), aiter) < std::distance (_user.begin (), biter);
47  }
48  if (aiter != _user.end ()) {
49  return true;
50  }
51  if (biter != _user.end ()) {
52  return false;
53  }
54  return ARDOUR::cmp_nocase ((*a).name, (*b).name) == -1;
55  }
56 
57  PluginUIOrderSorter (std::list<std::string> user)
58  : _user (user)
59  { }
60 
61 private:
62  std::list<std::string> _user;
63 };
64 
67  {
68  int cmp = ARDOUR::cmp_nocase_utf8 (a->name, b->name);
69  if (cmp == 0) {
70  /* identical name, compare type */
71  return a->type < b->type;
72  } else {
73  return cmp < 0;
74  }
75  }
76 };
77 
80  {
82 
83  int64_t lru_a, lru_b;
84  uint64_t use_a, use_b;
85  bool stats_a, stats_b;
86 
87  stats_a = manager.stats (a, lru_a, use_a);
88  stats_b = manager.stats (b, lru_b, use_b);
89 
90  if (stats_a && stats_b) {
91  return lru_a > lru_b;
92  }
93  if (stats_a) {
94  return true;
95  }
96  if (stats_b) {
97  return false;
98  }
99  return ARDOUR::cmp_nocase ((*a).name, (*b).name) == -1;
100  }
102  : manager (ARDOUR::PluginManager::instance ())
103  { }
104 
105 private:
107 };
108 
111  {
113 
114  int64_t lru_a, lru_b;
115  uint64_t use_a, use_b;
116  bool stats_a, stats_b;
117 
118  stats_a = manager.stats (a, lru_a, use_a);
119  stats_b = manager.stats (b, lru_b, use_b);
120 
121  if (stats_a && stats_b) {
122  return use_a > use_b;
123  }
124  if (stats_a) {
125  return true;
126  }
127  if (stats_b) {
128  return false;
129  }
130  return ARDOUR::cmp_nocase ((*a).name, (*b).name) == -1;
131  }
133  : manager (ARDOUR::PluginManager::instance ())
134  { }
135 
136 private:
138 };
139 
140 } // namespace ARDOUR_PLUGIN_UTILS
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:34
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:65
DebugBits PluginManager
Definition: plugin.h:541
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:66
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:110
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:79
PluginUIOrderSorter(std::list< std::string > user)
Definition: plugin_utils.h:57
bool operator()(ARDOUR::PluginInfoPtr a, ARDOUR::PluginInfoPtr b) const
Definition: plugin_utils.h:41