uint32 LV2Module::getNumPorts (PortType type, bool isInput) const { if (type == PortType::Unknown) return 0; const LilvNode* flow = isInput ? world.lv2_InputPort : world.lv2_OutputPort; const LilvNode* kind = type == PortType::Audio ? world.lv2_AudioPort : type == PortType::Atom ? world.lv2_AtomPort : type == PortType::Control ? world.lv2_ControlPort : type == PortType::CV ? world.lv2_CVPort : nullptr; if (kind == nullptr || flow == nullptr) return 0; return lilv_plugin_get_num_ports_of_class (plugin, kind, flow, nullptr); }
Lv2Plugin::Lv2Plugin(const LilvPlugin *plugin, LilvInstance *instance, const Lv2Constants &uris, Lv2Worker *worker) : plugin(plugin), instance(instance), midiOutputCount(0), controlConnections(4), newControlMappingsQueue(16), worker(worker) { // audio inputs audioInputCount = lilv_plugin_get_num_ports_of_class(plugin, uris.lv2AudioPort, uris.lv2InputPort, 0); audioInputIndex = new uint32_t[audioInputCount]; audioInput = new AudioConnector[audioInputCount]; // audio outputs audioOutputCount = lilv_plugin_get_num_ports_of_class(plugin, uris.lv2AudioPort, uris.lv2OutputPort, 0); audioOutputIndex = new uint32_t[audioOutputCount]; audioOutput = new AudioConnection*[audioOutputCount]; for(uint32_t i = 0; i < audioOutputCount; i++) { audioOutput[i] = new AudioConnection(this); audioOutput[i]->clear(); } // initialize port structures uint32_t numPorts = lilv_plugin_get_num_ports(plugin); uint32_t audioInputCounter = 0; uint32_t audioOutputCounter = 0; for(uint32_t i = 0; i < numPorts; i++) { const LilvPort *port = lilv_plugin_get_port_by_index(plugin, i); if(lilv_port_is_a(plugin, port, uris.lv2AudioPort)) { if(lilv_port_is_a(plugin, port, uris.lv2InputPort)) { audioInputIndex[audioInputCounter++] = i; } else if(lilv_port_is_a(plugin, port, uris.lv2OutputPort)) { audioOutputIndex[audioOutputCounter++] = i; } } else if(lilv_port_is_a(plugin, port, uris.lv2ControlPort) && lilv_port_is_a(plugin, port, uris.lv2InputPort)) { // get control name const LilvNode* symbol = lilv_port_get_symbol(plugin, port); std::string portName(lilv_node_as_string(symbol)); // create, connect and hash new control port object Lv2ControlPort *newPort = new Lv2ControlPort(); LilvNode *dfault, *minimum, *maximum; lilv_port_get_range(plugin, port, &dfault, &minimum, &maximum); newPort->dfault = dfault ? lilv_node_as_float(dfault) : 0; newPort->minimum = lilv_node_as_float(minimum); newPort->maximum = lilv_node_as_float(maximum); lilv_instance_connect_port(instance, i, &(newPort->value)); controlMap[portName] = newPort; } else if(lilv_port_is_a(plugin, port, uris.lv2AtomPort)) { // is it a MIDI/atom input? LilvNodes *atomBufferType = lilv_port_get_value(plugin, port, uris.lv2AtomBufferType); LilvNodes* atomSupports = lilv_port_get_value(plugin, port, uris.lv2AtomSupports); if (lilv_port_is_a(plugin, port, uris.lv2InputPort) && lilv_nodes_contains(atomBufferType, uris.lv2AtomSequence) && lilv_nodes_contains(atomSupports, uris.lv2MidiEvent)) { // create new inputs and connect to atom sequence location Lv2MidiInput *newAtomPort = new Lv2MidiInput(); lilv_instance_connect_port(instance, i, newAtomPort->getAtomSequence()); midiInputList.add(newAtomPort); } else if (lilv_port_is_a(plugin, port, uris.lv2OutputPort)) { //atomSequence->atom.type = Lv2PluginFactory::instance()->uridMapper.uriToId(LV2_ATOM__Sequence); Lv2MidiOutput *midiOutput = new Lv2MidiOutput(this); lilv_instance_connect_port(instance, i, midiOutput->getAtomSequence()); midiOutputList.add(midiOutput); midiOutputCount++; } else { // warn std::cout << "!!! unknown atom port at index " << i << ": " << lilv_node_as_string(lilv_port_get_name(plugin, port)) << std::endl; } lilv_nodes_free(atomSupports); lilv_nodes_free(atomBufferType); } else { lilv_instance_connect_port(instance, i, NULL); std::cout << "!!! unknown port at index " << i << ": " << lilv_node_as_string(lilv_port_get_name(plugin, port)) << std::endl; } } }