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 "pluginlv2.h"
27 #include "pluginlv2config.h"
32 PluginLV2UriTable::PluginLV2UriTable()
33 : Mutex("PluginLV2UriTable::PluginLV2UriTable")
38 PluginLV2UriTable::~PluginLV2UriTable()
43 LV2_URID PluginLV2UriTable::map(const char *uri)
45 lock("PluginLV2UriTable::map");
46 int i = 0, n = size();
47 while( i<n && strcmp(uri, get(i)) ) ++i;
48 if( i >= n ) append(cstrdup(uri));
53 const char *PluginLV2UriTable::unmap(LV2_URID urid)
55 lock("PluginLV2UriTable::unmap");
57 const char *ret = idx>=0 && idx<size() ? get(idx) : 0;
62 PluginLV2Client_OptName:: PluginLV2Client_OptName(PluginLV2Client_Opt *opt)
65 set_text(opt->get_name());
68 PluginLV2Client_OptValue::PluginLV2Client_OptValue(PluginLV2Client_Opt *opt)
74 int PluginLV2Client_OptValue::update()
77 sprintf(val, "%f", opt->get_value());
78 if( !strcmp(val, get_text()) ) return 0;
84 PluginLV2Client_Opt::PluginLV2Client_Opt(PluginLV2ClientConfig *conf, int idx)
88 item_name = new PluginLV2Client_OptName(this);
89 item_value = new PluginLV2Client_OptValue(this);
92 PluginLV2Client_Opt::~PluginLV2Client_Opt()
98 float PluginLV2Client_Opt::get_value()
100 return conf->ctls[idx];
103 const char *PluginLV2Client_Opt::get_symbol()
105 return conf->syms[idx];
108 void PluginLV2Client_Opt::set_value(float v)
113 int PluginLV2Client_Opt::update(float v)
116 return item_value->update();
119 const char *PluginLV2Client_Opt::get_name()
121 return conf->names[idx];
124 PluginLV2ClientConfig::PluginLV2ClientConfig()
135 PluginLV2ClientConfig::~PluginLV2ClientConfig()
138 remove_all_objects();
141 void PluginLV2ClientConfig::reset()
143 for( int i=0; i<nb_ports; ++i ) {
147 delete [] names; names = 0;
148 delete [] mins; mins = 0;
149 delete [] maxs; maxs = 0;
150 delete [] ctls; ctls = 0;
151 delete [] ports; ports = 0;
156 int PluginLV2ClientConfig::equivalent(PluginLV2ClientConfig &that)
158 PluginLV2ClientConfig &conf = *this;
159 for( int i=0; i<that.size(); ++i ) {
160 PluginLV2Client_Opt *topt = conf[i], *vopt = that[i];
161 if( !EQUIV(topt->get_value(), vopt->get_value()) ) return 0;
166 void PluginLV2ClientConfig::copy_from(PluginLV2ClientConfig &that)
168 if( nb_ports != that.nb_ports ) {
170 nb_ports = that.nb_ports;
171 names = new const char *[nb_ports];
172 syms = new const char *[nb_ports];
173 for( int i=0; i<nb_ports; ++i ) names[i] = syms[i] = 0;
174 mins = new float[nb_ports];
175 maxs = new float[nb_ports];
176 ctls = new float[nb_ports];
177 ports = new int[nb_ports];
179 for( int i=0; i<nb_ports; ++i ) {
180 delete [] names[i]; names[i] = cstrdup(that.names[i]);
181 delete [] syms[i]; syms[i] = cstrdup(that.syms[i]);
182 mins[i] = that.mins[i];
183 maxs[i] = that.maxs[i];
184 ctls[i] = that.ctls[i];
187 remove_all_objects();
188 for( int i=0; i<that.size(); ++i ) {
189 append(new PluginLV2Client_Opt(this, that[i]->idx));
193 void PluginLV2ClientConfig::interpolate(PluginLV2ClientConfig &prev, PluginLV2ClientConfig &next,
194 int64_t prev_frame, int64_t next_frame, int64_t current_frame)
199 void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv, PluginLV2 *lv2)
202 nb_ports = lilv_plugin_get_num_ports(lilv);
203 names = new const char *[nb_ports];
204 syms = new const char *[nb_ports];
205 mins = new float[nb_ports];
206 maxs = new float[nb_ports];
207 ctls = new float[nb_ports];
208 ports = new int[nb_ports];
209 lilv_plugin_get_port_ranges_float(lilv, mins, maxs, ctls);
210 for( int i=0; i<nb_ports; ++i ) {
211 const LilvPort *lp = lilv_plugin_get_port_by_index(lilv, i);
212 LilvNode *pnm = lilv_port_get_name(lilv, lp);
213 names[i] = cstrdup(lilv_node_as_string(pnm));
215 const LilvNode *sym = lilv_port_get_symbol(lilv, lp);
216 syms[i] = cstrdup(lilv_node_as_string(sym));
218 if( lilv_port_is_a(lilv, lp, lv2->lv2_AudioPort) ) port |= PORTS_AUDIO;
219 if( lilv_port_is_a(lilv, lp, lv2->lv2_ControlPort) ) port |= PORTS_CONTROL;
220 if( lilv_port_is_a(lilv, lp, lv2->lv2_InputPort) ) port |= PORTS_INPUT;
221 if( lilv_port_is_a(lilv, lp, lv2->lv2_OutputPort) ) port |= PORTS_OUTPUT;
222 if( lilv_port_is_a(lilv, lp, lv2->atom_AtomPort) ) port |= PORTS_ATOM;
227 int PluginLV2ClientConfig::update()
230 PluginLV2ClientConfig &conf = *this;
231 for( int i=0; i<size(); ++i ) {
232 if( conf[i]->item_value->update() ) ++ret;
237 void PluginLV2ClientConfig::dump(FILE *fp)
239 fprintf(fp, "Controls:\n");
240 for( int i=0; i<size(); ++i ) {
241 fprintf(fp, " %3d. (%3d) %-24s %f\n",
242 i, get(i)->idx, get(i)->get_symbol(), get(i)->get_value());
244 fprintf(fp, "Ports:\n");
245 for( int i=0; i<nb_ports; ++i ) {
246 fprintf(fp, " %3d. %-24s %f (%f - %f) %s\n",
247 i, syms[i], ctls[i], mins[i], maxs[i], names[i]);
251 #endif /* HAVE_LV2 */