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