2 Copyright (C) 2016 Robin Gareus <robin@gareus.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "timecode/bbt_time.h"
22 #include "pbd/stateful_diff_command.h"
23 #include "evoral/Control.hpp"
24 #include "evoral/ControlList.hpp"
25 #include "evoral/Range.hpp"
27 #include "ardour/audioengine.h"
28 #include "ardour/audiosource.h"
29 #include "ardour/audio_backend.h"
30 #include "ardour/audio_buffer.h"
31 #include "ardour/audio_track.h"
32 #include "ardour/buffer_set.h"
33 #include "ardour/chan_mapping.h"
34 #include "ardour/dB.h"
35 #include "ardour/dsp_filter.h"
36 #include "ardour/interthread_info.h"
37 #include "ardour/lua_api.h"
38 #include "ardour/luabindings.h"
39 #include "ardour/meter.h"
40 #include "ardour/midi_track.h"
41 #include "ardour/playlist.h"
42 #include "ardour/plugin.h"
43 #include "ardour/plugin_insert.h"
44 #include "ardour/runtime_functions.h"
45 #include "ardour/region.h"
46 #include "ardour/region_factory.h"
47 #include "ardour/session.h"
48 #include "ardour/session_object.h"
49 #include "ardour/sidechain.h"
50 #include "ardour/track.h"
51 #include "ardour/tempo.h"
53 #include "LuaBridge/LuaBridge.h"
55 /* Some notes on Lua bindings for libardour and friends
57 * - Prefer factory methods over Contructors whenever possible.
58 * Don't expose the constructor method unless required.
60 * e.g. Don't allow the script to construct a "Track" Object directly
61 * but do allow to create a "BBT_TIME" object.
63 * - Do not dereference Shared or Weak Pointers. Pass the pointer to Lua.
64 * - Define Objects as boost:shared_ptr Object whenever possible.
66 * Storing a boost::shared_ptr in a Lua-variable keeps the reference
67 * until that variable is set to 'nil'.
68 * (if the script were to keep a direct pointer to the object instance, the
69 * behaviour is undefined if the actual object goes away)
71 * Methods of the actual class are indirectly exposed,
72 * boost::*_ptr get() and ::lock() is implicit when the class is exported
73 * as LuaBridge's "WSPtrClass".
76 using namespace ARDOUR;
79 LuaBindings::stddef (lua_State* L)
81 // std::list<std::string>
82 luabridge::getGlobalNamespace (L)
84 .beginStdList <std::string> ("StringList")
87 // std::vector<std::string>
88 .beginStdVector <std::string> ("StringVector")
91 // register float array (float*)
92 .registerArray <float> ("FloatArray")
94 // register float array (int32_t*)
95 .registerArray <int32_t> ("IntArray")
102 LuaBindings::common (lua_State* L)
104 luabridge::getGlobalNamespace (L)
105 .beginNamespace ("PBD")
106 .beginClass <PBD::ID> ("ID")
107 .addConstructor <void (*) (std::string)> ()
108 .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
111 .beginClass <PBD::Stateful> ("Stateful")
112 .addFunction ("properties", &PBD::Stateful::properties)
113 .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
116 .beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
117 .addFunction ("properties", &PBD::Stateful::properties)
118 .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
121 .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
124 .deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructiblePtr")
127 .deriveClass <Command, PBD::StatefulDestructible> ("Command")
128 .addFunction ("set_name", &Command::set_name)
129 .addFunction ("name", &Command::name)
132 /* UndoTransaction::add_command() subscribes to DropReferences()
133 * and deletes the object.
135 * This object cannot be constructed by lua because lua would manage lifetime
136 * and delete the object leading to a double free.
138 * use Session::add_stateful_diff_command()
139 * and Session::abort_reversible_command()
141 .deriveClass <PBD::StatefulDiffCommand, Command> ("StatefulDiffCommand")
142 .addFunction ("undo", &PBD::StatefulDiffCommand::undo)
143 .addFunction ("empty", &PBD::StatefulDiffCommand::empty)
146 .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
147 .addFunction ("get_value", &PBD::Controllable::get_value)
150 .beginNamespace ("GroupControlDisposition")
151 .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
152 .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
153 .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
156 .endNamespace (); // PBD
158 luabridge::getGlobalNamespace (L)
159 .beginNamespace ("Timecode")
160 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
161 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
165 luabridge::getGlobalNamespace (L)
167 .beginNamespace ("Evoral")
168 .beginClass <Evoral::Parameter> ("Parameter")
169 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
170 .addFunction ("type", &Evoral::Parameter::type)
171 .addFunction ("channel", &Evoral::Parameter::channel)
172 .addFunction ("id", &Evoral::Parameter::id)
175 .beginWSPtrClass <Evoral::ControlList> ("ControlList")
176 .addFunction ("add", &Evoral::ControlList::add)
179 .beginWSPtrClass <Evoral::ControlSet> ("ControlSet")
182 .beginWSPtrClass <Evoral::Control> ("Control")
183 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
186 .beginClass <Evoral::ParameterDescriptor> ("ParameterDescriptor")
187 .addVoidConstructor ()
188 .addData ("lower", &Evoral::ParameterDescriptor::lower)
189 .addData ("upper", &Evoral::ParameterDescriptor::upper)
190 .addData ("normal", &Evoral::ParameterDescriptor::normal)
191 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
194 .beginClass <Evoral::Range<framepos_t> > ("Range")
195 .addConstructor <void (*) (framepos_t, framepos_t)> ()
196 .addData ("from", &Evoral::Range<framepos_t>::from)
197 .addData ("to", &Evoral::Range<framepos_t>::to)
200 .endNamespace () // Evoral
202 .beginNamespace ("ARDOUR")
204 .beginClass <InterThreadInfo> ("InterThreadInfo")
205 .addVoidConstructor ()
206 .addData ("done", const_cast<bool InterThreadInfo::*>(&InterThreadInfo::done))
207 .addData ("cancel", (bool InterThreadInfo::*)&InterThreadInfo::cancel)
208 .addData ("progress", const_cast<float InterThreadInfo::*>(&InterThreadInfo::progress))
211 .beginClass <AudioRange> ("AudioRange")
212 .addConstructor <void (*) (framepos_t, framepos_t, uint32_t)> ()
213 .addFunction ("length", &AudioRange::length)
214 .addFunction ("equal", &AudioRange::equal)
215 .addData ("start", &AudioRange::start)
216 .addData ("_end", &AudioRange::end) // XXX "end" is a lua reserved word
217 .addData ("id", &AudioRange::id)
220 .beginWSPtrClass <PluginInfo> ("PluginInfo")
221 .addVoidConstructor ()
224 .beginNamespace ("Route")
225 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
226 .addVoidConstructor ()
230 .beginClass <ChanMapping> ("ChanMapping")
231 .addVoidConstructor ()
232 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t) const>(&ChanMapping::get))
233 .addFunction ("set", &ChanMapping::set)
234 .addConst ("Invalid", 4294967295) // UINT32_MAX
237 .beginNamespace ("Properties")
238 // templated class definitions
239 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
240 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
241 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
242 // actual references (TODO: also expose GQuark for std::set)
244 .addConst ("Start", &ARDOUR::Properties::start)
245 .addConst ("Length", &ARDOUR::Properties::length)
246 .addConst ("Position", &ARDOUR::Properties::position)
249 .beginClass <PBD::PropertyChange> ("PropertyChange")
250 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
251 // -> direct map to lua table beginStdSet()A
253 // expand templated PropertyDescriptor<T>
254 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
255 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
256 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
259 .beginClass <PBD::PropertyList> ("PropertyList")
260 // is-a std::map<PropertyID, PropertyBase*>
263 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
266 .deriveClass <Location, PBD::StatefulDestructible> ("Location")
267 .addFunction ("locked", &Location::locked)
268 .addFunction ("lock", &Location::lock)
269 .addFunction ("start", &Location::start)
270 .addFunction ("_end", &Location::end) // XXX "end" is a lua reserved word
271 .addFunction ("length", &Location::length)
272 .addFunction ("set_start", &Location::set_start)
273 .addFunction ("set_end", &Location::set_end)
274 .addFunction ("set_length", &Location::set)
275 .addFunction ("move_to", &Location::move_to)
278 .deriveClass <Locations, PBD::StatefulDestructible> ("Location")
279 .addFunction ("auto_loop_location", &Locations::auto_loop_location)
280 .addFunction ("auto_punch_location", &Locations::auto_punch_location)
281 .addFunction ("session_range_location", &Locations::session_range_location)
282 .addFunction ("first_mark_after", &Locations::first_mark_after)
283 .addFunction ("first_mark_after", &Locations::first_mark_after)
286 .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
287 /* multiple inheritance is not covered by luabridge,
288 * we need explicit casts :( */
289 .addCast<PBD::Stateful> ("to_stateful")
290 .addCast<PBD::StatefulDestructible> ("to_statefuldestructible")
291 .addFunction ("name", &SessionObject::name)
294 .deriveWSPtrClass <IO, SessionObject> ("IO")
295 .addFunction ("active", &IO::active)
296 .addFunction ("add_port", &IO::add_port)
297 .addFunction ("remove_port", &IO::remove_port)
298 .addFunction ("connect", &IO::connect)
299 .addFunction ("disconnect", (int (IO::*)(boost::shared_ptr<Port>, std::string, void *))&IO::disconnect)
300 .addFunction ("physically_connected", &IO::physically_connected)
303 .deriveWSPtrClass <Route, SessionObject> ("Route")
304 .addCast<Track> ("to_track")
305 .addFunction ("set_name", &Route::set_name)
306 .addFunction ("comment", &Route::comment)
307 .addFunction ("active", &Route::active)
308 .addFunction ("set_active", &Route::set_active)
309 .addFunction ("nth_plugin", &Route::nth_plugin)
310 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
311 .addFunction ("remove_processor", &Route::remove_processor)
312 .addFunction ("replace_processor", &Route::replace_processor)
313 .addFunction ("n_inputs", &Route::n_inputs)
314 .addFunction ("n_outputs", &Route::n_outputs)
315 .addFunction ("set_comment", &Route::set_comment)
316 .addFunction ("strict_io", &Route::strict_io)
317 .addFunction ("set_strict_io", &Route::set_strict_io)
318 .addFunction ("reset_plugin_insert", &Route::reset_plugin_insert)
319 .addFunction ("customize_plugin_insert", &Route::customize_plugin_insert)
320 .addFunction ("add_sidechain", &Route::add_sidechain)
321 .addFunction ("remove_sidechain", &Route::remove_sidechain)
322 .addFunction ("main_outs", &Route::main_outs)
323 .addFunction ("muted", &Route::muted)
324 .addFunction ("soloed", &Route::soloed)
327 .deriveWSPtrClass <Playlist, SessionObject> ("Playlist")
328 .addFunction ("region_by_id", &Playlist::region_by_id)
329 .addFunction ("data_type", &Playlist::data_type)
330 .addFunction ("n_regions", &Playlist::n_regions)
331 //.addFunction ("get_extent", &Playlist::get_extent) // pair<framepos_t, framepos_t>
332 //.addFunction ("region_list", &Playlist::region_list) // RegionListProperty&
333 .addFunction ("add_region", &Playlist::add_region)
334 .addFunction ("remove_region", &Playlist::remove_region)
335 .addFunction ("regions_at", &Playlist::regions_at)
336 .addFunction ("top_region_at", &Playlist::top_region_at)
337 .addFunction ("top_unmuted_region_at", &Playlist::top_unmuted_region_at)
338 .addFunction ("find_next_region", &Playlist::find_next_region)
339 .addFunction ("find_next_region_boundary", &Playlist::find_next_region_boundary)
340 .addFunction ("count_regions_at", &Playlist::count_regions_at)
341 .addFunction ("regions_with_start_within", &Playlist::regions_with_start_within)
342 .addFunction ("regions_with_end_within", &Playlist::regions_with_end_within)
343 .addFunction ("raise_region", &Playlist::raise_region)
344 .addFunction ("lower_region", &Playlist::lower_region)
345 .addFunction ("raise_region_to_top", &Playlist::raise_region_to_top)
346 .addFunction ("lower_region_to_bottom", &Playlist::lower_region_to_bottom)
347 .addFunction ("duplicate", (void (Playlist::*)(boost::shared_ptr<Region>, framepos_t, framecnt_t, float))&Playlist::duplicate)
348 .addFunction ("duplicate_until", &Playlist::duplicate_until)
349 .addFunction ("duplicate_range", &Playlist::duplicate_range)
350 .addFunction ("combine", &Playlist::combine)
351 .addFunction ("uncombine", &Playlist::uncombine)
352 .addFunction ("split_region", &Playlist::split_region)
353 .addFunction ("split", (void (Playlist::*)(framepos_t))&Playlist::split)
354 .addFunction ("cut", (boost::shared_ptr<Playlist> (Playlist::*)(std::list<AudioRange>&, bool))&Playlist::cut)
356 .addFunction ("copy", &Playlist::copy)
357 .addFunction ("paste", &Playlist::paste)
361 .deriveWSPtrClass <Track, Route> ("Track")
362 .addCast<AudioTrack> ("to_audio_track")
363 .addCast<MidiTrack> ("to_midi_track")
364 .addFunction ("set_name", &Track::set_name)
365 .addFunction ("can_record", &Track::can_record)
366 .addFunction ("record_enabled", &Track::record_enabled)
367 .addFunction ("record_safe", &Track::record_safe)
368 .addFunction ("set_record_enabled", &Track::set_record_enabled)
369 .addFunction ("set_record_safe", &Track::set_record_safe)
370 .addFunction ("bounceable", &Track::bounceable)
371 .addFunction ("bounce", &Track::bounce_range)
372 .addFunction ("bounce_range", &Track::bounce_range)
373 .addFunction ("playlist", &Track::playlist)
376 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
379 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
382 .deriveWSPtrClass <Region, SessionObject> ("Region")
384 .addFunction ("position", &Region::position)
385 .addFunction ("start", &Region::start)
386 .addFunction ("length", &Region::length)
387 .addFunction ("layer", &Region::layer)
388 .addFunction ("data_type", &Region::data_type)
389 .addFunction ("stretch", &Region::stretch)
390 .addFunction ("shift", &Region::shift)
391 .addRefFunction ("sync_offset", &Region::sync_offset)
392 .addFunction ("sync_position", &Region::sync_position)
393 .addFunction ("hidden", &Region::hidden)
394 .addFunction ("muted", &Region::muted)
395 .addFunction ("opaque", &Region::opaque)
396 .addFunction ("locked", &Region::locked)
397 .addFunction ("position_locked", &Region::position_locked)
398 .addFunction ("video_locked", &Region::video_locked)
399 .addFunction ("valid_transients", &Region::valid_transients)
400 .addFunction ("automatic", &Region::automatic)
401 .addFunction ("whole_file", &Region::whole_file)
402 .addFunction ("captured", &Region::captured)
403 .addFunction ("can_move", &Region::can_move)
404 .addFunction ("sync_marked", &Region::sync_marked)
405 .addFunction ("external", &Region::external)
406 .addFunction ("import", &Region::import)
407 .addFunction ("covers", &Region::covers)
408 .addFunction ("at_natural_position", &Region::at_natural_position)
409 .addFunction ("is_compound", &Region::is_compound)
410 /* editing operations */
411 .addFunction ("set_length", &Region::set_length)
412 .addFunction ("set_start", &Region::set_start)
413 .addFunction ("set_position", &Region::set_position)
414 .addFunction ("set_initial_position", &Region::set_initial_position)
415 .addFunction ("nudge_position", &Region::nudge_position)
416 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
417 .addFunction ("move_start", &Region::move_start)
418 .addFunction ("trim_front", &Region::trim_front)
419 .addFunction ("trim_end", &Region::trim_end)
420 .addFunction ("trim_to", &Region::trim_to)
421 .addFunction ("cut_front", &Region::cut_front)
422 .addFunction ("cut_end", &Region::cut_end)
423 .addFunction ("raise", &Region::raise)
424 .addFunction ("lower", &Region::lower)
425 .addFunction ("raise_to_top", &Region::raise_to_top)
426 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
427 .addFunction ("set_sync_position", &Region::set_sync_position)
428 .addFunction ("clear_sync_position", &Region::clear_sync_position)
429 .addFunction ("set_hidden", &Region::set_hidden)
430 .addFunction ("set_muted", &Region::set_muted)
431 .addFunction ("set_opaque", &Region::set_opaque)
432 .addFunction ("set_locked", &Region::set_locked)
433 .addFunction ("set_video_locked", &Region::set_video_locked)
434 .addFunction ("set_position_locked", &Region::set_position_locked)
437 .beginWSPtrClass <Source> ("Source")
440 .beginClass <Plugin::PresetRecord> ("PresetRecord")
441 .addData ("uri", &Plugin::PresetRecord::uri, false)
442 .addData ("label", &Plugin::PresetRecord::label, false)
443 .addData ("user", &Plugin::PresetRecord::user, false)
444 .addData ("valid", &Plugin::PresetRecord::valid, false)
447 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
448 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
451 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
452 .addVoidConstructor ()
453 .addData ("label", &ParameterDescriptor::label)
454 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
457 .deriveWSPtrClass <Processor, Automatable> ("Processor")
458 .addCast<SessionObject> ("to_sessionobject")
459 .addCast<PluginInsert> ("to_insert")
460 .addCast<SideChain> ("to_sidechain")
461 .addCast<IOProcessor> ("to_ioprocessor")
462 .addFunction ("display_name", &Processor::display_name)
463 .addFunction ("active", &Processor::active)
464 .addFunction ("activate", &Processor::activate)
465 .addFunction ("deactivate", &Processor::deactivate)
466 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
467 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
470 .deriveWSPtrClass <IOProcessor, Processor> ("IOProcessor")
471 .addFunction ("natural_input_streams", &IOProcessor::natural_input_streams)
472 .addFunction ("natural_output_streams", &IOProcessor::natural_output_streams)
473 .addFunction ("input", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::input)
474 .addFunction ("output", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::output)
477 .deriveWSPtrClass <SideChain, IOProcessor> ("SideChain")
480 .deriveWSPtrClass <Delivery, IOProcessor> ("Delivery")
483 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("Plugin")
484 .addFunction ("label", &Plugin::label)
485 .addFunction ("name", &Plugin::name)
486 .addFunction ("maker", &Plugin::maker)
487 .addFunction ("parameter_count", &Plugin::parameter_count)
488 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
489 .addFunction ("preset_by_label", &Plugin::preset_by_label)
490 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
491 .addFunction ("load_preset", &Plugin::load_preset)
492 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
493 .addFunction ("get_docs", &Plugin::get_docs)
494 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
495 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
498 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
499 .addFunction ("plugin", &PluginInsert::plugin)
500 .addFunction ("activate", &PluginInsert::activate)
501 .addFunction ("deactivate", &PluginInsert::deactivate)
502 .addFunction ("strict_io_configured", &PluginInsert::strict_io_configured)
503 .addFunction ("input_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::input_map)
504 .addFunction ("output_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::output_map)
505 .addFunction ("set_input_map", &PluginInsert::set_input_map)
506 .addFunction ("set_output_map", &PluginInsert::set_output_map)
510 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
511 .addFunction ("automation_state", &AutomationControl::automation_state)
512 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
513 .addFunction ("start_touch", &AutomationControl::start_touch)
514 .addFunction ("stop_touch", &AutomationControl::stop_touch)
515 .addFunction ("get_value", &AutomationControl::get_value)
516 .addFunction ("set_value", &AutomationControl::set_value)
517 .addFunction ("writable", &AutomationControl::writable)
520 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
523 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
524 .addFunction ("readable_length", &AudioSource::readable_length)
525 .addFunction ("n_channels", &AudioSource::n_channels)
528 // <std::list<boost::shared_ptr <AudioTrack> >
529 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
532 // std::list<boost::shared_ptr <MidiTrack> >
533 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
536 // RouteList == std::list<boost::shared_ptr<Route> >
537 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
540 // boost::shared_ptr<RouteList>
541 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
544 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
545 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
548 // std::list< boost::weak_ptr <AudioSource> >
549 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
552 // typedef std::list<boost::shared_ptr<Region> > RegionList
553 .beginConstStdList <boost::shared_ptr<Region> > ("RegionList")
556 // boost::shared_ptr <std::list<boost::shared_ptr<Region> > >
557 .beginPtrStdList <boost::shared_ptr<Region> > ("RegionListPtr")
560 // used by Playlist::cut/copy
561 .beginConstStdList <AudioRange> ("AudioRangeList")
564 .beginConstStdList <Location*> ("LocationList")
567 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
568 // typedef Evoral::Note<Evoral::Beats> Note;
569 // std::set< boost::weak_ptr<Note> >
570 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
574 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
575 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
578 // std::list<boost::weak_ptr<Source> >
579 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
582 .beginClass <Tempo> ("Tempo")
583 .addConstructor <void (*) (double, double)> ()
584 .addFunction ("note_type", &Tempo::note_type)
585 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
586 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
589 .beginClass <Meter> ("Meter")
590 .addConstructor <void (*) (double, double)> ()
591 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
592 .addFunction ("note_divisor", &Meter::note_divisor)
593 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
594 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
597 .beginClass <TempoMap> ("TempoMap")
598 .addFunction ("add_tempo", &TempoMap::add_tempo)
599 .addFunction ("add_meter", &TempoMap::add_meter)
602 .beginClass <ChanCount> ("ChanCount")
603 .addConstructor <void (*) (DataType, uint32_t)> ()
604 .addFunction ("get", &ChanCount::get)
605 .addFunction ("set", &ChanCount::set)
606 .addFunction ("n_audio", &ChanCount::n_audio)
607 .addFunction ("n_midi", &ChanCount::n_midi)
608 .addFunction ("n_total", &ChanCount::n_total)
609 .addFunction ("reset", &ChanCount::reset)
612 .beginClass <DataType> ("DataType")
613 .addConstructor <void (*) (std::string)> ()
614 .addStaticCFunction ("null", &LuaAPI::datatype_ctor_null) // "nil" is a lua reseved word
615 .addStaticCFunction ("audio", &LuaAPI::datatype_ctor_audio)
616 .addStaticCFunction ("midi", &LuaAPI::datatype_ctor_midi)
617 .addFunction ("to_string", &DataType::to_string) // TODO Lua __tostring
618 // TODO add uint32_t cast, add operator== !=
621 /* libardour enums */
622 .beginNamespace ("PluginType")
623 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
624 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
625 .addConst ("LV2", ARDOUR::PluginType(LV2))
626 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
627 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
628 .addConst ("Lua", ARDOUR::PluginType(Lua))
631 .beginNamespace ("AutoStyle")
632 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
633 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
636 .beginNamespace ("AutoState")
637 .addConst ("Off", ARDOUR::AutoState(Off))
638 .addConst ("Write", ARDOUR::AutoState(Write))
639 .addConst ("Touch", ARDOUR::AutoState(Touch))
640 .addConst ("Play", ARDOUR::AutoState(Play))
643 .beginNamespace ("AutomationType")
644 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
647 .beginNamespace ("SrcQuality")
648 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
651 .beginNamespace ("PlaylistDisposition")
652 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
653 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
654 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
657 .beginNamespace ("RegionPoint")
658 .addConst ("Start", ARDOUR::RegionPoint(Start))
659 .addConst ("End", ARDOUR::RegionPoint(End))
660 .addConst ("SyncPoint", ARDOUR::RegionPoint(SyncPoint))
663 luabridge::getGlobalNamespace (L)
664 .beginNamespace ("ARDOUR")
665 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
666 .addData ("name", &AudioBackendInfo::name)
668 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
670 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
671 .addData ("name", &AudioBackend::DeviceStatus::name)
672 .addData ("available", &AudioBackend::DeviceStatus::available)
674 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
676 .beginWSPtrClass <AudioBackend> ("AudioBackend")
677 .addFunction ("info", &AudioBackend::info)
678 .addFunction ("sample_rate", &AudioBackend::sample_rate)
679 .addFunction ("buffer_size", &AudioBackend::buffer_size)
680 .addFunction ("period_size", &AudioBackend::period_size)
681 .addFunction ("input_channels", &AudioBackend::input_channels)
682 .addFunction ("output_channels", &AudioBackend::output_channels)
683 .addFunction ("dsp_load", &AudioBackend::dsp_load)
685 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
686 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
687 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
689 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
690 .addFunction ("driver_name", &AudioBackend::driver_name)
691 .addFunction ("set_driver", &AudioBackend::set_driver)
693 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
694 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
695 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
696 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
697 .addFunction ("device_name", &AudioBackend::device_name)
698 .addFunction ("input_device_name", &AudioBackend::input_device_name)
699 .addFunction ("output_device_name", &AudioBackend::output_device_name)
700 .addFunction ("set_device_name", &AudioBackend::set_device_name)
701 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
702 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
705 .beginClass <AudioEngine> ("AudioEngine")
706 .addFunction ("available_backends", &AudioEngine::available_backends)
707 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
708 .addFunction ("set_backend", &AudioEngine::set_backend)
709 .addFunction ("setup_required", &AudioEngine::setup_required)
710 .addFunction ("start", &AudioEngine::start)
711 .addFunction ("stop", &AudioEngine::stop)
712 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
713 .addFunction ("set_device_name", &AudioEngine::set_device_name)
714 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
715 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
716 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
720 // basic representation of Session
721 // functions which can be used from realtime and non-realtime contexts
722 luabridge::getGlobalNamespace (L)
723 .beginNamespace ("ARDOUR")
724 .beginClass <Session> ("Session")
725 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
726 .addFunction ("transport_rolling", &Session::transport_rolling)
727 .addFunction ("request_transport_speed", &Session::request_transport_speed)
728 .addFunction ("transport_frame", &Session::transport_frame)
729 .addFunction ("transport_speed", &Session::transport_speed)
730 .addFunction ("frame_rate", &Session::frame_rate)
731 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
732 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
733 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
734 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
735 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
736 .addFunction ("request_locate", &Session::request_locate)
737 .addFunction ("request_stop", &Session::request_stop)
738 .addFunction ("last_transport_start", &Session::last_transport_start)
739 .addFunction ("goto_start", &Session::goto_start)
740 .addFunction ("goto_end", &Session::goto_end)
741 .addFunction ("current_start_frame", &Session::current_start_frame)
742 .addFunction ("current_end_frame", &Session::current_end_frame)
743 .addFunction ("actively_recording", &Session::actively_recording)
744 .addFunction ("get_routes", &Session::get_routes)
745 .addFunction ("get_tracks", &Session::get_tracks)
746 .addFunction ("name", &Session::name)
747 .addFunction ("path", &Session::path)
748 .addFunction ("record_status", &Session::record_status)
749 .addFunction ("route_by_id", &Session::route_by_id)
750 .addFunction ("route_by_name", &Session::route_by_name)
751 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
752 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
753 .addFunction ("source_by_id", &Session::source_by_id)
754 .addFunction ("controllable_by_id", &Session::controllable_by_id)
755 .addFunction ("processor_by_id", &Session::processor_by_id)
756 .addFunction ("snap_name", &Session::snap_name)
757 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
758 .addFunction ("locations", &Session::locations)
759 .addFunction ("begin_reversible_command", (void (Session::*)(const std::string&))&Session::begin_reversible_command)
760 .addFunction ("commit_reversible_command", &Session::commit_reversible_command)
761 .addFunction ("abort_reversible_command", &Session::abort_reversible_command)
762 .addFunction ("add_stateful_diff_command", &Session::add_stateful_diff_command)
765 .beginClass <RegionFactory> ("RegionFactory")
766 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
770 .beginNamespace ("Session")
772 .beginNamespace ("RecordState")
773 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
774 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
775 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
778 .endNamespace () // END Session enums
780 .beginNamespace ("LuaAPI")
781 .addFunction ("nil_proc", ARDOUR::LuaAPI::nil_processor)
782 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
783 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
784 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
785 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
786 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
787 .addFunction ("usleep", Glib::usleep)
790 .endNamespace ();// END ARDOUR
794 LuaBindings::dsp (lua_State* L)
796 luabridge::getGlobalNamespace (L)
797 .beginNamespace ("ARDOUR")
799 .beginClass <AudioBuffer> ("AudioBuffer")
800 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
801 .addFunction ("silence", &AudioBuffer::silence)
802 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
803 .addFunction ("check_silence", &AudioBuffer::check_silence)
804 .addFunction ("read_from", (void (AudioBuffer::*)(const Sample*, framecnt_t, framecnt_t, framecnt_t))&AudioBuffer::check_silence)
807 .beginClass <MidiBuffer> ("MidiBuffer")
808 .addFunction ("silence", &MidiBuffer::silence)
809 .addFunction ("empty", &MidiBuffer::empty)
813 .beginClass <BufferSet> ("BufferSet")
814 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
815 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
819 luabridge::getGlobalNamespace (L)
820 .beginNamespace ("Evoral")
821 .beginClass <Evoral::Event<framepos_t> > ("Event")
822 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
823 .addFunction ("size", &Evoral::Event<framepos_t>::size)
824 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
825 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
828 .beginClass <Evoral::Beats> ("Beats")
829 .addFunction ("to_double", &Evoral::Beats::to_double)
832 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
834 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
835 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
836 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
837 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
841 // dsp releated session functions
842 luabridge::getGlobalNamespace (L)
843 .beginNamespace ("ARDOUR")
844 .beginClass <Session> ("Session")
845 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
846 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
850 luabridge::getGlobalNamespace (L)
851 .beginNamespace ("ARDOUR")
852 .beginNamespace ("DSP")
853 .addFunction ("compute_peak", ARDOUR::compute_peak)
854 .addFunction ("find_peaks", ARDOUR::find_peaks)
855 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
856 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
857 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
858 .addFunction ("copy_vector", ARDOUR::copy_vector)
859 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
860 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
861 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
862 .addFunction ("memset", &DSP::memset)
863 .addFunction ("mmult", &DSP::mmult)
864 .addFunction ("log_meter", &DSP::log_meter)
865 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
866 .addRefFunction ("peaks", &DSP::peaks)
868 .beginClass <DSP::LowPass> ("LowPass")
869 .addConstructor <void (*) (double, float)> ()
870 .addFunction ("proc", &DSP::LowPass::proc)
871 .addFunction ("ctrl", &DSP::LowPass::ctrl)
872 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
873 .addFunction ("reset", &DSP::LowPass::reset)
875 .beginClass <DSP::BiQuad> ("Biquad")
876 .addConstructor <void (*) (double)> ()
877 .addFunction ("run", &DSP::BiQuad::run)
878 .addFunction ("compute", &DSP::BiQuad::compute)
879 .addFunction ("reset", &DSP::BiQuad::reset)
883 .beginNamespace ("BiQuadType")
884 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
885 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
886 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
887 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
888 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
889 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
890 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
891 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
892 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
895 .beginClass <DSP::DspShm> ("DspShm")
896 .addFunction ("allocate", &DSP::DspShm::allocate)
897 .addFunction ("clear", &DSP::DspShm::clear)
898 .addFunction ("to_float", &DSP::DspShm::to_float)
899 .addFunction ("to_int", &DSP::DspShm::to_int)
900 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
901 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
904 .endNamespace () // DSP
905 .endNamespace (); // ARDOUR
909 LuaBindings::session (lua_State* L)
911 // non-realtime session functions
912 luabridge::getGlobalNamespace (L)
913 .beginNamespace ("ARDOUR")
914 .beginClass <Session> ("Session")
915 .addFunction ("save_state", &Session::save_state)
916 .addFunction ("set_dirty", &Session::set_dirty)
917 .addFunction ("unknown_processors", &Session::unknown_processors)
919 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
920 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
921 //.addFunction ("new_midi_track", &Session::new_midi_track)
924 .endNamespace (); // ARDOUR
928 LuaBindings::osc (lua_State* L)
930 luabridge::getGlobalNamespace (L)
931 .beginNamespace ("ARDOUR")
932 .beginNamespace ("LuaOSC")
933 .beginClass<LuaOSC::Address> ("Address")
934 .addConstructor<void (*) (std::string)> ()
935 .addCFunction ("send", &LuaOSC::Address::send)
942 LuaBindings::set_session (lua_State* L, Session *s)
944 /* LuaBridge uses unique keys to identify classes/c-types.
946 * Those keys are "generated" by using the memory-address of a static
947 * variable, templated for every Class.
948 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
950 * When linking the final executable there must be exactly one static
951 * function (static variable) for every templated class.
952 * This works fine on OSX and Linux...
954 * Windows (mingw and MSVC) however expand the template differently for libardour
955 * AND gtk2_ardour. We end up with two identical static functions
956 * at different addresses!!
958 * The Solution: have gtk2_ardour never include LuaBridge headers directly
959 * and always go via libardour function calls for classes that are registered
960 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
961 * which expand the template is not)
963 * (the actual cause: even static symbols in a .dll have no fixed address
964 * and are mapped when loading the dll. static functions in .exe do have a fixed
968 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
969 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
970 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
973 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
974 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
975 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
979 luabridge::push <Session *> (L, s);
980 lua_setglobal (L, "Session");
983 // call lua function.
984 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
985 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args