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/tempo.h"
45 #include "LuaBridge/LuaBridge.h"
47 /* Some notes on Lua bindings for libardour and friends
49 * - Prefer factory methods over Contructors whenever possible.
50 * Don't expose the constructor method unless required.
52 * e.g. Don't allow the script to construct a "Track" Object directly
53 * but do allow to create a "BBT_TIME" object.
55 * - Do not dereference Shared or Weak Pointers. Pass the pointer to Lua.
56 * - Define Objects as boost:shared_ptr Object whenever possible.
58 * Storing a boost::shared_ptr in a Lua-variable keeps the reference
59 * until that variable is set to 'nil'.
60 * (if the script were to keep a direct pointer to the object instance, the
61 * behaviour is undefined if the actual object goes away)
63 * Methods of the actual class are indirectly exposed,
64 * boost::*_ptr get() and ::lock() is implicit when the class is exported
65 * as LuaBridge's "WSPtrClass".
68 using namespace ARDOUR;
71 LuaBindings::stddef (lua_State* L)
73 // std::list<std::string>
74 luabridge::getGlobalNamespace (L)
76 .beginStdList <std::string> ("StringList")
79 // std::vector<std::string>
80 .beginStdVector <std::string> ("StringVector")
83 // register float array (float*)
84 .registerArray <float> ("FloatArray")
86 // register float array (int32_t*)
87 .registerArray <int32_t> ("IntArray")
89 // std::vector<std::string>
90 .beginStdVector <double> ("DoubleVector")
98 LuaBindings::common (lua_State* L)
100 luabridge::getGlobalNamespace (L)
101 .beginNamespace ("PBD")
102 .beginClass <PBD::ID> ("ID")
103 .addConstructor <void (*) (std::string)> ()
104 .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
107 .beginClass <PBD::Stateful> ("Stateful")
108 .addFunction ("properties", &PBD::Stateful::properties)
111 .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
114 .beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
115 .addFunction ("properties", &PBD::Stateful::properties)
118 .deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructiblePtr")
121 .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
122 .addFunction ("get_value", &PBD::Controllable::get_value)
125 .beginNamespace ("GroupControlDisposition")
126 .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
127 .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
128 .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
131 .endNamespace (); // PBD
133 luabridge::getGlobalNamespace (L)
134 .beginNamespace ("Timecode")
135 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
136 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
140 luabridge::getGlobalNamespace (L)
142 .beginNamespace ("Evoral")
143 .beginClass <Evoral::Parameter> ("Parameter")
144 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
145 .addFunction ("type", &Evoral::Parameter::type)
146 .addFunction ("channel", &Evoral::Parameter::channel)
147 .addFunction ("id", &Evoral::Parameter::id)
150 .beginWSPtrClass <Evoral::ControlList> ("ControlList")
151 .addFunction ("add", &Evoral::ControlList::add)
154 .beginWSPtrClass <Evoral::ControlSet> ("ControlSet")
157 .beginWSPtrClass <Evoral::Control> ("Control")
158 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
161 .beginClass <Evoral::ParameterDescriptor> ("ParameterDescriptor")
162 .addVoidConstructor ()
163 .addData ("lower", &Evoral::ParameterDescriptor::lower)
164 .addData ("upper", &Evoral::ParameterDescriptor::upper)
165 .addData ("normal", &Evoral::ParameterDescriptor::normal)
166 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
169 .endNamespace () // Evoral
171 .beginNamespace ("ARDOUR")
172 .beginWSPtrClass <PluginInfo> ("PluginInfo")
173 .addVoidConstructor ()
176 .beginNamespace ("Route")
177 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
178 .addVoidConstructor ()
182 .beginClass <ChanMapping> ("ChanMapping")
183 .addVoidConstructor ()
184 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t) const>(&ChanMapping::get))
185 .addFunction ("set", &ChanMapping::set)
186 .addConst ("Invalid", 4294967295) // UINT32_MAX
189 .beginNamespace ("Properties")
190 // templated class definitions
191 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
192 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
193 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
194 // actual references (TODO: also expose GQuark for std::set)
196 .addConst ("Start", &ARDOUR::Properties::start)
197 .addConst ("Length", &ARDOUR::Properties::length)
198 .addConst ("Position", &ARDOUR::Properties::position)
201 .beginClass <PBD::PropertyChange> ("PropertyChange")
202 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
203 // -> direct map to lua table beginStdSet()A
205 // expand templated PropertyDescriptor<T>
206 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
207 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
208 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
211 .beginClass <PBD::PropertyList> ("PropertyList")
212 // is-a std::map<PropertyID, PropertyBase*>
215 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
218 .deriveClass <Location, PBD::StatefulDestructible> ("Location")
219 .addFunction ("locked", &Location::locked)
220 .addFunction ("lock", &Location::lock)
221 .addFunction ("start", &Location::start)
222 .addFunction ("end", &Location::end)
223 .addFunction ("length", &Location::length)
224 .addFunction ("set_start", &Location::set_start)
225 .addFunction ("set_end", &Location::set_end)
226 .addFunction ("set_length", &Location::set)
227 .addFunction ("move_to", &Location::move_to)
230 .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
231 .addFunction ("name", &SessionObject::name)
234 .deriveWSPtrClass <Route, SessionObject> ("Route")
235 .addFunction ("set_name", &Route::set_name)
236 .addFunction ("comment", &Route::comment)
237 .addFunction ("active", &Route::active)
238 .addFunction ("set_active", &Route::set_active)
239 .addFunction ("nth_plugin", &Route::nth_plugin)
240 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
241 .addFunction ("remove_processor", &Route::remove_processor)
242 .addFunction ("replace_processor", &Route::replace_processor)
243 .addFunction ("n_inputs", &Route::n_inputs)
244 .addFunction ("n_outputs", &Route::n_outputs)
245 .addFunction ("set_comment", &Route::set_comment)
246 .addFunction ("strict_io", &Route::strict_io)
247 .addFunction ("set_strict_io", &Route::set_strict_io)
248 .addFunction ("reset_plugin_insert", &Route::reset_plugin_insert)
249 .addFunction ("customize_plugin_insert", &Route::customize_plugin_insert)
252 .deriveWSPtrClass <Track, Route> ("Track")
253 .addFunction ("set_name", &Track::set_name)
254 .addFunction ("can_record", &Track::can_record)
255 .addFunction ("record_enabled", &Track::record_enabled)
256 .addFunction ("record_safe", &Track::record_safe)
257 .addFunction ("set_record_enabled", &Track::set_record_enabled)
258 .addFunction ("set_record_safe", &Track::set_record_safe)
261 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
264 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
267 .deriveWSPtrClass <Region, SessionObject> ("Region")
269 .addFunction ("position", &Region::position)
270 .addFunction ("start", &Region::start)
271 .addFunction ("length", &Region::length)
272 .addFunction ("layer", &Region::layer)
273 .addFunction ("data_type", &Region::data_type)
274 .addFunction ("stretch", &Region::stretch)
275 .addFunction ("shift", &Region::shift)
276 .addRefFunction ("sync_offset", &Region::sync_offset)
277 .addFunction ("sync_position", &Region::sync_position)
278 .addFunction ("hidden", &Region::hidden)
279 .addFunction ("muted", &Region::muted)
280 .addFunction ("opaque", &Region::opaque)
281 .addFunction ("locked", &Region::locked)
282 .addFunction ("position_locked", &Region::position_locked)
283 .addFunction ("video_locked", &Region::video_locked)
284 .addFunction ("valid_transients", &Region::valid_transients)
285 .addFunction ("automatic", &Region::automatic)
286 .addFunction ("whole_file", &Region::whole_file)
287 .addFunction ("captured", &Region::captured)
288 .addFunction ("can_move", &Region::can_move)
289 .addFunction ("sync_marked", &Region::sync_marked)
290 .addFunction ("external", &Region::external)
291 .addFunction ("import", &Region::import)
292 .addFunction ("covers", &Region::covers)
293 .addFunction ("at_natural_position", &Region::at_natural_position)
294 .addFunction ("is_compound", &Region::is_compound)
295 /* editing operations */
296 .addFunction ("set_length", &Region::set_length)
297 .addFunction ("set_start", &Region::set_start)
298 .addFunction ("set_position", &Region::set_position)
299 .addFunction ("set_initial_position", &Region::set_initial_position)
300 .addFunction ("nudge_position", &Region::nudge_position)
301 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
302 .addFunction ("move_start", &Region::move_start)
303 .addFunction ("trim_front", &Region::trim_front)
304 .addFunction ("trim_end", &Region::trim_end)
305 .addFunction ("trim_to", &Region::trim_to)
306 .addFunction ("cut_front", &Region::cut_front)
307 .addFunction ("cut_end", &Region::cut_end)
308 .addFunction ("raise", &Region::raise)
309 .addFunction ("lower", &Region::lower)
310 .addFunction ("raise_to_top", &Region::raise_to_top)
311 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
312 .addFunction ("set_sync_position", &Region::set_sync_position)
313 .addFunction ("clear_sync_position", &Region::clear_sync_position)
314 .addFunction ("set_hidden", &Region::set_hidden)
315 .addFunction ("set_muted", &Region::set_muted)
316 .addFunction ("set_opaque", &Region::set_opaque)
317 .addFunction ("set_locked", &Region::set_locked)
318 .addFunction ("set_video_locked", &Region::set_video_locked)
319 .addFunction ("set_position_locked", &Region::set_position_locked)
322 .beginWSPtrClass <Source> ("Source")
325 .beginClass <Plugin::PresetRecord> ("PresetRecord")
326 .addData ("uri", &Plugin::PresetRecord::uri, false)
327 .addData ("label", &Plugin::PresetRecord::label, false)
328 .addData ("user", &Plugin::PresetRecord::user, false)
329 .addData ("valid", &Plugin::PresetRecord::valid, false)
332 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
333 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
336 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
337 .addVoidConstructor ()
338 .addData ("label", &ParameterDescriptor::label)
339 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
342 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
343 // TODO mult. inheritance
346 .deriveWSPtrClass <Processor, Automatable> ("Processor")
347 .addCast<PluginInsert> ("to_insert")
348 .addFunction ("display_name", &Processor::display_name)
349 .addFunction ("active", &Processor::active)
350 .addFunction ("activate", &Processor::activate)
351 .addFunction ("deactivate", &Processor::deactivate)
352 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
353 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
356 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("Plugin")
357 .addFunction ("label", &Plugin::label)
358 .addFunction ("name", &Plugin::name)
359 .addFunction ("maker", &Plugin::maker)
360 .addFunction ("parameter_count", &Plugin::parameter_count)
361 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
362 .addFunction ("preset_by_label", &Plugin::preset_by_label)
363 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
364 .addFunction ("load_preset", &Plugin::load_preset)
365 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
366 .addFunction ("get_docs", &Plugin::get_docs)
367 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
368 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
371 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
372 .addFunction ("plugin", &PluginInsert::plugin)
373 .addFunction ("activate", &PluginInsert::activate)
374 .addFunction ("deactivate", &PluginInsert::deactivate)
375 .addFunction ("strict_io_configured", &PluginInsert::strict_io_configured)
376 .addFunction ("no_inplace", &PluginInsert::no_inplace)
377 .addFunction ("input_map", &PluginInsert::input_map)
378 .addFunction ("output_map", &PluginInsert::output_map)
379 .addFunction ("set_no_inplace", &PluginInsert::set_no_inplace) // XXX
380 .addFunction ("set_input_map", &PluginInsert::set_input_map)
381 .addFunction ("set_output_map", &PluginInsert::set_output_map)
385 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
386 .addFunction ("automation_state", &AutomationControl::automation_state)
387 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
388 .addFunction ("start_touch", &AutomationControl::start_touch)
389 .addFunction ("stop_touch", &AutomationControl::stop_touch)
390 .addFunction ("get_value", &AutomationControl::get_value)
391 .addFunction ("set_value", &AutomationControl::set_value)
392 .addFunction ("writable", &AutomationControl::writable)
395 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
398 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
399 .addFunction ("readable_length", &AudioSource::readable_length)
400 .addFunction ("n_channels", &AudioSource::n_channels)
403 // <std::list<boost::shared_ptr <AudioTrack> >
404 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
407 // std::list<boost::shared_ptr <MidiTrack> >
408 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
411 // RouteList == std::list<boost::shared_ptr<Route> >
412 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
415 // boost::shared_ptr<RouteList>
416 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
419 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
420 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
423 // std::list< boost::weak_ptr <AudioSource>
424 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
427 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
428 // typedef Evoral::Note<Evoral::Beats> Note;
429 // std::set< boost::weak_ptr<Note> >
430 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
434 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
435 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
438 // std::list<boost::weak_ptr<Source> >
439 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
442 .beginClass <Tempo> ("Tempo")
443 .addConstructor <void (*) (double, double)> ()
444 .addFunction ("note_type", &Tempo::note_type)
445 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
446 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
449 .beginClass <Meter> ("Meter")
450 .addConstructor <void (*) (double, double)> ()
451 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
452 .addFunction ("note_divisor", &Meter::note_divisor)
453 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
454 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
457 .beginClass <TempoMap> ("TempoMap")
458 .addFunction ("add_tempo", &TempoMap::add_tempo)
459 .addFunction ("add_meter", &TempoMap::add_meter)
462 .beginClass <ChanCount> ("ChanCount")
463 .addConstructor <void (*) (DataType, uint32_t)> ()
464 .addFunction ("get", &ChanCount::get)
465 .addFunction ("set", &ChanCount::set)
466 .addFunction ("n_audio", &ChanCount::n_audio)
467 .addFunction ("n_midi", &ChanCount::n_midi)
468 .addFunction ("n_total", &ChanCount::n_total)
469 .addFunction ("reset", &ChanCount::reset)
472 .beginClass <DataType> ("DataType")
473 .addConstructor <void (*) (std::string)> ()
476 /* libardour enums */
477 .beginNamespace ("PluginType")
478 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
479 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
480 .addConst ("LV2", ARDOUR::PluginType(LV2))
481 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
482 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
483 .addConst ("Lua", ARDOUR::PluginType(Lua))
486 .beginNamespace ("AutoStyle")
487 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
488 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
491 .beginNamespace ("AutoState")
492 .addConst ("Off", ARDOUR::AutoState(Off))
493 .addConst ("Write", ARDOUR::AutoState(Write))
494 .addConst ("Touch", ARDOUR::AutoState(Touch))
495 .addConst ("Play", ARDOUR::AutoState(Play))
498 .beginNamespace ("AutomationType")
499 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
502 .beginNamespace ("SrcQuality")
503 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
506 .beginNamespace ("PlaylistDisposition")
507 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
508 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
509 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
512 luabridge::getGlobalNamespace (L)
513 .beginNamespace ("ARDOUR")
514 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
515 .addData ("name", &AudioBackendInfo::name)
517 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
519 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
520 .addData ("name", &AudioBackend::DeviceStatus::name)
521 .addData ("available", &AudioBackend::DeviceStatus::available)
523 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
525 .beginWSPtrClass <AudioBackend> ("AudioBackend")
526 .addFunction ("info", &AudioBackend::info)
527 .addFunction ("sample_rate", &AudioBackend::sample_rate)
528 .addFunction ("buffer_size", &AudioBackend::buffer_size)
529 .addFunction ("period_size", &AudioBackend::period_size)
530 .addFunction ("input_channels", &AudioBackend::input_channels)
531 .addFunction ("output_channels", &AudioBackend::output_channels)
532 .addFunction ("dsp_load", &AudioBackend::dsp_load)
534 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
535 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
536 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
538 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
539 .addFunction ("driver_name", &AudioBackend::driver_name)
540 .addFunction ("set_driver", &AudioBackend::set_driver)
542 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
543 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
544 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
545 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
546 .addFunction ("device_name", &AudioBackend::device_name)
547 .addFunction ("input_device_name", &AudioBackend::input_device_name)
548 .addFunction ("output_device_name", &AudioBackend::output_device_name)
549 .addFunction ("set_device_name", &AudioBackend::set_device_name)
550 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
551 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
554 .beginClass <AudioEngine> ("AudioEngine")
555 .addFunction ("available_backends", &AudioEngine::available_backends)
556 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
557 .addFunction ("set_backend", &AudioEngine::set_backend)
558 .addFunction ("setup_required", &AudioEngine::setup_required)
559 .addFunction ("start", &AudioEngine::start)
560 .addFunction ("stop", &AudioEngine::stop)
561 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
562 .addFunction ("set_device_name", &AudioEngine::set_device_name)
563 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
564 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
565 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
569 // basic representation of Session
570 // functions which can be used from realtime and non-realtime contexts
571 luabridge::getGlobalNamespace (L)
572 .beginNamespace ("ARDOUR")
573 .beginClass <Session> ("Session")
574 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
575 .addFunction ("transport_rolling", &Session::transport_rolling)
576 .addFunction ("request_transport_speed", &Session::request_transport_speed)
577 .addFunction ("transport_frame", &Session::transport_frame)
578 .addFunction ("transport_speed", &Session::transport_speed)
579 .addFunction ("frame_rate", &Session::frame_rate)
580 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
581 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
582 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
583 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
584 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
585 .addFunction ("request_locate", &Session::request_locate)
586 .addFunction ("request_stop", &Session::request_stop)
587 .addFunction ("last_transport_start", &Session::last_transport_start)
588 .addFunction ("goto_start", &Session::goto_start)
589 .addFunction ("goto_end", &Session::goto_end)
590 .addFunction ("current_start_frame", &Session::current_start_frame)
591 .addFunction ("current_end_frame", &Session::current_end_frame)
592 .addFunction ("actively_recording", &Session::actively_recording)
593 .addFunction ("get_routes", &Session::get_routes)
594 .addFunction ("get_tracks", &Session::get_tracks)
595 .addFunction ("name", &Session::name)
596 .addFunction ("path", &Session::path)
597 .addFunction ("record_status", &Session::record_status)
598 .addFunction ("route_by_id", &Session::route_by_id)
599 .addFunction ("route_by_name", &Session::route_by_name)
600 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
601 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
602 .addFunction ("source_by_id", &Session::source_by_id)
603 .addFunction ("controllable_by_id", &Session::controllable_by_id)
604 .addFunction ("processor_by_id", &Session::processor_by_id)
605 .addFunction ("snap_name", &Session::snap_name)
606 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
609 .beginClass <RegionFactory> ("RegionFactory")
610 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
614 .beginNamespace ("Session")
616 .beginNamespace ("RecordState")
617 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
618 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
619 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
622 .endNamespace () // END Session enums
624 .beginNamespace ("LuaAPI")
625 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
626 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
627 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
628 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
629 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
632 .endNamespace ();// END ARDOUR
636 LuaBindings::dsp (lua_State* L)
638 luabridge::getGlobalNamespace (L)
639 .beginNamespace ("ARDOUR")
641 .beginClass <AudioBuffer> ("AudioBuffer")
642 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
643 .addFunction ("silence", &AudioBuffer::silence)
644 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
647 .beginClass <MidiBuffer> ("MidiBuffer")
648 .addFunction ("silence", &MidiBuffer::silence)
649 .addFunction ("empty", &MidiBuffer::empty)
653 .beginClass <BufferSet> ("BufferSet")
654 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
655 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
659 luabridge::getGlobalNamespace (L)
660 .beginNamespace ("Evoral")
661 .beginClass <Evoral::Event<framepos_t> > ("Event")
662 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
663 .addFunction ("size", &Evoral::Event<framepos_t>::size)
664 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
665 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
668 .beginClass <Evoral::Beats> ("Beats")
669 .addFunction ("to_double", &Evoral::Beats::to_double)
672 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
674 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
675 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
676 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
677 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
681 // dsp releated session functions
682 luabridge::getGlobalNamespace (L)
683 .beginNamespace ("ARDOUR")
684 .beginClass <Session> ("Session")
685 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
686 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
690 luabridge::getGlobalNamespace (L)
691 .beginNamespace ("ARDOUR")
692 .beginNamespace ("DSP")
693 .addFunction ("compute_peak", ARDOUR::compute_peak)
694 .addFunction ("find_peaks", ARDOUR::find_peaks)
695 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
696 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
697 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
698 .addFunction ("copy_vector", ARDOUR::copy_vector)
699 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
700 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
701 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
702 .addFunction ("memset", &DSP::memset)
703 .addFunction ("mmult", &DSP::mmult)
704 .addFunction ("log_meter", &DSP::log_meter)
705 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
706 .addRefFunction ("peaks", &DSP::peaks)
708 .beginClass <DSP::LowPass> ("LowPass")
709 .addConstructor <void (*) (double, float)> ()
710 .addFunction ("proc", &DSP::LowPass::proc)
711 .addFunction ("ctrl", &DSP::LowPass::ctrl)
712 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
713 .addFunction ("reset", &DSP::LowPass::reset)
715 .beginClass <DSP::BiQuad> ("Biquad")
716 .addConstructor <void (*) (double)> ()
717 .addFunction ("run", &DSP::BiQuad::run)
718 .addFunction ("compute", &DSP::BiQuad::compute)
719 .addFunction ("reset", &DSP::BiQuad::reset)
723 .beginNamespace ("BiQuadType")
724 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
725 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
726 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
727 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
728 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
729 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
730 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
731 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
732 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
735 .beginClass <DSP::DspShm> ("DspShm")
736 .addFunction ("allocate", &DSP::DspShm::allocate)
737 .addFunction ("clear", &DSP::DspShm::clear)
738 .addFunction ("to_float", &DSP::DspShm::to_float)
739 .addFunction ("to_int", &DSP::DspShm::to_int)
740 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
741 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
744 .endNamespace () // DSP
745 .endNamespace (); // ARDOUR
749 LuaBindings::session (lua_State* L)
751 // non-realtime session functions
752 luabridge::getGlobalNamespace (L)
753 .beginNamespace ("ARDOUR")
754 .beginClass <Session> ("Session")
755 .addFunction ("save_state", &Session::save_state)
756 .addFunction ("set_dirty", &Session::set_dirty)
757 .addFunction ("unknown_processors", &Session::unknown_processors)
759 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
760 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
761 //.addFunction ("new_midi_track", &Session::new_midi_track)
764 .endNamespace (); // ARDOUR
768 LuaBindings::osc (lua_State* L)
770 luabridge::getGlobalNamespace (L)
771 .beginNamespace ("ARDOUR")
772 .beginNamespace ("LuaOSC")
773 .beginClass<LuaOSC::Address> ("Address")
774 .addConstructor<void (*) (std::string)> ()
775 .addCFunction ("send", &LuaOSC::Address::send)
782 LuaBindings::set_session (lua_State* L, Session *s)
784 /* LuaBridge uses unique keys to identify classes/c-types.
786 * Those keys are "generated" by using the memory-address of a static
787 * variable, templated for every Class.
788 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
790 * When linking the final executable there must be exactly one static
791 * function (static variable) for every templated class.
792 * This works fine on OSX and Linux...
794 * Windows (mingw and MSVC) however expand the template differently for libardour
795 * AND gtk2_ardour. We end up with two identical static functions
796 * at different addresses!!
798 * The Solution: have gtk2_ardour never include LuaBridge headers directly
799 * and always go via libardour function calls for classes that are registered
800 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
801 * which expand the template is not)
803 * (the actual cause: even static symbols in a .dll have no fixed address
804 * and are mapped when loading the dll. static functions in .exe do have a fixed
808 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
809 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
810 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
813 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
814 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
815 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
819 luabridge::push <Session *> (L, s);
820 lua_setglobal (L, "Session");
823 // call lua function.
824 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
825 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args