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/file_utils.h"
29 #include "ardour/debug.h"
30 #include "ardour/panner_manager.h"
31 #include "ardour/panner_search_path.h"
36 using namespace ARDOUR;
39 PannerManager* PannerManager::_instance = 0;
41 PannerManager::PannerManager ()
45 PannerManager::~PannerManager ()
47 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
53 PannerManager::instance ()
56 _instance = new PannerManager ();
63 PannerManager::discover_panners ()
65 vector<std::string> panner_modules;
67 Glib::PatternSpec so_extension_pattern("*.so");
68 Glib::PatternSpec dylib_extension_pattern("*.dylib");
70 find_matching_files_in_search_path (panner_search_path (),
71 so_extension_pattern, panner_modules);
73 find_matching_files_in_search_path (panner_search_path (),
74 dylib_extension_pattern, panner_modules);
76 DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for panners in %1"), panner_search_path().to_string()));
78 for (vector<std::string>::iterator i = panner_modules.begin(); i != panner_modules.end(); ++i) {
83 PannerManager::panner_discover (string path)
87 if ((pinfo = get_descriptor (path)) != 0) {
89 list<PannerInfo*>::iterator i;
91 for (i = panner_info.begin(); i != panner_info.end(); ++i) {
92 if (pinfo->descriptor.name == (*i)->descriptor.name) {
97 if (i == panner_info.end()) {
98 panner_info.push_back (pinfo);
99 DEBUG_TRACE (DEBUG::Panning, string_compose(_("Panner discovered: \"%1\" in %2"), pinfo->descriptor.name, path));
107 PannerManager::get_descriptor (string path)
109 Glib::Module* module = new Glib::Module(path);
110 PannerInfo* info = 0;
111 PanPluginDescriptor *descriptor = 0;
112 PanPluginDescriptor* (*dfunc)(void);
116 error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path,
117 Glib::Module::get_last_error()) << endmsg;
122 if (!module->get_symbol("panner_descriptor", func)) {
123 error << string_compose(_("PannerManager: module \"%1\" has no descriptor function."), path) << endmsg;
124 error << Glib::Module::get_last_error() << endmsg;
129 dfunc = (PanPluginDescriptor* (*)(void))func;
130 descriptor = dfunc();
133 info = new PannerInfo (*descriptor, module);
142 PannerManager::select_panner (ChanCount in, ChanCount out)
144 PanPluginDescriptor* d;
145 int32_t nin = in.n_audio();
146 int32_t nout = out.n_audio();
148 /* look for exact match first */
150 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
151 d = &(*p)->descriptor;
153 if (d->in == nin && d->out == nout) {
158 /* no exact match, look for good fit on inputs and variable on outputs */
160 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
161 d = &(*p)->descriptor;
163 if (d->in == nin && d->out == -1) {
168 /* no exact match, look for good fit on outputs and variable on inputs */
170 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
171 d = &(*p)->descriptor;
173 if (d->in == -1 && d->out == nout) {
178 /* no exact match, look for variable fit on inputs and outputs */
180 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
181 d = &(*p)->descriptor;
183 if (d->in == -1 && d->out == -1) {
188 warning << string_compose (_("no panner discovered for in/out = %1/%2"), nin, nout) << endmsg;