r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / new.C
blob40ac90c7d6964f0a4394936b0b8e57ae9d25f217
1 #include "clip.h"
2 #include "cplayback.h"
3 #include "cwindow.h"
4 #include "defaults.h"
5 #include "edl.h"
6 #include "edlsession.h"
7 #include "filexml.h"
8 #include "language.h"
9 #include "levelwindow.h"
10 #include "mainundo.h"
11 #include "mainmenu.h"
12 #include "mwindow.h"
13 #include "mwindowgui.h"
14 #include "new.h"
15 #include "newpresets.h"
16 #include "mainsession.h"
17 #include "patchbay.h"
18 #include "theme.h"
19 #include "transportque.h"
20 #include "videowindow.h"
21 #include "vplayback.h"
22 #include "vwindow.h"
24 #include <string.h>
27 #define WIDTH 600
28 #define HEIGHT 400
31 New::New(MWindow *mwindow)
32  : BC_MenuItem(_("New..."), "n", 'n')
34         this->mwindow = mwindow;
35         script = 0;
38 int New::create_objects()
40         thread = new NewThread(mwindow, this);
41         return 0;
44 int New::handle_event() 
46         if(thread->running())
47         {
48                 thread->window_lock->lock("New::handle_event");
49                 if(thread->nwindow)
50                 {
51                         thread->nwindow->lock_window("New::handle_event");
52                         thread->nwindow->raise_window();
53                         thread->nwindow->unlock_window();
54                 }
55                 thread->window_lock->unlock();
56                 return 1;
57         }
58         mwindow->edl->save_defaults(mwindow->defaults);
59         create_new_edl();
60         thread->start(); 
62         return 1;
65 void New::create_new_edl()
67         new_edl = new EDL;
68         new_edl->create_objects();
69         new_edl->load_defaults(mwindow->defaults);
73 int New::create_new_project()
75         mwindow->cwindow->playback_engine->que->send_command(STOP,
76                 CHANGE_NONE, 
77                 0,
78                 0);
79         mwindow->vwindow->playback_engine->que->send_command(STOP,
80                 CHANGE_NONE, 
81                 0,
82                 0);
83         mwindow->cwindow->playback_engine->interrupt_playback(0);
84         mwindow->vwindow->playback_engine->interrupt_playback(0);
86         mwindow->gui->lock_window();
87         mwindow->undo->update_undo_before(_("New"), LOAD_ALL);
89         new_edl->session->boundaries();
90         new_edl->create_default_tracks();
92         mwindow->set_filename("");
93         mwindow->undo->update_undo_after();
95         mwindow->hide_plugins();
96         delete mwindow->edl;
97 // Delete patches which are pointing to tracks which have been just deleted.
98         mwindow->patches->delete_all_patches();
99         mwindow->edl = new_edl;
100         mwindow->save_defaults();
102 // Load file sequence
103         mwindow->update_project(LOAD_REPLACE);
104         mwindow->session->changes_made = 0;
105         mwindow->gui->unlock_window();
106         return 0;
109 NewThread::NewThread(MWindow *mwindow, New *new_project)
110  : Thread()
112         this->mwindow = mwindow;
113         this->new_project = new_project;
114         window_lock = new Mutex("NewThread::window_lock");
117 NewThread::~NewThread()
119         delete window_lock;
123 void NewThread::run()
125         int result = 0;
126         load_defaults();
128         int x = mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2;
129         int y = mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2;
131         window_lock->lock("NewThread::run 1\n");
132         nwindow = new NewWindow(mwindow, this, x, y);
133         nwindow->create_objects();
134         window_lock->unlock();
136         result = nwindow->run_window();
138         window_lock->lock("NewThread::run 2\n");
139         delete nwindow; 
140         nwindow = 0;
141         window_lock->unlock();
143         new_project->new_edl->save_defaults(mwindow->defaults);
144         mwindow->defaults->save();
146         if(result)
147         {
148 // Aborted
149                 delete new_project->new_edl;
150         }
151         else
152         {
153 //printf("NewThread::run 4\n");
154                 new_project->create_new_project();
155 //printf("NewThread::run 5\n");
156         }
159 int NewThread::load_defaults()
161         auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
162         return 0;
165 int NewThread::save_defaults()
167         mwindow->defaults->update("AUTOASPECT", auto_aspect);
168         return 0;
171 int NewThread::update_aspect()
173         if(auto_aspect)
174         {
175                 char string[1024];
176                 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w, 
177                         new_project->new_edl->session->aspect_h, 
178                         new_project->new_edl->session->output_w, 
179                         new_project->new_edl->session->output_h);
180                 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
181                 nwindow->aspect_w_text->update(string);
182                 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
183                 nwindow->aspect_h_text->update(string);
184         }
185         return 0;
191 #if 0
192 N_("Cinelerra: New Project");
193 #endif
195 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
196  : BC_Window(_(PROGRAM_NAME ": New Project"), 
197                 x,
198                 y,
199                 WIDTH, 
200                 HEIGHT,
201                 -1,
202                 -1,
203                 0,
204                 0,
205                 1)
207         this->mwindow = mwindow;
208         this->new_thread = new_thread;
209         this->new_edl = new_thread->new_project->new_edl;
210         format_presets = 0;
213 NewWindow::~NewWindow()
215         if(format_presets) delete format_presets;
218 int NewWindow::create_objects()
220         int x = 10, y = 10, x1, y1;
221         BC_TextBox *textbox;
223         mwindow->theme->draw_new_bg(this);
225         add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
226         y += 20;
228         format_presets = new NewPresets(mwindow,
229                 this, 
230                 x, 
231                 y);
232         format_presets->create_objects();
233         x = format_presets->x;
234         y = format_presets->y;
238         y += 40;
239         y1 = y;
240         add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
241         y += 30;
243         x1 = x;
244         add_subwindow(new BC_Title(x1, y, _("Tracks:")));
245         x1 += 100;
246         add_subwindow(atracks = new NewATracks(this, "", x1, y));
247         x1 += atracks->get_w();
248         add_subwindow(new NewATracksTumbler(this, x1, y));
249         y += atracks->get_h() + 5;
251         x1 = x;
252         add_subwindow(new BC_Title(x1, y, _("Channels:")));
253         x1 += 100;
254         add_subwindow(achannels = new NewAChannels(this, "", x1, y));
255         x1 += achannels->get_w();
256         add_subwindow(new NewAChannelsTumbler(this, x1, y));
257         y += achannels->get_h() + 5;
259         x1 = x;
260         add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
261         x1 += 100;
262         add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
263         x1 += sample_rate->get_w();
264         add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
265         
266         x += 250;
267         y = y1;
268         add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
269         y += 30;
270         x1 = x;
271         add_subwindow(new BC_Title(x1, y, _("Tracks:")));
272         x1 += 100;
273         add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
274         x1 += vtracks->get_w();
275         add_subwindow(new NewVTracksTumbler(this, x1, y));
276         y += vtracks->get_h() + 5;
278 //      x1 = x;
279 //      add_subwindow(new BC_Title(x1, y, _("Channels:")));
280 //      x1 += 100;
281 //      add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
282 //      x1 += vchannels->get_w();
283 //      add_subwindow(new NewVChannelsTumbler(this, x1, y));
284 //      y += vchannels->get_h() + 5;
285         x1 = x;
286         add_subwindow(new BC_Title(x1, y, _("Framerate:")));
287         x1 += 100;
288         add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
289         x1 += frame_rate->get_w();
290         add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
291         y += frame_rate->get_h() + 5;
293 //      x1 = x;
294 //      add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
295 //      x1 += 100;
296 //      add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
297 //      x1 += canvas_w_text->get_w() + 2;
298 //      add_subwindow(new BC_Title(x1, y, "x"));
299 //      x1 += 10;
300 //      add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
301 //      x1 += canvas_h_text->get_w();
302 //      add_subwindow(new FrameSizePulldown(mwindow, 
303 //              canvas_w_text, 
304 //              canvas_h_text, 
305 //              x1, 
306 //              y));
307 //      x1 += 100;
308 //      add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
309 //      y += canvas_h_text->get_h() + 5;
311         x1 = x;
312         add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
313         x1 += 100;
314         add_subwindow(output_w_text = new NewOutputW(this, x1, y));
315         x1 += output_w_text->get_w() + 2;
316         add_subwindow(new BC_Title(x1, y, "x"));
317         x1 += 10;
318         add_subwindow(output_h_text = new NewOutputH(this, x1, y));
319         x1 += output_h_text->get_w();
320         add_subwindow(new FrameSizePulldown(mwindow, 
321                 output_w_text, 
322                 output_h_text, 
323                 x1, 
324                 y));
325         y += output_h_text->get_h() + 5;
327         x1 = x;
328         add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
329         x1 += 100;
330         add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
331         x1 += aspect_w_text->get_w() + 2;
332         add_subwindow(new BC_Title(x1, y, ":"));
333         x1 += 10;
334         add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
335         x1 += aspect_h_text->get_w();
336         add_subwindow(new AspectPulldown(mwindow, 
337                 aspect_w_text, 
338                 aspect_h_text, 
339                 x1, 
340                 y));
342         x1 = aspect_w_text->get_x();
343         y += aspect_w_text->get_h() + 5;
344         add_subwindow(new NewAspectAuto(this, x1, y));
345         y += 40;
346         add_subwindow(new BC_Title(x, y, _("Color model:")));
347         x += 100;
348         add_subwindow(textbox = new BC_TextBox(x, y, 200, 1, ""));
349         x += textbox->get_w();
350         add_subwindow(new ColormodelPulldown(mwindow, 
351                 textbox, 
352                 &new_edl->session->color_model,
353                 x, 
354                 y));
356         add_subwindow(new BC_OKButton(this));
357         add_subwindow(new BC_CancelButton(this));
358         flash();
359         update();
360         show_window();
361         return 0;
364 int NewWindow::update()
366         char string[BCTEXTLEN];
367         atracks->update((int64_t)new_edl->session->audio_tracks);
368         achannels->update((int64_t)new_edl->session->audio_channels);
369         sample_rate->update((int64_t)new_edl->session->sample_rate);
370         vtracks->update((int64_t)new_edl->session->video_tracks);
371         frame_rate->update((float)new_edl->session->frame_rate);
372         output_w_text->update((int64_t)new_edl->session->output_w);
373         output_h_text->update((int64_t)new_edl->session->output_h);
374         aspect_w_text->update((float)new_edl->session->aspect_w);
375         aspect_h_text->update((float)new_edl->session->aspect_h);
376         return 0;
385 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
386  : FormatPresets(mwindow, gui, 0, x, y)
390 NewPresets::~NewPresets()
394 int NewPresets::handle_event()
396         new_gui->update();
397         return 1;
400 EDL* NewPresets::get_edl()
402         return new_gui->new_edl;
407 NewATracks::NewATracks(NewWindow *nwindow, char *text, int x, int y)
408  : BC_TextBox(x, y, 90, 1, text)
410         this->nwindow = nwindow;
413 int NewATracks::handle_event()
415         nwindow->new_edl->session->audio_tracks = atol(get_text());
416         return 1;
419 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
420  : BC_Tumbler(x, y)
422         this->nwindow = nwindow;
424 int NewATracksTumbler::handle_up_event()
426         nwindow->new_edl->session->audio_tracks++;
427         nwindow->new_edl->boundaries();
428         nwindow->update();
429         return 1;
431 int NewATracksTumbler::handle_down_event()
433         nwindow->new_edl->session->audio_tracks--;
434         nwindow->new_edl->boundaries();
435         nwindow->update();
436         return 1;
439 NewAChannels::NewAChannels(NewWindow *nwindow, char *text, int x, int y)
440  : BC_TextBox(x, y, 90, 1, text)
442         this->nwindow = nwindow;
445 int NewAChannels::handle_event()
447         nwindow->new_edl->session->audio_channels = atol(get_text());
448         return 1;
451 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
452  : BC_Tumbler(x, y)
454         this->nwindow = nwindow;
456 int NewAChannelsTumbler::handle_up_event()
458         nwindow->new_edl->session->audio_channels++;
459         nwindow->new_edl->boundaries();
460         nwindow->update();
461         return 1;
463 int NewAChannelsTumbler::handle_down_event()
465         nwindow->new_edl->session->audio_channels--;
466         nwindow->new_edl->boundaries();
467         nwindow->update();
468         return 1;
472 NewSampleRate::NewSampleRate(NewWindow *nwindow, char *text, int x, int y)
473  : BC_TextBox(x, y, 90, 1, text)
475         this->nwindow = nwindow;
478 int NewSampleRate::handle_event()
480         nwindow->new_edl->session->sample_rate = atol(get_text());
481         return 1;
484 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
485  : BC_ListBox(x,
486         y,
487         100,
488         200,
489         LISTBOX_TEXT,
490         &mwindow->theme->sample_rates,
491         0,
492         0,
493         1,
494         0,
495         1)
497         this->mwindow = mwindow;
498         this->output = output;
500 int SampleRatePulldown::handle_event()
502         char *text = get_selection(0, 0)->get_text();
503         output->update(text);
504         output->handle_event();
505         return 1;
522 NewVTracks::NewVTracks(NewWindow *nwindow, char *text, int x, int y)
523  : BC_TextBox(x, y, 90, 1, text)
525         this->nwindow = nwindow;
528 int NewVTracks::handle_event()
530         nwindow->new_edl->session->video_tracks = atol(get_text());
531         return 1;
534 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
535  : BC_Tumbler(x, y)
537         this->nwindow = nwindow;
539 int NewVTracksTumbler::handle_up_event()
541         nwindow->new_edl->session->video_tracks++;
542         nwindow->new_edl->boundaries();
543         nwindow->update();
544         return 1;
546 int NewVTracksTumbler::handle_down_event()
548         nwindow->new_edl->session->video_tracks--;
549         nwindow->new_edl->boundaries();
550         nwindow->update();
551         return 1;
554 NewVChannels::NewVChannels(NewWindow *nwindow, char *text, int x, int y)
555  : BC_TextBox(x, y, 90, 1, text)
557         this->nwindow = nwindow;
560 int NewVChannels::handle_event()
562         nwindow->new_edl->session->video_channels = atol(get_text());
563         return 1;
566 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
567  : BC_Tumbler(x, y)
569         this->nwindow = nwindow;
571 int NewVChannelsTumbler::handle_up_event()
573         nwindow->new_edl->session->video_channels++;
574         nwindow->new_edl->boundaries();
575         nwindow->update();
576         return 1;
578 int NewVChannelsTumbler::handle_down_event()
580         nwindow->new_edl->session->video_channels--;
581         nwindow->new_edl->boundaries();
582         nwindow->update();
583         return 1;
586 NewFrameRate::NewFrameRate(NewWindow *nwindow, char *text, int x, int y)
587  : BC_TextBox(x, y, 90, 1, text)
589         this->nwindow = nwindow;
592 int NewFrameRate::handle_event()
594         nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
595         return 1;
598 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow, 
599         BC_TextBox *output, 
600         int x, 
601         int y)
602  : BC_ListBox(x,
603         y,
604         100,
605         200,
606         LISTBOX_TEXT,
607         &mwindow->theme->frame_rates,
608         0,
609         0,
610         1,
611         0,
612         1)
614         this->mwindow = mwindow;
615         this->output = output;
617 int FrameRatePulldown::handle_event()
619         char *text = get_selection(0, 0)->get_text();
620         output->update(text);
621         output->handle_event();
622         return 1;
625 // NewTrackW::NewTrackW(NewWindow *nwindow, int x, int y)
626 //  : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->track_w)
627 // {
628 //      this->nwindow = nwindow;
629 // }
630 // int NewTrackW::handle_event()
631 // {
632 //      nwindow->new_edl->session->track_w = atol(get_text());
633 //      return 1;
634 // }
635 // 
636 // NewTrackH::NewTrackH(NewWindow *nwindow, int x, int y)
637 //  : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->track_h)
638 // {
639 //      this->nwindow = nwindow;
640 // }
641 // 
642 // int NewTrackH::handle_event()
643 // {
644 //      nwindow->new_edl->session->track_h = atol(get_text());
645 //      return 1;
646 // }
648 FrameSizePulldown::FrameSizePulldown(MWindow *mwindow, 
649                 BC_TextBox *output_w, 
650                 BC_TextBox *output_h, 
651                 int x, 
652                 int y)
653  : BC_ListBox(x,
654         y,
655         100,
656         200,
657         LISTBOX_TEXT,
658         &mwindow->theme->frame_sizes,
659         0,
660         0,
661         1,
662         0,
663         1)
665         this->mwindow = mwindow;
666         this->output_w = output_w;
667         this->output_h = output_h;
669 int FrameSizePulldown::handle_event()
671         char *text = get_selection(0, 0)->get_text();
672         char string[BCTEXTLEN];
673         int64_t w, h;
674         char *ptr;
675         
676         strcpy(string, text);
677         ptr = strrchr(string, 'x');
678         if(ptr)
679         {
680                 ptr++;
681                 h = atol(ptr);
682                 
683                 *--ptr = 0;
684                 w = atol(string);
685                 output_w->update(w);
686                 output_h->update(h);
687                 output_w->handle_event();
688                 output_h->handle_event();
689         }
690         return 1;
693 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
694  : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
696         this->nwindow = nwindow;
698 int NewOutputW::handle_event()
700         nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
701         nwindow->new_thread->update_aspect();
702         return 1;
705 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
706  : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
708         this->nwindow = nwindow;
710 int NewOutputH::handle_event()
712         nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
713         nwindow->new_thread->update_aspect();
714         return 1;
717 NewAspectW::NewAspectW(NewWindow *nwindow, char *text, int x, int y)
718  : BC_TextBox(x, y, 70, 1, text)
720         this->nwindow = nwindow;
723 int NewAspectW::handle_event()
725         nwindow->new_edl->session->aspect_w = atof(get_text());
726         return 1;
729 NewAspectH::NewAspectH(NewWindow *nwindow, char *text, int x, int y)
730  : BC_TextBox(x, y, 70, 1, text)
732         this->nwindow = nwindow;
735 int NewAspectH::handle_event()
737         nwindow->new_edl->session->aspect_h = atof(get_text());
738         return 1;
741 AspectPulldown::AspectPulldown(MWindow *mwindow, 
742                 BC_TextBox *output_w, 
743                 BC_TextBox *output_h, 
744                 int x, 
745                 int y)
746  : BC_ListBox(x,
747         y,
748         100,
749         200,
750         LISTBOX_TEXT,
751         &mwindow->theme->aspect_ratios,
752         0,
753         0,
754         1,
755         0,
756         1)
758         this->mwindow = mwindow;
759         this->output_w = output_w;
760         this->output_h = output_h;
762 int AspectPulldown::handle_event()
764         char *text = get_selection(0, 0)->get_text();
765         char string[BCTEXTLEN];
766         float w, h;
767         char *ptr;
768         
769         strcpy(string, text);
770         ptr = strrchr(string, ':');
771         if(ptr)
772         {
773                 ptr++;
774                 h = atof(ptr);
775                 
776                 *--ptr = 0;
777                 w = atof(string);
778                 output_w->update(w);
779                 output_h->update(h);
780                 output_w->handle_event();
781                 output_h->handle_event();
782         }
783         return 1;
786 ColormodelItem::ColormodelItem(char *text, int value)
787  : BC_ListBoxItem(text)
789         this->value = value;
792 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow, 
793                 BC_TextBox *output_text, 
794                 int *output_value,
795                 int x, 
796                 int y)
797  : BC_ListBox(x,
798         y,
799         200,
800         150,
801         LISTBOX_TEXT,
802         (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
803         0,
804         0,
805         1,
806         0,
807         1)
809         this->mwindow = mwindow;
810         this->output_text = output_text;
811         this->output_value = output_value;
812         output_text->update(colormodel_to_text());
815 int ColormodelPulldown::handle_event()
817         output_text->update(get_selection(0, 0)->get_text());
818         *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
819         return 1;
822 char* ColormodelPulldown::colormodel_to_text()
824         for(int i = 0; i < mwindow->colormodels.total; i++)
825                 if(mwindow->colormodels.values[i]->value == *output_value) 
826                         return mwindow->colormodels.values[i]->get_text();
827         return "Unknown";
839 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
840  : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
842         this->nwindow = nwindow;
844 NewAspectAuto::~NewAspectAuto()
847 int NewAspectAuto::handle_event()
849         nwindow->new_thread->auto_aspect = get_value();
850         nwindow->new_thread->update_aspect();
851         return 1;
855 #if 0
857 NewCloneToggle::NewCloneToggle(MWindow *mwindow, NewWindow *nwindow, int x, int y)
858  : BC_Toggle(x, 
859         y, 
860         mwindow->theme->chain_data, 
861         nwindow->new_thread->auto_sizes,
862         "",
863         0, 
864         0, 
865         0)
867         this->mwindow = mwindow;
868         this->nwindow = nwindow;
871 int NewCloneToggle::handle_event()
873         nwindow->canvas_w_text->update((int64_t)nwindow->new_edl->session->track_w);
874         nwindow->canvas_h_text->update((int64_t)nwindow->new_edl->session->track_h);
875         nwindow->new_edl->session->output_w = nwindow->new_edl->session->track_w;
876         nwindow->new_edl->session->output_h = nwindow->new_edl->session->track_h;
877         nwindow->new_thread->update_aspect();
878         return 1;
881 #endif