5 * Copyright (C) 2018 GG
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "arraylist.h"
26 #include "pluginlv2config.h"
31 PluginLV2UriTable::PluginLV2UriTable()
36 PluginLV2UriTable::~PluginLV2UriTable()
41 LV2_URID PluginLV2UriTable::map(const char *uri)
43 mLock locker(uri_table_lock);
44 for( int i=0; i<size(); ++i )
45 if( !strcmp(uri, get(i)) ) return i+1;
50 const char *PluginLV2UriTable::unmap(LV2_URID urid)
52 mLock locker(uri_table_lock);
54 return idx>=0 && idx<size() ? get(idx) : 0;
57 PluginLV2Client_OptName:: PluginLV2Client_OptName(PluginLV2Client_Opt *opt)
60 set_text(opt->get_name());
63 PluginLV2Client_OptValue::PluginLV2Client_OptValue(PluginLV2Client_Opt *opt)
69 int PluginLV2Client_OptValue::update()
72 sprintf(val, "%f", opt->get_value());
73 if( !strcmp(val, get_text()) ) return 0;
79 PluginLV2Client_Opt::PluginLV2Client_Opt(PluginLV2ClientConfig *conf, int idx)
83 item_name = new PluginLV2Client_OptName(this);
84 item_value = new PluginLV2Client_OptValue(this);
87 PluginLV2Client_Opt::~PluginLV2Client_Opt()
93 float PluginLV2Client_Opt::get_value()
95 return conf->ctls[idx];
98 const char *PluginLV2Client_Opt::get_symbol()
100 return conf->syms[idx];
103 void PluginLV2Client_Opt::set_value(float v)
108 int PluginLV2Client_Opt::update(float v)
111 return item_value->update();
114 const char *PluginLV2Client_Opt::get_name()
116 return conf->names[idx];
119 PluginLV2ClientConfig::PluginLV2ClientConfig()
129 PluginLV2ClientConfig::~PluginLV2ClientConfig()
132 remove_all_objects();
135 void PluginLV2ClientConfig::reset()
137 for( int i=0; i<nb_ports; ++i ) {
141 delete [] names; names = 0;
142 delete [] mins; mins = 0;
143 delete [] maxs; maxs = 0;
144 delete [] ctls; ctls = 0;
149 int PluginLV2ClientConfig::equivalent(PluginLV2ClientConfig &that)
151 PluginLV2ClientConfig &conf = *this;
152 for( int i=0; i<that.size(); ++i ) {
153 PluginLV2Client_Opt *topt = conf[i], *vopt = that[i];
154 if( !EQUIV(topt->get_value(), vopt->get_value()) ) return 0;
159 void PluginLV2ClientConfig::copy_from(PluginLV2ClientConfig &that)
161 if( nb_ports != that.nb_ports ) {
163 nb_ports = that.nb_ports;
164 names = new const char *[nb_ports];
165 syms = new const char *[nb_ports];
166 for( int i=0; i<nb_ports; ++i ) names[i] = syms[i] = 0;
167 mins = new float[nb_ports];
168 maxs = new float[nb_ports];
169 ctls = new float[nb_ports];
171 for( int i=0; i<nb_ports; ++i ) {
172 delete [] names[i]; names[i] = cstrdup(that.names[i]);
173 delete [] syms[i]; syms[i] = cstrdup(that.syms[i]);
174 mins[i] = that.mins[i];
175 maxs[i] = that.maxs[i];
176 ctls[i] = that.ctls[i];
178 remove_all_objects();
179 for( int i=0; i<that.size(); ++i ) {
180 append(new PluginLV2Client_Opt(this, that[i]->idx));
184 void PluginLV2ClientConfig::interpolate(PluginLV2ClientConfig &prev, PluginLV2ClientConfig &next,
185 int64_t prev_frame, int64_t next_frame, int64_t current_frame)
190 void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv)
193 nb_ports = lilv_plugin_get_num_ports(lilv);
194 names = new const char *[nb_ports];
195 syms = new const char *[nb_ports];
196 mins = new float[nb_ports];
197 maxs = new float[nb_ports];
198 ctls = new float[nb_ports];
199 lilv_plugin_get_port_ranges_float(lilv, mins, maxs, ctls);
200 for( int i=0; i<nb_ports; ++i ) {
201 const LilvPort *lp = lilv_plugin_get_port_by_index(lilv, i);
202 LilvNode *pnm = lilv_port_get_name(lilv, lp);
203 names[i] = cstrdup(lilv_node_as_string(pnm));
205 const LilvNode *sym = lilv_port_get_symbol(lilv, lp);
206 syms[i] = cstrdup(lilv_node_as_string(sym));
210 int PluginLV2ClientConfig::update()
213 PluginLV2ClientConfig &conf = *this;
214 for( int i=0; i<size(); ++i ) {
215 if( conf[i]->item_value->update() ) ++ret;
220 void PluginLV2ClientConfig::dump(FILE *fp)
222 fprintf(fp, "Controls:\n");
223 for( int i=0; i<size(); ++i ) {
224 fprintf(fp, " %3d. (%3d) %-24s %f\n",
225 i, get(i)->idx, get(i)->get_symbol(), get(i)->get_value());
227 fprintf(fp, "Ports:\n");
228 for( int i=0; i<nb_ports; ++i ) {
229 fprintf(fp, " %3d. %-24s %f (%f - %f) %s\n",
230 i, syms[i], ctls[i], mins[i], maxs[i], names[i]);
234 #endif /* HAVE_LV2 */