Ardour  9.0-pre0-386-g96ef4d20f2
luainstance.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
3  *
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.
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 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.
17  */
18 
19 #pragma once
20 
21 #include <bitset>
22 
23 #include <cairo.h>
24 
25 #include "pbd/id.h"
26 #include "pbd/signals.h"
27 #include "pbd/xml++.h"
28 
29 #include "ardour/luascripting.h"
31 #include "ardour/luabindings.h"
32 #include "ardour/session_handle.h"
33 
34 #include "lua/luastate.h"
35 
36 #include "luasignal.h"
37 
38 namespace luabridge {
39  class LuaRef;
40 }
41 
42 namespace Gtk {
43  class Window;
44 }
45 
46 typedef std::bitset<LuaSignal::LAST_SIGNAL> ActionHook;
47 
48 class LuaCallback : public ARDOUR::SessionHandlePtr, public sigc::trackable
49 {
50 public:
51  LuaCallback (ARDOUR::Session*, const std::string&, const std::string&, const ActionHook&, const ARDOUR::LuaScriptParamList&);
54 
55  XMLNode& get_state () const;
57 
58  const PBD::ID& id () const { return _id; }
59  const std::string& name () const { return _name; }
60  ActionHook signals () const { return _signals; }
61  bool lua_slot (std::string&, std::string&, ActionHook&, ARDOUR::LuaScriptParamList&);
63 
64 protected:
66 
67 private:
69 
71  std::string _name;
73 
74  void reconnect ();
75  template <class T> void reconnect_object (T);
76  void init ();
77 
78  luabridge::LuaRef * _lua_add;
79  luabridge::LuaRef * _lua_get;
80  luabridge::LuaRef * _lua_call;
81  luabridge::LuaRef * _lua_save;
82  luabridge::LuaRef * _lua_load;
83 
85 
86  template <typename T, typename... C> void connect (enum LuaSignal::LuaSignal, T, PBD::Signal<void(C...)>*);
87  template <typename T, typename... C> void proxy (enum LuaSignal::LuaSignal, T, C...);
88 };
89 
90 typedef std::shared_ptr<LuaCallback> LuaCallbackPtr;
91 typedef std::map<PBD::ID, LuaCallbackPtr> LuaCallbackMap;
92 
93 
94 
96 {
97 public:
98  static LuaInstance* instance();
99  static void destroy_instance();
101 
102  static void register_classes (lua_State* L, bool sandbox);
103  static void register_hooks (lua_State* L);
104  static void bind_cairo (lua_State* L);
105  static void bind_dialog (lua_State* L);
106 
107  static void render_action_icon (cairo_t* cr, int w, int h, uint32_t c, void* i);
108 
110 
111  int set_state (const XMLNode&);
114 
115  int load_state ();
116  int save_state ();
117 
119 
120  /* actions */
121  void call_action (const int);
122  void render_icon (int i, cairo_t*, int, int, uint32_t);
123 
124  bool set_lua_action (const int, const std::string&, const std::string&, const ARDOUR::LuaScriptParamList&);
125  bool remove_lua_action (const int);
126  bool lua_action_name (const int, std::string&);
127  std::vector<std::string> lua_action_names ();
128  bool lua_action (const int, std::string&, std::string&, ARDOUR::LuaScriptParamList&);
129  bool lua_action_has_icon (const int);
130  sigc::signal<void,int,std::string> ActionChanged;
131 
132  /* callbacks */
133  bool register_lua_slot (const std::string&, const std::string&, const ARDOUR::LuaScriptParamList&);
135  std::vector<PBD::ID> lua_slots () const;
136  bool lua_slot_name (const PBD::ID&, std::string&) const;
137  std::vector<std::string> lua_slot_names () const;
138  bool lua_slot (const PBD::ID&, std::string&, std::string&, ActionHook&, ARDOUR::LuaScriptParamList&);
139  sigc::signal<void,PBD::ID,std::string,ActionHook> SlotChanged;
140 
141  static PBD::Signal<void()> LuaTimerS; // deci-seconds (Timer every 1s)
142  static PBD::Signal<void()> LuaTimerDS; // deci-seconds (Timer every .1s)
143  static PBD::Signal<void()> SetSession; // emitted when a session is loaded
144  static PBD::Signal<void()> SelectionChanged; // emitted when editor selection changes
145 
146 private:
149 
150  void init ();
151  void set_dirty ();
154  void pre_seed_script (std::string const&, int&);
155 
157 
158  luabridge::LuaRef * _lua_call_action;
159  luabridge::LuaRef * _lua_render_icon;
160  luabridge::LuaRef * _lua_add_action;
161  luabridge::LuaRef * _lua_del_action;
162  luabridge::LuaRef * _lua_get_action;
163 
164  luabridge::LuaRef * _lua_load;
165  luabridge::LuaRef * _lua_save;
166  luabridge::LuaRef * _lua_clear;
167 
170 
172 
173  void every_second ();
174  sigc::connection second_connection;
175 
177  sigc::connection point_one_second_connection;
178 
179 };
180 
PBD::ScopedConnectionList _connections
Definition: luainstance.h:84
bool lua_slot(std::string &, std::string &, ActionHook &, ARDOUR::LuaScriptParamList &)
XMLNode & get_state() const
LuaCallback(ARDOUR::Session *, const std::string &, const std::string &, const ActionHook &, const ARDOUR::LuaScriptParamList &)
void reconnect()
void connect(enum LuaSignal::LuaSignal, T, PBD::Signal< void(C...)> *)
ActionHook signals() const
Definition: luainstance.h:60
const std::string & name() const
Definition: luainstance.h:59
PBD::ID _id
Definition: luainstance.h:70
PBD::Signal< void()> drop_callback
Definition: luainstance.h:62
LuaCallback(ARDOUR::Session *, XMLNode &node)
LuaState lua
Definition: luainstance.h:68
void reconnect_object(T)
std::string _name
Definition: luainstance.h:71
void proxy(enum LuaSignal::LuaSignal, T, C...)
luabridge::LuaRef * _lua_get
Definition: luainstance.h:79
luabridge::LuaRef * _lua_call
Definition: luainstance.h:80
const PBD::ID & id() const
Definition: luainstance.h:58
luabridge::LuaRef * _lua_load
Definition: luainstance.h:82
void set_session(ARDOUR::Session *)
ActionHook _signals
Definition: luainstance.h:72
luabridge::LuaRef * _lua_add
Definition: luainstance.h:78
void session_going_away()
luabridge::LuaRef * _lua_save
Definition: luainstance.h:81
std::vector< PBD::ID > lua_slots() const
int set_state(const XMLNode &)
void set_dirty()
void render_icon(int i, cairo_t *, int, int, uint32_t)
PBD::ScopedConnectionList _slotcon
Definition: luainstance.h:169
bool lua_slot(const PBD::ID &, std::string &, std::string &, ActionHook &, ARDOUR::LuaScriptParamList &)
static void render_action_icon(cairo_t *cr, int w, int h, uint32_t c, void *i)
void pre_seed_scripts()
luabridge::LuaRef * _lua_render_icon
Definition: luainstance.h:159
static PBD::Signal< void()> SetSession
Definition: luainstance.h:143
std::vector< std::string > lua_action_names()
static LuaInstance * _instance
Definition: luainstance.h:148
luabridge::LuaRef * _lua_call_action
Definition: luainstance.h:158
bool lua_slot_name(const PBD::ID &, std::string &) const
static PBD::Signal< void()> SelectionChanged
Definition: luainstance.h:144
std::vector< std::string > lua_slot_names() const
luabridge::LuaRef * _lua_get_action
Definition: luainstance.h:162
bool interactive_add(Gtk::Window &, ARDOUR::LuaScriptInfo::ScriptType, int)
sigc::connection second_connection
Definition: luainstance.h:174
luabridge::LuaRef * _lua_load
Definition: luainstance.h:164
int save_state()
static void register_classes(lua_State *L, bool sandbox)
static void bind_dialog(lua_State *L)
static void bind_cairo(lua_State *L)
XMLNode & get_hook_state(void)
bool lua_action(const int, std::string &, std::string &, ARDOUR::LuaScriptParamList &)
static void register_hooks(lua_State *L)
static void destroy_instance()
void call_action(const int)
bool set_lua_action(const int, const std::string &, const std::string &, const ARDOUR::LuaScriptParamList &)
void pre_seed_script(std::string const &, int &)
bool lua_action_name(const int, std::string &)
bool unregister_lua_slot(const PBD::ID &)
LuaCallbackMap _callbacks
Definition: luainstance.h:168
luabridge::LuaRef * _lua_add_action
Definition: luainstance.h:160
void every_second()
void set_session(ARDOUR::Session *s)
luabridge::LuaRef * _lua_clear
Definition: luainstance.h:166
bool register_lua_slot(const std::string &, const std::string &, const ARDOUR::LuaScriptParamList &)
luabridge::LuaRef * _lua_del_action
Definition: luainstance.h:161
bool lua_action_has_icon(const int)
sigc::signal< void, PBD::ID, std::string, ActionHook > SlotChanged
Definition: luainstance.h:139
static PBD::Signal< void()> LuaTimerDS
Definition: luainstance.h:142
LuaState lua
Definition: luainstance.h:156
void session_going_away()
static LuaInstance * instance()
bool remove_lua_action(const int)
void every_point_one_seconds()
static PBD::Signal< void()> LuaTimerS
Definition: luainstance.h:141
void selection_changed()
sigc::signal< void, int, std::string > ActionChanged
Definition: luainstance.h:130
sigc::connection point_one_second_connection
Definition: luainstance.h:177
luabridge::LuaRef * _lua_save
Definition: luainstance.h:165
int load_state()
XMLNode & get_action_state(void)
Definition: LuaRef.h:52
Definition: id.h:34
Definition: Window.h:41
Definition: xml++.h:114
std::shared_ptr< LuaCallback > LuaCallbackPtr
Definition: luainstance.h:90
std::map< PBD::ID, LuaCallbackPtr > LuaCallbackMap
Definition: luainstance.h:91
std::bitset< LuaSignal::LAST_SIGNAL > ActionHook
Definition: luainstance.h:46
std::vector< LuaScriptParamPtr > LuaScriptParamList
Definition: luascripting.h:107
Definition: ardour_ui.h:187