2 Copyright (C) 2008-2012 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <giomm/file.h>
30 #include <boost/utility.hpp>
32 #include "pbd/compose.h"
33 #include "pbd/error.h"
34 #include "pbd/xml++.h"
36 #include "libardour-config.h"
38 #include "ardour/types.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audioengine.h"
41 #include "ardour/debug.h"
42 #include "ardour/lv2_plugin.h"
43 #include "ardour/session.h"
44 #include "ardour/tempo.h"
45 #include "ardour/worker.h"
50 #include <lilv/lilv.h>
52 #include "lv2/lv2plug.in/ns/ext/atom/atom.h"
53 #include "lv2/lv2plug.in/ns/ext/port-props/port-props.h"
54 #include "lv2/lv2plug.in/ns/ext/presets/presets.h"
55 #include "lv2/lv2plug.in/ns/ext/state/state.h"
56 #include "lv2/lv2plug.in/ns/ext/time/time.h"
57 #include "lv2/lv2plug.in/ns/ext/worker/worker.h"
58 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
60 #include "lv2_evbuf.h"
63 #include <suil/suil.h>
67 using namespace ARDOUR;
70 URIMap LV2Plugin::_uri_map;
71 uint32_t LV2Plugin::_midi_event_type = _uri_map.uri_to_id(
72 "http://lv2plug.in/ns/ext/midi#MidiEvent");
73 uint32_t LV2Plugin::_chunk_type = _uri_map.uri_to_id(
75 uint32_t LV2Plugin::_sequence_type = _uri_map.uri_to_id(
77 uint32_t LV2Plugin::_event_transfer_type = _uri_map.uri_to_id(
78 LV2_ATOM__eventTransfer);
79 uint32_t LV2Plugin::_path_type = _uri_map.uri_to_id(
82 class LV2World : boost::noncopyable {
89 LilvNode* atom_AtomPort;
91 LilvNode* atom_Sequence;
92 LilvNode* atom_bufferType;
93 LilvNode* atom_eventTransfer;
94 LilvNode* ev_EventPort;
95 LilvNode* ext_logarithmic;
96 LilvNode* lv2_AudioPort;
97 LilvNode* lv2_ControlPort;
98 LilvNode* lv2_InputPort;
99 LilvNode* lv2_OutputPort;
100 LilvNode* lv2_enumeration;
101 LilvNode* lv2_inPlaceBroken;
102 LilvNode* lv2_integer;
103 LilvNode* lv2_sampleRate;
104 LilvNode* lv2_toggled;
105 LilvNode* midi_MidiEvent;
106 LilvNode* rdfs_comment;
108 LilvNode* ui_external;
111 static LV2World _world;
113 /** Called by the plugin to schedule non-RT work. */
114 static LV2_Worker_Status
115 work_schedule(LV2_Worker_Schedule_Handle handle,
119 LV2Plugin* plugin = (LV2Plugin*)handle;
120 if (plugin->session().engine().freewheeling()) {
121 // Freewheeling, do the work immediately in this (audio) thread
122 return (LV2_Worker_Status)plugin->work(size, data);
124 // Enqueue message for the worker thread
125 return plugin->worker()->schedule(size, data) ?
126 LV2_WORKER_SUCCESS : LV2_WORKER_ERR_UNKNOWN;
130 /** Called by the plugin to respond to non-RT work. */
131 static LV2_Worker_Status
132 work_respond(LV2_Worker_Respond_Handle handle,
136 LV2Plugin* plugin = (LV2Plugin*)handle;
137 if (plugin->session().engine().freewheeling()) {
138 // Freewheeling, respond immediately in this (audio) thread
139 return (LV2_Worker_Status)plugin->work_response(size, data);
141 // Enqueue response for the worker
142 return plugin->worker()->respond(size, data) ?
143 LV2_WORKER_SUCCESS : LV2_WORKER_ERR_UNKNOWN;
147 struct LV2Plugin::Impl {
148 Impl() : plugin(0), ui(0), ui_type(0), name(0), author(0), instance(0)
153 /** Find the LV2 input port with the given designation.
154 * If found, bufptrs[port_index] will be set to bufptr.
156 LilvPort* designated_input (const char* uri, void** bufptrs[], void** bufptr);
160 const LilvNode* ui_type;
163 LilvInstance* instance;
164 LV2_Worker_Interface* work_iface;
168 LV2Plugin::LV2Plugin (AudioEngine& engine,
172 : Plugin (engine, session)
179 init(c_plugin, rate);
182 LV2Plugin::LV2Plugin (const LV2Plugin& other)
188 , _insert_id(other._insert_id)
190 init(other._impl->plugin, other._sample_rate);
192 for (uint32_t i = 0; i < parameter_count(); ++i) {
193 _control_data[i] = other._shadow_data[i];
194 _shadow_data[i] = other._shadow_data[i];
199 LV2Plugin::init(void* c_plugin, framecnt_t rate)
201 DEBUG_TRACE(DEBUG::LV2, "init\n");
203 _impl->plugin = (LilvPlugin*)c_plugin;
205 _impl->ui_type = NULL;
211 _bpm_control_port = 0;
212 _freewheel_control_port = 0;
213 _latency_control_port = 0;
215 _was_activated = false;
216 _has_state_interface = false;
218 _instance_access_feature.URI = "http://lv2plug.in/ns/ext/instance-access";
219 _data_access_feature.URI = "http://lv2plug.in/ns/ext/data-access";
220 _make_path_feature.URI = LV2_STATE__makePath;
221 _work_schedule_feature.URI = LV2_WORKER__schedule;
222 _work_schedule_feature.data = NULL;
224 LilvPlugin* plugin = _impl->plugin;
226 LilvNode* state_iface_uri = lilv_new_uri(_world.world, LV2_STATE__interface);
227 LilvNode* state_uri = lilv_new_uri(_world.world, LV2_STATE_URI);
228 _has_state_interface =
229 // What plugins should have (lv2:extensionData state:Interface)
230 lilv_plugin_has_extension_data(plugin, state_iface_uri)
231 // What some outdated/incorrect ones have
232 || lilv_plugin_has_feature(plugin, state_uri);
233 lilv_node_free(state_uri);
234 lilv_node_free(state_iface_uri);
236 _features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * 8);
237 _features[0] = &_instance_access_feature;
238 _features[1] = &_data_access_feature;
239 _features[2] = &_make_path_feature;
240 _features[3] = _uri_map.uri_map_feature();
241 _features[4] = _uri_map.urid_map_feature();
242 _features[5] = _uri_map.urid_unmap_feature();
246 LV2_State_Make_Path* make_path = (LV2_State_Make_Path*)malloc(
247 sizeof(LV2_State_Make_Path));
248 make_path->handle = this;
249 make_path->path = &lv2_state_make_path;
250 _make_path_feature.data = make_path;
252 LilvNode* worker_schedule = lilv_new_uri(_world.world, LV2_WORKER__schedule);
253 if (lilv_plugin_has_feature(plugin, worker_schedule)) {
254 LV2_Worker_Schedule* schedule = (LV2_Worker_Schedule*)malloc(
255 sizeof(LV2_Worker_Schedule));
256 _worker = new Worker(this, 4096);
257 schedule->handle = this;
258 schedule->schedule_work = work_schedule;
259 _work_schedule_feature.data = schedule;
260 _features[6] = &_work_schedule_feature;
262 lilv_node_free(worker_schedule);
264 _impl->instance = lilv_plugin_instantiate(plugin, rate, _features);
265 _impl->name = lilv_plugin_get_name(plugin);
266 _impl->author = lilv_plugin_get_author_name(plugin);
268 if (_impl->instance == 0) {
269 error << _("LV2: Failed to instantiate plugin ") << uri() << endmsg;
270 throw failed_constructor();
273 _instance_access_feature.data = (void*)_impl->instance->lv2_handle;
274 _data_access_extension_data.extension_data = _impl->instance->lv2_descriptor->extension_data;
275 _data_access_feature.data = &_data_access_extension_data;
277 _impl->work_iface = (LV2_Worker_Interface*)extension_data(LV2_WORKER__interface);
279 if (lilv_plugin_has_feature(plugin, _world.lv2_inPlaceBroken)) {
280 error << string_compose(
281 _("LV2: \"%1\" cannot be used, since it cannot do inplace processing"),
282 lilv_node_as_string(_impl->name)) << endmsg;
283 lilv_node_free(_impl->name);
284 lilv_node_free(_impl->author);
285 throw failed_constructor();
290 const uint32_t num_ports = this->num_ports();
291 for (uint32_t i = 0; i < num_ports; ++i) {
292 const LilvPort* port = lilv_plugin_get_port_by_index(_impl->plugin, i);
295 if (lilv_port_is_a(_impl->plugin, port, _world.lv2_OutputPort)) {
296 flags |= PORT_OUTPUT;
297 } else if (lilv_port_is_a(_impl->plugin, port, _world.lv2_InputPort)) {
300 error << string_compose(
301 "LV2: \"%1\" port %2 is neither input nor output",
302 lilv_node_as_string(_impl->name), i) << endmsg;
303 throw failed_constructor();
306 if (lilv_port_is_a(_impl->plugin, port, _world.lv2_ControlPort)) {
307 flags |= PORT_CONTROL;
308 } else if (lilv_port_is_a(_impl->plugin, port, _world.lv2_AudioPort)) {
310 } else if (lilv_port_is_a(_impl->plugin, port, _world.ev_EventPort)) {
312 } else if (lilv_port_is_a(_impl->plugin, port, _world.atom_AtomPort)) {
313 LilvNodes* buffer_types = lilv_port_get_value(
314 _impl->plugin, port, _world.atom_bufferType);
315 if (lilv_nodes_contains(buffer_types, _world.atom_Sequence)) {
316 flags |= PORT_MESSAGE;
318 lilv_nodes_free(buffer_types);
320 error << string_compose(
321 "LV2: \"%1\" port %2 has no known data type",
322 lilv_node_as_string(_impl->name), i) << endmsg;
323 throw failed_constructor();
326 _port_flags.push_back(flags);
329 _control_data = new float[num_ports];
330 _shadow_data = new float[num_ports];
331 _defaults = new float[num_ports];
332 _ev_buffers = new LV2_Evbuf*[num_ports];
333 memset(_ev_buffers, 0, sizeof(LV2_Evbuf*) * num_ports);
335 const bool latent = lilv_plugin_has_latency(plugin);
336 const uint32_t latency_index = (latent)
337 ? lilv_plugin_get_latency_port_index(plugin)
340 // Build an array of pointers to special parameter buffers
341 void*** params = new void**[num_ports];
342 for (uint32_t i = 0; i < num_ports; ++i) {
345 _impl->designated_input (LV2_TIME__beatsPerMinute, params, (void**)&_bpm_control_port);
346 _impl->designated_input (LV2_CORE__freeWheeling, params, (void**)&_freewheel_control_port);
348 for (uint32_t i = 0; i < num_ports; ++i) {
349 const LilvPort* port = lilv_plugin_get_port_by_index(plugin, i);
350 const LilvNode* sym = lilv_port_get_symbol(plugin, port);
352 // Store index in map so we can look up index by symbol
353 _port_indices.insert(std::make_pair(lilv_node_as_string(sym), i));
355 // Get range and default value if applicable
356 if (parameter_is_control(i)) {
358 lilv_port_get_range(plugin, port, &def, NULL, NULL);
359 _defaults[i] = def ? lilv_node_as_float(def) : 0.0f;
360 if (lilv_port_has_property (plugin, port, _world.lv2_sampleRate)) {
361 _defaults[i] *= _session.frame_rate ();
365 lilv_instance_connect_port(_impl->instance, i, &_control_data[i]);
367 if (latent && i == latency_index) {
368 _latency_control_port = &_control_data[i];
369 *_latency_control_port = 0;
372 if (parameter_is_input(i)) {
373 _shadow_data[i] = default_value(i);
375 *params[i] = (void*)&_shadow_data[i];
385 LilvUIs* uis = lilv_plugin_get_uis(plugin);
386 if (lilv_uis_size(uis) > 0) {
388 // Look for embeddable UI
389 LILV_FOREACH(uis, u, uis) {
390 const LilvUI* this_ui = lilv_uis_get(uis, u);
391 const LilvNode* this_ui_type = NULL;
392 if (lilv_ui_is_supported(this_ui,
396 // TODO: Multiple UI support
398 _impl->ui_type = this_ui_type;
403 // Look for Gtk native UI
404 LILV_FOREACH(uis, i, uis) {
405 const LilvUI* ui = lilv_uis_get(uis, i);
406 if (lilv_ui_is_a(ui, _world.ui_GtkUI)) {
408 _impl->ui_type = _world.ui_GtkUI;
414 // If Gtk UI is not available, try to find external UI
416 LILV_FOREACH(uis, i, uis) {
417 const LilvUI* ui = lilv_uis_get(uis, i);
418 if (lilv_ui_is_a(ui, _world.ui_external)) {
420 _impl->ui_type = _world.ui_external;
427 latency_compute_run();
430 LV2Plugin::~LV2Plugin ()
432 DEBUG_TRACE(DEBUG::LV2, string_compose("%1 destroy\n", name()));
437 lilv_instance_free(_impl->instance);
438 lilv_node_free(_impl->name);
439 lilv_node_free(_impl->author);
442 free(_make_path_feature.data);
443 free(_work_schedule_feature.data);
448 delete [] _control_data;
449 delete [] _shadow_data;
450 delete [] _ev_buffers;
454 LV2Plugin::is_external_ui() const
459 return lilv_ui_is_a(_impl->ui, _world.ui_external);
463 LV2Plugin::ui_is_resizable () const
465 const LilvNode* s = lilv_ui_get_uri(_impl->ui);
466 LilvNode* p = lilv_new_uri(_world.world, LV2_CORE__optionalFeature);
467 LilvNode* fs = lilv_new_uri(_world.world, LV2_UI__fixedSize);
468 LilvNode* nrs = lilv_new_uri(_world.world, LV2_UI__noUserResize);
470 LilvNodes* fs_matches = lilv_world_find_nodes(_world.world, s, p, fs);
471 LilvNodes* nrs_matches = lilv_world_find_nodes(_world.world, s, p, nrs);
473 lilv_nodes_free(nrs_matches);
474 lilv_nodes_free(fs_matches);
479 return !fs_matches && !nrs_matches;
483 LV2Plugin::unique_id() const
485 return lilv_node_as_uri(lilv_plugin_get_uri(_impl->plugin));
489 LV2Plugin::uri() const
491 return lilv_node_as_uri(lilv_plugin_get_uri(_impl->plugin));
495 LV2Plugin::label() const
497 return lilv_node_as_string(_impl->name);
501 LV2Plugin::name() const
503 return lilv_node_as_string(_impl->name);
507 LV2Plugin::maker() const
509 return _impl->author ? lilv_node_as_string (_impl->author) : "Unknown";
513 LV2Plugin::num_ports() const
515 return lilv_plugin_get_num_ports(_impl->plugin);
519 LV2Plugin::parameter_count() const
521 return lilv_plugin_get_num_ports(_impl->plugin);
525 LV2Plugin::default_value(uint32_t port)
527 return _defaults[port];
531 LV2Plugin::port_symbol(uint32_t index) const
533 const LilvPort* port = lilv_plugin_get_port_by_index(_impl->plugin, index);
535 error << name() << ": Invalid port index " << index << endmsg;
538 const LilvNode* sym = lilv_port_get_symbol(_impl->plugin, port);
539 return lilv_node_as_string(sym);
543 LV2Plugin::port_index (const char* symbol) const
545 const map<string, uint32_t>::const_iterator i = _port_indices.find(symbol);
546 if (i != _port_indices.end()) {
549 warning << string_compose(_("LV2: Unknown port %1"), symbol) << endmsg;
555 LV2Plugin::set_parameter(uint32_t which, float val)
557 DEBUG_TRACE(DEBUG::LV2, string_compose(
558 "%1 set parameter %2 to %3\n", name(), which, val));
560 if (which < lilv_plugin_get_num_ports(_impl->plugin)) {
561 _shadow_data[which] = val;
563 warning << string_compose(
564 _("Illegal parameter number used with plugin \"%1\". "
565 "This is a bug in either %2 or the LV2 plugin <%3>"),
566 name(), PROGRAM_NAME, unique_id()) << endmsg;
569 Plugin::set_parameter(which, val);
573 LV2Plugin::get_parameter(uint32_t which) const
575 if (parameter_is_input(which)) {
576 return (float)_shadow_data[which];
578 return (float)_control_data[which];
584 LV2Plugin::get_docs() const
586 LilvNodes* comments = lilv_plugin_get_value(_impl->plugin, _world.rdfs_comment);
588 const std::string docs(lilv_node_as_string(lilv_nodes_get_first(comments)));
589 lilv_nodes_free(comments);
597 LV2Plugin::get_parameter_docs(uint32_t which) const
599 LilvNodes* comments = lilv_port_get_value(
601 lilv_plugin_get_port_by_index(_impl->plugin, which),
602 _world.rdfs_comment);
605 const std::string docs(lilv_node_as_string(lilv_nodes_get_first(comments)));
606 lilv_nodes_free(comments);
614 LV2Plugin::nth_parameter(uint32_t n, bool& ok) const
617 for (uint32_t c = 0, x = 0; x < lilv_plugin_get_num_ports(_impl->plugin); ++x) {
618 if (parameter_is_control(x)) {
630 LV2Plugin::extension_data (const char* uri) const
632 return lilv_instance_get_extension_data(_impl->instance, uri);
636 LV2Plugin::c_plugin ()
638 return _impl->plugin;
644 return (void*)_impl->ui;
648 LV2Plugin::c_ui_type ()
650 return (void*)_impl->ui_type;
653 /** Directory for all plugin state. */
655 LV2Plugin::plugin_dir() const
657 return Glib::build_filename(_session.plugins_dir(), _insert_id.to_s());
660 /** Directory for files created by the plugin (except during save). */
662 LV2Plugin::scratch_dir() const
664 return Glib::build_filename(plugin_dir(), "scratch");
667 /** Directory for snapshots of files in the scratch directory. */
669 LV2Plugin::file_dir() const
671 return Glib::build_filename(plugin_dir(), "files");
674 /** Directory to save state snapshot version @c num into. */
676 LV2Plugin::state_dir(unsigned num) const
678 return Glib::build_filename(plugin_dir(), string_compose("state%1", num));
681 /** Implementation of state:makePath for files created at instantiation time.
682 * Note this is not used for files created at save time (Lilv deals with that).
685 LV2Plugin::lv2_state_make_path(LV2_State_Make_Path_Handle handle,
688 LV2Plugin* me = (LV2Plugin*)handle;
689 if (me->_insert_id == PBD::ID("0")) {
690 warning << string_compose(
691 "File path \"%1\" requested but LV2 %2 has no insert ID",
692 path, me->name()) << endmsg;
693 return g_strdup(path);
696 const std::string abs_path = Glib::build_filename(me->scratch_dir(), path);
697 const std::string dirname = Glib::path_get_dirname(abs_path);
698 g_mkdir_with_parents(dirname.c_str(), 0744);
700 DEBUG_TRACE(DEBUG::LV2, string_compose("new file path %1 => %2\n",
703 std::cerr << "MAKE PATH " << path
704 << " => " << g_strndup(abs_path.c_str(), abs_path.length())
706 return g_strndup(abs_path.c_str(), abs_path.length());
710 remove_directory(const std::string& path)
712 if (!Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) {
713 warning << string_compose("\"%1\" is not a directory", path) << endmsg;
717 Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path(path);
718 Glib::RefPtr<Gio::FileEnumerator> e = dir->enumerate_children();
719 Glib::RefPtr<Gio::FileInfo> fi;
720 while ((fi = e->next_file())) {
721 if (fi->get_type() == Gio::FILE_TYPE_DIRECTORY) {
722 remove_directory(fi->get_name());
724 dir->get_child(fi->get_name())->remove();
731 LV2Plugin::add_state(XMLNode* root) const
733 assert(_insert_id != PBD::ID("0"));
737 LocaleGuard lg(X_("POSIX"));
739 for (uint32_t i = 0; i < parameter_count(); ++i) {
740 if (parameter_is_input(i) && parameter_is_control(i)) {
741 child = new XMLNode("Port");
742 child->add_property("symbol", port_symbol(i));
743 snprintf(buf, sizeof(buf), "%+f", _shadow_data[i]);
744 child->add_property("value", string(buf));
745 root->add_child_nocopy(*child);
749 if (_has_state_interface) {
750 cout << "LV2 " << name() << " has state interface" << endl;
751 // Provisionally increment state version and create directory
752 const std::string new_dir = state_dir(++_state_version);
753 g_mkdir_with_parents(new_dir.c_str(), 0744);
755 cout << "NEW DIR: " << new_dir << endl;
757 LilvState* state = lilv_state_new_from_instance(
761 scratch_dir().c_str(),
763 _session.externals_dir().c_str(),
770 if (!_impl->state || !lilv_state_equals(state, _impl->state)) {
771 lilv_state_save(_world.world,
773 _uri_map.urid_unmap(),
779 lilv_state_free(_impl->state);
780 _impl->state = state;
782 cout << "Saved LV2 state to " << state_dir(_state_version) << endl;
784 // State is identical, decrement version and nuke directory
785 cout << "LV2 state identical, not saving" << endl;
786 lilv_state_free(state);
787 remove_directory(new_dir);
791 root->add_property("state-dir", string_compose("state%1", _state_version));
793 cout << "LV2 " << name() << " has no state interface." << endl;
797 static inline const LilvNode*
798 get_value(LilvWorld* world, const LilvNode* subject, const LilvNode* predicate)
800 LilvNodes* vs = lilv_world_find_nodes(world, subject, predicate, NULL);
801 return vs ? lilv_nodes_get_first(vs) : NULL;
805 LV2Plugin::find_presets()
807 LilvNode* lv2_appliesTo = lilv_new_uri(_world.world, LV2_CORE__appliesTo);
808 LilvNode* pset_Preset = lilv_new_uri(_world.world, LV2_PRESETS__Preset);
809 LilvNode* rdfs_label = lilv_new_uri(_world.world, LILV_NS_RDFS "label");
811 LilvNodes* presets = lilv_plugin_get_related(_impl->plugin, pset_Preset);
812 LILV_FOREACH(nodes, i, presets) {
813 const LilvNode* preset = lilv_nodes_get(presets, i);
814 lilv_world_load_resource(_world.world, preset);
815 const LilvNode* name = get_value(_world.world, preset, rdfs_label);
817 _presets.insert(std::make_pair(lilv_node_as_string(preset),
818 Plugin::PresetRecord(
819 lilv_node_as_string(preset),
820 lilv_node_as_string(name))));
822 warning << string_compose(
823 _("Plugin \"%1\% preset \"%2%\" is missing a label\n"),
824 lilv_node_as_string(lilv_plugin_get_uri(_impl->plugin)),
825 lilv_node_as_string(preset)) << endmsg;
828 lilv_nodes_free(presets);
830 lilv_node_free(rdfs_label);
831 lilv_node_free(pset_Preset);
832 lilv_node_free(lv2_appliesTo);
836 LV2Plugin::load_preset(PresetRecord r)
839 std::map<std::string,uint32_t>::iterator it;
841 LilvNode* lv2_port = lilv_new_uri(_world.world, LILV_NS_LV2 "port");
842 LilvNode* lv2_symbol = lilv_new_uri(_world.world, LILV_NS_LV2 "symbol");
843 LilvNode* preset = lilv_new_uri(_world.world, r.uri.c_str());
844 LilvNode* pset_value = lilv_new_uri(_world.world, LV2_PRESETS__value);
846 LilvNodes* ports = lilv_world_find_nodes(_world.world, preset, lv2_port, NULL);
847 LILV_FOREACH(nodes, i, ports) {
848 const LilvNode* port = lilv_nodes_get(ports, i);
849 const LilvNode* symbol = get_value(_world.world, port, lv2_symbol);
850 const LilvNode* value = get_value(_world.world, port, pset_value);
851 if (value && lilv_node_is_float(value)) {
852 it = _port_indices.find(lilv_node_as_string(symbol));
853 if (it != _port_indices.end())
854 set_parameter(it->second,lilv_node_as_float(value));
857 lilv_nodes_free(ports);
859 lilv_node_free(pset_value);
860 lilv_node_free(preset);
861 lilv_node_free(lv2_symbol);
862 lilv_node_free(lv2_port);
864 Plugin::load_preset(r);
870 ARDOUR::lv2plugin_get_port_value(const char* port_symbol,
875 // cerr << "get_port_value(" << port_symbol << ", ...) ... ";
876 LV2Plugin *plugin = (LV2Plugin *) user_data;
878 uint32_t index = plugin->port_index(port_symbol);
879 if (index != (uint32_t) -1) {
880 if (plugin->parameter_is_input(index) && plugin->parameter_is_control(index)) {
882 *size = sizeof(float);
883 *type = plugin->_uri_map.uri_to_id(LV2_ATOM__Float);
884 value = &plugin->_shadow_data[index];
885 // cerr << "index="<< index << ",*size=" << *size << ",*type=" << *type << ",*value=" << *value << endl;
889 // cerr << "port is not input control port! ";
892 // cerr << "returning NULL!" << endl;
899 LV2Plugin::do_save_preset(string name)
901 // cerr << "LV2Plugin::do_save_preset(" << name << ")" << endl;
903 string pset_uri = uri();
907 string save_dir = Glib::build_filename(
908 Glib::get_home_dir(),
909 Glib::build_filename(".lv2", "presets")
912 LilvState* state = lilv_state_new_from_instance(
916 scratch_dir().c_str(), // file_dir
919 save_dir.c_str(), // save_dir
920 lv2plugin_get_port_value, // get_value
921 (void*) this, // user_data
922 LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE, // flags
923 _features // features
926 lilv_state_set_label(state, name.c_str());
928 _world.world, // world
929 _uri_map.urid_map(), // map
930 _uri_map.urid_unmap(), // unmap
932 pset_uri.c_str(), // uri
933 save_dir.c_str(), // dir
934 (name + ".ttl").c_str() // filename
938 lilv_state_free(state);
943 LV2Plugin::do_remove_preset(string name)
945 string preset_file = Glib::build_filename(
946 Glib::get_home_dir(),
947 Glib::build_filename(
948 Glib::build_filename(".lv2", "presets"),
952 unlink(preset_file.c_str());
957 LV2Plugin::has_editor() const
959 return _impl->ui != NULL;
963 LV2Plugin::has_message_output() const
965 for (uint32_t i = 0; i < num_ports(); ++i) {
966 if ((_port_flags[i] & PORT_MESSAGE) && _port_flags[i] & PORT_OUTPUT) {
974 LV2Plugin::atom_eventTransfer() const
976 return _event_transfer_type;
980 LV2Plugin::write_to(RingBuffer<uint8_t>* dest,
986 const uint32_t buf_size = sizeof(UIMessage) + size;
987 uint8_t buf[buf_size];
989 UIMessage* msg = (UIMessage*)buf;
991 msg->protocol = protocol;
993 memcpy(msg + 1, body, size);
995 if (dest->write(buf, buf_size) != buf_size) {
996 error << "Error writing to UI=>Plugin RingBuffer" << endmsg;
1001 LV2Plugin::write_from_ui(uint32_t index,
1007 _from_ui = new RingBuffer<uint8_t>(4096);
1010 write_to(_from_ui, index, protocol, size, body);
1014 LV2Plugin::write_to_ui(uint32_t index,
1019 std::cerr << "WRITE TO UI" << std::endl;
1020 write_to(_to_ui, index, protocol, size, body);
1024 LV2Plugin::enable_ui_emmission()
1027 _to_ui = new RingBuffer<uint8_t>(4096);
1032 LV2Plugin::emit_to_ui(void* controller, UIMessageSink sink)
1038 uint32_t read_space = _to_ui->read_space();
1039 while (read_space > sizeof(UIMessage)) {
1041 if (_to_ui->read((uint8_t*)&msg, sizeof(msg)) != sizeof(msg)) {
1042 error << "Error reading from Plugin=>UI RingBuffer" << endmsg;
1045 uint8_t body[msg.size];
1046 if (_to_ui->read(body, msg.size) != msg.size) {
1047 error << "Error reading from Plugin=>UI RingBuffer" << endmsg;
1051 sink(controller, msg.index, msg.size, msg.protocol, body);
1053 read_space -= sizeof(msg) + msg.size;
1058 LV2Plugin::work(uint32_t size, const void* data)
1060 return _impl->work_iface->work(
1061 _impl->instance->lv2_handle, work_respond, this, size, data);
1065 LV2Plugin::work_response(uint32_t size, const void* data)
1067 return _impl->work_iface->work_response(
1068 _impl->instance->lv2_handle, size, data);
1072 LV2Plugin::set_insert_info(const PluginInsert* insert)
1074 _insert_id = insert->id();
1078 LV2Plugin::set_state(const XMLNode& node, int version)
1081 const XMLProperty* prop;
1082 XMLNodeConstIterator iter;
1087 LocaleGuard lg(X_("POSIX"));
1089 if (node.name() != state_node_name()) {
1090 error << _("Bad node sent to LV2Plugin::set_state") << endmsg;
1094 if (version < 3000) {
1095 nodes = node.children("port");
1097 nodes = node.children("Port");
1100 for (iter = nodes.begin(); iter != nodes.end(); ++iter) {
1104 if ((prop = child->property("symbol")) != 0) {
1105 sym = prop->value().c_str();
1107 warning << _("LV2: port has no symbol, ignored") << endmsg;
1111 map<string, uint32_t>::iterator i = _port_indices.find(sym);
1113 if (i != _port_indices.end()) {
1114 port_id = i->second;
1116 warning << _("LV2: port has unknown index, ignored") << endmsg;
1120 if ((prop = child->property("value")) != 0) {
1121 value = prop->value().c_str();
1123 warning << _("LV2: port has no value, ignored") << endmsg;
1127 set_parameter(port_id, atof(value));
1131 if ((prop = node.property("state-dir")) != 0) {
1132 if (sscanf(prop->value().c_str(), "state%u", &_state_version) != 1) {
1133 error << string_compose(
1134 "LV2: failed to parse state version from \"%1\"",
1135 prop->value()) << endmsg;
1138 std::string state_file = Glib::build_filename(
1140 Glib::build_filename(prop->value(), "state.ttl"));
1142 cout << "Loading LV2 state from " << state_file << endl;
1143 LilvState* state = lilv_state_new_from_file(
1144 _world.world, _uri_map.urid_map(), NULL, state_file.c_str());
1146 lilv_state_restore(state, _impl->instance, NULL, NULL, 0, NULL);
1149 latency_compute_run();
1151 return Plugin::set_state(node, version);
1155 LV2Plugin::get_parameter_descriptor(uint32_t which, ParameterDescriptor& desc) const
1157 const LilvPort* port = lilv_plugin_get_port_by_index(_impl->plugin, which);
1159 LilvNode *def, *min, *max;
1160 lilv_port_get_range(_impl->plugin, port, &def, &min, &max);
1162 desc.integer_step = lilv_port_has_property(_impl->plugin, port, _world.lv2_integer);
1163 desc.toggled = lilv_port_has_property(_impl->plugin, port, _world.lv2_toggled);
1164 desc.logarithmic = lilv_port_has_property(_impl->plugin, port, _world.ext_logarithmic);
1165 desc.sr_dependent = lilv_port_has_property(_impl->plugin, port, _world.lv2_sampleRate);
1166 desc.label = lilv_node_as_string(lilv_port_get_name(_impl->plugin, port));
1167 desc.lower = min ? lilv_node_as_float(min) : 0.0f;
1168 desc.upper = max ? lilv_node_as_float(max) : 1.0f;
1169 if (desc.sr_dependent) {
1170 desc.lower *= _session.frame_rate ();
1171 desc.upper *= _session.frame_rate ();
1174 desc.min_unbound = false; // TODO: LV2 extension required
1175 desc.max_unbound = false; // TODO: LV2 extension required
1177 if (desc.integer_step) {
1179 desc.smallstep = 0.1;
1180 desc.largestep = 10.0;
1182 const float delta = desc.upper - desc.lower;
1183 desc.step = delta / 1000.0f;
1184 desc.smallstep = delta / 10000.0f;
1185 desc.largestep = delta / 10.0f;
1188 desc.enumeration = lilv_port_has_property(_impl->plugin, port, _world.lv2_enumeration);
1190 lilv_node_free(def);
1191 lilv_node_free(min);
1192 lilv_node_free(max);
1198 LV2Plugin::describe_parameter(Evoral::Parameter which)
1200 if (( which.type() == PluginAutomation) && ( which.id() < parameter_count()) ) {
1201 LilvNode* name = lilv_port_get_name(_impl->plugin,
1202 lilv_plugin_get_port_by_index(_impl->plugin, which.id()));
1203 string ret(lilv_node_as_string(name));
1204 lilv_node_free(name);
1212 LV2Plugin::signal_latency() const
1214 if (_latency_control_port) {
1215 return (framecnt_t)floor(*_latency_control_port);
1221 set<Evoral::Parameter>
1222 LV2Plugin::automatable() const
1224 set<Evoral::Parameter> ret;
1226 for (uint32_t i = 0; i < parameter_count(); ++i) {
1227 if (parameter_is_input(i) && parameter_is_control(i)) {
1228 ret.insert(ret.end(), Evoral::Parameter(PluginAutomation, 0, i));
1236 LV2Plugin::activate()
1238 DEBUG_TRACE(DEBUG::LV2, string_compose("%1 activate\n", name()));
1240 if (!_was_activated) {
1241 lilv_instance_activate(_impl->instance);
1242 _was_activated = true;
1247 LV2Plugin::deactivate()
1249 DEBUG_TRACE(DEBUG::LV2, string_compose("%1 deactivate\n", name()));
1251 if (_was_activated) {
1252 lilv_instance_deactivate(_impl->instance);
1253 _was_activated = false;
1258 LV2Plugin::cleanup()
1260 DEBUG_TRACE(DEBUG::LV2, string_compose("%1 cleanup\n", name()));
1264 lilv_instance_free(_impl->instance);
1265 _impl->instance = NULL;
1269 LV2Plugin::connect_and_run(BufferSet& bufs,
1270 ChanMapping in_map, ChanMapping out_map,
1271 pframes_t nframes, framecnt_t offset)
1273 DEBUG_TRACE(DEBUG::LV2, string_compose("%1 run %2 offset %3\n", name(), nframes, offset));
1274 Plugin::connect_and_run(bufs, in_map, out_map, nframes, offset);
1276 cycles_t then = get_cycles();
1278 if (_freewheel_control_port) {
1279 *_freewheel_control_port = _session.engine().freewheeling ();
1282 if (_bpm_control_port) {
1283 TempoMap& tmap (_session.tempo_map ());
1284 Tempo tempo = tmap.tempo_at (_session.transport_frame () + offset);
1285 *_bpm_control_port = tempo.beats_per_minute ();
1288 ChanCount bufs_count;
1289 bufs_count.set(DataType::AUDIO, 1);
1290 bufs_count.set(DataType::MIDI, 1);
1291 BufferSet& silent_bufs = _session.get_silent_buffers(bufs_count);
1292 BufferSet& scratch_bufs = _session.get_silent_buffers(bufs_count);
1293 uint32_t const num_ports = parameter_count();
1295 uint32_t audio_in_index = 0;
1296 uint32_t audio_out_index = 0;
1297 uint32_t midi_in_index = 0;
1298 uint32_t midi_out_index = 0;
1300 for (uint32_t port_index = 0; port_index < num_ports; ++port_index) {
1303 PortFlags flags = _port_flags[port_index];
1304 if (flags & PORT_AUDIO) {
1305 if (flags & PORT_INPUT) {
1306 index = in_map.get(DataType::AUDIO, audio_in_index++, &valid);
1308 ? bufs.get_audio(index).data(offset)
1309 : silent_bufs.get_audio(0).data(offset);
1311 index = out_map.get(DataType::AUDIO, audio_out_index++, &valid);
1313 ? bufs.get_audio(index).data(offset)
1314 : scratch_bufs.get_audio(0).data(offset);
1316 } else if (flags & (PORT_EVENT|PORT_MESSAGE)) {
1317 /* FIXME: The checks here for bufs.count().n_midi() > index shouldn't
1318 be necessary, but the mapping is illegal in some cases. Ideally
1319 that should be fixed, but this is easier...
1321 if (flags & PORT_INPUT) {
1322 index = in_map.get(DataType::MIDI, midi_in_index++, &valid);
1323 _ev_buffers[port_index] = (valid && bufs.count().n_midi() > index)
1324 ? bufs.get_lv2_midi(true, index, flags & PORT_EVENT)
1325 : silent_bufs.get_lv2_midi(true, 0, flags & PORT_EVENT);
1326 buf = lv2_evbuf_get_buffer(_ev_buffers[port_index]);
1328 index = out_map.get(DataType::MIDI, midi_out_index++, &valid);
1329 _ev_buffers[port_index] = (valid && bufs.count().n_midi() > index)
1330 ? bufs.get_lv2_midi(false, index, flags & PORT_EVENT)
1331 : scratch_bufs.get_lv2_midi(false, 0, flags & PORT_EVENT);
1332 buf = lv2_evbuf_get_buffer(_ev_buffers[port_index]);
1335 continue; // Control port, leave buffer alone
1337 lilv_instance_connect_port(_impl->instance, port_index, buf);
1340 // Read messages from UI and push into appropriate buffers
1342 uint32_t read_space = _from_ui->read_space();
1343 while (read_space > sizeof(UIMessage)) {
1345 if (_from_ui->read((uint8_t*)&msg, sizeof(msg)) != sizeof(msg)) {
1346 error << "Error reading from UI=>Plugin RingBuffer" << endmsg;
1349 uint8_t body[msg.size];
1350 if (_from_ui->read(body, msg.size) != msg.size) {
1351 error << "Error reading from UI=>Plugin RingBuffer" << endmsg;
1354 if (msg.protocol == _event_transfer_type) {
1355 LV2_Evbuf* buf = _ev_buffers[msg.index];
1356 LV2_Evbuf_Iterator i = lv2_evbuf_end(buf);
1357 const LV2_Atom* const atom = (const LV2_Atom*)body;
1358 lv2_evbuf_write(&i, nframes, 0, atom->type, atom->size,
1359 (const uint8_t*)LV2_ATOM_BODY(atom));
1361 error << "Received unknown message type from UI" << endmsg;
1363 read_space -= sizeof(UIMessage) + msg.size;
1370 for (uint32_t port_index = 0; port_index < num_ports; ++port_index) {
1371 PortFlags flags = _port_flags[port_index];
1373 // Flush MIDI (write back to Ardour MIDI buffers)
1374 if ((flags & PORT_OUTPUT) && (flags & (PORT_EVENT|PORT_MESSAGE))) {
1375 const uint32_t buf_index = out_map.get(
1376 DataType::MIDI, midi_out_index++, &valid);
1378 bufs.flush_lv2_midi(true, buf_index);
1382 // Write messages to UI
1383 if (_to_ui && (flags & PORT_OUTPUT) && (flags & PORT_MESSAGE)) {
1384 LV2_Evbuf* buf = _ev_buffers[port_index];
1385 for (LV2_Evbuf_Iterator i = lv2_evbuf_begin(buf);
1386 lv2_evbuf_is_valid(i);
1387 i = lv2_evbuf_next(i)) {
1388 uint32_t frames, subframes, type, size;
1390 lv2_evbuf_get(i, &frames, &subframes, &type, &size, &data);
1391 write_to_ui(port_index, _event_transfer_type,
1392 size + sizeof(LV2_Atom),
1393 data - sizeof(LV2_Atom));
1398 cycles_t now = get_cycles();
1399 set_cycles((uint32_t)(now - then));
1405 LV2Plugin::parameter_is_control(uint32_t param) const
1407 assert(param < _port_flags.size());
1408 return _port_flags[param] & PORT_CONTROL;
1412 LV2Plugin::parameter_is_audio(uint32_t param) const
1414 assert(param < _port_flags.size());
1415 return _port_flags[param] & PORT_AUDIO;
1419 LV2Plugin::parameter_is_event(uint32_t param) const
1421 assert(param < _port_flags.size());
1422 return _port_flags[param] & PORT_EVENT;
1426 LV2Plugin::parameter_is_output(uint32_t param) const
1428 assert(param < _port_flags.size());
1429 return _port_flags[param] & PORT_OUTPUT;
1433 LV2Plugin::parameter_is_input(uint32_t param) const
1435 assert(param < _port_flags.size());
1436 return _port_flags[param] & PORT_INPUT;
1440 LV2Plugin::print_parameter(uint32_t param, char* buf, uint32_t len) const
1443 if (param < parameter_count()) {
1444 snprintf(buf, len, "%.3f", get_parameter(param));
1451 boost::shared_ptr<Plugin::ScalePoints>
1452 LV2Plugin::get_scale_points(uint32_t port_index) const
1454 const LilvPort* port = lilv_plugin_get_port_by_index(_impl->plugin, port_index);
1455 LilvScalePoints* points = lilv_port_get_scale_points(_impl->plugin, port);
1457 boost::shared_ptr<Plugin::ScalePoints> ret;
1462 ret = boost::shared_ptr<Plugin::ScalePoints>(new ScalePoints());
1464 LILV_FOREACH(scale_points, i, points) {
1465 const LilvScalePoint* p = lilv_scale_points_get(points, i);
1466 const LilvNode* label = lilv_scale_point_get_label(p);
1467 const LilvNode* value = lilv_scale_point_get_value(p);
1468 if (label && (lilv_node_is_float(value) || lilv_node_is_int(value))) {
1469 ret->insert(make_pair(lilv_node_as_string(label),
1470 lilv_node_as_float(value)));
1474 lilv_scale_points_free(points);
1479 LV2Plugin::run(pframes_t nframes)
1481 uint32_t const N = parameter_count();
1482 for (uint32_t i = 0; i < N; ++i) {
1483 if (parameter_is_control(i) && parameter_is_input(i)) {
1484 _control_data[i] = _shadow_data[i];
1488 lilv_instance_run(_impl->instance, nframes);
1490 if (_impl->work_iface) {
1491 _worker->emit_responses();
1492 if (_impl->work_iface->end_run) {
1493 _impl->work_iface->end_run(_impl->instance->lv2_handle);
1499 LV2Plugin::latency_compute_run()
1501 if (!_latency_control_port) {
1505 // Run the plugin so that it can set its latency parameter
1509 uint32_t port_index = 0;
1510 uint32_t in_index = 0;
1511 uint32_t out_index = 0;
1513 const framecnt_t bufsize = 1024;
1514 float buffer[bufsize];
1516 memset(buffer, 0, sizeof(float) * bufsize);
1518 // FIXME: Ensure plugins can handle in-place processing
1522 while (port_index < parameter_count()) {
1523 if (parameter_is_audio(port_index)) {
1524 if (parameter_is_input(port_index)) {
1525 lilv_instance_connect_port(_impl->instance, port_index, buffer);
1527 } else if (parameter_is_output(port_index)) {
1528 lilv_instance_connect_port(_impl->instance, port_index, buffer);
1540 LV2Plugin::Impl::designated_input (const char* uri, void** bufptrs[], void** bufptr)
1542 LilvPort* port = NULL;
1543 LilvNode* designation = lilv_new_uri(_world.world, uri);
1544 port = lilv_plugin_get_port_by_designation(
1545 plugin, _world.lv2_InputPort, designation);
1546 lilv_node_free(designation);
1548 bufptrs[lilv_port_get_index(plugin, port)] = bufptr;
1553 LV2World::LV2World()
1554 : world(lilv_world_new())
1556 lilv_world_load_all(world);
1557 atom_AtomPort = lilv_new_uri(world, LV2_ATOM__AtomPort);
1558 atom_Chunk = lilv_new_uri(world, LV2_ATOM__Chunk);
1559 atom_Sequence = lilv_new_uri(world, LV2_ATOM__Sequence);
1560 atom_bufferType = lilv_new_uri(world, LV2_ATOM__bufferType);
1561 atom_eventTransfer = lilv_new_uri(world, LV2_ATOM__eventTransfer);
1562 ev_EventPort = lilv_new_uri(world, LILV_URI_EVENT_PORT);
1563 ext_logarithmic = lilv_new_uri(world, LV2_PORT_PROPS__logarithmic);
1564 lv2_AudioPort = lilv_new_uri(world, LILV_URI_AUDIO_PORT);
1565 lv2_ControlPort = lilv_new_uri(world, LILV_URI_CONTROL_PORT);
1566 lv2_InputPort = lilv_new_uri(world, LILV_URI_INPUT_PORT);
1567 lv2_OutputPort = lilv_new_uri(world, LILV_URI_OUTPUT_PORT);
1568 lv2_inPlaceBroken = lilv_new_uri(world, LV2_CORE__inPlaceBroken);
1569 lv2_integer = lilv_new_uri(world, LV2_CORE__integer);
1570 lv2_sampleRate = lilv_new_uri(world, LV2_CORE__sampleRate);
1571 lv2_toggled = lilv_new_uri(world, LV2_CORE__toggled);
1572 lv2_enumeration = lilv_new_uri(world, LV2_CORE__enumeration);
1573 midi_MidiEvent = lilv_new_uri(world, LILV_URI_MIDI_EVENT);
1574 rdfs_comment = lilv_new_uri(world, LILV_NS_RDFS "comment");
1575 ui_GtkUI = lilv_new_uri(world, LV2_UI__GtkUI);
1576 ui_external = lilv_new_uri(world, "http://lv2plug.in/ns/extensions/ui#external");
1579 LV2World::~LV2World()
1581 lilv_node_free(ui_external);
1582 lilv_node_free(ui_GtkUI);
1583 lilv_node_free(midi_MidiEvent);
1584 lilv_node_free(lv2_toggled);
1585 lilv_node_free(lv2_sampleRate);
1586 lilv_node_free(lv2_integer);
1587 lilv_node_free(lv2_inPlaceBroken);
1588 lilv_node_free(lv2_OutputPort);
1589 lilv_node_free(lv2_InputPort);
1590 lilv_node_free(lv2_ControlPort);
1591 lilv_node_free(lv2_AudioPort);
1592 lilv_node_free(ext_logarithmic);
1593 lilv_node_free(ev_EventPort);
1594 lilv_node_free(atom_eventTransfer);
1595 lilv_node_free(atom_bufferType);
1596 lilv_node_free(atom_Sequence);
1597 lilv_node_free(atom_Chunk);
1598 lilv_node_free(atom_AtomPort);
1601 LV2PluginInfo::LV2PluginInfo (void* c_plugin)
1602 : _c_plugin(c_plugin)
1607 LV2PluginInfo::~LV2PluginInfo()
1611 LV2PluginInfo::load(Session& session)
1616 plugin.reset(new LV2Plugin(session.engine(), session,
1617 (LilvPlugin*)_c_plugin,
1618 session.frame_rate()));
1620 plugin->set_info(PluginInfoPtr(new LV2PluginInfo(*this)));
1622 } catch (failed_constructor& err) {
1623 return PluginPtr((Plugin*)0);
1630 LV2PluginInfo::discover()
1632 PluginInfoList* plugs = new PluginInfoList;
1633 const LilvPlugins* plugins = lilv_world_get_all_plugins(_world.world);
1635 info << "LV2: Discovering " << lilv_plugins_size(plugins) << " plugins" << endmsg;
1637 LILV_FOREACH(plugins, i, plugins) {
1638 const LilvPlugin* p = lilv_plugins_get(plugins, i);
1639 LV2PluginInfoPtr info(new LV2PluginInfo((void*)p));
1641 LilvNode* name = lilv_plugin_get_name(p);
1643 cerr << "LV2: invalid plugin\n";
1649 info->name = string(lilv_node_as_string(name));
1650 lilv_node_free(name);
1652 const LilvPluginClass* pclass = lilv_plugin_get_class(p);
1653 const LilvNode* label = lilv_plugin_class_get_label(pclass);
1654 info->category = lilv_node_as_string(label);
1656 LilvNode* author_name = lilv_plugin_get_author_name(p);
1657 info->creator = author_name ? string(lilv_node_as_string(author_name)) : "Unknown";
1658 lilv_node_free(author_name);
1660 info->path = "/NOPATH"; // Meaningless for LV2
1662 info->n_inputs.set_audio(
1663 lilv_plugin_get_num_ports_of_class(
1664 p, _world.lv2_InputPort, _world.lv2_AudioPort, NULL));
1665 info->n_inputs.set_midi(
1666 lilv_plugin_get_num_ports_of_class(
1667 p, _world.lv2_InputPort, _world.ev_EventPort, NULL)
1668 + lilv_plugin_get_num_ports_of_class(
1669 p, _world.lv2_InputPort, _world.atom_AtomPort, NULL));
1671 info->n_outputs.set_audio(
1672 lilv_plugin_get_num_ports_of_class(
1673 p, _world.lv2_OutputPort, _world.lv2_AudioPort, NULL));
1674 info->n_outputs.set_midi(
1675 lilv_plugin_get_num_ports_of_class(
1676 p, _world.lv2_OutputPort, _world.ev_EventPort, NULL)
1677 + lilv_plugin_get_num_ports_of_class(
1678 p, _world.lv2_OutputPort, _world.atom_AtomPort, NULL));
1680 info->unique_id = lilv_node_as_uri(lilv_plugin_get_uri(p));
1681 info->index = 0; // Meaningless for LV2
1683 plugs->push_back(info);