Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / batchrender.C
blobafe5f71ff8d3386c5ca0406910dd9e184476d4cc
1 #include "asset.h"
2 #include "batchrender.h"
3 #include "bcsignals.h"
4 #include "confirmsave.h"
5 #include "bchash.h"
6 #include "edl.h"
7 #include "edlsession.h"
8 #include "errorbox.h"
9 #include "filesystem.h"
10 #include "filexml.h"
11 #include "keys.h"
12 #include "language.h"
13 #include "mainsession.h"
14 #include "mutex.h"
15 #include "mwindow.h"
16 #include "mwindowgui.h"
17 #include "packagedispatcher.h"
18 #include "packagerenderer.h"
19 #include "preferences.h"
20 #include "render.h"
21 #include "theme.h"
22 #include "transportque.h"
23 #include "vframe.h"
29 static char *list_titles[] = 
31         N_("Enabled"), 
32         N_("Output"),
33         N_("EDL"),
34         N_("Elapsed")
37 static int list_widths[] =
39         50,
40         100,
41         200,
42         100
45 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
46  : BC_MenuItem(_("Batch Render..."), "Shift-B", 'B')
48         set_shift(1); 
49         this->mwindow = mwindow;
52 int BatchRenderMenuItem::handle_event()
54         mwindow->batch_render->start();
55         return 1;
65 BatchRenderJob::BatchRenderJob(Preferences *preferences)
67         this->preferences = preferences;
68         asset = Asset_GC(new Asset);
69         edl_path[0] = 0;
70         strategy = 0;
71         enabled = 1;
72         elapsed = 0;
75 void BatchRenderJob::copy_from(BatchRenderJob *src)
77         asset->copy_from(*src->asset, 0);
78         strcpy(edl_path, src->edl_path);
79         strategy = src->strategy;
80         enabled = src->enabled;
81         elapsed = 0;
84 void BatchRenderJob::load(FileXML *file)
86         int result = 0;
88         edl_path[0] = 0;
89         file->tag.get_property("EDL_PATH", edl_path);
90         strategy = file->tag.get_property("STRATEGY", strategy);
91         enabled = file->tag.get_property("ENABLED", enabled);
92         elapsed = file->tag.get_property("ELAPSED", elapsed);
93         fix_strategy();
95         result = file->read_tag();
96         if(!result)
97         {
98                 if(file->tag.title_is("ASSET"))
99                 {
100                         file->tag.get_property("SRC", asset->path);
101                         asset->read(file, 0);
102 // The compression parameters are stored in the defaults to reduce
103 // coding maintenance.  The defaults must now be stuffed into the XML for
104 // unique storage.
105                         BC_Hash defaults;
106                         defaults.load_string(file->read_text());
107                         asset->load_defaults(&defaults,
108                                 "",
109                                 0,
110                                 1,
111                                 0,
112                                 0,
113                                 0);
114                 }
115         }
118 void BatchRenderJob::save(FileXML *file)
120 TRACE("BatchRenderJob::save 1");
121         file->tag.set_property("EDL_PATH", edl_path);
122 TRACE("BatchRenderJob::save 1");
123         file->tag.set_property("STRATEGY", strategy);
124 TRACE("BatchRenderJob::save 1");
125         file->tag.set_property("ENABLED", enabled);
126 TRACE("BatchRenderJob::save 1");
127         file->tag.set_property("ELAPSED", elapsed);
128 TRACE("BatchRenderJob::save 1");
129         file->append_tag();
130 TRACE("BatchRenderJob::save 1");
131         file->append_newline();
132 TRACE("BatchRenderJob::save 1");
133         asset->write(file,
134                 0,
135                 "");
137 // The compression parameters are stored in the defaults to reduce
138 // coding maintenance.  The defaults must now be stuffed into the XML for
139 // unique storage.
140         BC_Hash defaults;
141         asset->save_defaults(&defaults, 
142                 "",
143                 0,
144                 1,
145                 0,
146                 0,
147                 0);
148         char *string;
149         defaults.save_string(string);
150         file->append_text(string);
151         delete [] string;
152 TRACE("BatchRenderJob::save 1");
153         file->tag.set_title("/JOB");
154 TRACE("BatchRenderJob::save 1");
155         file->append_tag();
156 TRACE("BatchRenderJob::save 1");
157         file->append_newline();
158 TRACE("BatchRenderJob::save 10");
161 void BatchRenderJob::fix_strategy()
163         strategy = Render::fix_strategy(strategy, preferences->use_renderfarm);
175 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
176  : BC_DialogThread()
178         this->mwindow = mwindow;
179         current_job = 0;
180         rendering_job = -1;
181         is_rendering = 0;
182         default_job = 0;
185 BatchRenderThread::BatchRenderThread()
186  : BC_DialogThread()
188         mwindow = 0;
189         current_job = 0;
190         rendering_job = -1;
191         is_rendering = 0;
192         default_job = 0;
195 void BatchRenderThread::handle_close_event(int result)
197 // Save settings
198 TRACE("BatchRenderThread::handle_close_event 1");
199         char path[BCTEXTLEN];
200 TRACE("BatchRenderThread::handle_close_event 1");
201         path[0] = 0;
202 TRACE("BatchRenderThread::handle_close_event 1");
203         save_jobs(path);
204 TRACE("BatchRenderThread::handle_close_event 1");
205         save_defaults(mwindow->defaults);
206 TRACE("BatchRenderThread::handle_close_event 1");
207         delete default_job;
208 TRACE("BatchRenderThread::handle_close_event 1");
209         default_job = 0;
210 TRACE("BatchRenderThread::handle_close_event 1");
211         jobs.remove_all_objects();
212 TRACE("BatchRenderThread::handle_close_event 100");
215 BC_Window* BatchRenderThread::new_gui()
217         current_start = 0.0;
218         current_end = 0.0;
219         default_job = new BatchRenderJob(mwindow->preferences);
221         char path[BCTEXTLEN];
222         path[0] = 0;
223         load_jobs(path, mwindow->preferences);
224         load_defaults(mwindow->defaults);
225         this->gui = new BatchRenderGUI(mwindow, 
226                 this,
227                 mwindow->session->batchrender_x,
228                 mwindow->session->batchrender_y,
229                 mwindow->session->batchrender_w,
230                 mwindow->session->batchrender_h);
231         this->gui->create_objects();
232         return this->gui;
236 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
238         FileXML file;
239         int result = 0;
241         jobs.remove_all_objects();
242         if(path[0])
243                 file.read_from_file(path);
244         else
245                 file.read_from_file(create_path(path));
247         while(!result)
248         {
249                 if(!(result = file.read_tag()))
250                 {
251                         if(file.tag.title_is("JOB"))
252                         {
253                                 BatchRenderJob *job;
254                                 jobs.append(job = new BatchRenderJob(preferences));
255                                 job->load(&file);
256                         }
257                 }
258         }
261 void BatchRenderThread::save_jobs(char *path)
263         FileXML file;
265         for(int i = 0; i < jobs.total; i++)
266         {
267                 file.tag.set_title("JOB");
268                 jobs.values[i]->save(&file);
269         }
271         if(path[0])
272                 file.write_to_file(path);
273         else
274                 file.write_to_file(create_path(path));
277 void BatchRenderThread::load_defaults(BC_Hash *defaults)
279         if(default_job)
280         {
281                 default_job->asset->load_defaults(defaults,
282                         "BATCHRENDER_",
283                         1,
284                         1,
285                         1,
286                         1,
287                         1);
288                 default_job->fix_strategy();
289         }
291         for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
292         {
293                 char string[BCTEXTLEN];
294                 sprintf(string, "BATCHRENDER_COLUMN%d", i);
295                 column_width[i] = defaults->get(string, list_widths[i]);
296         }
299 void BatchRenderThread::save_defaults(BC_Hash *defaults)
301         if(default_job)
302         {
303                 default_job->asset->save_defaults(defaults,
304                         "BATCHRENDER_",
305                         1,
306                         1,
307                         1,
308                         1,
309                         1);
310                 defaults->update("BATCHRENDER_STRATEGY", default_job->strategy);
311         }
312         for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
313         {
314                 char string[BCTEXTLEN];
315                 sprintf(string, "BATCHRENDER_COLUMN%d", i);
316                 defaults->update(string, column_width[i]);
317         }
318 //      defaults->update("BATCHRENDER_JOB", current_job);
319         if(mwindow)
320                 mwindow->save_defaults();
321         else
322                 defaults->save();
325 char* BatchRenderThread::create_path(char *string)
327         FileSystem fs;
328         sprintf(string, "%s", BCASTDIR);
329         fs.complete_path(string);
330         strcat(string, BATCH_PATH);
331         return string;
334 void BatchRenderThread::new_job()
336         BatchRenderJob *result = new BatchRenderJob(mwindow->preferences);
337         result->copy_from(get_current_job());
338         jobs.append(result);
339         current_job = jobs.total - 1;
340         gui->create_list(1);
341         gui->change_job();
344 void BatchRenderThread::delete_job()
346         if(current_job < jobs.total && current_job >= 0)
347         {
348                 jobs.remove_object_number(current_job);
349                 if(current_job > 0) current_job--;
350                 gui->create_list(1);
351                 gui->change_job();
352         }
355 BatchRenderJob* BatchRenderThread::get_current_job()
357         BatchRenderJob *result;
358         if(current_job >= jobs.total || current_job < 0)
359         {
360                 result = default_job;
361         }
362         else
363         {
364                 result = jobs.values[current_job];
365         }
366         return result;
370 Asset_GC BatchRenderThread::get_current_asset()
372         return get_current_job()->asset;
375 char* BatchRenderThread::get_current_edl()
377         return get_current_job()->edl_path;
381 // Test EDL files for existence
382 int BatchRenderThread::test_edl_files()
384         for(int i = 0; i < jobs.total; i++)
385         {
386                 if(jobs.values[i]->enabled)
387                 {
388                         FILE *fd = fopen(jobs.values[i]->edl_path, "r");
389                         if(!fd)
390                         {
391                                 char string[BCTEXTLEN];
392                                 sprintf(string, _("EDL %s not found.\n"), jobs.values[i]->edl_path);
393                                 if(mwindow)
394                                 {
395                                         ErrorBox error_box(PROGRAM_NAME ": Error",
396                                                 mwindow->gui->get_abs_cursor_x(1),
397                                                 mwindow->gui->get_abs_cursor_y(1));
398                                         error_box.create_objects(string);
399                                         error_box.run_window();
400                                         gui->new_batch->enable();
401                                         gui->delete_batch->enable();
402                                 }
403                                 else
404                                 {
405                                         fprintf(stderr, 
406                                                 "%s",
407                                                 string);
408                                 }
410                                 is_rendering = 0;
411                                 return 1;
412                         }
413                         else
414                         {
415                                 fclose(fd);
416                         }
417                 }
418         }
419         return 0;
422 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
423         Preferences *preferences,
424         ArrayList<PluginServer*> *plugindb)
426         for(int i = 0; i < jobs.total; i++)
427         {
428                 BatchRenderJob *job = jobs.values[i];
429                 if(job->enabled)
430                 {
431                         PackageDispatcher *packages = new PackageDispatcher;
433 // Load EDL
434                         TransportCommand *command = new TransportCommand;
435                         FileXML *file = new FileXML;
436                         file->read_from_file(job->edl_path);
438 // Use command to calculate range.
439                         command->command = NORMAL_FWD;
440                         command->get_edl()->load_xml(plugindb, 
441                                 file, 
442                                 LOAD_ALL);
443                         command->change_type = CHANGE_ALL;
444                         command->set_playback_range();
445                         command->playback_range_adjust_inout();
447 // Create test packages
448                         packages->create_packages(mwindow,
449                                 command->get_edl(),
450                                 preferences,
451                                 job->strategy, 
452                                 job->asset, 
453                                 command->start_position, 
454                                 command->end_position,
455                                 0);
457 // Append output paths allocated to total
458                         packages->get_package_paths(paths);
460 // Delete package harness
461                         delete packages;
462                         delete command;
463                         delete file;
464                 }
465         }
469 void BatchRenderThread::start_rendering(char *config_path,
470         char *batch_path)
472         BC_Hash *boot_defaults;
473         Preferences *preferences;
474         Render *render;
475         ArrayList<PluginServer*> *plugindb;
477 // Initialize stuff which MWindow does.
478         MWindow::init_defaults(boot_defaults, config_path);
479         load_defaults(boot_defaults);
480         preferences = new Preferences;
481         preferences->load_defaults(boot_defaults);
482         MWindow::init_plugins(preferences, plugindb, 0);
484         load_jobs(batch_path, preferences);
485         save_jobs(batch_path);
486         save_defaults(boot_defaults);
488 // Test EDL files for existence
489         if(test_edl_files()) return;
492 // Predict all destination paths
493         ArrayList<char*> paths;
494         calculate_dest_paths(&paths,
495                 preferences,
496                 plugindb);
498         int result = ConfirmSave::test_files(0, &paths);
499         paths.remove_all_objects();
501 // Abort on any existing file because it's so hard to set this up.
502         if(result) return;
504         render = new Render(0);
505         render->start_batches(&jobs, 
506                 boot_defaults,
507                 preferences,
508                 plugindb);
511 void BatchRenderThread::start_rendering()
513         if(is_rendering) return;
515         is_rendering = 1;
516         char path[BCTEXTLEN];
517         path[0] = 0;
518         save_jobs(path);
519         save_defaults(mwindow->defaults);
520         gui->new_batch->disable();
521         gui->delete_batch->disable();
523 // Test EDL files for existence
524         if(test_edl_files()) return;
526 // Predict all destination paths
527         ArrayList<char*> paths;
528         calculate_dest_paths(&paths,
529                 mwindow->preferences,
530                 mwindow->plugindb);
532 // Test destination files for overwrite
533         int result = ConfirmSave::test_files(mwindow, &paths);
534         paths.remove_all_objects();
536 // User cancelled
537         if(result)
538         {
539                 is_rendering = 0;
540                 gui->new_batch->enable();
541                 gui->delete_batch->enable();
542                 return;
543         }
545         mwindow->render->start_batches(&jobs);
548 void BatchRenderThread::stop_rendering()
550         if(!is_rendering) return;
551         mwindow->render->stop_operation();
552         is_rendering = 0;
555 void BatchRenderThread::update_active(int number)
557         gui->lock_window("BatchRenderThread::update_active");
558         if(number >= 0)
559         {
560                 current_job = number;
561                 rendering_job = number;
562         }
563         else
564         {
565                 rendering_job = -1;
566                 is_rendering = 0;
567         }
568         gui->create_list(1);
569         gui->unlock_window();
572 void BatchRenderThread::update_done(int number, 
573         int create_list, 
574         double elapsed_time)
576         gui->lock_window("BatchRenderThread::update_done");
577         if(number < 0)
578         {
579                 gui->new_batch->enable();
580                 gui->delete_batch->enable();
581         }
582         else
583         {
584                 jobs.values[number]->enabled = 0;
585                 jobs.values[number]->elapsed = elapsed_time;
586                 if(create_list) gui->create_list(1);
587         }
588         gui->unlock_window();
591 void BatchRenderThread::move_batch(int src, int dst)
593         BatchRenderJob *src_job = jobs.values[src];
594         if(dst < 0) dst = jobs.total - 1;
596         if(dst != src)
597         {
598                 for(int i = src; i < jobs.total - 1; i++)
599                         jobs.values[i] = jobs.values[i + 1];
600 //              if(dst > src) dst--;
601                 for(int i = jobs.total - 1; i > dst; i--)
602                         jobs.values[i] = jobs.values[i - 1];
603                 jobs.values[dst] = src_job;
604                 gui->create_list(1);
605         }
616 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow, 
617         BatchRenderThread *thread,
618         int x,
619         int y,
620         int w,
621         int h)
622  : BC_Window(PROGRAM_NAME ": Batch Render", 
623         x,
624         y,
625         w, 
626         h, 
627         50, 
628         50, 
629         1,
630         0, 
631         1)
633         this->mwindow = mwindow;
634         this->thread = thread;
637 BatchRenderGUI::~BatchRenderGUI()
639         delete format_tools;
643 void BatchRenderGUI::create_objects()
645         mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
646         create_list(0);
648         int x = mwindow->theme->batchrender_x1;
649         int y = 5;
650         int x1 = mwindow->theme->batchrender_x1;
651         int x2 = mwindow->theme->batchrender_x2;
652         int x3 = mwindow->theme->batchrender_x3;
653         int y1 = y;
654         int y2;
656 // output file
657         add_subwindow(output_path_title = new BC_Title(x1, y, _("Output path:")));
658         y += 20;
659         format_tools = new BatchFormat(mwindow,
660                                         this, 
661                                         thread->get_current_asset());
662         format_tools->create_objects(x, 
663                                                 y, 
664                                                 1, 
665                                                 1, 
666                                                 1, 
667                                                 1, 
668                                                 0, 
669                                                 1, 
670                                                 0, 
671                                                 0, 
672                                                 &thread->get_current_job()->strategy, 
673                                                 0);
675         x2 = x;
676         y2 = y + 10;
677         x += format_tools->get_w();
678         y = y1;
679         x1 = x;
680         x3 = x + 80;
682 // input EDL
683         x = x1;
684         add_subwindow(edl_path_title = new BC_Title(x, y, _("EDL Path:")));
685         y += 20;
686         add_subwindow(edl_path_text = new BatchRenderEDLPath(
687                 thread, 
688                 x, 
689                 y, 
690                 get_w() - x - 40, 
691                 thread->get_current_edl()));
693         x += edl_path_text->get_w();
694         add_subwindow(edl_path_browse = new BrowseButton(
695                 mwindow,
696                 this,
697                 edl_path_text, 
698                 x, 
699                 y, 
700                 thread->get_current_edl(),
701                 _("Input EDL"),
702                 _("Select an EDL to load:"),
703                 0));
705         x = x1;
707         y += 45;
708         add_subwindow(new_batch = new BatchRenderNew(thread, 
709                 x, 
710                 y));
711         x += new_batch->get_w() + 10;
713         add_subwindow(delete_batch = new BatchRenderDelete(thread, 
714                 x, 
715                 y));
716         x += delete_batch->get_w() + 10;
718         add_subwindow(savelist_batch = new BatchRenderSaveList(thread, 
719                 x, 
720                 y));
721         x += savelist_batch->get_w() + 10;
723         add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, 
724                 x, 
725                 y));
726         x += loadlist_batch->get_w() + 10;
729         x = x2;
730         y = y2;
731         add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
732         y += 20;
733         add_subwindow(batch_list = new BatchRenderList(thread, 
734                 x, 
735                 y,
736                 get_w() - x - 10,
737                 get_h() - y - BC_GenericButton::calculate_h() - 15));
739         y += batch_list->get_h() + 10;
740         add_subwindow(start_button = new BatchRenderStart(thread, 
741             x, 
742             y));
743         x = get_w() / 2 -
744                 BC_GenericButton::calculate_w(this, _("Stop")) / 2;
745         add_subwindow(stop_button = new BatchRenderStop(thread, 
746                 x, 
747                 y));
748         x = get_w() - 
749                 BC_GenericButton::calculate_w(this, _("Close")) - 
750                 10;
751         add_subwindow(cancel_button = new BatchRenderCancel(thread, 
752                 x, 
753                 y));
755         show_window();
758 int BatchRenderGUI::resize_event(int w, int h)
760         mwindow->session->batchrender_w = w;
761         mwindow->session->batchrender_h = h;
762         mwindow->theme->get_batchrender_sizes(this, w, h);
764         int x = mwindow->theme->batchrender_x1;
765         int y = 5;
766         int x1 = mwindow->theme->batchrender_x1;
767         int x2 = mwindow->theme->batchrender_x2;
768         int x3 = mwindow->theme->batchrender_x3;
769         int y1 = y;
770         int y2;
772         output_path_title->reposition_window(x1, y);
773         y += 20;
774         format_tools->reposition_window(x, y);
775         x2 = x;
776         y2 = y + 10;
777         y = y1;
778         x += format_tools->get_w();
779         x1 = x;
780         x3 = x + 80;
782         x = x1;
783         edl_path_title->reposition_window(x, y);
784         y += 20;
785         edl_path_text->reposition_window(x, y, w - x - 40);
786         x += edl_path_text->get_w();
787         edl_path_browse->reposition_window(x, y);
789         x = x1;
790 //      y += 30;
791 //      status_title->reposition_window(x, y);
792 //      x = x3;
793 //      status_text->reposition_window(x, y);
794 //      x = x1;
795 //      y += 30;
796 //      progress_bar->reposition_window(x, y, w - x - 10);
798         y += 30;
799         new_batch->reposition_window(x, y);
800         x += new_batch->get_w() + 10;
801         delete_batch->reposition_window(x, y);
802         x += delete_batch->get_w() + 10;
804         x = x2;
805         y = y2;
806         int y_margin = get_h() - batch_list->get_h();
807         list_title->reposition_window(x, y);
808         y += 20;
809         batch_list->reposition_window(x, y, w - x - 10, h - y_margin);
811         y += batch_list->get_h() + 10;
812         start_button->reposition_window(x, y);
813         x = w / 2 - 
814                 stop_button->get_w() / 2;
815         stop_button->reposition_window(x, y);
816         x = w -
817                 cancel_button->get_w() - 
818                 10;
819         cancel_button->reposition_window(x, y);
820         return 1;
823 int BatchRenderGUI::translation_event()
825         mwindow->session->batchrender_x = get_x();
826         mwindow->session->batchrender_y = get_y();
827         return 1;
830 int BatchRenderGUI::close_event()
832 // Stop batch rendering
833         unlock_window();
834         thread->stop_rendering();
835         lock_window("BatchRenderGUI::close_event");
836         set_done(1);
837         return 1;
840 void BatchRenderGUI::create_list(int update_widget)
842         for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
843         {
844                 list_columns[i].remove_all_objects();
845         }
847         for(int i = 0; i < thread->jobs.total; i++)
848         {
849                 BatchRenderJob *job = thread->jobs.values[i];
850                 char string[BCTEXTLEN];
851                 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? 
852                         (char*)"X" : 
853                         (char*)" ");
854                 BC_ListBoxItem *item1 = new BC_ListBoxItem(job->asset->path);
855                 BC_ListBoxItem *item2 = new BC_ListBoxItem(job->edl_path);
856                 BC_ListBoxItem *item3;
857                 if(job->elapsed)
858                         item3 = new BC_ListBoxItem(
859                                 Units::totext(string,
860                                         job->elapsed,
861                                         TIME_HMS2));
862                 else
863                         item3 = new BC_ListBoxItem(_("Unknown"));
864                 list_columns[0].append(enabled);
865                 list_columns[1].append(item1);
866                 list_columns[2].append(item2);
867                 list_columns[3].append(item3);
868                 if(i == thread->current_job)
869                 {
870                         enabled->set_selected(1);
871                         item1->set_selected(1);
872                         item2->set_selected(1);
873                         item3->set_selected(1);
874                 }
875                 if(i == thread->rendering_job)
876                 {
877                         enabled->set_color(RED);
878                         item1->set_color(RED);
879                         item2->set_color(RED);
880                         item3->set_color(RED);
881                 }
882         }
884         if(update_widget)
885         {
886                 batch_list->update(list_columns,
887                                                 list_titles,
888                                                 thread->column_width,
889                                                 BATCHRENDER_COLUMNS,
890                                                 batch_list->get_xposition(),
891                                                 batch_list->get_yposition(), 
892                                                 batch_list->get_highlighted_item(),  // Flat index of item cursor is over
893                                                 1,     // set all autoplace flags to 1
894                                                 1);
895         }
898 void BatchRenderGUI::change_job()
900         BatchRenderJob *job = thread->get_current_job();
901         format_tools->update(job->asset, &job->strategy);
902         edl_path_text->update(job->edl_path);
912 BatchFormat::BatchFormat(MWindow *mwindow,
913                         BatchRenderGUI *gui,
914                         Asset_GC asset)
915  : FormatTools(mwindow, gui, asset)
917         this->gui = gui;
918         this->mwindow = mwindow;
921 BatchFormat::~BatchFormat()
926 int BatchFormat::handle_event()
928         gui->create_list(1);
929         return 1;
942 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread, 
943         int x, 
944         int y, 
945         int w, 
946         char *text)
947  : BC_TextBox(x, 
948                 y, 
949                 w, 
950                 1,
951                 text)
953         this->thread = thread;
957 int BatchRenderEDLPath::handle_event()
959         strcpy(thread->get_current_edl(), get_text());
960         thread->gui->create_list(1);
961         return 1;
969 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread, 
970         int x, 
971         int y)
972  : BC_GenericButton(x, y, _("New"))
974         this->thread = thread;
977 int BatchRenderNew::handle_event()
979         thread->new_job();
980         return 1;
983 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, 
984         int x, 
985         int y)
986  : BC_GenericButton(x, y, _("Delete"))
988         this->thread = thread;
991 int BatchRenderDelete::handle_event()
993         thread->delete_job();
994         return 1;
999 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, 
1000         int x, 
1001         int y)
1002  : BC_GenericButton(x, y, _("Save List"))
1004         this->thread = thread;
1005         set_tooltip(_("Save a Batch Render List"));
1006         gui = 0;
1007         startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1010 BatchRenderSaveList::~BatchRenderSaveList()
1012         startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1013         if(gui)
1014         {
1015                 gui->lock_window();
1016                 gui->set_done(1);
1017                 gui->unlock_window();
1018         }
1019         startup_lock->unlock();
1020         Thread::join();
1021         delete startup_lock;
1024 int BatchRenderSaveList::handle_event()
1026         if(Thread::running())
1027         {
1028                 if(gui)
1029                 {
1030                         gui->lock_window();
1031                         gui->raise_window();
1032                         gui->unlock_window();
1033                 }
1034                 return 1;
1035         }
1036         startup_lock->lock("BatchRenderSaveList::handle_event 1");
1037         Thread::start();
1038         startup_lock->lock("BatchRenderSaveList::handle_event 2");
1039         startup_lock->unlock();
1040         return 1;
1043 void BatchRenderSaveList::run()
1045         char default_path[BCTEXTLEN];
1046         sprintf(default_path, "~");
1047         BC_FileBox filewindow(100,
1048                               100,
1049                               this->thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path),
1050                               _("Save Batch Render List"),
1051                               _("Enter a Batch Render filename to save as:"),
1052                               0,
1053                               0,
1054                               0,
1055                               0);
1057         gui = &filewindow;
1059         startup_lock->unlock();
1060         filewindow.create_objects();
1062         int result2 = filewindow.run_window();
1064         if(!result2)
1065         {
1066                 this->thread->save_jobs(filewindow.get_submitted_path());
1067                 this->thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", filewindow.get_submitted_path());
1068         }
1070         this->thread->gui->flush();
1071         startup_lock->lock("BatchRenderLoadList::run");
1072         gui = 0;
1073         startup_lock->unlock();
1076 int BatchRenderSaveList::keypress_event() {
1077         if (get_keypress() == 's' || 
1078             get_keypress() == 'S') return handle_event();
1079         return 0;
1085 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread, 
1086         int x, 
1087         int y)
1088   : BC_GenericButton(x, y, _("Load List")),
1089     Thread()
1091         this->thread = thread;
1092         set_tooltip(_("Load a previously saved Batch Render List"));
1093         gui = 0;
1094         startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1097 BatchRenderLoadList::~BatchRenderLoadList()
1099         startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1100         if(gui)
1101         {
1102                 gui->lock_window();
1103                 gui->set_done(1);
1104                 gui->unlock_window();
1105         }
1106         startup_lock->unlock();
1107         Thread::join();
1108         delete startup_lock;
1111 int BatchRenderLoadList::handle_event()
1113         if(Thread::running())
1114         {
1115                 if(gui)
1116                 {
1117                         gui->lock_window();
1118                         gui->raise_window();
1119                         gui->unlock_window();
1120                 }
1121                 return 1;
1122         }
1123         startup_lock->lock("BatchRenderLoadList::handle_event 1");
1124         Thread::start();
1125         startup_lock->lock("BatchRenderLoadList::handle_event 2");
1126         startup_lock->unlock();
1127         return 1;
1130 void BatchRenderLoadList::run()
1132         char default_path[BCTEXTLEN];
1133         sprintf(default_path, "~");
1134         BC_FileBox filewindow(100,
1135                               100,
1136                               this->thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path),
1137                               _("Load Batch Render List"),
1138                               _("Enter a Batch Render filename to load from:"),
1139                               0,
1140                               0,
1141                               0,
1142                               0);
1144         gui = &filewindow;
1146         startup_lock->unlock();
1147         filewindow.create_objects();
1149         int result2 = filewindow.run_window();
1151         if(!result2)
1152         {
1153                 this->thread->load_jobs(filewindow.get_submitted_path(),this->thread->mwindow->preferences);
1154                 this->thread->gui->create_list(1);
1155                 this->thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", filewindow.get_submitted_path());
1156         }
1158         this->thread->gui->flush();
1159         startup_lock->lock("BatchRenderLoadList::run");
1160         gui = 0;
1161         startup_lock->unlock();
1164 int BatchRenderLoadList::keypress_event() {
1165         if (get_keypress() == 'o' || 
1166             get_keypress() == 'O') return handle_event();
1167         return 0;
1170 BatchRenderList::BatchRenderList(BatchRenderThread *thread, 
1171         int x, 
1172         int y,
1173         int w,
1174         int h)
1175  : BC_ListBox(x, 
1176         y, 
1177         w, 
1178         h, 
1179         LISTBOX_TEXT,
1180         thread->gui->list_columns,
1181         list_titles,
1182         thread->column_width,
1183         BATCHRENDER_COLUMNS,
1184         0,
1185         0,
1186         LISTBOX_SINGLE,
1187         ICON_LEFT,
1188         1)
1190         this->thread = thread;
1191         dragging_item = 0;
1192         set_process_drag(0);
1195 int BatchRenderList::handle_event()
1197         return 1;
1200 int BatchRenderList::selection_changed()
1202         thread->current_job = get_selection_number(0, 0);
1203         thread->gui->change_job();
1204         if(get_cursor_x() < thread->column_width[0])
1205         {
1206                 BatchRenderJob *job = thread->get_current_job();
1207                 job->enabled = !job->enabled;
1208                 thread->gui->create_list(1);
1209         }
1210         return 1;
1213 int BatchRenderList::column_resize_event()
1215         for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
1216         {
1217                 thread->column_width[i] = get_column_width(i);
1218         }
1219         return 1;
1222 int BatchRenderList::drag_start_event()
1224         if(BC_ListBox::drag_start_event())
1225         {
1226                 dragging_item = 1;
1227                 return 1;
1228         }
1230         return 0;
1233 int BatchRenderList::drag_motion_event()
1235         if(BC_ListBox::drag_motion_event())
1236         {
1237                 return 1;
1238         }
1239         return 0;
1242 int BatchRenderList::drag_stop_event()
1244         if(dragging_item)
1245         {
1246                 int src = get_selection_number(0, 0);
1247                 int dst = get_highlighted_item();
1248                 if(src != dst)
1249                 {
1250                         thread->move_batch(src, dst);
1251                 }
1252                 BC_ListBox::drag_stop_event();
1253         }
1268 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, 
1269         int x, 
1270         int y)
1271  : BC_GenericButton(x, 
1272         y, 
1273         _("Start"))
1275         this->thread = thread;
1278 int BatchRenderStart::handle_event()
1280         thread->start_rendering();
1281         return 1;
1284 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, 
1285         int x, 
1286         int y)
1287  : BC_GenericButton(x, 
1288         y, 
1289         _("Stop"))
1291         this->thread = thread;
1294 int BatchRenderStop::handle_event()
1296         unlock_window();
1297         thread->stop_rendering();
1298         lock_window("BatchRenderStop::handle_event");
1299         return 1;
1303 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, 
1304         int x, 
1305         int y)
1306  : BC_GenericButton(x, 
1307         y, 
1308         _("Close"))
1310         this->thread = thread;
1313 int BatchRenderCancel::handle_event()
1315         unlock_window();
1316         thread->stop_rendering();
1317         lock_window("BatchRenderCancel::handle_event");
1318         thread->gui->set_done(1);
1319         return 1;
1322 int BatchRenderCancel::keypress_event()
1324         if(get_keypress() == ESC) 
1325         {
1326                 unlock_window();
1327                 thread->stop_rendering();
1328                 lock_window("BatchRenderCancel::keypress_event");
1329                 thread->gui->set_done(1);
1330                 return 1;
1331         }
1332         return 0;
1338 //      Local Variables:
1339 //      mode: C++
1340 //      c-file-style: "linux"
1341 //      End: