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()
89 new_edl->create_objects();
90 new_edl->load_defaults(mwindow->defaults);
95 int New::create_new_project()
97 mwindow->stop_playback(0);
98 mwindow->gui->lock_window();
99 mwindow->reset_caches();
101 memcpy(new_edl->session->achannel_positions,
102 &mwindow->preferences->channel_positions[new_edl->session->audio_channels - 1],
103 sizeof(new_edl->session->achannel_positions));
104 new_edl->session->boundaries();
105 new_edl->create_default_tracks();
107 mwindow->undo->update_undo_before();
108 mwindow->set_filename("");
110 mwindow->hide_plugins();
111 mwindow->edl->Garbage::remove_user();
112 mwindow->edl = new_edl;
114 mwindow->save_defaults();
116 // Load file sequence
117 mwindow->update_project(LOADMODE_REPLACE);
118 mwindow->session->changes_made = 0;
119 mwindow->undo->update_undo_after(_("New Project"), LOAD_ALL);
120 mwindow->gui->unlock_window();
124 NewThread::NewThread(MWindow *mwindow, New *new_project)
127 this->mwindow = mwindow;
128 this->new_project = new_project;
132 NewThread::~NewThread()
137 BC_Window* NewThread::new_gui()
139 mwindow->edl->save_defaults(mwindow->defaults);
140 new_project->create_new_edl();
143 mwindow->gui->lock_window("NewThread::new_gui");
144 int x = mwindow->gui->get_pop_cursor_x(0);
145 int y = mwindow->gui->get_pop_cursor_y(0);
147 nwindow = new NewWindow(mwindow, this, x, y);
148 nwindow->create_objects();
149 mwindow->gui->unlock_window();
153 void NewThread::handle_close_event(int result)
155 if( !new_project->new_edl ) return;
156 new_project->new_edl->save_defaults(mwindow->defaults);
157 mwindow->defaults->save();
161 if( !new_project->new_edl->Garbage::remove_user() )
162 new_project->new_edl = 0;
165 new_project->create_new_project();
169 int NewThread::load_defaults()
171 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
175 int NewThread::save_defaults()
177 mwindow->defaults->update("AUTOASPECT", auto_aspect);
181 int NewThread::update_aspect()
184 char string[BCTEXTLEN];
185 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
186 new_project->new_edl->session->aspect_h,
187 new_project->new_edl->session->output_w,
188 new_project->new_edl->session->output_h);
189 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
190 nwindow->aspect_w_text->update(string);
191 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
192 nwindow->aspect_h_text->update(string);
198 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
199 : BC_Window(_(PROGRAM_NAME ": New Project"), x, y, WIDTH, HEIGHT,
202 this->mwindow = mwindow;
203 this->new_thread = new_thread;
204 this->new_edl = new_thread->new_project->new_edl;
208 NewWindow::~NewWindow()
210 lock_window("NewWindow::~NewWindow");
211 if( format_presets ) delete format_presets;
215 void NewWindow::create_objects()
217 int x = 10, y = 10, x1, y1;
220 lock_window("NewWindow::create_objects");
221 mwindow->theme->draw_new_bg(this);
223 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
226 format_presets = new NewPresets(mwindow,
230 format_presets->create_objects();
231 x = format_presets->x;
232 y = format_presets->y;
236 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
240 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
242 add_subwindow(atracks = new NewATracks(this, "", x1, y));
243 x1 += atracks->get_w();
244 add_subwindow(new NewATracksTumbler(this, x1, y));
245 y += atracks->get_h() + 5;
248 add_subwindow(new BC_Title(x1, y, _("Channels:")));
250 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
251 x1 += achannels->get_w();
252 add_subwindow(new NewAChannelsTumbler(this, x1, y));
253 y += achannels->get_h() + 5;
256 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
258 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
259 x1 += sample_rate->get_w();
260 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
264 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
267 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
269 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
270 x1 += vtracks->get_w();
271 add_subwindow(new NewVTracksTumbler(this, x1, y));
272 y += vtracks->get_h() + 5;
275 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
277 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
278 // x1 += vchannels->get_w();
279 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
280 // y += vchannels->get_h() + 5;
282 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
284 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
285 x1 += frame_rate->get_w();
286 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
287 y += frame_rate->get_h() + 5;
290 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
292 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
293 // x1 += canvas_w_text->get_w() + 2;
294 // add_subwindow(new BC_Title(x1, y, "x"));
296 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
297 // x1 += canvas_h_text->get_w();
298 // add_subwindow(new FrameSizePulldown(mwindow,
304 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
305 // y += canvas_h_text->get_h() + 5;
308 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
310 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
311 x1 += output_w_text->get_w() + 2;
312 add_subwindow(new BC_Title(x1, y, "x"));
314 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
315 x1 += output_h_text->get_w();
316 FrameSizePulldown *pulldown;
317 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
322 x1 += pulldown->get_w() + 10;
323 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
324 y += output_h_text->get_h() + 5;
327 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
329 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
330 x1 += aspect_w_text->get_w() + 2;
331 add_subwindow(new BC_Title(x1, y, ":"));
333 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
334 x1 += aspect_h_text->get_w();
335 add_subwindow(new AspectPulldown(mwindow,
336 aspect_w_text, aspect_h_text, x1, y));
338 x1 = aspect_w_text->get_x();
339 y += aspect_w_text->get_h() + 5;
340 add_subwindow(new NewAspectAuto(this, x1, y));
343 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
344 x1 = x + title->get_w();
345 y1 = y; y += title->get_h() + 10;
346 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
347 int x2 = x + title->get_w();
348 int y2 = y; y += title->get_h() + 10;
349 if( x1 < x2 ) x1 = x2;
351 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
352 add_subwindow(color_model = new ColormodelPulldown(mwindow,
353 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
354 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
355 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
356 textbox, &new_edl->session->interlace_mode,
357 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
358 x1+textbox->get_w(), y2));
360 add_subwindow(new BC_OKButton(this,
361 mwindow->theme->get_image_set("new_ok_images")));
362 add_subwindow(new BC_CancelButton(this,
363 mwindow->theme->get_image_set("new_cancel_images")));
370 int NewWindow::update()
372 atracks->update((int64_t)new_edl->session->audio_tracks);
373 achannels->update((int64_t)new_edl->session->audio_channels);
374 sample_rate->update((int64_t)new_edl->session->sample_rate);
375 vtracks->update((int64_t)new_edl->session->video_tracks);
376 frame_rate->update((float)new_edl->session->frame_rate);
377 output_w_text->update((int64_t)new_edl->session->output_w);
378 output_h_text->update((int64_t)new_edl->session->output_h);
379 aspect_w_text->update((float)new_edl->session->aspect_w);
380 aspect_h_text->update((float)new_edl->session->aspect_h);
381 interlace_pulldown->update(new_edl->session->interlace_mode);
382 color_model->update_value(new_edl->session->color_model);
387 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
388 : FormatPresets(mwindow, gui, 0, x, y)
392 NewPresets::~NewPresets()
396 int NewPresets::handle_event()
402 EDL* NewPresets::get_edl()
404 return new_gui->new_edl;
408 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
409 : BC_TextBox(x, y, 90, 1, text)
411 this->nwindow = nwindow;
414 int NewATracks::handle_event()
416 nwindow->new_edl->session->audio_tracks = atol(get_text());
420 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
423 this->nwindow = nwindow;
425 int NewATracksTumbler::handle_up_event()
427 nwindow->new_edl->session->audio_tracks++;
428 nwindow->new_edl->boundaries();
432 int NewATracksTumbler::handle_down_event()
434 nwindow->new_edl->session->audio_tracks--;
435 nwindow->new_edl->boundaries();
441 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
442 : BC_TextBox(x, y, 90, 1, text)
444 this->nwindow = nwindow;
447 int NewAChannels::handle_event()
449 nwindow->new_edl->session->audio_channels = atol(get_text());
454 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
457 this->nwindow = nwindow;
459 int NewAChannelsTumbler::handle_up_event()
461 nwindow->new_edl->session->audio_channels++;
462 nwindow->new_edl->boundaries();
466 int NewAChannelsTumbler::handle_down_event()
468 nwindow->new_edl->session->audio_channels--;
469 nwindow->new_edl->boundaries();
475 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
476 : BC_TextBox(x, y, 90, 1, text)
478 this->nwindow = nwindow;
481 int NewSampleRate::handle_event()
483 nwindow->new_edl->session->sample_rate = atol(get_text());
488 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
489 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
490 &mwindow->theme->sample_rates, 0, 0, 1, 0, 1)
492 this->mwindow = mwindow;
493 this->output = output;
495 int SampleRatePulldown::handle_event()
497 char *text = get_selection(0, 0)->get_text();
498 output->update(text);
499 output->handle_event();
504 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
505 : BC_TextBox(x, y, 90, 1, text)
507 this->nwindow = nwindow;
510 int NewVTracks::handle_event()
512 nwindow->new_edl->session->video_tracks = atol(get_text());
517 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
520 this->nwindow = nwindow;
522 int NewVTracksTumbler::handle_up_event()
524 nwindow->new_edl->session->video_tracks++;
525 nwindow->new_edl->boundaries();
529 int NewVTracksTumbler::handle_down_event()
531 nwindow->new_edl->session->video_tracks--;
532 nwindow->new_edl->boundaries();
538 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
539 : BC_TextBox(x, y, 90, 1, text)
541 this->nwindow = nwindow;
544 int NewVChannels::handle_event()
546 nwindow->new_edl->session->video_channels = atol(get_text());
551 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
554 this->nwindow = nwindow;
556 int NewVChannelsTumbler::handle_up_event()
558 nwindow->new_edl->session->video_channels++;
559 nwindow->new_edl->boundaries();
563 int NewVChannelsTumbler::handle_down_event()
565 nwindow->new_edl->session->video_channels--;
566 nwindow->new_edl->boundaries();
572 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
573 : BC_TextBox(x, y, 90, 1, text)
575 this->nwindow = nwindow;
578 int NewFrameRate::handle_event()
580 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
585 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
586 BC_TextBox *output, int x, int y)
587 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
588 &mwindow->theme->frame_rates, 0, 0, 1, 0, 1)
590 this->mwindow = mwindow;
591 this->output = output;
593 int FrameRatePulldown::handle_event()
595 char *text = get_selection(0, 0)->get_text();
596 output->update(text);
597 output->handle_event();
601 FrameSizePulldown::FrameSizePulldown(Theme *theme,
602 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
603 : BC_ListBox(x, y, 180, 250, LISTBOX_TEXT,
604 &theme->frame_sizes, 0, 0, 1, 0, 1)
607 this->output_w = output_w;
608 this->output_h = output_h;
611 int FrameSizePulldown::handle_event()
613 char *text = get_selection(0, 0)->get_text();
614 char string[BCTEXTLEN];
618 strcpy(string, text);
619 ptr = strrchr(string, 'x');
628 output_w->handle_event();
629 output_h->handle_event();
635 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
636 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
638 this->nwindow = nwindow;
640 int NewOutputW::handle_event()
642 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
643 nwindow->new_thread->update_aspect();
648 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
649 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
651 this->nwindow = nwindow;
653 int NewOutputH::handle_event()
655 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
656 nwindow->new_thread->update_aspect();
661 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
662 : BC_TextBox(x, y, 70, 1, text)
664 this->nwindow = nwindow;
667 int NewAspectW::handle_event()
669 nwindow->new_edl->session->aspect_w = atof(get_text());
674 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
675 : BC_TextBox(x, y, 70, 1, text)
677 this->nwindow = nwindow;
680 int NewAspectH::handle_event()
682 nwindow->new_edl->session->aspect_h = atof(get_text());
687 AspectPulldown::AspectPulldown(MWindow *mwindow,
688 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
689 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
690 &mwindow->theme->aspect_ratios, 0, 0, 1, 0, 1)
692 this->mwindow = mwindow;
693 this->output_w = output_w;
694 this->output_h = output_h;
697 int AspectPulldown::handle_event()
699 char *text = get_selection(0, 0)->get_text();
700 char string[BCTEXTLEN];
704 strcpy(string, text);
705 ptr = strrchr(string, ':');
714 output_w->handle_event();
715 output_h->handle_event();
721 ColormodelItem::ColormodelItem(const char *text, int value)
722 : BC_ListBoxItem(text)
727 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
728 BC_TextBox *output_text, int *output_value, int x, int y)
729 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT,
730 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels, 0, 0, 1, 0, 1)
732 this->mwindow = mwindow;
733 this->output_text = output_text;
734 this->output_value = output_value;
735 output_text->update(colormodel_to_text());
738 int ColormodelPulldown::handle_event()
740 output_text->update(get_selection(0, 0)->get_text());
741 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
745 const char* ColormodelPulldown::colormodel_to_text()
747 for( int i=0; i<mwindow->colormodels.total; ++i )
748 if( mwindow->colormodels.values[i]->value == *output_value )
749 return mwindow->colormodels.values[i]->get_text();
753 void ColormodelPulldown::update_value(int value)
755 *output_value = value;
756 output_text->update(colormodel_to_text());
760 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
761 : BC_ListBoxItem(text)
766 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
767 BC_TextBox *output_text,
769 ArrayList<BC_ListBoxItem*> *data,
772 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
774 this->mwindow = mwindow;
775 this->output_text = output_text;
776 this->output_value = output_value;
777 output_text->update(interlacemode_to_text());
780 int InterlacemodePulldown::handle_event()
782 output_text->update(get_selection(0, 0)->get_text());
783 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
787 const char* InterlacemodePulldown::interlacemode_to_text()
789 ilacemode_to_text(this->string,*output_value);
790 return (this->string);
793 int InterlacemodePulldown::update(int interlace_mode)
795 *output_value = interlace_mode;
796 output_text->update(interlacemode_to_text());
801 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
802 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
804 this->nwindow = nwindow;
806 NewAspectAuto::~NewAspectAuto()
809 int NewAspectAuto::handle_event()
811 nwindow->new_thread->auto_aspect = get_value();
812 nwindow->new_thread->update_aspect();
817 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
818 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
820 this->mwindow = mwindow;
822 set_tooltip(_("Swap dimensions"));
825 int NewSwapExtents::handle_event()
827 int w = gui->new_edl->session->output_w;
828 int h = gui->new_edl->session->output_h;
829 gui->new_edl->session->output_w = h;
830 gui->new_edl->session->output_h = w;
831 gui->output_w_text->update((int64_t)h);
832 gui->output_h_text->update((int64_t)w);
833 gui->new_thread->update_aspect();