first vaguely working version using PresentationInfo
[ardour.git] / libs / ardour / luabindings.cc
index 9130af69d5535abe38876e2e81bb72ff75d48d40..765402efac93285c1638455c99ef170172472865 100644 (file)
 #include "evoral/ControlList.hpp"
 #include "evoral/Range.hpp"
 
+#include "ardour/amp.h"
 #include "ardour/audioengine.h"
 #include "ardour/audiosource.h"
 #include "ardour/audio_backend.h"
 #include "ardour/audio_buffer.h"
+#include "ardour/audio_port.h"
 #include "ardour/audio_track.h"
 #include "ardour/buffer_set.h"
 #include "ardour/chan_mapping.h"
 #include "ardour/interthread_info.h"
 #include "ardour/lua_api.h"
 #include "ardour/luabindings.h"
+#include "ardour/luaproc.h"
 #include "ardour/meter.h"
 #include "ardour/midi_track.h"
+#include "ardour/midi_port.h"
 #include "ardour/playlist.h"
 #include "ardour/plugin.h"
 #include "ardour/plugin_insert.h"
+#include "ardour/port_manager.h"
 #include "ardour/runtime_functions.h"
 #include "ardour/region.h"
 #include "ardour/region_factory.h"
+#include "ardour/route_group.h"
 #include "ardour/session.h"
 #include "ardour/session_object.h"
 #include "ardour/sidechain.h"
 
 #include "LuaBridge/LuaBridge.h"
 
