2 Copyright (C) 2011 Paul Davis
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.
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.
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.
22 #include <glibmm/pattern.h>
23 #include <glibmm/fileutils.h>
25 #include "pbd/error.h"
26 #include "pbd/compose.h"
27 #include "pbd/pathscanner.h"
28 #include "pbd/stl_delete.h"
30 #include "ardour/debug.h"
31 #include "ardour/panner_manager.h"
33 #include "ardour/panner_search_path.h"
38 using namespace ARDOUR;
41 PannerManager* PannerManager::_instance = 0;
43 PannerManager::PannerManager ()
47 PannerManager::~PannerManager ()
49 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
55 PannerManager::instance ()
58 _instance = new PannerManager ();
64 static bool panner_filter (const string& str, void */*arg*/)
67 return str[0] != '.' && (str.length() > 6 && str.find (".dylib") == (str.length() - 6));
69 return str[0] != '.' && (str.length() > 3 && (str.find (".so") == (str.length() - 3) || str.find (".dll") == (str.length() - 4)));
74 PannerManager::discover_panners ()
77 std::vector<std::string *> *panner_modules;
78 std::string search_path = panner_search_path().to_string();
80 DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for panners in %1\n"), search_path));
82 panner_modules = scanner (search_path, panner_filter, 0, false, true, 1, true);
84 for (vector<std::string *>::iterator i = panner_modules->begin(); i != panner_modules->end(); ++i) {
85 panner_discover (**i);
88 vector_delete (panner_modules);
92 PannerManager::panner_discover (string path)
96 if ((pinfo = get_descriptor (path)) != 0) {
98 list<PannerInfo*>::iterator i;
100 for (i = panner_info.begin(); i != panner_info.end(); ++i) {
101 if (pinfo->descriptor.name == (*i)->descriptor.name) {
106 if (i == panner_info.end()) {
107 panner_info.push_back (pinfo);
108 DEBUG_TRACE (DEBUG::Panning, string_compose(_("Panner discovered: \"%1\" in %2\n"), pinfo->descriptor.name, path));
116 PannerManager::get_descriptor (string path)
118 Glib::Module* module = new Glib::Module(path);
119 PannerInfo* info = 0;
120 PanPluginDescriptor *descriptor = 0;
121 PanPluginDescriptor* (*dfunc)(void);
125 error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path,
126 Glib::Module::get_last_error()) << endmsg;
131 if (!module->get_symbol("panner_descriptor", func)) {
132 error << string_compose(_("PannerManager: module \"%1\" has no descriptor function."), path) << endmsg;
133 error << Glib::Module::get_last_error() << endmsg;
138 dfunc = (PanPluginDescriptor* (*)(void))func;
139 descriptor = dfunc();
142 info = new PannerInfo (*descriptor, module);
151 PannerManager::select_panner (ChanCount in, ChanCount out, std::string const uri)
153 PannerInfo* rv = NULL;
154 PanPluginDescriptor* d;
155 int32_t nin = in.n_audio();
156 int32_t nout = out.n_audio();
157 uint32_t priority = 0;
159 /* look for user-preference -- check if channels match */
160 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
161 d = &(*p)->descriptor;
162 if (d->panner_uri != uri) continue;
163 if (d->in != nin && d->in != -1) continue;
164 if (d->out != nout && d->out != -1) continue;
168 /* look for exact match first */
170 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
171 d = &(*p)->descriptor;
173 if (d->in == nin && d->out == nout && d->priority > priority) {
174 priority = d->priority;
178 if (rv) { return rv; }
180 /* no exact match, look for good fit on inputs and variable on outputs */
183 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
184 d = &(*p)->descriptor;
186 if (d->in == nin && d->out == -1 && d->priority > priority) {
187 priority = d->priority;
191 if (rv) { return rv; }
193 /* no exact match, look for good fit on outputs and variable on inputs */
196 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
197 d = &(*p)->descriptor;
199 if (d->in == -1 && d->out == nout && d->priority > priority) {
200 priority = d->priority;
204 if (rv) { return rv; }
206 /* no exact match, look for variable fit on inputs and outputs */
209 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
210 d = &(*p)->descriptor;
212 if (d->in == -1 && d->out == -1 && d->priority > priority) {
213 priority = d->priority;
217 if (rv) { return rv; }
219 warning << string_compose (_("no panner discovered for in/out = %1/%2"), nin, nout) << endmsg;
225 PannerManager::get_by_uri (std::string uri) const
227 PannerInfo* pi = NULL;
228 for (list<PannerInfo*>::const_iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
229 if ((*p)->descriptor.panner_uri != uri) continue;
237 PannerManager::get_available_panners(uint32_t const a_in, uint32_t const a_out) const
240 int const out = a_out;
241 PannerUriMap panner_list;
243 if (out < 2 || in == 0) {
247 /* get available panners for current configuration. */
248 for (list<PannerInfo*>::const_iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
249 PanPluginDescriptor* d = &(*p)->descriptor;
250 if (d->in != -1 && d->in != in) continue;
251 if (d->out != -1 && d->out != out) continue;
252 if (d->in == -1 && d->out == -1 && out <= 2) continue;
253 panner_list.insert(std::pair<std::string,std::string>(d->panner_uri,d->name));