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)>(&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 ("n_audio", &ChanCount::n_audio)
467 .beginClass <DataType> ("DataType")
468 .addConstructor <void (*) (std::string)> ()
471 /* libardour enums */
472 .beginNamespace ("PluginType")
473 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
474 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
475 .addConst ("LV2", ARDOUR::PluginType(LV2))
476 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
477 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
478 .addConst ("Lua", ARDOUR::PluginType(Lua))
481 .beginNamespace ("AutoStyle")
482 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
483 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
486 .beginNamespace ("AutoState")
487 .addConst ("Off", ARDOUR::AutoState(Off))
488 .addConst ("Write", ARDOUR::AutoState(Write))
489 .addConst ("Touch", ARDOUR::AutoState(Touch))
490 .addConst ("Play", ARDOUR::AutoState(Play))
493 .beginNamespace ("AutomationType")
494 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
497 .beginNamespace ("SrcQuality")
498 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
501 .beginNamespace ("PlaylistDisposition")
502 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
503 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
504 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
507 luabridge::getGlobalNamespace (L)
508 .beginNamespace ("ARDOUR")
509 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
510 .addData ("name", &AudioBackendInfo::name)
512 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
514 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
515 .addData ("name", &AudioBackend::DeviceStatus::name)
516 .addData ("available", &AudioBackend::DeviceStatus::available)
518 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
520 .beginWSPtrClass <AudioBackend> ("AudioBackend")
521 .addFunction ("info", &AudioBackend::info)
522 .addFunction ("sample_rate", &AudioBackend::sample_rate)
523 .addFunction ("buffer_size", &AudioBackend::buffer_size)
524 .addFunction ("period_size", &AudioBackend::period_size)
525 .addFunction ("input_channels", &AudioBackend::input_channels)
526 .addFunction ("output_channels", &AudioBackend::output_channels)
527 .addFunction ("dsp_load", &AudioBackend::dsp_load)
529 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
530 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
531 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
533 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
534 .addFunction ("driver_name", &AudioBackend::driver_name)
535 .addFunction ("set_driver", &AudioBackend::set_driver)
537 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
538 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
539 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
540 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
541 .addFunction ("device_name", &AudioBackend::device_name)
542 .addFunction ("input_device_name", &AudioBackend::input_device_name)
543 .addFunction ("output_device_name", &AudioBackend::output_device_name)
544 .addFunction ("set_device_name", &AudioBackend::set_device_name)
545 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
546 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
549 .beginClass <AudioEngine> ("AudioEngine")
550 .addFunction ("available_backends", &AudioEngine::available_backends)
551 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
552 .addFunction ("set_backend", &AudioEngine::set_backend)
553 .addFunction ("setup_required", &AudioEngine::setup_required)
554 .addFunction ("start", &AudioEngine::start)
555 .addFunction ("stop", &AudioEngine::stop)
556 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
557 .addFunction ("set_device_name", &AudioEngine::set_device_name)
558 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
559 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
560 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
564 // basic representation of Session
565 // functions which can be used from realtime and non-realtime contexts
566 luabridge::getGlobalNamespace (L)
567 .beginNamespace ("ARDOUR")
568 .beginClass <Session> ("Session")
569 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
570 .addFunction ("transport_rolling", &Session::transport_rolling)
571 .addFunction ("request_transport_speed", &Session::request_transport_speed)
572 .addFunction ("transport_frame", &Session::transport_frame)
573 .addFunction ("transport_speed", &Session::transport_speed)
574 .addFunction ("frame_rate", &Session::frame_rate)
575 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
576 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
577 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
578 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
579 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
580 .addFunction ("request_locate", &Session::request_locate)
581 .addFunction ("request_stop", &Session::request_stop)
582 .addFunction ("last_transport_start", &Session::last_transport_start)
583 .addFunction ("goto_start", &Session::goto_start)
584 .addFunction ("goto_end", &Session::goto_end)
585 .addFunction ("current_start_frame", &Session::current_start_frame)
586 .addFunction ("current_end_frame", &Session::current_end_frame)
587 .addFunction ("actively_recording", &Session::actively_recording)
588 .addFunction ("get_routes", &Session::get_routes)
589 .addFunction ("get_tracks", &Session::get_tracks)
590 .addFunction ("name", &Session::name)
591 .addFunction ("path", &Session::path)
592 .addFunction ("record_status", &Session::record_status)
593 .addFunction ("route_by_id", &Session::route_by_id)
594 .addFunction ("route_by_name", &Session::route_by_name)
595 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
596 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
597 .addFunction ("source_by_id", &Session::source_by_id)
598 .addFunction ("controllable_by_id", &Session::controllable_by_id)
599 .addFunction ("processor_by_id", &Session::processor_by_id)
600 .addFunction ("snap_name", &Session::snap_name)
601 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
604 .beginClass <RegionFactory> ("RegionFactory")
605 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
609 .beginNamespace ("Session")
611 .beginNamespace ("RecordState")
612 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
613 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
614 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
617 .endNamespace () // END Session enums
619 .beginNamespace ("LuaAPI")
620 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
621 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
622 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
623 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
624 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
627 .endNamespace ();// END ARDOUR
631 LuaBindings::dsp (lua_State* L)
633 luabridge::getGlobalNamespace (L)
634 .beginNamespace ("ARDOUR")
636 .beginClass <AudioBuffer> ("AudioBuffer")
637 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
638 .addFunction ("silence", &AudioBuffer::silence)
639 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
642 .beginClass <MidiBuffer> ("MidiBuffer")
643 .addFunction ("silence", &MidiBuffer::silence)
644 .addFunction ("empty", &MidiBuffer::empty)
648 .beginClass <BufferSet> ("BufferSet")
649 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
650 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
654 luabridge::getGlobalNamespace (L)
655 .beginNamespace ("Evoral")
656 .beginClass <Evoral::Event<framepos_t> > ("Event")
657 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
658 .addFunction ("size", &Evoral::Event<framepos_t>::size)
659 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
660 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
663 .beginClass <Evoral::Beats> ("Beats")
664 .addFunction ("to_double", &Evoral::Beats::to_double)
667 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
669 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
670 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
671 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
672 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
676 // dsp releated session functions
677 luabridge::getGlobalNamespace (L)
678 .beginNamespace ("ARDOUR")
679 .beginClass <Session> ("Session")
680 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
681 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
685 luabridge::getGlobalNamespace (L)
686 .beginNamespace ("ARDOUR")
687 .beginNamespace ("DSP")
688 .addFunction ("compute_peak", ARDOUR::compute_peak)
689 .addFunction ("find_peaks", ARDOUR::find_peaks)
690 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
691 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
692 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
693 .addFunction ("copy_vector", ARDOUR::copy_vector)
694 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
695 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
696 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
697 .addFunction ("memset", &DSP::memset)
698 .addFunction ("mmult", &DSP::mmult)
699 .addFunction ("log_meter", &DSP::log_meter)
700 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
701 .addRefFunction ("peaks", &DSP::peaks)
703 .beginClass <DSP::LowPass> ("LowPass")
704 .addConstructor <void (*) (double, float)> ()
705 .addFunction ("proc", &DSP::LowPass::proc)
706 .addFunction ("ctrl", &DSP::LowPass::ctrl)
707 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
708 .addFunction ("reset", &DSP::LowPass::reset)
710 .beginClass <DSP::BiQuad> ("Biquad")
711 .addConstructor <void (*) (double)> ()
712 .addFunction ("run", &DSP::BiQuad::run)
713 .addFunction ("compute", &DSP::BiQuad::compute)
714 .addFunction ("reset", &DSP::BiQuad::reset)
718 .beginNamespace ("BiQuadType")
719 .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
720 .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
721 .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
722 .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
723 .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
724 .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
725 .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
726 .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
727 .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
730 .beginClass <DSP::DspShm> ("DspShm")
731 .addFunction ("allocate", &DSP::DspShm::allocate)
732 .addFunction ("clear", &DSP::DspShm::clear)
733 .addFunction ("to_float", &DSP::DspShm::to_float)
734 .addFunction ("to_int", &DSP::DspShm::to_int)
735 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
736 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
739 .endNamespace () // DSP
740 .endNamespace (); // ARDOUR
744 LuaBindings::session (lua_State* L)
746 // non-realtime session functions
747 luabridge::getGlobalNamespace (L)
748 .beginNamespace ("ARDOUR")
749 .beginClass <Session> ("Session")
750 .addFunction ("save_state", &Session::save_state)
751 .addFunction ("set_dirty", &Session::set_dirty)
752 .addFunction ("unknown_processors", &Session::unknown_processors)
754 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
755 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
756 //.addFunction ("new_midi_track", &Session::new_midi_track)
759 .endNamespace (); // ARDOUR
763 LuaBindings::osc (lua_State* L)
765 luabridge::getGlobalNamespace (L)
766 .beginNamespace ("ARDOUR")
767 .beginNamespace ("LuaOSC")
768 .beginClass<LuaOSC::Address> ("Address")
769 .addConstructor<void (*) (std::string)> ()
770 .addCFunction ("send", &LuaOSC::Address::send)
777 LuaBindings::set_session (lua_State* L, Session *s)
779 /* LuaBridge uses unique keys to identify classes/c-types.
781 * Those keys are "generated" by using the memory-address of a static
782 * variable, templated for every Class.
783 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
785 * When linking the final executable there must be exactly one static
786 * function (static variable) for every templated class.
787 * This works fine on OSX and Linux...
789 * Windows (mingw and MSVC) however expand the template differently for libardour
790 * AND gtk2_ardour. We end up with two identical static functions
791 * at different addresses!!
793 * The Solution: have gtk2_ardour never include LuaBridge headers directly
794 * and always go via libardour function calls for classes that are registered
795 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
796 * which expand the template is not)
798 * (the actual cause: even static symbols in a .dll have no fixed address
799 * and are mapped when loading the dll. static functions in .exe do have a fixed
803 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
804 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
805 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
808 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
809 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
810 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
814 luabridge::push <Session *> (L, s);
815 lua_setglobal (L, "Session");
818 // call lua function.
819 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
820 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args