Ardour  8.12
luaproc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 /* print runtime and garbage-collection timing statistics */
20 //#define WITH_LUAPROC_STATS
21 
22 /* memory allocation system, default: ReallocPool */
23 //#define USE_TLSF // use TLSF instead of ReallocPool
24 //#define USE_MALLOC // or plain OS provided realloc (no mlock) -- if USE_TLSF isn't defined
25 
26 #ifndef __ardour_luaproc_h__
27 #define __ardour_luaproc_h__
28 
29 #include <set>
30 #include <vector>
31 #include <string>
32 
33 #ifdef USE_TLSF
34 # include "pbd/tlsf.h"
35 #else
36 # include "pbd/reallocpool.h"
37 #endif
38 
39 #include "pbd/stateful.h"
40 
41 #include "ardour/types.h"
42 #include "ardour/plugin.h"
43 #include "ardour/luascripting.h"
44 #include "ardour/dsp_filter.h"
45 #include "ardour/lua_api.h"
46 
47 #include "lua/luastate.h"
48 
49 namespace luabridge {
50  class LuaRef;
51 }
52 
53 namespace ARDOUR {
54 
56 public:
57  LuaProc (AudioEngine&, Session&, const std::string&);
58  LuaProc (const LuaProc &);
60 
61  /* Plugin interface */
62 
63  std::string unique_id() const { return get_info()->unique_id; }
64  const char* name() const { return get_info()->name.c_str(); }
65  const char* label() const { return get_info()->name.c_str(); }
66  const char* maker() const { return get_info()->creator.c_str(); }
67 
68  uint32_t parameter_count() const;
69  float default_value (uint32_t port);
70  void set_parameter (uint32_t port, float val, sampleoffset_t);
71  float get_parameter (uint32_t port) const;
72  int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
73  uint32_t nth_parameter (uint32_t port, bool& ok) const;
74 
75  std::string get_docs () const { return _docs; }
76  std::string get_parameter_docs (uint32_t) const;
77 
78  PluginOutputConfiguration possible_output () const { return _output_configs; }
79 
80  void drop_references ();
81 
82  std::set<Evoral::Parameter> automatable() const;
83 
84  void activate () { }
85  void deactivate () { }
86  void cleanup () { }
87 
88  int set_block_size (pframes_t /*nframes*/) { return 0; }
89  bool requires_fixed_sized_buffers () const { return _requires_fixed_sized_buffers; }
90  bool connect_all_audio_outputs () const { return _connect_all_audio_outputs; }
91 
93  samplepos_t start, samplepos_t end, double speed,
94  ChanMapping const& in, ChanMapping const& out,
95  pframes_t nframes, samplecnt_t offset);
96 
98  std::shared_ptr<ScalePoints> get_scale_points(uint32_t port_index) const;
99 
100  bool parameter_is_audio (uint32_t) const { return false; }
101  bool parameter_is_control (uint32_t) const { return true; }
102  bool parameter_is_input (uint32_t) const;
103  bool parameter_is_output (uint32_t) const;
104 
106  return _designated_bypass_port;
107  }
108 
109  std::string state_node_name() const { return "luaproc"; }
110  void add_state (XMLNode *) const;
111  int set_state (const XMLNode&, int version);
113 
115  std::string do_save_preset (std::string);
116  void do_remove_preset (std::string);
117 
118  bool has_editor() const { return false; }
119 
120  bool match_variable_io (ChanCount& in, ChanCount& aux_in, ChanCount& out);
121  bool reconfigure_io (ChanCount in, ChanCount aux_in, ChanCount out);
122 
123  ChanCount output_streams() const { return _configured_out; }
124  ChanCount input_streams() const { return _configured_in; }
125 
126  bool has_inline_display () { return _lua_has_inline_display; }
128 
129  DSP::DspShm* instance_shm () { return &lshm; }
130  LuaTableRef* instance_ref () { return &lref; }
131 
132  struct FactoryPreset {
133  std::string name;
134  std::map<uint32_t, float> param;
135  };
136 
137  std::map<std::string, FactoryPreset> _factory_presets;
138 
139 private:
140  samplecnt_t plugin_latency() const { return _signal_latency; }
141  void find_presets ();
142 
143  /* END Plugin interface */
144 
145 public:
146  void set_origin (std::string& path) { _origin = path; }
147 
148 protected:
149  const std::string& script() const { return _script; }
150  const std::string& origin() const { return _origin; }
151 
152 private:
153 #ifdef USE_TLSF
154  PBD::TLSF _mempool;
155 #else
157 #endif
159  luabridge::LuaRef * _lua_dsp;
160  luabridge::LuaRef * _lua_latency;
161  std::string _script;
162  std::string _origin;
163  std::string _docs;
169 
170  void queue_draw () { QueueDraw(); /* EMIT SIGNAL */ }
172 
174 
175  std::weak_ptr<Route> route () const;
176 
177  void init ();
178  bool load_script ();
179  void lua_print (std::string s);
180 
183 
184  std::string preset_name_to_uri (const std::string&) const;
185  std::string presets_file () const;
187 
188  std::shared_ptr<ScalePoints> parse_scale_points (luabridge::LuaRef*);
189 
190  std::vector<std::pair<bool, int> > _ctrl_params;
191  std::map<int, ARDOUR::ParameterDescriptor> _param_desc;
192  std::map<int, std::string> _param_doc;
194 
196 
198  float* _shadow_data;
199 
202 
204 
207 
209 
212 
213 
214 #ifdef WITH_LUAPROC_STATS
215  int64_t _stats_avg[2];
216  int64_t _stats_max[2];
217  int64_t _stats_cnt;
218 #endif
219 };
220 
222 {
223  public:
226 
228  std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
229 
230  bool reconfigurable_io() const { return true; }
231  uint32_t max_configurable_outputs () const {
232  return _max_outputs;
233  }
234 
235  void set_factory_presets (std::vector<Plugin::PresetRecord> const& p) {
236  _factory_presets = p;
237  }
238 
239  private:
240  uint32_t _max_outputs;
241 
242  std::vector<Plugin::PresetRecord> _factory_presets;
243 };
244 
245 typedef std::shared_ptr<LuaPluginInfo> LuaPluginInfoPtr;
246 
247 } // namespace ARDOUR
248 
249 #endif // __ardour_luaproc_h__
void set_factory_presets(std::vector< Plugin::PresetRecord > const &p)
Definition: luaproc.h:235
std::vector< Plugin::PresetRecord > get_presets(bool user_only) const
bool reconfigurable_io() const
Definition: luaproc.h:230
uint32_t _max_outputs
Definition: luaproc.h:240
uint32_t max_configurable_outputs() const
Definition: luaproc.h:231
LuaPluginInfo(LuaScriptInfoPtr lsi)
std::vector< Plugin::PresetRecord > _factory_presets
Definition: luaproc.h:242
PluginPtr load(Session &session)
bool load_user_preset(PresetRecord const &)
float * _shadow_data
Definition: luaproc.h:198
void add_state(XMLNode *) const
void activate()
Definition: luaproc.h:84
std::vector< std::pair< bool, int > > _ctrl_params
Definition: luaproc.h:190
bool _has_midi_input
Definition: luaproc.h:210
bool parameter_is_audio(uint32_t) const
Definition: luaproc.h:100
void do_remove_preset(std::string)
ChanCount _configured_out
Definition: luaproc.h:201
int connect_and_run(BufferSet &bufs, samplepos_t start, samplepos_t end, double speed, ChanMapping const &in, ChanMapping const &out, pframes_t nframes, samplecnt_t offset)
void set_parameter(uint32_t port, float val, sampleoffset_t)
void set_origin(std::string &path)
Definition: luaproc.h:146
std::map< int, ARDOUR::ParameterDescriptor > _param_desc
Definition: luaproc.h:191
bool connect_all_audio_outputs() const
Definition: luaproc.h:90
PBD::ReallocPool _mempool
Definition: luaproc.h:156
std::shared_ptr< ScalePoints > parse_scale_points(luabridge::LuaRef *)
int set_script_from_state(const XMLNode &)
std::string preset_name_to_uri(const std::string &) const
const char * label() const
Definition: luaproc.h:65
int set_state(const XMLNode &, int version)
std::string get_parameter_docs(uint32_t) const
bool has_inline_display()
Definition: luaproc.h:126
samplecnt_t _signal_latency
Definition: luaproc.h:195
bool parameter_is_input(uint32_t) const
uint32_t nth_parameter(uint32_t port, bool &ok) const
void lua_print(std::string s)
bool parameter_is_output(uint32_t) const
LuaState lua
Definition: luaproc.h:158
samplecnt_t plugin_latency() const
Definition: luaproc.h:140
luabridge::LuaRef * _lua_latency
Definition: luaproc.h:160
void cleanup()
Definition: luaproc.h:86
bool parameter_is_control(uint32_t) const
Definition: luaproc.h:101
std::map< std::string, FactoryPreset > _factory_presets
Definition: luaproc.h:137
void deactivate()
Definition: luaproc.h:85
bool _set_time_info
Definition: luaproc.h:168
bool _has_midi_output
Definition: luaproc.h:211
DSP::DspShm lshm
Definition: luaproc.h:171
bool match_variable_io(ChanCount &in, ChanCount &aux_in, ChanCount &out)
bool load_preset(PresetRecord)
uint32_t _designated_bypass_port
Definition: luaproc.h:193
bool _connect_all_audio_outputs
Definition: luaproc.h:167
luabridge::LuaRef * _lua_dsp
Definition: luaproc.h:159
std::string unique_id() const
Definition: luaproc.h:63
void setup_lua_inline_gui(LuaState *lua_gui)
std::set< Evoral::Parameter > automatable() const
PluginOutputConfiguration possible_output() const
Definition: luaproc.h:78
bool has_editor() const
Definition: luaproc.h:118
PluginOutputConfiguration _output_configs
Definition: luaproc.h:208
XMLTree * presets_tree() const
ChanCount input_streams() const
Definition: luaproc.h:124
bool _lua_does_channelmapping
Definition: luaproc.h:164
std::string do_save_preset(std::string)
std::string _origin
Definition: luaproc.h:162
ChanCount _selected_out
Definition: luaproc.h:206
void drop_references()
const std::string & script() const
Definition: luaproc.h:149
std::weak_ptr< Route > route() const
ChanCount _selected_in
Definition: luaproc.h:205
std::string _script
Definition: luaproc.h:161
std::map< int, std::string > _param_doc
Definition: luaproc.h:192
void queue_draw()
Definition: luaproc.h:170
bool _configured
Definition: luaproc.h:203
uint32_t designated_bypass_port()
Definition: luaproc.h:105
LuaTableRef lref
Definition: luaproc.h:173
float * _control_data
Definition: luaproc.h:197
const std::string & origin() const
Definition: luaproc.h:150
int get_parameter_descriptor(uint32_t which, ParameterDescriptor &) const
bool requires_fixed_sized_buffers() const
Definition: luaproc.h:89
bool reconfigure_io(ChanCount in, ChanCount aux_in, ChanCount out)
LuaTableRef * instance_ref()
Definition: luaproc.h:130
float get_parameter(uint32_t port) const
bool _requires_fixed_sized_buffers
Definition: luaproc.h:166
std::string describe_parameter(Evoral::Parameter)
std::string get_docs() const
Definition: luaproc.h:75
bool _lua_has_inline_display
Definition: luaproc.h:165
ChanCount _configured_in
Definition: luaproc.h:200
float default_value(uint32_t port)
bool load_factory_preset(PresetRecord const &)
uint32_t parameter_count() const
DSP::DspShm * instance_shm()
Definition: luaproc.h:129
std::shared_ptr< ScalePoints > get_scale_points(uint32_t port_index) const
std::string state_node_name() const
Definition: luaproc.h:109
std::string _docs
Definition: luaproc.h:163
ChanCount output_streams() const
Definition: luaproc.h:123
const char * name() const
Definition: luaproc.h:64
std::string presets_file() const
int set_block_size(pframes_t)
Definition: luaproc.h:88
LuaProc(AudioEngine &, Session &, const std::string &)
const char * maker() const
Definition: luaproc.h:66
LuaProc(const LuaProc &)
Definition: LuaRef.h:52
Definition: tlsf.h:30
Definition: xml++.h:114
Definition: xml++.h:74
#define LIBARDOUR_API
void session(lua_State *L)
PBD::PropertyDescriptor< timepos_t > start
std::shared_ptr< LuaScriptInfo > LuaScriptInfoPtr
Definition: luascripting.h:103
uint32_t pframes_t
std::shared_ptr< Plugin > PluginPtr
Definition: plugin.h:63
std::shared_ptr< LuaPluginInfo > LuaPluginInfoPtr
Definition: luaproc.h:245
Temporal::samplecnt_t samplecnt_t
Temporal::sampleoffset_t sampleoffset_t
Temporal::samplepos_t samplepos_t
std::set< uint32_t > PluginOutputConfiguration
Definition: plugin.h:68
std::map< uint32_t, float > param
Definition: luaproc.h:134