4 #include "edlsession.h"
7 #include "formatcheck.h"
12 #include "localsession.h"
14 #include "mainsession.h"
17 #include "mwindowgui.h"
18 #include "menueffects.h"
19 #include "neworappend.h"
20 #include "playbackengine.h"
21 #include "pluginarray.h"
22 #include "pluginserver.h"
23 #include "preferences.h"
25 #include "sighandler.h"
30 #define _(String) gettext(String)
31 #define gettext_noop(String) String
32 #define N_(String) gettext_noop (String)
35 MenuEffects::MenuEffects(MWindow *mwindow)
36 : BC_MenuItem(_("Render effect..."))
38 this->mwindow = mwindow;
41 MenuEffects::~MenuEffects()
46 int MenuEffects::handle_event()
48 thread->set_title("");
56 MenuEffectPacket::MenuEffectPacket()
62 MenuEffectPacket::~MenuEffectPacket()
71 MenuEffectThread::MenuEffectThread(MWindow *mwindow)
73 this->mwindow = mwindow;
77 MenuEffectThread::~MenuEffectThread()
85 int MenuEffectThread::set_title(char *title)
87 strcpy(this->title, title);
90 // for recent effect menu items and running new effects
91 // prompts for an effect if title is blank
92 void MenuEffectThread::run()
94 // get stuff from main window
95 ArrayList<PluginServer*> *plugindb = mwindow->plugindb;
96 Defaults *defaults = mwindow->defaults;
97 ArrayList<BC_ListBoxItem*> plugin_list;
98 ArrayList<PluginServer*> local_plugindb;
102 // Default configuration
105 ArrayList<Asset*> assets;
107 //printf("MenuEffectThread::run 1\n");
108 // sprintf(string, "");
109 // defaults->get("EFFECTPATH", string);
111 // check for recordable tracks
112 if(!get_recordable_tracks(&default_asset))
114 sprintf(string, _("No recordable tracks specified."));
115 ErrorBox error(PROGRAM_NAME ": Error");
116 error.create_objects(string);
121 //printf("MenuEffectThread::run 1\n");
125 sprintf(string, _("No plugins available."));
126 ErrorBox error(PROGRAM_NAME ": Error");
127 error.create_objects(string);
132 //printf("MenuEffectThread::run 1\n");
134 //printf("MenuEffectThread::run 1\n");
135 // get default attributes for output file
136 // used after completion
137 get_derived_attributes(&default_asset, defaults);
138 // to_tracks = defaults->get("RENDER_EFFECT_TO_TRACKS", 1);
139 load_mode = defaults->get("RENDER_EFFECT_LOADMODE", LOAD_PASTE);
140 strategy = defaults->get("RENDER_EFFECT_STRATEGY", SINGLE_PASS);
142 //printf("MenuEffectThread::run 1\n");
143 // get plugin information
150 //printf("MenuEffectThread::run 1\n");
151 // generate a list of plugins for the window
154 mwindow->create_plugindb(default_asset.audio_data,
155 default_asset.video_data,
161 //printf("MenuEffectThread::run 1\n");
162 for(int i = 0; i < local_plugindb.total; i++)
164 plugin_list.append(new BC_ListBoxItem(local_plugindb.values[i]->title, BLACK));
168 //printf("MenuEffectThread::run 2\n");
169 // find out which effect to run and get output file
170 int plugin_number, format_error = 0;
175 MenuEffectWindow window(mwindow,
177 need_plugin ? &plugin_list : 0,
179 window.create_objects();
180 result = window.run_window();
181 plugin_number = window.result;
184 //printf("MenuEffectThread::run 3\n");
187 FormatCheck format_check(&default_asset);
188 format_error = format_check.check_format();
190 }while(format_error && !result);
192 //printf("MenuEffectThread::run 4\n");
194 save_derived_attributes(&default_asset, defaults);
195 defaults->update("RENDER_EFFECT_LOADMODE", load_mode);
196 defaults->update("RENDER_EFFECT_STRATEGY", strategy);
197 mwindow->save_defaults();
199 //printf("MenuEffectThread::run 5\n");
200 // get plugin server to use and delete the plugin list
201 PluginServer *plugin_server = 0;
202 PluginServer *plugin = 0;
205 plugin_list.remove_all_objects();
206 if(plugin_number > -1)
208 plugin_server = local_plugindb.values[plugin_number];
209 strcpy(title, plugin_server->title);
214 for(int i = 0; i < plugindb->total && !plugin_server; i++)
216 if(!strcmp(plugindb->values[i]->title, title))
218 plugin_server = plugindb->values[i];
224 // Update the most recently used effects and copy the plugin server.
227 plugin = new PluginServer(*plugin_server);
231 //printf("MenuEffectThread::run 6\n");
232 if(!result && !strlen(default_asset.path))
234 result = 1; // no output path given
235 ErrorBox error(PROGRAM_NAME ": Error");
236 error.create_objects(_("No output file specified."));
240 if(!result && plugin_number < 0)
242 result = 1; // no output path given
243 ErrorBox error(PROGRAM_NAME ": Error");
244 error.create_objects(_("No effect selected."));
247 //printf("MenuEffectThread::run 7\n");
249 // Configuration for realtime plugins.
250 KeyFrame plugin_data;
251 //printf("MenuEffectThread::run 8\n");
253 // get selection to render
255 double total_start, total_end;
257 //printf("MenuEffectThread::run 9\n");
258 total_start = mwindow->edl->local_session->get_selectionstart();
261 if(mwindow->edl->local_session->get_selectionend() ==
262 mwindow->edl->local_session->get_selectionstart())
263 total_end = mwindow->edl->tracks->total_playable_length();
265 total_end = mwindow->edl->local_session->get_selectionend();
269 //printf("MenuEffectThread::run 10\n");
270 // get native units for range
271 total_start = to_units(total_start, 0);
272 total_end = to_units(total_end, 1);
276 // Trick boundaries in case of a non-realtime synthesis plugin
279 total_end == total_start) total_end = total_start + 1;
280 //printf("MenuEffectThread::run 11\n");
282 //printf("MenuEffectThread::run 1\n");
283 // Units are now in the track's units.
284 int64_t total_length = (int64_t)total_end - (int64_t)total_start;
285 // length of output file
286 int64_t output_start, output_end;
288 if(!result && total_length <= 0)
290 result = 1; // no output path given
291 ErrorBox error(PROGRAM_NAME ": Error");
292 error.create_objects(_("No selected range to process."));
296 // ========================= get keyframe from user
299 // ========================= realtime plugin
304 //printf("MenuEffectThread::run 10 %s\n", plugin->title);
305 MenuEffectPrompt prompt(mwindow);
306 prompt.create_objects();
308 sprintf(title, PROGRAM_NAME ": %s", plugin->title);
309 //printf("MenuEffectThread::run 11 %s\n", plugin->title);
311 // Open the plugin GUI
312 plugin->set_mwindow(mwindow);
313 plugin->set_keyframe(&plugin_data);
314 plugin->set_prompt(&prompt);
315 //printf("MenuEffectThread::run 11 %s\n", plugin->title);
316 plugin->open_plugin(0, mwindow->edl, 0);
317 //printf("MenuEffectThread::run 11 %s\n", plugin->title);
319 //printf("MenuEffectThread::run 12 %s\n", plugin->title);
321 // wait for user input
322 result = prompt.run_window();
323 //printf("MenuEffectThread::run 13 %s\n", plugin->title);
326 plugin->save_data(&plugin_data);
327 //printf("MenuEffectThread::run 13 %s\n", plugin->title);
329 //printf("MenuEffectThread::run 14\n");
330 default_asset.sample_rate = mwindow->edl->session->sample_rate;
331 default_asset.frame_rate = mwindow->edl->session->frame_rate;
335 // ============================non realtime plugin
337 //printf("MenuEffectThread::run 15\n");
338 plugin->set_mwindow(mwindow);
339 //printf("MenuEffectThread::run 16\n");
340 plugin->open_plugin(0, mwindow->edl, 0);
341 //printf("MenuEffectThread::run 17\n");
342 result = plugin->get_parameters();
343 // some plugins can change the sample rate and the frame rate
344 //printf("MenuEffectThread::run 18\n");
349 default_asset.sample_rate = plugin->get_samplerate();
350 default_asset.frame_rate = plugin->get_framerate();
352 //printf("MenuEffectThread::run 19\n");
357 // Should take from first recordable track
358 default_asset.width = mwindow->edl->session->output_w;
359 default_asset.height = mwindow->edl->session->output_h;
362 //printf("MenuEffectThread::run 20\n");
363 // Process the total length in fragments
364 Label *current_label = mwindow->edl->labels->first;
365 mwindow->stop_brender();
370 Render::get_starting_number(default_asset.path,
374 for(int64_t fragment_start = (int64_t)total_start, fragment_end;
375 fragment_start < (int64_t)total_end && !result;
376 fragment_start = fragment_end)
379 if(strategy == FILE_PER_LABEL || strategy == FILE_PER_LABEL_FARM)
381 while(current_label &&
382 to_units(current_label->position, 0) <= fragment_start)
383 current_label = current_label->next;
386 fragment_end = (int64_t)total_end;
388 fragment_end = to_units(current_label->position, 0);
392 fragment_end = (int64_t)total_end;
396 Asset *asset = new Asset(default_asset);
397 if(strategy == FILE_PER_LABEL || strategy == FILE_PER_LABEL_FARM)
398 Render::create_filename(asset->path,
405 result = Render::test_existence(mwindow, asset);
409 assets.append(asset);
410 File *file = new File;
412 // Open the output file after getting the information because the sample rate
416 // open output file in write mode
417 file->set_processors(mwindow->edl->session->smp + 1);
418 if(file->open_file(mwindow->plugindb,
422 mwindow->edl->session->sample_rate,
423 mwindow->edl->session->frame_rate))
426 sprintf(string, _("Couldn't open %s"), asset->path);
427 ErrorBox error(PROGRAM_NAME ": Error");
428 error.create_objects(string);
434 mwindow->sighandler->push_file(file);
435 IndexFile::delete_index(mwindow->preferences, asset);
439 //printf("MenuEffectThread::run 10\n");
446 PluginArray *plugin_array;
447 plugin_array = create_plugin_array();
449 //printf("MenuEffectThread::run 11\n");
450 plugin_array->start_plugins(mwindow,
457 //printf("MenuEffectThread::run 12\n");
458 plugin_array->run_plugins();
460 //printf("MenuEffectThread::run 13\n");
461 plugin_array->stop_plugins();
462 mwindow->sighandler->pull_file(file);
464 asset->audio_length = file->asset->audio_length;
465 asset->video_length = file->asset->video_length;
466 //printf("MenuEffectThread::run 14 %d %d\n", asset->audio_length, asset->video_length);
468 //printf("MenuEffectThread::run 16\n");
474 //printf("MenuEffectThread::run 16 %d\n", result);
477 // paste output to tracks
478 if(!result && load_mode != LOAD_NOTHING)
480 mwindow->gui->lock_window();
481 //printf("MenuEffectThread::run 17\n");
482 mwindow->undo->update_undo_before(title, LOAD_ALL);
484 //printf("MenuEffectThread::run 18\n");
485 if(load_mode == LOAD_PASTE)
487 mwindow->load_assets(&assets,
492 mwindow->edl->session->labels_follow_edits,
493 mwindow->edl->session->plugins_follow_edits);
495 //printf("MenuEffectThread::run 19\n");
497 mwindow->save_backup();
498 mwindow->undo->update_undo_after();
502 mwindow->restart_brender();
503 mwindow->update_plugin_guis();
504 mwindow->gui->update(1,
511 mwindow->sync_parameters(CHANGE_ALL);
512 //printf("MenuEffectThread::run 22\n");
513 mwindow->gui->unlock_window();
514 //printf("MenuEffectThread::run 23\n");
517 assets.remove_all_objects();
518 //printf("MenuEffectThread::run 24\n");
524 MenuEffectItem::MenuEffectItem(MenuEffects *menueffect, char *string)
525 : BC_MenuItem(string)
527 this->menueffect = menueffect;
529 int MenuEffectItem::handle_event()
531 menueffect->thread->set_title(get_text());
532 menueffect->thread->start();
546 MenuEffectWindow::MenuEffectWindow(MWindow *mwindow,
547 MenuEffectThread *menueffects,
548 ArrayList<BC_ListBoxItem*> *plugin_list,
550 : BC_Window(PROGRAM_NAME ": Render effect",
551 mwindow->gui->get_abs_cursor_x(),
552 mwindow->gui->get_abs_cursor_y() - mwindow->session->menueffect_h / 2,
553 mwindow->session->menueffect_w,
554 mwindow->session->menueffect_h,
561 this->menueffects = menueffects;
562 this->plugin_list = plugin_list;
564 this->mwindow = mwindow;
567 MenuEffectWindow::~MenuEffectWindow()
572 // int MenuEffectWindow::calculate_w(int use_plugin_list)
574 // return use_plugin_list ? 580 : 420;
577 // int MenuEffectWindow::calculate_h(int use_plugin_list)
583 int MenuEffectWindow::create_objects()
587 mwindow->theme->get_menueffect_sizes(plugin_list ? 1 : 0);
589 // only add the list if needed
592 add_subwindow(list_title = new BC_Title(mwindow->theme->menueffect_list_x,
593 mwindow->theme->menueffect_list_y,
594 _("Select an effect")));
595 add_subwindow(list = new MenuEffectWindowList(this,
596 mwindow->theme->menueffect_list_x,
597 mwindow->theme->menueffect_list_y + 20,
598 mwindow->theme->menueffect_list_w,
599 mwindow->theme->menueffect_list_h,
603 add_subwindow(file_title = new BC_Title(mwindow->theme->menueffect_file_x,
604 mwindow->theme->menueffect_file_y,
605 (char*)((menueffects->strategy == FILE_PER_LABEL || menueffects->strategy == FILE_PER_LABEL_FARM) ?
606 _("Select the first file to render to:") :
607 _("Select a file to render to:"))));
609 x = mwindow->theme->menueffect_tools_x;
610 y = mwindow->theme->menueffect_tools_y;
611 format_tools = new FormatTools(mwindow,
614 format_tools->create_objects(x,
624 &menueffects->strategy,
627 loadmode = new LoadMode(mwindow,
631 &menueffects->load_mode,
633 loadmode->create_objects();
635 add_subwindow(new MenuEffectWindowOK(this));
636 add_subwindow(new MenuEffectWindowCancel(this));
642 int MenuEffectWindow::resize_event(int w, int h)
644 mwindow->session->menueffect_w = w;
645 mwindow->session->menueffect_h = h;
646 mwindow->theme->get_menueffect_sizes(plugin_list ? 1 : 0);
650 list_title->reposition_window(mwindow->theme->menueffect_list_x,
651 mwindow->theme->menueffect_list_y);
652 list->reposition_window(mwindow->theme->menueffect_list_x,
653 mwindow->theme->menueffect_list_y + 20,
654 mwindow->theme->menueffect_list_w,
655 mwindow->theme->menueffect_list_h);
658 file_title->reposition_window(mwindow->theme->menueffect_file_x,
659 mwindow->theme->menueffect_file_y);
660 int x = mwindow->theme->menueffect_tools_x;
661 int y = mwindow->theme->menueffect_tools_y;
662 format_tools->reposition_window(x, y);
663 loadmode->reposition_window(x, y);
668 MenuEffectWindowOK::MenuEffectWindowOK(MenuEffectWindow *window)
669 : BC_OKButton(window)
671 this->window = window;
674 int MenuEffectWindowOK::handle_event()
676 if(window->plugin_list)
677 window->result = window->list->get_selection_number(0, 0);
682 int MenuEffectWindowOK::keypress_event()
684 if(get_keypress() == 13)
692 MenuEffectWindowCancel::MenuEffectWindowCancel(MenuEffectWindow *window)
693 : BC_CancelButton(window)
695 this->window = window;
698 int MenuEffectWindowCancel::handle_event()
703 int MenuEffectWindowCancel::keypress_event()
705 if(get_keypress() == ESC)
713 MenuEffectWindowList::MenuEffectWindowList(MenuEffectWindow *window,
718 ArrayList<BC_ListBoxItem*> *plugin_list)
726 this->window = window;
729 int MenuEffectWindowList::handle_event()
731 window->result = get_selection_number(0, 0);
737 MenuEffectPrompt::MenuEffectPrompt(MWindow *mwindow)
738 : BC_Window(PROGRAM_NAME ": Effect Prompt",
739 mwindow->gui->get_abs_cursor_x() - 260 / 2,
740 mwindow->gui->get_abs_cursor_y() - 300,
751 MenuEffectPrompt::~MenuEffectPrompt()
755 int MenuEffectPrompt::create_objects()
758 add_subwindow(new BC_Title(x, y, _("Set up effect panel and hit \"OK\"")));
760 add_subwindow(new BC_OKButton(this));
762 add_subwindow(new BC_CancelButton(this));