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"
56 New::New(MWindow *mwindow)
57 : BC_MenuItem(_("New"), "n", 'n')
59 this->mwindow = mwindow;
70 void New::create_objects()
72 thread = new NewThread(mwindow, this);
75 int New::handle_event()
77 mwindow->gui->unlock_window();
78 mwindow->edl->save_defaults(mwindow->defaults);
82 mwindow->gui->lock_window("New::handle_event");
87 void New::create_new_edl()
92 new_edl->create_objects();
93 new_edl->load_defaults(mwindow->defaults);
98 int New::create_new_project()
100 mwindow->cwindow->playback_engine->que->send_command(STOP,
105 for(int i = 0; i < mwindow->vwindows.size(); i++)
107 mwindow->vwindows.get(i)->playback_engine->que->send_command(STOP,
111 mwindow->vwindows.get(i)->playback_engine->interrupt_playback(0);
114 mwindow->cwindow->playback_engine->interrupt_playback(0);
116 mwindow->gui->lock_window();
117 mwindow->reset_caches();
121 memcpy(new_edl->session->achannel_positions,
122 &mwindow->preferences->channel_positions[
123 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
124 sizeof(int) * MAXCHANNELS);
125 new_edl->session->boundaries();
126 new_edl->create_default_tracks();
128 mwindow->undo->update_undo_before();
129 mwindow->set_filename("");
131 mwindow->hide_plugins();
132 mwindow->edl->Garbage::remove_user();
133 mwindow->edl = new_edl;
135 mwindow->save_defaults();
137 // Load file sequence
138 mwindow->update_project(LOADMODE_REPLACE);
139 mwindow->session->changes_made = 0;
140 mwindow->undo->update_undo_after(_("New"), LOAD_ALL);
141 mwindow->gui->unlock_window();
145 NewThread::NewThread(MWindow *mwindow, New *new_project)
148 this->mwindow = mwindow;
149 this->new_project = new_project;
153 NewThread::~NewThread()
160 BC_Window* NewThread::new_gui()
162 mwindow->edl->save_defaults(mwindow->defaults);
163 new_project->create_new_edl();
166 mwindow->gui->lock_window("NewThread::new_gui");
167 int x = mwindow->gui->get_abs_cursor_x(0) - WIDTH / 2;
168 int y = mwindow->gui->get_abs_cursor_y(0) - HEIGHT / 2;
170 nwindow = new NewWindow(mwindow, this, x, y);
171 nwindow->create_objects();
172 mwindow->gui->unlock_window();
178 void NewThread::handle_close_event(int result)
181 new_project->new_edl->save_defaults(mwindow->defaults);
182 mwindow->defaults->save();
187 if( !new_project->new_edl->Garbage::remove_user() )
188 new_project->new_edl = 0;
192 new_project->create_new_project();
198 int NewThread::load_defaults()
200 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
204 int NewThread::save_defaults()
206 mwindow->defaults->update("AUTOASPECT", auto_aspect);
210 int NewThread::update_aspect()
214 char string[BCTEXTLEN];
215 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
216 new_project->new_edl->session->aspect_h,
217 new_project->new_edl->session->output_w,
218 new_project->new_edl->session->output_h);
219 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
220 nwindow->aspect_w_text->update(string);
221 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
222 nwindow->aspect_h_text->update(string);
230 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
231 : BC_Window(_(_(PROGRAM_NAME ": New Project")),
242 this->mwindow = mwindow;
243 this->new_thread = new_thread;
244 this->new_edl = new_thread->new_project->new_edl;
248 NewWindow::~NewWindow()
250 lock_window("NewWindow::~NewWindow");
251 if(format_presets) delete format_presets;
255 void NewWindow::create_objects()
257 int x = 10, y = 10, x1, y1;
260 lock_window("NewWindow::create_objects");
261 mwindow->theme->draw_new_bg(this);
263 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
266 format_presets = new NewPresets(mwindow,
270 format_presets->create_objects();
271 x = format_presets->x;
272 y = format_presets->y;
278 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
282 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
284 add_subwindow(atracks = new NewATracks(this, "", x1, y));
285 x1 += atracks->get_w();
286 add_subwindow(new NewATracksTumbler(this, x1, y));
287 y += atracks->get_h() + 5;
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));
306 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
309 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
311 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
312 x1 += vtracks->get_w();
313 add_subwindow(new NewVTracksTumbler(this, x1, y));
314 y += vtracks->get_h() + 5;
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() + 5;
365 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
366 y += output_h_text->get_h() + 5;
369 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
371 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
372 x1 += aspect_w_text->get_w() + 2;
373 add_subwindow(new BC_Title(x1, y, ":"));
375 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
376 x1 += aspect_h_text->get_w();
377 add_subwindow(new AspectPulldown(mwindow,
383 x1 = aspect_w_text->get_x();
384 y += aspect_w_text->get_h() + 5;
385 add_subwindow(new NewAspectAuto(this, x1, y));
387 add_subwindow(new BC_Title(x, y, _("Color model:")));
388 add_subwindow(textbox = new BC_TextBox(x + 100, y, 200, 1, ""));
389 add_subwindow(color_model = new ColormodelPulldown(mwindow,
391 &new_edl->session->color_model,
392 x + 100 + textbox->get_w(),
394 y += textbox->get_h() + 5;
396 // --------------------
397 add_subwindow(new BC_Title(x, y, _("Interlace mode:")));
398 add_subwindow(textbox = new BC_TextBox(x + 100, y, 140, 1, ""));
399 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
401 &new_edl->session->interlace_mode,
402 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
403 x + 100 + textbox->get_w(),
405 y += textbox->get_h() + 5;
407 add_subwindow(new BC_OKButton(this,
408 mwindow->theme->get_image_set("new_ok_images")));
409 add_subwindow(new BC_CancelButton(this,
410 mwindow->theme->get_image_set("new_cancel_images")));
417 int NewWindow::update()
419 atracks->update((int64_t)new_edl->session->audio_tracks);
420 achannels->update((int64_t)new_edl->session->audio_channels);
421 sample_rate->update((int64_t)new_edl->session->sample_rate);
422 vtracks->update((int64_t)new_edl->session->video_tracks);
423 frame_rate->update((float)new_edl->session->frame_rate);
424 output_w_text->update((int64_t)new_edl->session->output_w);
425 output_h_text->update((int64_t)new_edl->session->output_h);
426 aspect_w_text->update((float)new_edl->session->aspect_w);
427 aspect_h_text->update((float)new_edl->session->aspect_h);
428 interlace_pulldown->update(new_edl->session->interlace_mode);
429 color_model->update_value(new_edl->session->color_model);
439 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
440 : FormatPresets(mwindow, gui, 0, x, y)
444 NewPresets::~NewPresets()
448 int NewPresets::handle_event()
454 EDL* NewPresets::get_edl()
456 return new_gui->new_edl;
461 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
462 : BC_TextBox(x, y, 90, 1, text)
464 this->nwindow = nwindow;
467 int NewATracks::handle_event()
469 nwindow->new_edl->session->audio_tracks = atol(get_text());
473 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
476 this->nwindow = nwindow;
478 int NewATracksTumbler::handle_up_event()
480 nwindow->new_edl->session->audio_tracks++;
481 nwindow->new_edl->boundaries();
485 int NewATracksTumbler::handle_down_event()
487 nwindow->new_edl->session->audio_tracks--;
488 nwindow->new_edl->boundaries();
493 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
494 : BC_TextBox(x, y, 90, 1, text)
496 this->nwindow = nwindow;
499 int NewAChannels::handle_event()
501 nwindow->new_edl->session->audio_channels = atol(get_text());
505 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
508 this->nwindow = nwindow;
510 int NewAChannelsTumbler::handle_up_event()
512 nwindow->new_edl->session->audio_channels++;
513 nwindow->new_edl->boundaries();
517 int NewAChannelsTumbler::handle_down_event()
519 nwindow->new_edl->session->audio_channels--;
520 nwindow->new_edl->boundaries();
526 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
527 : BC_TextBox(x, y, 90, 1, text)
529 this->nwindow = nwindow;
532 int NewSampleRate::handle_event()
534 nwindow->new_edl->session->sample_rate = atol(get_text());
538 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
544 &mwindow->theme->sample_rates,
551 this->mwindow = mwindow;
552 this->output = output;
554 int SampleRatePulldown::handle_event()
556 char *text = get_selection(0, 0)->get_text();
557 output->update(text);
558 output->handle_event();
576 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
577 : BC_TextBox(x, y, 90, 1, text)
579 this->nwindow = nwindow;
582 int NewVTracks::handle_event()
584 nwindow->new_edl->session->video_tracks = atol(get_text());
588 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
591 this->nwindow = nwindow;
593 int NewVTracksTumbler::handle_up_event()
595 nwindow->new_edl->session->video_tracks++;
596 nwindow->new_edl->boundaries();
600 int NewVTracksTumbler::handle_down_event()
602 nwindow->new_edl->session->video_tracks--;
603 nwindow->new_edl->boundaries();
608 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
609 : BC_TextBox(x, y, 90, 1, text)
611 this->nwindow = nwindow;
614 int NewVChannels::handle_event()
616 nwindow->new_edl->session->video_channels = atol(get_text());
620 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
623 this->nwindow = nwindow;
625 int NewVChannelsTumbler::handle_up_event()
627 nwindow->new_edl->session->video_channels++;
628 nwindow->new_edl->boundaries();
632 int NewVChannelsTumbler::handle_down_event()
634 nwindow->new_edl->session->video_channels--;
635 nwindow->new_edl->boundaries();
640 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
641 : BC_TextBox(x, y, 90, 1, text)
643 this->nwindow = nwindow;
646 int NewFrameRate::handle_event()
648 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
652 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
661 &mwindow->theme->frame_rates,
668 this->mwindow = mwindow;
669 this->output = output;
671 int FrameRatePulldown::handle_event()
673 char *text = get_selection(0, 0)->get_text();
674 output->update(text);
675 output->handle_event();
679 FrameSizePulldown::FrameSizePulldown(Theme *theme,
680 BC_TextBox *output_w,
681 BC_TextBox *output_h,
697 this->output_w = output_w;
698 this->output_h = output_h;
700 int FrameSizePulldown::handle_event()
702 char *text = get_selection(0, 0)->get_text();
703 char string[BCTEXTLEN];
707 strcpy(string, text);
708 ptr = strrchr(string, 'x');
718 output_w->handle_event();
719 output_h->handle_event();
724 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
725 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
727 this->nwindow = nwindow;
729 int NewOutputW::handle_event()
731 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
732 nwindow->new_thread->update_aspect();
736 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
737 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
739 this->nwindow = nwindow;
741 int NewOutputH::handle_event()
743 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
744 nwindow->new_thread->update_aspect();
748 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
749 : BC_TextBox(x, y, 70, 1, text)
751 this->nwindow = nwindow;
754 int NewAspectW::handle_event()
756 nwindow->new_edl->session->aspect_w = atof(get_text());
760 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
761 : BC_TextBox(x, y, 70, 1, text)
763 this->nwindow = nwindow;
766 int NewAspectH::handle_event()
768 nwindow->new_edl->session->aspect_h = atof(get_text());
772 AspectPulldown::AspectPulldown(MWindow *mwindow,
773 BC_TextBox *output_w,
774 BC_TextBox *output_h,
782 &mwindow->theme->aspect_ratios,
789 this->mwindow = mwindow;
790 this->output_w = output_w;
791 this->output_h = output_h;
793 int AspectPulldown::handle_event()
795 char *text = get_selection(0, 0)->get_text();
796 char string[BCTEXTLEN];
800 strcpy(string, text);
801 ptr = strrchr(string, ':');
811 output_w->handle_event();
812 output_h->handle_event();
817 ColormodelItem::ColormodelItem(const char *text, int value)
818 : BC_ListBoxItem(text)
823 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
824 BC_TextBox *output_text,
833 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
840 this->mwindow = mwindow;
841 this->output_text = output_text;
842 this->output_value = output_value;
843 output_text->update(colormodel_to_text());
846 int ColormodelPulldown::handle_event()
848 output_text->update(get_selection(0, 0)->get_text());
849 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
853 const char* ColormodelPulldown::colormodel_to_text()
855 for(int i = 0; i < mwindow->colormodels.total; i++)
856 if(mwindow->colormodels.values[i]->value == *output_value)
857 return mwindow->colormodels.values[i]->get_text();
861 void ColormodelPulldown::update_value(int value)
863 *output_value = value;
864 output_text->update(colormodel_to_text());
868 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
869 : BC_ListBoxItem(text)
874 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
875 BC_TextBox *output_text,
877 ArrayList<BC_ListBoxItem*> *data,
880 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
882 this->mwindow = mwindow;
883 this->output_text = output_text;
884 this->output_value = output_value;
885 output_text->update(interlacemode_to_text());
888 int InterlacemodePulldown::handle_event()
890 output_text->update(get_selection(0, 0)->get_text());
891 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
895 const char* InterlacemodePulldown::interlacemode_to_text()
897 ilacemode_to_text(this->string,*output_value);
898 return (this->string);
901 int InterlacemodePulldown::update(int interlace_mode)
903 *output_value = interlace_mode;
904 output_text->update(interlacemode_to_text());
909 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
910 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
912 this->nwindow = nwindow;
914 NewAspectAuto::~NewAspectAuto()
917 int NewAspectAuto::handle_event()
919 nwindow->new_thread->auto_aspect = get_value();
920 nwindow->new_thread->update_aspect();
931 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
932 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
934 this->mwindow = mwindow;
936 set_tooltip(_("Swap dimensions"));
939 int NewSwapExtents::handle_event()
941 int w = gui->new_edl->session->output_w;
942 int h = gui->new_edl->session->output_h;
943 gui->new_edl->session->output_w = h;
944 gui->new_edl->session->output_h = w;
945 gui->output_w_text->update((int64_t)h);
946 gui->output_h_text->update((int64_t)w);
947 gui->new_thread->update_aspect();