2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "pbd/error.h"
22 #include "pbd/compose.h"
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"
32 using namespace ARDOUR;
36 boost::shared_ptr<Processor>
37 ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
40 return boost::shared_ptr<Processor> ();
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) {
53 warning << _("Script with given name was not found\n");
54 return boost::shared_ptr<Processor> ();
59 LuaPluginInfoPtr lpi (new LuaPluginInfo(spi));
62 warning << _("Failed to instantiate Lua Processor\n");
63 return boost::shared_ptr<Processor> ();
66 return boost::shared_ptr<Processor> (new PluginInsert (*s, p));
70 ARDOUR::LuaAPI::LuaOSCAddress::send (lua_State *L)
72 LuaOSCAddress * const luaosc = luabridge::Userdata::get <LuaOSCAddress> (L, 1, false);
74 return luaL_error (L, "Invalid pointer to OSC.Address");
77 return luaL_error (L, "Invalid Destination Address");
80 int top = lua_gettop(L);
82 return luaL_argerror (L, 1, "invalid number of arguments, :send (path, type, ...)");
85 const char* path = luaL_checkstring (L, 2);
86 const char* type = luaL_checkstring (L, 3);
87 assert (path && type);
89 if ((int) strlen(type) != top - 3) {
90 return luaL_argerror (L, 3, "type description does not match arguments");
93 lo_message msg = lo_message_new ();
95 for (int i = 4; i <= top; ++i) {
97 int lt = lua_type(L, i);
101 if (t == LO_STRING) {
102 ok = lo_message_add_string (msg, luaL_checkstring(L, i));
103 } else if (t == LO_CHAR) {
104 char c = luaL_checkstring (L, i) [0];
105 ok = lo_message_add_char (msg, c);
109 if (t == LO_TRUE || t == LO_FALSE) {
110 if (lua_toboolean (L, i)) {
111 ok = lo_message_add_true (msg);
113 ok = lo_message_add_false (msg);
119 ok = lo_message_add_int32 (msg, (int32_t) luaL_checkinteger(L, i));
121 else if (t == LO_FLOAT) {
122 ok = lo_message_add_float (msg, (float) luaL_checknumber(L, i));
124 else if (t == LO_DOUBLE) {
125 ok = lo_message_add_double (msg, (double) luaL_checknumber(L, i));
127 else if (t == LO_INT64) {
128 ok = lo_message_add_double (msg, (int64_t) luaL_checknumber(L, i));
135 return luaL_argerror (L, i, "type description does not match parameter");
139 int rv = lo_send_message (luaosc->_addr, path, msg);
140 lo_message_free (msg);
141 luabridge::Stack<int>::push (L, rv);