+#ifdef PLATFORM_WINDOWS
+/* luabridge uses addresses of static functions/variables to identify classes.
+ *
+ * Static symbols on windows (even identical symbols) are not
+ * mapped to the same address when mixing .dll + .exe.
+ * So we need a single point to define those static functions.
+ * (normally they're header-only in libs/lua/LuaBridge/detail/ClassInfo.h)
+ *
+ * Really!! A static function with a static variable in a library header
+ * should never ever be replicated, even if it is a template.
+ * But then again this is windows... what else can go wrong.
+ */
+
+template <class T>
+void const*
+luabridge::ClassInfo<T>::getStaticKey ()
+{
+       static char value;
+       return &value;
+}
+
+template <class T>
+void const*
+luabridge::ClassInfo<T>::getClassKey ()
+{
+       static char value;
+       return &value;
+}
+
+template <class T>
+void const*
+luabridge::ClassInfo<T>::getConstKey ()
+{
+       static char value;
+       return &value;
+}
+
+void*
+luabridge::getIdentityKey ()
+{
+  static char value;
+  return &value;
+}
+
+/* ...and this is the ugly part of it.
+ *
+ * We need to foward declare classes from gtk2_ardour
+ * end explicily list classes which are used by gtk2_ardour's bindings.
+ *
+ * This is needed because some of the GUI classes use objects from libardour
+ * as function parameters and the .exe would re-create symbols for libardour
+ * objects.
+ *
+ * Classes which don't use libardour symbols could be moved to
+ * gtk2_ardour/luainstance.cc, but keeping this here reduces code
+ * duplication and does not give the compiler a chance to even think
+ * about replicating the symbols.
+ */
+
+#define CLASSKEYS(CLS) \
+       template void const* luabridge::ClassInfo< CLS >::getStaticKey(); \
+       template void const* luabridge::ClassInfo< CLS >::getClassKey();  \
+       template void const* luabridge::ClassInfo< CLS >::getConstKey();
+
+#define CLASSINFO(CLS) \
+       class CLS; \
+       template void const* luabridge::ClassInfo< CLS >::getStaticKey(); \
+       template void const* luabridge::ClassInfo< CLS >::getClassKey();  \
+       template void const* luabridge::ClassInfo< CLS >::getConstKey();
+
+CLASSINFO(MarkerSelection);
+CLASSINFO(TrackSelection);
+CLASSINFO(TrackViewList);
+CLASSINFO(TimeSelection);
+CLASSINFO(RegionSelection);
+CLASSINFO(PublicEditor);
+CLASSINFO(Selection);
+CLASSINFO(ArdourMarker);
+
+namespace Cairo {
+       class Context;
+}
+CLASSKEYS(Cairo::Context);
+CLASSKEYS(std::vector<double>);
+CLASSKEYS(std::list<ArdourMarker*>);
+CLASSKEYS(std::bitset<47ul>); // LuaSignal::LAST_SIGNAL
+CLASSKEYS(ArdourMarker*);
+CLASSKEYS(ARDOUR::RouteGroup);
+CLASSKEYS(ARDOUR::LuaProc);
+CLASSKEYS(ARDOUR::DataType);
+CLASSKEYS(ARDOUR::ChanCount);
+CLASSKEYS(boost::shared_ptr<ARDOUR::Processor>);
+CLASSKEYS(ARDOUR::ParameterDescriptor);
+CLASSKEYS(boost::shared_ptr<ARDOUR::AutomationList>);
+CLASSKEYS(boost::shared_ptr<Evoral::ControlList>);
+CLASSKEYS(ARDOUR::LuaOSC::Address);
+CLASSKEYS(ARDOUR::Session);
+CLASSKEYS(ARDOUR::BufferSet);
+CLASSKEYS(ARDOUR::ChanMapping);
+CLASSKEYS(ARDOUR::DSP::DspShm);
+CLASSKEYS(PBD::ID);
+CLASSKEYS(ARDOUR::Location);
+CLASSKEYS(ARDOUR::PluginInfo);
+CLASSKEYS(PBD::PropertyChange);
+CLASSKEYS(std::vector<std::string>);
+CLASSKEYS(std::list<boost::shared_ptr<ARDOUR::Route> >);
+CLASSKEYS(std::list<boost::shared_ptr<ARDOUR::Port> >);
+CLASSKEYS(boost::shared_ptr<ARDOUR::PluginInfo>);
+CLASSKEYS(boost::shared_ptr<ARDOUR::Region>);
+CLASSKEYS(boost::weak_ptr<ARDOUR::Route>);
+CLASSKEYS(std::list<boost::shared_ptr<ARDOUR::Region> >);
+CLASSKEYS(std::list<ARDOUR::AudioRange>);
+CLASSKEYS(Evoral::Beats);
+CLASSKEYS(ARDOUR::PortEngine);
+CLASSKEYS(ARDOUR::PortManager);
+CLASSKEYS(ARDOUR::AudioEngine);
+CLASSKEYS(void);
+CLASSKEYS(float);
+
+#endif // end windows special case
+
 /* Some notes on Lua bindings for libardour and friends
  *
  * - Prefer factory methods over Contructors whenever possible.
@@ -108,12 +235,18 @@ LuaBindings::common (lua_State* L)
                .addFunction ("to_s", &PBD::ID::to_s) // TODO special case LUA __tostring ?
                .endClass ()
 
+               .beginClass <XMLNode> ("XMLNode")
+               .addFunction ("name", &XMLNode::name)
+               .endClass ()
+
                .beginClass <PBD::Stateful> ("Stateful")
+               .addFunction ("id", &PBD::Stateful::id)
                .addFunction ("properties", &PBD::Stateful::properties)
                .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
                .endClass ()
 
                .beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
+               .addFunction ("id", &PBD::Stateful::id)
                .addFunction ("properties", &PBD::Stateful::properties)
                .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
                .endClass ()
@@ -144,9 +277,11 @@ LuaBindings::common (lua_State* L)
                .endClass ()
 
                .deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
+               .addFunction ("name", &PBD::Controllable::name)
                .addFunction ("get_value", &PBD::Controllable::get_value)
                .endClass ()
 
+               /* PBD enums */
                .beginNamespace ("GroupControlDisposition")
                .addConst ("InverseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::InverseGroup))
                .addConst ("NoGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::NoGroup))
@@ -174,6 +309,15 @@ LuaBindings::common (lua_State* L)
 
                .beginWSPtrClass <Evoral::ControlList> ("ControlList")
                .addFunction ("add", &Evoral::ControlList::add)
+               .addFunction ("thin", &Evoral::ControlList::thin)
+               .addFunction ("eval", &Evoral::ControlList::eval)
+               .addRefFunction ("rt_safe_eval", &Evoral::ControlList::rt_safe_eval)
+               .addFunction ("interpolation", &Evoral::ControlList::interpolation)
+               .addFunction ("set_interpolation", &Evoral::ControlList::set_interpolation)
+               .addFunction ("truncate_end", &Evoral::ControlList::truncate_end)
+               .addFunction ("truncate_start", &Evoral::ControlList::truncate_start)
+               .addFunction ("clear", (void (Evoral::ControlList::*)(double, double))&Evoral::ControlList::clear)
+               .addFunction ("in_write_pass", &Evoral::ControlList::in_write_pass)
                .endClass ()
 
                .beginWSPtrClass <Evoral::ControlSet> ("ControlSet")
@@ -197,6 +341,13 @@ LuaBindings::common (lua_State* L)
                .addData ("to", &Evoral::Range<framepos_t>::to)
                .endClass ()
 
+               /* libevoral enums */
+               .beginNamespace ("InterpolationStyle")
+               .addConst ("Discrete", Evoral::ControlList::InterpolationStyle(Evoral::ControlList::Discrete))
+               .addConst ("Linear", Evoral::ControlList::InterpolationStyle(Evoral::ControlList::Linear))
+               .addConst ("Curved", Evoral::ControlList::InterpolationStyle(Evoral::ControlList::Curved))
+               .endNamespace ()
+
                .endNamespace () // Evoral
 
                .beginNamespace ("ARDOUR")
@@ -204,7 +355,9 @@ LuaBindings::common (lua_State* L)
                .beginClass <InterThreadInfo> ("InterThreadInfo")
                .addVoidConstructor ()
                .addData ("done", const_cast<bool InterThreadInfo::*>(&InterThreadInfo::done))
+#if 0 // currently unused, lua is single-threaded, no custom UIs.
                .addData ("cancel", (bool InterThreadInfo::*)&InterThreadInfo::cancel)
+#endif
                .addData ("progress", const_cast<float InterThreadInfo::*>(&InterThreadInfo::progress))
                .endClass ()
 
@@ -231,7 +384,7 @@ LuaBindings::common (lua_State* L)
                .addVoidConstructor ()
                .addFunction ("get", static_cast<uint32_t(ChanMapping::*)(DataType, uint32_t) const>(&ChanMapping::get))
                .addFunction ("set", &ChanMapping::set)
-               .addConst ("Invalid", 4294967295) // UINT32_MAX
+               .addConst ("Invalid", 4294967295U) // UINT32_MAX
                .endClass ()
 
                .beginNamespace ("Properties")
@@ -263,6 +416,17 @@ LuaBindings::common (lua_State* L)
                .deriveClass <PBD::OwnedPropertyList, PBD::PropertyList> ("OwnedPropertyList")
                .endClass ()
 
+               .beginWSPtrClass <AutomationList> ("AutomationList")
+               .addCast<PBD::Stateful> ("to_stateful")
+               .addCast<PBD::StatefulDestructible> ("to_statefuldestructible")
+               .addCast<Evoral::ControlList> ("list")
+               .addFunction ("get_state", &AutomationList::get_state)
+               .addFunction ("memento_command", &AutomationList::memento_command)
+               .addFunction ("touching", &AutomationList::touching)
+               .addFunction ("writing", &AutomationList::writing)
+               .addFunction ("touch_enabled", &AutomationList::touch_enabled)
+               .endClass ()
+
                .deriveClass <Location, PBD::StatefulDestructible> ("Location")
                .addFunction ("locked", &Location::locked)
                .addFunction ("lock", &Location::lock)
@@ -275,22 +439,63 @@ LuaBindings::common (lua_State* L)
                .addFunction ("move_to", &Location::move_to)
                .endClass ()
 
-               .deriveClass <Locations, PBD::StatefulDestructible> ("Location")
+               .deriveClass <Locations, PBD::StatefulDestructible> ("Locations")
                .addFunction ("auto_loop_location", &Locations::auto_loop_location)
                .addFunction ("auto_punch_location", &Locations::auto_punch_location)
                .addFunction ("session_range_location", &Locations::session_range_location)
                .addFunction ("first_mark_after", &Locations::first_mark_after)
-               .addFunction ("first_mark_after", &Locations::first_mark_after)
+               .addFunction ("first_mark_before", &Locations::first_mark_before)
+               .addFunction ("first_mark_at", &Locations::mark_at)
+               .addRefFunction ("marks_either_side", &Locations::marks_either_side)
+               .addRefFunction ("find_all_between", &Locations::find_all_between)
                .endClass ()
 
-               .deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
-               /* multiple inheritance is not covered by luabridge,
-                * we need explicit casts :( */
+               .beginWSPtrClass <SessionObject> ("SessionObject")
+               /* SessionObject is-a PBD::StatefulDestructible,
+                * but multiple inheritance is not covered by luabridge,
+                * we need explicit casts */
                .addCast<PBD::Stateful> ("to_stateful")
                .addCast<PBD::StatefulDestructible> ("to_statefuldestructible")
                .addFunction ("name", &SessionObject::name)
                .endClass ()
 
+               .beginWSPtrClass <Port> ("Port")
+               .addCast<MidiPort> ("to_midiport")
+               .addCast<AudioPort> ("to_audioport")
+               .addFunction ("name", &Port::name)
+               .addFunction ("pretty_name", &Port::pretty_name)
+               .addFunction ("receives_input", &Port::receives_input)
+               .addFunction ("sends_output", &Port::sends_output)
+               .addFunction ("connected", &Port::connected)
+               .addFunction ("disconnect_all", &Port::disconnect_all)
+               .addFunction ("connected_to_name", (bool (Port::*)(std::string const &)const)&Port::connected_to)
+               .addFunction ("connect_by_name", (int (Port::*)(std::string const &))&Port::connect)
+               .addFunction ("disconnect_by_name", (int (Port::*)(std::string const &))&Port::disconnect)
+               .addFunction ("connected_to", (bool (Port::*)(Port*)const)&Port::connected_to)
+               .addFunction ("connect", (int (Port::*)(Port*))&Port::connect)
+               .addFunction ("disconnect", (int (Port::*)(Port*))&Port::disconnect)
+               //.addStaticFunction ("port_offset", &Port::port_offset) // static
+               .endClass ()
+
+               .deriveWSPtrClass <AudioPort, Port> ("AudioPort")
+               .endClass ()
+
+               .deriveWSPtrClass <MidiPort, Port> ("MidiPort")
+               .addFunction ("input_active", &MidiPort::input_active)
+               .addFunction ("set_input_active", &MidiPort::set_input_active)
+               .addFunction ("get_midi_buffer", &MidiPort::get_midi_buffer) // DSP only
+               .endClass ()
+
+               .beginWSPtrClass <PortSet> ("PortSet")
+               .addFunction ("num_ports", (size_t (PortSet::*)(DataType)const)&PortSet::num_ports)
+               .addFunction ("add", &PortSet::add)
+               .addFunction ("remove", &PortSet::remove)
+               .addFunction ("port", (boost::shared_ptr<Port> (PortSet::*)(DataType, size_t)const)&PortSet::port)
+               .addFunction ("contains", &PortSet::contains)
+               .addFunction ("clear", &PortSet::clear)
+               .addFunction ("empty", &PortSet::empty)
+               .endClass ()
+
                .deriveWSPtrClass <IO, SessionObject> ("IO")
                .addFunction ("active", &IO::active)
                .addFunction ("add_port", &IO::add_port)
@@ -298,6 +503,16 @@ LuaBindings::common (lua_State* L)
                .addFunction ("connect", &IO::connect)
                .addFunction ("disconnect", (int (IO::*)(boost::shared_ptr<Port>, std::string, void *))&IO::disconnect)
                .addFunction ("physically_connected", &IO::physically_connected)
+               .addFunction ("has_port", &IO::has_port)
+               .addFunction ("nth", &IO::nth)
+               .addFunction ("audio", &IO::audio)
+               .addFunction ("midi", &IO::midi)
+               .addFunction ("port_by_name", &IO::nth)
+               .addFunction ("n_ports", &IO::n_ports)
+               .endClass ()
+
+               .beginClass <RouteGroup> ("RouteGroup")
+               // stub RouteGroup* is needed for new_audio_track()
                .endClass ()
 
                .deriveWSPtrClass <Route, SessionObject> ("Route")
@@ -307,6 +522,8 @@ LuaBindings::common (lua_State* L)
                .addFunction ("active", &Route::active)
                .addFunction ("set_active", &Route::set_active)
                .addFunction ("nth_plugin", &Route::nth_plugin)
+               .addFunction ("nth_processor", &Route::nth_processor)
+               .addFunction ("nth_send", &Route::nth_send)
                .addFunction ("add_processor_by_index", &Route::add_processor_by_index)
                .addFunction ("remove_processor", &Route::remove_processor)
                .addFunction ("replace_processor", &Route::replace_processor)
@@ -322,6 +539,8 @@ LuaBindings::common (lua_State* L)
                .addFunction ("main_outs", &Route::main_outs)
                .addFunction ("muted", &Route::muted)
                .addFunction ("soloed", &Route::soloed)
+               .addFunction ("amp", &Route::amp)
+               .addFunction ("trim", &Route::trim)
                .endClass ()
 
                .deriveWSPtrClass <Playlist, SessionObject> ("Playlist")
@@ -338,6 +557,7 @@ LuaBindings::common (lua_State* L)
                .addFunction ("find_next_region", &Playlist::find_next_region)
                .addFunction ("find_next_region_boundary", &Playlist::find_next_region_boundary)
                .addFunction ("count_regions_at", &Playlist::count_regions_at)
+               .addFunction ("regions_touched", &Playlist::regions_touched)
                .addFunction ("regions_with_start_within", &Playlist::regions_with_start_within)
                .addFunction ("regions_with_end_within", &Playlist::regions_with_end_within)
                .addFunction ("raise_region", &Playlist::raise_region)
@@ -363,12 +583,12 @@ LuaBindings::common (lua_State* L)
                .addCast<MidiTrack> ("to_midi_track")
                .addFunction ("set_name", &Track::set_name)
                .addFunction ("can_record", &Track::can_record)
-               .addFunction ("record_enabled", &Track::record_enabled)
-               .addFunction ("record_safe", &Track::record_safe)
-               .addFunction ("set_record_enabled", &Track::set_record_enabled)
-               .addFunction ("set_record_safe", &Track::set_record_safe)
+               //.addFunction ("record_enabled", &Track::record_enabled)
+               //.addFunction ("record_safe", &Track::record_safe)
+               //.addFunction ("set_record_enabled", &Track::set_record_enabled)
+               //.addFunction ("set_record_safe", &Track::set_record_safe)
                .addFunction ("bounceable", &Track::bounceable)
-               .addFunction ("bounce", &Track::bounce_range)
+               .addFunction ("bounce", &Track::bounce)
                .addFunction ("bounce_range", &Track::bounce_range)
                .addFunction ("playlist", &Track::playlist)
                .endClass ()
@@ -396,7 +616,6 @@ LuaBindings::common (lua_State* L)
                .addFunction ("locked", &Region::locked)
                .addFunction ("position_locked", &Region::position_locked)
                .addFunction ("video_locked", &Region::video_locked)
-               .addFunction ("valid_transients", &Region::valid_transients)
                .addFunction ("automatic", &Region::automatic)
                .addFunction ("whole_file", &Region::whole_file)
                .addFunction ("captured", &Region::captured)
@@ -438,6 +657,7 @@ LuaBindings::common (lua_State* L)
                .endClass ()
 
                .beginClass <Plugin::PresetRecord> ("PresetRecord")
+               .addVoidConstructor ()
                .addData ("uri", &Plugin::PresetRecord::uri, false)
                .addData ("label", &Plugin::PresetRecord::label, false)
                .addData ("user", &Plugin::PresetRecord::user, false)
@@ -454,11 +674,19 @@ LuaBindings::common (lua_State* L)
                .addData ("logarithmic", &ParameterDescriptor::logarithmic)
                .endClass ()
 
-               .deriveWSPtrClass <Processor, Automatable> ("Processor")
-               .addCast<SessionObject> ("to_sessionobject")
+               .deriveWSPtrClass <Processor, SessionObject> ("Processor")
+               .addCast<Automatable> ("to_automatable")
                .addCast<PluginInsert> ("to_insert")
                .addCast<SideChain> ("to_sidechain")
                .addCast<IOProcessor> ("to_ioprocessor")
+               .addCast<UnknownProcessor> ("to_unknownprocessor")
+               .addCast<Amp> ("to_amp")
+#if 0 // those objects are not yet bound
+               .addCast<MonitorProcessor> ("to_monitorprocessor")
+               .addCast<CapturingProcessor> ("to_capturingprocessor")
+               .addCast<DelayLine> ("to_delayline")
+               .addCast<PeakMeter> ("to_meter")
+#endif
                .addFunction ("display_name", &Processor::display_name)
                .addFunction ("active", &Processor::active)
                .addFunction ("activate", &Processor::activate)
@@ -504,17 +732,31 @@ LuaBindings::common (lua_State* L)
                .addFunction ("output_map", (ARDOUR::ChanMapping (PluginInsert::*)(uint32_t) const)&PluginInsert::output_map)
                .addFunction ("set_input_map", &PluginInsert::set_input_map)
                .addFunction ("set_output_map", &PluginInsert::set_output_map)
-
+               .addFunction ("sidechain_input", &PluginInsert::sidechain_input)
                .endClass ()
 
-               .deriveWSPtrClass <AutomationControl, Evoral::Control> ("AutomationControl")
+               .deriveWSPtrClass <AutomationControl, PBD::Controllable> ("AutomationControl")
+               .addCast<Evoral::Control> ("to_ctrl")
                .addFunction ("automation_state", &AutomationControl::automation_state)
+               .addFunction ("automation_style", &AutomationControl::automation_style)
+               .addFunction ("set_automation_state", &AutomationControl::set_automation_state)
                .addFunction ("set_automation_style", &AutomationControl::set_automation_style)
                .addFunction ("start_touch", &AutomationControl::start_touch)
                .addFunction ("stop_touch", &AutomationControl::stop_touch)
                .addFunction ("get_value", &AutomationControl::get_value)
                .addFunction ("set_value", &AutomationControl::set_value)
                .addFunction ("writable", &AutomationControl::writable)
+               .addFunction ("alist", &AutomationControl::alist)
+               .endClass ()
+
+               .deriveWSPtrClass <GainControl, AutomationControl> ("GainControl")
+               .endClass ()
+
+               .deriveWSPtrClass <Amp, Processor> ("Amp")
+               .addFunction ("gain_control", (boost::shared_ptr<GainControl>(Amp::*)())&Amp::gain_control)
+               .endClass ()
+
+               .deriveWSPtrClass <UnknownProcessor, Processor> ("UnknownProcessor")
                .endClass ()
 
                .deriveWSPtrClass <PluginInsert::PluginControl, AutomationControl> ("PluginControl")
@@ -557,6 +799,10 @@ LuaBindings::common (lua_State* L)
                .beginPtrStdList <boost::shared_ptr<Region> > ("RegionListPtr")
                .endClass ()
 
+               //std::list<boost::shared_ptr<Port> > PortList;
+               .beginConstStdList <boost::shared_ptr<Port> > ("PortList")
+               .endClass ()
+
                // used by Playlist::cut/copy
                .beginConstStdList <AudioRange> ("AudioRangeList")
                .endClass ()
@@ -571,10 +817,6 @@ LuaBindings::common (lua_State* L)
                .endClass ()
 #endif
 
-       // typedef std::set<boost::weak_ptr<AudioPort> > PortSet
-               .beginStdSet <boost::weak_ptr<AudioPort> > ("WeakPortSet")
-               .endClass ()
-
        // std::list<boost::weak_ptr<Source> >
                .beginConstStdList <boost::weak_ptr<Source> > ("WeakSourceList")
                .endClass ()
@@ -642,12 +884,22 @@ LuaBindings::common (lua_State* L)
 
                .beginNamespace ("AutomationType")
                .addConst ("PluginAutomation", ARDOUR::AutomationType(PluginAutomation))
+               .addConst ("PluginAutomation", ARDOUR::AutomationType(GainAutomation))
+               .addConst ("PluginAutomation", ARDOUR::AutomationType(TrimAutomation))
                .endNamespace ()
 
                .beginNamespace ("SrcQuality")
                .addConst ("SrcBest", ARDOUR::SrcQuality(SrcBest))
                .endNamespace ()
 
+               .beginNamespace ("PortFlags")
+               .addConst ("IsInput", ARDOUR::PortFlags(IsInput))
+               .addConst ("IsOutput", ARDOUR::PortFlags(IsOutput))
+               .addConst ("IsPhysical", ARDOUR::PortFlags(IsPhysical))
+               .addConst ("CanMonitor", ARDOUR::PortFlags(CanMonitor))
+               .addConst ("IsTerminal", ARDOUR::PortFlags(IsTerminal))
+               .endNamespace ()
+
                .beginNamespace ("PlaylistDisposition")
                .addConst ("CopyPlaylist", ARDOUR::PlaylistDisposition(CopyPlaylist))
                .addConst ("NewPlaylist", ARDOUR::PlaylistDisposition(NewPlaylist))
@@ -658,7 +910,14 @@ LuaBindings::common (lua_State* L)
                .addConst ("Start", ARDOUR::RegionPoint(Start))
                .addConst ("End", ARDOUR::RegionPoint(End))
                .addConst ("SyncPoint", ARDOUR::RegionPoint(SyncPoint))
-               .endNamespace ();
+               .endNamespace ()
+
+               .beginNamespace ("TrackMode")
+               .addConst ("Normal", ARDOUR::TrackMode(Start))
+               .addConst ("NonLayered", ARDOUR::TrackMode(NonLayered))
+               .addConst ("Destructive", ARDOUR::TrackMode(Destructive))
+               .endNamespace ()
+               .endNamespace (); // end ARDOUR
 
        luabridge::getGlobalNamespace (L)
                .beginNamespace ("ARDOUR")
@@ -702,7 +961,29 @@ LuaBindings::common (lua_State* L)
                .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
                .endClass()
 
-               .beginClass <AudioEngine> ("AudioEngine")
+               .beginClass <PortEngine> ("PortEngine")
+               .endClass()
+
+               .beginClass <PortManager> ("PortManager")
+               .addFunction ("port_engine", &PortManager::port_engine)
+               .addFunction ("connected", &PortManager::connected)
+               .addFunction ("connect", &PortManager::connect)
+               .addFunction ("physically_connected", &PortManager::physically_connected)
+               .addFunction ("disconnect", (int (PortManager::*)(const std::string&, const std::string&))&PortManager::disconnect)
+               .addFunction ("disconnect_port", (int (PortManager::*)(boost::shared_ptr<Port>))&PortManager::disconnect)
+               .addFunction ("get_port_by_name", &PortManager::get_port_by_name)
+               .addFunction ("get_pretty_name_by_name", &PortManager::get_pretty_name_by_name)
+               .addFunction ("port_is_physical", &PortManager::port_is_physical)
+               .addFunction ("get_physical_outputs", &PortManager::get_physical_outputs)
+               .addFunction ("get_physical_inputs", &PortManager::get_physical_inputs)
+               .addFunction ("n_physical_outputs", &PortManager::n_physical_outputs)
+               .addFunction ("n_physical_inputs", &PortManager::n_physical_inputs)
+               .addRefFunction ("get_connections", &PortManager::get_connections)
+               .addRefFunction ("get_ports", (int (PortManager::*)(DataType, PortManager::PortList&))&PortManager::get_ports)
+               .addRefFunction ("get_backend_ports", (int (PortManager::*)(const std::string&, DataType, PortFlags, std::vector<std::string>&))&PortManager::get_ports)
+               .endClass()
+
+               .deriveClass <AudioEngine, PortManager> ("AudioEngine")
                .addFunction ("available_backends", &AudioEngine::available_backends)
                .addFunction ("current_backend_name", &AudioEngine::current_backend_name)
                .addFunction ("set_backend", &AudioEngine::set_backend)
@@ -741,6 +1022,10 @@ LuaBindings::common (lua_State* L)
                .addFunction ("current_start_frame", &Session::current_start_frame)
                .addFunction ("current_end_frame", &Session::current_end_frame)
                .addFunction ("actively_recording", &Session::actively_recording)
+               .addFunction ("new_audio_track", &Session::new_audio_track)
+               .addFunction ("new_audio_route", &Session::new_audio_route)
+               .addFunction ("new_midi_track", &Session::new_midi_track)
+               .addFunction ("new_midi_route", &Session::new_midi_route)
                .addFunction ("get_routes", &Session::get_routes)
                .addFunction ("get_tracks", &Session::get_tracks)
                .addFunction ("name", &Session::name)
@@ -748,25 +1033,34 @@ LuaBindings::common (lua_State* L)
                .addFunction ("record_status", &Session::record_status)
                .addFunction ("route_by_id", &Session::route_by_id)
                .addFunction ("route_by_name", &Session::route_by_name)
-               .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
+               // STRIPABLE .addFunction ("route_by_remote_id", &Session::route_by_remote_id)
                .addFunction ("track_by_diskstream_id", &Session::track_by_diskstream_id)
                .addFunction ("source_by_id", &Session::source_by_id)
                .addFunction ("controllable_by_id", &Session::controllable_by_id)
                .addFunction ("processor_by_id", &Session::processor_by_id)
                .addFunction ("snap_name", &Session::snap_name)
+               .addFunction ("monitor_out", &Session::monitor_out)
+               .addFunction ("master_out", &Session::master_out)
                .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map)
                .addFunction ("locations", &Session::locations)
                .addFunction ("begin_reversible_command", (void (Session::*)(const std::string&))&Session::begin_reversible_command)
                .addFunction ("commit_reversible_command", &Session::commit_reversible_command)
                .addFunction ("abort_reversible_command", &Session::abort_reversible_command)
+               .addFunction ("add_command", &Session::add_command)
                .addFunction ("add_stateful_diff_command", &Session::add_stateful_diff_command)
+               .addFunction ("engine", (AudioEngine& (Session::*)())&Session::engine)
+               .addFunction ("get_block_size", &Session::get_block_size)
+               .addFunction ("worst_output_latency", &Session::worst_output_latency)
+               .addFunction ("worst_input_latency", &Session::worst_input_latency)
+               .addFunction ("worst_track_latency", &Session::worst_track_latency)
+               .addFunction ("worst_playback_latency", &Session::worst_playback_latency)
                .endClass ()
 
                .beginClass <RegionFactory> ("RegionFactory")
                .addStaticFunction ("region_by_id", &RegionFactory::region_by_id)
                .endClass ()
 
-               /* session enums */
+               /* session enums (rt-safe, common) */
                .beginNamespace ("Session")
 
                .beginNamespace ("RecordState")
@@ -775,7 +1069,20 @@ LuaBindings::common (lua_State* L)
                .addConst ("Recording", ARDOUR::Session::RecordState(Session::Recording))
                .endNamespace ()
 
-               .endNamespace () // END Session enums
+               .endNamespace () // end Session enums
+
+               /* ardour enums (rt-safe, common) */
+               .beginNamespace ("LocationFlags")
+               .addConst ("IsMark", ARDOUR::Location::Flags(Location::IsMark))
+               .addConst ("IsAutoPunch", ARDOUR::Location::Flags(Location::IsAutoPunch))
+               .addConst ("IsAutoLoop", ARDOUR::Location::Flags(Location::IsAutoLoop))
+               .addConst ("IsHidden", ARDOUR::Location::Flags(Location::IsHidden))
+               .addConst ("IsCDMarker", ARDOUR::Location::Flags(Location::IsCDMarker))
+               .addConst ("IsRangeMarker", ARDOUR::Location::Flags(Location::IsRangeMarker))
+               .addConst ("IsSessionRange", ARDOUR::Location::Flags(Location::IsSessionRange))
+               .addConst ("IsSkip", ARDOUR::Location::Flags(Location::IsSkip))
+               .addConst ("IsSkipping", ARDOUR::Location::Flags(Location::IsSkipping))
+               .endNamespace ()
 
                .beginNamespace ("LuaAPI")
                .addFunction ("nil_proc", ARDOUR::LuaAPI::nil_processor)
@@ -784,10 +1091,10 @@ LuaBindings::common (lua_State* L)
                .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
                .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
                .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
+               .addCFunction ("plugin_automation", ARDOUR::LuaAPI::plugin_automation)
                .addFunction ("usleep", Glib::usleep)
-               .endNamespace ()
-
-               .endNamespace ();// END ARDOUR
+               .endNamespace () // end LuaAPI
+               .endNamespace ();// end ARDOUR
 }
 
 void
