1fa0f15e6d03e55c960c2079fa0d1334713c4cb9
[goodguy/history.git] / cinelerra-5.1 / cinelerra / new.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "clip.h"
23 #include "cplayback.h"
24 #include "cwindow.h"
25 #include "bchash.h"
26 #include "edl.h"
27 #include "edlsession.h"
28 #include "filexml.h"
29 #include "interlacemodes.h"
30 #include "language.h"
31 #include "levelwindow.h"
32 #include "mainundo.h"
33 #include "mainmenu.h"
34 #include "mutex.h"
35 #include "mwindow.h"
36 #include "mwindowgui.h"
37 #include "new.h"
38 #include "newpresets.h"
39 #include "mainsession.h"
40 #include "patchbay.h"
41 #include "preferences.h"
42 #include "theme.h"
43 #include "transportque.h"
44 #include "videowindow.h"
45 #include "vplayback.h"
46 #include "vwindow.h"
47
48
49 #include <string.h>
50
51
52 #define WIDTH 640
53 #define HEIGHT 425
54
55 New::New(MWindow *mwindow)
56 {
57         this->mwindow = mwindow;
58         script = 0;
59         new_edl = 0;
60         thread = 0;
61 }
62
63 New::~New()
64 {
65         delete thread;
66 }
67
68 int New::handle_event()
69 {
70         mwindow->gui->unlock_window();
71         mwindow->edl->save_defaults(mwindow->defaults);
72         create_new_edl();
73         thread->start();
74         mwindow->gui->lock_window("New::handle_event");
75
76         return 1;
77 }
78
79 void New::create_new_edl()
80 {
81         if( !new_edl ) {
82                 new_edl = new EDL;
83                 new_edl->create_objects();
84                 new_edl->load_defaults(mwindow->defaults);
85         }
86 }
87
88
89 int New::create_new_project(int load_mode)
90 {
91         mwindow->stop_playback(0);
92         mwindow->gui->lock_window();
93         mwindow->reset_caches();
94
95         memcpy(new_edl->session->achannel_positions,
96                 &mwindow->preferences->channel_positions[new_edl->session->audio_channels - 1],
97                 sizeof(new_edl->session->achannel_positions));
98         new_edl->session->boundaries();
99         new_edl->create_default_tracks();
100
101         mwindow->undo->update_undo_before();
102         mwindow->set_filename("");
103         ArrayList<EDL *>new_edls;
104         new_edls.append(new_edl);
105         mwindow->paste_edls(&new_edls, load_mode, 0,0,0,0,0,0);
106         new_edl->remove_user();
107         new_edl = 0;
108
109 // Load file sequence
110         mwindow->update_project(load_mode);
111         mwindow->session->changes_made = 0;
112         mwindow->undo->update_undo_after(load_mode == LOADMODE_REPLACE ?
113                 _("New Project") : _("Append Project"), LOAD_ALL);
114         mwindow->gui->unlock_window();
115         return 0;
116 }
117
118 NewProject::NewProject(MWindow *mwindow)
119  : BC_MenuItem(_("New Project..."), "n", 'n'), New(mwindow)
120 {
121 }
122 NewProject::~NewProject()
123 {
124 }
125
126 void NewProject::create_objects()
127 {
128         thread = new NewThread(mwindow, this,
129                 _(PROGRAM_NAME ": New Project"), LOADMODE_REPLACE);
130 }
131
132 AppendTracks::AppendTracks(MWindow *mwindow)
133  : BC_MenuItem(_("Append to Project..."), "N", 'N'), New(mwindow)
134 {
135         set_shift(1);
136 }
137 AppendTracks::~AppendTracks()
138 {
139 }
140
141 void AppendTracks::create_objects()
142 {
143         thread = new NewThread(mwindow, this,
144                 _(PROGRAM_NAME ": Append to Project"), LOADMODE_NEW_TRACKS);
145 }
146
147
148 NewThread::NewThread(MWindow *mwindow, New *new_project,
149                 const char *title, int load_mode)
150  : BC_DialogThread()
151 {
152         this->mwindow = mwindow;
153         this->new_project = new_project;
154         this->title = title;
155         this->load_mode = load_mode;
156         nwindow = 0;
157 }
158
159 NewThread::~NewThread()
160 {
161         close_window();
162 }
163
164 BC_Window* NewThread::new_gui()
165 {
166         mwindow->edl->save_defaults(mwindow->defaults);
167         new_project->create_new_edl();
168         load_defaults();
169
170         mwindow->gui->lock_window("NewThread::new_gui");
171         int x = mwindow->gui->get_pop_cursor_x(0);
172         int y = mwindow->gui->get_pop_cursor_y(0);
173
174         nwindow = new NewWindow(mwindow, this, x, y);
175         nwindow->create_objects();
176         mwindow->gui->unlock_window();
177         return nwindow;
178 }
179
180 void NewThread::handle_close_event(int result)
181 {
182         if( !new_project->new_edl ) return;
183         new_project->new_edl->save_defaults(mwindow->defaults);
184         mwindow->defaults->save();
185
186         if( result ) {
187 // Aborted
188                 if( !new_project->new_edl->Garbage::remove_user() )
189                         new_project->new_edl = 0;
190         }
191         else {
192                 new_project->create_new_project(load_mode);
193         }
194 }
195
196 int NewThread::load_defaults()
197 {
198         auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
199         return 0;
200 }
201
202 int NewThread::save_defaults()
203 {
204         mwindow->defaults->update("AUTOASPECT", auto_aspect);
205         return 0;
206 }
207
208 int NewThread::update_aspect()
209 {
210         if( auto_aspect ) {
211                 char string[BCTEXTLEN];
212                 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
213                         new_project->new_edl->session->aspect_h,
214                         new_project->new_edl->session->output_w,
215                         new_project->new_edl->session->output_h);
216                 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
217                 if( nwindow->aspect_w_text ) nwindow->aspect_w_text->update(string);
218                 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
219                 if( nwindow->aspect_h_text )nwindow->aspect_h_text->update(string);
220         }
221         return 0;
222 }
223
224
225 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
226  : BC_Window(new_thread->title, x, y,
227                 WIDTH, new_thread->load_mode == LOADMODE_REPLACE ? HEIGHT : HEIGHT-180,
228                 -1, -1, 0, 0, 1)
229 {
230         this->mwindow = mwindow;
231         this->new_thread = new_thread;
232         this->new_edl = new_thread->new_project->new_edl;
233         format_presets = 0;
234         atracks = 0;
235         achannels = 0;
236         sample_rate = 0;
237         vtracks = 0;
238         frame_rate = 0;
239         output_w_text = 0;
240         output_h_text = 0;
241         aspect_w_text = 0;
242         aspect_h_text = 0;
243         interlace_pulldown = 0;
244         color_model = 0;
245 }
246
247 NewWindow::~NewWindow()
248 {
249         lock_window("NewWindow::~NewWindow");
250         delete format_presets;
251         unlock_window();
252 }
253
254 void NewWindow::create_objects()
255 {
256         int x = 10, y = 10, x1, y1;
257         BC_TextBox *textbox;
258
259         lock_window("NewWindow::create_objects");
260         mwindow->theme->draw_new_bg(this);
261
262         add_subwindow( new BC_Title(x, y, new_thread->load_mode == LOADMODE_REPLACE ?
263                         _("Parameters for the new project:") :
264                         _("Parameters for additional tracks:") ) );
265         y += 20;
266
267         format_presets = new NewPresets(mwindow,
268                 this,
269                 x,
270                 y);
271         format_presets->create_objects();
272         x = format_presets->x;
273         y = format_presets->y;
274
275         y += 40;
276         y1 = y;
277         add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
278         y += 30;
279
280         x1 = x;
281         add_subwindow(new BC_Title(x1, y, _("Tracks:")));
282         x1 += 100;
283         add_subwindow(atracks = new NewATracks(this, "", x1, y));
284         x1 += atracks->get_w();
285         add_subwindow(new NewATracksTumbler(this, x1, y));
286         y += atracks->get_h() + 5;
287
288         if( new_thread->load_mode == LOADMODE_REPLACE ) {
289                 x1 = x;
290                 add_subwindow(new BC_Title(x1, y, _("Channels:")));
291                 x1 += 100;
292                 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
293                 x1 += achannels->get_w();
294                 add_subwindow(new NewAChannelsTumbler(this, x1, y));
295                 y += achannels->get_h() + 5;
296
297                 x1 = x;
298                 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
299                 x1 += 100;
300                 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
301                 x1 += sample_rate->get_w();
302                 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
303         }
304
305         x += 250;
306         y = y1;
307         add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
308         y += 30;
309         x1 = x;
310         add_subwindow(new BC_Title(x1, y, _("Tracks:")));
311         x1 += 115;
312         add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
313         x1 += vtracks->get_w();
314         add_subwindow(new NewVTracksTumbler(this, x1, y));
315         y += vtracks->get_h() + 5;
316
317         if( new_thread->load_mode == LOADMODE_REPLACE ) {
318 //              x1 = x;
319 //              add_subwindow(new BC_Title(x1, y, _("Channels:")));
320 //              x1 += 100;
321 //              add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
322 //              x1 += vchannels->get_w();
323 //              add_subwindow(new NewVChannelsTumbler(this, x1, y));
324 //              y += vchannels->get_h() + 5;
325                 x1 = x;
326                 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
327                 x1 += 115;
328                 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
329                 x1 += frame_rate->get_w();
330                 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
331                 y += frame_rate->get_h() + 5;
332         }
333 //      x1 = x;
334 //      add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
335 //      x1 += 100;
336 //      add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
337 //      x1 += canvas_w_text->get_w() + 2;
338 //      add_subwindow(new BC_Title(x1, y, "x"));
339 //      x1 += 10;
340 //      add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
341 //      x1 += canvas_h_text->get_w();
342 //      add_subwindow(new FrameSizePulldown(mwindow,
343 //              canvas_w_text,
344 //              canvas_h_text,
345 //              x1,
346 //              y));
347 //      x1 += 100;
348 //      add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
349 //      y += canvas_h_text->get_h() + 5;
350
351         x1 = x;
352         add_subwindow(new BC_Title(x1, y, _("Track size:")));
353         x1 += 115;
354         add_subwindow(output_w_text = new NewOutputW(this, x1, y));
355         x1 += output_w_text->get_w() + 2;
356         add_subwindow(new BC_Title(x1, y, "x"));
357         x1 += 10;
358         add_subwindow(output_h_text = new NewOutputH(this, x1, y));
359         x1 += output_h_text->get_w();
360         FrameSizePulldown *pulldown;
361         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
362                 output_w_text,
363                 output_h_text,
364                 x1,
365                 y));
366         x1 += pulldown->get_w() + 10;
367         add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
368         y += output_h_text->get_h() + 5;
369
370         if( new_thread->load_mode == LOADMODE_REPLACE ) {
371                 x1 = x;
372                 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
373                 x1 += 115;
374                 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
375                 x1 += aspect_w_text->get_w() + 2;
376                 add_subwindow(new BC_Title(x1, y, ":"));
377                 x1 += 10;
378                 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
379                 x1 += aspect_h_text->get_w();
380                 add_subwindow(new AspectPulldown(mwindow,
381                         aspect_w_text, aspect_h_text, x1, y));
382
383                 x1 = aspect_w_text->get_x();
384                 y += aspect_w_text->get_h() + 5;
385                 add_subwindow(new NewAspectAuto(this, x1, y));
386                 y += 40;
387                 BC_Title *title;
388                 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
389                 x1 = x + title->get_w();
390                 y1 = y;  y += title->get_h() + 10;
391                 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
392                 int x2 = x + title->get_w();
393                 int y2 = y;  y += title->get_h() + 10;
394                 if( x1 < x2 ) x1 = x2;
395                 x1 += 20;
396                 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
397                 add_subwindow(color_model = new ColormodelPulldown(mwindow,
398                         textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
399                 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
400                 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
401                         textbox, &new_edl->session->interlace_mode,
402                         (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
403                         x1+textbox->get_w(), y2));
404         }
405
406         add_subwindow(new BC_OKButton(this,
407                 mwindow->theme->get_image_set("new_ok_images")));
408         add_subwindow(new BC_CancelButton(this,
409                 mwindow->theme->get_image_set("new_cancel_images")));
410         flash();
411         update();
412         show_window();
413         unlock_window();
414 }
415
416 int NewWindow::update()
417 {
418         if( atracks ) atracks->update((int64_t)new_edl->session->audio_tracks);
419         if( achannels ) achannels->update((int64_t)new_edl->session->audio_channels);
420         if( sample_rate ) sample_rate->update((int64_t)new_edl->session->sample_rate);
421         if( vtracks ) vtracks->update((int64_t)new_edl->session->video_tracks);
422         if( frame_rate ) frame_rate->update((float)new_edl->session->frame_rate);
423         if( output_w_text ) output_w_text->update((int64_t)new_edl->session->output_w);
424         if( output_h_text ) output_h_text->update((int64_t)new_edl->session->output_h);
425         if( aspect_w_text ) aspect_w_text->update((float)new_edl->session->aspect_w);
426         if( aspect_h_text ) aspect_h_text->update((float)new_edl->session->aspect_h);
427         if( interlace_pulldown ) interlace_pulldown->update(new_edl->session->interlace_mode);
428         if( color_model ) color_model->update_value(new_edl->session->color_model);
429         return 0;
430 }
431
432
433 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
434  : FormatPresets(mwindow, gui, 0, x, y)
435 {
436 }
437
438 NewPresets::~NewPresets()
439 {
440 }
441
442 int NewPresets::handle_event()
443 {
444         new_gui->update();
445         return 1;
446 }
447
448 EDL* NewPresets::get_edl()
449 {
450         return new_gui->new_edl;
451 }
452
453
454 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
455  : BC_TextBox(x, y, 90, 1, text)
456 {
457         this->nwindow = nwindow;
458 }
459
460 int NewATracks::handle_event()
461 {
462         nwindow->new_edl->session->audio_tracks = atol(get_text());
463         return 1;
464 }
465
466 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
467  : BC_Tumbler(x, y)
468 {
469         this->nwindow = nwindow;
470 }
471 int NewATracksTumbler::handle_up_event()
472 {
473         nwindow->new_edl->session->audio_tracks++;
474         nwindow->new_edl->boundaries();
475         nwindow->update();
476         return 1;
477 }
478 int NewATracksTumbler::handle_down_event()
479 {
480         nwindow->new_edl->session->audio_tracks--;
481         nwindow->new_edl->boundaries();
482         nwindow->update();
483         return 1;
484 }
485
486
487 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
488  : BC_TextBox(x, y, 90, 1, text)
489 {
490         this->nwindow = nwindow;
491 }
492
493 int NewAChannels::handle_event()
494 {
495         nwindow->new_edl->session->audio_channels = atol(get_text());
496         return 1;
497 }
498
499
500 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
501  : BC_Tumbler(x, y)
502 {
503         this->nwindow = nwindow;
504 }
505 int NewAChannelsTumbler::handle_up_event()
506 {
507         nwindow->new_edl->session->audio_channels++;
508         nwindow->new_edl->boundaries();
509         nwindow->update();
510         return 1;
511 }
512 int NewAChannelsTumbler::handle_down_event()
513 {
514         nwindow->new_edl->session->audio_channels--;
515         nwindow->new_edl->boundaries();
516         nwindow->update();
517         return 1;
518 }
519
520
521 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
522  : BC_TextBox(x, y, 90, 1, text)
523 {
524         this->nwindow = nwindow;
525 }
526
527 int NewSampleRate::handle_event()
528 {
529         nwindow->new_edl->session->sample_rate = atol(get_text());
530         return 1;
531 }
532
533
534 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
535  : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
536         &mwindow->theme->sample_rates, 0, 0, 1, 0, 1)
537 {
538         this->mwindow = mwindow;
539         this->output = output;
540 }
541 int SampleRatePulldown::handle_event()
542 {
543         char *text = get_selection(0, 0)->get_text();
544         output->update(text);
545         output->handle_event();
546         return 1;
547 }
548
549
550 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
551  : BC_TextBox(x, y, 90, 1, text)
552 {
553         this->nwindow = nwindow;
554 }
555
556 int NewVTracks::handle_event()
557 {
558         nwindow->new_edl->session->video_tracks = atol(get_text());
559         return 1;
560 }
561
562
563 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
564  : BC_Tumbler(x, y)
565 {
566         this->nwindow = nwindow;
567 }
568 int NewVTracksTumbler::handle_up_event()
569 {
570         nwindow->new_edl->session->video_tracks++;
571         nwindow->new_edl->boundaries();
572         nwindow->update();
573         return 1;
574 }
575 int NewVTracksTumbler::handle_down_event()
576 {
577         nwindow->new_edl->session->video_tracks--;
578         nwindow->new_edl->boundaries();
579         nwindow->update();
580         return 1;
581 }
582
583
584 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
585  : BC_TextBox(x, y, 90, 1, text)
586 {
587         this->nwindow = nwindow;
588 }
589
590 int NewVChannels::handle_event()
591 {
592         nwindow->new_edl->session->video_channels = atol(get_text());
593         return 1;
594 }
595
596
597 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
598  : BC_Tumbler(x, y)
599 {
600         this->nwindow = nwindow;
601 }
602 int NewVChannelsTumbler::handle_up_event()
603 {
604         nwindow->new_edl->session->video_channels++;
605         nwindow->new_edl->boundaries();
606         nwindow->update();
607         return 1;
608 }
609 int NewVChannelsTumbler::handle_down_event()
610 {
611         nwindow->new_edl->session->video_channels--;
612         nwindow->new_edl->boundaries();
613         nwindow->update();
614         return 1;
615 }
616
617
618 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
619  : BC_TextBox(x, y, 90, 1, text)
620 {
621         this->nwindow = nwindow;
622 }
623
624 int NewFrameRate::handle_event()
625 {
626         nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
627         return 1;
628 }
629
630
631 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
632         BC_TextBox *output, int x, int y)
633  : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
634         &mwindow->theme->frame_rates, 0, 0, 1, 0, 1)
635 {
636         this->mwindow = mwindow;
637         this->output = output;
638 }
639 int FrameRatePulldown::handle_event()
640 {
641         char *text = get_selection(0, 0)->get_text();
642         output->update(text);
643         output->handle_event();
644         return 1;
645 }
646
647 FrameSizePulldown::FrameSizePulldown(Theme *theme,
648                 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
649  : BC_ListBox(x, y, 180, 250, LISTBOX_TEXT,
650         &theme->frame_sizes, 0, 0, 1, 0, 1)
651 {
652         this->theme = theme;
653         this->output_w = output_w;
654         this->output_h = output_h;
655 }
656
657 int FrameSizePulldown::handle_event()
658 {
659         char *text = get_selection(0, 0)->get_text();
660         char string[BCTEXTLEN];
661         int64_t w, h;
662         char *ptr;
663
664         strcpy(string, text);
665         ptr = strrchr(string, 'x');
666         if( ptr ) {
667                 ptr++;
668                 h = atol(ptr);
669
670                 *--ptr = 0;
671                 w = atol(string);
672                 output_w->update(w);
673                 output_h->update(h);
674                 output_w->handle_event();
675                 output_h->handle_event();
676         }
677         return 1;
678 }
679
680
681 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
682  : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
683 {
684         this->nwindow = nwindow;
685 }
686 int NewOutputW::handle_event()
687 {
688         nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
689         nwindow->new_thread->update_aspect();
690         return 1;
691 }
692
693
694 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
695  : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
696 {
697         this->nwindow = nwindow;
698 }
699 int NewOutputH::handle_event()
700 {
701         nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
702         nwindow->new_thread->update_aspect();
703         return 1;
704 }
705
706
707 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
708  : BC_TextBox(x, y, 70, 1, text)
709 {
710         this->nwindow = nwindow;
711 }
712
713 int NewAspectW::handle_event()
714 {
715         nwindow->new_edl->session->aspect_w = atof(get_text());
716         return 1;
717 }
718
719
720 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
721  : BC_TextBox(x, y, 70, 1, text)
722 {
723         this->nwindow = nwindow;
724 }
725
726 int NewAspectH::handle_event()
727 {
728         nwindow->new_edl->session->aspect_h = atof(get_text());
729         return 1;
730 }
731
732
733 AspectPulldown::AspectPulldown(MWindow *mwindow,
734                 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
735  : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
736         &mwindow->theme->aspect_ratios, 0, 0, 1, 0, 1)
737 {
738         this->mwindow = mwindow;
739         this->output_w = output_w;
740         this->output_h = output_h;
741 }
742
743 int AspectPulldown::handle_event()
744 {
745         char *text = get_selection(0, 0)->get_text();
746         char string[BCTEXTLEN];
747         float w, h;
748         char *ptr;
749
750         strcpy(string, text);
751         ptr = strrchr(string, ':');
752         if( ptr ) {
753                 ptr++;
754                 h = atof(ptr);
755
756                 *--ptr = 0;
757                 w = atof(string);
758                 output_w->update(w);
759                 output_h->update(h);
760                 output_w->handle_event();
761                 output_h->handle_event();
762         }
763         return 1;
764 }
765
766
767 ColormodelItem::ColormodelItem(const char *text, int value)
768  : BC_ListBoxItem(text)
769 {
770         this->value = value;
771 }
772
773 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
774                 BC_TextBox *output_text, int *output_value, int x, int y)
775  : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT,
776         (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels, 0, 0, 1, 0, 1)
777 {
778         this->mwindow = mwindow;
779         this->output_text = output_text;
780         this->output_value = output_value;
781         output_text->update(colormodel_to_text());
782 }
783
784 int ColormodelPulldown::handle_event()
785 {
786         output_text->update(get_selection(0, 0)->get_text());
787         *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
788         return 1;
789 }
790
791 const char* ColormodelPulldown::colormodel_to_text()
792 {
793         for( int i=0; i<mwindow->colormodels.total; ++i )
794                 if( mwindow->colormodels.values[i]->value == *output_value )
795                         return mwindow->colormodels.values[i]->get_text();
796         return _("Unknown");
797 }
798
799 void ColormodelPulldown::update_value(int value)
800 {
801         *output_value = value;
802         output_text->update(colormodel_to_text());
803 }
804
805
806 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
807  : BC_ListBoxItem(text)
808 {
809         this->value = value;
810 }
811
812 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
813                 BC_TextBox *output_text,
814                 int *output_value,
815                 ArrayList<BC_ListBoxItem*> *data,
816                 int x,
817                 int y)
818  : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
819 {
820         this->mwindow = mwindow;
821         this->output_text = output_text;
822         this->output_value = output_value;
823         output_text->update(interlacemode_to_text());
824 }
825
826 int InterlacemodePulldown::handle_event()
827 {
828         output_text->update(get_selection(0, 0)->get_text());
829         *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
830         return 1;
831 }
832
833 const char* InterlacemodePulldown::interlacemode_to_text()
834 {
835         ilacemode_to_text(this->string,*output_value);
836         return (this->string);
837 }
838
839 int InterlacemodePulldown::update(int interlace_mode)
840 {
841         *output_value = interlace_mode;
842         output_text->update(interlacemode_to_text());
843         return 1;
844 }
845
846
847 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
848  : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
849 {
850         this->nwindow = nwindow;
851 }
852 NewAspectAuto::~NewAspectAuto()
853 {
854 }
855 int NewAspectAuto::handle_event()
856 {
857         nwindow->new_thread->auto_aspect = get_value();
858         nwindow->new_thread->update_aspect();
859         return 1;
860 }
861
862
863 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
864  : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
865 {
866         this->mwindow = mwindow;
867         this->gui = gui;
868         set_tooltip(_("Swap dimensions"));
869 }
870
871 int NewSwapExtents::handle_event()
872 {
873         int w = gui->new_edl->session->output_w;
874         int h = gui->new_edl->session->output_h;
875         gui->new_edl->session->output_w = h;
876         gui->new_edl->session->output_h = w;
877         gui->output_w_text->update((int64_t)h);
878         gui->output_h_text->update((int64_t)w);
879         gui->new_thread->update_aspect();
880         return 1;
881 }
882