4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "cplayback.h"
27 #include "edlsession.h"
29 #include "interlacemodes.h"
31 #include "levelwindow.h"
36 #include "mwindowgui.h"
38 #include "newpresets.h"
39 #include "mainsession.h"
41 #include "preferences.h"
43 #include "transportque.h"
46 #include "videowindow.h"
47 #include "vplayback.h"
57 New::New(MWindow *mwindow)
59 this->mwindow = mwindow;
70 int New::handle_event()
72 mwindow->gui->unlock_window();
73 mwindow->edl->save_defaults(mwindow->defaults);
76 mwindow->gui->lock_window("New::handle_event");
81 void New::create_new_edl()
85 new_edl->create_objects();
86 new_edl->load_defaults(mwindow->defaults);
91 int New::create_new_project(int load_mode)
93 mwindow->stop_playback(0);
94 mwindow->gui->lock_window();
95 mwindow->reset_caches();
97 memcpy(new_edl->session->achannel_positions,
98 &mwindow->preferences->channel_positions[new_edl->session->audio_channels - 1],
99 sizeof(new_edl->session->achannel_positions));
100 new_edl->session->boundaries();
101 new_edl->create_default_tracks();
102 if( load_mode == LOADMODE_NEW_TRACKS ) {
103 Tracks *tracks = mwindow->edl->tracks;
104 int vindex = tracks->total_video_tracks();
105 int aindex = tracks->total_audio_tracks();
106 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
107 switch( track->data_type ) {
109 sprintf(track->title, _("Audio %d"), ++aindex);
112 sprintf(track->title, _("Video %d"), ++vindex);
117 mwindow->undo->update_undo_before();
118 mwindow->set_filename("");
119 ArrayList<EDL *>new_edls;
120 new_edls.append(new_edl);
121 mwindow->paste_edls(&new_edls, load_mode, 0,0,0,0,0,0);
122 new_edl->remove_user();
125 // Load file sequence
126 mwindow->update_project(load_mode);
127 mwindow->session->changes_made = 0;
128 mwindow->undo->update_undo_after(load_mode == LOADMODE_REPLACE ?
129 _("New Project") : _("Append to Project"), LOAD_ALL);
130 mwindow->gui->unlock_window();
134 NewProject::NewProject(MWindow *mwindow)
135 : BC_MenuItem(_("New Project..."), "n", 'n'), New(mwindow)
138 NewProject::~NewProject()
142 void NewProject::create_objects()
144 thread = new NewThread(mwindow, this,
145 _(PROGRAM_NAME ": New Project"), LOADMODE_REPLACE);
148 AppendTracks::AppendTracks(MWindow *mwindow)
149 : BC_MenuItem(_("Append to Project..."), "N", 'N'), New(mwindow)
153 AppendTracks::~AppendTracks()
157 void AppendTracks::create_objects()
159 thread = new NewThread(mwindow, this,
160 _(PROGRAM_NAME ": Append to Project"), LOADMODE_NEW_TRACKS);
164 NewThread::NewThread(MWindow *mwindow, New *new_project,
165 const char *title, int load_mode)
168 this->mwindow = mwindow;
169 this->new_project = new_project;
171 this->load_mode = load_mode;
175 NewThread::~NewThread()
180 BC_Window* NewThread::new_gui()
182 mwindow->edl->save_defaults(mwindow->defaults);
183 new_project->create_new_edl();
186 mwindow->gui->lock_window("NewThread::new_gui");
187 int x = mwindow->gui->get_pop_cursor_x(0);
188 int y = mwindow->gui->get_pop_cursor_y(0);
190 nwindow = new NewWindow(mwindow, this, x, y);
191 nwindow->create_objects();
192 mwindow->gui->unlock_window();
196 void NewThread::handle_close_event(int result)
198 if( !new_project->new_edl ) return;
199 new_project->new_edl->save_defaults(mwindow->defaults);
200 mwindow->defaults->save();
204 if( !new_project->new_edl->Garbage::remove_user() )
205 new_project->new_edl = 0;
208 new_project->create_new_project(load_mode);
212 int NewThread::load_defaults()
214 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
218 int NewThread::save_defaults()
220 mwindow->defaults->update("AUTOASPECT", auto_aspect);
224 int NewThread::update_aspect()
227 char string[BCTEXTLEN];
228 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
229 new_project->new_edl->session->aspect_h,
230 new_project->new_edl->session->output_w,
231 new_project->new_edl->session->output_h);
232 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
233 if( nwindow->aspect_w_text ) nwindow->aspect_w_text->update(string);
234 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
235 if( nwindow->aspect_h_text )nwindow->aspect_h_text->update(string);
241 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
242 : BC_Window(new_thread->title, x, y,
243 WIDTH, new_thread->load_mode == LOADMODE_REPLACE ? HEIGHT : HEIGHT-180,
246 this->mwindow = mwindow;
247 this->new_thread = new_thread;
248 this->new_edl = new_thread->new_project->new_edl;
259 interlace_pulldown = 0;
263 NewWindow::~NewWindow()
265 lock_window("NewWindow::~NewWindow");
266 delete format_presets;
270 void NewWindow::create_objects()
272 int x = 10, y = 10, x1, y1;
275 lock_window("NewWindow::create_objects");
276 mwindow->theme->draw_new_bg(this);
278 add_subwindow( new BC_Title(x, y, new_thread->load_mode == LOADMODE_REPLACE ?
279 _("Parameters for the new project:") :
280 _("Parameters for additional tracks:") ) );
283 format_presets = new NewPresets(mwindow,
287 format_presets->create_objects();
288 x = format_presets->x;
289 y = format_presets->y;
293 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
297 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
299 add_subwindow(atracks = new NewATracks(this, "", x1, y));
300 x1 += atracks->get_w();
301 add_subwindow(new NewATracksTumbler(this, x1, y));
302 y += atracks->get_h() + 5;
304 if( new_thread->load_mode == LOADMODE_REPLACE ) {
306 add_subwindow(new BC_Title(x1, y, _("Channels:")));
308 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
309 x1 += achannels->get_w();
310 add_subwindow(new NewAChannelsTumbler(this, x1, y));
311 y += achannels->get_h() + 5;
314 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
316 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
317 x1 += sample_rate->get_w();
318 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
323 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
326 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
328 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
329 x1 += vtracks->get_w();
330 add_subwindow(new NewVTracksTumbler(this, x1, y));
331 y += vtracks->get_h() + 5;
333 if( new_thread->load_mode == LOADMODE_REPLACE ) {
335 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
337 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
338 // x1 += vchannels->get_w();
339 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
340 // y += vchannels->get_h() + 5;
342 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
344 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
345 x1 += frame_rate->get_w();
346 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
347 y += frame_rate->get_h() + 5;
350 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
352 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
353 // x1 += canvas_w_text->get_w() + 2;
354 // add_subwindow(new BC_Title(x1, y, "x"));
356 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
357 // x1 += canvas_h_text->get_w();
358 // add_subwindow(new FrameSizePulldown(mwindow,
364 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
365 // y += canvas_h_text->get_h() + 5;
368 add_subwindow(new BC_Title(x1, y, _("Track size:")));
370 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
371 x1 += output_w_text->get_w() + 2;
372 add_subwindow(new BC_Title(x1, y, "x"));
374 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
375 x1 += output_h_text->get_w();
376 FrameSizePulldown *pulldown;
377 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
382 x1 += pulldown->get_w() + 10;
383 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
384 y += output_h_text->get_h() + 5;
386 if( new_thread->load_mode == LOADMODE_REPLACE ) {
388 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
390 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
391 x1 += aspect_w_text->get_w() + 2;
392 add_subwindow(new BC_Title(x1, y, ":"));
394 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
395 x1 += aspect_h_text->get_w();
396 add_subwindow(new AspectPulldown(mwindow,
397 aspect_w_text, aspect_h_text, x1, y));
399 x1 = aspect_w_text->get_x();
400 y += aspect_w_text->get_h() + 5;
401 add_subwindow(new NewAspectAuto(this, x1, y));
404 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
405 x1 = x + title->get_w();
406 y1 = y; y += title->get_h() + 10;
407 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
408 int x2 = x + title->get_w();
409 int y2 = y; y += title->get_h() + 10;
410 if( x1 < x2 ) x1 = x2;
412 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
413 add_subwindow(color_model = new ColormodelPulldown(mwindow,
414 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
415 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
416 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
417 textbox, &new_edl->session->interlace_mode,
418 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
419 x1+textbox->get_w(), y2));
422 add_subwindow(new BC_OKButton(this,
423 mwindow->theme->get_image_set("new_ok_images")));
424 add_subwindow(new BC_CancelButton(this,
425 mwindow->theme->get_image_set("new_cancel_images")));
432 int NewWindow::update()
434 if( atracks ) atracks->update((int64_t)new_edl->session->audio_tracks);
435 if( achannels ) achannels->update((int64_t)new_edl->session->audio_channels);
436 if( sample_rate ) sample_rate->update((int64_t)new_edl->session->sample_rate);
437 if( vtracks ) vtracks->update((int64_t)new_edl->session->video_tracks);
438 if( frame_rate ) frame_rate->update((float)new_edl->session->frame_rate);
439 if( output_w_text ) output_w_text->update((int64_t)new_edl->session->output_w);
440 if( output_h_text ) output_h_text->update((int64_t)new_edl->session->output_h);
441 if( aspect_w_text ) aspect_w_text->update((float)new_edl->session->aspect_w);
442 if( aspect_h_text ) aspect_h_text->update((float)new_edl->session->aspect_h);
443 if( interlace_pulldown ) interlace_pulldown->update(new_edl->session->interlace_mode);
444 if( color_model ) color_model->update_value(new_edl->session->color_model);
449 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
450 : FormatPresets(mwindow, gui, 0, x, y)
454 NewPresets::~NewPresets()
458 int NewPresets::handle_event()
464 EDL* NewPresets::get_edl()
466 return new_gui->new_edl;
470 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
471 : BC_TextBox(x, y, 90, 1, text)
473 this->nwindow = nwindow;
476 int NewATracks::handle_event()
478 nwindow->new_edl->session->audio_tracks = atol(get_text());
482 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
485 this->nwindow = nwindow;
487 int NewATracksTumbler::handle_up_event()
489 nwindow->new_edl->session->audio_tracks++;
490 nwindow->new_edl->boundaries();
494 int NewATracksTumbler::handle_down_event()
496 nwindow->new_edl->session->audio_tracks--;
497 nwindow->new_edl->boundaries();
503 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
504 : BC_TextBox(x, y, 90, 1, text)
506 this->nwindow = nwindow;
509 int NewAChannels::handle_event()
511 nwindow->new_edl->session->audio_channels = atol(get_text());
516 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
519 this->nwindow = nwindow;
521 int NewAChannelsTumbler::handle_up_event()
523 nwindow->new_edl->session->audio_channels++;
524 nwindow->new_edl->boundaries();
528 int NewAChannelsTumbler::handle_down_event()
530 nwindow->new_edl->session->audio_channels--;
531 nwindow->new_edl->boundaries();
537 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
538 : BC_TextBox(x, y, 90, 1, text)
540 this->nwindow = nwindow;
543 int NewSampleRate::handle_event()
545 nwindow->new_edl->session->sample_rate = atol(get_text());
550 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
551 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
552 &mwindow->theme->sample_rates, 0, 0, 1, 0, 1)
554 this->mwindow = mwindow;
555 this->output = output;
557 int SampleRatePulldown::handle_event()
559 char *text = get_selection(0, 0)->get_text();
560 output->update(text);
561 output->handle_event();
566 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
567 : BC_TextBox(x, y, 90, 1, text)
569 this->nwindow = nwindow;
572 int NewVTracks::handle_event()
574 nwindow->new_edl->session->video_tracks = atol(get_text());
579 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
582 this->nwindow = nwindow;
584 int NewVTracksTumbler::handle_up_event()
586 nwindow->new_edl->session->video_tracks++;
587 nwindow->new_edl->boundaries();
591 int NewVTracksTumbler::handle_down_event()
593 nwindow->new_edl->session->video_tracks--;
594 nwindow->new_edl->boundaries();
600 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
601 : BC_TextBox(x, y, 90, 1, text)
603 this->nwindow = nwindow;
606 int NewVChannels::handle_event()
608 nwindow->new_edl->session->video_channels = atol(get_text());
613 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
616 this->nwindow = nwindow;
618 int NewVChannelsTumbler::handle_up_event()
620 nwindow->new_edl->session->video_channels++;
621 nwindow->new_edl->boundaries();
625 int NewVChannelsTumbler::handle_down_event()
627 nwindow->new_edl->session->video_channels--;
628 nwindow->new_edl->boundaries();
634 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
635 : BC_TextBox(x, y, 90, 1, text)
637 this->nwindow = nwindow;
640 int NewFrameRate::handle_event()
642 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
647 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
648 BC_TextBox *output, int x, int y)
649 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
650 &mwindow->theme->frame_rates, 0, 0, 1, 0, 1)
652 this->mwindow = mwindow;
653 this->output = output;
655 int FrameRatePulldown::handle_event()
657 char *text = get_selection(0, 0)->get_text();
658 output->update(text);
659 output->handle_event();
663 FrameSizePulldown::FrameSizePulldown(Theme *theme,
664 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
665 : BC_ListBox(x, y, 180, 250, LISTBOX_TEXT,
666 &theme->frame_sizes, 0, 0, 1, 0, 1)
669 this->output_w = output_w;
670 this->output_h = output_h;
673 int FrameSizePulldown::handle_event()
675 char *text = get_selection(0, 0)->get_text();
676 char string[BCTEXTLEN];
680 strcpy(string, text);
681 ptr = strrchr(string, 'x');
690 output_w->handle_event();
691 output_h->handle_event();
697 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
698 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
700 this->nwindow = nwindow;
702 int NewOutputW::handle_event()
704 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
705 nwindow->new_thread->update_aspect();
710 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
711 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
713 this->nwindow = nwindow;
715 int NewOutputH::handle_event()
717 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
718 nwindow->new_thread->update_aspect();
723 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
724 : BC_TextBox(x, y, 70, 1, text)
726 this->nwindow = nwindow;
729 int NewAspectW::handle_event()
731 nwindow->new_edl->session->aspect_w = atof(get_text());
736 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
737 : BC_TextBox(x, y, 70, 1, text)
739 this->nwindow = nwindow;
742 int NewAspectH::handle_event()
744 nwindow->new_edl->session->aspect_h = atof(get_text());
749 AspectPulldown::AspectPulldown(MWindow *mwindow,
750 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
751 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
752 &mwindow->theme->aspect_ratios, 0, 0, 1, 0, 1)
754 this->mwindow = mwindow;
755 this->output_w = output_w;
756 this->output_h = output_h;
759 int AspectPulldown::handle_event()
761 char *text = get_selection(0, 0)->get_text();
762 char string[BCTEXTLEN];
766 strcpy(string, text);
767 ptr = strrchr(string, ':');
776 output_w->handle_event();
777 output_h->handle_event();
783 ColormodelItem::ColormodelItem(const char *text, int value)
784 : BC_ListBoxItem(text)
789 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
790 BC_TextBox *output_text, int *output_value, int x, int y)
791 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT,
792 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels, 0, 0, 1, 0, 1)
794 this->mwindow = mwindow;
795 this->output_text = output_text;
796 this->output_value = output_value;
797 output_text->update(colormodel_to_text());
800 int ColormodelPulldown::handle_event()
802 output_text->update(get_selection(0, 0)->get_text());
803 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
807 const char* ColormodelPulldown::colormodel_to_text()
809 for( int i=0; i<mwindow->colormodels.total; ++i )
810 if( mwindow->colormodels.values[i]->value == *output_value )
811 return mwindow->colormodels.values[i]->get_text();
815 void ColormodelPulldown::update_value(int value)
817 *output_value = value;
818 output_text->update(colormodel_to_text());
822 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
823 : BC_ListBoxItem(text)
828 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
829 BC_TextBox *output_text,
831 ArrayList<BC_ListBoxItem*> *data,
834 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
836 this->mwindow = mwindow;
837 this->output_text = output_text;
838 this->output_value = output_value;
839 output_text->update(interlacemode_to_text());
842 int InterlacemodePulldown::handle_event()
844 output_text->update(get_selection(0, 0)->get_text());
845 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
849 const char* InterlacemodePulldown::interlacemode_to_text()
851 ilacemode_to_text(this->string,*output_value);
852 return (this->string);
855 int InterlacemodePulldown::update(int interlace_mode)
857 *output_value = interlace_mode;
858 output_text->update(interlacemode_to_text());
863 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
864 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
866 this->nwindow = nwindow;
868 NewAspectAuto::~NewAspectAuto()
871 int NewAspectAuto::handle_event()
873 nwindow->new_thread->auto_aspect = get_value();
874 nwindow->new_thread->update_aspect();
879 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
880 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
882 this->mwindow = mwindow;
884 set_tooltip(_("Swap dimensions"));
887 int NewSwapExtents::handle_event()
889 int w = gui->new_edl->session->output_w;
890 int h = gui->new_edl->session->output_h;
891 gui->new_edl->session->output_w = h;
892 gui->new_edl->session->output_h = w;
893 gui->output_w_text->update((int64_t)h);
894 gui->output_h_text->update((int64_t)w);
895 gui->new_thread->update_aspect();