@@ -797,6 +1104,7 @@ LuaBindings::dsp (lua_State* L)
                .beginNamespace ("ARDOUR")
 
                .beginClass <AudioBuffer> ("AudioBuffer")
+               .addEqualCheck ()
                .addFunction ("data", (Sample*(AudioBuffer::*)(framecnt_t))&AudioBuffer::data)
                .addFunction ("silence", &AudioBuffer::silence)
                .addFunction ("apply_gain", &AudioBuffer::apply_gain)
@@ -805,12 +1113,16 @@ LuaBindings::dsp (lua_State* L)
                .endClass()
 
                .beginClass <MidiBuffer> ("MidiBuffer")
+               .addEqualCheck ()
                .addFunction ("silence", &MidiBuffer::silence)
-               .addFunction ("empty", &MidiBuffer::empty)
+               .addFunction ("push_event", (bool (MidiBuffer::*)(const Evoral::MIDIEvent<framepos_t>&))&MidiBuffer::push_back)
+               .addFunction ("push_back", (bool (MidiBuffer::*)(framepos_t, size_t, const uint8_t*))&MidiBuffer::push_back)
                // TODO iterators..
+               .addExtCFunction ("table", &luabridge::CFunc::listToTable<const Evoral::MIDIEvent<framepos_t>, MidiBuffer>)
                .endClass()
 
                .beginClass <BufferSet> ("BufferSet")
