Reported by Fedora team for gcc-13 and Andrew created patch here
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / convert.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2015 Adam Williams <broadcast at earthling dot net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #include "assets.h"
22 #include "audiodevice.h"
23 #include "autos.h"
24 #include "bchash.h"
25 #include "bcpot.h"
26 #include "bctimer.h"
27 #include "cache.h"
28 #include "convert.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "file.h"
32 #include "filesystem.h"
33 #include "formattools.h"
34 #include "indexfile.h"
35 #include "language.h"
36 #include "localsession.h"
37 #include "mainerror.h"
38 #include "mainindexes.h"
39 #include "mainprogress.h"
40 #include "mainundo.h"
41 #include "mutex.h"
42 #include "mwindow.h"
43 #include "mwindowgui.h"
44 #include "packagedispatcher.h"
45 #include "packagerenderer.h"
46 #include "panautos.h"
47 #include "panauto.h"
48 #include "preferences.h"
49 #include "render.h"
50 #include "theme.h"
51 #include "tracks.h"
52
53
54 #define WIDTH xS(400)
55 #define HEIGHT yS(360)
56 #define MAX_SCALE 16
57
58 ConvertRender::ConvertRender(MWindow *mwindow)
59  : Thread(1, 0, 0)
60 {
61         this->mwindow = mwindow;
62         suffix = 0;
63         format_asset = 0;
64         progress = 0;
65         progress_timer = new Timer;
66         convert_progress = 0;
67         counter_lock = new Mutex("ConvertDialog::counter_lock");
68         total_rendered = 0;
69         remove_originals = 0;
70         failed = 0;  canceled = 0;
71         result = 0;
72         beep = 0;
73         to_proxy = 0;
74         renderer = 0;
75 }
76
77 ConvertRender::~ConvertRender()
78 {
79         if( running() ) {
80                 canceled = 1;
81                 if( renderer )
82                         renderer->set_result(1);
83                 cancel();
84                 join();
85         }
86         delete renderer;
87         delete [] suffix;
88         delete progress;
89         delete counter_lock;
90         delete progress_timer;
91         delete convert_progress;
92         if( format_asset )
93                 format_asset->remove_user();
94         reset();
95 }
96
97 void ConvertRender::reset()
98 {
99         for( int i=0,n=orig_idxbls.size(); i<n; ++i )
100                 orig_idxbls[i]->remove_user();
101         orig_idxbls.remove_all();
102         for( int i=0,n=orig_copies.size(); i<n; ++i )
103                 orig_copies[i]->remove_user();
104         orig_copies.remove_all();
105         for( int i=0,n=needed_idxbls.size(); i<n; ++i )
106                 needed_idxbls[i]->remove_user();
107         needed_idxbls.remove_all();
108         for( int i=0,n=needed_copies.size(); i<n; ++i )
109                 needed_copies[i]->remove_user();
110         needed_copies.remove_all();
111 }
112
113 void ConvertRender::to_convert_path(char *new_path, Indexable *idxbl)
114 {
115         if( to_proxy ) {
116                 char *bp = idxbl->path, *cp = strrchr(bp, '/');
117                 if( cp ) bp = cp+1;
118                 char filename[BCTEXTLEN], proxy_path[BCTEXTLEN];
119                 strcpy(filename, bp);
120                 File::getenv_path(proxy_path, mwindow->preferences->nested_proxy_path);
121                 sprintf(new_path, "%s/%s", proxy_path, filename);
122         }
123         else
124                 strcpy(new_path, idxbl->path);
125         int n = strlen(suffix);
126         char *ep = new_path + strlen(new_path);
127         char *sfx = strrchr(new_path, '.');
128         if( sfx ) {
129 // insert suffix, path.sfx => path+suffix-sfx.ext
130                 char *bp = ep, *cp = (ep += n);
131                 while( --bp > sfx ) *--cp = *bp;
132                 *--cp = '-';
133         }
134         else {
135 // insert suffix, path => path+suffix.ext
136                 sfx = ep;  ep += n;
137         }
138         for( const char *cp=suffix; --n>=0; ++cp ) *sfx++ = *cp;
139         *ep++ = '.';
140         const char *ext = format_asset->format == FILE_FFMPEG ?
141                         format_asset->fformat :
142                         File::get_tag(format_asset->format);
143         while( *ext ) *ep++ = *ext++;
144         *ep = 0;
145 }
146
147 int ConvertRender::from_convert_path(char *path, Indexable *idxbl)
148 {
149         strcpy(path, idxbl->path);
150         char *ep = path + strlen(path);
151         const char *ext = format_asset->format == FILE_FFMPEG ?
152                         format_asset->fformat :
153                         File::get_tag(format_asset->format);
154         const char *rp = ext + strlen(ext);
155         do {
156                 --rp;  --ep;
157         } while( rp>=ext && ep>=path && *ep == *rp );
158         if( rp >= ext || ep < path && *--ep != '.' ) return 1;   // didnt find .ext
159         int n = strlen(suffix), len = 0;
160         char *lp = ep - n;  // <suffix-chars>+.ext
161         for( ; --lp>=path ; ++len ) {
162                 if( strncmp(lp, suffix, n) ) continue;
163                 if( !len || lp[n] == '-' ) break;
164         }
165         if( lp < path ) return 1;  // didnt find suffix
166         if( *(rp=lp+n) == '-' ) {
167 // remove suffix, path+suffix-sfx.ext >= path.sfx
168                 *lp++ = '.';  ++rp;
169                 while( rp < ep ) *lp++ = *rp++;
170         }
171 // remove suffix, path+suffix.ext => path
172         *lp = 0;
173         return 0;
174 }
175
176 double ConvertRender::get_video_length(Indexable *idxbl)
177 {
178         int64_t video_frames = idxbl->get_video_frames();
179         double frame_rate = idxbl->get_frame_rate();
180         if( video_frames < 0 && mwindow->edl->session->si_useduration )
181                 video_frames = mwindow->edl->session->si_duration * frame_rate;
182         if( video_frames < 0 ) video_frames = 1;
183         return !video_frames ? 0 : video_frames / frame_rate;
184 }
185
186 double ConvertRender::get_audio_length(Indexable *idxbl)
187 {
188         int64_t audio_samples = idxbl->get_audio_samples();
189         return !audio_samples ? 0 :
190                 (double)audio_samples / idxbl->get_sample_rate();
191 }
192
193 double ConvertRender::get_length(Indexable *idxbl)
194 {
195         return bmax(get_video_length(idxbl), get_audio_length(idxbl));
196 }
197
198 int ConvertRender::match_format(Asset *asset)
199 {
200 // close enough
201         return format_asset->audio_data == asset->audio_data &&
202                 format_asset->video_data == asset->video_data ? 1 : 0;
203 }
204
205 EDL *ConvertRender::convert_edl(EDL *edl, Indexable *idxbl)
206 {
207         Asset *copy_asset = edl->assets->get_asset(idxbl->path);
208         if( !copy_asset ) return 0;
209         if( !copy_asset->layers && !copy_asset->channels ) return 0;
210 // make a clip from 1st video track and audio tracks
211         EDL *copy_edl = new EDL(edl);
212         copy_edl->create_objects();
213         copy_edl->set_path(copy_asset->path);
214         char path[BCTEXTLEN];
215         FileSystem fs;  fs.extract_name(path, copy_asset->path);
216         strcpy(copy_edl->local_session->clip_title, path);
217         strcpy(copy_edl->local_session->clip_notes, _("Transcode clip"));
218
219         double video_length = get_video_length(idxbl);
220         double audio_length = get_audio_length(idxbl);
221         copy_edl->session->video_tracks =
222                  video_length > 0 ? 1 : 0;
223         copy_edl->session->audio_tracks =
224                  audio_length > 0 ? copy_asset->channels : 0;
225
226         copy_edl->create_default_tracks();
227         Track *current = copy_edl->session->video_tracks ?
228                 copy_edl->tracks->first : 0;
229         for( int vtrack=0; current; current=NEXT ) {
230                 if( current->data_type != TRACK_VIDEO ) continue;
231                 current->insert_asset(copy_asset, 0, video_length, 0, vtrack);
232                 break;
233         }
234         current = copy_edl->session->audio_tracks ?
235                 copy_edl->tracks->first : 0;
236         for( int atrack=0; current; current=NEXT ) {
237                 if( current->data_type != TRACK_AUDIO ) continue;
238                 current->insert_asset(copy_asset, 0, audio_length, 0, atrack);
239                 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
240                 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
241                 for( int i=0; i < MAXCHANNELS; ++i ) pan_auto->values[i] = 0;
242                 pan_auto->values[atrack++] = 1;
243                 if( atrack >= MAXCHANNELS ) atrack = 0;
244         }
245         copy_edl->folder_no = AW_MEDIA_FOLDER;
246         return copy_edl;
247 }
248
249 int ConvertRender::add_original(EDL *edl, Indexable *idxbl)
250 {
251         char new_path[BCTEXTLEN];
252 // if idxbl already a convert
253         if( !from_convert_path(new_path, idxbl) ) return 0;
254 // don't convert if not readable
255         if( idxbl->is_asset && access(idxbl->path, R_OK) ) return 0;
256 // found readable unconverted asset
257         to_convert_path(new_path, idxbl);
258 // add to orig_idxbls & orig_copies if it isn't already there.
259         int got_it = 0;
260         for( int i = 0; !got_it && i<orig_copies.size(); ++i )
261                 got_it = !strcmp(orig_copies[i]->path, new_path);
262         if( got_it ) return 0;
263         idxbl->add_user();
264         orig_idxbls.append(idxbl);
265         int needed = 1;
266         Asset *convert = edl->assets->get_asset(new_path);
267         if( !convert ) {
268                 convert = new Asset(new_path);
269                 FileSystem fs;
270                 if( fs.get_size(new_path) > 0 ) {
271 // copy already on disk
272                         int64_t orig_mtime = fs.get_date(idxbl->path);
273                         int64_t convert_mtime = fs.get_date(new_path);
274 // render needed if it is too old
275                         if( orig_mtime < convert_mtime ) {
276                                 File file;
277                                 int ret = file.open_file(mwindow->preferences, convert, 1, 0);
278 // render not needed if can use copy
279                                 if( ret == FILE_OK ) {
280                                         if( match_format(file.asset) ) {
281                                                 mwindow->mainindexes->add_indexable(convert);
282                                                 mwindow->mainindexes->start_build();
283                                                 needed = 0;
284                                         }
285                                         else
286                                                 needed = -1;
287                                 }
288                         }
289                 }
290         }
291         else if( match_format(convert) ) {
292 // dont render if copy already an assets
293                 convert->add_user();
294                 needed = 0;
295         }
296         else
297                 needed = -1;
298         if( needed < 0 ) {
299                 eprintf(_("transcode target file exists but is incorrect format:\n%s\n"
300                           "remove file from disk before transcode to new format.\n"), new_path);
301                 return -1;
302         }
303         orig_copies.append(convert);
304         if( needed ) {
305                 convert->copy_format(format_asset, 0);
306 // new compression parameters
307                 convert->video_data = format_asset->video_data;
308                 if( convert->video_data ) {
309                         convert->layers = 1;
310                         convert->width = idxbl->get_w();
311                         if( convert->width & 1 ) ++convert->width;
312                         convert->actual_width = convert->width;
313                         convert->height = idxbl->get_h();
314                         if( convert->height & 1 ) ++convert->height;
315                         convert->actual_height = convert->height;
316                         convert->frame_rate = mwindow->edl->session->frame_rate;
317                 }
318                 convert->audio_data = format_asset->audio_data;
319                 if( convert->audio_data ) {
320                         convert->sample_rate = mwindow->edl->session->sample_rate;
321                 }
322                 convert->folder_no = AW_MEDIA_FOLDER;
323                 add_needed(idxbl, convert);
324         }
325         return 1;
326 }
327
328 void ConvertRender::add_needed(Indexable *idxbl, Asset *convert)
329 {
330         needed_idxbls.append(idxbl);
331         idxbl->add_user();
332         needed_copies.append(convert);
333         convert->add_user();
334 }
335
336
337 int ConvertRender::is_canceled()
338 {
339         return progress->is_cancelled();
340 }
341
342 int ConvertRender::find_convertable_assets(EDL *edl)
343 {
344         reset();
345         Asset *orig_asset = edl->assets->first;
346         int count = 0;
347         for( ; orig_asset; orig_asset=orig_asset->next ) {
348                 int ret = add_original(edl, orig_asset);
349                 if( ret < 0 ) return -1;
350                 if( ret ) ++count;
351         }
352         return count;
353 }
354
355 void ConvertRender::set_format(Asset *asset, const char *suffix, int to_proxy)
356 {
357         delete [] this->suffix;
358         this->suffix = cstrdup(suffix);
359         if( !format_asset )
360                 format_asset = new Asset();
361         format_asset->copy_from(asset, 0);
362         this->to_proxy = to_proxy;
363 }
364
365 void ConvertRender::start_convert(float beep, int remove_originals)
366 {
367         this->beep = beep;
368         this->remove_originals = remove_originals;
369         start();
370 }
371
372 void ConvertRender::run()
373 {
374         mwindow->stop_brender();
375         result = 0;
376         total_rendered = 0;
377         failed = 0;  canceled = 0;
378
379         progress_timer->update();
380         start_progress();
381
382         for( int i=0; !failed && !canceled && i<needed_copies.size(); ++i )
383                 create_copy(i);
384
385         canceled = progress->is_cancelled();
386 printf(_("convert: failed=%d canceled=%d\n"), failed, canceled);
387         double elapsed_time = progress_timer->get_scaled_difference(1);
388
389         char elapsed[BCSTRLEN], text[BCSTRLEN];
390         Units::totext(elapsed, elapsed_time, TIME_HMS2);
391         printf(_("TranscodeRender::run: done in %s\n"), elapsed);
392         if( canceled )
393                 strcpy(text, _("transcode cancelled"));
394         else if( failed )
395                 strcpy(text, _("transcode failed"));
396         else
397                 sprintf(text, _("transcode %d files, render time %s"),
398                         needed_copies.size(), elapsed);
399 // stop progress bar
400         stop_progress(text);
401
402         if( !failed ) {
403                 mwindow->finish_convert(remove_originals);
404         }
405         else if( !canceled ) {
406                 eprintf(_("Error making transcode."));
407         }
408
409         if( !canceled && beep > 0 ) {
410                 if( failed ) {
411                         mwindow->beep(4000., 0.5, beep);
412                         usleep(250000);
413                         mwindow->beep(1000., 0.5, beep);
414                         usleep(250000);
415                         mwindow->beep(4000., 0.5, beep);
416                 }
417                 else
418                         mwindow->beep(2000., 2.0, beep);
419         }
420         mwindow->restart_brender();
421 }
422
423 void ConvertRender::start_progress()
424 {
425         double total_len= 0;
426         for( int i = 0; i < needed_idxbls.size(); i++ ) {
427                 Indexable *orig_idxbl = needed_idxbls[i];
428                 double length = get_length(orig_idxbl);
429                 total_len += length;
430         }
431         int64_t total_samples = total_len * format_asset->sample_rate;
432         mwindow->gui->lock_window("Render::start_progress");
433         progress = mwindow->mainprogress->
434                 start_progress(_("Transcode files..."), total_samples);
435         mwindow->gui->unlock_window();
436         convert_progress = new ConvertProgress(mwindow, this);
437         convert_progress->start();
438 }
439
440 void ConvertRender::stop_progress(const char *msg)
441 {
442         delete convert_progress;  convert_progress = 0;
443         mwindow->gui->lock_window("ConvertRender::stop_progress");
444         progress->update(0);
445         mwindow->mainprogress->end_progress(progress);
446         progress = 0;
447         mwindow->gui->show_message(msg);
448         mwindow->gui->update_default_message();
449         mwindow->gui->unlock_window();
450 }
451
452
453 ConvertPackageRenderer::ConvertPackageRenderer(ConvertRender *render)
454  : PackageRenderer()
455 {
456         this->render = render;
457 }
458
459 ConvertPackageRenderer::~ConvertPackageRenderer()
460 {
461 }
462
463 int ConvertPackageRenderer::get_master()
464 {
465         return 1;
466 }
467
468 int ConvertPackageRenderer::get_result()
469 {
470         return render->result;
471 }
472
473 void ConvertPackageRenderer::set_result(int value)
474 {
475         if( value )
476                 render->result = value;
477 }
478
479 void ConvertPackageRenderer::set_progress(int64_t value)
480 {
481         render->counter_lock->lock("ConvertPackageRenderer::set_progress");
482 // Increase total rendered for all nodes
483         render->total_rendered += value;
484         render->counter_lock->unlock();
485 }
486
487 int ConvertPackageRenderer::progress_cancelled()
488 {
489         return render->progress && render->progress->is_cancelled();
490 }
491
492 ConvertProgress::ConvertProgress(MWindow *mwindow, ConvertRender *render)
493  : Thread(1, 0, 0)
494 {
495         this->mwindow = mwindow;
496         this->render = render;
497         last_value = 0;
498 }
499
500 ConvertProgress::~ConvertProgress()
501 {
502         cancel();
503         join();
504 }
505
506 void ConvertProgress::run()
507 {
508         Thread::disable_cancel();
509         for( ;; ) {
510                 if( render->total_rendered != last_value ) {
511                         render->progress->update(render->total_rendered);
512                         last_value = render->total_rendered;
513                 }
514
515                 Thread::enable_cancel();
516                 sleep(1);
517                 Thread::disable_cancel();
518         }
519 }
520
521 void ConvertRender::create_copy(int i)
522 {
523         Indexable *orig_idxbl = needed_idxbls[i];
524         Asset *needed_copy = needed_copies[i];
525         EDL *edl = convert_edl(mwindow->edl, orig_idxbl);
526         double length = get_length(orig_idxbl);
527         renderer = new ConvertPackageRenderer(this);
528         renderer->initialize(mwindow, edl, mwindow->preferences, needed_copy);
529         PackageDispatcher dispatcher;
530         dispatcher.create_packages(mwindow, edl, mwindow->preferences,
531                 SINGLE_PASS, needed_copy, 0, length, 0);
532         RenderPackage *package = dispatcher.get_package(0);
533         if( !renderer->render_package(package) ) {
534                 Asset *asset = mwindow->edl->assets->update(needed_copy);
535                 mwindow->mainindexes->add_indexable(asset);
536                 mwindow->mainindexes->start_build();
537         }
538         else
539                 failed = 1;
540         delete renderer;  renderer = 0;
541         edl->remove_user();
542 }
543
544 ConvertWindow::ConvertWindow(MWindow *mwindow, ConvertDialog *dialog, int x, int y)
545  : BC_Window(_(PROGRAM_NAME ": Transcode settings"), x, y, WIDTH, HEIGHT,
546                 -1, -1, 0, 0, 1)
547 {
548         this->mwindow = mwindow;
549         this->dialog = dialog;
550         format_tools = 0;
551 // *** CONTEXT_HELP ***
552         context_help_set_keyword("Transcode");
553 }
554
555 ConvertWindow::~ConvertWindow()
556 {
557         lock_window("ConvertWindow::~ConvertWindow");
558         delete format_tools;
559         unlock_window();
560 }
561
562
563 void ConvertWindow::create_objects()
564 {
565         lock_window("ConvertWindow::create_objects");
566         int margin = mwindow->theme->widget_border;
567         int lmargin = margin + xS(10);
568
569         int x = lmargin;
570         int y = margin + yS(10);
571
572         BC_Title *text;
573         add_subwindow(text = new BC_Title(x, y,
574                 _("Render untagged assets and replace in project")));
575         y += text->get_h() + margin + yS(10);
576         int y1 = y;
577         y += BC_Title::calculate_h(this, _("Tag suffix:")) + margin + yS(10);
578
579         x = lmargin;
580         format_tools = new ConvertFormatTools(mwindow, this, dialog->asset);
581         format_tools->create_objects(x, y, 1, 1, 1, 1, 0, 1, 0, 1, // skip the path
582                 0, 0);
583
584         x = lmargin;
585         add_subwindow(text = new BC_Title(x, y1, _("Tag suffix:")));
586         x = format_tools->format_text->get_x();
587         add_subwindow(suffix_text = new ConvertSuffixText(this, dialog, x, y1));
588         x = lmargin;
589         y += margin + yS(10);
590
591         add_subwindow(remove_originals = new ConvertRemoveOriginals(this, x, y));
592         x = lmargin;
593         y += remove_originals->get_h() + margin;
594         add_subwindow(to_proxy_path = new ConvertToProxyPath(this, x, y));
595         y += to_proxy_path->get_h() + margin;
596
597         add_subwindow(beep_on_done = new ConvertBeepOnDone(this, x, y));
598         x += beep_on_done->get_w() + margin + xS(10);
599         add_subwindow(new BC_Title(x, y+yS(10), _("Beep on done volume")));
600 //      y += beep_on_done->get_h() + margin;
601
602         add_subwindow(new BC_OKButton(this));
603         add_subwindow(new BC_CancelButton(this));
604         show_window(1);
605         unlock_window();
606 }
607
608 ConvertSuffixText::ConvertSuffixText(ConvertWindow *gui,
609                 ConvertDialog *dialog, int x, int y)
610  : BC_TextBox(x, y, 160, 1, dialog->suffix)
611 {
612         this->gui = gui;
613         this->dialog = dialog;
614 }
615
616 ConvertSuffixText::~ConvertSuffixText()
617 {
618 }
619
620 int ConvertSuffixText::handle_event()
621 {
622         strcpy(dialog->suffix, get_text());
623         return 1;
624 }
625
626 ConvertFormatTools::ConvertFormatTools(MWindow *mwindow, ConvertWindow *gui, Asset *asset)
627  : FormatTools(mwindow, gui, asset)
628 {
629         this->gui = gui;
630 }
631
632 void ConvertFormatTools::update_format()
633 {
634         asset->save_defaults(mwindow->defaults, "CONVERT_", 1, 1, 0, 0, 0);
635         FormatTools::update_format();
636 }
637
638
639 ConvertMenuItem::ConvertMenuItem(MWindow *mwindow)
640  : BC_MenuItem(_("Transcode..."),  _("Alt-e"), 'e')
641 {
642         this->mwindow = mwindow;
643         set_alt();
644         dialog = 0;
645 }
646 ConvertMenuItem::~ConvertMenuItem()
647 {
648         delete dialog;
649 }
650
651 void ConvertMenuItem::create_objects()
652 {
653         dialog = new ConvertDialog(mwindow);
654 }
655
656 int ConvertMenuItem::handle_event()
657 {
658         mwindow->gui->unlock_window();
659         dialog->start();
660         mwindow->gui->lock_window("ConvertMenuItem::handle_event");
661         return 1;
662 }
663
664
665 ConvertDialog::ConvertDialog(MWindow *mwindow)
666 {
667         this->mwindow = mwindow;
668         gui = 0;
669         asset = new Asset;
670         strcpy(suffix, ".transcode");
671 // quicker than some, not as good as others
672         asset->format = FILE_FFMPEG;
673         strcpy(asset->fformat, "mp4");
674         strcpy(asset->vcodec, "h264.mp4");
675         asset->ff_video_bitrate = 2560000;
676         asset->video_data = 1;
677         strcpy(asset->acodec, "h264.mp4");
678         asset->ff_audio_bitrate = 256000;
679         asset->audio_data = 1;
680         remove_originals = 1;
681         beep = 0;
682         to_proxy = 0;
683 }
684
685 ConvertDialog::~ConvertDialog()
686 {
687         close_window();
688         asset->remove_user();
689 }
690
691 BC_Window* ConvertDialog::new_gui()
692 {
693         asset->format = FILE_FFMPEG;
694         asset->frame_rate = mwindow->edl->session->frame_rate;
695         asset->sample_rate = mwindow->edl->session->sample_rate;
696         asset->load_defaults(mwindow->defaults, "CONVERT_", 1, 1, 0, 1, 0);
697         remove_originals = mwindow->defaults->get("CONVERT_REMOVE_ORIGINALS", remove_originals);
698         beep = mwindow->defaults->get("CONVERT_BEEP", beep);
699         to_proxy = mwindow->defaults->get("CONVERT_TO_PROXY", to_proxy);
700         mwindow->defaults->get("CONVERT_SUFFIX", suffix);
701         mwindow->gui->lock_window("ConvertDialog::new_gui");
702         int cx, cy;
703         mwindow->gui->get_abs_cursor(cx, cy);
704         gui = new ConvertWindow(mwindow, this, cx - WIDTH/2, cy - HEIGHT/2);
705         gui->create_objects();
706         mwindow->gui->unlock_window();
707         return gui;
708 }
709
710 void ConvertDialog::handle_close_event(int result)
711 {
712         if( result ) return;
713         mwindow->defaults->update("CONVERT_SUFFIX", suffix);
714         mwindow->defaults->update("CONVERT_REMOVE_ORIGINALS", remove_originals);
715         mwindow->defaults->update("CONVERT_BEEP", beep);
716         mwindow->defaults->update("CONVERT_TO_PROXY", to_proxy);
717         asset->save_defaults(mwindow->defaults, "CONVERT_", 1, 1, 0, 1, 0);
718         mwindow->start_convert(asset, suffix, beep, to_proxy, remove_originals);
719 }
720
721
722 ConvertRemoveOriginals::ConvertRemoveOriginals(ConvertWindow *gui, int x, int y)
723  : BC_CheckBox(x, y, gui->dialog->remove_originals, _("Remove originals from project"))
724 {
725         this->gui = gui;
726 }
727
728 ConvertRemoveOriginals::~ConvertRemoveOriginals()
729 {
730 }
731
732 int ConvertRemoveOriginals::handle_event()
733 {
734         gui->dialog->remove_originals = get_value();
735         return 1;
736 }
737
738 ConvertToProxyPath::ConvertToProxyPath(ConvertWindow *gui, int x, int y)
739  : BC_CheckBox(x, y, gui->dialog->to_proxy, _("Into Nested Proxy directory"))
740 {
741         this->gui = gui;
742 }
743
744 ConvertToProxyPath::~ConvertToProxyPath()
745 {
746 }
747
748 int ConvertToProxyPath::handle_event()
749 {
750         gui->dialog->to_proxy = get_value();
751         return 1;
752 }
753
754 ConvertBeepOnDone::ConvertBeepOnDone(ConvertWindow *gui, int x, int y)
755  : BC_FPot(x, y, gui->dialog->beep*100.f, 0.f, 100.f)
756 {
757         this->gui = gui;
758 }
759
760 int ConvertBeepOnDone::handle_event()
761 {
762         gui->dialog->beep = get_value()/100.f;
763         return 1;
764 }
765