2019-08-02 17:26:43 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2016-02-21 16:08:36 -05:00
|
|
|
#ifndef __gtkardour_luainstance_h__
|
|
|
|
#define __gtkardour_luainstance_h__
|
|
|
|
|
|
|
|
#include <bitset>
|
|
|
|
|
2017-02-17 12:56:18 -05:00
|
|
|
#include <cairo.h>
|
|
|
|
|
2016-02-21 16:08:36 -05:00
|
|
|
#include "pbd/id.h"
|
|
|
|
#include "pbd/signals.h"
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
|
|
|
#include "ardour/luascripting.h"
|
2016-03-23 08:49:25 -04:00
|
|
|
#include "ardour/lua_script_params.h"
|
2016-02-21 16:08:36 -05:00
|
|
|
#include "ardour/luabindings.h"
|
|
|
|
#include "ardour/session_handle.h"
|
|
|
|
|
|
|
|
#include "lua/luastate.h"
|
|
|
|
|
|
|
|
#include "luasignal.h"
|
|
|
|
|
2016-03-28 13:14:56 -04:00
|
|
|
namespace luabridge {
|
|
|
|
class LuaRef;
|
|
|
|
}
|
|
|
|
|
2016-02-21 16:08:36 -05:00
|
|
|
typedef std::bitset<LuaSignal::LAST_SIGNAL> ActionHook;
|
|
|
|
|
|
|
|
class LuaCallback : public ARDOUR::SessionHandlePtr, public sigc::trackable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LuaCallback (ARDOUR::Session*, const std::string&, const std::string&, const ActionHook&, const ARDOUR::LuaScriptParamList&);
|
|
|
|
LuaCallback (ARDOUR::Session*, XMLNode & node);
|
|
|
|
~LuaCallback ();
|
|
|
|
|
|
|
|
XMLNode& get_state (void);
|
|
|
|
void set_session (ARDOUR::Session *);
|
|
|
|
|
|
|
|
const PBD::ID& id () const { return _id; }
|
|
|
|
const std::string& name () const { return _name; }
|
|
|
|
ActionHook signals () const { return _signals; }
|
|
|
|
bool lua_slot (std::string&, std::string&, ActionHook&, ARDOUR::LuaScriptParamList&);
|
|
|
|
PBD::Signal0<void> drop_callback;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void session_going_away ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
LuaState lua;
|
|
|
|
|
|
|
|
PBD::ID _id;
|
|
|
|
std::string _name;
|
|
|
|
ActionHook _signals;
|
|
|
|
|
|
|
|
void reconnect ();
|
|
|
|
template <class T> void reconnect_object (T);
|
|
|
|
void init ();
|
|
|
|
|
|
|
|
luabridge::LuaRef * _lua_add;
|
|
|
|
luabridge::LuaRef * _lua_get;
|
|
|
|
luabridge::LuaRef * _lua_call;
|
|
|
|
luabridge::LuaRef * _lua_save;
|
|
|
|
luabridge::LuaRef * _lua_load;
|
|
|
|
|
|
|
|
PBD::ScopedConnectionList _connections;
|
|
|
|
|
|
|
|
template <typename T, typename S> void connect_0 (enum LuaSignal::LuaSignal, T, S*);
|
|
|
|
template <typename T> void proxy_0 (enum LuaSignal::LuaSignal, T);
|
|
|
|
|
|
|
|
template <typename T, typename C1> void connect_1 (enum LuaSignal::LuaSignal, T, PBD::Signal1<void, C1>*);
|
|
|
|
template <typename T, typename C1> void proxy_1 (enum LuaSignal::LuaSignal, T, C1);
|
|
|
|
|
|
|
|
template <typename T, typename C1, typename C2> void connect_2 (enum LuaSignal::LuaSignal, T, PBD::Signal2<void, C1, C2>*);
|
|
|
|
template <typename T, typename C1, typename C2> void proxy_2 (enum LuaSignal::LuaSignal, T, C1, C2);
|
2018-01-29 16:21:59 -05:00
|
|
|
|
|
|
|
template <typename T, typename C1, typename C2, typename C3> void connect_3 (enum LuaSignal::LuaSignal, T, PBD::Signal3<void, C1, C2, C3>*);
|
|
|
|
template <typename T, typename C1, typename C2, typename C3> void proxy_3 (enum LuaSignal::LuaSignal, T, C1, C2, C3);
|
2016-02-21 16:08:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef boost::shared_ptr<LuaCallback> LuaCallbackPtr;
|
|
|
|
typedef std::map<PBD::ID, LuaCallbackPtr> LuaCallbackMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LuaInstance : public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static LuaInstance* instance();
|
2017-01-20 05:48:59 -05:00
|
|
|
static void destroy_instance();
|
2016-02-21 16:08:36 -05:00
|
|
|
~LuaInstance();
|
|
|
|
|
|
|
|
static void register_classes (lua_State* L);
|
|
|
|
static void register_hooks (lua_State* L);
|
2016-03-17 10:53:19 -04:00
|
|
|
static void bind_cairo (lua_State* L);
|
2017-04-24 16:12:09 -04:00
|
|
|
static void bind_dialog (lua_State* L);
|
2016-02-21 16:08:36 -05:00
|
|
|
|
2017-02-17 12:56:18 -05:00
|
|
|
static void render_action_icon (cairo_t* cr, int w, int h, uint32_t c, void* i);
|
|
|
|
|
2016-02-21 16:08:36 -05:00
|
|
|
void set_session (ARDOUR::Session* s);
|
|
|
|
|
|
|
|
int set_state (const XMLNode&);
|
|
|
|
XMLNode& get_action_state (void);
|
|
|
|
XMLNode& get_hook_state (void);
|
|
|
|
|
2018-11-04 12:46:21 -05:00
|
|
|
int load_state ();
|
|
|
|
int save_state ();
|
|
|
|
|
2016-02-21 16:08:36 -05:00
|
|
|
bool interactive_add (ARDOUR::LuaScriptInfo::ScriptType, int);
|
|
|
|
|
|
|
|
/* actions */
|
|
|
|
void call_action (const int);
|
2017-02-17 12:56:18 -05:00
|
|
|
void render_icon (int i, cairo_t*, int, int, uint32_t);
|
2016-02-21 16:08:36 -05:00
|
|
|
|
|
|
|
bool set_lua_action (const int, const std::string&, const std::string&, const ARDOUR::LuaScriptParamList&);
|
|
|
|
bool remove_lua_action (const int);
|
|
|
|
bool lua_action_name (const int, std::string&);
|
|
|
|
std::vector<std::string> lua_action_names ();
|
|
|
|
bool lua_action (const int, std::string&, std::string&, ARDOUR::LuaScriptParamList&);
|
2017-02-17 12:56:18 -05:00
|
|
|
bool lua_action_has_icon (const int);
|
2016-02-21 16:08:36 -05:00
|
|
|
sigc::signal<void,int,std::string> ActionChanged;
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
bool register_lua_slot (const std::string&, const std::string&, const ARDOUR::LuaScriptParamList&);
|
|
|
|
bool unregister_lua_slot (const PBD::ID&);
|
|
|
|
std::vector<PBD::ID> lua_slots () const;
|
|
|
|
bool lua_slot_name (const PBD::ID&, std::string&) const;
|
|
|
|
std::vector<std::string> lua_slot_names () const;
|
|
|
|
bool lua_slot (const PBD::ID&, std::string&, std::string&, ActionHook&, ARDOUR::LuaScriptParamList&);
|
|
|
|
sigc::signal<void,PBD::ID,std::string,ActionHook> SlotChanged;
|
|
|
|
|
2018-11-16 18:12:10 -05:00
|
|
|
static PBD::Signal0<void> LuaTimerS; // deci-seconds (Timer every 1s)
|
2016-07-22 08:42:38 -04:00
|
|
|
static PBD::Signal0<void> LuaTimerDS; // deci-seconds (Timer every .1s)
|
2017-08-09 08:09:27 -04:00
|
|
|
static PBD::Signal0<void> SetSession; // emitted when a session is loaded
|
2016-07-22 08:42:38 -04:00
|
|
|
|
2016-02-21 16:08:36 -05:00
|
|
|
private:
|
|
|
|
LuaInstance();
|
|
|
|
static LuaInstance* _instance;
|
|
|
|
|
|
|
|
void init ();
|
2018-11-04 12:46:21 -05:00
|
|
|
void set_dirty ();
|
2016-02-21 16:08:36 -05:00
|
|
|
void session_going_away ();
|
|
|
|
|
|
|
|
LuaState lua;
|
|
|
|
|
|
|
|
luabridge::LuaRef * _lua_call_action;
|
2017-02-17 12:56:18 -05:00
|
|
|
luabridge::LuaRef * _lua_render_icon;
|
2016-02-21 16:08:36 -05:00
|
|
|
luabridge::LuaRef * _lua_add_action;
|
|
|
|
luabridge::LuaRef * _lua_del_action;
|
|
|
|
luabridge::LuaRef * _lua_get_action;
|
|
|
|
|
|
|
|
luabridge::LuaRef * _lua_load;
|
|
|
|
luabridge::LuaRef * _lua_save;
|
|
|
|
luabridge::LuaRef * _lua_clear;
|
|
|
|
|
|
|
|
LuaCallbackMap _callbacks;
|
|
|
|
PBD::ScopedConnectionList _slotcon;
|
2016-07-22 08:42:38 -04:00
|
|
|
|
2018-11-16 18:12:10 -05:00
|
|
|
void every_second ();
|
|
|
|
sigc::connection second_connection;
|
|
|
|
|
2016-07-22 08:42:38 -04:00
|
|
|
void every_point_one_seconds ();
|
|
|
|
sigc::connection point_one_second_connection;
|
2016-02-21 16:08:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|