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