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"
44 #include "videowindow.h"
45 #include "vplayback.h"
55 New::New(MWindow *mwindow)
57 this->mwindow = mwindow;
68 int New::handle_event()
70 mwindow->gui->unlock_window();
71 mwindow->edl->save_defaults(mwindow->defaults);
74 mwindow->gui->lock_window("New::handle_event");
79 void New::create_new_edl()
83 new_edl->create_objects();
84 new_edl->load_defaults(mwindow->defaults);
89 int New::create_new_project(int load_mode)
91 mwindow->stop_playback(0);
92 mwindow->gui->lock_window();
93 mwindow->reset_caches();
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();
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();
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();
118 NewProject::NewProject(MWindow *mwindow)
119 : BC_MenuItem(_("New Project..."), "n", 'n'), New(mwindow)
122 NewProject::~NewProject()
126 void NewProject::create_objects()
128 thread = new NewThread(mwindow, this,
129 _(PROGRAM_NAME ": New Project"), LOADMODE_REPLACE);
132 AppendTracks::AppendTracks(MWindow *mwindow)
133 : BC_MenuItem(_("Append to Project..."), "N", 'N'), New(mwindow)
137 AppendTracks::~AppendTracks()
141 void AppendTracks::create_objects()
143 thread = new NewThread(mwindow, this,
144 _(PROGRAM_NAME ": Append to Project"), LOADMODE_NEW_TRACKS);
148 NewThread::NewThread(MWindow *mwindow, New *new_project,
149 const char *title, int load_mode)
152 this->mwindow = mwindow;
153 this->new_project = new_project;
155 this->load_mode = load_mode;
159 NewThread::~NewThread()
164 BC_Window* NewThread::new_gui()
166 mwindow->edl->save_defaults(mwindow->defaults);
167 new_project->create_new_edl();
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);
174 nwindow = new NewWindow(mwindow, this, x, y);
175 nwindow->create_objects();
176 mwindow->gui->unlock_window();
180 void NewThread::handle_close_event(int result)
182 if( !new_project->new_edl ) return;
183 new_project->new_edl->save_defaults(mwindow->defaults);
184 mwindow->defaults->save();
188 if( !new_project->new_edl->Garbage::remove_user() )
189 new_project->new_edl = 0;
192 new_project->create_new_project(load_mode);
196 int NewThread::load_defaults()
198 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
202 int NewThread::save_defaults()
204 mwindow->defaults->update("AUTOASPECT", auto_aspect);
208 int NewThread::update_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);
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,
230 this->mwindow = mwindow;
231 this->new_thread = new_thread;
232 this->new_edl = new_thread->new_project->new_edl;
243 interlace_pulldown = 0;
247 NewWindow::~NewWindow()
249 lock_window("NewWindow::~NewWindow");
250 delete format_presets;
254 void NewWindow::create_objects()
256 int x = 10, y = 10, x1, y1;
259 lock_window("NewWindow::create_objects");
260 mwindow->theme->draw_new_bg(this);
262 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
265 format_presets = new NewPresets(mwindow,
269 format_presets->create_objects();
270 x = format_presets->x;
271 y = format_presets->y;
275 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
279 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
281 add_subwindow(atracks = new NewATracks(this, "", x1, y));
282 x1 += atracks->get_w();
283 add_subwindow(new NewATracksTumbler(this, x1, y));
284 y += atracks->get_h() + 5;
286 if( new_thread->load_mode == LOADMODE_REPLACE ) {
288 add_subwindow(new BC_Title(x1, y, _("Channels:")));
290 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
291 x1 += achannels->get_w();
292 add_subwindow(new NewAChannelsTumbler(this, x1, y));
293 y += achannels->get_h() + 5;
296 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
298 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
299 x1 += sample_rate->get_w();
300 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
305 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
308 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
310 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
311 x1 += vtracks->get_w();
312 add_subwindow(new NewVTracksTumbler(this, x1, y));
313 y += vtracks->get_h() + 5;
315 if( new_thread->load_mode == LOADMODE_REPLACE ) {
317 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
319 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
320 // x1 += vchannels->get_w();
321 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
322 // y += vchannels->get_h() + 5;
324 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
326 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
327 x1 += frame_rate->get_w();
328 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
329 y += frame_rate->get_h() + 5;
332 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
334 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
335 // x1 += canvas_w_text->get_w() + 2;
336 // add_subwindow(new BC_Title(x1, y, "x"));
338 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
339 // x1 += canvas_h_text->get_w();
340 // add_subwindow(new FrameSizePulldown(mwindow,
346 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
347 // y += canvas_h_text->get_h() + 5;
350 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
352 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
353 x1 += output_w_text->get_w() + 2;
354 add_subwindow(new BC_Title(x1, y, "x"));
356 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
357 x1 += output_h_text->get_w();
358 FrameSizePulldown *pulldown;
359 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
364 x1 += pulldown->get_w() + 10;
365 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
366 y += output_h_text->get_h() + 5;
368 if( new_thread->load_mode == LOADMODE_REPLACE ) {
370 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
372 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
373 x1 += aspect_w_text->get_w() + 2;
374 add_subwindow(new BC_Title(x1, y, ":"));
376 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
377 x1 += aspect_h_text->get_w();
378 add_subwindow(new AspectPulldown(mwindow,
379 aspect_w_text, aspect_h_text, x1, y));
381 x1 = aspect_w_text->get_x();
382 y += aspect_w_text->get_h() + 5;
383 add_subwindow(new NewAspectAuto(this, x1, y));
386 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
387 x1 = x + title->get_w();
388 y1 = y; y += title->get_h() + 10;
389 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
390 int x2 = x + title->get_w();
391 int y2 = y; y += title->get_h() + 10;
392 if( x1 < x2 ) x1 = x2;
394 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
395 add_subwindow(color_model = new ColormodelPulldown(mwindow,
396 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
397 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
398 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
399 textbox, &new_edl->session->interlace_mode,
400 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
401 x1+textbox->get_w(), y2));
404 add_subwindow(new BC_OKButton(this,
405 mwindow->theme->get_image_set("new_ok_images")));
406 add_subwindow(new BC_CancelButton(this,
407 mwindow->theme->get_image_set("new_cancel_images")));
414 int NewWindow::update()
416 if( atracks ) atracks->update((int64_t)new_edl->session->audio_tracks);
417 if( achannels ) achannels->update((int64_t)new_edl->session->audio_channels);
418 if( sample_rate ) sample_rate->update((int64_t)new_edl->session->sample_rate);
419 if( vtracks ) vtracks->update((int64_t)new_edl->session->video_tracks);
420 if( frame_rate ) frame_rate->update((float)new_edl->session->frame_rate);
421 if( output_w_text ) output_w_text->update((int64_t)new_edl->session->output_w);
422 if( output_h_text ) output_h_text->update((int64_t)new_edl->session->output_h);
423 if( aspect_w_text ) aspect_w_text->update((float)new_edl->session->aspect_w);
424 if( aspect_h_text ) aspect_h_text->update((float)new_edl->session->aspect_h);
425 if( interlace_pulldown ) interlace_pulldown->update(new_edl->session->interlace_mode);
426 if( color_model ) color_model->update_value(new_edl->session->color_model);
431 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
432 : FormatPresets(mwindow, gui, 0, x, y)
436 NewPresets::~NewPresets()
440 int NewPresets::handle_event()
446 EDL* NewPresets::get_edl()
448 return new_gui->new_edl;
452 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
453 : BC_TextBox(x, y, 90, 1, text)
455 this->nwindow = nwindow;
458 int NewATracks::handle_event()
460 nwindow->new_edl->session->audio_tracks = atol(get_text());
464 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
467 this->nwindow = nwindow;
469 int NewATracksTumbler::handle_up_event()
471 nwindow->new_edl->session->audio_tracks++;
472 nwindow->new_edl->boundaries();
476 int NewATracksTumbler::handle_down_event()
478 nwindow->new_edl->session->audio_tracks--;
479 nwindow->new_edl->boundaries();
485 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
486 : BC_TextBox(x, y, 90, 1, text)
488 this->nwindow = nwindow;
491 int NewAChannels::handle_event()
493 nwindow->new_edl->session->audio_channels = atol(get_text());
498 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
501 this->nwindow = nwindow;
503 int NewAChannelsTumbler::handle_up_event()
505 nwindow->new_edl->session->audio_channels++;
506 nwindow->new_edl->boundaries();
510 int NewAChannelsTumbler::handle_down_event()
512 nwindow->new_edl->session->audio_channels--;
513 nwindow->new_edl->boundaries();
519 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
520 : BC_TextBox(x, y, 90, 1, text)
522 this->nwindow = nwindow;
525 int NewSampleRate::handle_event()
527 nwindow->new_edl->session->sample_rate = atol(get_text());
532 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
533 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
534 &mwindow->theme->sample_rates, 0, 0, 1, 0, 1)
536 this->mwindow = mwindow;
537 this->output = output;
539 int SampleRatePulldown::handle_event()
541 char *text = get_selection(0, 0)->get_text();
542 output->update(text);
543 output->handle_event();
548 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
549 : BC_TextBox(x, y, 90, 1, text)
551 this->nwindow = nwindow;
554 int NewVTracks::handle_event()
556 nwindow->new_edl->session->video_tracks = atol(get_text());
561 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
564 this->nwindow = nwindow;
566 int NewVTracksTumbler::handle_up_event()
568 nwindow->new_edl->session->video_tracks++;
569 nwindow->new_edl->boundaries();
573 int NewVTracksTumbler::handle_down_event()
575 nwindow->new_edl->session->video_tracks--;
576 nwindow->new_edl->boundaries();
582 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
583 : BC_TextBox(x, y, 90, 1, text)
585 this->nwindow = nwindow;
588 int NewVChannels::handle_event()
590 nwindow->new_edl->session->video_channels = atol(get_text());
595 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
598 this->nwindow = nwindow;
600 int NewVChannelsTumbler::handle_up_event()
602 nwindow->new_edl->session->video_channels++;
603 nwindow->new_edl->boundaries();
607 int NewVChannelsTumbler::handle_down_event()
609 nwindow->new_edl->session->video_channels--;
610 nwindow->new_edl->boundaries();
616 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
617 : BC_TextBox(x, y, 90, 1, text)
619 this->nwindow = nwindow;
622 int NewFrameRate::handle_event()
624 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
629 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
630 BC_TextBox *output, int x, int y)
631 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
632 &mwindow->theme->frame_rates, 0, 0, 1, 0, 1)
634 this->mwindow = mwindow;
635 this->output = output;
637 int FrameRatePulldown::handle_event()
639 char *text = get_selection(0, 0)->get_text();
640 output->update(text);
641 output->handle_event();
645 FrameSizePulldown::FrameSizePulldown(Theme *theme,
646 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
647 : BC_ListBox(x, y, 180, 250, LISTBOX_TEXT,
648 &theme->frame_sizes, 0, 0, 1, 0, 1)
651 this->output_w = output_w;
652 this->output_h = output_h;
655 int FrameSizePulldown::handle_event()
657 char *text = get_selection(0, 0)->get_text();
658 char string[BCTEXTLEN];
662 strcpy(string, text);
663 ptr = strrchr(string, 'x');
672 output_w->handle_event();
673 output_h->handle_event();
679 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
680 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
682 this->nwindow = nwindow;
684 int NewOutputW::handle_event()
686 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
687 nwindow->new_thread->update_aspect();
692 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
693 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
695 this->nwindow = nwindow;
697 int NewOutputH::handle_event()
699 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
700 nwindow->new_thread->update_aspect();
705 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
706 : BC_TextBox(x, y, 70, 1, text)
708 this->nwindow = nwindow;
711 int NewAspectW::handle_event()
713 nwindow->new_edl->session->aspect_w = atof(get_text());
718 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
719 : BC_TextBox(x, y, 70, 1, text)
721 this->nwindow = nwindow;
724 int NewAspectH::handle_event()
726 nwindow->new_edl->session->aspect_h = atof(get_text());
731 AspectPulldown::AspectPulldown(MWindow *mwindow,
732 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
733 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
734 &mwindow->theme->aspect_ratios, 0, 0, 1, 0, 1)
736 this->mwindow = mwindow;
737 this->output_w = output_w;
738 this->output_h = output_h;
741 int AspectPulldown::handle_event()
743 char *text = get_selection(0, 0)->get_text();
744 char string[BCTEXTLEN];
748 strcpy(string, text);
749 ptr = strrchr(string, ':');
758 output_w->handle_event();
759 output_h->handle_event();
765 ColormodelItem::ColormodelItem(const char *text, int value)
766 : BC_ListBoxItem(text)
771 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
772 BC_TextBox *output_text, int *output_value, int x, int y)
773 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT,
774 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels, 0, 0, 1, 0, 1)
776 this->mwindow = mwindow;
777 this->output_text = output_text;
778 this->output_value = output_value;
779 output_text->update(colormodel_to_text());
782 int ColormodelPulldown::handle_event()
784 output_text->update(get_selection(0, 0)->get_text());
785 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
789 const char* ColormodelPulldown::colormodel_to_text()
791 for( int i=0; i<mwindow->colormodels.total; ++i )
792 if( mwindow->colormodels.values[i]->value == *output_value )
793 return mwindow->colormodels.values[i]->get_text();
797 void ColormodelPulldown::update_value(int value)
799 *output_value = value;
800 output_text->update(colormodel_to_text());
804 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
805 : BC_ListBoxItem(text)
810 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
811 BC_TextBox *output_text,
813 ArrayList<BC_ListBoxItem*> *data,
816 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
818 this->mwindow = mwindow;
819 this->output_text = output_text;
820 this->output_value = output_value;
821 output_text->update(interlacemode_to_text());
824 int InterlacemodePulldown::handle_event()
826 output_text->update(get_selection(0, 0)->get_text());
827 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
831 const char* InterlacemodePulldown::interlacemode_to_text()
833 ilacemode_to_text(this->string,*output_value);
834 return (this->string);
837 int InterlacemodePulldown::update(int interlace_mode)
839 *output_value = interlace_mode;
840 output_text->update(interlacemode_to_text());
845 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
846 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
848 this->nwindow = nwindow;
850 NewAspectAuto::~NewAspectAuto()
853 int NewAspectAuto::handle_event()
855 nwindow->new_thread->auto_aspect = get_value();
856 nwindow->new_thread->update_aspect();
861 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
862 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
864 this->mwindow = mwindow;
866 set_tooltip(_("Swap dimensions"));
869 int NewSwapExtents::handle_event()
871 int w = gui->new_edl->session->output_w;
872 int h = gui->new_edl->session->output_h;
873 gui->new_edl->session->output_w = h;
874 gui->new_edl->session->output_h = w;
875 gui->output_w_text->update((int64_t)h);
876 gui->output_h_text->update((int64_t)w);
877 gui->new_thread->update_aspect();