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)
75 .beginNamespace ("ARDOUR")
76 .beginStdList <std::string> ("StringList")
80 // std::vector<std::string>
81 luabridge::getGlobalNamespace (L)
82 .beginNamespace ("ARDOUR")
83 .beginStdVector <std::string> ("StringVector")
87 // register float array (float*)
88 luabridge::getGlobalNamespace (L)
89 .beginNamespace ("ARDOUR")
90 .registerArray <float> ("FloatArray")
93 // register float array (int32_t*)
94 luabridge::getGlobalNamespace (L)
95 .beginNamespace ("ARDOUR")
96 .registerArray <int32_t> ("IntArray")
99 // std::vector<std::string>
100 luabridge::getGlobalNamespace (L)
101 .beginNamespace ("ARDOUR")
102 .beginStdVector <double> ("DoubleVector")
110 LuaBindings::common (lua_State* L)
112 luabridge::getGlobalNamespace (L)
113 .beginNamespace ("PBD")
114 .beginClass <PBD::ID> ("ID")
115 .addConstructor <void (*) (std::string)> ()
116 .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
119 .beginWSPtrClass <PBD::Stateful> ("Stateful")
120 .addFunction ("properties", &PBD::Stateful::properties)
123 .deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
126 .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
127 .addFunction ("get_value", &PBD::Controllable::get_value)
130 .beginNamespace ("GroupControlDisposition")
131 .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
132 .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
133 .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
138 luabridge::getGlobalNamespace (L)
139 .beginNamespace ("ARDOUR") // XXX really libtimecode
140 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
141 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
145 luabridge::getGlobalNamespace (L)
146 .beginNamespace ("ARDOUR")
147 .beginWSPtrClass <PluginInfo> ("PluginInfo")
148 .addVoidConstructor ()
151 .beginNamespace ("Route")
152 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
153 .addVoidConstructor ()
157 .beginNamespace ("Properties")
158 // templated class definitions
159 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
160 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
161 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
162 // actual references (TODO: also expose GQuark for std::set)
164 .addConst ("Start", &ARDOUR::Properties::start)
165 .addConst ("Length", &ARDOUR::Properties::length)
166 .addConst ("Position", &ARDOUR::Properties::position)
169 .beginClass <PBD::PropertyChange> ("PropertyChange")
170 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
171 // -> direct map to lua table beginStdSet()A
173 // expand templated PropertyDescriptor<T>
174 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
175 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
176 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
179 .beginClass <PBD::PropertyList> ("PropertyList")
180 // is-a std::map<PropertyID, PropertyBase*>
183 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
186 .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
187 .addFunction ("name", &SessionObject::name)
190 .deriveWSPtrClass <Route, SessionObject> ("Route")
191 .addFunction ("set_name", &Route::set_name)
192 .addFunction ("comment", &Route::comment)
193 .addFunction ("active", &Route::active)
194 .addFunction ("set_active", &Route::set_active)
195 .addFunction ("nth_plugin", &Route::nth_plugin)
196 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
197 .addFunction ("remove_processor", &Route::remove_processor)
198 .addFunction ("replace_processor", &Route::replace_processor)
199 .addFunction ("n_inputs", &Route::n_inputs)
200 .addFunction ("n_outputs", &Route::n_outputs)
201 .addFunction ("set_comment", &Route::set_comment)
204 .deriveWSPtrClass <Track, Route> ("Track")
205 .addFunction ("set_name", &Track::set_name)
206 .addFunction ("can_record", &Track::can_record)
207 .addFunction ("record_enabled", &Track::record_enabled)
208 .addFunction ("record_safe", &Track::record_safe)
209 .addFunction ("set_record_enabled", &Track::set_record_enabled)
210 .addFunction ("set_record_safe", &Track::set_record_safe)
213 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
216 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
219 .deriveWSPtrClass <Region, SessionObject> ("Region")
221 .addFunction ("position", &Region::position)
222 .addFunction ("start", &Region::start)
223 .addFunction ("length", &Region::length)
224 .addFunction ("layer", &Region::layer)
225 .addFunction ("data_type", &Region::data_type)
226 .addFunction ("stretch", &Region::stretch)
227 .addFunction ("shift", &Region::shift)
228 .addFunction ("sync_offset", &Region::sync_offset)
229 .addFunction ("sync_position", &Region::sync_position)
230 .addFunction ("hidden", &Region::hidden)
231 .addFunction ("muted", &Region::muted)
232 .addFunction ("opaque", &Region::opaque)
233 .addFunction ("locked", &Region::locked)
234 .addFunction ("position_locked", &Region::position_locked)
235 .addFunction ("video_locked", &Region::video_locked)
236 .addFunction ("valid_transients", &Region::valid_transients)
237 .addFunction ("automatic", &Region::automatic)
238 .addFunction ("whole_file", &Region::whole_file)
239 .addFunction ("captured", &Region::captured)
240 .addFunction ("can_move", &Region::can_move)
241 .addFunction ("sync_marked", &Region::sync_marked)
242 .addFunction ("external", &Region::external)
243 .addFunction ("import", &Region::import)
244 .addFunction ("covers", &Region::covers)
245 .addFunction ("at_natural_position", &Region::at_natural_position)
246 .addFunction ("is_compound", &Region::is_compound)
247 /* editing operations */
248 .addFunction ("set_length", &Region::set_length)
249 .addFunction ("set_start", &Region::set_start)
250 .addFunction ("set_position", &Region::set_position)
251 .addFunction ("set_initial_position", &Region::set_initial_position)
252 .addFunction ("nudge_position", &Region::nudge_position)
253 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
254 .addFunction ("move_start", &Region::move_start)
255 .addFunction ("trim_front", &Region::trim_front)
256 .addFunction ("trim_end", &Region::trim_end)
257 .addFunction ("trim_to", &Region::trim_to)
258 .addFunction ("cut_front", &Region::cut_front)
259 .addFunction ("cut_end", &Region::cut_end)
260 .addFunction ("raise", &Region::raise)
261 .addFunction ("lower", &Region::lower)
262 .addFunction ("raise_to_top", &Region::raise_to_top)
263 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
264 .addFunction ("set_sync_position", &Region::set_sync_position)
265 .addFunction ("clear_sync_position", &Region::clear_sync_position)
266 .addFunction ("set_hidden", &Region::set_hidden)
267 .addFunction ("set_muted", &Region::set_muted)
268 .addFunction ("set_opaque", &Region::set_opaque)
269 .addFunction ("set_locked", &Region::set_locked)
270 .addFunction ("set_video_locked", &Region::set_video_locked)
271 .addFunction ("set_position_locked", &Region::set_position_locked)
274 .beginWSPtrClass <Source> ("Source")
277 .beginClass <Evoral::Parameter> ("EvoralParameter")
278 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
279 .addFunction ("type", &Evoral::Parameter::type)
280 .addFunction ("channel", &Evoral::Parameter::channel)
281 .addFunction ("id", &Evoral::Parameter::id)
284 .beginClass <Plugin::PresetRecord> ("PresetRecord")
285 .addData ("uri", &Plugin::PresetRecord::uri, false)
286 .addData ("label", &Plugin::PresetRecord::label, false)
287 .addData ("user", &Plugin::PresetRecord::user, false)
288 .addData ("valid", &Plugin::PresetRecord::valid, false)
291 .beginWSPtrClass <Evoral::ControlList> ("EvoralControlList")
292 .addFunction ("add", &Evoral::ControlList::add)
295 .beginWSPtrClass <Evoral::ControlSet> ("EvoralControlSet")
298 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
299 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
302 .beginWSPtrClass <Evoral::Control> ("EvoralControl")
303 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
306 .beginClass <Evoral::ParameterDescriptor> ("EvoralParameterDescriptor")
307 .addVoidConstructor ()
308 .addData ("lower", &Evoral::ParameterDescriptor::lower)
309 .addData ("upper", &Evoral::ParameterDescriptor::upper)
310 .addData ("normal", &Evoral::ParameterDescriptor::normal)
311 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
314 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
315 .addVoidConstructor ()
316 .addData ("label", &ParameterDescriptor::label)
317 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
320 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
321 // TODO mult. inheritance
324 .deriveWSPtrClass <Processor, Automatable> ("Processor")
325 .addCast<PluginInsert> ("to_insert")
326 .addFunction ("display_name", &Processor::display_name)
327 .addFunction ("active", &Processor::active)
328 .addFunction ("activate", &Processor::activate)
329 .addFunction ("deactivate", &Processor::deactivate)
330 .addFunction ("control", (boost::shared_ptr<Evoral::Control>(Evoral::ControlSet::*)(const Evoral::Parameter&, bool))&Evoral::ControlSet::control)
331 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
334 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("PluginInsert")
335 .addFunction ("label", &Plugin::label)
336 .addFunction ("name", &Plugin::name)
337 .addFunction ("maker", &Plugin::maker)
338 .addFunction ("parameter_count", &Plugin::parameter_count)
339 .addFunction ("nth_parameter", &Plugin::nth_parameter)
340 .addFunction ("preset_by_label", &Plugin::preset_by_label)
341 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
342 .addFunction ("load_preset", &Plugin::load_preset)
343 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
344 .addFunction ("get_docs", &Plugin::get_docs)
345 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
346 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
349 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
350 .addFunction ("plugin", &PluginInsert::plugin)
351 .addFunction ("activate", &PluginInsert::activate)
352 .addFunction ("deactivate", &PluginInsert::deactivate)
355 .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
356 .addFunction ("automation_state", &AutomationControl::automation_state)
357 .addFunction ("automation_style", &AutomationControl::automation_style)
358 .addFunction ("set_automation_state", &AutomationControl::set_automation_state)
359 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
360 .addFunction ("start_touch", &AutomationControl::start_touch)
361 .addFunction ("stop_touch", &AutomationControl::stop_touch)
362 .addFunction ("get_value", &AutomationControl::get_value)
363 .addFunction ("set_value", &AutomationControl::set_value)
364 .addFunction ("writable", &AutomationControl::writable)
367 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
370 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
371 .addFunction ("readable_length", &AudioSource::readable_length)
372 .addFunction ("n_channels", &AudioSource::n_channels)
375 // <std::list<boost::shared_ptr <AudioTrack> >
376 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
379 // std::list<boost::shared_ptr <MidiTrack> >
380 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
383 // RouteList == boost::shared_ptr<std::list<boost::shared_ptr<Route> > >
384 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
387 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
388 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
391 // std::list< boost::weak_ptr <AudioSource>
392 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
395 #if 0 // depends on Evoal:: Note, Beats see note_fixer.h
396 // typedef Evoral::Note<Evoral::Beats> Note;
397 // std::set< boost::weak_ptr<Note> >
398 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
402 // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
403 .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
406 // std::list<boost::weak_ptr<Source> >
407 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
410 .beginClass <Tempo> ("Tempo")
411 .addConstructor <void (*) (double, double)> ()
412 .addFunction ("note_type", &Tempo::note_type)
413 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
414 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
417 .beginClass <Meter> ("Meter")
418 .addConstructor <void (*) (double, double)> ()
419 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
420 .addFunction ("note_divisor", &Meter::note_divisor)
421 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
422 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
425 .beginClass <TempoMap> ("TempoMap")
426 .addFunction ("add_tempo", &TempoMap::add_tempo)
427 .addFunction ("add_meter", &TempoMap::add_meter)
430 .beginClass <ChanCount> ("ChanCount")
431 .addFunction ("n_audio", &ChanCount::n_audio)
434 .beginClass <DataType> ("DataType")
435 .addConstructor <void (*) (std::string)> ()
438 /* libardour enums */
439 .beginNamespace ("PluginType")
440 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
441 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
442 .addConst ("LV2", ARDOUR::PluginType(LV2))
443 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
444 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
445 .addConst ("Lua", ARDOUR::PluginType(Lua))
448 .beginNamespace ("Autostyle")
449 .addConst ("Absolute", ARDOUR::AutoState(Absolute))
450 .addConst ("Trim", ARDOUR::AutoState(Trim))
453 .beginNamespace ("AutoState")
454 .addConst ("Off", ARDOUR::AutoState(Off))
455 .addConst ("Write", ARDOUR::AutoState(Write))
456 .addConst ("Touch", ARDOUR::AutoState(Touch))
457 .addConst ("Play", ARDOUR::AutoState(Play))
460 .beginNamespace ("AutomationType")
461 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
464 .beginNamespace ("SrcQuality")
465 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
468 .beginNamespace ("PlaylistDisposition")
469 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
470 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
471 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
474 luabridge::getGlobalNamespace (L)
475 .beginNamespace ("ARDOUR")
476 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
477 .addData ("name", &AudioBackendInfo::name)
479 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
481 .beginNamespace ("ARDOUR")
482 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
483 .addData ("name", &AudioBackend::DeviceStatus::name)
484 .addData ("available", &AudioBackend::DeviceStatus::available)
486 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
489 .beginWSPtrClass <AudioBackend> ("AudioBackend")
490 .addFunction ("info", &AudioBackend::info)
491 .addFunction ("sample_rate", &AudioBackend::sample_rate)
492 .addFunction ("buffer_size", &AudioBackend::buffer_size)
493 .addFunction ("period_size", &AudioBackend::period_size)
494 .addFunction ("input_channels", &AudioBackend::input_channels)
495 .addFunction ("output_channels", &AudioBackend::output_channels)
496 .addFunction ("dsp_load", &AudioBackend::dsp_load)
498 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
499 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
500 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
502 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
503 .addFunction ("driver_name", &AudioBackend::driver_name)
504 .addFunction ("set_driver", &AudioBackend::set_driver)
506 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
507 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
508 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
509 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
510 .addFunction ("device_name", &AudioBackend::device_name)
511 .addFunction ("input_device_name", &AudioBackend::input_device_name)
512 .addFunction ("output_device_name", &AudioBackend::output_device_name)
513 .addFunction ("set_device_name", &AudioBackend::set_device_name)
514 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
515 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
518 .beginClass <AudioEngine> ("AudioEngine")
519 .addFunction ("available_backends", &AudioEngine::available_backends)
520 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
521 .addFunction ("set_backend", &AudioEngine::set_backend)
522 .addFunction ("setup_required", &AudioEngine::setup_required)
523 .addFunction ("start", &AudioEngine::start)
524 .addFunction ("stop", &AudioEngine::stop)
525 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
526 .addFunction ("set_device_name", &AudioEngine::set_device_name)
527 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
528 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
529 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
533 // basic representation of Session
534 // functions which can be used from realtime and non-realtime contexts
535 luabridge::getGlobalNamespace (L)
536 .beginNamespace ("ARDOUR")
537 .beginClass <Session> ("Session")
538 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
539 .addFunction ("transport_rolling", &Session::transport_rolling)
540 .addFunction ("request_transport_speed", &Session::request_transport_speed)
541 .addFunction ("transport_frame", &Session::transport_frame)
542 .addFunction ("transport_speed", &Session::transport_speed)
543 .addFunction ("frame_rate", &Session::frame_rate)
544 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
545 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
546 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
547 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
548 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
549 .addFunction ("request_locate", &Session::request_locate)
550 .addFunction ("request_stop", &Session::request_stop)
551 .addFunction ("last_transport_start", &Session::last_transport_start)
552 .addFunction ("goto_start", &Session::goto_start)
553 .addFunction ("goto_end", &Session::goto_end)
554 .addFunction ("current_start_frame", &Session::current_start_frame)
555 .addFunction ("current_end_frame", &Session::current_end_frame)
556 .addFunction ("actively_recording", &Session::actively_recording)
557 .addFunction ("get_routes", &Session::get_routes)
558 .addFunction ("get_tracks", &Session::get_tracks)
559 .addFunction ("name", &Session::name)
560 .addFunction ("path", &Session::path)
561 .addFunction ("record_status", &Session::record_status)
562 .addFunction ("route_by_id", &Session::route_by_id)
563 .addFunction ("route_by_name", &Session::route_by_name)
564 .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
565 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
566 .addFunction ("source_by_id", &Session::source_by_id)
567 .addFunction ("controllable_by_id", &Session::controllable_by_id)
568 .addFunction ("processor_by_id", &Session::processor_by_id)
569 .addFunction ("snap_name", &Session::snap_name)
570 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
573 .beginClass <RegionFactory> ("RegionFactory")
574 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
578 .beginNamespace ("Session")
580 .beginNamespace ("RecordState")
581 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
582 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
583 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
586 .endNamespace () // END Session enums
588 .beginNamespace ("LuaAPI")
589 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
590 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
591 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
592 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
595 .endNamespace ();// END ARDOUR
599 LuaBindings::dsp (lua_State* L)
601 luabridge::getGlobalNamespace (L)
602 .beginNamespace ("ARDOUR")
604 .beginClass <AudioBuffer> ("AudioBuffer")
605 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
606 .addFunction ("silence", &AudioBuffer::silence)
607 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
610 .beginClass <MidiBuffer> ("MidiBuffer")
611 .addFunction ("silence", &MidiBuffer::silence)
612 .addFunction ("empty", &MidiBuffer::empty)
616 .beginClass <BufferSet> ("BufferSet")
617 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
618 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
621 .beginClass <ChanMapping> ("ChanMapping")
622 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t)>(&ChanMapping::get))
623 .addFunction ("set", &ChanMapping::set)
624 .addConst ("Invalid", 4294967295) // UINT32_MAX
628 luabridge::getGlobalNamespace (L)
629 .beginNamespace ("Evoral")
630 .beginClass <Evoral::Event<framepos_t> > ("Event")
631 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
632 .addFunction ("size", &Evoral::Event<framepos_t>::size)
633 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
634 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
637 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
639 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
640 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
641 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
642 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
646 // dsp releated session functions
647 luabridge::getGlobalNamespace (L)
648 .beginNamespace ("ARDOUR")
649 .beginClass <Session> ("Session")
650 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
651 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
655 luabridge::getGlobalNamespace (L)
656 .beginNamespace ("ARDOUR")
657 .beginNamespace ("DSP")
658 .addFunction ("compute_peak", ARDOUR::compute_peak)
659 .addFunction ("find_peaks", ARDOUR::find_peaks)
660 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
661 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
662 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
663 .addFunction ("copy_vector", ARDOUR::copy_vector)
664 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
665 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
666 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
667 .addFunction ("memset", &DSP::memset)
668 .addFunction ("mmult", &DSP::mmult)
669 .addFunction ("log_meter", &DSP::log_meter)
670 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
671 .addRefFunction ("peaks", &DSP::peaks)
673 .beginClass <DSP::LowPass> ("LowPass")
674 .addConstructor <void (*) (double, float)> ()
675 .addFunction ("proc", &DSP::LowPass::proc)
676 .addFunction ("ctrl", &DSP::LowPass::ctrl)
677 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
678 .addFunction ("reset", &DSP::LowPass::reset)
680 .beginClass <DSP::BiQuad> ("Biquad")
681 .addConstructor <void (*) (double)> ()
682 .addFunction ("run", &DSP::BiQuad::run)
683 .addFunction ("compute", &DSP::BiQuad::compute)
684 .addFunction ("reset", &DSP::BiQuad::reset)
687 .beginClass <DSP::DspShm> ("DspShm")
688 .addFunction ("allocate", &DSP::DspShm::allocate)
689 .addFunction ("clear", &DSP::DspShm::clear)
690 .addFunction ("to_float", &DSP::DspShm::to_float)
691 .addFunction ("to_int", &DSP::DspShm::to_int)
692 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
693 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
696 .endNamespace () // DSP
697 .endNamespace (); // ARDOUR
701 LuaBindings::session (lua_State* L)
703 // non-realtime session functions
704 luabridge::getGlobalNamespace (L)
705 .beginNamespace ("ARDOUR")
706 .beginClass <Session> ("Session")
707 .addFunction ("save_state", &Session::save_state)
708 .addFunction ("set_dirty", &Session::set_dirty)
709 .addFunction ("unknown_processors", &Session::unknown_processors)
711 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
712 // TODO session_add_audio_track session_add_midi_track session_add_mixed_track
713 //.addFunction ("new_midi_track", &Session::new_midi_track)
716 .endNamespace (); // ARDOUR
720 LuaBindings::osc (lua_State* L)
722 luabridge::getGlobalNamespace (L)
723 .beginNamespace ("OSC")
724 .beginClass<LuaAPI::LuaOSCAddress> ("Address")
725 .addConstructor<void (*) (std::string)> ()
726 .addCFunction ("send", &LuaAPI::LuaOSCAddress::send)
732 LuaBindings::set_session (lua_State* L, Session *s)
734 /* LuaBridge uses unique keys to identify classes/c-types.
736 * Those keys are "generated" by using the memory-address of a static
737 * variable, templated for every Class.
738 * (see libs/lua/LuaBridge/detail/ClassInfo.h)
740 * When linking the final executable there must be exactly one static
741 * function (static variable) for every templated class.
742 * This works fine on OSX and Linux...
744 * Windows (mingw and MSVC) however expand the template differently for libardour
745 * AND gtk2_ardour. We end up with two identical static functions
746 * at different addresses!!
748 * The Solution: have gtk2_ardour never include LuaBridge headers directly
749 * and always go via libardour function calls for classes that are registered
750 * in libardour. (calling lua itself is fine, calling c-functions in the GUI
751 * which expand the template is not)
753 * (the actual cause: even static symbols in a .dll have no fixed address
754 * and are mapped when loading the dll. static functions in .exe do have a fixed
758 * 0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
759 * 0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
760 * 0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
763 * 000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
764 * 000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
765 * 0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
769 luabridge::push <Session *> (L, s);
770 lua_setglobal (L, "Session");
773 // call lua function.
774 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
775 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args