gcc4 compat
[ardour.git] / libs / ardour / lua_api.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 #include <cstring>
20
21 #include "pbd/error.h"
22 #include "pbd/compose.h"
23
24 #include "ardour/lua_api.h"
25 #include "ardour/luaproc.h"
26 #include "ardour/luascripting.h"
27 #include "ardour/plugin.h"
28 #include "ardour/plugin_insert.h"
29
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33 using namespace PBD;
34 using namespace std;
35
36 boost::shared_ptr<Processor>
37 ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
38 {
39         if (!s) {
40                 return boost::shared_ptr<Processor> (0);
41         }
42
43         LuaScriptInfoPtr spi;
44         ARDOUR::LuaScriptList & _scripts (LuaScripting::instance ().scripts (LuaScriptInfo::DSP));
45         for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
46                 if (name == (*s)->name) {
47                         spi = *s;
48                         break;
49                 }
50         }
51
52         if (!spi) {
53                 warning << _("Script with given name was not found\n");
54                 return boost::shared_ptr<Processor> ();
55         }
56
57         PluginPtr p;
58         try {
59                 LuaPluginInfoPtr lpi (new LuaPluginInfo(spi));
60                 p = (lpi->load (*s));
61         } catch (...) {
62                 warning << _("Failed to instantiate Lua Processor\n");
63                 return boost::shared_ptr<Processor> ();
64         }
65
66         return boost::shared_ptr<Processor> (new PluginInsert (*s, p));
67 }