2 #include "data/lad_picon_png.h"
5 #include "pluginaclientlad.h"
6 #include "pluginserver.h"
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
19 PluginAClientConfig::PluginAClientConfig()
24 PluginAClientConfig::~PluginAClientConfig()
29 void PluginAClientConfig::reset()
36 void PluginAClientConfig::delete_objects()
46 int PluginAClientConfig::equivalent(PluginAClientConfig &that)
48 if(that.total_ports != total_ports) return 0;
49 for(int i = 0; i < total_ports; i++)
50 if(!EQUIV(port_data[i], that.port_data[i])) return 0;
54 // Need PluginServer to do this.
55 void PluginAClientConfig::copy_from(PluginAClientConfig &that)
57 if(total_ports != that.total_ports)
60 total_ports = that.total_ports;
61 port_data = new LADSPA_Data[total_ports];
62 port_type = new int[total_ports];
65 for(int i = 0; i < total_ports; i++)
67 port_type[i] = that.port_type[i];
68 port_data[i] = that.port_data[i];
69 //printf("PluginAClientConfig::copy_from 1 %f %f\n", port_data[i], that.port_data[i]);
74 void PluginAClientConfig::interpolate(PluginAClientConfig &prev,
75 PluginAClientConfig &next,
78 int64_t current_frame)
83 void PluginAClientConfig::initialize(PluginServer *server)
87 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
89 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
90 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
96 port_data = new LADSPA_Data[total_ports];
97 port_type = new int[total_ports];
100 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
102 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
103 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
105 // Convert LAD default to default value
107 const LADSPA_PortRangeHint *lad_hint = &server->lad_descriptor->PortRangeHints[i];
108 LADSPA_PortRangeHintDescriptor hint_desc = lad_hint->HintDescriptor;
110 // Store type of port for GUI use
111 port_type[current_port] = PORT_NORMAL;
112 if(LADSPA_IS_HINT_SAMPLE_RATE(hint_desc))/* &&
113 !LADSPA_IS_HINT_BOUNDED_ABOVE(hint_desc) &&
114 !LADSPA_IS_HINT_BOUNDED_BELOW(hint_desc))*/
116 // LAD frequency table
117 port_type[current_port] = PORT_FREQ_INDEX;
120 if(LADSPA_IS_HINT_TOGGLED(hint_desc))
121 port_type[current_port] = PORT_TOGGLE;
123 if(LADSPA_IS_HINT_INTEGER(hint_desc))
124 port_type[current_port] = PORT_INTEGER;
131 // Get default of port using crazy hinting system
132 if(LADSPA_IS_HINT_DEFAULT_0(hint_desc))
135 if(LADSPA_IS_HINT_DEFAULT_1(hint_desc))
138 if(LADSPA_IS_HINT_DEFAULT_100(hint_desc))
141 if(LADSPA_IS_HINT_DEFAULT_440(hint_desc))
143 if(port_type[current_port] == PORT_FREQ_INDEX)
144 value = 440.0 / 44100;
149 if(LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_desc))
150 value = lad_hint->UpperBound;
152 if(LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_desc))
153 value = lad_hint->LowerBound;
155 if(LADSPA_IS_HINT_DEFAULT_LOW(hint_desc))
157 if(LADSPA_IS_HINT_LOGARITHMIC(hint_desc))
158 value = exp(log(lad_hint->LowerBound) * 0.25 +
159 log(lad_hint->UpperBound) * 0.75);
161 value = lad_hint->LowerBound * 0.25 +
162 lad_hint->UpperBound * 0.75;
165 if(LADSPA_IS_HINT_DEFAULT_MIDDLE(hint_desc))
167 if(LADSPA_IS_HINT_LOGARITHMIC(hint_desc))
168 value = exp(log(lad_hint->LowerBound) * 0.5 +
169 log(lad_hint->UpperBound) * 0.5);
171 value = lad_hint->LowerBound * 0.5 +
172 lad_hint->UpperBound * 0.5;
175 if(LADSPA_IS_HINT_DEFAULT_HIGH(hint_desc))
177 if(LADSPA_IS_HINT_LOGARITHMIC(hint_desc))
178 value = exp(log(lad_hint->LowerBound) * 0.75 +
179 log(lad_hint->UpperBound) * 0.25);
181 value = lad_hint->LowerBound * 0.75 +
182 lad_hint->UpperBound * 0.25;
193 port_data[current_port] = value;
209 PluginACLientToggle::PluginACLientToggle(PluginAClientLAD *plugin,
213 : BC_CheckBox(x, y, (int)(*output))
215 this->plugin = plugin;
216 this->output = output;
219 int PluginACLientToggle::handle_event()
221 *output = get_value();
222 plugin->send_configure_change();
232 PluginACLientILinear::PluginACLientILinear(PluginAClientLAD *plugin,
238 : BC_IPot(x, y, (int)(*output), min, max)
240 this->plugin = plugin;
241 this->output = output;
244 int PluginACLientILinear::handle_event()
246 *output = get_value();
247 plugin->send_configure_change();
256 PluginACLientFLinear::PluginACLientFLinear(PluginAClientLAD *plugin,
262 : BC_FPot(x, y, *output, min, max)
264 this->plugin = plugin;
265 this->output = output;
269 int PluginACLientFLinear::handle_event()
271 *output = get_value();
272 plugin->send_configure_change();
282 PluginACLientFreq::PluginACLientFreq(PluginAClientLAD *plugin,
286 int translate_linear)
290 (int)(*output * plugin->PluginAClient::project_sample_rate) :
293 //printf("PluginACLientFreq::PluginACLientFreq 1 %f\n", *output);
294 this->plugin = plugin;
295 this->output = output;
296 this->translate_linear = translate_linear;
299 int PluginACLientFreq::handle_event()
301 *output = translate_linear ?
302 (float)get_value() / plugin->PluginAClient::project_sample_rate :
304 //printf("PluginACLientFreq::handle_event 1 %f %d %d\n", *output, get_value(), plugin->PluginAClient::project_sample_rate);
305 plugin->send_configure_change();
317 PluginAClientWindow::PluginAClientWindow(PluginAClientLAD *plugin,
320 : BC_Window(plugin->gui_string,
324 plugin->config.total_ports * 30 + 60,
326 plugin->config.total_ports * 30 + 60,
330 this->plugin = plugin;
333 PluginAClientWindow::~PluginAClientWindow()
338 int PluginAClientWindow::create_objects()
340 PluginServer *server = plugin->server;
341 char string[BCTEXTLEN];
342 int current_port = 0;
347 int title_vmargin = 5;
349 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
351 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
352 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
354 int w = get_text_width(MEDIUMFONT, (char*)server->lad_descriptor->PortNames[i]);
355 if(w > max_w) max_w = w;
361 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
363 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
364 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
366 const LADSPA_PortRangeHint *lad_hint = &server->lad_descriptor->PortRangeHints[i];
367 LADSPA_PortRangeHintDescriptor hint_desc = lad_hint->HintDescriptor;
368 int use_min = LADSPA_IS_HINT_BOUNDED_BELOW(hint_desc);
369 int use_max = LADSPA_IS_HINT_BOUNDED_ABOVE(hint_desc);
370 sprintf(string, "%s:", server->lad_descriptor->PortNames[i]);
372 // printf("PluginAClientWindow::create_objects 1 %s type=%d lower: %d %f upper: %d %f\n",
374 // plugin->config.port_type[current_port],
376 // lad_hint->LowerBound,
378 // lad_hint->UpperBound);
380 switch(plugin->config.port_type[current_port])
382 case PluginAClientConfig::PORT_NORMAL:
384 PluginACLientFLinear *flinear;
385 float min = use_min ? lad_hint->LowerBound : 0;
386 float max = use_max ? lad_hint->UpperBound : 100;
387 add_subwindow(new BC_Title(x,
390 add_subwindow(flinear = new PluginACLientFLinear(
392 (current_port % 2) ? x2 : x3,
394 &plugin->config.port_data[current_port],
397 fpots.append(flinear);
400 case PluginAClientConfig::PORT_FREQ_INDEX:
402 PluginACLientFreq *freq;
403 add_subwindow(new BC_Title(x,
406 add_subwindow(freq = new PluginACLientFreq(
408 (current_port % 2) ? x2 : x3,
410 &plugin->config.port_data[current_port],
412 /* (plugin->config.port_type[current_port] ==
413 PluginAClientConfig::PORT_FREQ_INDEX
418 case PluginAClientConfig::PORT_TOGGLE:
420 PluginACLientToggle *toggle;
421 add_subwindow(new BC_Title(x,
424 add_subwindow(toggle = new PluginACLientToggle(
426 (current_port % 2) ? x2 : x3,
428 &plugin->config.port_data[current_port]));
429 toggles.append(toggle);
432 case PluginAClientConfig::PORT_INTEGER:
434 PluginACLientILinear *ilinear;
435 float min = use_min ? lad_hint->LowerBound : 0;
436 float max = use_max ? lad_hint->UpperBound : 100;
437 add_subwindow(new BC_Title(x,
440 add_subwindow(ilinear = new PluginACLientILinear(
442 (current_port % 2) ? x2 : x3,
444 &plugin->config.port_data[current_port],
447 ipots.append(ilinear);
453 //printf("PluginAClientWindow::create_objects 2\n");
458 sprintf(string, _("Author: %s"), server->lad_descriptor->Maker);
459 add_subwindow(new BC_Title(x, y, string));
461 sprintf(string, _("License: %s"), server->lad_descriptor->Copyright);
462 add_subwindow(new BC_Title(x, y, string));
465 int PluginAClientWindow::close_event()
482 PLUGIN_THREAD_OBJECT(PluginAClientLAD, PluginAClientThread, PluginAClientWindow)
488 PluginAClientLAD::PluginAClientLAD(PluginServer *server)
489 : PluginAClient(server)
491 PLUGIN_CONSTRUCTOR_MACRO
495 total_outbuffers = 0;
496 buffer_allocation = 0;
500 PluginAClientLAD::~PluginAClientLAD()
502 PLUGIN_DESTRUCTOR_MACRO
507 int PluginAClientLAD::is_realtime()
512 int PluginAClientLAD::is_multichannel()
514 if(get_inchannels() > 1 || get_outchannels() > 1) return 1;
518 int PluginAClientLAD::get_inchannels()
521 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
523 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i]) &&
524 LADSPA_IS_PORT_AUDIO(server->lad_descriptor->PortDescriptors[i]))
530 int PluginAClientLAD::get_outchannels()
533 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
535 if(LADSPA_IS_PORT_OUTPUT(server->lad_descriptor->PortDescriptors[i]) &&
536 LADSPA_IS_PORT_AUDIO(server->lad_descriptor->PortDescriptors[i]))
543 char* PluginAClientLAD::plugin_title()
545 return (char*)server->lad_descriptor->Name;
548 int PluginAClientLAD::uses_gui()
553 int PluginAClientLAD::is_synthesis()
558 VFrame* PluginAClientLAD::new_picon()
560 return new VFrame(lad_picon_png);
563 SHOW_GUI_MACRO(PluginAClientLAD, PluginAClientThread)
564 RAISE_WINDOW_MACRO(PluginAClientLAD)
565 SET_STRING_MACRO(PluginAClientLAD)
566 LOAD_CONFIGURATION_MACRO(PluginAClientLAD, PluginAClientConfig)
568 void PluginAClientLAD::update_gui()
572 char* PluginAClientLAD::lad_to_string(char *string, char *input)
574 strcpy(string, input);
575 for(int j = 0; j < strlen(string); j++)
577 if(string[j] == ' ' ||
579 string[j] == '>') string[j] = '_';
584 char* PluginAClientLAD::lad_to_upper(char *string, char *input)
586 lad_to_string(string, input);
587 for(int j = 0; j < strlen(string); j++)
588 string[j] = toupper(string[j]);
593 int PluginAClientLAD::load_defaults()
595 char directory[BCTEXTLEN];
596 char string[BCTEXTLEN];
599 strcpy(string, plugin_title());
600 for(int i = 0; i < strlen(string); i++)
601 if(string[i] == ' ') string[i] = '_';
602 // set the default directory
603 sprintf(directory, "%s%s.rc", BCASTDIR, string);
604 //printf("PluginAClientLAD::load_defaults %s\n", directory);
607 defaults = new Defaults(directory);
609 config.initialize(server);
611 int current_port = 0;
612 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
614 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
615 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
617 PluginAClientLAD::lad_to_upper(string,
618 (char*)server->lad_descriptor->PortNames[i]);
620 config.port_data[current_port] =
621 defaults->get(string,
622 config.port_data[current_port]);
623 //printf("PluginAClientLAD::load_defaults %d %f\n", current_port, config.port_data[current_port]);
631 int PluginAClientLAD::save_defaults()
633 char string[BCTEXTLEN];
634 int current_port = 0;
635 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
637 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
638 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
640 // Convert LAD port name to default title
641 PluginAClientLAD::lad_to_upper(string,
642 (char*)server->lad_descriptor->PortNames[i]);
644 defaults->update(string, config.port_data[current_port]);
645 //printf("PluginAClientLAD::save_defaults %d %f\n", current_port, config.port_data[current_port]);
655 void PluginAClientLAD::save_data(KeyFrame *keyframe)
658 char string[BCTEXTLEN];
660 // cause data to be stored directly in text
661 output.set_shared_string(keyframe->data, MESSAGESIZE);
662 output.tag.set_title(lad_to_upper(string, plugin_title()));
664 int current_port = 0;
665 //printf("PluginAClientLAD::save_data %d\n", server->lad_descriptor->PortCount);
666 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
668 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
669 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
671 // Convert LAD port name to default title
672 PluginAClientLAD::lad_to_upper(string,
673 (char*)server->lad_descriptor->PortNames[i]);
675 output.tag.set_property(string, config.port_data[current_port]);
676 //printf("PluginAClientLAD::save_data %d %f\n", current_port, config.port_data[current_port]);
682 output.terminate_string();
685 void PluginAClientLAD::read_data(KeyFrame *keyframe)
688 char string[BCTEXTLEN];
690 input.set_shared_string(keyframe->data, strlen(keyframe->data));
691 config.initialize(server);
696 result = input.read_tag();
700 //printf("PluginAClientLAD::read_data %s\n", input.tag.get_title());
701 if(input.tag.title_is(lad_to_upper(string, plugin_title())))
703 int current_port = 0;
704 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
706 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i] &&
707 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i])))
709 PluginAClientLAD::lad_to_upper(string,
710 (char*)server->lad_descriptor->PortNames[i]);
712 config.port_data[current_port] =
713 input.tag.get_property(string,
714 config.port_data[current_port]);
715 //printf("PluginAClientLAD::read_data %d %f\n", current_port, config.port_data[current_port]);
724 void PluginAClientLAD::delete_buffers()
728 for(int i = 0; i < total_inbuffers; i++) delete [] in_buffers[i];
732 for(int i = 0; i < total_outbuffers; i++) delete [] out_buffers[i];
737 total_outbuffers = 0;
738 buffer_allocation = 0;
741 void PluginAClientLAD::delete_plugin()
745 if(server->lad_descriptor->deactivate)
746 server->lad_descriptor->deactivate(lad_instance);
747 server->lad_descriptor->cleanup(lad_instance);
752 void PluginAClientLAD::init_plugin(int total_in, int total_out, int size)
754 //printf("PluginAClientLAD::init_plugin 1\n");
755 if(buffer_allocation && buffer_allocation < size)
760 buffer_allocation = MAX(size, buffer_allocation);
763 total_inbuffers = total_in;
764 in_buffers = new LADSPA_Data*[total_inbuffers];
765 for(int i = 0; i < total_inbuffers; i++)
766 in_buffers[i] = new LADSPA_Data[buffer_allocation];
771 total_outbuffers = total_out;
772 out_buffers = new LADSPA_Data*[total_outbuffers];
773 for(int i = 0; i < total_outbuffers; i++)
774 out_buffers[i] = new LADSPA_Data[buffer_allocation];
777 int need_reconfigure = 0;
780 need_reconfigure = 1;
782 need_reconfigure |= load_configuration();
787 lad_instance = server->lad_descriptor->instantiate(
788 server->lad_descriptor,
789 PluginAClient::project_sample_rate);
791 int current_port = 0;
792 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
794 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i]) &&
795 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i]))
797 server->lad_descriptor->connect_port(lad_instance,
799 config.port_data + current_port);
800 //printf("PluginAClientLAD::init_plugin %d %f\n", current_port, config.port_data[current_port]);
804 if(LADSPA_IS_PORT_OUTPUT(server->lad_descriptor->PortDescriptors[i]) &&
805 LADSPA_IS_PORT_CONTROL(server->lad_descriptor->PortDescriptors[i]))
807 server->lad_descriptor->connect_port(lad_instance,
809 &dummy_control_output);
812 if(server->lad_descriptor->activate)
813 server->lad_descriptor->activate(lad_instance);
814 need_reconfigure = 0;
817 int current_port = 0;
818 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
820 if(LADSPA_IS_PORT_INPUT(server->lad_descriptor->PortDescriptors[i]) &&
821 LADSPA_IS_PORT_AUDIO(server->lad_descriptor->PortDescriptors[i]))
823 server->lad_descriptor->connect_port(lad_instance,
825 in_buffers[current_port]);
831 for(int i = 0; i < server->lad_descriptor->PortCount; i++)
833 if(LADSPA_IS_PORT_OUTPUT(server->lad_descriptor->PortDescriptors[i]) &&
834 LADSPA_IS_PORT_AUDIO(server->lad_descriptor->PortDescriptors[i]))
836 server->lad_descriptor->connect_port(lad_instance,
838 out_buffers[current_port]);
842 //printf("PluginAClientLAD::init_plugin 10\n");
845 int PluginAClientLAD::process_realtime(int64_t size,
849 int in_channels = get_inchannels();
850 int out_channels = get_outchannels();
851 init_plugin(in_channels, out_channels, size);
853 //printf("PluginAClientLAD::process_realtime 1 %p\n", lad_instance);
854 for(int i = 0; i < in_channels; i++)
856 LADSPA_Data *in_buffer = in_buffers[i];
857 for(int j = 0; j < size; j++)
858 in_buffer[j] = input_ptr[j];
860 for(int i = 0; i < out_channels; i++)
861 bzero(out_buffers[i], sizeof(float) * size);
862 //printf("PluginAClientLAD::process_realtime 4\n");
864 server->lad_descriptor->run(lad_instance, size);
865 //printf("PluginAClientLAD::process_realtime 5\n");
867 LADSPA_Data *out_buffer = out_buffers[0];
868 for(int i = 0; i < size; i++)
870 output_ptr[i] = out_buffer[i];
872 //printf("PluginAClientLAD::process_realtime 6\n");
876 int PluginAClientLAD::process_realtime(int64_t size,
880 int in_channels = get_inchannels();
881 int out_channels = get_outchannels();
882 // printf("PluginAClientLAD::process_realtime 2 %p %d %d %d %d\n",
883 // lad_instance, in_channels, out_channels, PluginClient::total_in_buffers, PluginClient::total_out_buffers);
884 init_plugin(in_channels, out_channels, size);
885 //printf("PluginAClientLAD::process_realtime 2 %p\n", lad_instance);
887 for(int i = 0; i < in_channels; i++)
889 float *in_buffer = in_buffers[i];
891 if(i < PluginClient::total_in_buffers)
892 in_ptr = input_ptr[i];
894 in_ptr = input_ptr[0];
895 for(int j = 0; j < size; j++)
896 in_buffer[j] = in_ptr[j];
898 //printf("PluginAClientLAD::process_realtime 2 %p\n", lad_instance);
899 for(int i = 0; i < out_channels; i++)
900 bzero(out_buffers[i], sizeof(float) * size);
901 //printf("PluginAClientLAD::process_realtime 2 %p\n", lad_instance);
903 server->lad_descriptor->run(lad_instance, size);
904 //printf("PluginAClientLAD::process_realtime 2 %p\n", lad_instance);
906 for(int i = 0; i < PluginClient::total_out_buffers; i++)
908 if(i < total_outbuffers)
910 LADSPA_Data *out_buffer = out_buffers[i];
911 double *out_ptr = output_ptr[i];
912 for(int j = 0; j < size; j++)
913 out_ptr[j] = out_buffer[j];
916 //printf("PluginAClientLAD::process_realtime 3 %p\n", lad_instance);