+               .addEqualCheck ()
                .addFunction ("get_audio", static_cast<AudioBuffer&(BufferSet::*)(size_t)>(&BufferSet::get_audio))
                .addFunction ("count", static_cast<const ChanCount&(BufferSet::*)()const>(&BufferSet::count))
                .endClass()
@@ -833,8 +1145,8 @@ LuaBindings::dsp (lua_State* L)
                // add Ctor?
                .addFunction ("type", &Evoral::MIDIEvent<framepos_t>::type)
                .addFunction ("channel", &Evoral::MIDIEvent<framepos_t>::channel)
-               .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::type)
-               .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::channel)
+               .addFunction ("set_type", &Evoral::MIDIEvent<framepos_t>::set_type)
+               .addFunction ("set_channel", &Evoral::MIDIEvent<framepos_t>::set_channel)
                .endClass ()
                .endNamespace ();
 
@@ -872,24 +1184,25 @@ LuaBindings::dsp (lua_State* L)
                .addFunction ("set_cutoff", &DSP::LowPass::set_cutoff)
                .addFunction ("reset", &DSP::LowPass::reset)
                .endClass ()
-               .beginClass <DSP::BiQuad> ("Biquad")
+               .beginClass <DSP::Biquad> ("Biquad")
                .addConstructor <void (*) (double)> ()
