VST report audioMasterPinConnected according to Pin Management
[ardour.git] / libs / ardour / luabindings.cc
index 21a8fdeed47da4628a1955cb496c6acc4940647a..5dcd0964cd755dbdf4d19d294d38b2029d5b54ac 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 "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(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::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 +270,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 ()
 
@@ -307,7 +429,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 +437,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 +461,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)
@@ -434,7 +565,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 +651,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 +701,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)