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, new_thread->load_mode == LOADMODE_REPLACE ?
263 _("Parameters for the new project:") :
264 _("Parameters for additional tracks:") ) );
267 format_presets = new NewPresets(mwindow,
271 format_presets->create_objects();
272 x = format_presets->x;
273 y = format_presets->y;
277 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
281 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
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;
288 if( new_thread->load_mode == LOADMODE_REPLACE ) {
290 add_subwindow(new BC_Title(x1, y, _("Channels:")));
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;
298 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
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));
307 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
310 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
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;
317 if( new_thread->load_mode == LOADMODE_REPLACE ) {
319 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
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;
326 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
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;
334 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
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"));
340 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
341 // x1 += canvas_h_text->get_w();
342 // add_subwindow(new FrameSizePulldown(mwindow,
348 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
349 // y += canvas_h_text->get_h() + 5;
352 add_subwindow(new BC_Title(x1, y, _("Track size:")));
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"));
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,
366 x1 += pulldown->get_w() + 10;
367 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
368 y += output_h_text->get_h() + 5;
370 if( new_thread->load_mode == LOADMODE_REPLACE ) {
372 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
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, ":"));
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));
383 x1 = aspect_w_text->get_x();
384 y += aspect_w_text->get_h() + 5;
385 add_subwindow(new NewAspectAuto(this, x1, y));
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;
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));
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")));
416 int NewWindow::update()
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);
433 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
434 : FormatPresets(mwindow, gui, 0, x, y)
438 NewPresets::~NewPresets()
442 int NewPresets::handle_event()
448 EDL* NewPresets::get_edl()
450 return new_gui->new_edl;
454 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
455 : BC_TextBox(x, y, 90, 1, text)
457 this->nwindow = nwindow;
460 int NewATracks::handle_event()
462 nwindow->new_edl->session->audio_tracks = atol(get_text());
466 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
469 this->nwindow = nwindow;
471 int NewATracksTumbler::handle_up_event()
473 nwindow->new_edl->session->audio_tracks++;
474 nwindow->new_edl->boundaries();
478 int NewATracksTumbler::handle_down_event()
480 nwindow->new_edl->session->audio_tracks--;
481 nwindow->new_edl->boundaries();
487 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
488 : BC_TextBox(x, y, 90, 1, text)
490 this->nwindow = nwindow;
493 int NewAChannels::handle_event()
495 nwindow->new_edl->session->audio_channels = atol(get_text());
500 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
503 this->nwindow = nwindow;
505 int NewAChannelsTumbler::handle_up_event()
507 nwindow->new_edl->session->audio_channels++;
508 nwindow->new_edl->boundaries();
512 int NewAChannelsTumbler::handle_down_event()
514 nwindow->new_edl->session->audio_channels--;
515 nwindow->new_edl->boundaries();
521 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
522 : BC_TextBox(x, y, 90, 1, text)
524 this->nwindow = nwindow;
527 int NewSampleRate::handle_event()
529 nwindow->new_edl->session->sample_rate = atol(get_text());
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)
538 this->mwindow = mwindow;
539 this->output = output;
541 int SampleRatePulldown::handle_event()
543 char *text = get_selection(0, 0)->get_text();
544 output->update(text);
545 output->handle_event();
550 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
551 : BC_TextBox(x, y, 90, 1, text)
553 this->nwindow = nwindow;
556 int NewVTracks::handle_event()
558 nwindow->new_edl->session->video_tracks = atol(get_text());
563 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
566 this->nwindow = nwindow;
568 int NewVTracksTumbler::handle_up_event()
570 nwindow->new_edl->session->video_tracks++;
571 nwindow->new_edl->boundaries();
575 int NewVTracksTumbler::handle_down_event()
577 nwindow->new_edl->session->video_tracks--;
578 nwindow->new_edl->boundaries();
584 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
585 : BC_TextBox(x, y, 90, 1, text)
587 this->nwindow = nwindow;
590 int NewVChannels::handle_event()
592 nwindow->new_edl->session->video_channels = atol(get_text());
597 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
600 this->nwindow = nwindow;
602 int NewVChannelsTumbler::handle_up_event()
604 nwindow->new_edl->session->video_channels++;
605 nwindow->new_edl->boundaries();
609 int NewVChannelsTumbler::handle_down_event()
611 nwindow->new_edl->session->video_channels--;
612 nwindow->new_edl->boundaries();
618 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
619 : BC_TextBox(x, y, 90, 1, text)
621 this->nwindow = nwindow;
624 int NewFrameRate::handle_event()
626 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
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)
636 this->mwindow = mwindow;
637 this->output = output;
639 int FrameRatePulldown::handle_event()
641 char *text = get_selection(0, 0)->get_text();
642 output->update(text);
643 output->handle_event();
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)
653 this->output_w = output_w;
654 this->output_h = output_h;
657 int FrameSizePulldown::handle_event()
659 char *text = get_selection(0, 0)->get_text();
660 char string[BCTEXTLEN];
664 strcpy(string, text);
665 ptr = strrchr(string, 'x');
674 output_w->handle_event();
675 output_h->handle_event();
681 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
682 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
684 this->nwindow = nwindow;
686 int NewOutputW::handle_event()
688 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
689 nwindow->new_thread->update_aspect();
694 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
695 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
697 this->nwindow = nwindow;
699 int NewOutputH::handle_event()
701 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
702 nwindow->new_thread->update_aspect();
707 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
708 : BC_TextBox(x, y, 70, 1, text)
710 this->nwindow = nwindow;
713 int NewAspectW::handle_event()
715 nwindow->new_edl->session->aspect_w = atof(get_text());
720 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
721 : BC_TextBox(x, y, 70, 1, text)
723 this->nwindow = nwindow;
726 int NewAspectH::handle_event()
728 nwindow->new_edl->session->aspect_h = atof(get_text());
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)
738 this->mwindow = mwindow;
739 this->output_w = output_w;
740 this->output_h = output_h;
743 int AspectPulldown::handle_event()
745 char *text = get_selection(0, 0)->get_text();
746 char string[BCTEXTLEN];
750 strcpy(string, text);
751 ptr = strrchr(string, ':');
760 output_w->handle_event();
761 output_h->handle_event();
767 ColormodelItem::ColormodelItem(const char *text, int value)
768 : BC_ListBoxItem(text)
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)
778 this->mwindow = mwindow;
779 this->output_text = output_text;
780 this->output_value = output_value;
781 output_text->update(colormodel_to_text());
784 int ColormodelPulldown::handle_event()
786 output_text->update(get_selection(0, 0)->get_text());
787 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
791 const char* ColormodelPulldown::colormodel_to_text()
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();
799 void ColormodelPulldown::update_value(int value)
801 *output_value = value;
802 output_text->update(colormodel_to_text());
806 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
807 : BC_ListBoxItem(text)
812 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
813 BC_TextBox *output_text,
815 ArrayList<BC_ListBoxItem*> *data,
818 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
820 this->mwindow = mwindow;
821 this->output_text = output_text;
822 this->output_value = output_value;
823 output_text->update(interlacemode_to_text());
826 int InterlacemodePulldown::handle_event()
828 output_text->update(get_selection(0, 0)->get_text());
829 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
833 const char* InterlacemodePulldown::interlacemode_to_text()
835 ilacemode_to_text(this->string,*output_value);
836 return (this->string);
839 int InterlacemodePulldown::update(int interlace_mode)
841 *output_value = interlace_mode;
842 output_text->update(interlacemode_to_text());
847 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
848 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
850 this->nwindow = nwindow;
852 NewAspectAuto::~NewAspectAuto()
855 int NewAspectAuto::handle_event()
857 nwindow->new_thread->auto_aspect = get_value();
858 nwindow->new_thread->update_aspect();
863 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
864 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
866 this->mwindow = mwindow;
868 set_tooltip(_("Swap dimensions"));
871 int NewSwapExtents::handle_event()
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();