No more disk-reader roll-delay
[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)
84                         : name (n)
85                         , title (t)
86                         , dflt (d)
87                         , optional (o)
88                         , is_set (false)
89                         , value (d)
90         {}
91
92                 std::string name;
93                 std::string title;
94                 std::string dflt;
95                 bool optional;
96                 bool is_set;
97                 std::string value;
98 };
99
100
101 typedef boost::shared_ptr<LuaScriptInfo> LuaScriptInfoPtr;
102 typedef std::vector<LuaScriptInfoPtr> LuaScriptList;
103
104 typedef boost::shared_ptr<LuaScriptParam> LuaScriptParamPtr;
105 typedef std::vector<LuaScriptParamPtr> LuaScriptParamList;
106
107
108 class LIBARDOUR_API LuaScripting {
109
110 public:
111         static LuaScripting& instance();
112
113         ~LuaScripting ();
114
115         LuaScriptList &scripts (LuaScriptInfo::ScriptType);
116         void refresh (bool run_scan = false);
117         PBD::Signal0<void> scripts_changed;
118
119         static LuaScriptInfoPtr script_info (const std::string &script);
120         static bool try_compile (const std::string&, const LuaScriptParamList&);
121         static std::string get_factory_bytecode (const std::string&, const std::string& ffn = "factory", const std::string& fp = "f");
122         static std::string user_script_dir ();
123
124 private:
125         static LuaScripting* _instance; // singleton
126         LuaScripting ();
127
128         void scan ();
129         static LuaScriptInfoPtr scan_script (const std::string &, const std::string & sc = "");
130         static void lua_print (std::string s);
131
132         LuaScriptList *_sl_dsp;
133         LuaScriptList *_sl_session;
134         LuaScriptList *_sl_hook;
135         LuaScriptList *_sl_action;
136         LuaScriptList *_sl_snippet;
137         LuaScriptList *_sl_setup;
138         LuaScriptList *_sl_tracks;
139         LuaScriptList  _empty_script_info;
140
141         Glib::Threads::Mutex _lock;
142 };
143
144 } // namespace ARDOUR
145
146 #endif // _ardour_luascripting_h_