2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2003 Alexander König
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.
21 Description: This handles the effects in the per vtt fx chain. Supports the
22 buitlin echo/lowpass effects and ladspa plugins.
29 #define myvtt ((vtt_class *) vtt)
30 #include "tX_global.h"
32 float ladspa_dummy_output_port;
34 void vtt_fx :: reconnect_buffer()
39 vtt_fx :: ~vtt_fx() {}
40 void vtt_fx::toggle_drywet() {}
41 tX_drywet_type vtt_fx::has_drywet_feature() { return NOT_DRYWET_CAPABLE; }
43 /******************* builtin fx ***/
46 void vtt_fx_lp :: activate() { myvtt->lp_reset(); }
47 void vtt_fx_lp :: deactivate() { /* NOP */ }
48 void vtt_fx_lp :: run() { myvtt->render_lp(); }
49 int vtt_fx_lp :: isEnabled() { return myvtt->lp_enable; }
51 void vtt_fx_lp :: save (FILE *rc, gzFile rz, char *indent) {
52 tX_store("%s<cutoff/>\n", indent);
56 const char *vtt_fx_lp :: get_info_string()
58 return "TerminatorX built-in resonant lowpass filter.";
63 void vtt_fx_ec :: activate() { /* NOP */ }
64 void vtt_fx_ec :: deactivate() { myvtt->ec_clear_buffer(); }
65 void vtt_fx_ec :: run() { myvtt->render_ec(); }
66 int vtt_fx_ec :: isEnabled() { return myvtt->ec_enable; }
68 void vtt_fx_ec :: save (FILE *rc, gzFile rz, char *indent) {
69 tX_store("%s<lowpass/>\n", indent);
72 const char *vtt_fx_ec :: get_info_string()
74 return "TerminatorX built-in echo effect.";
77 /******************** LADSPA fx ***/
78 /* short cut "cpd" macro to current port descriptor */
80 #define cpd plugin->getDescriptor()->PortDescriptors[port]
81 #define cpn plugin->getDescriptor()->PortNames[port]
82 #define cph plugin->getDescriptor()->PortRangeHints[port]
84 void vtt_fx_ladspa :: reconnect_buffer()
86 plugin->getDescriptor()->connect_port(instance, input_port, myvtt->output_buffer);
88 plugin->getDescriptor()->connect_port(instance, output_port, wet_buffer);
90 plugin->getDescriptor()->connect_port(instance, output_port, myvtt->output_buffer);
94 static void wrapstr(char *str)
100 token=strtok(str, " ");
104 if (strlen(token)+strlen(temp)<10)
106 if (strlen(temp)) strcat(temp, " ");
113 if(strlen(target)) strcat(target, "\n");
121 strcat(target, temp);
125 token=strtok(NULL, " ");
130 if(strlen(target)) strcat(target, "\n");
131 strcat(target, temp);
137 vtt_fx_ladspa :: vtt_fx_ladspa(LADSPA_Plugin *p, void *v)
148 instance=(LADSPA_Handle *) plugin->getDescriptor()->instantiate(plugin->getDescriptor(), 44100);
152 fprintf (stderr, "tX: Fatal Error: failed to instantiate plugin \"%s\".\n", plugin->getDescriptor()->Name);
153 /* How to handle this ? */
156 sp = sp_enable = new tX_seqpar_vttfx_bool();
157 sp->set_mapping_parameters(1, 0, 0, 0);
158 sprintf(buffer, "%s: Enable", plugin->getName());
159 sp->set_name(buffer, "Enable");
161 controls.push_back(sp);
166 /* connecting ports */
167 for (port=0; port < plugin->getPortCount(); port++) {
168 if (LADSPA_IS_PORT_AUDIO(cpd)) {
169 if (LADSPA_IS_PORT_INPUT(cpd)) input_port=port;
170 else if (LADSPA_IS_PORT_OUTPUT(cpd)) output_port=port;
171 } else if ((LADSPA_IS_PORT_CONTROL(cpd)) && (LADSPA_IS_PORT_INPUT(cpd))) {
175 if (LADSPA_IS_HINT_BOUNDED_BELOW(cph.HintDescriptor)) min=cph.LowerBound;
176 if (LADSPA_IS_HINT_BOUNDED_ABOVE(cph.HintDescriptor)) max=cph.UpperBound;
178 if (LADSPA_IS_HINT_SAMPLE_RATE(cph.HintDescriptor)) {
179 min*=44100; max*=44100;
182 if (LADSPA_IS_HINT_TOGGLED(cph.HintDescriptor)) {
183 sp=new tX_seqpar_vttfx_bool();
184 sp->set_mapping_parameters(max, min, 0, 0);
185 } else if (LADSPA_IS_HINT_INTEGER(cph.HintDescriptor)) {
186 sp=new tX_seqpar_vttfx_int();
187 sp->set_mapping_parameters(max, min, 0, 0);
189 sp=new tX_seqpar_vttfx_float();
190 sp->set_mapping_parameters(max, min, (max-min)/100.0, 1);
193 sprintf(buffer, "%s: %s", plugin->getLabel(), cpn);
194 strcpy(buffer2, cpn);
197 sp->set_name(buffer, buffer2);
199 plugin->getDescriptor()->connect_port(instance, port, sp->get_value_ptr());
200 controls.push_back(sp);
201 } else if ((LADSPA_IS_PORT_CONTROL(cpd)) && (LADSPA_IS_PORT_OUTPUT(cpd))) {
202 plugin->getDescriptor()->connect_port(instance, port, &ladspa_dummy_output_port);
208 void vtt_fx_ladspa :: realloc_drywet()
211 wet_buffer=(f_prec *) malloc(sizeof(float)*vtt_class::samples_in_mix_buffer);
214 void vtt_fx_ladspa :: free_drywet()
222 void vtt_fx_ladspa :: activate()
227 reconnect_buffer(); // we always have to reconnect...
228 if (plugin->getDescriptor()->activate) plugin->getDescriptor()->activate(instance);
231 void vtt_fx_ladspa :: deactivate()
233 if (plugin->getDescriptor()->deactivate) plugin->getDescriptor()->deactivate(instance);
238 void vtt_fx_ladspa :: run()
240 plugin->getDescriptor()->run(instance, (vtt_class::samples_in_mix_buffer)>>1);
243 f_prec wet=sp_wet->get_value();
246 for (int sample=0; sample < (vtt_class::samples_in_mix_buffer)>>1; sample++) {
247 myvtt->output_buffer[sample]=dry*myvtt->output_buffer[sample]+wet*wet_buffer[sample];
252 int vtt_fx_ladspa :: isEnabled()
254 return (int) sp_enable->get_value();
257 const char *vtt_fx_ladspa :: get_info_string()
259 return plugin->get_info_string();
262 vtt_fx_ladspa :: ~vtt_fx_ladspa()
264 list <tX_seqpar_vttfx *> :: iterator sp;
266 while (controls.size()) {
268 controls.remove((*sp));
272 plugin->getDescriptor()->cleanup(instance);
274 if (wet_buffer) free(wet_buffer);
279 void vtt_fx_ladspa :: save (FILE *rc, gzFile rz, char *indent) {
280 long ID=plugin->getUniqueID();
281 list <tX_seqpar_vttfx *> :: iterator sp;
283 tX_store("%s<ladspa_plugin>\n", indent);
284 strcat (indent, "\t");
286 store_int("ladspa_id", ID);
287 store_bool("has_drywet", (sp_wet!=NULL));
289 for (sp=controls.begin(); sp!=controls.end(); sp++) {
290 store_float_sp("param", (*sp)->get_value(), (*(*sp)));
293 store_bool("panel_hidden", panel->is_hidden());
295 indent[strlen(indent)-1]=0;
296 tX_store("%s</ladspa_plugin>\n", indent);
299 void vtt_fx_ladspa :: load(xmlDocPtr doc, xmlNodePtr node) {
302 list <tX_seqpar_vttfx *> :: iterator sp=controls.begin();
307 for (xmlNodePtr cur=node->xmlChildrenNode; cur!=NULL; cur=cur->next) {
308 if (cur->type == XML_ELEMENT_NODE) {
311 restore_int("ladspa_id", dummy);
312 restore_bool("panel_hidden", hidden);
313 restore_bool_ac("has_drywet", bdummy, add_drywet());
315 if ((!elementFound) && (xmlStrcmp(cur->name, (xmlChar *) "param")==0)) {
320 if (sp==controls.end()) {
321 tX_warning("found unexpected parameters for ladspa plugin [%i].", dummy);
323 restore_float_id("param", val, (*(*sp)), (*sp)->do_exec(val));
324 (*sp)->do_update_graphics();
330 tX_warning("unhandled ladspa_plugin element %s.", cur->name);
338 void vtt_fx_ladspa :: toggle_drywet() {
346 void vtt_fx_ladspa :: add_drywet() {
349 sp_wet=new tX_seqpar_vttfx_float();
350 sp_wet->set_mapping_parameters(1.0, 0, 0.01, 1);
351 sprintf(buffer, "%s: Dry/Wet", plugin->getLabel());
352 sp_wet->set_name(buffer, "Dry/Wet");
353 sp_wet->set_vtt(vtt);
354 panel->add_client_widget(sp_wet->get_widget());
356 pthread_mutex_lock(&vtt_class::render_lock);
357 controls.push_back(sp_wet);
360 pthread_mutex_unlock(&vtt_class::render_lock);
363 void vtt_fx_ladspa :: remove_drywet() {
364 pthread_mutex_lock(&vtt_class::render_lock);
367 controls.remove(sp_wet);
372 pthread_mutex_unlock(&vtt_class::render_lock);
375 tX_drywet_type vtt_fx_ladspa::has_drywet_feature()
377 if (sp_wet) return DRYWET_ACTIVE;
378 else return DRYWET_AVAILABLE;