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)
260 .addFunction ("add_sidechain", &Route::add_sidechain)
261 .addFunction ("remove_sidechain", &Route::remove_sidechain)
264 .deriveWSPtrClass <Track, Route> ("Track")
265 .addFunction ("set_name", &Track::set_name)
266 .addFunction ("can_record", &Track::can_record)
267 .addFunction ("record_enabled", &Track::record_enabled)
268 .addFunction ("record_safe", &Track::record_safe)
269 .addFunction ("set_record_enabled", &Track::set_record_enabled)
270 .addFunction ("set_record_safe", &Track::set_record_safe)
273 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
276 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
279 .deriveWSPtrClass <Region, SessionObject> ("Region")
281 .addFunction ("position", &Region::position)
282 .addFunction ("start", &Region::start)
283 .addFunction ("length", &Region::length)
284 .addFunction ("layer", &Region::layer)
285 .addFunction ("data_type", &Region::data_type)
286 .addFunction ("stretch", &Region::stretch)
287 .addFunction ("shift", &Region::shift)
288 .addRefFunction ("sync_offset", &Region::sync_offset)
289 .addFunction ("sync_position", &Region::sync_position)
290 .addFunction ("hidden", &Region::hidden)
291 .addFunction ("muted", &Region::muted)
292 .addFunction ("opaque", &Region::opaque)
293 .addFunction ("locked", &Region::locked)
294 .addFunction ("position_locked", &Region::position_locked)
295 .addFunction ("video_locked", &Region::video_locked)
296 .addFunction ("valid_transients", &Region::valid_transients)
297 .addFunction ("automatic", &Region::automatic)
298 .addFunction ("whole_file", &Region::whole_file)
299 .addFunction ("captured", &Region::captured)
300 .addFunction ("can_move", &Region::can_move)
301 .addFunction ("sync_marked", &Region::sync_marked)
302 .addFunction ("external", &Region::external)
303 .addFunction ("import", &Region::import)
304 .addFunction ("covers", &Region::covers)
305 .addFunction ("at_natural_position", &Region::at_natural_position)
306 .addFunction ("is_compound", &Region::is_compound)
307 /* editing operations */
308 .addFunction ("set_length", &Region::set_length)
309 .addFunction ("set_start", &Region::set_start)
310 .addFunction ("set_position", &Region::set_position)
311 .addFunction ("set_initial_position", &Region::set_initial_position)
312 .addFunction ("nudge_position", &Region::nudge_position)
313 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
314 .addFunction ("move_start", &Region::move_start)
315 .addFunction ("trim_front", &Region::trim_front)
316 .addFunction ("trim_end", &Region::trim_end)
317 .addFunction ("trim_to", &Region::trim_to)
318 .addFunction ("cut_front", &Region::cut_front)
319 .addFunction ("cut_end", &Region::cut_end)
320 .addFunction ("raise", &Region::raise)
321 .addFunction ("lower", &Region::lower)
322 .addFunction ("raise_to_top", &Region::raise_to_top)
323 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
324 .addFunction ("set_sync_position", &Region::set_sync_position)
325 .addFunction ("clear_sync_position", &Region::clear_sync_position)
326 .addFunction ("set_hidden", &Region::set_hidden)
327 .addFunction ("set_muted", &Region::set_muted)
328 .addFunction ("set_opaque", &Region::set_opaque)
329 .addFunction ("set_locked", &Region::set_locked)
330 .addFunction ("set_video_locked", &Region::set_video_locked)
331 .addFunction ("set_position_locked", &Region::set_position_locked)
334 .beginWSPtrClass <Source> ("Source")
337 .beginClass <Plugin::PresetRecord> ("PresetRecord")
338 .addData ("uri", &Plugin::PresetRecord::uri, false)
339 .addData ("label", &Plugin::PresetRecord::label, false)
340 .addData ("user", &Plugin::PresetRecord::user, false)
341 .addData ("valid", &Plugin::PresetRecord::valid, false)
344 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
345 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
348 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
349 .addVoidConstructor ()
350 .addData ("label", &ParameterDescriptor::label)
351 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
354 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
355 // TODO mult. inheritance
358 .deriveWSPtrClass <Processor, Automatable> ("Processor")
359 .addCast<PluginInsert> ("to_insert")
360 .addCast<SideChain> ("to_sidechain")
361 .addCast<IOProcessor> ("to_ioprocessor")
362 .addFunction ("display_name", &Processor::display_name)
363 .addFunction ("active", &Processor::active)
364 .addFunction ("activate", &Processor::activate)
365 .addFunction ("deactivate", &Processor::deactivate)
366 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
367 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
370 .deriveWSPtrClass <IOProcessor, Processor> ("IOProcessor")
371 .addFunction ("natural_input_streams", &IOProcessor::natural_input_streams)
372 .addFunction ("natural_output_streams", &IOProcessor::natural_output_streams)
373 .addFunction ("input", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::input)
374 .addFunction ("output", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::output)
377 .deriveWSPtrClass <SideChain, IOProcessor> ("SideChain")
380 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("Plugin")
381 .addFunction ("label", &Plugin::label)
382 .addFunction ("name", &Plugin::name)
383 .addFunction ("maker", &Plugin::maker)
384 .addFunction ("parameter_count", &Plugin::parameter_count)
385 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
386 .addFunction ("preset_by_label", &Plugin::preset_by_label)
387 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
388 .addFunction ("load_preset", &Plugin::load_preset)
389 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
390 .addFunction ("get_docs", &Plugin::get_docs)
391 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
392 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
395 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
396 .addFunction ("plugin", &PluginInsert::plugin)
397 .addFunction ("activate", &PluginInsert::activate)
398 .addFunction ("deactivate", &PluginInsert::deactivate)
399 .addFunction ("strict_io_configured", &PluginInsert::strict_io_configured)
400 .addFunction ("input_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::input_map)
401 .addFunction ("output_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::output_map)
402 .addFunction ("set_input_map", &PluginInsert::set_input_map)
403 .addFunction ("set_output_map", &PluginInsert::set_output_map)
407 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
408 .addFunction ("automation_state", &AutomationControl::automation_state)
409 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
410 .addFunction ("start_touch", &AutomationControl::start_touch)
411 .addFunction ("stop_touch", &AutomationControl::stop_touch)
412 .addFunction ("get_value", &AutomationControl::get_value)
413 .addFunction ("set_value", &AutomationControl::set_value)
414 .addFunction ("writable", &AutomationControl::writable)
417 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
420 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
421 .addFunction ("readable_length", &AudioSource::readable_length)
422 .addFunction ("n_channels", &AudioSource::n_channels)
425 // <std::list<boost::shared_ptr <AudioTrack> >
426 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
429 // std::list<boost::shared_ptr <MidiTrack> >
430 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
433 // RouteList == std::list<boost::shared_ptr<Route> >
434 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
437 // boost::shared_ptr<RouteList>
438 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
441 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
442 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
445 // std::list< boost::weak_ptr <AudioSource>
446 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
449 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
450 // typedef Evoral::Note<Evoral::Beats> Note;
451 // std::set< boost::weak_ptr<Note> >
452 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
456 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
457 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
460 // std::list<boost::weak_ptr<Source> >
461 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
464 .beginClass <Tempo> ("Tempo")
465 .addConstructor <void (*) (double, double)> ()
466 .addFunction ("note_type", &Tempo::note_type)
467 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
468 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
471 .beginClass <Meter> ("Meter")
472 .addConstructor <void (*) (double, double)> ()
473 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
474 .addFunction ("note_divisor", &Meter::note_divisor)
475 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
476 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
479 .beginClass <TempoMap> ("TempoMap")
480 .addFunction ("add_tempo", &TempoMap::add_tempo)
481 .addFunction ("add_meter", &TempoMap::add_meter)
484 .beginClass <ChanCount> ("ChanCount")
485 .addConstructor <void (*) (DataType, uint32_t)> ()
486 .addFunction ("get", &ChanCount::get)
487 .addFunction ("set", &ChanCount::set)
488 .addFunction ("n_audio", &ChanCount::n_audio)
489 .addFunction ("n_midi", &ChanCount::n_midi)
490 .addFunction ("n_total", &ChanCount::n_total)
491 .addFunction ("reset", &ChanCount::reset)
494 .beginClass <DataType> ("DataType")
495 .addConstructor <void (*) (std::string)> ()
496 .addStaticCFunction ("null", &LuaAPI::datatype_ctor_nil) // "nil" is a lua reseved word
497 .addStaticCFunction ("audio", &LuaAPI::datatype_ctor_audio)
498 .addStaticCFunction ("midi", &LuaAPI::datatype_ctor_midi)
501 /* libardour enums */
502 .beginNamespace ("PluginType")
503 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
504 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
505 .addConst ("LV2", ARDOUR::PluginType(LV2))
506 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
507 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
508 .addConst ("Lua", ARDOUR::PluginType(Lua))
511 .beginNamespace ("AutoStyle")
512 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
513 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
516 .beginNamespace ("AutoState")
517 .addConst ("Off", ARDOUR::AutoState(Off))
518 .addConst ("Write", ARDOUR::AutoState(Write))
519 .addConst ("Touch", ARDOUR::AutoState(Touch))
520 .addConst ("Play", ARDOUR::AutoState(Play))
523 .beginNamespace ("AutomationType")
524 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
527 .beginNamespace ("SrcQuality")
528 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
531 .beginNamespace ("PlaylistDisposition")
532 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
533 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
534 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
537 luabridge::getGlobalNamespace (L)
538 .beginNamespace ("ARDOUR")
539 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
540 .addData ("name", &AudioBackendInfo::name)
542 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
544 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
545 .addData ("name", &AudioBackend::DeviceStatus::name)
546 .addData ("available", &AudioBackend::DeviceStatus::available)
548 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
550 .beginWSPtrClass <AudioBackend> ("AudioBackend")
551 .addFunction ("info", &AudioBackend::info)
552 .addFunction ("sample_rate", &AudioBackend::sample_rate)
553 .addFunction ("buffer_size", &AudioBackend::buffer_size)
554 .addFunction ("period_size", &AudioBackend::period_size)
555 .addFunction ("input_channels", &AudioBackend::input_channels)
556 .addFunction ("output_channels", &AudioBackend::output_channels)
557 .addFunction ("dsp_load", &AudioBackend::dsp_load)
559 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
560 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
561 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
563 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
564 .addFunction ("driver_name", &AudioBackend::driver_name)
565 .addFunction ("set_driver", &AudioBackend::set_driver)
567 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
568 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
569 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
570 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
571 .addFunction ("device_name", &AudioBackend::device_name)
572 .addFunction ("input_device_name", &AudioBackend::input_device_name)
573 .addFunction ("output_device_name", &AudioBackend::output_device_name)
574 .addFunction ("set_device_name", &AudioBackend::set_device_name)
575 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
576 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
579 .beginClass <AudioEngine> ("AudioEngine")
580 .addFunction ("available_backends", &AudioEngine::available_backends)
581 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
582 .addFunction ("set_backend", &AudioEngine::set_backend)
583 .addFunction ("setup_required", &AudioEngine::setup_required)
584 .addFunction ("start", &AudioEngine::start)
585 .addFunction ("stop", &AudioEngine::stop)
586 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
587 .addFunction ("set_device_name", &AudioEngine::set_device_name)
588 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
589 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
590 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
594 // basic representation of Session
595 // functions which can be used from realtime and non-realtime contexts
596 luabridge::getGlobalNamespace (L)
597 .beginNamespace ("ARDOUR")
598 .beginClass <Session> ("Session")
599 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
600 .addFunction ("transport_rolling", &Session::transport_rolling)
601 .addFunction ("request_transport_speed", &Session::request_transport_speed)
602 .addFunction ("transport_frame", &Session::transport_frame)
603 .addFunction ("transport_speed", &Session::transport_speed)
604 .addFunction ("frame_rate", &Session::frame_rate)
605 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
606 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
607 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
608 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
609 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
610 .addFunction ("request_locate", &Session::request_locate)
611 .addFunction ("request_stop", &Session::request_stop)
612 .addFunction ("last_transport_start", &Session::last_transport_start)
613 .addFunction ("goto_start", &Session::goto_start)
614 .addFunction ("goto_end", &Session::goto_end)
615 .addFunction ("current_start_frame", &Session::current_start_frame)
616 .addFunction ("current_end_frame", &Session::current_end_frame)
617 .addFunction ("actively_recording", &Session::actively_recording)
618 .addFunction ("get_routes", &Session::get_routes)
619 .addFunction ("get_tracks", &Session::get_tracks)
620 .addFunction ("name", &Session::name)
621 .addFunction ("path", &Session::path)
622 .addFunction ("record_status", &Session::record_status)
623 .addFunction ("route_by_id", &Session::route_by_id)
624 .addFunction ("route_by_name", &Session::route_by_name)
625 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
626 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
627 .addFunction ("source_by_id", &Session::source_by_id)
628 .addFunction ("controllable_by_id", &Session::controllable_by_id)
629 .addFunction ("processor_by_id", &Session::processor_by_id)
630 .addFunction ("snap_name", &Session::snap_name)
631 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
634 .beginClass <RegionFactory> ("RegionFactory")
635 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
639 .beginNamespace ("Session")
641 .beginNamespace ("RecordState")
642 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
643 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
644 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
647 .endNamespace () // END Session enums
649 .beginNamespace ("LuaAPI")
650 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
651 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
652 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
653 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
654 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
657 .endNamespace ();// END ARDOUR
661 LuaBindings::dsp (lua_State* L)
663 luabridge::getGlobalNamespace (L)
664 .beginNamespace ("ARDOUR")
666 .beginClass <AudioBuffer> ("AudioBuffer")
667 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
668 .addFunction ("silence", &AudioBuffer::silence)
669 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
672 .beginClass <MidiBuffer> ("MidiBuffer")
673 .addFunction ("silence", &MidiBuffer::silence)
674 .addFunction ("empty", &MidiBuffer::empty)
678 .beginClass <BufferSet> ("BufferSet")
679 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
680 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
684 luabridge::getGlobalNamespace (L)
685 .beginNamespace ("Evoral")
686 .beginClass <Evoral::Event<framepos_t> > ("Event")
687 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
688 .addFunction ("size", &Evoral::Event<framepos_t>::size)
689 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
690 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
693 .beginClass <Evoral::Beats> ("Beats")
694 .addFunction ("to_double", &Evoral::Beats::to_double)
697 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
699 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
700 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
701 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
702 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
706 // dsp releated session functions
707 luabridge::getGlobalNamespace (L)
708 .beginNamespace ("ARDOUR")
709 .beginClass <Session> ("Session")
710 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
711 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
715 luabridge::getGlobalNamespace (L)
716 .beginNamespace ("ARDOUR")
717 .beginNamespace ("DSP")
718 .addFunction ("compute_peak", ARDOUR::compute_peak)
719 .addFunction ("find_peaks", ARDOUR::find_peaks)
720 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
721 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
722 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
723 .addFunction ("copy_vector", ARDOUR::copy_vector)
724 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
725 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
726 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
727 .addFunction ("memset", &DSP::memset)
728 .addFunction ("mmult", &DSP::mmult)
729 .addFunction ("log_meter", &DSP::log_meter)
730 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
731 .addRefFunction ("peaks", &DSP::peaks)
733 .beginClass <DSP::LowPass> ("LowPass")
734 .addConstructor <void (*) (double, float)> ()
735 .addFunction ("proc", &DSP::LowPass::proc)
736 .addFunction ("ctrl", &DSP::LowPass::ctrl)
737 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
738 .addFunction ("reset", &DSP::LowPass::reset)
740 .beginClass <DSP::BiQuad> ("Biquad")
741 .addConstructor <void (*) (double)> ()
742 .addFunction ("run", &DSP::BiQuad::run)
743 .addFunction ("compute", &DSP::BiQuad::compute)
744 .addFunction ("reset", &DSP::BiQuad::reset)
748 .beginNamespace ("BiQuadType")
749 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
750 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
751 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
752 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
753 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
754 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
755 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
756 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
757 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
760 .beginClass <DSP::DspShm> ("DspShm")
761 .addFunction ("allocate", &DSP::DspShm::allocate)
762 .addFunction ("clear", &DSP::DspShm::clear)
763 .addFunction ("to_float", &DSP::DspShm::to_float)
764 .addFunction ("to_int", &DSP::DspShm::to_int)
765 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
766 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
769 .endNamespace () // DSP
770 .endNamespace (); // ARDOUR
774 LuaBindings::session (lua_State* L)
776 // non-realtime session functions
777 luabridge::getGlobalNamespace (L)
778 .beginNamespace ("ARDOUR")
779 .beginClass <Session> ("Session")
780 .addFunction ("save_state", &Session::save_state)
781 .addFunction ("set_dirty", &Session::set_dirty)
782 .addFunction ("unknown_processors", &Session::unknown_processors)
784 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
785 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
786 //.addFunction ("new_midi_track", &Session::new_midi_track)
789 .endNamespace (); // ARDOUR
793 LuaBindings::osc (lua_State* L)
795 luabridge::getGlobalNamespace (L)
796 .beginNamespace ("ARDOUR")
797 .beginNamespace ("LuaOSC")
798 .beginClass<LuaOSC::Address> ("Address")
799 .addConstructor<void (*) (std::string)> ()
800 .addCFunction ("send", &LuaOSC::Address::send)
807 LuaBindings::set_session (lua_State* L, Session *s)
809 /* LuaBridge uses unique keys to identify classes/c-types.
811 * Those keys are "generated" by using the memory-address of a static
812 * variable, templated for every Class.
813 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
815 * When linking the final executable there must be exactly one static
816 * function (static variable) for every templated class.
817 * This works fine on OSX and Linux...
819 * Windows (mingw and MSVC) however expand the template differently for libardour
820 * AND gtk2_ardour. We end up with two identical static functions
821 * at different addresses!!
823 * The Solution: have gtk2_ardour never include LuaBridge headers directly
824 * and always go via libardour function calls for classes that are registered
825 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
826 * which expand the template is not)
828 * (the actual cause: even static symbols in a .dll have no fixed address
829 * and are mapped when loading the dll. static functions in .exe do have a fixed
833 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
834 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
835 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
838 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
839 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
840 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
844 luabridge::push <Session *> (L, s);
845 lua_setglobal (L, "Session");
848 // call lua function.
849 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
850 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args