-               .addFunction ("run", &DSP::BiQuad::run)
-               .addFunction ("compute", &DSP::BiQuad::compute)
-               .addFunction ("reset", &DSP::BiQuad::reset)
+               .addFunction ("run", &DSP::Biquad::run)
+               .addFunction ("compute", &DSP::Biquad::compute)
+               .addFunction ("reset", &DSP::Biquad::reset)
+               .addFunction ("dB_at_freq", &DSP::Biquad::dB_at_freq)
                .endClass ()
 
                /* DSP enums */
-               .beginNamespace ("BiQuadType")
-               .addConst ("LowPass", ARDOUR::DSP::BiQuad::LowPass)
-               .addConst ("HighPass", ARDOUR::DSP::BiQuad::HighPass)
-               .addConst ("BandPassSkirt", ARDOUR::DSP::BiQuad::BandPassSkirt)
-               .addConst ("BandPass0dB", ARDOUR::DSP::BiQuad::BandPass0dB)
-               .addConst ("Notch", ARDOUR::DSP::BiQuad::Notch)
-               .addConst ("AllPass", ARDOUR::DSP::BiQuad::AllPass)
-               .addConst ("Peaking", ARDOUR::DSP::BiQuad::Peaking)
-               .addConst ("LowShelf", ARDOUR::DSP::BiQuad::LowShelf)
-               .addConst ("HighShelf", ARDOUR::DSP::BiQuad::HighShelf)
+               .beginNamespace ("BiquadType")
+               .addConst ("LowPass", ARDOUR::DSP::Biquad::LowPass)
+               .addConst ("HighPass", ARDOUR::DSP::Biquad::HighPass)
+               .addConst ("BandPassSkirt", ARDOUR::DSP::Biquad::BandPassSkirt)
+               .addConst ("BandPass0dB", ARDOUR::DSP::Biquad::BandPass0dB)
+               .addConst ("Notch", ARDOUR::DSP::Biquad::Notch)
+               .addConst ("AllPass", ARDOUR::DSP::Biquad::AllPass)
+               .addConst ("Peaking", ARDOUR::DSP::Biquad::Peaking)
+               .addConst ("LowShelf", ARDOUR::DSP::Biquad::LowShelf)
+               .addConst ("HighShelf", ARDOUR::DSP::Biquad::HighShelf)
                .endNamespace ()
 
                .beginClass <DSP::DspShm> ("DspShm")