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