#ifdef HAVE_LV2 /* * CINELERRA * Copyright (C) 2018 GG * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "arraylist.h" #include "cstrdup.h" #include "language.h" #include "pluginlv2.h" #include "pluginlv2config.h" #include #include PluginLV2UriTable::PluginLV2UriTable() : Mutex("PluginLV2UriTable::PluginLV2UriTable") { set_array_delete(); } PluginLV2UriTable::~PluginLV2UriTable() { remove_all_objects(); } LV2_URID PluginLV2UriTable::map(const char *uri) { lock("PluginLV2UriTable::map"); int i = 0, n = size(); while( i= n ) append(cstrdup(uri)); unlock(); return i+1; } const char *PluginLV2UriTable::unmap(LV2_URID urid) { lock("PluginLV2UriTable::unmap"); int idx = urid - 1; const char *ret = idx>=0 && idxopt = opt; set_text(opt->get_name()); } PluginLV2Client_OptValue::PluginLV2Client_OptValue(PluginLV2Client_Opt *opt) { this->opt = opt; update(); } int PluginLV2Client_OptValue::update() { char val[BCSTRLEN]; sprintf(val, "%f", opt->get_value()); if( !strcmp(val, get_text()) ) return 0; set_text(val); return 1; } PluginLV2Client_Opt::PluginLV2Client_Opt(PluginLV2ClientConfig *conf, int idx) { this->conf = conf; this->idx = idx; item_name = new PluginLV2Client_OptName(this); item_value = new PluginLV2Client_OptValue(this); } PluginLV2Client_Opt::~PluginLV2Client_Opt() { delete item_name; delete item_value; } float PluginLV2Client_Opt::get_value() { return conf->ctls[idx]; } const char *PluginLV2Client_Opt::get_symbol() { return conf->syms[idx]; } void PluginLV2Client_Opt::set_value(float v) { conf->ctls[idx] = v; } int PluginLV2Client_Opt::update(float v) { set_value(v); return item_value->update(); } const char *PluginLV2Client_Opt::get_name() { return conf->names[idx]; } PluginLV2ClientConfig::PluginLV2ClientConfig() { names = 0; syms = 0; mins = 0; maxs = 0; ctls = 0; ports = 0; nb_ports = 0; } PluginLV2ClientConfig::~PluginLV2ClientConfig() { reset(); remove_all_objects(); } void PluginLV2ClientConfig::reset() { for( int i=0; iget_value(), vopt->get_value()) ) return 0; } return 1; } void PluginLV2ClientConfig::copy_from(PluginLV2ClientConfig &that) { if( nb_ports != that.nb_ports ) { reset(); nb_ports = that.nb_ports; names = new const char *[nb_ports]; syms = new const char *[nb_ports]; for( int i=0; iidx)); } } void PluginLV2ClientConfig::interpolate(PluginLV2ClientConfig &prev, PluginLV2ClientConfig &next, int64_t prev_frame, int64_t next_frame, int64_t current_frame) { copy_from(prev); } void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv, PluginLV2 *lv2) { reset(); nb_ports = lilv_plugin_get_num_ports(lilv); names = new const char *[nb_ports]; syms = new const char *[nb_ports]; mins = new float[nb_ports]; maxs = new float[nb_ports]; ctls = new float[nb_ports]; ports = new int[nb_ports]; lilv_plugin_get_port_ranges_float(lilv, mins, maxs, ctls); for( int i=0; ilv2_AudioPort) ) port |= PORTS_AUDIO; if( lilv_port_is_a(lilv, lp, lv2->lv2_ControlPort) ) port |= PORTS_CONTROL; if( lilv_port_is_a(lilv, lp, lv2->lv2_InputPort) ) port |= PORTS_INPUT; if( lilv_port_is_a(lilv, lp, lv2->lv2_OutputPort) ) port |= PORTS_OUTPUT; if( lilv_port_is_a(lilv, lp, lv2->atom_AtomPort) ) port |= PORTS_ATOM; ports[i] = port; } } int PluginLV2ClientConfig::update() { int ret = 0; PluginLV2ClientConfig &conf = *this; for( int i=0; iitem_value->update() ) ++ret; } return ret; } void PluginLV2ClientConfig::dump(FILE *fp) { fprintf(fp, "Controls:\n"); for( int i=0; iidx, get(i)->get_symbol(), get(i)->get_value()); } fprintf(fp, "Ports:\n"); for( int i=0; i