Track Templates: initial lua backend support.
[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                 SessionSetup,
42                 TrackSetup,
43         };
44
45         static std::string type2str (const ScriptType t);
46         static ScriptType str2type (const std::string& str);
47
48         LuaScriptInfo (ScriptType t, const std::string &n, const std::string &p, const std::string &uid)
49         : type (t)
50         , name (n)
51         , path (p)
52         , unique_id (uid)
53         { }
54
55         virtual ~LuaScriptInfo () { }
56
57         ScriptType type;
58         std::string name;
59         std::string path;
60         std::string unique_id;
61
62         std::string author;
63         std::string license;
64         std::string category;
65         std::string description;
66 };
67
68 struct LIBARDOUR_API LuaScriptParam {
69         public:
70                 LuaScriptParam (
71                                 const std::string& n,
72                                 const std::string& t,
73                                 const std::string& d,
74                                 bool o)
75                         : name (n)
76                         , title (t)
77                         , dflt (d)
78                         , optional (o)
79                         , is_set (false)
80                         , value (d)
81         {}
82
83                 std::string name;
84                 std::string title;
85                 std::string dflt;
86                 bool optional;
87                 bool is_set;
88                 std::string value;
89 };
90
91
92 typedef boost::shared_ptr<LuaScriptInfo> LuaScriptInfoPtr;
93 typedef std::vector<LuaScriptInfoPtr> LuaScriptList;
94
95 typedef boost::shared_ptr<LuaScriptParam> LuaScriptParamPtr;
96 typedef std::vector<LuaScriptParamPtr> LuaScriptParamList;
97
98
99 class LIBARDOUR_API LuaScripting {
100
101 public:
102         static LuaScripting& instance();
103
104         ~LuaScripting ();
105
106         LuaScriptList &scripts (LuaScriptInfo::ScriptType);
107         void refresh (bool run_scan = false);
108         PBD::Signal0<void> scripts_changed;
109
110         static LuaScriptInfoPtr script_info (const std::string &script);
111         static bool try_compile (const std::string&, const LuaScriptParamList&);
112         static std::string get_factory_bytecode (const std::string&, const std::string& ffn = "factory", const std::string& fp = "f");
113         static std::string user_script_dir ();
114
115 private:
116         static LuaScripting* _instance; // singleton
117         LuaScripting ();
118
119         void scan ();
120         static LuaScriptInfoPtr scan_script (const std::string &, const std::string & sc = "");
121         static void lua_print (std::string s);
122
123         LuaScriptList *_sl_dsp;
124         LuaScriptList *_sl_session;
125         LuaScriptList *_sl_hook;
126         LuaScriptList *_sl_action;
127         LuaScriptList *_sl_snippet;
128         LuaScriptList *_sl_setup;
129         LuaScriptList *_sl_tracks;
130         LuaScriptList  _empty_script_info;
131
132         Glib::Threads::Mutex _lock;
133 };
134
135 } // namespace ARDOUR
136
137 #endif // _ardour_luascripting_h_