variable plugin port config.
[ardour.git] / libs / ardour / ardour / luaproc.h
1 /*
2     Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3     Copyright (C) 2006 Paul Davis
4
5     This program is free software; you can redistribute it and/or modify it
6     under the terms of the GNU General Public License as published by the Free
7     Software Foundation; either version 2 of the License, or (at your option)
8     any later version.
9
10     This program is distributed in the hope that it will be useful, but WITHOUT
11     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13     for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __ardour_luaproc_h__
21 #define __ardour_luaproc_h__
22
23 #include <set>
24 #include <vector>
25 #include <string>
26
27 #include "pbd/reallocpool.h"
28 #include "pbd/stateful.h"
29
30 #include "ardour/types.h"
31 #include "ardour/plugin.h"
32 #include "ardour/luascripting.h"
33 #include "ardour/dsp_filter.h"
34
35 #include "lua/luastate.h"
36
37 namespace luabridge {
38         class LuaRef;
39 }
40
41 namespace ARDOUR {
42
43 class LIBARDOUR_API LuaProc : public ARDOUR::Plugin {
44 public:
45         LuaProc (AudioEngine&, Session&, const std::string&);
46         LuaProc (const LuaProc &);
47         ~LuaProc ();
48
49         /* Plugin interface */
50
51         std::string unique_id() const { return get_info()->unique_id; }
52         const char* name()  const { return get_info()->name.c_str(); }
53         const char* label() const { return get_info()->name.c_str(); }
54         const char* maker() const { return get_info()->creator.c_str(); }
55
56         uint32_t    parameter_count() const;
57         float       default_value (uint32_t port);
58         void        set_parameter (uint32_t port, float val);
59         float       get_parameter (uint32_t port) const;
60         int         get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
61         uint32_t    nth_parameter (uint32_t port, bool& ok) const;
62
63         std::string get_docs () const { return _docs; }
64         std::string get_parameter_docs (uint32_t) const;
65
66         PluginOutputConfiguration possible_output () const { return _output_configs; }
67
68         std::set<Evoral::Parameter> automatable() const;
69
70         void activate () { }
71         void deactivate () { }
72         void cleanup () { }
73
74         int set_block_size (pframes_t /*nframes*/) { return 0; }
75         framecnt_t  signal_latency() const { return 0; }
76
77         int connect_and_run (BufferSet& bufs,
78                         ChanMapping in, ChanMapping out,
79                         pframes_t nframes, framecnt_t offset);
80
81         std::string describe_parameter (Evoral::Parameter);
82         void        print_parameter (uint32_t, char*, uint32_t len) const;
83         boost::shared_ptr<ScalePoints> get_scale_points(uint32_t port_index) const;
84
85         bool parameter_is_audio (uint32_t) const { return false; }
86         bool parameter_is_control (uint32_t) const { return true; }
87         bool parameter_is_input (uint32_t) const;
88         bool parameter_is_output (uint32_t) const;
89
90         std::string state_node_name() const { return "luaproc"; }
91         void add_state (XMLNode *) const;
92         int set_state (const XMLNode&, int version);
93         int set_script_from_state (const XMLNode&);
94
95         bool load_preset (PresetRecord) { return false; }
96         bool has_editor() const { return false; }
97
98         bool can_support_io_configuration (const ChanCount& in, ChanCount& out, ChanCount* imprecise);
99         bool configure_io (ChanCount in, ChanCount out);
100
101         ChanCount output_streams() const { return _configured_out; }
102         ChanCount input_streams() const { return _configured_in; }
103
104         std::string do_save_preset (std::string) { return ""; }
105         void do_remove_preset (std::string) { }
106
107         bool has_inline_display () { return _lua_has_inline_display; }
108         void setup_lua_inline_gui (LuaState *lua_gui);
109
110 private:
111         void find_presets () { }
112
113         /* END Plugin interface */
114 protected:
115         const std::string& script() const { return _script; }
116
117 private:
118         PBD::ReallocPool _mempool;
119         LuaState lua;
120         luabridge::LuaRef * _lua_dsp;
121         std::string _script;
122         std::string _docs;
123         bool _lua_does_channelmapping;
124         bool _lua_has_inline_display;
125
126         void queue_draw () { QueueDraw(); /* EMIT SIGNAL */ }
127         DSP::DspShm* instance_shm () { return &lshm; }
128         DSP::DspShm lshm;
129
130         void init ();
131         bool load_script ();
132         void lua_print (std::string s);
133
134         boost::shared_ptr<ScalePoints> parse_scale_points (luabridge::LuaRef*);
135
136         std::vector<std::pair<bool, int> > _ctrl_params;
137         std::map<int, ARDOUR::ParameterDescriptor> _param_desc;
138         std::map<int, std::string> _param_doc;
139
140         float* _control_data;
141         float* _shadow_data;
142
143         ChanCount _configured_in;
144         ChanCount _configured_out;
145         PluginOutputConfiguration _output_configs;
146
147         bool _has_midi_input;
148         bool _has_midi_output;
149
150 #ifdef WITH_LUAPROC_STATS
151         int64_t _stats_avg[2];
152         int64_t _stats_max[2];
153         int64_t _stats_cnt;
154 #endif
155 };
156
157 class LIBARDOUR_API LuaPluginInfo : public PluginInfo
158 {
159   public:
160         LuaPluginInfo (LuaScriptInfoPtr lsi);
161         ~LuaPluginInfo () { };
162
163         PluginPtr load (Session& session);
164         std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
165
166         bool is_instrument () const { return _is_instrument ; }
167         bool reconfigurable_io() const { return true; }
168
169         bool _is_instrument;
170 };
171
172 typedef boost::shared_ptr<LuaPluginInfo> LuaPluginInfoPtr;
173
174 } // namespace ARDOUR
175
176 #endif // __ardour_luaproc_h__