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")
90 // std::vector<std::string>
91 .beginStdVector <double> ("DoubleVector")
99 LuaBindings::common (lua_State* L)
101 luabridge::getGlobalNamespace (L)
102 .beginNamespace ("PBD")
103 .beginClass <PBD::ID> ("ID")
104 .addConstructor <void (*) (std::string)> ()
105 .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
108 .beginClass <PBD::Stateful> ("Stateful")
109 .addFunction ("properties", &PBD::Stateful::properties)
112 .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
115 .beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
116 .addFunction ("properties", &PBD::Stateful::properties)
119 .deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructiblePtr")
122 .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
123 .addFunction ("get_value", &PBD::Controllable::get_value)
126 .beginNamespace ("GroupControlDisposition")
127 .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
128 .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
129 .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
132 .endNamespace (); // PBD
134 luabridge::getGlobalNamespace (L)
135 .beginNamespace ("Timecode")
136 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
137 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
141 luabridge::getGlobalNamespace (L)
143 .beginNamespace ("Evoral")
144 .beginClass <Evoral::Parameter> ("Parameter")
145 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
146 .addFunction ("type", &Evoral::Parameter::type)
147 .addFunction ("channel", &Evoral::Parameter::channel)
148 .addFunction ("id", &Evoral::Parameter::id)
151 .beginWSPtrClass <Evoral::ControlList> ("ControlList")
152 .addFunction ("add", &Evoral::ControlList::add)
155 .beginWSPtrClass <Evoral::ControlSet> ("ControlSet")
158 .beginWSPtrClass <Evoral::Control> ("Control")
159 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
162 .beginClass <Evoral::ParameterDescriptor> ("ParameterDescriptor")
163 .addVoidConstructor ()
164 .addData ("lower", &Evoral::ParameterDescriptor::lower)
165 .addData ("upper", &Evoral::ParameterDescriptor::upper)
166 .addData ("normal", &Evoral::ParameterDescriptor::normal)
167 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
170 .endNamespace () // Evoral
172 .beginNamespace ("ARDOUR")
173 .beginWSPtrClass <PluginInfo> ("PluginInfo")
174 .addVoidConstructor ()
177 .beginNamespace ("Route")
178 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
179 .addVoidConstructor ()
183 .beginClass <ChanMapping> ("ChanMapping")
184 .addVoidConstructor ()
185 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t) const>(&ChanMapping::get))
186 .addFunction ("set", &ChanMapping::set)
187 .addConst ("Invalid", 4294967295) // UINT32_MAX
190 .beginNamespace ("Properties")
191 // templated class definitions
192 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
193 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
194 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
195 // actual references (TODO: also expose GQuark for std::set)
197 .addConst ("Start", &ARDOUR::Properties::start)
198 .addConst ("Length", &ARDOUR::Properties::length)
199 .addConst ("Position", &ARDOUR::Properties::position)
202 .beginClass <PBD::PropertyChange> ("PropertyChange")
203 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
204 // -> direct map to lua table beginStdSet()A
206 // expand templated PropertyDescriptor<T>
207 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
208 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
209 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
212 .beginClass <PBD::PropertyList> ("PropertyList")
213 // is-a std::map<PropertyID, PropertyBase*>
216 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
219 .deriveClass <Location, PBD::StatefulDestructible> ("Location")
220 .addFunction ("locked", &Location::locked)
221 .addFunction ("lock", &Location::lock)
222 .addFunction ("start", &Location::start)
223 .addFunction ("end", &Location::end)
224 .addFunction ("length", &Location::length)
225 .addFunction ("set_start", &Location::set_start)
226 .addFunction ("set_end", &Location::set_end)
227 .addFunction ("set_length", &Location::set)
228 .addFunction ("move_to", &Location::move_to)
231 .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
232 .addFunction ("name", &SessionObject::name)
235 .deriveWSPtrClass <IO, SessionObject> ("IO")
236 .addFunction ("active", &IO::active)
237 .addFunction ("add_port", &IO::add_port)
238 .addFunction ("remove_port", &IO::remove_port)
239 .addFunction ("connect", &IO::connect)
240 .addFunction ("disconnect", (int (IO::*)(boost::shared_ptr<Port>, std::string, void *))&IO::disconnect)
241 .addFunction ("physically_connected", &IO::physically_connected)
244 .deriveWSPtrClass <Route, SessionObject> ("Route")
245 .addFunction ("set_name", &Route::set_name)
246 .addFunction ("comment", &Route::comment)
247 .addFunction ("active", &Route::active)
248 .addFunction ("set_active", &Route::set_active)
249 .addFunction ("nth_plugin", &Route::nth_plugin)
250 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
251 .addFunction ("remove_processor", &Route::remove_processor)
252 .addFunction ("replace_processor", &Route::replace_processor)
253 .addFunction ("n_inputs", &Route::n_inputs)
254 .addFunction ("n_outputs", &Route::n_outputs)
255 .addFunction ("set_comment", &Route::set_comment)
256 .addFunction ("strict_io", &Route::strict_io)
257 .addFunction ("set_strict_io", &Route::set_strict_io)
258 .addFunction ("reset_plugin_insert", &Route::reset_plugin_insert)
259 .addFunction ("customize_plugin_insert", &Route::customize_plugin_insert)
262 .deriveWSPtrClass <Track, Route> ("Track")
263 .addFunction ("set_name", &Track::set_name)
264 .addFunction ("can_record", &Track::can_record)
265 .addFunction ("record_enabled", &Track::record_enabled)
266 .addFunction ("record_safe", &Track::record_safe)
267 .addFunction ("set_record_enabled", &Track::set_record_enabled)
268 .addFunction ("set_record_safe", &Track::set_record_safe)
271 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
274 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
277 .deriveWSPtrClass <Region, SessionObject> ("Region")
279 .addFunction ("position", &Region::position)
280 .addFunction ("start", &Region::start)
281 .addFunction ("length", &Region::length)
282 .addFunction ("layer", &Region::layer)
283 .addFunction ("data_type", &Region::data_type)
284 .addFunction ("stretch", &Region::stretch)
285 .addFunction ("shift", &Region::shift)
286 .addRefFunction ("sync_offset", &Region::sync_offset)
287 .addFunction ("sync_position", &Region::sync_position)
288 .addFunction ("hidden", &Region::hidden)
289 .addFunction ("muted", &Region::muted)
290 .addFunction ("opaque", &Region::opaque)
291 .addFunction ("locked", &Region::locked)
292 .addFunction ("position_locked", &Region::position_locked)
293 .addFunction ("video_locked", &Region::video_locked)
294 .addFunction ("valid_transients", &Region::valid_transients)
295 .addFunction ("automatic", &Region::automatic)
296 .addFunction ("whole_file", &Region::whole_file)
297 .addFunction ("captured", &Region::captured)
298 .addFunction ("can_move", &Region::can_move)
299 .addFunction ("sync_marked", &Region::sync_marked)
300 .addFunction ("external", &Region::external)
301 .addFunction ("import", &Region::import)
302 .addFunction ("covers", &Region::covers)
303 .addFunction ("at_natural_position", &Region::at_natural_position)
304 .addFunction ("is_compound", &Region::is_compound)
305 /* editing operations */
306 .addFunction ("set_length", &Region::set_length)
307 .addFunction ("set_start", &Region::set_start)
308 .addFunction ("set_position", &Region::set_position)
309 .addFunction ("set_initial_position", &Region::set_initial_position)
310 .addFunction ("nudge_position", &Region::nudge_position)
311 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
312 .addFunction ("move_start", &Region::move_start)
313 .addFunction ("trim_front", &Region::trim_front)
314 .addFunction ("trim_end", &Region::trim_end)
315 .addFunction ("trim_to", &Region::trim_to)
316 .addFunction ("cut_front", &Region::cut_front)
317 .addFunction ("cut_end", &Region::cut_end)
318 .addFunction ("raise", &Region::raise)
319 .addFunction ("lower", &Region::lower)
320 .addFunction ("raise_to_top", &Region::raise_to_top)
321 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
322 .addFunction ("set_sync_position", &Region::set_sync_position)
323 .addFunction ("clear_sync_position", &Region::clear_sync_position)
324 .addFunction ("set_hidden", &Region::set_hidden)
325 .addFunction ("set_muted", &Region::set_muted)
326 .addFunction ("set_opaque", &Region::set_opaque)
327 .addFunction ("set_locked", &Region::set_locked)
328 .addFunction ("set_video_locked", &Region::set_video_locked)
329 .addFunction ("set_position_locked", &Region::set_position_locked)
332 .beginWSPtrClass <Source> ("Source")
335 .beginClass <Plugin::PresetRecord> ("PresetRecord")
336 .addData ("uri", &Plugin::PresetRecord::uri, false)
337 .addData ("label", &Plugin::PresetRecord::label, false)
338 .addData ("user", &Plugin::PresetRecord::user, false)
339 .addData ("valid", &Plugin::PresetRecord::valid, false)
342 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
343 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
346 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
347 .addVoidConstructor ()
348 .addData ("label", &ParameterDescriptor::label)
349 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
352 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
353 // TODO mult. inheritance
356 .deriveWSPtrClass <Processor, Automatable> ("Processor")
357 .addCast<PluginInsert> ("to_insert")
358 .addCast<SideChain> ("to_sidechain")
359 .addCast<IOProcessor> ("to_ioprocessor")
360 .addFunction ("display_name", &Processor::display_name)
361 .addFunction ("active", &Processor::active)
362 .addFunction ("activate", &Processor::activate)
363 .addFunction ("deactivate", &Processor::deactivate)
364 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
365 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
368 .deriveWSPtrClass <IOProcessor, Processor> ("IOProcessor")
369 .addFunction ("natural_input_streams", &IOProcessor::natural_input_streams)
370 .addFunction ("natural_output_streams", &IOProcessor::natural_output_streams)
371 .addFunction ("input", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::input)
372 .addFunction ("output", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::output)
375 .deriveWSPtrClass <SideChain, IOProcessor> ("SideChain")
378 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("Plugin")
379 .addFunction ("label", &Plugin::label)
380 .addFunction ("name", &Plugin::name)
381 .addFunction ("maker", &Plugin::maker)
382 .addFunction ("parameter_count", &Plugin::parameter_count)
383 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
384 .addFunction ("preset_by_label", &Plugin::preset_by_label)
385 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
386 .addFunction ("load_preset", &Plugin::load_preset)
387 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
388 .addFunction ("get_docs", &Plugin::get_docs)
389 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
390 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
393 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
394 .addFunction ("plugin", &PluginInsert::plugin)
395 .addFunction ("activate", &PluginInsert::activate)
396 .addFunction ("deactivate", &PluginInsert::deactivate)
397 .addFunction ("strict_io_configured", &PluginInsert::strict_io_configured)
398 .addFunction ("input_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::input_map)
399 .addFunction ("output_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::output_map)
400 .addFunction ("set_input_map", &PluginInsert::set_input_map)
401 .addFunction ("set_output_map", &PluginInsert::set_output_map)
405 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
406 .addFunction ("automation_state", &AutomationControl::automation_state)
407 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
408 .addFunction ("start_touch", &AutomationControl::start_touch)
409 .addFunction ("stop_touch", &AutomationControl::stop_touch)
410 .addFunction ("get_value", &AutomationControl::get_value)
411 .addFunction ("set_value", &AutomationControl::set_value)
412 .addFunction ("writable", &AutomationControl::writable)
415 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
418 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
419 .addFunction ("readable_length", &AudioSource::readable_length)
420 .addFunction ("n_channels", &AudioSource::n_channels)
423 // <std::list<boost::shared_ptr <AudioTrack> >
424 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
427 // std::list<boost::shared_ptr <MidiTrack> >
428 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
431 // RouteList == std::list<boost::shared_ptr<Route> >
432 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
435 // boost::shared_ptr<RouteList>
436 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
439 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
440 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
443 // std::list< boost::weak_ptr <AudioSource>
444 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
447 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
448 // typedef Evoral::Note<Evoral::Beats> Note;
449 // std::set< boost::weak_ptr<Note> >
450 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
454 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
455 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
458 // std::list<boost::weak_ptr<Source> >
459 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
462 .beginClass <Tempo> ("Tempo")
463 .addConstructor <void (*) (double, double)> ()
464 .addFunction ("note_type", &Tempo::note_type)
465 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
466 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
469 .beginClass <Meter> ("Meter")
470 .addConstructor <void (*) (double, double)> ()
471 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
472 .addFunction ("note_divisor", &Meter::note_divisor)
473 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
474 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
477 .beginClass <TempoMap> ("TempoMap")
478 .addFunction ("add_tempo", &TempoMap::add_tempo)
479 .addFunction ("add_meter", &TempoMap::add_meter)
482 .beginClass <ChanCount> ("ChanCount")
483 .addConstructor <void (*) (DataType, uint32_t)> ()
484 .addFunction ("get", &ChanCount::get)
485 .addFunction ("set", &ChanCount::set)
486 .addFunction ("n_audio", &ChanCount::n_audio)
487 .addFunction ("n_midi", &ChanCount::n_midi)
488 .addFunction ("n_total", &ChanCount::n_total)
489 .addFunction ("reset", &ChanCount::reset)
492 .beginClass <DataType> ("DataType")
493 .addConstructor <void (*) (std::string)> ()
494 .addStaticCFunction ("null", &LuaAPI::datatype_ctor_nil) // "nil" is a lua reseved word
495 .addStaticCFunction ("audio", &LuaAPI::datatype_ctor_audio)
496 .addStaticCFunction ("midi", &LuaAPI::datatype_ctor_midi)
499 /* libardour enums */
500 .beginNamespace ("PluginType")
501 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
502 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
503 .addConst ("LV2", ARDOUR::PluginType(LV2))
504 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
505 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
506 .addConst ("Lua", ARDOUR::PluginType(Lua))
509 .beginNamespace ("AutoStyle")
510 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
511 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
514 .beginNamespace ("AutoState")
515 .addConst ("Off", ARDOUR::AutoState(Off))
516 .addConst ("Write", ARDOUR::AutoState(Write))
517 .addConst ("Touch", ARDOUR::AutoState(Touch))
518 .addConst ("Play", ARDOUR::AutoState(Play))
521 .beginNamespace ("AutomationType")
522 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
525 .beginNamespace ("SrcQuality")
526 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
529 .beginNamespace ("PlaylistDisposition")
530 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
531 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
532 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
535 luabridge::getGlobalNamespace (L)
536 .beginNamespace ("ARDOUR")
537 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
538 .addData ("name", &AudioBackendInfo::name)
540 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
542 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
543 .addData ("name", &AudioBackend::DeviceStatus::name)
544 .addData ("available", &AudioBackend::DeviceStatus::available)
546 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
548 .beginWSPtrClass <AudioBackend> ("AudioBackend")
549 .addFunction ("info", &AudioBackend::info)
550 .addFunction ("sample_rate", &AudioBackend::sample_rate)
551 .addFunction ("buffer_size", &AudioBackend::buffer_size)
552 .addFunction ("period_size", &AudioBackend::period_size)
553 .addFunction ("input_channels", &AudioBackend::input_channels)
554 .addFunction ("output_channels", &AudioBackend::output_channels)
555 .addFunction ("dsp_load", &AudioBackend::dsp_load)
557 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
558 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
559 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
561 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
562 .addFunction ("driver_name", &AudioBackend::driver_name)
563 .addFunction ("set_driver", &AudioBackend::set_driver)
565 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
566 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
567 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
568 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
569 .addFunction ("device_name", &AudioBackend::device_name)
570 .addFunction ("input_device_name", &AudioBackend::input_device_name)
571 .addFunction ("output_device_name", &AudioBackend::output_device_name)
572 .addFunction ("set_device_name", &AudioBackend::set_device_name)
573 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
574 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
577 .beginClass <AudioEngine> ("AudioEngine")
578 .addFunction ("available_backends", &AudioEngine::available_backends)
579 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
580 .addFunction ("set_backend", &AudioEngine::set_backend)
581 .addFunction ("setup_required", &AudioEngine::setup_required)
582 .addFunction ("start", &AudioEngine::start)
583 .addFunction ("stop", &AudioEngine::stop)
584 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
585 .addFunction ("set_device_name", &AudioEngine::set_device_name)
586 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
587 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
588 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
592 // basic representation of Session
593 // functions which can be used from realtime and non-realtime contexts
594 luabridge::getGlobalNamespace (L)
595 .beginNamespace ("ARDOUR")
596 .beginClass <Session> ("Session")
597 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
598 .addFunction ("transport_rolling", &Session::transport_rolling)
599 .addFunction ("request_transport_speed", &Session::request_transport_speed)
600 .addFunction ("transport_frame", &Session::transport_frame)
601 .addFunction ("transport_speed", &Session::transport_speed)
602 .addFunction ("frame_rate", &Session::frame_rate)
603 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
604 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
605 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
606 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
607 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
608 .addFunction ("request_locate", &Session::request_locate)
609 .addFunction ("request_stop", &Session::request_stop)
610 .addFunction ("last_transport_start", &Session::last_transport_start)
611 .addFunction ("goto_start", &Session::goto_start)
612 .addFunction ("goto_end", &Session::goto_end)
613 .addFunction ("current_start_frame", &Session::current_start_frame)
614 .addFunction ("current_end_frame", &Session::current_end_frame)
615 .addFunction ("actively_recording", &Session::actively_recording)
616 .addFunction ("get_routes", &Session::get_routes)
617 .addFunction ("get_tracks", &Session::get_tracks)
618 .addFunction ("name", &Session::name)
619 .addFunction ("path", &Session::path)
620 .addFunction ("record_status", &Session::record_status)
621 .addFunction ("route_by_id", &Session::route_by_id)
622 .addFunction ("route_by_name", &Session::route_by_name)
623 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
624 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
625 .addFunction ("source_by_id", &Session::source_by_id)
626 .addFunction ("controllable_by_id", &Session::controllable_by_id)
627 .addFunction ("processor_by_id", &Session::processor_by_id)
628 .addFunction ("snap_name", &Session::snap_name)
629 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
632 .beginClass <RegionFactory> ("RegionFactory")
633 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
637 .beginNamespace ("Session")
639 .beginNamespace ("RecordState")
640 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
641 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
642 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
645 .endNamespace () // END Session enums
647 .beginNamespace ("LuaAPI")
648 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
649 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
650 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
651 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
652 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
655 .endNamespace ();// END ARDOUR
659 LuaBindings::dsp (lua_State* L)
661 luabridge::getGlobalNamespace (L)
662 .beginNamespace ("ARDOUR")
664 .beginClass <AudioBuffer> ("AudioBuffer")
665 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
666 .addFunction ("silence", &AudioBuffer::silence)
667 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
670 .beginClass <MidiBuffer> ("MidiBuffer")
671 .addFunction ("silence", &MidiBuffer::silence)
672 .addFunction ("empty", &MidiBuffer::empty)
676 .beginClass <BufferSet> ("BufferSet")
677 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
678 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
682 luabridge::getGlobalNamespace (L)
683 .beginNamespace ("Evoral")
684 .beginClass <Evoral::Event<framepos_t> > ("Event")
685 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
686 .addFunction ("size", &Evoral::Event<framepos_t>::size)
687 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
688 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
691 .beginClass <Evoral::Beats> ("Beats")
692 .addFunction ("to_double", &Evoral::Beats::to_double)
695 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
697 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
698 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
699 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
700 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
704 // dsp releated session functions
705 luabridge::getGlobalNamespace (L)
706 .beginNamespace ("ARDOUR")
707 .beginClass <Session> ("Session")
708 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
709 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
713 luabridge::getGlobalNamespace (L)
714 .beginNamespace ("ARDOUR")
715 .beginNamespace ("DSP")
716 .addFunction ("compute_peak", ARDOUR::compute_peak)
717 .addFunction ("find_peaks", ARDOUR::find_peaks)
718 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
719 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
720 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
721 .addFunction ("copy_vector", ARDOUR::copy_vector)
722 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
723 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
724 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
725 .addFunction ("memset", &DSP::memset)
726 .addFunction ("mmult", &DSP::mmult)
727 .addFunction ("log_meter", &DSP::log_meter)
728 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
729 .addRefFunction ("peaks", &DSP::peaks)
731 .beginClass <DSP::LowPass> ("LowPass")
732 .addConstructor <void (*) (double, float)> ()
733 .addFunction ("proc", &DSP::LowPass::proc)
734 .addFunction ("ctrl", &DSP::LowPass::ctrl)
735 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
736 .addFunction ("reset", &DSP::LowPass::reset)
738 .beginClass <DSP::BiQuad> ("Biquad")
739 .addConstructor <void (*) (double)> ()
740 .addFunction ("run", &DSP::BiQuad::run)
741 .addFunction ("compute", &DSP::BiQuad::compute)
742 .addFunction ("reset", &DSP::BiQuad::reset)
746 .beginNamespace ("BiQuadType")
747 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
748 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
749 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
750 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
751 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
752 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
753 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
754 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
755 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
758 .beginClass <DSP::DspShm> ("DspShm")
759 .addFunction ("allocate", &DSP::DspShm::allocate)
760 .addFunction ("clear", &DSP::DspShm::clear)
761 .addFunction ("to_float", &DSP::DspShm::to_float)
762 .addFunction ("to_int", &DSP::DspShm::to_int)
763 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
764 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
767 .endNamespace () // DSP
768 .endNamespace (); // ARDOUR
772 LuaBindings::session (lua_State* L)
774 // non-realtime session functions
775 luabridge::getGlobalNamespace (L)
776 .beginNamespace ("ARDOUR")
777 .beginClass <Session> ("Session")
778 .addFunction ("save_state", &Session::save_state)
779 .addFunction ("set_dirty", &Session::set_dirty)
780 .addFunction ("unknown_processors", &Session::unknown_processors)
782 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
783 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
784 //.addFunction ("new_midi_track", &Session::new_midi_track)
787 .endNamespace (); // ARDOUR
791 LuaBindings::osc (lua_State* L)
793 luabridge::getGlobalNamespace (L)
794 .beginNamespace ("ARDOUR")
795 .beginNamespace ("LuaOSC")
796 .beginClass<LuaOSC::Address> ("Address")
797 .addConstructor<void (*) (std::string)> ()
798 .addCFunction ("send", &LuaOSC::Address::send)
805 LuaBindings::set_session (lua_State* L, Session *s)
807 /* LuaBridge uses unique keys to identify classes/c-types.
809 * Those keys are "generated" by using the memory-address of a static
810 * variable, templated for every Class.
811 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
813 * When linking the final executable there must be exactly one static
814 * function (static variable) for every templated class.
815 * This works fine on OSX and Linux...
817 * Windows (mingw and MSVC) however expand the template differently for libardour
818 * AND gtk2_ardour. We end up with two identical static functions
819 * at different addresses!!
821 * The Solution: have gtk2_ardour never include LuaBridge headers directly
822 * and always go via libardour function calls for classes that are registered
823 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
824 * which expand the template is not)
826 * (the actual cause: even static symbols in a .dll have no fixed address
827 * and are mapped when loading the dll. static functions in .exe do have a fixed
831 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
832 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
833 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
836 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
837 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
838 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
842 luabridge::push <Session *> (L, s);
843 lua_setglobal (L, "Session");
846 // call lua function.
847 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
848 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args