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))
133 luabridge::getGlobalNamespace (L)
134 .beginNamespace ("ARDOUR") // XXX really libtimecode
135 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
136 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
140 luabridge::getGlobalNamespace (L)
141 .beginNamespace ("ARDOUR")
142 .beginWSPtrClass <PluginInfo> ("PluginInfo")
143 .addVoidConstructor ()
146 .beginNamespace ("Route")
147 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
148 .addVoidConstructor ()
152 .beginNamespace ("Properties")
153 // templated class definitions
154 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
155 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
156 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
157 // actual references (TODO: also expose GQuark for std::set)
159 .addConst ("Start", &ARDOUR::Properties::start)
160 .addConst ("Length", &ARDOUR::Properties::length)
161 .addConst ("Position", &ARDOUR::Properties::position)
164 .beginClass <PBD::PropertyChange> ("PropertyChange")
165 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
166 // -> direct map to lua table beginStdSet()A
168 // expand templated PropertyDescriptor<T>
169 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
170 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
171 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
174 .beginClass <PBD::PropertyList> ("PropertyList")
175 // is-a std::map<PropertyID, PropertyBase*>
178 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
181 .deriveClass <Location, PBD::StatefulDestructible> ("Location")
182 .addFunction ("locked", &Location::locked)
183 .addFunction ("lock", &Location::lock)
184 .addFunction ("start", &Location::start)
185 .addFunction ("end", &Location::end)
186 .addFunction ("length", &Location::length)
187 .addFunction ("set_start", &Location::set_start)
188 .addFunction ("set_end", &Location::set_end)
189 .addFunction ("set_length", &Location::set)
190 .addFunction ("move_to", &Location::move_to)
193 .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
194 .addFunction ("name", &SessionObject::name)
197 .deriveWSPtrClass <Route, SessionObject> ("Route")
198 .addFunction ("set_name", &Route::set_name)
199 .addFunction ("comment", &Route::comment)
200 .addFunction ("active", &Route::active)
201 .addFunction ("set_active", &Route::set_active)
202 .addFunction ("nth_plugin", &Route::nth_plugin)
203 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
204 .addFunction ("remove_processor", &Route::remove_processor)
205 .addFunction ("replace_processor", &Route::replace_processor)
206 .addFunction ("n_inputs", &Route::n_inputs)
207 .addFunction ("n_outputs", &Route::n_outputs)
208 .addFunction ("set_comment", &Route::set_comment)
211 .deriveWSPtrClass <Track, Route> ("Track")
212 .addFunction ("set_name", &Track::set_name)
213 .addFunction ("can_record", &Track::can_record)
214 .addFunction ("record_enabled", &Track::record_enabled)
215 .addFunction ("record_safe", &Track::record_safe)
216 .addFunction ("set_record_enabled", &Track::set_record_enabled)
217 .addFunction ("set_record_safe", &Track::set_record_safe)
220 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
223 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
226 .deriveWSPtrClass <Region, SessionObject> ("Region")
228 .addFunction ("position", &Region::position)
229 .addFunction ("start", &Region::start)
230 .addFunction ("length", &Region::length)
231 .addFunction ("layer", &Region::layer)
232 .addFunction ("data_type", &Region::data_type)
233 .addFunction ("stretch", &Region::stretch)
234 .addFunction ("shift", &Region::shift)
235 .addRefFunction ("sync_offset", &Region::sync_offset)
236 .addFunction ("sync_position", &Region::sync_position)
237 .addFunction ("hidden", &Region::hidden)
238 .addFunction ("muted", &Region::muted)
239 .addFunction ("opaque", &Region::opaque)
240 .addFunction ("locked", &Region::locked)
241 .addFunction ("position_locked", &Region::position_locked)
242 .addFunction ("video_locked", &Region::video_locked)
243 .addFunction ("valid_transients", &Region::valid_transients)
244 .addFunction ("automatic", &Region::automatic)
245 .addFunction ("whole_file", &Region::whole_file)
246 .addFunction ("captured", &Region::captured)
247 .addFunction ("can_move", &Region::can_move)
248 .addFunction ("sync_marked", &Region::sync_marked)
249 .addFunction ("external", &Region::external)
250 .addFunction ("import", &Region::import)
251 .addFunction ("covers", &Region::covers)
252 .addFunction ("at_natural_position", &Region::at_natural_position)
253 .addFunction ("is_compound", &Region::is_compound)
254 /* editing operations */
255 .addFunction ("set_length", &Region::set_length)
256 .addFunction ("set_start", &Region::set_start)
257 .addFunction ("set_position", &Region::set_position)
258 .addFunction ("set_initial_position", &Region::set_initial_position)
259 .addFunction ("nudge_position", &Region::nudge_position)
260 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
261 .addFunction ("move_start", &Region::move_start)
262 .addFunction ("trim_front", &Region::trim_front)
263 .addFunction ("trim_end", &Region::trim_end)
264 .addFunction ("trim_to", &Region::trim_to)
265 .addFunction ("cut_front", &Region::cut_front)
266 .addFunction ("cut_end", &Region::cut_end)
267 .addFunction ("raise", &Region::raise)
268 .addFunction ("lower", &Region::lower)
269 .addFunction ("raise_to_top", &Region::raise_to_top)
270 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
271 .addFunction ("set_sync_position", &Region::set_sync_position)
272 .addFunction ("clear_sync_position", &Region::clear_sync_position)
273 .addFunction ("set_hidden", &Region::set_hidden)
274 .addFunction ("set_muted", &Region::set_muted)
275 .addFunction ("set_opaque", &Region::set_opaque)
276 .addFunction ("set_locked", &Region::set_locked)
277 .addFunction ("set_video_locked", &Region::set_video_locked)
278 .addFunction ("set_position_locked", &Region::set_position_locked)
281 .beginWSPtrClass <Source> ("Source")
284 .beginClass <Evoral::Parameter> ("EvoralParameter")
285 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
286 .addFunction ("type", &Evoral::Parameter::type)
287 .addFunction ("channel", &Evoral::Parameter::channel)
288 .addFunction ("id", &Evoral::Parameter::id)
291 .beginClass <Plugin::PresetRecord> ("PresetRecord")
292 .addData ("uri", &Plugin::PresetRecord::uri, false)
293 .addData ("label", &Plugin::PresetRecord::label, false)
294 .addData ("user", &Plugin::PresetRecord::user, false)
295 .addData ("valid", &Plugin::PresetRecord::valid, false)
298 .beginWSPtrClass <Evoral::ControlList> ("EvoralControlList")
299 .addFunction ("add", &Evoral::ControlList::add)
302 .beginWSPtrClass <Evoral::ControlSet> ("EvoralControlSet")
305 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
306 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
309 .beginWSPtrClass <Evoral::Control> ("EvoralControl")
310 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
313 .beginClass <Evoral::ParameterDescriptor> ("EvoralParameterDescriptor")
314 .addVoidConstructor ()
315 .addData ("lower", &Evoral::ParameterDescriptor::lower)
316 .addData ("upper", &Evoral::ParameterDescriptor::upper)
317 .addData ("normal", &Evoral::ParameterDescriptor::normal)
318 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
321 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
322 .addVoidConstructor ()
323 .addData ("label", &ParameterDescriptor::label)
324 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
327 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
328 // TODO mult. inheritance
331 .deriveWSPtrClass <Processor, Automatable> ("Processor")
332 .addCast<PluginInsert> ("to_insert")
333 .addFunction ("display_name", &Processor::display_name)
334 .addFunction ("active", &Processor::active)
335 .addFunction ("activate", &Processor::activate)
336 .addFunction ("deactivate", &Processor::deactivate)
337 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
338 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
341 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("PluginInsert")
342 .addFunction ("label", &Plugin::label)
343 .addFunction ("name", &Plugin::name)
344 .addFunction ("maker", &Plugin::maker)
345 .addFunction ("parameter_count", &Plugin::parameter_count)
346 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
347 .addFunction ("preset_by_label", &Plugin::preset_by_label)
348 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
349 .addFunction ("load_preset", &Plugin::load_preset)
350 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
351 .addFunction ("get_docs", &Plugin::get_docs)
352 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
353 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
356 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
357 .addFunction ("plugin", &PluginInsert::plugin)
358 .addFunction ("activate", &PluginInsert::activate)
359 .addFunction ("deactivate", &PluginInsert::deactivate)
362 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
363 .addFunction ("automation_state", &AutomationControl::automation_state)
364 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
365 .addFunction ("start_touch", &AutomationControl::start_touch)
366 .addFunction ("stop_touch", &AutomationControl::stop_touch)
367 .addFunction ("get_value", &AutomationControl::get_value)
368 .addFunction ("set_value", &AutomationControl::set_value)
369 .addFunction ("writable", &AutomationControl::writable)
372 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
375 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
376 .addFunction ("readable_length", &AudioSource::readable_length)
377 .addFunction ("n_channels", &AudioSource::n_channels)
380 // <std::list<boost::shared_ptr <AudioTrack> >
381 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
384 // std::list<boost::shared_ptr <MidiTrack> >
385 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
388 // RouteList == std::list<boost::shared_ptr<Route> >
389 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
392 // boost::shared_ptr<RouteList>
393 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
396 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
397 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
400 // std::list< boost::weak_ptr <AudioSource>
401 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
404 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
405 // typedef Evoral::Note<Evoral::Beats> Note;
406 // std::set< boost::weak_ptr<Note> >
407 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
411 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
412 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
415 // std::list<boost::weak_ptr<Source> >
416 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
419 .beginClass <Tempo> ("Tempo")
420 .addConstructor <void (*) (double, double)> ()
421 .addFunction ("note_type", &Tempo::note_type)
422 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
423 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
426 .beginClass <Meter> ("Meter")
427 .addConstructor <void (*) (double, double)> ()
428 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
429 .addFunction ("note_divisor", &Meter::note_divisor)
430 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
431 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
434 .beginClass <TempoMap> ("TempoMap")
435 .addFunction ("add_tempo", &TempoMap::add_tempo)
436 .addFunction ("add_meter", &TempoMap::add_meter)
439 .beginClass <ChanCount> ("ChanCount")
440 .addFunction ("n_audio", &ChanCount::n_audio)
443 .beginClass <DataType> ("DataType")
444 .addConstructor <void (*) (std::string)> ()
447 /* libardour enums */
448 .beginNamespace ("PluginType")
449 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
450 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
451 .addConst ("LV2", ARDOUR::PluginType(LV2))
452 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
453 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
454 .addConst ("Lua", ARDOUR::PluginType(Lua))
457 .beginNamespace ("AutoStyle")
458 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
459 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
462 .beginNamespace ("AutoState")
463 .addConst ("Off", ARDOUR::AutoState(Off))
464 .addConst ("Write", ARDOUR::AutoState(Write))
465 .addConst ("Touch", ARDOUR::AutoState(Touch))
466 .addConst ("Play", ARDOUR::AutoState(Play))
469 .beginNamespace ("AutomationType")
470 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
473 .beginNamespace ("SrcQuality")
474 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
477 .beginNamespace ("PlaylistDisposition")
478 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
479 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
480 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
483 luabridge::getGlobalNamespace (L)
484 .beginNamespace ("ARDOUR")
485 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
486 .addData ("name", &AudioBackendInfo::name)
488 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
490 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
491 .addData ("name", &AudioBackend::DeviceStatus::name)
492 .addData ("available", &AudioBackend::DeviceStatus::available)
494 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
496 .beginWSPtrClass <AudioBackend> ("AudioBackend")
497 .addFunction ("info", &AudioBackend::info)
498 .addFunction ("sample_rate", &AudioBackend::sample_rate)
499 .addFunction ("buffer_size", &AudioBackend::buffer_size)
500 .addFunction ("period_size", &AudioBackend::period_size)
501 .addFunction ("input_channels", &AudioBackend::input_channels)
502 .addFunction ("output_channels", &AudioBackend::output_channels)
503 .addFunction ("dsp_load", &AudioBackend::dsp_load)
505 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
506 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
507 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
509 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
510 .addFunction ("driver_name", &AudioBackend::driver_name)
511 .addFunction ("set_driver", &AudioBackend::set_driver)
513 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
514 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
515 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
516 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
517 .addFunction ("device_name", &AudioBackend::device_name)
518 .addFunction ("input_device_name", &AudioBackend::input_device_name)
519 .addFunction ("output_device_name", &AudioBackend::output_device_name)
520 .addFunction ("set_device_name", &AudioBackend::set_device_name)
521 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
522 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
525 .beginClass <AudioEngine> ("AudioEngine")
526 .addFunction ("available_backends", &AudioEngine::available_backends)
527 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
528 .addFunction ("set_backend", &AudioEngine::set_backend)
529 .addFunction ("setup_required", &AudioEngine::setup_required)
530 .addFunction ("start", &AudioEngine::start)
531 .addFunction ("stop", &AudioEngine::stop)
532 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
533 .addFunction ("set_device_name", &AudioEngine::set_device_name)
534 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
535 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
536 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
540 // basic representation of Session
541 // functions which can be used from realtime and non-realtime contexts
542 luabridge::getGlobalNamespace (L)
543 .beginNamespace ("ARDOUR")
544 .beginClass <Session> ("Session")
545 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
546 .addFunction ("transport_rolling", &Session::transport_rolling)
547 .addFunction ("request_transport_speed", &Session::request_transport_speed)
548 .addFunction ("transport_frame", &Session::transport_frame)
549 .addFunction ("transport_speed", &Session::transport_speed)
550 .addFunction ("frame_rate", &Session::frame_rate)
551 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
552 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
553 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
554 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
555 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
556 .addFunction ("request_locate", &Session::request_locate)
557 .addFunction ("request_stop", &Session::request_stop)
558 .addFunction ("last_transport_start", &Session::last_transport_start)
559 .addFunction ("goto_start", &Session::goto_start)
560 .addFunction ("goto_end", &Session::goto_end)
561 .addFunction ("current_start_frame", &Session::current_start_frame)
562 .addFunction ("current_end_frame", &Session::current_end_frame)
563 .addFunction ("actively_recording", &Session::actively_recording)
564 .addFunction ("get_routes", &Session::get_routes)
565 .addFunction ("get_tracks", &Session::get_tracks)
566 .addFunction ("name", &Session::name)
567 .addFunction ("path", &Session::path)
568 .addFunction ("record_status", &Session::record_status)
569 .addFunction ("route_by_id", &Session::route_by_id)
570 .addFunction ("route_by_name", &Session::route_by_name)
571 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
572 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
573 .addFunction ("source_by_id", &Session::source_by_id)
574 .addFunction ("controllable_by_id", &Session::controllable_by_id)
575 .addFunction ("processor_by_id", &Session::processor_by_id)
576 .addFunction ("snap_name", &Session::snap_name)
577 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
580 .beginClass <RegionFactory> ("RegionFactory")
581 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
585 .beginNamespace ("Session")
587 .beginNamespace ("RecordState")
588 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
589 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
590 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
593 .endNamespace () // END Session enums
595 .beginNamespace ("LuaAPI")
596 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
597 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
598 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
599 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
600 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
603 .endNamespace ();// END ARDOUR
607 LuaBindings::dsp (lua_State* L)
609 luabridge::getGlobalNamespace (L)
610 .beginNamespace ("ARDOUR")
612 .beginClass <AudioBuffer> ("AudioBuffer")
613 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
614 .addFunction ("silence", &AudioBuffer::silence)
615 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
618 .beginClass <MidiBuffer> ("MidiBuffer")
619 .addFunction ("silence", &MidiBuffer::silence)
620 .addFunction ("empty", &MidiBuffer::empty)
624 .beginClass <BufferSet> ("BufferSet")
625 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
626 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
629 .beginClass <ChanMapping> ("ChanMapping")
630 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t)>(&ChanMapping::get))
631 .addFunction ("set", &ChanMapping::set)
632 .addConst ("Invalid", 4294967295) // UINT32_MAX
636 luabridge::getGlobalNamespace (L)
637 .beginNamespace ("Evoral")
638 .beginClass <Evoral::Event<framepos_t> > ("Event")
639 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
640 .addFunction ("size", &Evoral::Event<framepos_t>::size)
641 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
642 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
645 .beginClass <Evoral::Beats> ("Beats")
646 .addFunction ("to_double", &Evoral::Beats::to_double)
649 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
651 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
652 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
653 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
654 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
658 // dsp releated session functions
659 luabridge::getGlobalNamespace (L)
660 .beginNamespace ("ARDOUR")
661 .beginClass <Session> ("Session")
662 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
663 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
667 luabridge::getGlobalNamespace (L)
668 .beginNamespace ("ARDOUR")
669 .beginNamespace ("DSP")
670 .addFunction ("compute_peak", ARDOUR::compute_peak)
671 .addFunction ("find_peaks", ARDOUR::find_peaks)
672 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
673 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
674 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
675 .addFunction ("copy_vector", ARDOUR::copy_vector)
676 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
677 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
678 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
679 .addFunction ("memset", &DSP::memset)
680 .addFunction ("mmult", &DSP::mmult)
681 .addFunction ("log_meter", &DSP::log_meter)
682 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
683 .addRefFunction ("peaks", &DSP::peaks)
685 .beginClass <DSP::LowPass> ("LowPass")
686 .addConstructor <void (*) (double, float)> ()
687 .addFunction ("proc", &DSP::LowPass::proc)
688 .addFunction ("ctrl", &DSP::LowPass::ctrl)
689 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
690 .addFunction ("reset", &DSP::LowPass::reset)
692 .beginClass <DSP::BiQuad> ("Biquad")
693 .addConstructor <void (*) (double)> ()
694 .addFunction ("run", &DSP::BiQuad::run)
695 .addFunction ("compute", &DSP::BiQuad::compute)
696 .addFunction ("reset", &DSP::BiQuad::reset)
700 .beginNamespace ("BiQuadType")
701 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
702 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
703 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
704 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
705 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
706 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
707 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
708 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
709 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
712 .beginClass <DSP::DspShm> ("DspShm")
713 .addFunction ("allocate", &DSP::DspShm::allocate)
714 .addFunction ("clear", &DSP::DspShm::clear)
715 .addFunction ("to_float", &DSP::DspShm::to_float)
716 .addFunction ("to_int", &DSP::DspShm::to_int)
717 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
718 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
721 .endNamespace () // DSP
722 .endNamespace (); // ARDOUR
726 LuaBindings::session (lua_State* L)
728 // non-realtime session functions
729 luabridge::getGlobalNamespace (L)
730 .beginNamespace ("ARDOUR")
731 .beginClass <Session> ("Session")
732 .addFunction ("save_state", &Session::save_state)
733 .addFunction ("set_dirty", &Session::set_dirty)
734 .addFunction ("unknown_processors", &Session::unknown_processors)
736 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
737 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
738 //.addFunction ("new_midi_track", &Session::new_midi_track)
741 .endNamespace (); // ARDOUR
745 LuaBindings::osc (lua_State* L)
747 luabridge::getGlobalNamespace (L)
748 .beginNamespace ("OSC")
749 .beginClass<LuaAPI::LuaOSCAddress> ("Address")
750 .addConstructor<void (*) (std::string)> ()
751 .addCFunction ("send", &LuaAPI::LuaOSCAddress::send)
757 LuaBindings::set_session (lua_State* L, Session *s)
759 /* LuaBridge uses unique keys to identify classes/c-types.
761 * Those keys are "generated" by using the memory-address of a static
762 * variable, templated for every Class.
763 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
765 * When linking the final executable there must be exactly one static
766 * function (static variable) for every templated class.
767 * This works fine on OSX and Linux...
769 * Windows (mingw and MSVC) however expand the template differently for libardour
770 * AND gtk2_ardour. We end up with two identical static functions
771 * at different addresses!!
773 * The Solution: have gtk2_ardour never include LuaBridge headers directly
774 * and always go via libardour function calls for classes that are registered
775 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
776 * which expand the template is not)
778 * (the actual cause: even static symbols in a .dll have no fixed address
779 * and are mapped when loading the dll. static functions in .exe do have a fixed
783 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
784 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
785 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
788 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
789 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
790 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
794 luabridge::push <Session *> (L, s);
795 lua_setglobal (L, "Session");
798 // call lua function.
799 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
800 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args