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)
56 : BC_MenuItem(_("New Project..."), "n", 'n')
58 this->mwindow = mwindow;
69 void New::create_objects()
71 thread = new NewThread(mwindow, this);
74 int New::handle_event()
76 mwindow->gui->unlock_window();
77 mwindow->edl->save_defaults(mwindow->defaults);
80 mwindow->gui->lock_window("New::handle_event");
85 void New::create_new_edl()
90 new_edl->create_objects();
91 new_edl->load_defaults(mwindow->defaults);
96 int New::create_new_project()
98 mwindow->cwindow->playback_engine->que->send_command(STOP,
103 for(int i = 0; i < mwindow->vwindows.size(); i++)
105 VWindow *vwindow = mwindow->vwindows.get(i);
106 if( !vwindow->is_running() ) continue;
107 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
108 vwindow->playback_engine->interrupt_playback(0);
111 mwindow->cwindow->playback_engine->interrupt_playback(0);
113 mwindow->gui->lock_window();
114 mwindow->reset_caches();
118 memcpy(new_edl->session->achannel_positions,
119 &mwindow->preferences->channel_positions[
120 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
121 sizeof(int) * MAXCHANNELS);
122 new_edl->session->boundaries();
123 new_edl->create_default_tracks();
125 mwindow->undo->update_undo_before();
126 mwindow->set_filename("");
128 mwindow->hide_plugins();
129 mwindow->edl->Garbage::remove_user();
130 mwindow->edl = new_edl;
132 mwindow->save_defaults();
134 // Load file sequence
135 mwindow->update_project(LOADMODE_REPLACE);
136 mwindow->session->changes_made = 0;
137 mwindow->undo->update_undo_after(_("New Project"), LOAD_ALL);
138 mwindow->gui->unlock_window();
142 NewThread::NewThread(MWindow *mwindow, New *new_project)
145 this->mwindow = mwindow;
146 this->new_project = new_project;
150 NewThread::~NewThread()
157 BC_Window* NewThread::new_gui()
159 mwindow->edl->save_defaults(mwindow->defaults);
160 new_project->create_new_edl();
163 mwindow->gui->lock_window("NewThread::new_gui");
164 int x = mwindow->gui->get_pop_cursor_x(0);
165 int y = mwindow->gui->get_pop_cursor_y(0);
167 nwindow = new NewWindow(mwindow, this, x, y);
168 nwindow->create_objects();
169 mwindow->gui->unlock_window();
175 void NewThread::handle_close_event(int result)
178 if( !new_project->new_edl ) return;
179 new_project->new_edl->save_defaults(mwindow->defaults);
180 mwindow->defaults->save();
185 if( !new_project->new_edl->Garbage::remove_user() )
186 new_project->new_edl = 0;
190 new_project->create_new_project();
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()
212 char string[BCTEXTLEN];
213 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
214 new_project->new_edl->session->aspect_h,
215 new_project->new_edl->session->output_w,
216 new_project->new_edl->session->output_h);
217 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
218 nwindow->aspect_w_text->update(string);
219 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
220 nwindow->aspect_h_text->update(string);
228 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
229 : BC_Window(_(PROGRAM_NAME ": New Project"), x, y, WIDTH, HEIGHT,
232 this->mwindow = mwindow;
233 this->new_thread = new_thread;
234 this->new_edl = new_thread->new_project->new_edl;
238 NewWindow::~NewWindow()
240 lock_window("NewWindow::~NewWindow");
241 if(format_presets) delete format_presets;
245 void NewWindow::create_objects()
247 int x = 10, y = 10, x1, y1;
250 lock_window("NewWindow::create_objects");
251 mwindow->theme->draw_new_bg(this);
253 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
256 format_presets = new NewPresets(mwindow,
260 format_presets->create_objects();
261 x = format_presets->x;
262 y = format_presets->y;
268 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
272 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
274 add_subwindow(atracks = new NewATracks(this, "", x1, y));
275 x1 += atracks->get_w();
276 add_subwindow(new NewATracksTumbler(this, x1, y));
277 y += atracks->get_h() + 5;
280 add_subwindow(new BC_Title(x1, y, _("Channels:")));
282 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
283 x1 += achannels->get_w();
284 add_subwindow(new NewAChannelsTumbler(this, x1, y));
285 y += achannels->get_h() + 5;
288 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
290 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
291 x1 += sample_rate->get_w();
292 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
296 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
299 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
301 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
302 x1 += vtracks->get_w();
303 add_subwindow(new NewVTracksTumbler(this, x1, y));
304 y += vtracks->get_h() + 5;
307 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
309 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
310 // x1 += vchannels->get_w();
311 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
312 // y += vchannels->get_h() + 5;
314 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
316 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
317 x1 += frame_rate->get_w();
318 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
319 y += frame_rate->get_h() + 5;
322 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
324 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
325 // x1 += canvas_w_text->get_w() + 2;
326 // add_subwindow(new BC_Title(x1, y, "x"));
328 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
329 // x1 += canvas_h_text->get_w();
330 // add_subwindow(new FrameSizePulldown(mwindow,
336 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
337 // y += canvas_h_text->get_h() + 5;
340 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
342 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
343 x1 += output_w_text->get_w() + 2;
344 add_subwindow(new BC_Title(x1, y, "x"));
346 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
347 x1 += output_h_text->get_w();
348 FrameSizePulldown *pulldown;
349 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
354 x1 += pulldown->get_w() + 10;
355 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
356 y += output_h_text->get_h() + 5;
359 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
361 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
362 x1 += aspect_w_text->get_w() + 2;
363 add_subwindow(new BC_Title(x1, y, ":"));
365 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
366 x1 += aspect_h_text->get_w();
367 add_subwindow(new AspectPulldown(mwindow,
373 x1 = aspect_w_text->get_x();
374 y += aspect_w_text->get_h() + 5;
375 add_subwindow(new NewAspectAuto(this, x1, y));
378 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
379 x1 = x + title->get_w();
380 y1 = y; y += title->get_h() + 10;
381 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
382 int x2 = x + title->get_w();
383 int y2 = y; y += title->get_h() + 10;
384 if( x1 < x2 ) x1 = x2;
386 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
387 add_subwindow(color_model = new ColormodelPulldown(mwindow,
388 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
389 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
390 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
391 textbox, &new_edl->session->interlace_mode,
392 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
393 x1+textbox->get_w(), y2));
395 add_subwindow(new BC_OKButton(this,
396 mwindow->theme->get_image_set("new_ok_images")));
397 add_subwindow(new BC_CancelButton(this,
398 mwindow->theme->get_image_set("new_cancel_images")));
405 int NewWindow::update()
407 atracks->update((int64_t)new_edl->session->audio_tracks);
408 achannels->update((int64_t)new_edl->session->audio_channels);
409 sample_rate->update((int64_t)new_edl->session->sample_rate);
410 vtracks->update((int64_t)new_edl->session->video_tracks);
411 frame_rate->update((float)new_edl->session->frame_rate);
412 output_w_text->update((int64_t)new_edl->session->output_w);
413 output_h_text->update((int64_t)new_edl->session->output_h);
414 aspect_w_text->update((float)new_edl->session->aspect_w);
415 aspect_h_text->update((float)new_edl->session->aspect_h);
416 interlace_pulldown->update(new_edl->session->interlace_mode);
417 color_model->update_value(new_edl->session->color_model);
427 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
428 : FormatPresets(mwindow, gui, 0, x, y)
432 NewPresets::~NewPresets()
436 int NewPresets::handle_event()
442 EDL* NewPresets::get_edl()
444 return new_gui->new_edl;
449 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
450 : BC_TextBox(x, y, 90, 1, text)
452 this->nwindow = nwindow;
455 int NewATracks::handle_event()
457 nwindow->new_edl->session->audio_tracks = atol(get_text());
461 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
464 this->nwindow = nwindow;
466 int NewATracksTumbler::handle_up_event()
468 nwindow->new_edl->session->audio_tracks++;
469 nwindow->new_edl->boundaries();
473 int NewATracksTumbler::handle_down_event()
475 nwindow->new_edl->session->audio_tracks--;
476 nwindow->new_edl->boundaries();
481 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
482 : BC_TextBox(x, y, 90, 1, text)
484 this->nwindow = nwindow;
487 int NewAChannels::handle_event()
489 nwindow->new_edl->session->audio_channels = atol(get_text());
493 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
496 this->nwindow = nwindow;
498 int NewAChannelsTumbler::handle_up_event()
500 nwindow->new_edl->session->audio_channels++;
501 nwindow->new_edl->boundaries();
505 int NewAChannelsTumbler::handle_down_event()
507 nwindow->new_edl->session->audio_channels--;
508 nwindow->new_edl->boundaries();
514 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
515 : BC_TextBox(x, y, 90, 1, text)
517 this->nwindow = nwindow;
520 int NewSampleRate::handle_event()
522 nwindow->new_edl->session->sample_rate = atol(get_text());
526 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
532 &mwindow->theme->sample_rates,
539 this->mwindow = mwindow;
540 this->output = output;
542 int SampleRatePulldown::handle_event()
544 char *text = get_selection(0, 0)->get_text();
545 output->update(text);
546 output->handle_event();
564 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
565 : BC_TextBox(x, y, 90, 1, text)
567 this->nwindow = nwindow;
570 int NewVTracks::handle_event()
572 nwindow->new_edl->session->video_tracks = atol(get_text());
576 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
579 this->nwindow = nwindow;
581 int NewVTracksTumbler::handle_up_event()
583 nwindow->new_edl->session->video_tracks++;
584 nwindow->new_edl->boundaries();
588 int NewVTracksTumbler::handle_down_event()
590 nwindow->new_edl->session->video_tracks--;
591 nwindow->new_edl->boundaries();
596 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
597 : BC_TextBox(x, y, 90, 1, text)
599 this->nwindow = nwindow;
602 int NewVChannels::handle_event()
604 nwindow->new_edl->session->video_channels = atol(get_text());
608 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
611 this->nwindow = nwindow;
613 int NewVChannelsTumbler::handle_up_event()
615 nwindow->new_edl->session->video_channels++;
616 nwindow->new_edl->boundaries();
620 int NewVChannelsTumbler::handle_down_event()
622 nwindow->new_edl->session->video_channels--;
623 nwindow->new_edl->boundaries();
628 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
629 : BC_TextBox(x, y, 90, 1, text)
631 this->nwindow = nwindow;
634 int NewFrameRate::handle_event()
636 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
640 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
649 &mwindow->theme->frame_rates,
656 this->mwindow = mwindow;
657 this->output = output;
659 int FrameRatePulldown::handle_event()
661 char *text = get_selection(0, 0)->get_text();
662 output->update(text);
663 output->handle_event();
667 FrameSizePulldown::FrameSizePulldown(Theme *theme,
668 BC_TextBox *output_w,
669 BC_TextBox *output_h,
685 this->output_w = output_w;
686 this->output_h = output_h;
688 int FrameSizePulldown::handle_event()
690 char *text = get_selection(0, 0)->get_text();
691 char string[BCTEXTLEN];
695 strcpy(string, text);
696 ptr = strrchr(string, 'x');
706 output_w->handle_event();
707 output_h->handle_event();
712 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
713 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
715 this->nwindow = nwindow;
717 int NewOutputW::handle_event()
719 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
720 nwindow->new_thread->update_aspect();
724 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
725 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
727 this->nwindow = nwindow;
729 int NewOutputH::handle_event()
731 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
732 nwindow->new_thread->update_aspect();
736 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
737 : BC_TextBox(x, y, 70, 1, text)
739 this->nwindow = nwindow;
742 int NewAspectW::handle_event()
744 nwindow->new_edl->session->aspect_w = atof(get_text());
748 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
749 : BC_TextBox(x, y, 70, 1, text)
751 this->nwindow = nwindow;
754 int NewAspectH::handle_event()
756 nwindow->new_edl->session->aspect_h = atof(get_text());
760 AspectPulldown::AspectPulldown(MWindow *mwindow,
761 BC_TextBox *output_w,
762 BC_TextBox *output_h,
770 &mwindow->theme->aspect_ratios,
777 this->mwindow = mwindow;
778 this->output_w = output_w;
779 this->output_h = output_h;
781 int AspectPulldown::handle_event()
783 char *text = get_selection(0, 0)->get_text();
784 char string[BCTEXTLEN];
788 strcpy(string, text);
789 ptr = strrchr(string, ':');
799 output_w->handle_event();
800 output_h->handle_event();
805 ColormodelItem::ColormodelItem(const char *text, int value)
806 : BC_ListBoxItem(text)
811 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
812 BC_TextBox *output_text,
821 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
828 this->mwindow = mwindow;
829 this->output_text = output_text;
830 this->output_value = output_value;
831 output_text->update(colormodel_to_text());
834 int ColormodelPulldown::handle_event()
836 output_text->update(get_selection(0, 0)->get_text());
837 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
841 const char* ColormodelPulldown::colormodel_to_text()
843 for(int i = 0; i < mwindow->colormodels.total; i++)
844 if(mwindow->colormodels.values[i]->value == *output_value)
845 return mwindow->colormodels.values[i]->get_text();
849 void ColormodelPulldown::update_value(int value)
851 *output_value = value;
852 output_text->update(colormodel_to_text());
856 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
857 : BC_ListBoxItem(text)
862 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
863 BC_TextBox *output_text,
865 ArrayList<BC_ListBoxItem*> *data,
868 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
870 this->mwindow = mwindow;
871 this->output_text = output_text;
872 this->output_value = output_value;
873 output_text->update(interlacemode_to_text());
876 int InterlacemodePulldown::handle_event()
878 output_text->update(get_selection(0, 0)->get_text());
879 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
883 const char* InterlacemodePulldown::interlacemode_to_text()
885 ilacemode_to_text(this->string,*output_value);
886 return (this->string);
889 int InterlacemodePulldown::update(int interlace_mode)
891 *output_value = interlace_mode;
892 output_text->update(interlacemode_to_text());
897 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
898 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
900 this->nwindow = nwindow;
902 NewAspectAuto::~NewAspectAuto()
905 int NewAspectAuto::handle_event()
907 nwindow->new_thread->auto_aspect = get_value();
908 nwindow->new_thread->update_aspect();
919 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
920 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
922 this->mwindow = mwindow;
924 set_tooltip(_("Swap dimensions"));
927 int NewSwapExtents::handle_event()
929 int w = gui->new_edl->session->output_w;
930 int h = gui->new_edl->session->output_h;
931 gui->new_edl->session->output_w = h;
932 gui->new_edl->session->output_h = w;
933 gui->output_w_text->update((int64_t)h);
934 gui->output_h_text->update((int64_t)w);
935 gui->new_thread->update_aspect();