allow to customize variable i/o plugin inputs
[ardour.git] / libs / ardour / luabindings.cc
index 21a8fdeed47da4628a1955cb496c6acc4940647a..c5ff0ada33bb00d28cd13d18a2cc75b699841636 100644 (file)
@@ -29,6 +29,7 @@
 #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::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.
@@ -149,6 +274,7 @@ 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 ()
 
@@ -225,7 +351,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 ()
 
@@ -307,7 +435,7 @@ 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)
@@ -315,9 +443,10 @@ LuaBindings::common (lua_State* L)
                .addFunction ("first_mark_after", &Locations::first_mark_after)
                .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)
@@ -338,6 +467,14 @@ LuaBindings::common (lua_State* L)
                .addFunction ("disconnect", (int (Port::*)(Port*))&Port::disconnect)
                .endClass ()
 
+               .deriveWSPtrClass <AudioPort, Port> ("AudioPort")
+               .endClass ()
+
+               .deriveWSPtrClass <MidiPort, Port> ("MidiPort")
+               .addFunction ("input_active", &MidiPort::input_active)
+               .addFunction ("set_input_active", &MidiPort::set_input_active)
+               .endClass ()
+
                .beginWSPtrClass <PortSet> ("PortSet")
                .addFunction ("num_ports", (size_t (PortSet::*)(DataType)const)&PortSet::num_ports)
                .addFunction ("add", &PortSet::add)
@@ -363,6 +500,10 @@ LuaBindings::common (lua_State* L)
                .addFunction ("n_ports", &IO::n_ports)
                .endClass ()
 
+               .beginClass <RouteGroup> ("RouteGroup")
+               // stub RouteGroup* is needed for new_audio_track()
+               .endClass ()
+
                .deriveWSPtrClass <Route, SessionObject> ("Route")
                .addCast<Track> ("to_track")
                .addFunction ("set_name", &Route::set_name)
@@ -434,7 +575,7 @@ LuaBindings::common (lua_State* L)
                .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 ()
@@ -520,8 +661,8 @@ 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")
@@ -570,10 +711,10 @@ 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)
@@ -634,6 +775,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 ()
@@ -723,6 +868,14 @@ LuaBindings::common (lua_State* L)
                .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))
@@ -733,6 +886,13 @@ LuaBindings::common (lua_State* L)
                .addConst ("Start", ARDOUR::RegionPoint(Start))
                .addConst ("End", ARDOUR::RegionPoint(End))
                .addConst ("SyncPoint", ARDOUR::RegionPoint(SyncPoint))
+               .endNamespace ()
+
+               .beginNamespace ("TrackMode")
+               .addConst ("Normal", ARDOUR::TrackMode(Start))
+               .addConst ("NonLayered", ARDOUR::TrackMode(NonLayered))
+               .addConst ("Destructive", ARDOUR::TrackMode(Destructive))
+               .endNamespace ()
                .endNamespace ();
 
        luabridge::getGlobalNamespace (L)
@@ -777,7 +937,26 @@ LuaBindings::common (lua_State* L)
                .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name)
                .endClass()
 
-               .beginClass <AudioEngine> ("AudioEngine")
+               .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)
@@ -816,6 +995,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)
@@ -829,6 +1012,8 @@ LuaBindings::common (lua_State* L)
                .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)
@@ -836,6 +1021,7 @@ LuaBindings::common (lua_State* L)
                .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)
                .endClass ()
 
                .beginClass <RegionFactory> ("RegionFactory")
@@ -874,6 +1060,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)
@@ -882,12 +1069,14 @@ LuaBindings::dsp (lua_State* L)
                .endClass()
 
                .beginClass <MidiBuffer> ("MidiBuffer")
+               .addEqualCheck ()
                .addFunction ("silence", &MidiBuffer::silence)
                .addFunction ("empty", &MidiBuffer::empty)
                // TODO iterators..
                .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()