Ardour  9.0-pre0-439-ga53b99b307
lua_api.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License 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  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 #ifndef _ardour_lua_api_h_
20 #define _ardour_lua_api_h_
21 
22 #include <memory>
23 #include <string>
24 
25 #include <lo/lo.h>
26 #include <rubberband/RubberBandStretcher.h>
27 #include <vamp-hostsdk/Plugin.h>
28 
29 #include "evoral/Note.h"
30 
32 
33 #include "ardour/audioregion.h"
34 #include "ardour/midi_model.h"
35 #include "ardour/processor.h"
36 #include "ardour/session.h"
37 
38 namespace ARDOUR {
39  class AudioReadable;
40 }
41 
42 namespace ARDOUR { namespace LuaAPI {
43 
56 
63  std::shared_ptr<Processor> new_send (Session* s, std::shared_ptr<ARDOUR::Route> r, std::shared_ptr<ARDOUR::Processor> p);
64 
69  std::shared_ptr<ARDOUR::Processor> nil_processor ();
70 
78  std::shared_ptr<ARDOUR::Processor> new_luaproc_with_time_domain (ARDOUR::Session *s, const std::string& p, Temporal::TimeDomain td);
79 
80  /* As above but uses default time domain for the session/application */
81  std::shared_ptr<ARDOUR::Processor> new_luaproc (ARDOUR::Session *s, const std::string& p);
82 
84  std::list<std::shared_ptr<ARDOUR::PluginInfo> > list_plugins ();
85 
89  std::string dump_untagged_plugins ();
90 
97  std::shared_ptr<ARDOUR::PluginInfo> new_plugin_info (const std::string& id, ARDOUR::PluginType type);
98 
108  std::shared_ptr<ARDOUR::Processor> new_plugin_with_time_domain (ARDOUR::Session *s, const std::string& id, ARDOUR::PluginType type, Temporal::TimeDomain td, const std::string& preset = "");
109 
110  /* As above but uses default time domain for the session/application */
111  std::shared_ptr<ARDOUR::Processor> new_plugin (ARDOUR::Session *s, const std::string& id, ARDOUR::PluginType type, const std::string& preset = "");
112 
120  bool set_processor_param (std::shared_ptr<ARDOUR::Processor> proc, uint32_t which, float value);
121 
129  float get_processor_param (std::shared_ptr<Processor> proc, uint32_t which, bool &ok);
130 
138  bool reset_processor_to_default (std::shared_ptr<Processor> proc);
139 
149  bool set_plugin_insert_param (std::shared_ptr<ARDOUR::PluginInsert> pi, uint32_t which, float value);
150 
158  float get_plugin_insert_param (std::shared_ptr<ARDOUR::PluginInsert> pi, uint32_t which, bool &ok);
159 
167  bool set_plugin_insert_property (std::shared_ptr<ARDOUR::PluginInsert> pi, std::string const& uri, luabridge::LuaRef value);
168 
175 
201 
202  /*
203  * A convenience function to get a scale-points from a ParameterDescriptor
204  * @param p a ParameterDescriptor
205  * @returns Lua Table with "name" -> value pairs
206  */
208 
209  /* Replace all automation data for an AutomationContol from a Lua table
210  * @param ac an AutomationControl
211  * @param tbl Lua Table {[sample-time] = value}
212  * @param thin thinning factor (-1; use default, 0: no thinning)
213  * @returns true on success
214  */
215  bool set_automation_data (std::shared_ptr<ARDOUR::AutomationControl> ac, luabridge::LuaRef tbl, double thin = -1);
216 
228 
244 
247  std::string ascii_dtostr (const double d);
248 
256 
262 
268 
275 
282 
287 
295  bool wait_for_process_callback (size_t n_cycles, int64_t timeout_ms);
296 
298  void segfault ();
299 
301  std::vector<std::string> env ();
302 
303  class Vamp {
314  public:
315  Vamp (const std::string&, float sample_rate);
316  ~Vamp ();
317 
321  static std::vector<std::string> list_plugins ();
322 
323  ::Vamp::Plugin* plugin () { return _plugin; }
324 
337  int analyze (std::shared_ptr<ARDOUR::AudioReadable> r, uint32_t channel, luabridge::LuaRef fn);
338 
340  void reset ();
341 
359  bool initialize ();
360 
361  bool initialized () const { return _initialized; }
362 
373  ::Vamp::Plugin::FeatureSet process (const std::vector<float*>& d, ::Vamp::RealTime rt);
374 
375  private:
376  ::Vamp::Plugin* _plugin;
381 
382  };
383 
384  class Rubberband : public AudioReadable , public std::enable_shared_from_this<Rubberband>
385  {
386  public:
387  Rubberband (std::shared_ptr<AudioRegion>, bool percussive);
389  bool set_strech_and_pitch (double stretch_ratio, double pitch_ratio);
390  bool set_mapping (luabridge::LuaRef tbl);
391  std::shared_ptr<AudioRegion> process (luabridge::LuaRef cb);
392  std::shared_ptr<AudioReadable> readable ();
393 
394  /* audioreadable API */
396  uint32_t n_channels () const { return _n_channels; }
397  samplecnt_t read (Sample*, samplepos_t pos, samplecnt_t cnt, int channel) const;
398 
399  private:
400  Rubberband (Rubberband const&); // no copy construction
401  bool read_region (bool study);
402  bool retrieve (float**);
403  void cleanup (bool abort);
404  std::shared_ptr<AudioRegion> finalize ();
405 
406  std::shared_ptr<AudioRegion> _region;
407 
408  uint32_t _n_channels;
412 
413  std::vector<std::shared_ptr<AudioSource> > _asrc;
414 
415  RubberBand::RubberBandStretcher _rbs;
416  std::map<size_t, size_t> _mapping;
417 
419  double _pitch_ratio;
420 
421  luabridge::LuaRef* _cb;
422  std::shared_ptr<Rubberband> _self;
423  static const samplecnt_t _bufsize;
424  };
425 
426  std::shared_ptr<Evoral::Note<Temporal::Beats> >
427  new_noteptr (uint8_t, Temporal::Beats, Temporal::Beats, uint8_t, uint8_t);
428 
429  std::list<std::shared_ptr< Evoral::Note<Temporal::Beats> > >
430  note_list (std::shared_ptr<ARDOUR::MidiModel>);
431 
432  std::list<std::shared_ptr< Evoral::Event<Temporal::Beats> > >
433  sysex_list (std::shared_ptr<ARDOUR::MidiModel>);
434 
435  std::list<std::shared_ptr< Evoral::PatchChange<Temporal::Beats> > >
436  patch_change_list (std::shared_ptr<ARDOUR::MidiModel>);
437 
438 
439 } } /* namespace */
440 
441 namespace ARDOUR { namespace LuaOSC {
446  class Address {
447  /*
448  * OSC is kinda special, lo_address is a void* and lo_send() has varags
449  * and typed arguments which makes it hard to bind, even lo_cpp.
450  */
451  public:
455  Address (std::string uri) {
456  _addr = lo_address_new_from_url (uri.c_str());
457  }
458 
459  ~Address () { if (_addr) { lo_address_free (_addr); } }
485  int send (lua_State *lua);
486  private:
487  lo_address _addr;
488  };
489 
490 }
491 
492 class LuaTableRef {
493 public:
496 
497  int get (lua_State* L);
498  int set (lua_State* L);
499 
500 private:
501  struct LuaTableEntry {
502  LuaTableEntry (int kt, int vt)
503  : keytype (kt)
504  , valuetype (vt)
505  { }
506 
507  int keytype;
508  std::string k_s;
509  unsigned int k_n;
510 
512  // LUA_TUSERDATA
513  const void* c;
514  void* p;
515  // LUA_TBOOLEAN
516  bool b;
517  // LUA_TSTRING:
518  std::string s;
519  // LUA_TNUMBER:
520  double n;
521  };
522 
523  std::vector<LuaTableEntry> _data;
524 
525  static void* findclasskey (lua_State *L, const void* key);
526  template<typename T>
527  static void assign (luabridge::LuaRef* rv, T key, const LuaTableEntry& s);
528 };
529 
530 } /* namespace */
531 
532 #endif // _ardour_lua_api_h_
static const samplecnt_t _bufsize
Definition: lua_api.h:423
samplecnt_t _read_offset
Definition: lua_api.h:411
bool set_strech_and_pitch(double stretch_ratio, double pitch_ratio)
bool read_region(bool study)
std::shared_ptr< AudioRegion > _region
Definition: lua_api.h:406
luabridge::LuaRef * _cb
Definition: lua_api.h:421
uint32_t n_channels() const
Definition: lua_api.h:396
samplecnt_t read(Sample *, samplepos_t pos, samplecnt_t cnt, int channel) const
std::shared_ptr< AudioReadable > readable()
RubberBand::RubberBandStretcher _rbs
Definition: lua_api.h:415
void cleanup(bool abort)
std::map< size_t, size_t > _mapping
Definition: lua_api.h:416
std::shared_ptr< Rubberband > _self
Definition: lua_api.h:422
std::vector< std::shared_ptr< AudioSource > > _asrc
Definition: lua_api.h:413
bool set_mapping(luabridge::LuaRef tbl)
samplecnt_t _read_start
Definition: lua_api.h:410
Rubberband(Rubberband const &)
std::shared_ptr< AudioRegion > finalize()
std::shared_ptr< AudioRegion > process(luabridge::LuaRef cb)
Rubberband(std::shared_ptr< AudioRegion >, bool percussive)
samplecnt_t readable_length_samples() const
Definition: lua_api.h:395
::Vamp::Plugin::FeatureSet process(const std::vector< float * > &d, ::Vamp::RealTime rt)
int analyze(std::shared_ptr< ARDOUR::AudioReadable > r, uint32_t channel, luabridge::LuaRef fn)
Vamp(const std::string &, float sample_rate)
samplecnt_t _stepsize
Definition: lua_api.h:379
::Vamp::Plugin * plugin()
Definition: lua_api.h:323
static std::vector< std::string > list_plugins()
bool initialized() const
Definition: lua_api.h:361
samplecnt_t _bufsize
Definition: lua_api.h:378
::Vamp::Plugin * _plugin
Definition: lua_api.h:376
int send(lua_State *lua)
Address(std::string uri)
Definition: lua_api.h:455
int get(lua_State *L)
static void assign(luabridge::LuaRef *rv, T key, const LuaTableEntry &s)
static void * findclasskey(lua_State *L, const void *key)
int set(lua_State *L)
std::vector< LuaTableEntry > _data
Definition: lua_api.h:523
float get_plugin_insert_param(std::shared_ptr< ARDOUR::PluginInsert > pi, uint32_t which, bool &ok)
int hsla_to_rgba(lua_State *lua)
std::list< std::shared_ptr< Evoral::PatchChange< Temporal::Beats > > > patch_change_list(std::shared_ptr< ARDOUR::MidiModel >)
int datatype_ctor_midi(lua_State *L)
bool set_plugin_insert_param(std::shared_ptr< ARDOUR::PluginInsert > pi, uint32_t which, float value)
std::list< std::shared_ptr< Evoral::Note< Temporal::Beats > > > note_list(std::shared_ptr< ARDOUR::MidiModel >)
std::string ascii_dtostr(const double d)
int datatype_ctor_audio(lua_State *L)
int timecode_to_sample_lua(lua_State *L)
std::shared_ptr< ARDOUR::Processor > new_luaproc(ARDOUR::Session *s, const std::string &p)
std::string dump_untagged_plugins()
int sample_to_timecode(lua_State *L)
std::shared_ptr< ARDOUR::Processor > nil_processor()
std::list< std::shared_ptr< ARDOUR::PluginInfo > > list_plugins()
bool set_automation_data(std::shared_ptr< ARDOUR::AutomationControl > ac, luabridge::LuaRef tbl, double thin=-1)
int sample_to_timecode_lua(lua_State *L)
bool set_processor_param(std::shared_ptr< ARDOUR::Processor > proc, uint32_t which, float value)
int simple_export(lua_State *L)
std::shared_ptr< ARDOUR::Processor > new_plugin_with_time_domain(ARDOUR::Session *s, const std::string &id, ARDOUR::PluginType type, Temporal::TimeDomain td, const std::string &preset="")
std::shared_ptr< Evoral::Note< Temporal::Beats > > new_noteptr(uint8_t, Temporal::Beats, Temporal::Beats, uint8_t, uint8_t)
std::list< std::shared_ptr< Evoral::Event< Temporal::Beats > > > sysex_list(std::shared_ptr< ARDOUR::MidiModel >)
float get_processor_param(std::shared_ptr< Processor > proc, uint32_t which, bool &ok)
int color_to_rgba(lua_State *lua)
bool set_plugin_insert_property(std::shared_ptr< ARDOUR::PluginInsert > pi, std::string const &uri, luabridge::LuaRef value)
int plugin_automation(lua_State *lua)
int get_plugin_insert_property(lua_State *p)
std::shared_ptr< ARDOUR::Processor > new_plugin(ARDOUR::Session *s, const std::string &id, ARDOUR::PluginType type, const std::string &preset="")
std::shared_ptr< ARDOUR::PluginInfo > new_plugin_info(const std::string &id, ARDOUR::PluginType type)
int build_filename(lua_State *lua)
int timecode_to_sample(lua_State *L)
bool wait_for_process_callback(size_t n_cycles, int64_t timeout_ms)
bool reset_processor_to_default(std::shared_ptr< Processor > proc)
std::shared_ptr< Processor > new_send(Session *s, std::shared_ptr< ARDOUR::Route > r, std::shared_ptr< ARDOUR::Processor > p)
std::vector< std::string > env()
std::shared_ptr< ARDOUR::Processor > new_luaproc_with_time_domain(ARDOUR::Session *s, const std::string &p, Temporal::TimeDomain td)
int datatype_ctor_null(lua_State *lua)
int desc_scale_points(lua_State *p)
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t