Merge branch 'master' into windows
[ardour.git] / libs / ardour / lv2_plugin.cc
index 4f1f9b96776deb4fbecab1baa3efcb5540a6dcd6..6288616824c2b70c7c8689117059e7b5f57717eb 100644 (file)
@@ -143,6 +143,7 @@ public:
        LilvNode* time_Position;
        LilvNode* ui_GtkUI;
        LilvNode* ui_external;
+       LilvNode* ui_externalkx;
 
 private:
        bool _bundle_checked;
@@ -290,7 +291,7 @@ LV2Plugin::init(const void* c_plugin, framecnt_t rate)
        _latency_control_port   = 0;
        _next_cycle_start       = std::numeric_limits<framepos_t>::max();
        _next_cycle_speed       = 1.0;
-       _block_length           = _engine.frames_per_cycle();
+       _block_length           = _engine.samples_per_cycle();
        _seq_size               = _engine.raw_buffer_size(DataType::MIDI);
        _state_version          = 0;
        _was_activated          = false;
@@ -562,11 +563,15 @@ LV2Plugin::init(const void* c_plugin, framecnt_t rate)
                if (!_impl->ui) {
                        LILV_FOREACH(uis, i, uis) {
                                const LilvUI* ui = lilv_uis_get(uis, i);
-                               if (lilv_ui_is_a(ui, _world.ui_external)) {
+                               if (lilv_ui_is_a(ui, _world.ui_externalkx)) {
                                        _impl->ui      = ui;
                                        _impl->ui_type = _world.ui_external;
                                        break;
                                }
+                               if (lilv_ui_is_a(ui, _world.ui_external)) {
+                                       _impl->ui      = ui;
+                                       _impl->ui_type = _world.ui_external;
+                               }
                        }
                }
        }
@@ -614,7 +619,16 @@ LV2Plugin::is_external_ui() const
        if (!_impl->ui) {
                return false;
        }
-       return lilv_ui_is_a(_impl->ui, _world.ui_external);
+       return lilv_ui_is_a(_impl->ui, _world.ui_external) || lilv_ui_is_a(_impl->ui, _world.ui_externalkx);
+}
+
+bool
+LV2Plugin::is_external_kx() const
+{
+       if (!_impl->ui) {
+               return false;
+       }
+       return lilv_ui_is_a(_impl->ui, _world.ui_externalkx);
 }
 
 bool
@@ -1138,8 +1152,20 @@ LV2Plugin::write_from_ui(uint32_t       index,
                          const uint8_t* body)
 {
        if (!_from_ui) {
-               _from_ui = new RingBuffer<uint8_t>(
-                       _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS);
+               size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS;
+               /* buffer data communication from plugin UI to plugin instance.
+                * this buffer needs to potentially hold
+                *   (port's minimumSize) * (audio-periods) / (UI-periods)
+                * bytes.
+                *
+                *  e.g 48kSPS / 128fpp -> audio-periods = 375 Hz
+                *  ui-periods = 25 Hz (SuperRapidScreenUpdate)
+                *  default minimumSize = 32K (see LV2Plugin::allocate_atom_event_buffers()
+                *  -> 15 * 32K
+                * it is safe to overflow (but the plugin state may be inconsistent).
+                */
+               rbs = max((size_t) 32768 * 6, rbs);
+               _from_ui = new RingBuffer<uint8_t>(rbs);
        }
 
        if (!write_to(_from_ui, index, protocol, size, body)) {
@@ -1166,8 +1192,10 @@ void
 LV2Plugin::enable_ui_emmission()
 {
        if (!_to_ui) {
-               _to_ui = new RingBuffer<uint8_t>(
-                       _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS);
+               /* see note in LV2Plugin::write_from_ui() */
+               size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS;
+               rbs = max((size_t) 32768 * 8, rbs);
+               _to_ui = new RingBuffer<uint8_t>(rbs);
        }
 }
 
@@ -1354,11 +1382,6 @@ LV2Plugin::describe_parameter(Evoral::Parameter which)
                        return X_("hidden");
                }
 
-               if (lilv_port_has_property(_impl->plugin,
-                                       lilv_plugin_get_port_by_index(_impl->plugin, which.id()), _world.lv2_sampleRate)) {
-                       return X_("hidden");
-               }
-
                if (lilv_port_has_property(_impl->plugin,
                                        lilv_plugin_get_port_by_index(_impl->plugin, which.id()), _world.lv2_reportsLatency)) {
                        return X_("latency");
@@ -1902,7 +1925,7 @@ LV2Plugin::Impl::designated_input (const char* uri, void** bufptrs[], void** buf
        return port;
 }
 
-static bool lv2_filter (const string& str, void *arg)
+static bool lv2_filter (const string& str, void* /*arg*/)
 {
        /* Not a dotfile, has a prefix before a period, suffix is "lv2" */
        
@@ -1942,10 +1965,12 @@ LV2World::LV2World()
        time_Position      = lilv_new_uri(world, LV2_TIME__Position);
        ui_GtkUI           = lilv_new_uri(world, LV2_UI__GtkUI);
        ui_external        = lilv_new_uri(world, "http://lv2plug.in/ns/extensions/ui#external");
+       ui_externalkx      = lilv_new_uri(world, "http://kxstudio.sf.net/ns/lv2ext/external-ui#Widget");
 }
 
 LV2World::~LV2World()
 {
+       lilv_node_free(ui_externalkx);
        lilv_node_free(ui_external);
        lilv_node_free(ui_GtkUI);
        lilv_node_free(time_Position);
@@ -1983,7 +2008,7 @@ LV2World::load_bundled_plugins()
                vector<string *> *plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true);
                if (plugin_objects) {
                        for ( vector<string *>::iterator x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
-#ifdef WINDOWS
+#ifdef PLATFORM_WINDOWS
                                string uri = "file:///" + **x + "/";
 #else
                                string uri = "file://" + **x + "/";