Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
27 
28 #include <set>
29 #include <vector>
30 #include <string>
31 
32 #ifdef USE_TLSF
33 # include "pbd/tlsf.h"
34 #else
35 # include "pbd/reallocpool.h"
36 #endif
37 
38 #include "pbd/stateful.h"
39 
40 #include "ardour/types.h"
41 #include "ardour/plugin.h"
42 #include "ardour/luascripting.h"
43 #include "ardour/dsp_filter.h"
44 #include "ardour/lua_api.h"
45 
46 #include "lua/luastate.h"
47 
48 namespace luabridge {
49  class LuaRef;
50 }
51 
52 namespace ARDOUR {
53 
55 public:
56  LuaProc (AudioEngine&, Session&, const std::string&);
57  LuaProc (const LuaProc &);
59 
60  /* Plugin interface */
61 
62  std::string unique_id() const { return get_info()->unique_id; }
63  const char* name() const { return get_info()->name.c_str(); }
64  const char* label() const { return get_info()->name.c_str(); }
65  const char* maker() const { return get_info()->creator.c_str(); }
66 
67  uint32_t parameter_count() const;
68  float default_value (uint32_t port);
69  void set_parameter (uint32_t port, float val, sampleoffset_t);
70  float get_parameter (uint32_t port) const;
71  int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
72  uint32_t nth_parameter (uint32_t port, bool& ok) const;
73 
74  std::string get_docs () const { return _docs; }
75  std::string get_parameter_docs (uint32_t) const;
76 
77  PluginOutputConfiguration possible_output () const { return _output_configs; }
78 
79  void drop_references ();
80 
81  std::set<Evoral::Parameter> automatable() const;
82 
83  void activate () { }
84  void deactivate () { }
85  void cleanup () { }
86 
87  int set_block_size (pframes_t /*nframes*/) { return 0; }
88  bool requires_fixed_sized_buffers () const { return _requires_fixed_sized_buffers; }
89  bool connect_all_audio_outputs () const { return _connect_all_audio_outputs; }
90 
92  samplepos_t start, samplepos_t end, double speed,
93  ChanMapping const& in, ChanMapping const& out,
94  pframes_t nframes, samplecnt_t offset);
95 
97  std::shared_ptr<ScalePoints> get_scale_points(uint32_t port_index) const;
98 
99  bool parameter_is_audio (uint32_t) const { return false; }
100  bool parameter_is_control (uint32_t) const { return true; }
101  bool parameter_is_input (uint32_t) const;
102  bool parameter_is_output (uint32_t) const;
103 
105  return _designated_bypass_port;
106  }
107 
108  std::string state_node_name() const { return "luaproc"; }
109  void add_state (XMLNode *) const;
110  int set_state (const XMLNode&, int version);
112 
114  std::string do_save_preset (std::string);
115  void do_remove_preset (std::string);
116 
117  bool has_editor() const { return false; }
118 
119  bool match_variable_io (ChanCount& in, ChanCount& aux_in, ChanCount& out);
120  bool reconfigure_io (ChanCount in, ChanCount aux_in, ChanCount out);
121 
122  ChanCount output_streams() const { return _configured_out; }
123  ChanCount input_streams() const { return _configured_in; }
124 
125  bool has_inline_display () { return _lua_has_inline_display; }
127 
128  DSP::DspShm* instance_shm () { return &lshm; }
129  LuaTableRef* instance_ref () { return &lref; }
130 
131  struct FactoryPreset {
132  std::string name;
133  std::map<uint32_t, float> param;
134  };
135 
136  std::map<std::string, FactoryPreset> _factory_presets;
137 
138 private:
139  samplecnt_t plugin_latency() const { return _signal_latency; }
140  void find_presets ();
141 
142  /* END Plugin interface */
143 
144 public:
145  void set_origin (std::string& path) { _origin = path; }
146 
147 protected:
148  const std::string& script() const { return _script; }
149  const std::string& origin() const { return _origin; }
150 
151 private:
152 #ifdef USE_TLSF
153  PBD::TLSF _mempool;
154 #else
156 #endif
158  luabridge::LuaRef * _lua_dsp;
159  luabridge::LuaRef * _lua_latency;
160  std::string _script;
161  std::string _origin;
162  std::string _docs;
168 
169  void queue_draw () { QueueDraw(); /* EMIT SIGNAL */ }
171 
173 
174  std::weak_ptr<Route> route () const;
175 
176  void init ();
177  bool load_script ();
178  void lua_print (std::string s);
179 
182 
183  std::string preset_name_to_uri (const std::string&) const;
184  std::string presets_file () const;
186 
187  std::shared_ptr<ScalePoints> parse_scale_points (luabridge::LuaRef*);
188 
189  std::vector<std::pair<bool, int> > _ctrl_params;
190  std::map<int, ARDOUR::ParameterDescriptor> _param_desc;
191  std::map<int, std::string> _param_doc;
193 
195 
197  float* _shadow_data;
198 
201 
203 
206 
208 
211 
212 
213 #ifdef WITH_LUAPROC_STATS
214  int64_t _stats_avg[2];
215  int64_t _stats_max[2];
216  int64_t _stats_cnt;
217 #endif
218 };
219 
221 {
222  public:
225 
227  std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
228 
229  bool reconfigurable_io() const { return true; }
230  uint32_t max_configurable_outputs () const {
231  return _max_outputs;
232  }
233 
234  void set_factory_presets (std::vector<Plugin::PresetRecord> const& p) {
235  _factory_presets = p;
236  }
237 
238  private:
239  uint32_t _max_outputs;
240 
241  std::vector<Plugin::PresetRecord> _factory_presets;
242 };
243 
244 typedef std::shared_ptr<LuaPluginInfo> LuaPluginInfoPtr;
245 
246 } // namespace ARDOUR
247 
void set_factory_presets(std::vector< Plugin::PresetRecord > const &p)
Definition: luaproc.h:234
std::vector< Plugin::PresetRecord > get_presets(bool user_only) const
bool reconfigurable_io() const
Definition: luaproc.h:229
uint32_t _max_outputs
Definition: luaproc.h:239
uint32_t max_configurable_outputs() const
Definition: luaproc.h:230
LuaPluginInfo(LuaScriptInfoPtr lsi)
std::vector< Plugin::PresetRecord > _factory_presets
Definition: luaproc.h:241
PluginPtr load(Session &session)
bool load_user_preset(PresetRecord const &)
float * _shadow_data
Definition: luaproc.h:197
void add_state(XMLNode *) const
void activate()
Definition: luaproc.h:83
std::vector< std::pair< bool, int > > _ctrl_params
Definition: luaproc.h:189
bool _has_midi_input
Definition: luaproc.h:209
bool parameter_is_audio(uint32_t) const
Definition: luaproc.h:99
void do_remove_preset(std::string)
ChanCount _configured_out
Definition: luaproc.h:200
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:145
std::map< int, ARDOUR::ParameterDescriptor > _param_desc
Definition: luaproc.h:190
bool connect_all_audio_outputs() const
Definition: luaproc.h:89
PBD::ReallocPool _mempool
Definition: luaproc.h:155
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:64
int set_state(const XMLNode &, int version)
std::string get_parameter_docs(uint32_t) const
bool has_inline_display()
Definition: luaproc.h:125
samplecnt_t _signal_latency
Definition: luaproc.h:194
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:157
samplecnt_t plugin_latency() const
Definition: luaproc.h:139
luabridge::LuaRef * _lua_latency
Definition: luaproc.h:159
void cleanup()
Definition: luaproc.h:85
bool parameter_is_control(uint32_t) const
Definition: luaproc.h:100
std::map< std::string, FactoryPreset > _factory_presets
Definition: luaproc.h:136
void deactivate()
Definition: luaproc.h:84
bool _set_time_info
Definition: luaproc.h:167
bool _has_midi_output
Definition: luaproc.h:210
DSP::DspShm lshm
Definition: luaproc.h:170
bool match_variable_io(ChanCount &in, ChanCount &aux_in, ChanCount &out)
bool load_preset(PresetRecord)
uint32_t _designated_bypass_port
Definition: luaproc.h:192
bool _connect_all_audio_outputs
Definition: luaproc.h:166
luabridge::LuaRef * _lua_dsp
Definition: luaproc.h:158
std::string unique_id() const
Definition: luaproc.h:62
void setup_lua_inline_gui(LuaState *lua_gui)
std::set< Evoral::Parameter > automatable() const
PluginOutputConfiguration possible_output() const
Definition: luaproc.h:77
bool has_editor() const
Definition: luaproc.h:117
PluginOutputConfiguration _output_configs
Definition: luaproc.h:207
XMLTree * presets_tree() const
ChanCount input_streams() const
Definition: luaproc.h:123
bool _lua_does_channelmapping
Definition: luaproc.h:163
std::string do_save_preset(std::string)
std::string _origin
Definition: luaproc.h:161
ChanCount _selected_out
Definition: luaproc.h:205
void drop_references()
const std::string & script() const
Definition: luaproc.h:148
std::weak_ptr< Route > route() const
ChanCount _selected_in
Definition: luaproc.h:204
std::string _script
Definition: luaproc.h:160
std::map< int, std::string > _param_doc
Definition: luaproc.h:191
void queue_draw()
Definition: luaproc.h:169
bool _configured
Definition: luaproc.h:202
uint32_t designated_bypass_port()
Definition: luaproc.h:104
LuaTableRef lref
Definition: luaproc.h:172
float * _control_data
Definition: luaproc.h:196
const std::string & origin() const
Definition: luaproc.h:149
int get_parameter_descriptor(uint32_t which, ParameterDescriptor &) const
bool requires_fixed_sized_buffers() const
Definition: luaproc.h:88
bool reconfigure_io(ChanCount in, ChanCount aux_in, ChanCount out)
LuaTableRef * instance_ref()
Definition: luaproc.h:129
float get_parameter(uint32_t port) const
bool _requires_fixed_sized_buffers
Definition: luaproc.h:165
std::string describe_parameter(Evoral::Parameter)
std::string get_docs() const
Definition: luaproc.h:74
bool _lua_has_inline_display
Definition: luaproc.h:164
ChanCount _configured_in
Definition: luaproc.h:199
float default_value(uint32_t port)
bool load_factory_preset(PresetRecord const &)
uint32_t parameter_count() const
DSP::DspShm * instance_shm()
Definition: luaproc.h:128
std::shared_ptr< ScalePoints > get_scale_points(uint32_t port_index) const
std::string state_node_name() const
Definition: luaproc.h:108
std::string _docs
Definition: luaproc.h:162
ChanCount output_streams() const
Definition: luaproc.h:122
const char * name() const
Definition: luaproc.h:63
std::string presets_file() const
int set_block_size(pframes_t)
Definition: luaproc.h:87
LuaProc(AudioEngine &, Session &, const std::string &)
const char * maker() const
Definition: luaproc.h:65
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:62
std::shared_ptr< LuaPluginInfo > LuaPluginInfoPtr
Definition: luaproc.h:244
Temporal::samplecnt_t samplecnt_t
Temporal::sampleoffset_t sampleoffset_t
Temporal::samplepos_t samplepos_t
std::set< uint32_t > PluginOutputConfiguration
Definition: plugin.h:67
std::map< uint32_t, float > param
Definition: luaproc.h:133