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()
199 int x = xS(10), y = yS(10);
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)
224 : BC_PopupMenu(x, y, xS(100),
225 OverlayAudioConfig::output_to_text(plugin->config.output_track),
228 this->plugin = plugin;
231 void OutputTrack::create_objects()
233 add_item(new BC_MenuItem(
234 OverlayAudioConfig::output_to_text(
235 OverlayAudioConfig::TOP)));
236 add_item(new BC_MenuItem(
237 OverlayAudioConfig::output_to_text(
238 OverlayAudioConfig::BOTTOM)));
241 int OutputTrack::handle_event()
243 char *text = get_text();
246 OverlayAudioConfig::output_to_text(
247 OverlayAudioConfig::TOP)))
248 plugin->config.output_track = OverlayAudioConfig::TOP;
251 OverlayAudioConfig::output_to_text(
252 OverlayAudioConfig::BOTTOM)))
253 plugin->config.output_track = OverlayAudioConfig::BOTTOM;
255 plugin->send_configure_change();
270 OverlayMode::OverlayMode(OverlayAudio *plugin, int x, int y)
271 : BC_PopupMenu(x, y, xS(150),
272 OverlayAudioConfig::mode_to_text(plugin->config.mode),
275 this->plugin = plugin;
278 void OverlayMode::create_objects()
280 for(int i = 0; i < AUDIO_TRANSFER_TYPES; i++)
281 add_item(new BC_MenuItem(OverlayAudioConfig::mode_to_text(i)));
284 int OverlayMode::handle_event()
286 char *text = get_text();
288 for(int i = 0; i < AUDIO_TRANSFER_TYPES; i++)
290 if(!strcmp(text, OverlayAudioConfig::mode_to_text(i)))
292 plugin->config.mode = i;
297 plugin->send_configure_change();
309 REGISTER_PLUGIN(OverlayAudio)
314 OverlayAudio::OverlayAudio(PluginServer *server)
315 : PluginAClient(server)
320 OverlayAudio::~OverlayAudio()
325 const char* OverlayAudio::plugin_title() { return N_("Overlay"); }
326 int OverlayAudio::is_realtime() { return 1; }
327 int OverlayAudio::is_multichannel() { return 1; }
331 void OverlayAudio::read_data(KeyFrame *keyframe)
334 input.set_shared_input(keyframe->xbuf);
339 result = input.read_tag();
343 if(input.tag.title_is("OVERLAY"))
345 config.output_track = input.tag.get_property("OUTPUT", config.output_track);
346 config.mode = input.tag.get_property("MODE", config.mode);
352 void OverlayAudio::save_data(KeyFrame *keyframe)
355 output.set_shared_output(keyframe->xbuf);
357 output.tag.set_title("OVERLAY");
358 output.tag.set_property("OUTPUT", config.output_track);
359 output.tag.set_property("MODE", config.mode);
361 output.tag.set_title("/OVERLAY");
363 output.append_newline();
364 output.terminate_string();
369 void OverlayAudio::update_gui()
373 if(load_configuration())
375 thread->window->lock_window("OverlayAudio::update_gui");
376 ((OverlayAudioWindow*)thread->window)->output->set_text(
377 OverlayAudioConfig::output_to_text(config.output_track));
378 ((OverlayAudioWindow*)thread->window)->mode->set_text(
379 OverlayAudioConfig::mode_to_text(config.mode));
380 thread->window->unlock_window();
385 NEW_WINDOW_MACRO(OverlayAudio, OverlayAudioWindow)
386 LOAD_CONFIGURATION_MACRO(OverlayAudio, OverlayAudioConfig)
389 int OverlayAudio::process_buffer(int64_t size,
391 int64_t start_position,
394 load_configuration();
397 int output_track = 0;
398 if(config.output_track == OverlayAudioConfig::BOTTOM)
399 output_track = get_total_buffers() - 1;
401 // Direct copy the output track
402 read_samples(buffer[output_track],
408 // Add remaining tracks
409 Samples *output_buffer = buffer[output_track];
410 double *output_samples = output_buffer->get_data();
411 for(int i = 0; i < get_total_buffers(); i++)
413 if(i != output_track)
415 Samples *input_buffer = buffer[i];
416 read_samples(buffer[i],
421 double *input_samples = input_buffer->get_data();
425 case OverlayAudioConfig::ADD:
426 for(int j = 0; j < size; j++)
428 output_samples[j] += input_samples[j];
433 case OverlayAudioConfig::MULTIPLY:
434 for(int j = 0; j < size; j++)
436 output_samples[j] *= input_samples[j];