1b6c760d4ddeb7b54aeabad6c929a831e3b5d550
[ardour.git] / libs / ardour / luabindings.cc
1 /*
2     Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3
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)
7     any later version.
8
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
12     for more details.
13
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.
17 */
18
19 #include <glibmm.h>
20
21 #include "timecode/bbt_time.h"
22 #include "pbd/stateful_diff_command.h"
23 #include "pbd/openuri.h"
24 #include "evoral/Control.hpp"
25 #include "evoral/ControlList.hpp"
26 #include "evoral/Range.hpp"
27
28 #include "ardour/amp.h"
29 #include "ardour/audioengine.h"
30 #include "ardour/audiosource.h"
31 #include "ardour/audio_backend.h"
32 #include "ardour/audio_buffer.h"
33 #include "ardour/audio_port.h"
34 #include "ardour/audio_track.h"
35 #include "ardour/buffer_set.h"
36 #include "ardour/chan_mapping.h"
37 #include "ardour/dB.h"
38 #include "ardour/dsp_filter.h"
39 #include "ardour/interthread_info.h"
40 #include "ardour/lua_api.h"
41 #include "ardour/luabindings.h"
42 #include "ardour/luaproc.h"
43 #include "ardour/meter.h"
44 #include "ardour/midi_track.h"
45 #include "ardour/midi_port.h"
46 #include "ardour/phase_control.h"
47 #include "ardour/playlist.h"
48 #include "ardour/plugin.h"
49 #include "ardour/plugin_insert.h"
50 #include "ardour/port_manager.h"
51 #include "ardour/runtime_functions.h"
52 #include "ardour/region.h"
53 #include "ardour/region_factory.h"
54 #include "ardour/route_group.h"
55 #include "ardour/session.h"
56 #include "ardour/session_object.h"
57 #include "ardour/sidechain.h"
58 #include "ardour/solo_isolate_control.h"
59 #include "ardour/solo_safe_control.h"
60 #include "ardour/stripable.h"
61 #include "ardour/track.h"
62 #include "ardour/tempo.h"
63
64 #include "LuaBridge/LuaBridge.h"
65
66 #ifdef PLATFORM_WINDOWS
67 /* luabridge uses addresses of static functions/variables to identify classes.
68  *
69  * Static symbols on windows (even identical symbols) are not
70  * mapped to the same address when mixing .dll + .exe.
71  * So we need a single point to define those static functions.
72  * (normally they're header-only in libs/lua/LuaBridge/detail/ClassInfo.h)
73  *
74  * Really!! A static function with a static variable in a library header
75  * should never ever be replicated, even if it is a template.
76  * But then again this is windows... what else can go wrong.
77  */
78
79 template <class T>
80 void const*
81 luabridge::ClassInfo<T>::getStaticKey ()
82 {
83         static char value;
84         return &value;
85 }
86
87 template <class T>
88 void const*
89 luabridge::ClassInfo<T>::getClassKey ()
90 {
91         static char value;
92         return &value;
93 }
94
95 template <class T>
96 void const*
97 luabridge::ClassInfo<T>::getConstKey ()
98 {
99         static char value;
100         return &value;
101 }
102
103 void*
104 luabridge::getIdentityKey ()
105 {
106   static char value;
107   return &value;
108 }
109
110 /* ...and this is the ugly part of it.
111  *
112  * We need to foward declare classes from gtk2_ardour
113  * end explicily list classes which are used by gtk2_ardour's bindings.
114  *
115  * This is needed because some of the GUI classes use objects from libardour
116  * as function parameters and the .exe would re-create symbols for libardour
117  * objects.
118  *
119  * Classes which don't use libardour symbols could be moved to
120  * gtk2_ardour/luainstance.cc, but keeping this here reduces code
121  * duplication and does not give the compiler a chance to even think
122  * about replicating the symbols.
123  */
124
125 #define CLASSKEYS(CLS) \
126         template void const* luabridge::ClassInfo< CLS >::getStaticKey(); \
127         template void const* luabridge::ClassInfo< CLS >::getClassKey();  \
128         template void const* luabridge::ClassInfo< CLS >::getConstKey();
129
130 #define CLASSINFO(CLS) \
131         class CLS; \
132         template void const* luabridge::ClassInfo< CLS >::getStaticKey(); \
133         template void const* luabridge::ClassInfo< CLS >::getClassKey();  \
134         template void const* luabridge::ClassInfo< CLS >::getConstKey();
135
136 CLASSINFO(MarkerSelection);
137 CLASSINFO(TrackSelection);
138 CLASSINFO(TrackViewList);
139 CLASSINFO(TimeSelection);
140 CLASSINFO(RegionSelection);
141 CLASSINFO(PublicEditor);
142 CLASSINFO(Selection);
143 CLASSINFO(ArdourMarker);
144
145 namespace LuaCairo {
146         class ImageSurface;
147         class PangoLayout;
148 }
149 CLASSKEYS(LuaCairo::ImageSurface);
150 CLASSKEYS(LuaCairo::PangoLayout);
151
152 namespace Cairo {
153         class Context;
154 }
155 CLASSKEYS(Cairo::Context);
156 CLASSKEYS(std::vector<double>);
157 CLASSKEYS(std::list<ArdourMarker*>);
158 CLASSKEYS(std::bitset<47ul>); // LuaSignal::LAST_SIGNAL
159 CLASSKEYS(ArdourMarker*);
160 CLASSKEYS(ARDOUR::RouteGroup);
161 CLASSKEYS(ARDOUR::LuaProc);
162 CLASSKEYS(ARDOUR::DataType);
163 CLASSKEYS(ARDOUR::ChanCount);
164 CLASSKEYS(boost::shared_ptr<ARDOUR::Processor>);
165 CLASSKEYS(ARDOUR::ParameterDescriptor);
166 CLASSKEYS(boost::shared_ptr<ARDOUR::AutomationList>);
167 CLASSKEYS(boost::shared_ptr<Evoral::ControlList>);
168 CLASSKEYS(ARDOUR::LuaOSC::Address);
169 CLASSKEYS(ARDOUR::Session);
170 CLASSKEYS(ARDOUR::BufferSet);
171 CLASSKEYS(ARDOUR::ChanMapping);
172 CLASSKEYS(ARDOUR::DSP::DspShm);
173 CLASSKEYS(ARDOUR::LuaTableRef);
174 CLASSKEYS(PBD::Configuration);
175 CLASSKEYS(ARDOUR::PresentationInfo);
176 CLASSKEYS(ARDOUR::SessionConfiguration);
177 CLASSKEYS(PBD::ID);
178 CLASSKEYS(ARDOUR::Location);
179 CLASSKEYS(ARDOUR::PluginInfo);
180 CLASSKEYS(PBD::PropertyChange);
181 CLASSKEYS(std::vector<std::string>);
182 CLASSKEYS(std::list<boost::shared_ptr<ARDOUR::Route> >);
183 CLASSKEYS(std::list<boost::shared_ptr<ARDOUR::Port> >);
184 CLASSKEYS(boost::shared_ptr<ARDOUR::PluginInfo>);
185 CLASSKEYS(boost::shared_ptr<ARDOUR::Region>);
186 CLASSKEYS(boost::weak_ptr<ARDOUR::Route>);
187 CLASSKEYS(std::list<boost::shared_ptr<ARDOUR::Region> >);
188 CLASSKEYS(std::list<ARDOUR::AudioRange>);
189 CLASSKEYS(Evoral::Beats);
190 CLASSKEYS(ARDOUR::PortEngine);
191 CLASSKEYS(ARDOUR::PortManager);
192 CLASSKEYS(ARDOUR::AudioEngine);
193 CLASSKEYS(void);
194 CLASSKEYS(float);
195
196 #endif // end windows special case
197
198 /* Some notes on Lua bindings for libardour and friends
199  *
200  * - Prefer factory methods over Contructors whenever possible.
201  *   Don't expose the constructor method unless required.
202  *
203  *   e.g. Don't allow the script to construct a "Track" Object directly
204  *   but do allow to create a "BBT_TIME" object.
205  *
206  * - Do not dereference Shared or Weak Pointers. Pass the pointer to Lua.
207  * - Define Objects as boost:shared_ptr Object whenever possible.
208  *
209  *   Storing a boost::shared_ptr in a Lua-variable keeps the reference
210  *   until that variable is set to 'nil'.
211  *   (if the script were to keep a direct pointer to the object instance, the
212  *   behaviour is undefined if the actual object goes away)
213  *
214  *   Methods of the actual class are indirectly exposed,
215  *   boost::*_ptr get() and ::lock() is implicit when the class is exported
216  *   as LuaBridge's "WSPtrClass".
217  */
218
219 using namespace ARDOUR;
220
221 void
222 LuaBindings::stddef (lua_State* L)
223 {
224         // std::list<std::string>
225         luabridge::getGlobalNamespace (L)
226                 .beginNamespace ("C")
227                 .beginStdList <std::string> ("StringList")
228                 .endClass ()
229
230         // std::vector<std::string>
231                 .beginStdVector <std::string> ("StringVector")
232                 .endClass ()
233
234         // register float array (uint8_t*)
235                 .registerArray <uint8_t> ("ByteArray")
236
237         // register float array (float*)
238                 .registerArray <float> ("FloatArray")
239
240         // register float array (int32_t*)
241                 .registerArray <int32_t> ("IntArray")
242
243         // TODO std::set
244                 .endNamespace ();
245 }
246
247 void
248 LuaBindings::common (lua_State* L)
249 {
250         luabridge::getGlobalNamespace (L)
251                 .beginNamespace ("PBD")
252
253                 .addFunction ("open_uri", (bool (*) (const std::string&))&PBD::open_uri)
254                 .addFunction ("open_uri", &PBD::open_folder)
255
256                 .beginClass <PBD::ID> ("ID")
257                 .addConstructor <void (*) (std::string)> ()
258                 .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
259                 .endClass ()
260
261                 .beginStdVector <PBD::ID> ("IdVector").endClass ()
262
263                 .beginClass <XMLNode> ("XMLNode")
264                 .addFunction ("name", &XMLNode::name)
265                 .endClass ()
266
267                 .beginClass <PBD::Stateful> ("Stateful")
268                 .addFunction ("id", &PBD::Stateful::id)
269                 .addFunction ("properties", &PBD::Stateful::properties)
270                 .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
271                 .endClass ()
272
273                 .beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
274                 .addFunction ("id", &PBD::Stateful::id)
275                 .addFunction ("properties", &PBD::Stateful::properties)
276                 .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
277                 .endClass ()
278
279                 .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
280                 .endClass ()
281
282                 .deriveClass <PBD::Configuration, PBD::Stateful> ("Configuration")
283                 .endClass()
284
285                 .deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructiblePtr")
286                 .endClass ()
287
288                 .deriveClass <Command, PBD::StatefulDestructible> ("Command")
289                 .addFunction ("set_name", &Command::set_name)
290                 .addFunction ("name", &Command::name)
291                 .endClass ()
292
293                 /* UndoTransaction::add_command() subscribes to DropReferences()
294                  * and deletes the object.
295                  *
296                  * This object cannot be constructed by lua because lua would manage lifetime
297                  * and delete the object leading to a double free.
298                  *
299                  * use Session::add_stateful_diff_command()
300                  * and Session::abort_reversible_command()
301                  */
302                 .deriveClass <PBD::StatefulDiffCommand, Command> ("StatefulDiffCommand")
303                 .addFunction ("undo", &PBD::StatefulDiffCommand::undo)
304                 .addFunction ("empty", &PBD::StatefulDiffCommand::empty)
305                 .endClass ()
306
307                 .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
308                 .addFunction ("name", &PBD::Controllable::name)
309                 .addFunction ("get_value", &PBD::Controllable::get_value)
310                 .endClass ()
311
312                 .beginClass <PBD::RingBufferNPT <uint8_t> > ("RingBuffer8")
313                 .addConstructor <void (*) (size_t)> ()
314                 .addFunction ("reset", &PBD::RingBufferNPT<uint8_t>::reset)
315                 .addFunction ("read", &PBD::RingBufferNPT<uint8_t>::read)
316                 .addFunction ("write", &PBD::RingBufferNPT<uint8_t>::write)
317                 .addFunction ("write_one", &PBD::RingBufferNPT<uint8_t>::write_one)
318                 .addFunction ("write_space", &PBD::RingBufferNPT<uint8_t>::write_space)
319                 .addFunction ("read_space", &PBD::RingBufferNPT<uint8_t>::read_space)
320                 .addFunction ("increment_read_ptr", &PBD::RingBufferNPT<uint8_t>::increment_read_ptr)
321                 .addFunction ("increment_write_ptr", &PBD::RingBufferNPT<uint8_t>::increment_write_ptr)
322                 .endClass ()
323
324                 .beginClass <PBD::RingBufferNPT <float> > ("RingBufferF")
325                 .addConstructor <void (*) (size_t)> ()
326                 .addFunction ("reset", &PBD::RingBufferNPT<float>::reset)
327                 .addFunction ("read", &PBD::RingBufferNPT<float>::read)
328                 .addFunction ("write", &PBD::RingBufferNPT<float>::write)
329                 .addFunction ("write_one", &PBD::RingBufferNPT<float>::write_one)
330                 .addFunction ("write_space", &PBD::RingBufferNPT<float>::write_space)
331                 .addFunction ("read_space", &PBD::RingBufferNPT<float>::read_space)
332                 .addFunction ("increment_read_ptr", &PBD::RingBufferNPT<float>::increment_read_ptr)
333                 .addFunction ("increment_write_ptr", &PBD::RingBufferNPT<float>::increment_write_ptr)
334                 .endClass ()
335
336                 .beginClass <PBD::RingBufferNPT <int> > ("RingBufferI")
337                 .addConstructor <void (*) (size_t)> ()
338                 .addFunction ("reset", &PBD::RingBufferNPT<int>::reset)
339                 .addFunction ("read", &PBD::RingBufferNPT<int>::read)
340                 .addFunction ("write", &PBD::RingBufferNPT<int>::write)
341                 .addFunction ("write_one", &PBD::RingBufferNPT<int>::write_one)
342                 .addFunction ("write_space", &PBD::RingBufferNPT<int>::write_space)
343                 .addFunction ("read_space", &PBD::RingBufferNPT<int>::read_space)
344                 .addFunction ("increment_read_ptr", &PBD::RingBufferNPT<int>::increment_read_ptr)
345                 .addFunction ("increment_write_ptr", &PBD::RingBufferNPT<int>::increment_write_ptr)
346                 .endClass ()
347
348                 /* PBD enums */
349                 .beginNamespace ("GroupControlDisposition")
350                 .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
351                 .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
352                 .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
353                 .endNamespace ()
354
355                 .endNamespace (); // PBD
356
357         luabridge::getGlobalNamespace (L)
358                 .beginNamespace ("Timecode")
359                 .beginClass <Timecode::BBT_Time> ("BBT_TIME")
360                 .addConstructor <void (*) (uint32_t, uint32_t, uint32_t)> ()
361                 .endClass ()
362
363                 /* libtimecode enums */
364                 .beginNamespace ("TimecodeFormat")
365                 .addConst ("TC23976", Timecode::TimecodeFormat(Timecode::timecode_23976))
366                 .addConst ("TC24", Timecode::TimecodeFormat(Timecode::timecode_24))
367                 .addConst ("TC24976", Timecode::TimecodeFormat(Timecode::timecode_24976))
368                 .addConst ("TC25", Timecode::TimecodeFormat(Timecode::timecode_25))
369                 .addConst ("TC2997", Timecode::TimecodeFormat(Timecode::timecode_2997))
370                 .addConst ("TC2997DF", Timecode::TimecodeFormat(Timecode::timecode_2997drop))
371                 .addConst ("TC2997000", Timecode::TimecodeFormat(Timecode::timecode_2997000))
372                 .addConst ("TC2997000DF", Timecode::TimecodeFormat(Timecode::timecode_2997000drop))
373                 .addConst ("TC30", Timecode::TimecodeFormat(Timecode::timecode_30))
374                 .addConst ("TC5994", Timecode::TimecodeFormat(Timecode::timecode_5994))
375                 .addConst ("TC60", Timecode::TimecodeFormat(Timecode::timecode_60))
376                 .endNamespace ()
377                 .endNamespace ();
378
379         luabridge::getGlobalNamespace (L)
380
381                 .beginNamespace ("Evoral")
382                 .beginClass <Evoral::Parameter> ("Parameter")
383                 .addConstructor <void (*) (uint32_t, uint8_t, uint32_t)> ()
384                 .addFunction ("type", &Evoral::Parameter::type)
385                 .addFunction ("channel", &Evoral::Parameter::channel)
386                 .addFunction ("id", &Evoral::Parameter::id)
387                 .endClass ()
388
389                 .beginWSPtrClass <Evoral::ControlList> ("ControlList")
390                 .addFunction ("add", &Evoral::ControlList::add)
391                 .addFunction ("thin", &Evoral::ControlList::thin)
392                 .addFunction ("eval", &Evoral::ControlList::eval)
393                 .addRefFunction ("rt_safe_eval", &Evoral::ControlList::rt_safe_eval)
394                 .addFunction ("interpolation", &Evoral::ControlList::interpolation)
395                 .addFunction ("set_interpolation", &Evoral::ControlList::set_interpolation)
396                 .addFunction ("truncate_end", &Evoral::ControlList::truncate_end)
397                 .addFunction ("truncate_start", &Evoral::ControlList::truncate_start)
398                 .addFunction ("clear", (void (Evoral::ControlList::*)(double, double))&Evoral::ControlList::clear)
399                 .addFunction ("in_write_pass", &Evoral::ControlList::in_write_pass)
400                 .endClass ()
401
402                 .beginWSPtrClass <Evoral::ControlSet> ("ControlSet")
403                 .endClass ()
404
405                 .beginWSPtrClass <Evoral::Control> ("Control")
406                 .addFunction ("list", (boost::shared_ptr<Evoral::ControlList>(Evoral::Control::*)())&Evoral::Control::list)
407                 .endClass ()
408
409                 .beginClass <Evoral::ParameterDescriptor> ("ParameterDescriptor")
410                 .addVoidConstructor ()
411                 .addData ("lower", &Evoral::ParameterDescriptor::lower)
412                 .addData ("upper", &Evoral::ParameterDescriptor::upper)
413                 .addData ("normal", &Evoral::ParameterDescriptor::normal)
414                 .addData ("toggled", &Evoral::ParameterDescriptor::toggled)
415                 .endClass ()
416
417                 .beginClass <Evoral::Range<framepos_t> > ("Range")
418                 .addConstructor <void (*) (framepos_t, framepos_t)> ()
419                 .addData ("from", &Evoral::Range<framepos_t>::from)
420                 .addData ("to", &Evoral::Range<framepos_t>::to)
421                 .endClass ()
422
423                 /* libevoral enums */
424                 .beginNamespace ("InterpolationStyle")
425                 .addConst ("Discrete", Evoral::ControlList::InterpolationStyle(Evoral::ControlList::Discrete))
426                 .addConst ("Linear", Evoral::ControlList::InterpolationStyle(Evoral::ControlList::Linear))
427                 .addConst ("Curved", Evoral::ControlList::InterpolationStyle(Evoral::ControlList::Curved))
428                 .endNamespace ()
429
430                 .endNamespace () // Evoral
431
432                 .beginNamespace ("ARDOUR")
433
434                 .beginClass <InterThreadInfo> ("InterThreadInfo")
435                 .addVoidConstructor ()
436                 .addData ("done", const_cast<bool InterThreadInfo::*>(&InterThreadInfo::done))
437 #if 0 // currently unused, lua is single-threaded, no custom UIs.
438                 .addData ("cancel", (bool InterThreadInfo::*)&InterThreadInfo::cancel)
439 #endif
440                 .addData ("progress", const_cast<float InterThreadInfo::*>(&InterThreadInfo::progress))
441                 .endClass ()
442
443                 .beginClass <AudioRange> ("AudioRange")
444                 .addConstructor <void (*) (framepos_t, framepos_t, uint32_t)> ()
445                 .addFunction ("length", &AudioRange::length)
446                 .addFunction ("equal", &AudioRange::equal)
447                 .addData ("start", &AudioRange::start)
448                 .addData ("_end", &AudioRange::end) // XXX "end" is a lua reserved word
449                 .addData ("id", &AudioRange::id)
450                 .endClass ()
451
452                 .beginWSPtrClass <PluginInfo> ("PluginInfo")
453                 .addVoidConstructor ()
454                 .endClass ()
455
456                 .beginNamespace ("Route")
457                 .beginClass <Route::ProcessorStreams> ("ProcessorStreams")
458                 .addVoidConstructor ()
459                 .endClass ()
460                 .endNamespace ()
461
462                 .beginClass <ChanMapping> ("ChanMapping")
463                 .addVoidConstructor ()
464                 .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t) const>(&ChanMapping::get))
465                 .addFunction ("set", &ChanMapping::set)
466                 .addFunction ("count", &ChanMapping::count)
467                 .addFunction ("n_total", &ChanMapping::n_total)
468                 .addFunction ("is_monotonic", &ChanMapping::is_monotonic)
469                 .addConst ("Invalid", 4294967295U) // UINT32_MAX
470                 .endClass ()
471
472                 .beginNamespace ("Properties")
473                 // templated class definitions
474                 .beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
475                 .beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
476                 .beginClass <PBD::PropertyDescriptor<framepos_t> > ("FrameposProperty").endClass ()
477                 // actual references (TODO: also expose GQuark for std::set)
478                 //   ardour/region.h
479                 .addConst ("Start", &ARDOUR::Properties::start)
480                 .addConst ("Length", &ARDOUR::Properties::length)
481                 .addConst ("Position", &ARDOUR::Properties::position)
482                 .endNamespace ()
483
484                 .beginClass <PBD::PropertyChange> ("PropertyChange")
485                 // TODO add special handling (std::set<PropertyID>), PropertyID is a GQuark.
486                 // -> direct map to lua table  beginStdSet()A
487                 //
488                 // expand templated PropertyDescriptor<T>
489                 .addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
490                 .addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
491                 .addFunction ("containsFramePos", &PBD::PropertyChange::contains<framepos_t>)
492                 .endClass ()
493
494                 .beginClass <PBD::PropertyList> ("PropertyList")
495                 // is-a  std::map<PropertyID, PropertyBase*>
496                 .endClass ()
497
498                 .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
499                 .endClass ()
500
501                 .beginWSPtrClass <AutomationList> ("AutomationList")
502                 .addCast<PBD::Stateful> ("to_stateful")
503                 .addCast<PBD::StatefulDestructible> ("to_statefuldestructible")
504                 .addCast<Evoral::ControlList> ("list")
505                 .addFunction ("get_state", &AutomationList::get_state)
506                 .addFunction ("memento_command", &AutomationList::memento_command)
507                 .addFunction ("touching", &AutomationList::touching)
508                 .addFunction ("writing", &AutomationList::writing)
509                 .addFunction ("touch_enabled", &AutomationList::touch_enabled)
510                 .endClass ()
511
512                 .deriveClass <Location, PBD::StatefulDestructible> ("Location")
513                 .addFunction ("locked", &Location::locked)
514                 .addFunction ("lock", &Location::lock)
515                 .addFunction ("unlock", &Location::unlock)
516                 .addFunction ("start", &Location::start)
517                 .addFunction ("_end", &Location::end) // XXX "end" is a lua reserved word
518                 .addFunction ("length", &Location::length)
519                 .addFunction ("set_start", &Location::set_start)
520                 .addFunction ("set_end", &Location::set_end)
521                 .addFunction ("set_length", &Location::set)
522                 .addFunction ("move_to", &Location::move_to)
523                 .addFunction ("matches", &Location::matches)
524                 .addFunction ("flags", &Location::flags)
525                 .addFunction ("is_auto_punch", &Location::is_auto_punch)
526                 .addFunction ("is_auto_loop", &Location::is_auto_loop)
527                 .addFunction ("is_mark", &Location::is_mark)
528                 .addFunction ("is_hidden", &Location::is_hidden)
529                 .addFunction ("is_cd_marker", &Location::is_cd_marker)
530                 .addFunction ("is_session_range", &Location::is_session_range)
531                 .addFunction ("is_range_marker", &Location::is_range_marker)
532                 .endClass ()
533
534                 .deriveClass <Locations, PBD::StatefulDestructible> ("Locations")
535                 .addFunction ("list", static_cast<Locations::LocationList (Locations::*)()>(&Locations::list))
536                 .addFunction ("auto_loop_location", &Locations::auto_loop_location)
537                 .addFunction ("auto_punch_location", &Locations::auto_punch_location)
538                 .addFunction ("session_range_location", &Locations::session_range_location)
539                 .addFunction ("first_mark_after", &Locations::first_mark_after)
540                 .addFunction ("first_mark_before", &Locations::first_mark_before)
541                 .addFunction ("first_mark_at", &Locations::mark_at)
542                 .addRefFunction ("marks_either_side", &Locations::marks_either_side)
543                 .addRefFunction ("find_all_between", &Locations::find_all_between)
544                 .endClass ()
545
546                 .beginWSPtrClass <SessionObject> ("SessionObject")
547                 /* SessionObject is-a PBD::StatefulDestructible,
548                  * but multiple inheritance is not covered by luabridge,
549                  * we need explicit casts */
550                 .addCast<PBD::Stateful> ("to_stateful")
551                 .addCast<PBD::StatefulDestructible> ("to_statefuldestructible")
552                 .addFunction ("name", &SessionObject::name)
553                 .endClass ()
554
555                 .beginWSPtrClass <Port> ("Port")
556                 .addCast<MidiPort> ("to_midiport")
557                 .addCast<AudioPort> ("to_audioport")
558                 .addFunction ("name", &Port::name)
559                 .addFunction ("pretty_name", &Port::pretty_name)
560                 .addFunction ("receives_input", &Port::receives_input)
561                 .addFunction ("sends_output", &Port::sends_output)
562                 .addFunction ("connected", &Port::connected)
563                 .addFunction ("disconnect_all", &Port::disconnect_all)
564                 .addFunction ("connected_to_name", (bool (Port::*)(std::string const &)const)&Port::connected_to)
565                 .addFunction ("connect_by_name", (int (Port::*)(std::string const &))&Port::connect)
566                 .addFunction ("disconnect_by_name", (int (Port::*)(std::string const &))&Port::disconnect)
567                 .addFunction ("connected_to", (bool (Port::*)(Port*)const)&Port::connected_to)
568                 .addFunction ("connect", (int (Port::*)(Port*))&Port::connect)
569                 .addFunction ("disconnect", (int (Port::*)(Port*))&Port::disconnect)
570                 //.addStaticFunction ("port_offset", &Port::port_offset) // static
571                 .endClass ()
572
573                 .deriveWSPtrClass <AudioPort, Port> ("AudioPort")
574                 .endClass ()
575
576                 .deriveWSPtrClass <MidiPort, Port> ("MidiPort")
577                 .addFunction ("input_active", &MidiPort::input_active)
578                 .addFunction ("set_input_active", &MidiPort::set_input_active)
579                 .addFunction ("get_midi_buffer", &MidiPort::get_midi_buffer) // DSP only
580                 .endClass ()
581
582                 .beginWSPtrClass <PortSet> ("PortSet")
583                 .addFunction ("num_ports", (size_t (PortSet::*)(DataType)const)&PortSet::num_ports)
584                 .addFunction ("add", &PortSet::add)
585                 .addFunction ("remove", &PortSet::remove)
586                 .addFunction ("port", (boost::shared_ptr<Port> (PortSet::*)(DataType, size_t)const)&PortSet::port)
587                 .addFunction ("contains", &PortSet::contains)
588                 .addFunction ("clear", &PortSet::clear)
589                 .addFunction ("empty", &PortSet::empty)
590                 .endClass ()
591
592                 .deriveWSPtrClass <IO, SessionObject> ("IO")
593                 .addFunction ("active", &IO::active)
594                 .addFunction ("add_port", &IO::add_port)
595                 .addFunction ("remove_port", &IO::remove_port)
596                 .addFunction ("connect", &IO::connect)
597                 .addFunction ("disconnect", (int (IO::*)(boost::shared_ptr<Port>, std::string, void *))&IO::disconnect)
598                 .addFunction ("physically_connected", &IO::physically_connected)
599                 .addFunction ("has_port", &IO::has_port)
600                 .addFunction ("nth", &IO::nth)
601                 .addFunction ("audio", &IO::audio)
602                 .addFunction ("midi", &IO::midi)
603                 .addFunction ("port_by_name", &IO::nth)
604                 .addFunction ("n_ports", &IO::n_ports)
605                 .endClass ()
606
607                 .beginClass <RouteGroup> ("RouteGroup")
608                 // stub RouteGroup* is needed for new_audio_track()
609                 .endClass ()
610
611                 .deriveClass <PresentationInfo, PBD::Stateful> ("PresentationInfo")
612                 .addFunction ("color", &PresentationInfo::color)
613                 .addFunction ("set_color", &PresentationInfo::set_color)
614                 .addFunction ("order", &PresentationInfo::order)
615                 .endClass ()
616
617                 .deriveWSPtrClass <Stripable, SessionObject> ("Stripable")
618                 .addCast<Route> ("to_route")
619                 .addFunction ("is_auditioner", &Stripable::is_auditioner)
620                 .addFunction ("is_master", &Stripable::is_master)
621                 .addFunction ("is_monitor", &Stripable::is_monitor)
622                 .addFunction ("is_hidden", &Stripable::is_hidden)
623                 .addFunction ("is_selected", &Stripable::is_selected)
624                 .addFunction ("gain_control", &Stripable::gain_control)
625                 .addFunction ("solo_control", &Stripable::solo_control)
626                 .addFunction ("solo_isolate_control", &Stripable::solo_isolate_control)
627                 .addFunction ("solo_safe_control", &Stripable::solo_safe_control)
628                 .addFunction ("mute_control", &Stripable::mute_control)
629                 .addFunction ("phase_control", &Stripable::phase_control)
630                 .addFunction ("trim_control", &Stripable::trim_control)
631                 .addFunction ("rec_enable_control", &Stripable::rec_enable_control)
632                 .addFunction ("rec_safe_control", &Stripable::rec_safe_control)
633                 .addFunction ("pan_azimuth_control", &Stripable::pan_azimuth_control)
634                 .addFunction ("pan_elevation_control", &Stripable::pan_elevation_control)
635                 .addFunction ("pan_width_control", &Stripable::pan_width_control)
636                 .addFunction ("pan_frontback_control", &Stripable::pan_frontback_control)
637                 .addFunction ("pan_lfe_control", &Stripable::pan_lfe_control)
638                 .addFunction ("send_level_control", &Stripable::send_level_controllable)
639                 .addFunction ("send_enable_control", &Stripable::send_level_controllable)
640                 .addFunction ("send_name", &Stripable::send_name)
641                 .addFunction ("monitor_control", &Stripable::monitor_control)
642                 .addFunction ("master_send_enable_control ", &Stripable::master_send_enable_controllable )
643                 .addFunction ("comp_enable_control ", &Stripable::comp_enable_controllable )
644                 .addFunction ("comp_threshold_control ", &Stripable::comp_threshold_controllable )
645                 .addFunction ("comp_speed_control ", &Stripable::comp_speed_controllable )
646                 .addFunction ("comp_mode_control ", &Stripable::comp_mode_controllable )
647                 .addFunction ("comp_makeup_control ", &Stripable::comp_makeup_controllable )
648                 .addFunction ("comp_redux_control ", &Stripable::comp_redux_controllable )
649                 .addFunction ("comp_mode_name", &Stripable::comp_mode_name)
650                 .addFunction ("comp_speed_name", &Stripable::comp_speed_name)
651                 .addFunction ("eq_band_cnt ", &Stripable::eq_band_cnt)
652                 .addFunction ("eq_band_name", &Stripable::eq_band_name)
653                 .addFunction ("eq_gain_control", &Stripable::eq_gain_controllable)
654                 .addFunction ("eq_freq_control ", &Stripable::eq_freq_controllable )
655                 .addFunction ("eq_q_control ", &Stripable::eq_q_controllable )
656                 .addFunction ("eq_shape_control ", &Stripable::eq_shape_controllable )
657                 .addFunction ("eq_enable_control ", &Stripable::eq_enable_controllable )
658                 .addFunction ("eq_hpf_control ", &Stripable::eq_hpf_controllable )
659                 .addFunction ("set_presentation_order", &Stripable::set_presentation_order)
660                 .addFunction ("presentation_info_ptr", &Stripable::presentation_info_ptr)
661
662                 .endClass ()
663
664                 .deriveWSPtrClass <Route, Stripable> ("Route")
665                 .addCast<Track> ("to_track")
666                 .addFunction ("set_name", &Route::set_name)
667                 .addFunction ("comment", &Route::comment)
668                 .addFunction ("active", &Route::active)
669                 .addFunction ("set_active", &Route::set_active)
670                 .addFunction ("nth_plugin", &Route::nth_plugin)
671                 .addFunction ("nth_processor", &Route::nth_processor)
672                 .addFunction ("nth_send", &Route::nth_send)
673                 .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
674                 .addFunction ("remove_processor", &Route::remove_processor)
675                 .addFunction ("replace_processor", &Route::replace_processor)
676                 .addFunction ("n_inputs", &Route::n_inputs)
677                 .addFunction ("n_outputs", &Route::n_outputs)
678                 .addFunction ("set_comment", &Route::set_comment)
679                 .addFunction ("strict_io", &Route::strict_io)
680                 .addFunction ("set_strict_io", &Route::set_strict_io)
681                 .addFunction ("reset_plugin_insert", &Route::reset_plugin_insert)
682                 .addFunction ("customize_plugin_insert", &Route::customize_plugin_insert)
683                 .addFunction ("add_sidechain", &Route::add_sidechain)
684                 .addFunction ("remove_sidechain", &Route::remove_sidechain)
685                 .addFunction ("main_outs", &Route::main_outs)
686                 .addFunction ("muted", &Route::muted)
687                 .addFunction ("soloed", &Route::soloed)
688                 .addFunction ("amp", &Route::amp)
689                 .addFunction ("trim", &Route::trim)
690                 .endClass ()
691
692                 .deriveWSPtrClass <Playlist, SessionObject> ("Playlist")
693                 .addFunction ("region_by_id", &Playlist::region_by_id)
694                 .addFunction ("data_type", &Playlist::data_type)
695                 .addFunction ("n_regions", &Playlist::n_regions)
696                 //.addFunction ("get_extent", &Playlist::get_extent) // pair<framepos_t, framepos_t>
697                 .addFunction ("region_list", &Playlist::region_list)
698                 .addFunction ("add_region", &Playlist::add_region)
699                 .addFunction ("remove_region", &Playlist::remove_region)
700                 .addFunction ("regions_at", &Playlist::regions_at)
701                 .addFunction ("top_region_at", &Playlist::top_region_at)
702                 .addFunction ("top_unmuted_region_at", &Playlist::top_unmuted_region_at)
703                 .addFunction ("find_next_region", &Playlist::find_next_region)
704                 .addFunction ("find_next_region_boundary", &Playlist::find_next_region_boundary)
705                 .addFunction ("count_regions_at", &Playlist::count_regions_at)
706                 .addFunction ("regions_touched", &Playlist::regions_touched)
707                 .addFunction ("regions_with_start_within", &Playlist::regions_with_start_within)
708                 .addFunction ("regions_with_end_within", &Playlist::regions_with_end_within)
709                 .addFunction ("raise_region", &Playlist::raise_region)
710                 .addFunction ("lower_region", &Playlist::lower_region)
711                 .addFunction ("raise_region_to_top", &Playlist::raise_region_to_top)
712                 .addFunction ("lower_region_to_bottom", &Playlist::lower_region_to_bottom)
713                 .addFunction ("duplicate", (void (Playlist::*)(boost::shared_ptr<Region>, framepos_t, framecnt_t, float))&Playlist::duplicate)
714                 .addFunction ("duplicate_until", &Playlist::duplicate_until)
715                 .addFunction ("duplicate_range", &Playlist::duplicate_range)
716                 .addFunction ("combine", &Playlist::combine)
717                 .addFunction ("uncombine", &Playlist::uncombine)
718                 .addFunction ("split_region", &Playlist::split_region)
719                 .addFunction ("split", (void (Playlist::*)(framepos_t))&Playlist::split)
720                 .addFunction ("cut", (boost::shared_ptr<Playlist> (Playlist::*)(std::list<AudioRange>&, bool))&Playlist::cut)
721 #if 0
722                 .addFunction ("copy", &Playlist::copy)
723                 .addFunction ("paste", &Playlist::paste)
724 #endif
725                 .endClass ()
726
727                 .deriveWSPtrClass <Track, Route> ("Track")
728                 .addCast<AudioTrack> ("to_audio_track")
729                 .addCast<MidiTrack> ("to_midi_track")
730                 .addFunction ("set_name", &Track::set_name)
731                 .addFunction ("can_record", &Track::can_record)
732                 .addFunction ("bounceable", &Track::bounceable)
733                 .addFunction ("bounce", &Track::bounce)
734                 .addFunction ("bounce_range", &Track::bounce_range)
735                 .addFunction ("playlist", &Track::playlist)
736                 .endClass ()
737
738                 .deriveWSPtrClass <AudioTrack, Track> ("AudioTrack")
739                 .endClass ()
740
741                 .deriveWSPtrClass <MidiTrack, Track> ("MidiTrack")
742                 .endClass ()
743
744                 .deriveWSPtrClass <Region, SessionObject> ("Region")
745                 /* properties */
746                 .addFunction ("position", &Region::position)
747                 .addFunction ("start", &Region::start)
748                 .addFunction ("length", &Region::length)
749                 .addFunction ("layer", &Region::layer)
750                 .addFunction ("data_type", &Region::data_type)
751                 .addFunction ("stretch", &Region::stretch)
752                 .addFunction ("shift", &Region::shift)
753                 .addRefFunction ("sync_offset", &Region::sync_offset)
754                 .addFunction ("sync_position", &Region::sync_position)
755                 .addFunction ("hidden", &Region::hidden)
756                 .addFunction ("muted", &Region::muted)
757                 .addFunction ("opaque", &Region::opaque)
758                 .addFunction ("locked", &Region::locked)
759                 .addFunction ("position_locked", &Region::position_locked)
760                 .addFunction ("video_locked", &Region::video_locked)
761                 .addFunction ("automatic", &Region::automatic)
762                 .addFunction ("whole_file", &Region::whole_file)
763                 .addFunction ("captured", &Region::captured)
764                 .addFunction ("can_move", &Region::can_move)
765                 .addFunction ("sync_marked", &Region::sync_marked)
766                 .addFunction ("external", &Region::external)
767                 .addFunction ("import", &Region::import)
768                 .addFunction ("covers", &Region::covers)
769                 .addFunction ("at_natural_position", &Region::at_natural_position)
770                 .addFunction ("is_compound", &Region::is_compound)
771                 /* editing operations */
772                 .addFunction ("set_length", &Region::set_length)
773                 .addFunction ("set_start", &Region::set_start)
774                 .addFunction ("set_position", &Region::set_position)
775                 .addFunction ("set_initial_position", &Region::set_initial_position)
776                 .addFunction ("nudge_position", &Region::nudge_position)
777                 .addFunction ("move_to_natural_position", &Region::move_to_natural_position)
778                 .addFunction ("move_start", &Region::move_start)
779                 .addFunction ("trim_front", &Region::trim_front)
780                 .addFunction ("trim_end", &Region::trim_end)
781                 .addFunction ("trim_to", &Region::trim_to)
782                 .addFunction ("cut_front", &Region::cut_front)
783                 .addFunction ("cut_end", &Region::cut_end)
784                 .addFunction ("raise", &Region::raise)
785                 .addFunction ("lower", &Region::lower)
786                 .addFunction ("raise_to_top", &Region::raise_to_top)
787                 .addFunction ("lower_to_bottom", &Region::lower_to_bottom)
788                 .addFunction ("set_sync_position", &Region::set_sync_position)
789                 .addFunction ("clear_sync_position", &Region::clear_sync_position)
790                 .addFunction ("set_hidden", &Region::set_hidden)
791                 .addFunction ("set_muted", &Region::set_muted)
792                 .addFunction ("set_opaque", &Region::set_opaque)
793                 .addFunction ("set_locked", &Region::set_locked)
794                 .addFunction ("set_video_locked", &Region::set_video_locked)
795                 .addFunction ("set_position_locked", &Region::set_position_locked)
796                 .endClass ()
797
798                 .beginWSPtrClass <Source> ("Source")
799                 .endClass ()
800
801                 .beginClass <Plugin::PresetRecord> ("PresetRecord")
802                 .addVoidConstructor ()
803                 .addData ("uri", &Plugin::PresetRecord::uri, false)
804                 .addData ("label", &Plugin::PresetRecord::label, false)
805                 .addData ("user", &Plugin::PresetRecord::user, false)
806                 .addData ("valid", &Plugin::PresetRecord::valid, false)
807                 .endClass ()
808
809                 .deriveWSPtrClass <Automatable, Evoral::ControlSet> ("Automatable")
810                 .addFunction ("automation_control", (boost::shared_ptr<AutomationControl>(Automatable::*)(const Evoral::Parameter&, bool))&Automatable::automation_control)
811                 .endClass ()
812
813                 .deriveClass <ParameterDescriptor, Evoral::ParameterDescriptor> ("ParameterDescriptor")
814                 .addVoidConstructor ()
815                 .addData ("label", &ParameterDescriptor::label)
816                 .addData ("logarithmic", &ParameterDescriptor::logarithmic)
817                 .addStaticFunction ("midi_note_name", &ParameterDescriptor::midi_note_name)
818                 .endClass ()
819
820                 .deriveWSPtrClass <Processor, SessionObject> ("Processor")
821                 .addCast<Automatable> ("to_automatable")
822                 .addCast<PluginInsert> ("to_insert")
823                 .addCast<SideChain> ("to_sidechain")
824                 .addCast<IOProcessor> ("to_ioprocessor")
825                 .addCast<UnknownProcessor> ("to_unknownprocessor")
826                 .addCast<Amp> ("to_amp")
827 #if 0 // those objects are not yet bound
828                 .addCast<MonitorProcessor> ("to_monitorprocessor")
829                 .addCast<CapturingProcessor> ("to_capturingprocessor")
830                 .addCast<DelayLine> ("to_delayline")
831                 .addCast<PeakMeter> ("to_meter")
832 #endif
833                 .addFunction ("display_name", &Processor::display_name)
834                 .addFunction ("active", &Processor::active)
835                 .addFunction ("activate", &Processor::activate)
836                 .addFunction ("deactivate", &Processor::deactivate)
837                 .endClass ()
838
839                 .deriveWSPtrClass <IOProcessor, Processor> ("IOProcessor")
840                 .addFunction ("natural_input_streams", &IOProcessor::natural_input_streams)
841                 .addFunction ("natural_output_streams", &IOProcessor::natural_output_streams)
842                 .addFunction ("input", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::input)
843                 .addFunction ("output", (boost::shared_ptr<IO>(IOProcessor::*)())&IOProcessor::output)
844                 .endClass ()
845
846                 .deriveWSPtrClass <SideChain, IOProcessor> ("SideChain")
847                 .endClass ()
848
849                 .deriveWSPtrClass <Delivery, IOProcessor> ("Delivery")
850                 .endClass ()
851
852                 .deriveWSPtrClass <Plugin, PBD::StatefulDestructible> ("Plugin")
853                 .addFunction ("label", &Plugin::label)
854                 .addFunction ("name", &Plugin::name)
855                 .addFunction ("maker", &Plugin::maker)
856                 .addFunction ("parameter_count", &Plugin::parameter_count)
857                 .addRefFunction ("nth_parameter", &Plugin::nth_parameter)
858                 .addFunction ("preset_by_label", &Plugin::preset_by_label)
859                 .addFunction ("preset_by_uri", &Plugin::preset_by_uri)
860                 .addFunction ("load_preset", &Plugin::load_preset)
861                 .addFunction ("parameter_is_input", &Plugin::parameter_is_input)
862                 .addFunction ("get_docs", &Plugin::get_docs)
863                 .addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
864                 .addRefFunction ("get_parameter_descriptor", &Plugin::get_parameter_descriptor)
865                 .endClass ()
866
867                 .deriveWSPtrClass <PluginInsert, Processor> ("PluginInsert")
868                 .addFunction ("plugin", &PluginInsert::plugin)
869                 .addFunction ("activate", &PluginInsert::activate)
870                 .addFunction ("deactivate", &PluginInsert::deactivate)
871                 .addFunction ("strict_io_configured", &PluginInsert::strict_io_configured)
872                 .addFunction ("input_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::input_map)
873                 .addFunction ("output_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::output_map)
874                 .addFunction ("set_input_map", &PluginInsert::set_input_map)
875                 .addFunction ("set_output_map", &PluginInsert::set_output_map)
876                 .addFunction ("sidechain_input", &PluginInsert::sidechain_input)
877                 .endClass ()
878
879                 .deriveWSPtrClass <AutomationControl, PBD::Controllable> ("AutomationControl")
880                 .addCast<Evoral::Control> ("to_ctrl")
881                 .addFunction ("automation_state", &AutomationControl::automation_state)
882                 .addFunction ("automation_style", &AutomationControl::automation_style)
883                 .addFunction ("set_automation_state", &AutomationControl::set_automation_state)
884                 .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
885                 .addFunction ("start_touch", &AutomationControl::start_touch)
886                 .addFunction ("stop_touch", &AutomationControl::stop_touch)
887                 .addFunction ("get_value", &AutomationControl::get_value)
888                 .addFunction ("set_value", &AutomationControl::set_value)
889                 .addFunction ("writable", &AutomationControl::writable)
890                 .addFunction ("alist", &AutomationControl::alist)
891                 .endClass ()
892
893                 .deriveWSPtrClass <SlavableAutomationControl, AutomationControl> ("SlavableAutomationControl,")
894                 .addFunction ("add_master", &SlavableAutomationControl::add_master)
895                 .addFunction ("remove_master", &SlavableAutomationControl::remove_master)
896                 .addFunction ("clear_masters", &SlavableAutomationControl::clear_masters)
897                 .addFunction ("slaved_to", &SlavableAutomationControl::slaved_to)
898                 .addFunction ("slaved", &SlavableAutomationControl::slaved)
899                 .addFunction ("get_masters_value", &SlavableAutomationControl::get_masters_value)
900                 .addFunction ("get_boolean_masters", &SlavableAutomationControl::get_boolean_masters)
901                 //.addFunction ("masters", &SlavableAutomationControl::masters) // not implemented
902                 .endClass ()
903
904                 .deriveWSPtrClass <PhaseControl, AutomationControl> ("PhaseControl")
905                 .addFunction ("set_phase_invert", (void(PhaseControl::*)(uint32_t, bool))&PhaseControl::set_phase_invert)
906                 .addFunction ("inverted", &PhaseControl::inverted)
907                 .endClass ()
908
909                 .deriveWSPtrClass <GainControl, SlavableAutomationControl> ("GainControl")
910                 .endClass ()
911
912                 .deriveWSPtrClass <SoloControl, SlavableAutomationControl> ("SoloControl")
913                 .addFunction ("can_solo", &SoloControl::can_solo)
914                 .addFunction ("soloed", &SoloControl::soloed)
915                 .addFunction ("self_soloed", &SoloControl::self_soloed)
916                 .endClass ()
917
918                 .deriveWSPtrClass <MuteControl, SlavableAutomationControl> ("MuteControl")
919                 .addFunction ("muted", &MuteControl::muted)
920                 .addFunction ("muted_by_self", &MuteControl::muted_by_self)
921                 .endClass ()
922
923                 .deriveWSPtrClass <SoloIsolateControl, SlavableAutomationControl> ("SoloIsolateControl")
924                 .addFunction ("solo_isolated", &SoloIsolateControl::solo_isolated)
925                 .addFunction ("self_solo_isolated", &SoloIsolateControl::self_solo_isolated)
926                 .endClass ()
927
928                 .deriveWSPtrClass <SoloSafeControl, SlavableAutomationControl> ("SoloSafeControl")
929                 .addFunction ("solo_safe", &SoloSafeControl::solo_safe)
930                 .endClass ()
931
932                 .deriveWSPtrClass <Amp, Processor> ("Amp")
933                 .addFunction ("gain_control", (boost::shared_ptr<GainControl>(Amp::*)())&Amp::gain_control)
934                 .endClass ()
935
936                 .deriveWSPtrClass <UnknownProcessor, Processor> ("UnknownProcessor")
937                 .endClass ()
938
939                 .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
940                 .endClass ()
941
942                 .deriveWSPtrClass <AudioSource, Source> ("AudioSource")
943                 .addFunction ("readable_length", &AudioSource::readable_length)
944                 .addFunction ("n_channels", &AudioSource::n_channels)
945                 .endClass ()
946
947                 // <std::list<boost::shared_ptr <AudioTrack> >
948                 .beginStdList <boost::shared_ptr<AudioTrack> > ("AudioTrackList")
949                 .endClass ()
950
951                 // std::list<boost::shared_ptr <MidiTrack> >
952                 .beginStdList <boost::shared_ptr<MidiTrack> > ("MidiTrackList")
953                 .endClass ()
954
955                 // RouteList == std::list<boost::shared_ptr<Route> >
956                 .beginConstStdList <boost::shared_ptr<Route> > ("RouteList")
957                 .endClass ()
958
959                 // boost::shared_ptr<RouteList>
960                 .beginPtrStdList <boost::shared_ptr<Route> > ("RouteListPtr")
961                 .endClass ()
962
963                 // typedef std::list<boost::weak_ptr <Route> > WeakRouteList
964                 .beginConstStdList <boost::weak_ptr<Route> > ("WeakRouteList")
965                 .endClass ()
966
967                 // std::list< boost::weak_ptr <AudioSource> >
968                 .beginConstStdList <boost::weak_ptr<AudioSource> > ("WeakAudioSourceList")
969                 .endClass ()
970
971                 // typedef std::list<boost::shared_ptr<Region> > RegionList
972                 .beginConstStdList <boost::shared_ptr<Region> > ("RegionList")
973                 .endClass ()
974
975                 // boost::shared_ptr <std::list<boost::shared_ptr<Region> > >
976                 .beginPtrStdList <boost::shared_ptr<Region> > ("RegionListPtr")
977                 .endClass ()
978
979                 //std::list<boost::shared_ptr<Port> > PortList;
980                 .beginConstStdList <boost::shared_ptr<Port> > ("PortList")
981                 .endClass ()
982
983                 // used by Playlist::cut/copy
984                 .beginConstStdList <AudioRange> ("AudioRangeList")
985                 .endClass ()
986
987                 .beginConstStdList <Location*> ("LocationList")
988                 .endClass ()
989
990 #if 0  // depends on Evoal:: Note, Beats see note_fixer.h
991         // typedef Evoral::Note<Evoral::Beats> Note;
992         // std::set< boost::weak_ptr<Note> >
993                 .beginStdSet <boost::weak_ptr<Note> > ("WeakNoteSet")
994                 .endClass ()
995 #endif
996
997         // std::list<boost::weak_ptr<Source> >
998                 .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
999                 .endClass ()
1000
1001                 .beginClass <Tempo> ("Tempo")
1002                 .addConstructor <void (*) (double, double)> ()
1003                 .addFunction ("note_type", &Tempo::note_type)
1004                 .addFunction ("beats_per_minute", &Tempo::beats_per_minute)
1005                 .addFunction ("frames_per_beat", &Tempo::frames_per_beat)
1006                 .endClass ()
1007
1008                 .beginClass <Meter> ("Meter")
1009                 .addConstructor <void (*) (double, double)> ()
1010                 .addFunction ("divisions_per_bar", &Meter::divisions_per_bar)
1011                 .addFunction ("note_divisor", &Meter::note_divisor)
1012                 .addFunction ("frames_per_bar", &Meter::frames_per_bar)
1013                 .addFunction ("frames_per_grid", &Meter::frames_per_grid)
1014                 .endClass ()
1015
1016                 .beginClass <TempoMap> ("TempoMap")
1017                 .addFunction ("add_tempo", &TempoMap::add_tempo)
1018                 .addFunction ("add_meter", &TempoMap::add_meter)
1019                 .addFunction ("tempo_section_at_frame", &TempoMap::tempo_section_at_frame)
1020                 .addFunction ("meter_section_at_frame", &TempoMap::meter_section_at_frame)
1021                 .addFunction ("meter_section_at_beat", &TempoMap::meter_section_at_beat)
1022                 .endClass ()
1023
1024                 .beginClass <MetricSection> ("MetricSection")
1025                 .addFunction ("pulse", &MetricSection::pulse)
1026                 .addFunction ("set_pulse", &MetricSection::set_pulse)
1027                 .endClass ()
1028
1029                 .deriveClass <TempoSection, MetricSection> ("TempoSection")
1030                 .addFunction ("c_func", (double(TempoSection::*)()const)&TempoSection::c_func)
1031                 .endClass ()
1032
1033                 .deriveClass <MeterSection, MetricSection> ("MeterSection")
1034                 .addCast<Meter> ("to_meter")
1035                 .addFunction ("set_pulse", &MeterSection::set_pulse)
1036                 .addFunction ("set_beat", (void(MeterSection::*)(double))&MeterSection::set_beat)
1037                 .endClass ()
1038
1039                 .beginClass <ChanCount> ("ChanCount")
1040                 .addConstructor <void (*) (DataType, uint32_t)> ()
1041                 .addFunction ("get", &ChanCount::get)
1042                 .addFunction ("set", &ChanCount::set)
1043                 .addFunction ("n_audio", &ChanCount::n_audio)
1044                 .addFunction ("n_midi", &ChanCount::n_midi)
1045                 .addFunction ("n_total", &ChanCount::n_total)
1046                 .addFunction ("reset", &ChanCount::reset)
1047                 .endClass()
1048
1049                 .beginClass <DataType> ("DataType")
1050                 .addConstructor <void (*) (std::string)> ()
1051                 .addStaticCFunction ("null",  &LuaAPI::datatype_ctor_null) // "nil" is a lua reseved word
1052                 .addStaticCFunction ("audio", &LuaAPI::datatype_ctor_audio)
1053                 .addStaticCFunction ("midi",  &LuaAPI::datatype_ctor_midi)
1054                 .addFunction ("to_string",  &DataType::to_string) // TODO Lua __tostring
1055                 // TODO add uint32_t cast, add operator==  !=
1056                 .endClass()
1057
1058                 /* libardour enums */
1059                 .beginNamespace ("PluginType")
1060                 .addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
1061                 .addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
1062                 .addConst ("LV2", ARDOUR::PluginType(LV2))
1063                 .addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
1064                 .addConst ("LXVST", ARDOUR::PluginType(LXVST))
1065                 .addConst ("Lua", ARDOUR::PluginType(Lua))
1066                 .endNamespace ()
1067
1068                 .beginNamespace ("PresentationInfo")
1069                 .beginNamespace ("Flag")
1070                 .addConst ("AudioTrack", ARDOUR::PresentationInfo::Flag(PresentationInfo::AudioTrack))
1071                 .addConst ("MidiTrack", ARDOUR::PresentationInfo::Flag(PresentationInfo::MidiTrack))
1072                 .addConst ("AudioBus", ARDOUR::PresentationInfo::Flag(PresentationInfo::AudioBus))
1073                 .addConst ("MidiBus", ARDOUR::PresentationInfo::Flag(PresentationInfo::MidiBus))
1074                 .addConst ("VCA", ARDOUR::PresentationInfo::Flag(PresentationInfo::VCA))
1075                 .addConst ("MasterOut", ARDOUR::PresentationInfo::Flag(PresentationInfo::MasterOut))
1076                 .addConst ("MonitorOut", ARDOUR::PresentationInfo::Flag(PresentationInfo::MonitorOut))
1077                 .addConst ("Auditioner", ARDOUR::PresentationInfo::Flag(PresentationInfo::Auditioner))
1078                 .addConst ("Selected", ARDOUR::PresentationInfo::Flag(PresentationInfo::Selected))
1079                 .addConst ("Hidden", ARDOUR::PresentationInfo::Flag(PresentationInfo::Hidden))
1080                 .addConst ("GroupOrderSet", ARDOUR::PresentationInfo::Flag(PresentationInfo::OrderSet))
1081                 .addConst ("StatusMask", ARDOUR::PresentationInfo::Flag(PresentationInfo::StatusMask))
1082                 .endNamespace ()
1083                 .endNamespace ()
1084
1085                 .beginNamespace ("AutoStyle")
1086                 .addConst ("Absolute", ARDOUR::AutoStyle(Absolute))
1087                 .addConst ("Trim", ARDOUR::AutoStyle(Trim))
1088                 .endNamespace ()
1089
1090                 .beginNamespace ("AutoState")
1091                 .addConst ("Off", ARDOUR::AutoState(Off))
1092                 .addConst ("Write", ARDOUR::AutoState(Write))
1093                 .addConst ("Touch", ARDOUR::AutoState(Touch))
1094                 .addConst ("Play", ARDOUR::AutoState(Play))
1095                 .endNamespace ()
1096
1097                 .beginNamespace ("AutomationType")
1098                 .addConst ("GainAutomation", ARDOUR::AutomationType(GainAutomation))
1099                 .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
1100                 .addConst ("SoloAutomation", ARDOUR::AutomationType(SoloAutomation))
1101                 .addConst ("SoloIsolateAutomation", ARDOUR::AutomationType(SoloIsolateAutomation))
1102                 .addConst ("SoloSafeAutomation", ARDOUR::AutomationType(SoloSafeAutomation))
1103                 .addConst ("MuteAutomation", ARDOUR::AutomationType(MuteAutomation))
1104                 .addConst ("RecEnableAutomation", ARDOUR::AutomationType(RecEnableAutomation))
1105                 .addConst ("RecSafeAutomation", ARDOUR::AutomationType(RecSafeAutomation))
1106                 .addConst ("TrimAutomation", ARDOUR::AutomationType(TrimAutomation))
1107                 .addConst ("PhaseAutomation", ARDOUR::AutomationType(PhaseAutomation))
1108                 .endNamespace ()
1109
1110                 .beginNamespace ("SrcQuality")
1111                 .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
1112                 .endNamespace ()
1113
1114                 .beginNamespace ("PortFlags")
1115                 .addConst ("IsInput", ARDOUR::PortFlags(IsInput))
1116                 .addConst ("IsOutput", ARDOUR::PortFlags(IsOutput))
1117                 .addConst ("IsPhysical", ARDOUR::PortFlags(IsPhysical))
1118                 .addConst ("CanMonitor", ARDOUR::PortFlags(CanMonitor))
1119                 .addConst ("IsTerminal", ARDOUR::PortFlags(IsTerminal))
1120                 .endNamespace ()
1121
1122                 .beginNamespace ("PlaylistDisposition")
1123                 .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
1124                 .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
1125                 .addConst ("SharePlaylist", ARDOUR::PlaylistDisposition(SharePlaylist))
1126                 .endNamespace ()
1127
1128                 .beginNamespace ("RegionPoint")
1129                 .addConst ("Start", ARDOUR::RegionPoint(Start))
1130                 .addConst ("End", ARDOUR::RegionPoint(End))
1131                 .addConst ("SyncPoint", ARDOUR::RegionPoint(SyncPoint))
1132                 .endNamespace ()
1133
1134                 .beginNamespace ("TempoSection")
1135                 .beginNamespace ("PositionLockStyle")
1136                 .addConst ("AudioTime", ARDOUR::PositionLockStyle(AudioTime))
1137                 .addConst ("MusicTime", ARDOUR::PositionLockStyle(MusicTime))
1138                 .endNamespace ()
1139                 .endNamespace ()
1140
1141                 .beginNamespace ("TempoSection")
1142                 .beginNamespace ("Type")
1143                 .addConst ("Ramp", ARDOUR::TempoSection::Type(TempoSection::Ramp))
1144                 .addConst ("Constant", ARDOUR::TempoSection::Type(TempoSection::Constant))
1145                 .endNamespace ()
1146                 .endNamespace ()
1147
1148                 .beginNamespace ("TrackMode")
1149                 .addConst ("Normal", ARDOUR::TrackMode(Start))
1150                 .addConst ("NonLayered", ARDOUR::TrackMode(NonLayered))
1151                 .addConst ("Destructive", ARDOUR::TrackMode(Destructive))
1152                 .endNamespace ()
1153
1154                 .beginNamespace ("SampleFormat")
1155                 .addConst ("Float", ARDOUR::SampleFormat(FormatFloat))
1156                 .addConst ("Int24", ARDOUR::SampleFormat(FormatInt24))
1157                 .addConst ("Int16", ARDOUR::SampleFormat(FormatInt16))
1158                 .endNamespace ()
1159
1160                 .beginNamespace ("HeaderFormat")
1161                 .addConst ("BWF", ARDOUR::HeaderFormat(BWF))
1162                 .addConst ("WAVE", ARDOUR::HeaderFormat(WAVE))
1163                 .addConst ("WAVE64", ARDOUR::HeaderFormat(WAVE64))
1164                 .addConst ("CAF", ARDOUR::HeaderFormat(CAF))
1165                 .addConst ("AIFF", ARDOUR::HeaderFormat(AIFF))
1166                 .addConst ("iXML", ARDOUR::HeaderFormat(iXML))
1167                 .addConst ("RF64", ARDOUR::HeaderFormat(RF64))
1168                 .addConst ("RF64_WAV", ARDOUR::HeaderFormat(RF64_WAV))
1169                 .addConst ("MBWF", ARDOUR::HeaderFormat(MBWF))
1170                 .endNamespace ()
1171
1172                 .beginNamespace ("InsertMergePolicy")
1173                 .addConst ("Reject", ARDOUR::InsertMergePolicy(InsertMergeReject))
1174                 .addConst ("Relax", ARDOUR::InsertMergePolicy(InsertMergeRelax))
1175                 .addConst ("Replace", ARDOUR::InsertMergePolicy(InsertMergeReplace))
1176                 .addConst ("TruncateExisting", ARDOUR::InsertMergePolicy(InsertMergeTruncateExisting))
1177                 .addConst ("TruncateAddition", ARDOUR::InsertMergePolicy(InsertMergeTruncateAddition))
1178                 .addConst ("Extend", ARDOUR::InsertMergePolicy(InsertMergeExtend))
1179                 .endNamespace ()
1180
1181                 .endNamespace (); // end ARDOUR
1182
1183         luabridge::getGlobalNamespace (L)
1184                 .beginNamespace ("ARDOUR")
1185                 .beginClass <AudioBackendInfo> ("AudioBackendInfo")
1186                 .addData ("name", &AudioBackendInfo::name)
1187                 .endClass()
1188                 .beginStdVector <const AudioBackendInfo*> ("BackendVector").endClass ()
1189
1190                 .beginClass <AudioBackend::DeviceStatus> ("DeviceStatus")
1191                 .addData ("name", &AudioBackend::DeviceStatus::name)
1192                 .addData ("available", &AudioBackend::DeviceStatus::available)
1193                 .endClass()
1194                 .beginStdVector <AudioBackend::DeviceStatus> ("DeviceStatusVector").endClass ()
1195
1196                 .beginWSPtrClass <AudioBackend> ("AudioBackend")
1197                 .addFunction ("info", &AudioBackend::info)
1198                 .addFunction ("sample_rate", &AudioBackend::sample_rate)
1199                 .addFunction ("buffer_size", &AudioBackend::buffer_size)
1200                 .addFunction ("period_size", &AudioBackend::period_size)
1201                 .addFunction ("input_channels", &AudioBackend::input_channels)
1202                 .addFunction ("output_channels", &AudioBackend::output_channels)
1203                 .addFunction ("dsp_load", &AudioBackend::dsp_load)
1204
1205                 .addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
1206                 .addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
1207                 .addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
1208
1209                 .addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
1210                 .addFunction ("driver_name", &AudioBackend::driver_name)
1211                 .addFunction ("set_driver", &AudioBackend::set_driver)
1212
1213                 .addFunction ("use_separate_input_and_output_devices", &AudioBackend::use_separate_input_and_output_devices)
1214                 .addFunction ("enumerate_devices", &AudioBackend::enumerate_devices)
1215                 .addFunction ("enumerate_input_devices", &AudioBackend::enumerate_input_devices)
1216                 .addFunction ("enumerate_output_devices", &AudioBackend::enumerate_output_devices)
1217                 .addFunction ("device_name", &AudioBackend::device_name)
1218                 .addFunction ("input_device_name", &AudioBackend::input_device_name)
1219                 .addFunction ("output_device_name", &AudioBackend::output_device_name)
1220                 .addFunction ("set_device_name", &AudioBackend::set_device_name)
1221                 .addFunction ("set_input_device_name", &AudioBackend::set_input_device_name)
1222                 .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
1223                 .endClass()
1224
1225                 .beginClass <PortEngine> ("PortEngine")
1226                 .endClass()
1227
1228                 .beginClass <PortManager> ("PortManager")
1229                 .addFunction ("port_engine", &PortManager::port_engine)
1230                 .addFunction ("connected", &PortManager::connected)
1231                 .addFunction ("connect", &PortManager::connect)
1232                 .addFunction ("physically_connected", &PortManager::physically_connected)
1233                 .addFunction ("disconnect", (int (PortManager::*)(const std::string&, const std::string&))&PortManager::disconnect)
1234                 .addFunction ("disconnect_port", (int (PortManager::*)(boost::shared_ptr<Port>))&PortManager::disconnect)
1235                 .addFunction ("get_port_by_name", &PortManager::get_port_by_name)
1236                 .addFunction ("get_pretty_name_by_name", &PortManager::get_pretty_name_by_name)
1237                 .addFunction ("port_is_physical", &PortManager::port_is_physical)
1238                 .addFunction ("get_physical_outputs", &PortManager::get_physical_outputs)
1239                 .addFunction ("get_physical_inputs", &PortManager::get_physical_inputs)
1240                 .addFunction ("n_physical_outputs", &PortManager::n_physical_outputs)
1241                 .addFunction ("n_physical_inputs", &PortManager::n_physical_inputs)
1242                 .addRefFunction ("get_connections", &PortManager::get_connections)
1243                 .addRefFunction ("get_ports", (int (PortManager::*)(DataType, PortManager::PortList&))&PortManager::get_ports)
1244                 .addRefFunction ("get_backend_ports", (int (PortManager::*)(const std::string&, DataType, PortFlags, std::vector<std::string>&))&PortManager::get_ports)
1245                 .endClass()
1246
1247                 .deriveClass <AudioEngine, PortManager> ("AudioEngine")
1248                 .addFunction ("available_backends", &AudioEngine::available_backends)
1249                 .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
1250                 .addFunction ("set_backend", &AudioEngine::set_backend)
1251                 .addFunction ("setup_required", &AudioEngine::setup_required)
1252                 .addFunction ("start", &AudioEngine::start)
1253                 .addFunction ("stop", &AudioEngine::stop)
1254                 .addFunction ("get_dsp_load", &AudioEngine::get_dsp_load)
1255                 .addFunction ("set_device_name", &AudioEngine::set_device_name)
1256                 .addFunction ("set_sample_rate", &AudioEngine::set_sample_rate)
1257                 .addFunction ("set_buffer_size", &AudioEngine::set_buffer_size)
1258                 .addFunction ("get_last_backend_error", &AudioEngine::get_last_backend_error)
1259                 .endClass()
1260
1261                 .deriveClass <SessionConfiguration, PBD::Configuration> ("SessionConfiguration")
1262 #undef  CONFIG_VARIABLE
1263 #undef  CONFIG_VARIABLE_SPECIAL
1264 #define CONFIG_VARIABLE(Type,var,name,value) \
1265                 .addFunction ("get_" # var, &SessionConfiguration::get_##var) \
1266                 .addFunction ("set_" # var, &SessionConfiguration::set_##var) \
1267                 .addProperty (#var, &SessionConfiguration::get_##var, &SessionConfiguration::set_##var)
1268
1269 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) \
1270                 .addFunction ("get_" # var, &SessionConfiguration::get_##var) \
1271                 .addFunction ("set_" # var, &SessionConfiguration::set_##var) \
1272                 .addProperty (#var, &SessionConfiguration::get_##var, &SessionConfiguration::set_##var)
1273
1274 #include "ardour/session_configuration_vars.h"
1275
1276 #undef CONFIG_VARIABLE
1277 #undef CONFIG_VARIABLE_SPECIAL
1278                 .endClass()
1279                 .endNamespace ();
1280
1281         // basic representation of Session
1282         // functions which can be used from realtime and non-realtime contexts
1283         luabridge::getGlobalNamespace (L)
1284                 .beginNamespace ("ARDOUR")
1285                 .beginClass <Session> ("Session")
1286                 .addFunction ("scripts_changed", &Session::scripts_changed) // used internally
1287                 .addFunction ("transport_rolling", &Session::transport_rolling)
1288                 .addFunction ("request_transport_speed", &Session::request_transport_speed)
1289                 .addFunction ("transport_frame", &Session::transport_frame)
1290                 .addFunction ("transport_speed", &Session::transport_speed)
1291                 .addFunction ("frame_rate", &Session::frame_rate)
1292                 .addFunction ("nominal_frame_rate", &Session::nominal_frame_rate)
1293                 .addFunction ("frames_per_timecode_frame", &Session::frames_per_timecode_frame)
1294                 .addFunction ("timecode_frames_per_hour", &Session::timecode_frames_per_hour)
1295                 .addFunction ("timecode_frames_per_second", &Session::timecode_frames_per_second)
1296                 .addFunction ("timecode_drop_frames", &Session::timecode_drop_frames)
1297                 .addFunction ("request_locate", &Session::request_locate)
1298                 .addFunction ("request_stop", &Session::request_stop)
1299                 .addFunction ("last_transport_start", &Session::last_transport_start)
1300                 .addFunction ("goto_start", &Session::goto_start)
1301                 .addFunction ("goto_end", &Session::goto_end)
1302                 .addFunction ("current_start_frame", &Session::current_start_frame)
1303                 .addFunction ("current_end_frame", &Session::current_end_frame)
1304                 .addFunction ("actively_recording", &Session::actively_recording)
1305                 .addFunction ("new_audio_track", &Session::new_audio_track)
1306                 .addFunction ("new_audio_route", &Session::new_audio_route)
1307                 .addFunction ("new_midi_track", &Session::new_midi_track)
1308                 .addFunction ("new_midi_route", &Session::new_midi_route)
1309                 .addFunction ("get_routes", &Session::get_routes)
1310                 .addFunction ("get_tracks", &Session::get_tracks)
1311                 .addFunction ("name", &Session::name)
1312                 .addFunction ("path", &Session::path)
1313                 .addFunction ("record_status", &Session::record_status)
1314                 .addFunction ("route_by_id", &Session::route_by_id)
1315                 .addFunction ("route_by_name", &Session::route_by_name)
1316                 .addFunction ("get_remote_nth_stripable", &Session::get_remote_nth_stripable)
1317                 .addFunction ("get_remote_nth_route", &Session::get_remote_nth_route)
1318                 .addFunction ("route_by_selected_count", &Session::route_by_selected_count)
1319                 .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
1320                 .addFunction ("source_by_id", &Session::source_by_id)
1321                 .addFunction ("controllable_by_id", &Session::controllable_by_id)
1322                 .addFunction ("processor_by_id", &Session::processor_by_id)
1323                 .addFunction ("snap_name", &Session::snap_name)
1324                 .addFunction ("monitor_out", &Session::monitor_out)
1325                 .addFunction ("master_out", &Session::master_out)
1326                 .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
1327                 .addFunction ("locations", &Session::locations)
1328                 .addFunction ("begin_reversible_command", (void (Session::*)(const std::string&))&Session::begin_reversible_command)
1329                 .addFunction ("commit_reversible_command", &Session::commit_reversible_command)
1330                 .addFunction ("abort_reversible_command", &Session::abort_reversible_command)
1331                 .addFunction ("add_command", &Session::add_command)
1332                 .addFunction ("add_stateful_diff_command", &Session::add_stateful_diff_command)
1333                 .addFunction ("engine", (AudioEngine& (Session::*)())&Session::engine)
1334                 .addFunction ("get_block_size", &Session::get_block_size)
1335                 .addFunction ("worst_output_latency", &Session::worst_output_latency)
1336                 .addFunction ("worst_input_latency", &Session::worst_input_latency)
1337                 .addFunction ("worst_track_latency", &Session::worst_track_latency)
1338                 .addFunction ("worst_playback_latency", &Session::worst_playback_latency)
1339                 .addFunction ("cfg", &Session::cfg)
1340                 .endClass ()
1341
1342                 .beginClass <RegionFactory> ("RegionFactory")
1343                 .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
1344                 .endClass ()
1345
1346                 /* session enums (rt-safe, common) */
1347                 .beginNamespace ("Session")
1348
1349                 .beginNamespace ("RecordState")
1350                 .addConst ("Disabled", ARDOUR::Session::RecordState(Session::Disabled))
1351                 .addConst ("Enabled", ARDOUR::Session::RecordState(Session::Enabled))
1352                 .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
1353                 .endNamespace ()
1354
1355                 .endNamespace () // end Session enums
1356
1357                 /* ardour enums (rt-safe, common) */
1358                 .beginNamespace ("LocationFlags")
1359                 .addConst ("IsMark", ARDOUR::Location::Flags(Location::IsMark))
1360                 .addConst ("IsAutoPunch", ARDOUR::Location::Flags(Location::IsAutoPunch))
1361                 .addConst ("IsAutoLoop", ARDOUR::Location::Flags(Location::IsAutoLoop))
1362                 .addConst ("IsHidden", ARDOUR::Location::Flags(Location::IsHidden))
1363                 .addConst ("IsCDMarker", ARDOUR::Location::Flags(Location::IsCDMarker))
1364                 .addConst ("IsRangeMarker", ARDOUR::Location::Flags(Location::IsRangeMarker))
1365                 .addConst ("IsSessionRange", ARDOUR::Location::Flags(Location::IsSessionRange))
1366                 .addConst ("IsSkip", ARDOUR::Location::Flags(Location::IsSkip))
1367                 .addConst ("IsSkipping", ARDOUR::Location::Flags(Location::IsSkipping))
1368                 .endNamespace ()
1369
1370                 .beginNamespace ("LuaAPI")
1371                 .addFunction ("nil_proc", ARDOUR::LuaAPI::nil_processor)
1372                 .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
1373                 .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info)
1374                 .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
1375                 .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
1376                 .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
1377                 .addCFunction ("plugin_automation", ARDOUR::LuaAPI::plugin_automation)
1378                 .addCFunction ("hsla_to_rgba", ARDOUR::LuaAPI::hsla_to_rgba)
1379                 .addFunction ("usleep", Glib::usleep)
1380                 .endNamespace () // end LuaAPI
1381                 .endNamespace ();// end ARDOUR
1382 }
1383
1384 void
1385 LuaBindings::dsp (lua_State* L)
1386 {
1387         luabridge::getGlobalNamespace (L)
1388                 .beginNamespace ("ARDOUR")
1389
1390                 .beginClass <AudioBuffer> ("AudioBuffer")
1391                 .addEqualCheck ()
1392                 .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
1393                 .addFunction ("silence", &AudioBuffer::silence)
1394                 .addFunction ("apply_gain", &AudioBuffer::apply_gain)
1395                 .addFunction ("check_silence", &AudioBuffer::check_silence)
1396                 .addFunction ("read_from", (void (AudioBuffer::*)(const Sample*, framecnt_t, framecnt_t, framecnt_t))&AudioBuffer::check_silence)
1397                 .endClass()
1398
1399                 .beginClass <MidiBuffer> ("MidiBuffer")
1400                 .addEqualCheck ()
1401                 .addFunction ("silence", &MidiBuffer::silence)
1402                 .addFunction ("size", &MidiBuffer::size)
1403                 .addFunction ("empty", &MidiBuffer::empty)
1404                 .addFunction ("resize", &MidiBuffer::resize)
1405                 .addFunction ("copy", (void (MidiBuffer::*)(MidiBuffer const * const))&MidiBuffer::copy)
1406                 .addFunction ("push_event", (bool (MidiBuffer::*)(const Evoral::MIDIEvent<framepos_t>&))&MidiBuffer::push_back)
1407                 .addFunction ("push_back", (bool (MidiBuffer::*)(framepos_t, size_t, const uint8_t*))&MidiBuffer::push_back)
1408                 // TODO iterators..
1409                 .addExtCFunction ("table", &luabridge::CFunc::listToTable<const Evoral::MIDIEvent<framepos_t>, MidiBuffer>)
1410                 .endClass()
1411
1412                 .beginClass <BufferSet> ("BufferSet")
1413                 .addEqualCheck ()
1414                 .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
1415                 .addFunction ("get_midi", static_cast<MidiBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_midi))
1416                 .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
1417                 .endClass()
1418                 .endNamespace ();
1419
1420         luabridge::getGlobalNamespace (L)
1421                 .beginNamespace ("Evoral")
1422                 .beginClass <Evoral::Event<framepos_t> > ("Event")
1423                 .addFunction ("clear", &Evoral::Event<framepos_t>::clear)
1424                 .addFunction ("size", &Evoral::Event<framepos_t>::size)
1425                 .addFunction ("set_buffer", &Evoral::Event<framepos_t>::set_buffer)
1426                 .addFunction ("buffer", (uint8_t*(Evoral::Event<framepos_t>::*)())&Evoral::Event<framepos_t>::buffer)
1427                 .addFunction ("time", (framepos_t (Evoral::Event<framepos_t>::*)())&Evoral::MIDIEvent<framepos_t>::time)
1428                 .endClass ()
1429
1430                 .beginClass <Evoral::Beats> ("Beats")
1431                 .addFunction ("to_double", &Evoral::Beats::to_double)
1432                 .endClass ()
1433
1434                 .deriveClass <Evoral::MIDIEvent<framepos_t>, Evoral::Event<framepos_t> > ("MidiEvent")
1435                 // add Ctor?
1436                 .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
1437                 .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
1438                 .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::set_type)
1439                 .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::set_channel)
1440                 .endClass ()
1441                 .endNamespace ();
1442
1443         // dsp releated session functions
1444         luabridge::getGlobalNamespace (L)
1445                 .beginNamespace ("ARDOUR")
1446                 .beginClass <Session> ("Session")
1447                 .addFunction ("get_scratch_buffers", &Session::get_scratch_buffers)
1448                 .addFunction ("get_silent_buffers", &Session::get_silent_buffers)
1449                 .endClass ()
1450                 .endNamespace ();
1451
1452         luabridge::getGlobalNamespace (L)
1453                 .beginNamespace ("ARDOUR")
1454                 .beginNamespace ("DSP")
1455                 .addFunction ("compute_peak", ARDOUR::compute_peak)
1456                 .addFunction ("find_peaks", ARDOUR::find_peaks)
1457                 .addFunction ("apply_gain_to_buffer", ARDOUR::apply_gain_to_buffer)
1458                 .addFunction ("mix_buffers_no_gain", ARDOUR::mix_buffers_no_gain)
1459                 .addFunction ("mix_buffers_with_gain", ARDOUR::mix_buffers_with_gain)
1460                 .addFunction ("copy_vector", ARDOUR::copy_vector)
1461                 .addFunction ("dB_to_coefficient", &dB_to_coefficient)
1462                 .addFunction ("fast_coefficient_to_dB", &fast_coefficient_to_dB)
1463                 .addFunction ("accurate_coefficient_to_dB", &accurate_coefficient_to_dB)
1464                 .addFunction ("memset", &DSP::memset)
1465                 .addFunction ("mmult", &DSP::mmult)
1466                 .addFunction ("log_meter", &DSP::log_meter)
1467                 .addFunction ("log_meter_coeff", &DSP::log_meter_coeff)
1468                 .addFunction ("process_map", &DSP::process_map)
1469                 .addRefFunction ("peaks", &DSP::peaks)
1470
1471                 .beginClass <DSP::LowPass> ("LowPass")
1472                 .addConstructor <void (*) (double, float)> ()
1473                 .addFunction ("proc", &DSP::LowPass::proc)
1474                 .addFunction ("ctrl", &DSP::LowPass::ctrl)
1475                 .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
1476                 .addFunction ("reset", &DSP::LowPass::reset)
1477                 .endClass ()
1478                 .beginClass <DSP::Biquad> ("Biquad")
1479                 .addConstructor <void (*) (double)> ()
1480                 .addFunction ("run", &DSP::Biquad::run)
1481                 .addFunction ("compute", &DSP::Biquad::compute)
1482                 .addFunction ("configure", &DSP::Biquad::configure)
1483                 .addFunction ("reset", &DSP::Biquad::reset)
1484                 .addFunction ("dB_at_freq", &DSP::Biquad::dB_at_freq)
1485                 .endClass ()
1486                 .beginClass <DSP::FFTSpectrum> ("FFTSpectrum")
1487                 .addConstructor <void (*) (uint32_t, double)> ()
1488                 .addFunction ("set_data_hann", &DSP::FFTSpectrum::set_data_hann)
1489                 .addFunction ("execute", &DSP::FFTSpectrum::execute)
1490                 .addFunction ("power_at_bin", &DSP::FFTSpectrum::power_at_bin)
1491                 .addFunction ("freq_at_bin", &DSP::FFTSpectrum::freq_at_bin)
1492                 .endClass ()
1493
1494                 /* DSP enums */
1495                 .beginNamespace ("BiquadType")
1496                 .addConst ("LowPass", ARDOUR::DSP::Biquad::LowPass)
1497                 .addConst ("HighPass", ARDOUR::DSP::Biquad::HighPass)
1498                 .addConst ("BandPassSkirt", ARDOUR::DSP::Biquad::BandPassSkirt)
1499                 .addConst ("BandPass0dB", ARDOUR::DSP::Biquad::BandPass0dB)
1500                 .addConst ("Notch", ARDOUR::DSP::Biquad::Notch)
1501                 .addConst ("AllPass", ARDOUR::DSP::Biquad::AllPass)
1502                 .addConst ("Peaking", ARDOUR::DSP::Biquad::Peaking)
1503                 .addConst ("LowShelf", ARDOUR::DSP::Biquad::LowShelf)
1504                 .addConst ("HighShelf", ARDOUR::DSP::Biquad::HighShelf)
1505                 .endNamespace ()
1506
1507                 .beginClass <DSP::DspShm> ("DspShm")
1508                 .addConstructor<void (*) (size_t)> ()
1509                 .addFunction ("allocate", &DSP::DspShm::allocate)
1510                 .addFunction ("clear", &DSP::DspShm::clear)
1511                 .addFunction ("to_float", &DSP::DspShm::to_float)
1512                 .addFunction ("to_int", &DSP::DspShm::to_int)
1513                 .addFunction ("atomic_set_int", &DSP::DspShm::atomic_set_int)
1514                 .addFunction ("atomic_get_int", &DSP::DspShm::atomic_get_int)
1515                 .endClass ()
1516
1517                 .endNamespace () // DSP
1518
1519                 .beginClass <LuaTableRef> ("LuaTableRef")
1520                 .addCFunction ("get", &LuaTableRef::get)
1521                 .addCFunction ("set", &LuaTableRef::set)
1522                 .endClass ()
1523
1524                 .endNamespace (); // ARDOUR
1525 }
1526
1527 void
1528 LuaBindings::session (lua_State* L)
1529 {
1530         // non-realtime session functions
1531         luabridge::getGlobalNamespace (L)
1532                 .beginNamespace ("ARDOUR")
1533                 .beginClass <Session> ("Session")
1534                 .addFunction ("save_state", &Session::save_state)
1535                 .addFunction ("set_dirty", &Session::set_dirty)
1536                 .addFunction ("unknown_processors", &Session::unknown_processors)
1537
1538                 .addFunction<RouteList (Session::*)(uint32_t, const std::string&, const std::string&, PlaylistDisposition)> ("new_route_from_template", &Session::new_route_from_template)
1539                 // TODO  session_add_audio_track  session_add_midi_track  session_add_mixed_track
1540                 //.addFunction ("new_midi_track", &Session::new_midi_track)
1541                 .endClass ()
1542
1543                 .endNamespace (); // ARDOUR
1544 }
1545
1546 void
1547 LuaBindings::osc (lua_State* L)
1548 {
1549         luabridge::getGlobalNamespace (L)
1550                 .beginNamespace ("ARDOUR")
1551                 .beginNamespace ("LuaOSC")
1552                 .beginClass<LuaOSC::Address> ("Address")
1553                 .addConstructor<void (*) (std::string)> ()
1554                 .addCFunction ("send", &LuaOSC::Address::send)
1555                 .endClass ()
1556                 .endNamespace ()
1557                 .endNamespace ();
1558 }
1559
1560 void
1561 LuaBindings::set_session (lua_State* L, Session *s)
1562 {
1563         /* LuaBridge uses unique keys to identify classes/c-types.
1564          *
1565          * Those keys are "generated" by using the memory-address of a static
1566          * variable, templated for every Class.
1567          * (see libs/lua/LuaBridge/detail/ClassInfo.h)
1568          *
1569          * When linking the final executable there must be exactly one static
1570          * function (static variable) for every templated class.
1571          * This works fine on OSX and Linux...
1572          *
1573          * Windows (mingw and MSVC) however expand the template differently for libardour
1574          * AND gtk2_ardour. We end up with two identical static functions
1575          * at different addresses!!
1576          *
1577          * The Solution: have gtk2_ardour never include LuaBridge headers directly
1578          * and always go via libardour function calls for classes that are registered
1579          * in libardour. (calling lua itself is fine,  calling c-functions in the GUI
1580          * which expand the template is not)
1581          *
1582          * (the actual cause: even static symbols in a .dll have no fixed address
1583          * and are mapped when loading the dll. static functions in .exe do have a fixed
1584          * address)
1585          *
1586          * libardour:
1587          *  0000000000000000 I __imp__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
1588          *  0000000000000000 I __nm__ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
1589          *  0000000000000000 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
1590          *
1591          * ardour.exe
1592          *  000000000104f560 d .data$_ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
1593          *  000000000104f560 D _ZZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEvE5value
1594          *  0000000000e9baf0 T _ZN9luabridge9ClassInfoIN6ARDOUR7SessionEE11getClassKeyEv
1595          *
1596          *
1597          */
1598         luabridge::push <Session *> (L, s);
1599         lua_setglobal (L, "Session");
1600
1601         if (s) {
1602                 // call lua function.
1603                 luabridge::LuaRef cb_ses = luabridge::getGlobal (L, "new_session");
1604                 if (cb_ses.type() == LUA_TFUNCTION) { cb_ses(s->name()); } // TODO args
1605         }
1606 }