libardour lua-script-manager
[ardour.git] / libs / ardour / ardour / luascripting.h
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 #ifndef _ardour_luascripting_h_
20 #define _ardour_luascripting_h_
21 #include <vector>
22
23 #include <boost/shared_ptr.hpp>
24 #include <glibmm/threads.h>
25
26 #include "ardour/libardour_visibility.h"
27
28 namespace ARDOUR {
29
30 class LIBARDOUR_API LuaScriptInfo {
31   public:
32
33         enum ScriptType {
34                 Invalid,
35                 DSP,
36                 Session,
37                 EditorHook,
38                 EditorAction,
39         };
40
41         static std::string type2str (const ScriptType t);
42         static ScriptType str2type (const std::string& str);
43
44         LuaScriptInfo (ScriptType t, const std::string &n, const std::string &p)
45         : type (t)
46         , name (n)
47         , path (p)
48         { }
49
50         virtual ~LuaScriptInfo () { }
51
52         ScriptType type;
53         std::string name;
54         std::string path;
55
56         std::string author;
57         std::string license;
58         std::string category;
59         std::string description;
60 };
61
62 struct LIBARDOUR_API LuaScriptParam {
63         public:
64                 LuaScriptParam (
65                                 const std::string& n,
66                                 const std::string& t,
67                                 const std::string& d,
68                                 bool o)
69                         : name (n)
70                         , title (t)
71                         , dflt (d)
72                         , optional (o)
73                         , is_set (false)
74                         , value (d)
75         {}
76
77                 std::string name;
78                 std::string title;
79                 std::string dflt;
80                 bool optional;
81                 bool is_set;
82                 std::string value;
83 };
84
85
86 typedef boost::shared_ptr<LuaScriptInfo> LuaScriptInfoPtr;
87 typedef std::vector<LuaScriptInfoPtr> LuaScriptList;
88
89 typedef boost::shared_ptr<LuaScriptParam> LuaScriptParamPtr;
90 typedef std::vector<LuaScriptParamPtr> LuaScriptParamList;
91
92
93 class LIBARDOUR_API LuaScripting {
94
95 public:
96         static LuaScripting& instance();
97
98         ~LuaScripting ();
99
100         LuaScriptList &scripts (LuaScriptInfo::ScriptType);
101
102         void refresh ();
103         static LuaScriptInfoPtr script_info (const std::string &script ) { return scan_script ("", script); }
104
105         static LuaScriptParamList script_params (LuaScriptInfoPtr, const std::string &);
106         static LuaScriptParamList session_script_params (LuaScriptInfoPtr lsi) {
107                 return script_params (lsi, "sess_params");
108         }
109
110         static bool try_compile (const std::string&, const LuaScriptParamList&);
111         static std::string get_factory_bytecode (const std::string&);
112
113 private:
114         static LuaScripting* _instance; // singleton
115         LuaScripting ();
116
117         void scan ();
118         void check_scan ();
119         static LuaScriptInfoPtr scan_script (const std::string &, const std::string & sc = "");
120         static void lua_print (std::string s);
121
122         LuaScriptList *_sl_dsp;
123         LuaScriptList *_sl_session;
124         LuaScriptList *_sl_hook;
125         LuaScriptList *_sl_action;
126         LuaScriptList  _empty_script_info;
127
128         Glib::Threads::Mutex _lock;
129 };
130
131 } // namespace ARDOUR
132
133 #endif // _ardour_luascripting_h_