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.
19 #include "timecode/bbt_time.h"
20 #include "evoral/Control.hpp"
21 #include "evoral/ControlList.hpp"
23 #include "ardour/audioengine.h"
24 #include "ardour/audiosource.h"
25 #include "ardour/audio_backend.h"
26 #include "ardour/audio_buffer.h"
27 #include "ardour/audio_track.h"
28 #include "ardour/buffer_set.h"
29 #include "ardour/chan_mapping.h"
30 #include "ardour/dB.h"
31 #include "ardour/dsp_filter.h"
32 #include "ardour/lua_api.h"
33 #include "ardour/luabindings.h"
34 #include "ardour/meter.h"
35 #include "ardour/midi_track.h"
36 #include "ardour/plugin.h"
37 #include "ardour/plugin_insert.h"
38 #include "ardour/runtime_functions.h"
39 #include "ardour/region.h"
40 #include "ardour/region_factory.h"
41 #include "ardour/session.h"
42 #include "ardour/session_object.h"
43 #include "ardour/sidechain.h"
44 #include "ardour/tempo.h"
46 #include "LuaBridge/LuaBridge.h"
48 /* Some notes on Lua bindings for libardour and friends
50 * - Prefer factory methods over Contructors whenever possible.
51 * Don't expose the constructor method unless required.
53 * e.g. Don't allow the script to construct a "Track" Object directly
54 * but do allow to create a "BBT_TIME" object.
56 * - Do not dereference Shared or Weak Pointers. Pass the pointer to Lua.
57 * - Define Objects as boost:shared_ptr Object whenever possible.
59 * Storing a boost::shared_ptr in a Lua-variable keeps the reference
60 * until that variable is set to 'nil'.
61 * (if the script were to keep a direct pointer to the object instance, the
62 * behaviour is undefined if the actual object goes away)
64 * Methods of the actual class are indirectly exposed,
65 * boost::*_ptr get() and ::lock() is implicit when the class is exported
66 * as LuaBridge's "WSPtrClass".
69 using namespace ARDOUR;
72 LuaBindings::stddef (lua_State* L)
74 // std::list<std::string>
75 luabridge::getGlobalNamespace (L)
77 .beginStdList <std::string> ("StringList")
80 // std::vector<std::string>
81 .beginStdVector <std::string> ("StringVector")
84 // register float array (float*)
85 .registerArray <float> ("FloatArray")
87 // register float array (int32_t*)
88 .registerArray <int32_t> ("IntArray")
95 LuaBindings::common (lua_State* L)
97 luabridge::getGlobalNamespace (L)
98 .beginNamespace ("PBD")
99 .beginClass <PBD::ID> ("ID")
100 .addConstructor <void (*) (std::string)> ()
101 .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
104 .beginClass <PBD::Stateful> ("Stateful")
105 .addFunction ("properties", &PBD::Stateful::properties)
108 .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
111 .beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
112 .addFunction ("properties", &PBD::Stateful::properties)
115 .deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructiblePtr")
118 .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
119 .addFunction ("get_value", &PBD::Controllable::get_value)
122 .beginNamespace ("GroupControlDisposition")
123 .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
124 .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
125 .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
128 .endNamespace (); // PBD
130 luabridge::getGlobalNamespace (L)
131 .beginNamespace ("Timecode")
132 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
133 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
137 luabridge::getGlobalNamespace (L)
139 .beginNamespace ("Evoral")
140 .beginClass <Evoral::Parameter> ("Parameter")
141 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
142 .addFunction ("type", &Evoral::Parameter::type)
143 .addFunction ("channel", &Evoral::Parameter::channel)
144 .addFunction ("id", &Evoral::Parameter::id)
147 .beginWSPtrClass <Evoral::ControlList> ("ControlList")
148 .addFunction ("add", &Evoral::ControlList::add)
151 .beginWSPtrClass <Evoral::ControlSet> ("ControlSet")
154 .beginWSPtrClass <Evoral::Control> ("Control")
155 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
158 .beginClass <Evoral::ParameterDescriptor> ("ParameterDescriptor")
159 .addVoidConstructor ()
160 .addData ("lower", &Evoral::ParameterDescriptor::lower)
161 .addData ("upper", &Evoral::ParameterDescriptor::upper)
162 .addData ("normal", &Evoral::ParameterDescriptor::normal)
163 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
166 .endNamespace () // Evoral
168 .beginNamespace ("ARDOUR")
169 .beginWSPtrClass <PluginInfo> ("PluginInfo")
170 .addVoidConstructor ()
173 .beginNamespace ("Route")
174 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
175 .addVoidConstructor ()
179 .beginClass <ChanMapping> ("ChanMapping")
180 .addVoidConstructor ()
181 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t) const>(&ChanMapping::get))
182 .addFunction ("set", &ChanMapping::set)
183 .addConst ("Invalid", 4294967295) // UINT32_MAX
186 .beginNamespace ("Properties")
187 // templated class definitions
188 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
189 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
190 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
191 // actual references (TODO: also expose GQuark for std::set)
193 .addConst ("Start", &ARDOUR::Properties::start)
194 .addConst ("Length", &ARDOUR::Properties::length)
195 .addConst ("Position", &ARDOUR::Properties::position)
198 .beginClass <PBD::PropertyChange> ("PropertyChange")
199 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
200 // -> direct map to lua table beginStdSet()A
202 // expand templated PropertyDescriptor<T>
203 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
204 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
205 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
208 .beginClass <PBD::PropertyList> ("PropertyList")
209 // is-a std::map<PropertyID, PropertyBase*>
212 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
215 .deriveClass <Location, PBD::StatefulDestructible> ("Location")
216 .addFunction ("locked", &Location::locked)
217 .addFunction ("lock", &Location::lock)
218 .addFunction ("start", &Location::start)
219 .addFunction ("end", &Location::end)
220 .addFunction ("length", &Location::length)
221 .addFunction ("set_start", &Location::set_start)
222 .addFunction ("set_end", &Location::set_end)
223 .addFunction ("set_length", &Location::set)
224 .addFunction ("move_to", &Location::move_to)
227 .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
228 .addFunction ("name", &SessionObject::name)
231 .deriveWSPtrClass <IO, SessionObject> ("IO")
232 .addFunction ("active", &IO::active)
233 .addFunction ("add_port", &IO::add_port)
234 .addFunction ("remove_port", &IO::remove_port)
235 .addFunction ("connect", &IO::connect)
236 .addFunction ("disconnect", (int (IO::*)(boost::shared_ptr<Port>, std::string, void *))&IO::disconnect)
237 .addFunction ("physically_connected", &IO::physically_connected)
240 .deriveWSPtrClass <Route, SessionObject> ("Route")
241 .addFunction ("set_name", &Route::set_name)
242 .addFunction ("comment", &Route::comment)
243 .addFunction ("active", &Route::active)
244 .addFunction ("set_active", &Route::set_active)
245 .addFunction ("nth_plugin", &Route::nth_plugin)
246 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
247 .addFunction ("remove_processor", &Route::remove_processor)
248 .addFunction ("replace_processor", &Route::replace_processor)
249 .addFunction ("n_inputs", &Route::n_inputs)
250 .addFunction ("n_outputs", &Route::n_outputs)
251 .addFunction ("set_comment", &Route::set_comment)
252 .addFunction ("strict_io", &Route::strict_io)
253 .addFunction ("set_strict_io", &Route::set_strict_io)
254 .addFunction ("reset_plugin_insert", &Route::reset_plugin_insert)
255 .addFunction ("customize_plugin_insert", &Route::customize_plugin_insert)
256 .addFunction ("add_sidechain", &Route::add_sidechain)
257 .addFunction ("remove_sidechain", &Route::remove_sidechain)
260 .deriveWSPtrClass <Track, Route> ("Track")
261 .addFunction ("set_name", &Track::set_name)
262 .addFunction ("can_record", &Track::can_record)
263 .addFunction ("record_enabled", &Track::record_enabled)
264 .addFunction ("record_safe", &Track::record_safe)
265 .addFunction ("set_record_enabled", &Track::set_record_enabled)
266 .addFunction ("set_record_safe", &Track::set_record_safe)
269 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
272 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
275 .deriveWSPtrClass <Region, SessionObject> ("Region")
277 .addFunction ("position", &Region::position)
278 .addFunction ("start", &Region::start)
279 .addFunction ("length", &Region::length)
280 .addFunction ("layer", &Region::layer)
281 .addFunction ("data_type", &Region::data_type)
282 .addFunction ("stretch", &Region::stretch)
283 .addFunction ("shift", &Region::shift)
284 .addRefFunction ("sync_offset", &Region::sync_offset)
285 .addFunction ("sync_position", &Region::sync_position)
286 .addFunction ("hidden", &Region::hidden)
287 .addFunction ("muted", &Region::muted)
288 .addFunction ("opaque", &Region::opaque)
289 .addFunction ("locked", &Region::locked)
290 .addFunction ("position_locked", &Region::position_locked)
291 .addFunction ("video_locked", &Region::video_locked)
292 .addFunction ("valid_transients", &Region::valid_transients)
293 .addFunction ("automatic", &Region::automatic)
294 .addFunction ("whole_file", &Region::whole_file)
295 .addFunction ("captured", &Region::captured)
296 .addFunction ("can_move", &Region::can_move)
297 .addFunction ("sync_marked", &Region::sync_marked)
298 .addFunction ("external", &Region::external)
299 .addFunction ("import", &Region::import)
300 .addFunction ("covers", &Region::covers)
301 .addFunction ("at_natural_position", &Region::at_natural_position)
302 .addFunction ("is_compound", &Region::is_compound)
303 /* editing operations */
304 .addFunction ("set_length", &Region::set_length)
305 .addFunction ("set_start", &Region::set_start)
306 .addFunction ("set_position", &Region::set_position)
307 .addFunction ("set_initial_position", &Region::set_initial_position)
308 .addFunction ("nudge_position", &Region::nudge_position)
309 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
310 .addFunction ("move_start", &Region::move_start)
311 .addFunction ("trim_front", &Region::trim_front)
312 .addFunction ("trim_end", &Region::trim_end)
313 .addFunction ("trim_to", &Region::trim_to)
314 .addFunction ("cut_front", &Region::cut_front)
315 .addFunction ("cut_end", &Region::cut_end)
316 .addFunction ("raise", &Region::raise)
317 .addFunction ("lower", &Region::lower)
318 .addFunction ("raise_to_top", &Region::raise_to_top)
319 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
320 .addFunction ("set_sync_position", &Region::set_sync_position)
321 .addFunction ("clear_sync_position", &Region::clear_sync_position)
322 .addFunction ("set_hidden", &Region::set_hidden)
323 .addFunction ("set_muted", &Region::set_muted)
324 .addFunction ("set_opaque", &Region::set_opaque)
325 .addFunction ("set_locked", &Region::set_locked)
326 .addFunction ("set_video_locked", &Region::set_video_locked)
327 .addFunction ("set_position_locked", &Region::set_position_locked)
330 .beginWSPtrClass <Source> ("Source")
333 .beginClass <Plugin::PresetRecord> ("PresetRecord")
334 .addData ("uri", &Plugin::PresetRecord::uri, false)
335 .addData ("label", &Plugin::PresetRecord::label, false)
336 .addData ("user", &Plugin::PresetRecord::user, false)
337 .addData ("valid", &Plugin::PresetRecord::valid, false)
340 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
341 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
344 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
345 .addVoidConstructor ()
346 .addData ("label", &ParameterDescriptor::label)
347 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
350 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
351 // TODO mult. inheritance
354 .deriveWSPtrClass <Processor, Automatable> ("Processor")
355 .addCast<PluginInsert> ("to_insert")
356 .addCast<SideChain> ("to_sidechain")
357 .addCast<IOProcessor> ("to_ioprocessor")
358 .addFunction ("display_name", &Processor::display_name)
359 .addFunction ("active", &Processor::active)
360 .addFunction ("activate", &Processor::activate)
361 .addFunction ("deactivate", &Processor::deactivate)
362 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
363 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
366 .deriveWSPtrClass <IOProcessor, Processor> ("IOProcessor")
367 .addFunction ("natural_input_streams", &IOProcessor::natural_input_streams)
368 .addFunction ("natural_output_streams", &IOProcessor::natural_output_streams)
369 .addFunction ("input", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::input)
370 .addFunction ("output", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::output)
373 .deriveWSPtrClass <SideChain, IOProcessor> ("SideChain")
376 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("Plugin")
377 .addFunction ("label", &Plugin::label)
378 .addFunction ("name", &Plugin::name)
379 .addFunction ("maker", &Plugin::maker)
380 .addFunction ("parameter_count", &Plugin::parameter_count)
381 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
382 .addFunction ("preset_by_label", &Plugin::preset_by_label)
383 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
384 .addFunction ("load_preset", &Plugin::load_preset)
385 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
386 .addFunction ("get_docs", &Plugin::get_docs)
387 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
388 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
391 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
392 .addFunction ("plugin", &PluginInsert::plugin)
393 .addFunction ("activate", &PluginInsert::activate)
394 .addFunction ("deactivate", &PluginInsert::deactivate)
395 .addFunction ("strict_io_configured", &PluginInsert::strict_io_configured)
396 .addFunction ("input_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::input_map)
397 .addFunction ("output_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::output_map)
398 .addFunction ("set_input_map", &PluginInsert::set_input_map)
399 .addFunction ("set_output_map", &PluginInsert::set_output_map)
403 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
404 .addFunction ("automation_state", &AutomationControl::automation_state)
405 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
406 .addFunction ("start_touch", &AutomationControl::start_touch)
407 .addFunction ("stop_touch", &AutomationControl::stop_touch)
408 .addFunction ("get_value", &AutomationControl::get_value)
409 .addFunction ("set_value", &AutomationControl::set_value)
410 .addFunction ("writable", &AutomationControl::writable)
413 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
416 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
417 .addFunction ("readable_length", &AudioSource::readable_length)
418 .addFunction ("n_channels", &AudioSource::n_channels)
421 // <std::list<boost::shared_ptr <AudioTrack> >
422 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
425 // std::list<boost::shared_ptr <MidiTrack> >
426 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
429 // RouteList == std::list<boost::shared_ptr<Route> >
430 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
433 // boost::shared_ptr<RouteList>
434 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
437 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
438 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
441 // std::list< boost::weak_ptr <AudioSource>
442 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
445 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
446 // typedef Evoral::Note<Evoral::Beats> Note;
447 // std::set< boost::weak_ptr<Note> >
448 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
452 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
453 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
456 // std::list<boost::weak_ptr<Source> >
457 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
460 .beginClass <Tempo> ("Tempo")
461 .addConstructor <void (*) (double, double)> ()
462 .addFunction ("note_type", &Tempo::note_type)
463 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
464 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
467 .beginClass <Meter> ("Meter")
468 .addConstructor <void (*) (double, double)> ()
469 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
470 .addFunction ("note_divisor", &Meter::note_divisor)
471 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
472 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
475 .beginClass <TempoMap> ("TempoMap")
476 .addFunction ("add_tempo", &TempoMap::add_tempo)
477 .addFunction ("add_meter", &TempoMap::add_meter)
480 .beginClass <ChanCount> ("ChanCount")
481 .addConstructor <void (*) (DataType, uint32_t)> ()
482 .addFunction ("get", &ChanCount::get)
483 .addFunction ("set", &ChanCount::set)
484 .addFunction ("n_audio", &ChanCount::n_audio)
485 .addFunction ("n_midi", &ChanCount::n_midi)
486 .addFunction ("n_total", &ChanCount::n_total)
487 .addFunction ("reset", &ChanCount::reset)
490 .beginClass <DataType> ("DataType")
491 .addConstructor <void (*) (std::string)> ()
492 .addStaticCFunction ("null", &LuaAPI::datatype_ctor_nil) // "nil" is a lua reseved word
493 .addStaticCFunction ("audio", &LuaAPI::datatype_ctor_audio)
494 .addStaticCFunction ("midi", &LuaAPI::datatype_ctor_midi)
497 /* libardour enums */
498 .beginNamespace ("PluginType")
499 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
500 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
501 .addConst ("LV2", ARDOUR::PluginType(LV2))
502 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
503 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
504 .addConst ("Lua", ARDOUR::PluginType(Lua))
507 .beginNamespace ("AutoStyle")
508 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
509 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
512 .beginNamespace ("AutoState")
513 .addConst ("Off", ARDOUR::AutoState(Off))
514 .addConst ("Write", ARDOUR::AutoState(Write))
515 .addConst ("Touch", ARDOUR::AutoState(Touch))
516 .addConst ("Play", ARDOUR::AutoState(Play))
519 .beginNamespace ("AutomationType")
520 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
523 .beginNamespace ("SrcQuality")
524 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
527 .beginNamespace ("PlaylistDisposition")
528 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
529 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
530 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
533 luabridge::getGlobalNamespace (L)
534 .beginNamespace ("ARDOUR")
535 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
536 .addData ("name", &AudioBackendInfo::name)
538 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
540 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
541 .addData ("name", &AudioBackend::DeviceStatus::name)
542 .addData ("available", &AudioBackend::DeviceStatus::available)
544 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
546 .beginWSPtrClass <AudioBackend> ("AudioBackend")
547 .addFunction ("info", &AudioBackend::info)
548 .addFunction ("sample_rate", &AudioBackend::sample_rate)
549 .addFunction ("buffer_size", &AudioBackend::buffer_size)
550 .addFunction ("period_size", &AudioBackend::period_size)
551 .addFunction ("input_channels", &AudioBackend::input_channels)
552 .addFunction ("output_channels", &AudioBackend::output_channels)
553 .addFunction ("dsp_load", &AudioBackend::dsp_load)
555 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
556 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
557 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
559 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
560 .addFunction ("driver_name", &AudioBackend::driver_name)
561 .addFunction ("set_driver", &AudioBackend::set_driver)
563 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
564 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
565 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
566 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
567 .addFunction ("device_name", &AudioBackend::device_name)
568 .addFunction ("input_device_name", &AudioBackend::input_device_name)
569 .addFunction ("output_device_name", &AudioBackend::output_device_name)
570 .addFunction ("set_device_name", &AudioBackend::set_device_name)
571 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
572 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
575 .beginClass <AudioEngine> ("AudioEngine")
576 .addFunction ("available_backends", &AudioEngine::available_backends)
577 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
578 .addFunction ("set_backend", &AudioEngine::set_backend)
579 .addFunction ("setup_required", &AudioEngine::setup_required)
580 .addFunction ("start", &AudioEngine::start)
581 .addFunction ("stop", &AudioEngine::stop)
582 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
583 .addFunction ("set_device_name", &AudioEngine::set_device_name)
584 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
585 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
586 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
590 // basic representation of Session
591 // functions which can be used from realtime and non-realtime contexts
592 luabridge::getGlobalNamespace (L)
593 .beginNamespace ("ARDOUR")
594 .beginClass <Session> ("Session")
595 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
596 .addFunction ("transport_rolling", &Session::transport_rolling)
597 .addFunction ("request_transport_speed", &Session::request_transport_speed)
598 .addFunction ("transport_frame", &Session::transport_frame)
599 .addFunction ("transport_speed", &Session::transport_speed)
600 .addFunction ("frame_rate", &Session::frame_rate)
601 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
602 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
603 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
604 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
605 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
606 .addFunction ("request_locate", &Session::request_locate)
607 .addFunction ("request_stop", &Session::request_stop)
608 .addFunction ("last_transport_start", &Session::last_transport_start)
609 .addFunction ("goto_start", &Session::goto_start)
610 .addFunction ("goto_end", &Session::goto_end)
611 .addFunction ("current_start_frame", &Session::current_start_frame)
612 .addFunction ("current_end_frame", &Session::current_end_frame)
613 .addFunction ("actively_recording", &Session::actively_recording)
614 .addFunction ("get_routes", &Session::get_routes)
615 .addFunction ("get_tracks", &Session::get_tracks)
616 .addFunction ("name", &Session::name)
617 .addFunction ("path", &Session::path)
618 .addFunction ("record_status", &Session::record_status)
619 .addFunction ("route_by_id", &Session::route_by_id)
620 .addFunction ("route_by_name", &Session::route_by_name)
621 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
622 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
623 .addFunction ("source_by_id", &Session::source_by_id)
624 .addFunction ("controllable_by_id", &Session::controllable_by_id)
625 .addFunction ("processor_by_id", &Session::processor_by_id)
626 .addFunction ("snap_name", &Session::snap_name)
627 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
630 .beginClass <RegionFactory> ("RegionFactory")
631 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
635 .beginNamespace ("Session")
637 .beginNamespace ("RecordState")
638 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
639 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
640 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
643 .endNamespace () // END Session enums
645 .beginNamespace ("LuaAPI")
646 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
647 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
648 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
649 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
650 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
653 .endNamespace ();// END ARDOUR
657 LuaBindings::dsp (lua_State* L)
659 luabridge::getGlobalNamespace (L)
660 .beginNamespace ("ARDOUR")
662 .beginClass <AudioBuffer> ("AudioBuffer")
663 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
664 .addFunction ("silence", &AudioBuffer::silence)
665 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
668 .beginClass <MidiBuffer> ("MidiBuffer")
669 .addFunction ("silence", &MidiBuffer::silence)
670 .addFunction ("empty", &MidiBuffer::empty)
674 .beginClass <BufferSet> ("BufferSet")
675 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
676 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
680 luabridge::getGlobalNamespace (L)
681 .beginNamespace ("Evoral")
682 .beginClass <Evoral::Event<framepos_t> > ("Event")
683 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
684 .addFunction ("size", &Evoral::Event<framepos_t>::size)
685 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
686 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
689 .beginClass <Evoral::Beats> ("Beats")
690 .addFunction ("to_double", &Evoral::Beats::to_double)
693 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
695 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
696 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
697 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
698 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
702 // dsp releated session functions
703 luabridge::getGlobalNamespace (L)
704 .beginNamespace ("ARDOUR")
705 .beginClass <Session> ("Session")
706 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
707 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
711 luabridge::getGlobalNamespace (L)
712 .beginNamespace ("ARDOUR")
713 .beginNamespace ("DSP")
714 .addFunction ("compute_peak", ARDOUR::compute_peak)
715 .addFunction ("find_peaks", ARDOUR::find_peaks)
716 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
717 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
718 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
719 .addFunction ("copy_vector", ARDOUR::copy_vector)
720 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
721 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
722 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
723 .addFunction ("memset", &DSP::memset)
724 .addFunction ("mmult", &DSP::mmult)
725 .addFunction ("log_meter", &DSP::log_meter)
726 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
727 .addRefFunction ("peaks", &DSP::peaks)
729 .beginClass <DSP::LowPass> ("LowPass")
730 .addConstructor <void (*) (double, float)> ()
731 .addFunction ("proc", &DSP::LowPass::proc)
732 .addFunction ("ctrl", &DSP::LowPass::ctrl)
733 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
734 .addFunction ("reset", &DSP::LowPass::reset)
736 .beginClass <DSP::BiQuad> ("Biquad")
737 .addConstructor <void (*) (double)> ()
738 .addFunction ("run", &DSP::BiQuad::run)
739 .addFunction ("compute", &DSP::BiQuad::compute)
740 .addFunction ("reset", &DSP::BiQuad::reset)
744 .beginNamespace ("BiQuadType")
745 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
746 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
747 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
748 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
749 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
750 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
751 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
752 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
753 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
756 .beginClass <DSP::DspShm> ("DspShm")
757 .addFunction ("allocate", &DSP::DspShm::allocate)
758 .addFunction ("clear", &DSP::DspShm::clear)
759 .addFunction ("to_float", &DSP::DspShm::to_float)
760 .addFunction ("to_int", &DSP::DspShm::to_int)
761 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
762 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
765 .endNamespace () // DSP
766 .endNamespace (); // ARDOUR
770 LuaBindings::session (lua_State* L)
772 // non-realtime session functions
773 luabridge::getGlobalNamespace (L)
774 .beginNamespace ("ARDOUR")
775 .beginClass <Session> ("Session")
776 .addFunction ("save_state", &Session::save_state)
777 .addFunction ("set_dirty", &Session::set_dirty)
778 .addFunction ("unknown_processors", &Session::unknown_processors)
780 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
781 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
782 //.addFunction ("new_midi_track", &Session::new_midi_track)
785 .endNamespace (); // ARDOUR
789 LuaBindings::osc (lua_State* L)
791 luabridge::getGlobalNamespace (L)
792 .beginNamespace ("ARDOUR")
793 .beginNamespace ("LuaOSC")
794 .beginClass<LuaOSC::Address> ("Address")
795 .addConstructor<void (*) (std::string)> ()
796 .addCFunction ("send", &LuaOSC::Address::send)
803 LuaBindings::set_session (lua_State* L, Session *s)
805 /* LuaBridge uses unique keys to identify classes/c-types.
807 * Those keys are "generated" by using the memory-address of a static
808 * variable, templated for every Class.
809 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
811 * When linking the final executable there must be exactly one static
812 * function (static variable) for every templated class.
813 * This works fine on OSX and Linux...
815 * Windows (mingw and MSVC) however expand the template differently for libardour
816 * AND gtk2_ardour. We end up with two identical static functions
817 * at different addresses!!
819 * The Solution: have gtk2_ardour never include LuaBridge headers directly
820 * and always go via libardour function calls for classes that are registered
821 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
822 * which expand the template is not)
824 * (the actual cause: even static symbols in a .dll have no fixed address
825 * and are mapped when loading the dll. static functions in .exe do have a fixed
829 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
830 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
831 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
834 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
835 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
836 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
840 luabridge::push <Session *> (L, s);
841 lua_setglobal (L, "Session");
844 // call lua function.
845 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
846 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args