2 * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef __gtkardour_luainstance_h__
20 #define __gtkardour_luainstance_h__
27 #include "pbd/signals.h"
28 #include "pbd/xml++.h"
30 #include "ardour/luascripting.h"
31 #include "ardour/lua_script_params.h"
32 #include "ardour/luabindings.h"
33 #include "ardour/session_handle.h"
35 #include "lua/luastate.h"
37 #include "luasignal.h"
43 typedef std::bitset<LuaSignal::LAST_SIGNAL> ActionHook;
45 class LuaCallback : public ARDOUR::SessionHandlePtr, public sigc::trackable
48 LuaCallback (ARDOUR::Session*, const std::string&, const std::string&, const ActionHook&, const ARDOUR::LuaScriptParamList&);
49 LuaCallback (ARDOUR::Session*, XMLNode & node);
52 XMLNode& get_state (void);
53 void set_session (ARDOUR::Session *);
55 const PBD::ID& id () const { return _id; }
56 const std::string& name () const { return _name; }
57 ActionHook signals () const { return _signals; }
58 bool lua_slot (std::string&, std::string&, ActionHook&, ARDOUR::LuaScriptParamList&);
59 PBD::Signal0<void> drop_callback;
62 void session_going_away ();
72 template <class T> void reconnect_object (T);
75 luabridge::LuaRef * _lua_add;
76 luabridge::LuaRef * _lua_get;
77 luabridge::LuaRef * _lua_call;
78 luabridge::LuaRef * _lua_save;
79 luabridge::LuaRef * _lua_load;
81 PBD::ScopedConnectionList _connections;
83 template <typename T, typename S> void connect_0 (enum LuaSignal::LuaSignal, T, S*);
84 template <typename T> void proxy_0 (enum LuaSignal::LuaSignal, T);
86 template <typename T, typename C1> void connect_1 (enum LuaSignal::LuaSignal, T, PBD::Signal1<void, C1>*);
87 template <typename T, typename C1> void proxy_1 (enum LuaSignal::LuaSignal, T, C1);
89 template <typename T, typename C1, typename C2> void connect_2 (enum LuaSignal::LuaSignal, T, PBD::Signal2<void, C1, C2>*);
90 template <typename T, typename C1, typename C2> void proxy_2 (enum LuaSignal::LuaSignal, T, C1, C2);
92 template <typename T, typename C1, typename C2, typename C3> void connect_3 (enum LuaSignal::LuaSignal, T, PBD::Signal3<void, C1, C2, C3>*);
93 template <typename T, typename C1, typename C2, typename C3> void proxy_3 (enum LuaSignal::LuaSignal, T, C1, C2, C3);
96 typedef boost::shared_ptr<LuaCallback> LuaCallbackPtr;
97 typedef std::map<PBD::ID, LuaCallbackPtr> LuaCallbackMap;
101 class LuaInstance : public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
104 static LuaInstance* instance();
105 static void destroy_instance();
108 static void register_classes (lua_State* L);
109 static void register_hooks (lua_State* L);
110 static void bind_cairo (lua_State* L);
111 static void bind_dialog (lua_State* L);
113 static void render_action_icon (cairo_t* cr, int w, int h, uint32_t c, void* i);
115 void set_session (ARDOUR::Session* s);
117 int set_state (const XMLNode&);
118 XMLNode& get_action_state (void);
119 XMLNode& get_hook_state (void);
124 bool interactive_add (ARDOUR::LuaScriptInfo::ScriptType, int);
127 void call_action (const int);
128 void render_icon (int i, cairo_t*, int, int, uint32_t);
130 bool set_lua_action (const int, const std::string&, const std::string&, const ARDOUR::LuaScriptParamList&);
131 bool remove_lua_action (const int);
132 bool lua_action_name (const int, std::string&);
133 std::vector<std::string> lua_action_names ();
134 bool lua_action (const int, std::string&, std::string&, ARDOUR::LuaScriptParamList&);
135 bool lua_action_has_icon (const int);
136 sigc::signal<void,int,std::string> ActionChanged;
139 bool register_lua_slot (const std::string&, const std::string&, const ARDOUR::LuaScriptParamList&);
140 bool unregister_lua_slot (const PBD::ID&);
141 std::vector<PBD::ID> lua_slots () const;
142 bool lua_slot_name (const PBD::ID&, std::string&) const;
143 std::vector<std::string> lua_slot_names () const;
144 bool lua_slot (const PBD::ID&, std::string&, std::string&, ActionHook&, ARDOUR::LuaScriptParamList&);
145 sigc::signal<void,PBD::ID,std::string,ActionHook> SlotChanged;
147 static PBD::Signal0<void> LuaTimerS; // deci-seconds (Timer every 1s)
148 static PBD::Signal0<void> LuaTimerDS; // deci-seconds (Timer every .1s)
149 static PBD::Signal0<void> SetSession; // emitted when a session is loaded
153 static LuaInstance* _instance;
157 void session_going_away ();
158 void pre_seed_scripts ();
162 luabridge::LuaRef * _lua_call_action;
163 luabridge::LuaRef * _lua_render_icon;
164 luabridge::LuaRef * _lua_add_action;
165 luabridge::LuaRef * _lua_del_action;
166 luabridge::LuaRef * _lua_get_action;
168 luabridge::LuaRef * _lua_load;
169 luabridge::LuaRef * _lua_save;
170 luabridge::LuaRef * _lua_clear;
172 LuaCallbackMap _callbacks;
173 PBD::ScopedConnectionList _slotcon;
175 void every_second ();
176 sigc::connection second_connection;
178 void every_point_one_seconds ();
179 sigc::connection point_one_second_connection;