1 #include "bcdisplayinfo.h"
8 #include "overlayframe.h"
10 #include "pluginvclient.h"
26 static char* mode_to_text(int mode);
29 static char* direction_to_text(int direction);
37 static char* output_to_text(int output_layer);
50 class OverlayMode : public BC_PopupMenu
53 OverlayMode(Overlay *plugin,
56 void create_objects();
61 class OverlayDirection : public BC_PopupMenu
64 OverlayDirection(Overlay *plugin,
67 void create_objects();
72 class OverlayOutput : public BC_PopupMenu
75 OverlayOutput(Overlay *plugin,
78 void create_objects();
84 class OverlayWindow : public BC_Window
87 OverlayWindow(Overlay *plugin, int x, int y);
90 void create_objects();
95 OverlayDirection *direction;
96 OverlayOutput *output;
100 PLUGIN_THREAD_HEADER(Overlay, OverlayThread, OverlayWindow)
104 class Overlay : public PluginVClient
107 Overlay(PluginServer *server);
111 PLUGIN_CLASS_MEMBERS(OverlayConfig, OverlayThread);
113 int process_buffer(VFrame **frame,
114 int64_t start_position,
117 int is_multichannel();
120 void save_data(KeyFrame *keyframe);
121 void read_data(KeyFrame *keyframe);
124 OverlayFrame *overlayer;
139 OverlayConfig::OverlayConfig()
141 mode = TRANSFER_NORMAL;
142 direction = OverlayConfig::BOTTOM_FIRST;
143 output_layer = OverlayConfig::TOP;
146 char* OverlayConfig::mode_to_text(int mode)
150 case TRANSFER_NORMAL:
154 case TRANSFER_REPLACE:
158 case TRANSFER_ADDITION:
162 case TRANSFER_SUBTRACT:
166 case TRANSFER_MULTIPLY:
170 case TRANSFER_DIVIDE:
181 char* OverlayConfig::direction_to_text(int direction)
185 case OverlayConfig::BOTTOM_FIRST: return _("Bottom first");
186 case OverlayConfig::TOP_FIRST: return _("Top first");
191 char* OverlayConfig::output_to_text(int output_layer)
195 case OverlayConfig::TOP: return _("Top");
196 case OverlayConfig::BOTTOM: return _("Bottom");
209 OverlayWindow::OverlayWindow(Overlay *plugin, int x, int y)
210 : BC_Window(plugin->gui_string,
221 this->plugin = plugin;
224 OverlayWindow::~OverlayWindow()
228 void OverlayWindow::create_objects()
233 add_subwindow(title = new BC_Title(x, y, _("Mode:")));
234 add_subwindow(mode = new OverlayMode(plugin,
235 x + title->get_w() + 5,
237 mode->create_objects();
240 add_subwindow(title = new BC_Title(x, y, _("Layer order:")));
241 add_subwindow(direction = new OverlayDirection(plugin,
242 x + title->get_w() + 5,
244 direction->create_objects();
247 add_subwindow(title = new BC_Title(x, y, _("Output layer:")));
248 add_subwindow(output = new OverlayOutput(plugin,
249 x + title->get_w() + 5,
251 output->create_objects();
257 WINDOW_CLOSE_EVENT(OverlayWindow)
263 OverlayMode::OverlayMode(Overlay *plugin,
269 OverlayConfig::mode_to_text(plugin->config.mode),
272 this->plugin = plugin;
275 void OverlayMode::create_objects()
277 for(int i = 0; i < TRANSFER_TYPES; i++)
278 add_item(new BC_MenuItem(OverlayConfig::mode_to_text(i)));
281 int OverlayMode::handle_event()
283 char *text = get_text();
285 for(int i = 0; i < TRANSFER_TYPES; i++)
287 if(!strcmp(text, OverlayConfig::mode_to_text(i)))
289 plugin->config.mode = i;
294 plugin->send_configure_change();
299 OverlayDirection::OverlayDirection(Overlay *plugin,
305 OverlayConfig::direction_to_text(plugin->config.direction),
308 this->plugin = plugin;
311 void OverlayDirection::create_objects()
313 add_item(new BC_MenuItem(
314 OverlayConfig::direction_to_text(
315 OverlayConfig::TOP_FIRST)));
316 add_item(new BC_MenuItem(
317 OverlayConfig::direction_to_text(
318 OverlayConfig::BOTTOM_FIRST)));
321 int OverlayDirection::handle_event()
323 char *text = get_text();
326 OverlayConfig::direction_to_text(
327 OverlayConfig::TOP_FIRST)))
328 plugin->config.direction = OverlayConfig::TOP_FIRST;
331 OverlayConfig::direction_to_text(
332 OverlayConfig::BOTTOM_FIRST)))
333 plugin->config.direction = OverlayConfig::BOTTOM_FIRST;
335 plugin->send_configure_change();
340 OverlayOutput::OverlayOutput(Overlay *plugin,
346 OverlayConfig::output_to_text(plugin->config.output_layer),
349 this->plugin = plugin;
352 void OverlayOutput::create_objects()
354 add_item(new BC_MenuItem(
355 OverlayConfig::output_to_text(
356 OverlayConfig::TOP)));
357 add_item(new BC_MenuItem(
358 OverlayConfig::output_to_text(
359 OverlayConfig::BOTTOM)));
362 int OverlayOutput::handle_event()
364 char *text = get_text();
367 OverlayConfig::output_to_text(
368 OverlayConfig::TOP)))
369 plugin->config.output_layer = OverlayConfig::TOP;
372 OverlayConfig::output_to_text(
373 OverlayConfig::BOTTOM)))
374 plugin->config.output_layer = OverlayConfig::BOTTOM;
376 plugin->send_configure_change();
388 PLUGIN_THREAD_OBJECT(Overlay, OverlayThread, OverlayWindow)
399 REGISTER_PLUGIN(Overlay)
406 Overlay::Overlay(PluginServer *server)
407 : PluginVClient(server)
409 PLUGIN_CONSTRUCTOR_MACRO
417 PLUGIN_DESTRUCTOR_MACRO
418 if(overlayer) delete overlayer;
419 if(temp) delete temp;
424 int Overlay::process_buffer(VFrame **frame,
425 int64_t start_position,
428 load_configuration();
430 if(!temp) temp = new VFrame(0,
433 frame[0]->get_color_model(),
437 overlayer = new OverlayFrame(get_project_smp() + 1);
439 // Inclusive layer numbers
446 if(config.direction == OverlayConfig::BOTTOM_FIRST)
448 input_layer1 = get_total_buffers() - 1;
455 input_layer2 = get_total_buffers();
459 if(config.output_layer == OverlayConfig::TOP)
465 output_layer = get_total_buffers() - 1;
470 // Direct copy the first layer
471 output = frame[output_layer];
476 for(int i = input_layer1 + step; i != input_layer2; i += step)
482 overlayer->overlay(output,
504 char* Overlay::plugin_title() { return N_("Overlay"); }
505 int Overlay::is_realtime() { return 1; }
506 int Overlay::is_multichannel() { return 1; }
510 NEW_PICON_MACRO(Overlay)
512 SHOW_GUI_MACRO(Overlay, OverlayThread)
514 RAISE_WINDOW_MACRO(Overlay)
516 SET_STRING_MACRO(Overlay);
518 int Overlay::load_configuration()
520 KeyFrame *prev_keyframe;
521 prev_keyframe = get_prev_keyframe(get_source_position());
522 read_data(prev_keyframe);
526 int Overlay::load_defaults()
528 char directory[BCTEXTLEN];
529 // set the default directory
530 sprintf(directory, "%soverlay.rc", BCASTDIR);
533 defaults = new Defaults(directory);
536 config.mode = defaults->get("MODE", config.mode);
537 config.direction = defaults->get("DIRECTION", config.direction);
538 config.output_layer = defaults->get("OUTPUT_LAYER", config.output_layer);
542 int Overlay::save_defaults()
544 defaults->update("MODE", config.mode);
545 defaults->update("DIRECTION", config.direction);
546 defaults->update("OUTPUT_LAYER", config.output_layer);
551 void Overlay::save_data(KeyFrame *keyframe)
555 // cause data to be stored directly in text
556 output.set_shared_string(keyframe->data, MESSAGESIZE);
557 output.tag.set_title("OVERLAY");
558 output.tag.set_property("MODE", config.mode);
559 output.tag.set_property("DIRECTION", config.direction);
560 output.tag.set_property("OUTPUT_LAYER", config.output_layer);
562 output.terminate_string();
565 void Overlay::read_data(KeyFrame *keyframe)
569 input.set_shared_string(keyframe->data, strlen(keyframe->data));
573 while(!input.read_tag())
575 if(input.tag.title_is("OVERLAY"))
577 config.mode = input.tag.get_property("MODE", config.mode);
578 config.direction = input.tag.get_property("DIRECTION", config.direction);
579 config.output_layer = input.tag.get_property("OUTPUT_LAYER", config.output_layer);
584 void Overlay::update_gui()
588 thread->window->lock_window("Overlay::update_gui");
589 thread->window->mode->set_text(OverlayConfig::mode_to_text(config.mode));
590 thread->window->direction->set_text(OverlayConfig::direction_to_text(config.direction));
591 thread->window->output->set_text(OverlayConfig::output_to_text(config.output_layer));
592 thread->window->unlock_window();