1 #include "bcdisplayinfo.h"
6 #include "pluginaclient.h"
10 class OverlayAudioWindow;
13 class OverlayAudioConfig
17 int equivalent(OverlayAudioConfig &that);
18 void copy_from(OverlayAudioConfig &that);
19 void interpolate(OverlayAudioConfig &prev,
20 OverlayAudioConfig &next,
23 int64_t current_frame);
24 static char* output_to_text(int output_layer);
34 class OutputTrack : public BC_PopupMenu
37 OutputTrack(OverlayAudio *plugin, int x, int y);
38 void create_objects();
43 class OverlayAudioWindow : public BC_Window
46 OverlayAudioWindow(OverlayAudio *plugin, int x, int y);
55 PLUGIN_THREAD_HEADER(OverlayAudio, OverlayAudioThread, OverlayAudioWindow)
57 class OverlayAudio : public PluginAClient
60 OverlayAudio(PluginServer *server);
63 int is_multichannel();
65 void read_data(KeyFrame *keyframe);
66 void save_data(KeyFrame *keyframe);
67 int process_buffer(int64_t size,
69 int64_t start_position,
76 PLUGIN_CLASS_MEMBERS(OverlayAudioConfig, OverlayAudioThread)
86 OverlayAudioConfig::OverlayAudioConfig()
88 output_track = OverlayAudioConfig::TOP;
91 int OverlayAudioConfig::equivalent(OverlayAudioConfig &that)
93 return that.output_track == output_track;
96 void OverlayAudioConfig::copy_from(OverlayAudioConfig &that)
98 output_track = that.output_track;
101 void OverlayAudioConfig::interpolate(OverlayAudioConfig &prev,
102 OverlayAudioConfig &next,
105 int64_t current_frame)
107 output_track = prev.output_track;
110 char* OverlayAudioConfig::output_to_text(int output_layer)
114 case OverlayAudioConfig::TOP: return _("Top");
115 case OverlayAudioConfig::BOTTOM: return _("Bottom");
126 OverlayAudioWindow::OverlayAudioWindow(OverlayAudio *plugin, int x, int y)
127 : BC_Window(plugin->gui_string,
138 this->plugin = plugin;
141 int OverlayAudioWindow::create_objects()
145 add_subwindow(title = new BC_Title(x, y, "Output track:"));
146 x += title->get_w() + 10;
147 add_subwindow(output = new OutputTrack(plugin, x, y));
148 output->create_objects();
153 WINDOW_CLOSE_EVENT(OverlayAudioWindow)
158 OutputTrack::OutputTrack(OverlayAudio *plugin, int x , int y)
162 OverlayAudioConfig::output_to_text(plugin->config.output_track),
165 this->plugin = plugin;
168 void OutputTrack::create_objects()
170 add_item(new BC_MenuItem(
171 OverlayAudioConfig::output_to_text(
172 OverlayAudioConfig::TOP)));
173 add_item(new BC_MenuItem(
174 OverlayAudioConfig::output_to_text(
175 OverlayAudioConfig::BOTTOM)));
178 int OutputTrack::handle_event()
180 char *text = get_text();
183 OverlayAudioConfig::output_to_text(
184 OverlayAudioConfig::TOP)))
185 plugin->config.output_track = OverlayAudioConfig::TOP;
188 OverlayAudioConfig::output_to_text(
189 OverlayAudioConfig::BOTTOM)))
190 plugin->config.output_track = OverlayAudioConfig::BOTTOM;
192 plugin->send_configure_change();
197 PLUGIN_THREAD_OBJECT(OverlayAudio, OverlayAudioThread, OverlayAudioWindow)
202 REGISTER_PLUGIN(OverlayAudio)
207 OverlayAudio::OverlayAudio(PluginServer *server)
208 : PluginAClient(server)
210 PLUGIN_CONSTRUCTOR_MACRO
213 OverlayAudio::~OverlayAudio()
215 PLUGIN_DESTRUCTOR_MACRO
218 char* OverlayAudio::plugin_title() { return N_("Overlay"); }
219 int OverlayAudio::is_realtime() { return 1; }
220 int OverlayAudio::is_multichannel() { return 1; }
224 void OverlayAudio::read_data(KeyFrame *keyframe)
227 input.set_shared_string(keyframe->data, strlen(keyframe->data));
232 result = input.read_tag();
236 if(input.tag.title_is("OVERLAY"))
238 config.output_track = input.tag.get_property("OUTPUT", config.output_track);
244 void OverlayAudio::save_data(KeyFrame *keyframe)
247 output.set_shared_string(keyframe->data, MESSAGESIZE);
249 output.tag.set_title("OVERLAY");
250 output.tag.set_property("OUTPUT", config.output_track);
252 output.tag.set_title("/OVERLAY");
254 output.append_newline();
255 output.terminate_string();
258 int OverlayAudio::load_defaults()
260 char directory[BCTEXTLEN];
261 sprintf(directory, "%soverlayaudio.rc", BCASTDIR);
262 defaults = new BC_Hash(directory);
265 config.output_track = defaults->get("OUTPUT", config.output_track);
269 int OverlayAudio::save_defaults()
271 defaults->update("OUTPUT", config.output_track);
278 void OverlayAudio::update_gui()
282 if(load_configuration())
284 thread->window->lock_window("OverlayAudio::update_gui");
285 thread->window->output->set_text(
286 OverlayAudioConfig::output_to_text(config.output_track));
287 thread->window->unlock_window();
292 NEW_PICON_MACRO(OverlayAudio)
293 SHOW_GUI_MACRO(OverlayAudio, OverlayAudioThread)
294 RAISE_WINDOW_MACRO(OverlayAudio)
295 SET_STRING_MACRO(OverlayAudio)
296 LOAD_CONFIGURATION_MACRO(OverlayAudio, OverlayAudioConfig)
299 int OverlayAudio::process_buffer(int64_t size,
301 int64_t start_position,
304 load_configuration();
307 int output_track = 0;
308 if(config.output_track == OverlayAudioConfig::BOTTOM)
309 output_track = get_total_buffers() - 1;
311 // Direct copy the output track
312 read_samples(buffer[output_track],
318 // Add remaining tracks
319 double *output_buffer = buffer[output_track];
320 for(int i = 0; i < get_total_buffers(); i++)
322 if(i != output_track)
324 double *input_buffer = buffer[i];
325 read_samples(buffer[i],
330 for(int j = 0; j < size; j++)
332 output_buffer[j] += input_buffer[j];