Optimize automation-event process splitting
[ardour.git] / libs / ardour / lv2_plugin.cc
index 92badc4b5ace30ca2a93d33e5e5ee89a8ab96ef2..79bef11cdde146bb9170f406d56800eafbbb5342 100644 (file)
 #include "pbd/windows_special_dirs.h"
 #endif
 
+#ifdef WAF_BUILD
 #include "libardour-config.h"
+#endif
 
 #include "ardour/audio_buffer.h"
 #include "ardour/audioengine.h"
+#include "ardour/directory_names.h"
 #include "ardour/debug.h"
 #include "ardour/lv2_plugin.h"
 #include "ardour/midi_patch_manager.h"
@@ -1378,13 +1381,20 @@ LV2Plugin::add_state(XMLNode* root) const
                unsigned int saved_state = _state_version;;
                g_mkdir_with_parents(new_dir.c_str(), 0744);
 
+               std::string xternal_dir = _session.externals_dir ();
+
+               if (!_plugin_state_dir.empty()) {
+                       xternal_dir = Glib::build_filename (_plugin_state_dir, externals_dir_name);
+                       g_mkdir_with_parents(xternal_dir.c_str(), 0744);
+               }
+
                LilvState* state = lilv_state_new_from_instance(
                        _impl->plugin,
                        _impl->instance,
                        _uri_map.urid_map(),
                        scratch_dir().c_str(),
                        file_dir().c_str(),
-                       _session.externals_dir().c_str(),
+                       xternal_dir.c_str(),
                        new_dir.c_str(),
                        NULL,
                        const_cast<LV2Plugin*>(this),
@@ -1414,6 +1424,7 @@ LV2Plugin::add_state(XMLNode* root) const
                        } else {
                                // template save (dedicated state-dir)
                                lilv_state_free(state);
+                               g_rmdir (xternal_dir.c_str()); // try remove unused dir
                                --_state_version;
                        }
                } else {
@@ -1981,6 +1992,16 @@ LV2Plugin::load_supported_properties(PropertyDescriptors& descs)
        lilv_nodes_free(properties);
 }
 
+Variant
+LV2Plugin::get_property_value (uint32_t prop_id) const
+{
+       std::map<uint32_t, Variant>::const_iterator it;
+       if ((it = _property_values.find (prop_id)) == _property_values.end()) {
+               return Variant();
+       }
+       return it->second;
+}
+
 void
 LV2Plugin::announce_property_values()
 {
@@ -2323,18 +2344,22 @@ LV2Plugin::describe_parameter(Evoral::Parameter which)
 {
        if (( which.type() == PluginAutomation) && ( which.id() < parameter_count()) ) {
 
-               if (lilv_port_has_property(_impl->plugin,
-                                       lilv_plugin_get_port_by_index(_impl->plugin, which.id()), _world.ext_notOnGUI)) {
+               const LilvPort* port = lilv_plugin_get_port_by_index(_impl->plugin, which.id());
+
+               if (lilv_port_has_property(_impl->plugin, port, _world.ext_notOnGUI)) {
                        return X_("hidden");
                }
 
-               if (lilv_port_has_property(_impl->plugin,
-                                       lilv_plugin_get_port_by_index(_impl->plugin, which.id()), _world.lv2_freewheeling)) {
+               const LilvPort* fwport = lilv_plugin_get_port_by_designation(_impl->plugin, _world.lv2_InputPort, _world.lv2_freewheeling);
+               if (fwport && fwport == port) {
                        return X_("hidden");
                }
 
-               if (lilv_port_has_property(_impl->plugin,
-                                       lilv_plugin_get_port_by_index(_impl->plugin, which.id()), _world.lv2_reportsLatency)) {
+               if (lilv_port_has_property(_impl->plugin, port, _world.lv2_freewheeling)) {
+                       return X_("hidden");
+               }
+
+               if (lilv_port_has_property(_impl->plugin, port, _world.lv2_reportsLatency)) {
                        return X_("latency");
                }
 
@@ -2553,7 +2578,7 @@ write_position(LV2_Atom_Forge*     forge,
 int
 LV2Plugin::connect_and_run(BufferSet& bufs,
                samplepos_t start, samplepos_t end, double speed,
-               ChanMapping in_map, ChanMapping out_map,
+               ChanMapping const& in_map, ChanMapping const& out_map,
                pframes_t nframes, samplecnt_t offset)
 {
        DEBUG_TRACE(DEBUG::LV2, string_compose("%1 run %2 offset %3\n", name(), nframes, offset));
@@ -2929,6 +2954,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
                                                                // Emit PropertyChanged signal for UI
                                                                // TODO: This should emit the control's Changed signal
                                                                PropertyChanged(prop_id, Variant(Variant::PATH, path));
+                                                               _property_values[prop_id] = Variant(Variant::PATH, path);
                                                        } else {
                                                                std::cerr << "warning: patch:Set for unknown property" << std::endl;
                                                        }
@@ -3411,31 +3437,6 @@ LV2PluginInfo::get_presets (bool /*user_only*/) const
        return p;
 }
 
-bool
-LV2PluginInfo::in_category (const std::string &c) const
-{
-       // TODO use untranslated lilv_plugin_get_class()
-       // match gtk2_ardour/plugin_selector.cc
-       return category == c;
-}
-
-bool
-LV2PluginInfo::is_instrument () const
-{
-       if (category == "Instrument") {
-               return true;
-       }
-#if 1
-       /* until we make sure that category remains untranslated in the lv2.ttl spec
-        * and until most instruments also classify themselves as such, there's a 2nd check:
-        */
-       if (n_inputs.n_midi() > 0 && n_inputs.n_audio() == 0 && n_outputs.n_audio() > 0) {
-               return true;
-       }
-#endif
-       return false;
-}
-
 PluginInfoList*
 LV2PluginInfo::discover()
 {