4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
26 #include "pluginaclient.h"
32 class OverlayAudioWindow;
35 #define AUDIO_TRANSFER_TYPES 2
38 class OverlayAudioConfig
42 int equivalent(OverlayAudioConfig &that);
43 void copy_from(OverlayAudioConfig &that);
44 void interpolate(OverlayAudioConfig &prev,
45 OverlayAudioConfig &next,
48 int64_t current_frame);
49 static const char* output_to_text(int output_layer);
50 static const char* mode_to_text(int mode);
67 class OutputTrack : public BC_PopupMenu
70 OutputTrack(OverlayAudio *plugin, int x, int y);
71 void create_objects();
77 class OverlayMode : public BC_PopupMenu
80 OverlayMode(OverlayAudio *plugin,
83 void create_objects();
88 class OverlayAudioWindow : public PluginClientWindow
91 OverlayAudioWindow(OverlayAudio *plugin);
93 void create_objects();
103 class OverlayAudio : public PluginAClient
106 OverlayAudio(PluginServer *server);
109 int is_multichannel();
111 void read_data(KeyFrame *keyframe);
112 void save_data(KeyFrame *keyframe);
113 int process_buffer(int64_t size,
115 int64_t start_position,
120 PLUGIN_CLASS_MEMBERS2(OverlayAudioConfig)
130 OverlayAudioConfig::OverlayAudioConfig()
132 output_track = OverlayAudioConfig::TOP;
133 mode = OverlayAudioConfig::ADD;
137 int OverlayAudioConfig::equivalent(OverlayAudioConfig &that)
139 return that.output_track == output_track &&
143 void OverlayAudioConfig::copy_from(OverlayAudioConfig &that)
145 output_track = that.output_track;
149 void OverlayAudioConfig::interpolate(OverlayAudioConfig &prev,
150 OverlayAudioConfig &next,
153 int64_t current_frame)
155 output_track = prev.output_track;
159 const char* OverlayAudioConfig::output_to_text(int output_layer)
163 case OverlayAudioConfig::TOP: return _("Top");
164 case OverlayAudioConfig::BOTTOM: return _("Bottom");
170 const char* OverlayAudioConfig::mode_to_text(int mode)
174 case OverlayAudioConfig::ADD: return _("Add");
175 case OverlayAudioConfig::MULTIPLY: return _("Multiply");
186 OverlayAudioWindow::OverlayAudioWindow(OverlayAudio *plugin)
187 : PluginClientWindow(plugin,
194 this->plugin = plugin;
197 void OverlayAudioWindow::create_objects()
202 add_subwindow(title = new BC_Title(x, y, _("Output track:")));
203 x += title->get_w() + plugin->get_theme()->widget_border;
204 add_subwindow(output = new OutputTrack(plugin, x, y));
205 output->create_objects();
207 y += output->get_h() + plugin->get_theme()->widget_border;
209 add_subwindow(title = new BC_Title(x, y, _("Mode:")));
210 x += title->get_w() + plugin->get_theme()->widget_border;
211 add_subwindow(mode = new OverlayMode(plugin, x, y));
212 mode->create_objects();
223 OutputTrack::OutputTrack(OverlayAudio *plugin, int x , int y)
227 OverlayAudioConfig::output_to_text(plugin->config.output_track),
230 this->plugin = plugin;
233 void OutputTrack::create_objects()
235 add_item(new BC_MenuItem(
236 OverlayAudioConfig::output_to_text(
237 OverlayAudioConfig::TOP)));
238 add_item(new BC_MenuItem(
239 OverlayAudioConfig::output_to_text(
240 OverlayAudioConfig::BOTTOM)));
243 int OutputTrack::handle_event()
245 char *text = get_text();
248 OverlayAudioConfig::output_to_text(
249 OverlayAudioConfig::TOP)))
250 plugin->config.output_track = OverlayAudioConfig::TOP;
253 OverlayAudioConfig::output_to_text(
254 OverlayAudioConfig::BOTTOM)))
255 plugin->config.output_track = OverlayAudioConfig::BOTTOM;
257 plugin->send_configure_change();
272 OverlayMode::OverlayMode(OverlayAudio *plugin,
278 OverlayAudioConfig::mode_to_text(plugin->config.mode),
281 this->plugin = plugin;
284 void OverlayMode::create_objects()
286 for(int i = 0; i < AUDIO_TRANSFER_TYPES; i++)
287 add_item(new BC_MenuItem(OverlayAudioConfig::mode_to_text(i)));
290 int OverlayMode::handle_event()
292 char *text = get_text();
294 for(int i = 0; i < AUDIO_TRANSFER_TYPES; i++)
296 if(!strcmp(text, OverlayAudioConfig::mode_to_text(i)))
298 plugin->config.mode = i;
303 plugin->send_configure_change();
315 REGISTER_PLUGIN(OverlayAudio)
320 OverlayAudio::OverlayAudio(PluginServer *server)
321 : PluginAClient(server)
326 OverlayAudio::~OverlayAudio()
331 const char* OverlayAudio::plugin_title() { return N_("Overlay"); }
332 int OverlayAudio::is_realtime() { return 1; }
333 int OverlayAudio::is_multichannel() { return 1; }
337 void OverlayAudio::read_data(KeyFrame *keyframe)
340 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
345 result = input.read_tag();
349 if(input.tag.title_is("OVERLAY"))
351 config.output_track = input.tag.get_property("OUTPUT", config.output_track);
352 config.mode = input.tag.get_property("MODE", config.mode);
358 void OverlayAudio::save_data(KeyFrame *keyframe)
361 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
363 output.tag.set_title("OVERLAY");
364 output.tag.set_property("OUTPUT", config.output_track);
365 output.tag.set_property("MODE", config.mode);
367 output.tag.set_title("/OVERLAY");
369 output.append_newline();
370 output.terminate_string();
375 void OverlayAudio::update_gui()
379 if(load_configuration())
381 thread->window->lock_window("OverlayAudio::update_gui");
382 ((OverlayAudioWindow*)thread->window)->output->set_text(
383 OverlayAudioConfig::output_to_text(config.output_track));
384 ((OverlayAudioWindow*)thread->window)->mode->set_text(
385 OverlayAudioConfig::mode_to_text(config.mode));
386 thread->window->unlock_window();
391 NEW_WINDOW_MACRO(OverlayAudio, OverlayAudioWindow)
392 LOAD_CONFIGURATION_MACRO(OverlayAudio, OverlayAudioConfig)
395 int OverlayAudio::process_buffer(int64_t size,
397 int64_t start_position,
400 load_configuration();
403 int output_track = 0;
404 if(config.output_track == OverlayAudioConfig::BOTTOM)
405 output_track = get_total_buffers() - 1;
407 // Direct copy the output track
408 read_samples(buffer[output_track],
414 // Add remaining tracks
415 Samples *output_buffer = buffer[output_track];
416 double *output_samples = output_buffer->get_data();
417 for(int i = 0; i < get_total_buffers(); i++)
419 if(i != output_track)
421 Samples *input_buffer = buffer[i];
422 read_samples(buffer[i],
427 double *input_samples = input_buffer->get_data();
431 case OverlayAudioConfig::ADD:
432 for(int j = 0; j < size; j++)
434 output_samples[j] += input_samples[j];
439 case OverlayAudioConfig::MULTIPLY:
440 for(int j = 0; j < size; j++)
442 output_samples[j] *= input_samples[j];