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/panner_manager.h"
30 #include "ardour/panner_search_path.h"
35 using namespace ARDOUR;
38 PannerManager* PannerManager::_instance = 0;
40 PannerManager::PannerManager ()
44 PannerManager::~PannerManager ()
46 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
52 PannerManager::instance ()
55 _instance = new PannerManager ();
62 PannerManager::discover_panners ()
64 vector<sys::path> panner_modules;
66 Glib::PatternSpec so_extension_pattern("*.so");
67 Glib::PatternSpec dylib_extension_pattern("*.dylib");
69 find_matching_files_in_search_path (panner_search_path (),
70 so_extension_pattern, panner_modules);
72 find_matching_files_in_search_path (panner_search_path (),
73 dylib_extension_pattern, panner_modules);
75 info << string_compose (_("looking for panners in %1"), panner_search_path().to_string()) << endmsg;
77 for (vector<sys::path>::iterator i = panner_modules.begin(); i != panner_modules.end(); ++i) {
78 panner_discover ((*i).to_string());
82 PannerManager::panner_discover (string path)
86 if ((pinfo = get_descriptor (path)) != 0) {
88 list<PannerInfo*>::iterator i;
90 for (i = panner_info.begin(); i != panner_info.end(); ++i) {
91 if (pinfo->descriptor.name == (*i)->descriptor.name) {
96 if (i == panner_info.end()) {
97 panner_info.push_back (pinfo);
98 info << string_compose(_("Panner discovered: \"%1\" in %2"), pinfo->descriptor.name, path) << endmsg;
106 PannerManager::get_descriptor (string path)
109 PannerInfo* info = 0;
110 PanPluginDescriptor *descriptor = 0;
111 PanPluginDescriptor* (*dfunc)(void);
114 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
115 error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
119 dfunc = (PanPluginDescriptor* (*)(void)) dlsym (module, "panner_descriptor");
121 if ((errstr = dlerror()) != 0) {
122 error << string_compose(_("PannerManager: module \"%1\" has no descriptor function."), path) << endmsg;
123 error << errstr << endmsg;
128 descriptor = dfunc();
130 info = new PannerInfo (*descriptor, module);
139 PannerManager::select_panner (ChanCount in, ChanCount out)
141 PanPluginDescriptor* d;
142 int32_t nin = in.n_audio();
143 int32_t nout = out.n_audio();
145 /* look for exact match first */
147 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
148 d = &(*p)->descriptor;
150 if (d->in == nin && d->out == nout) {
155 /* no exact match, look for good fit on inputs and variable on outputs */
157 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
158 d = &(*p)->descriptor;
160 if (d->in == nin && d->out == -1) {
165 /* no exact match, look for good fit on outputs and variable on inputs */
167 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
168 d = &(*p)->descriptor;
170 if (d->in == -1 && d->out == nout) {
175 /* no exact match, look for variable fit on inputs and outputs */
177 for (list<PannerInfo*>::iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
178 d = &(*p)->descriptor;
180 if (d->in == -1 && d->out == -1) {
185 warning << string_compose (_("no panner discovered for in/out = %1/%2"), nin, nout) << endmsg;