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);
81 mwindow->gui->lock_window("New::handle_event");
86 void New::create_new_edl()
91 new_edl->create_objects();
92 new_edl->load_defaults(mwindow->defaults);
97 int New::create_new_project()
99 mwindow->cwindow->playback_engine->que->send_command(STOP,
104 for(int i = 0; i < mwindow->vwindows.size(); i++)
106 VWindow *vwindow = mwindow->vwindows.get(i);
107 if( !vwindow->is_running() ) continue;
108 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
109 vwindow->playback_engine->interrupt_playback(0);
112 mwindow->cwindow->playback_engine->interrupt_playback(0);
114 mwindow->gui->lock_window();
115 mwindow->reset_caches();
119 memcpy(new_edl->session->achannel_positions,
120 &mwindow->preferences->channel_positions[
121 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
122 sizeof(int) * MAXCHANNELS);
123 new_edl->session->boundaries();
124 new_edl->create_default_tracks();
126 mwindow->undo->update_undo_before();
127 mwindow->set_filename("");
129 mwindow->hide_plugins();
130 mwindow->edl->Garbage::remove_user();
131 mwindow->edl = new_edl;
133 mwindow->save_defaults();
135 // Load file sequence
136 mwindow->update_project(LOADMODE_REPLACE);
137 mwindow->session->changes_made = 0;
138 mwindow->undo->update_undo_after(_("New Project"), LOAD_ALL);
139 mwindow->gui->unlock_window();
143 NewThread::NewThread(MWindow *mwindow, New *new_project)
146 this->mwindow = mwindow;
147 this->new_project = new_project;
151 NewThread::~NewThread()
158 BC_Window* NewThread::new_gui()
160 mwindow->edl->save_defaults(mwindow->defaults);
161 new_project->create_new_edl();
164 mwindow->gui->lock_window("NewThread::new_gui");
165 int x = mwindow->gui->get_pop_cursor_x(0);
166 int y = mwindow->gui->get_pop_cursor_y(0);
168 nwindow = new NewWindow(mwindow, this, x, y);
169 nwindow->create_objects();
170 mwindow->gui->unlock_window();
176 void NewThread::handle_close_event(int result)
179 if( !new_project->new_edl ) return;
180 new_project->new_edl->save_defaults(mwindow->defaults);
181 mwindow->defaults->save();
186 if( !new_project->new_edl->Garbage::remove_user() )
187 new_project->new_edl = 0;
191 new_project->create_new_project();
197 int NewThread::load_defaults()
199 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
203 int NewThread::save_defaults()
205 mwindow->defaults->update("AUTOASPECT", auto_aspect);
209 int NewThread::update_aspect()
213 char string[BCTEXTLEN];
214 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
215 new_project->new_edl->session->aspect_h,
216 new_project->new_edl->session->output_w,
217 new_project->new_edl->session->output_h);
218 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
219 nwindow->aspect_w_text->update(string);
220 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
221 nwindow->aspect_h_text->update(string);
229 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
230 : BC_Window(_(PROGRAM_NAME ": New Project"), x, y, WIDTH, HEIGHT,
233 this->mwindow = mwindow;
234 this->new_thread = new_thread;
235 this->new_edl = new_thread->new_project->new_edl;
239 NewWindow::~NewWindow()
241 lock_window("NewWindow::~NewWindow");
242 if(format_presets) delete format_presets;
246 void NewWindow::create_objects()
248 int x = 10, y = 10, x1, y1;
251 lock_window("NewWindow::create_objects");
252 mwindow->theme->draw_new_bg(this);
254 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
257 format_presets = new NewPresets(mwindow,
261 format_presets->create_objects();
262 x = format_presets->x;
263 y = format_presets->y;
269 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
273 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
275 add_subwindow(atracks = new NewATracks(this, "", x1, y));
276 x1 += atracks->get_w();
277 add_subwindow(new NewATracksTumbler(this, x1, y));
278 y += atracks->get_h() + 5;
281 add_subwindow(new BC_Title(x1, y, _("Channels:")));
283 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
284 x1 += achannels->get_w();
285 add_subwindow(new NewAChannelsTumbler(this, x1, y));
286 y += achannels->get_h() + 5;
289 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
291 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
292 x1 += sample_rate->get_w();
293 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
297 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
300 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
302 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
303 x1 += vtracks->get_w();
304 add_subwindow(new NewVTracksTumbler(this, x1, y));
305 y += vtracks->get_h() + 5;
308 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
310 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
311 // x1 += vchannels->get_w();
312 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
313 // y += vchannels->get_h() + 5;
315 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
317 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
318 x1 += frame_rate->get_w();
319 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
320 y += frame_rate->get_h() + 5;
323 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
325 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
326 // x1 += canvas_w_text->get_w() + 2;
327 // add_subwindow(new BC_Title(x1, y, "x"));
329 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
330 // x1 += canvas_h_text->get_w();
331 // add_subwindow(new FrameSizePulldown(mwindow,
337 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
338 // y += canvas_h_text->get_h() + 5;
341 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
343 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
344 x1 += output_w_text->get_w() + 2;
345 add_subwindow(new BC_Title(x1, y, "x"));
347 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
348 x1 += output_h_text->get_w();
349 FrameSizePulldown *pulldown;
350 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
355 x1 += pulldown->get_w() + 10;
356 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
357 y += output_h_text->get_h() + 5;
360 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
362 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
363 x1 += aspect_w_text->get_w() + 2;
364 add_subwindow(new BC_Title(x1, y, ":"));
366 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
367 x1 += aspect_h_text->get_w();
368 add_subwindow(new AspectPulldown(mwindow,
374 x1 = aspect_w_text->get_x();
375 y += aspect_w_text->get_h() + 5;
376 add_subwindow(new NewAspectAuto(this, x1, y));
379 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
380 x1 = x + title->get_w();
381 y1 = y; y += title->get_h() + 10;
382 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
383 int x2 = x + title->get_w();
384 int y2 = y; y += title->get_h() + 10;
385 if( x1 < x2 ) x1 = x2;
387 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
388 add_subwindow(color_model = new ColormodelPulldown(mwindow,
389 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
390 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
391 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
392 textbox, &new_edl->session->interlace_mode,
393 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
394 x1+textbox->get_w(), y2));
396 add_subwindow(new BC_OKButton(this,
397 mwindow->theme->get_image_set("new_ok_images")));
398 add_subwindow(new BC_CancelButton(this,
399 mwindow->theme->get_image_set("new_cancel_images")));
406 int NewWindow::update()
408 atracks->update((int64_t)new_edl->session->audio_tracks);
409 achannels->update((int64_t)new_edl->session->audio_channels);
410 sample_rate->update((int64_t)new_edl->session->sample_rate);
411 vtracks->update((int64_t)new_edl->session->video_tracks);
412 frame_rate->update((float)new_edl->session->frame_rate);
413 output_w_text->update((int64_t)new_edl->session->output_w);
414 output_h_text->update((int64_t)new_edl->session->output_h);
415 aspect_w_text->update((float)new_edl->session->aspect_w);
416 aspect_h_text->update((float)new_edl->session->aspect_h);
417 interlace_pulldown->update(new_edl->session->interlace_mode);
418 color_model->update_value(new_edl->session->color_model);
428 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
429 : FormatPresets(mwindow, gui, 0, x, y)
433 NewPresets::~NewPresets()
437 int NewPresets::handle_event()
443 EDL* NewPresets::get_edl()
445 return new_gui->new_edl;
450 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
451 : BC_TextBox(x, y, 90, 1, text)
453 this->nwindow = nwindow;
456 int NewATracks::handle_event()
458 nwindow->new_edl->session->audio_tracks = atol(get_text());
462 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
465 this->nwindow = nwindow;
467 int NewATracksTumbler::handle_up_event()
469 nwindow->new_edl->session->audio_tracks++;
470 nwindow->new_edl->boundaries();
474 int NewATracksTumbler::handle_down_event()
476 nwindow->new_edl->session->audio_tracks--;
477 nwindow->new_edl->boundaries();
482 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
483 : BC_TextBox(x, y, 90, 1, text)
485 this->nwindow = nwindow;
488 int NewAChannels::handle_event()
490 nwindow->new_edl->session->audio_channels = atol(get_text());
494 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
497 this->nwindow = nwindow;
499 int NewAChannelsTumbler::handle_up_event()
501 nwindow->new_edl->session->audio_channels++;
502 nwindow->new_edl->boundaries();
506 int NewAChannelsTumbler::handle_down_event()
508 nwindow->new_edl->session->audio_channels--;
509 nwindow->new_edl->boundaries();
515 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
516 : BC_TextBox(x, y, 90, 1, text)
518 this->nwindow = nwindow;
521 int NewSampleRate::handle_event()
523 nwindow->new_edl->session->sample_rate = atol(get_text());
527 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
533 &mwindow->theme->sample_rates,
540 this->mwindow = mwindow;
541 this->output = output;
543 int SampleRatePulldown::handle_event()
545 char *text = get_selection(0, 0)->get_text();
546 output->update(text);
547 output->handle_event();
565 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
566 : BC_TextBox(x, y, 90, 1, text)
568 this->nwindow = nwindow;
571 int NewVTracks::handle_event()
573 nwindow->new_edl->session->video_tracks = atol(get_text());
577 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
580 this->nwindow = nwindow;
582 int NewVTracksTumbler::handle_up_event()
584 nwindow->new_edl->session->video_tracks++;
585 nwindow->new_edl->boundaries();
589 int NewVTracksTumbler::handle_down_event()
591 nwindow->new_edl->session->video_tracks--;
592 nwindow->new_edl->boundaries();
597 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
598 : BC_TextBox(x, y, 90, 1, text)
600 this->nwindow = nwindow;
603 int NewVChannels::handle_event()
605 nwindow->new_edl->session->video_channels = atol(get_text());
609 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
612 this->nwindow = nwindow;
614 int NewVChannelsTumbler::handle_up_event()
616 nwindow->new_edl->session->video_channels++;
617 nwindow->new_edl->boundaries();
621 int NewVChannelsTumbler::handle_down_event()
623 nwindow->new_edl->session->video_channels--;
624 nwindow->new_edl->boundaries();
629 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
630 : BC_TextBox(x, y, 90, 1, text)
632 this->nwindow = nwindow;
635 int NewFrameRate::handle_event()
637 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
641 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
650 &mwindow->theme->frame_rates,
657 this->mwindow = mwindow;
658 this->output = output;
660 int FrameRatePulldown::handle_event()
662 char *text = get_selection(0, 0)->get_text();
663 output->update(text);
664 output->handle_event();
668 FrameSizePulldown::FrameSizePulldown(Theme *theme,
669 BC_TextBox *output_w,
670 BC_TextBox *output_h,
686 this->output_w = output_w;
687 this->output_h = output_h;
689 int FrameSizePulldown::handle_event()
691 char *text = get_selection(0, 0)->get_text();
692 char string[BCTEXTLEN];
696 strcpy(string, text);
697 ptr = strrchr(string, 'x');
707 output_w->handle_event();
708 output_h->handle_event();
713 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
714 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
716 this->nwindow = nwindow;
718 int NewOutputW::handle_event()
720 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
721 nwindow->new_thread->update_aspect();
725 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
726 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
728 this->nwindow = nwindow;
730 int NewOutputH::handle_event()
732 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
733 nwindow->new_thread->update_aspect();
737 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
738 : BC_TextBox(x, y, 70, 1, text)
740 this->nwindow = nwindow;
743 int NewAspectW::handle_event()
745 nwindow->new_edl->session->aspect_w = atof(get_text());
749 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
750 : BC_TextBox(x, y, 70, 1, text)
752 this->nwindow = nwindow;
755 int NewAspectH::handle_event()
757 nwindow->new_edl->session->aspect_h = atof(get_text());
761 AspectPulldown::AspectPulldown(MWindow *mwindow,
762 BC_TextBox *output_w,
763 BC_TextBox *output_h,
771 &mwindow->theme->aspect_ratios,
778 this->mwindow = mwindow;
779 this->output_w = output_w;
780 this->output_h = output_h;
782 int AspectPulldown::handle_event()
784 char *text = get_selection(0, 0)->get_text();
785 char string[BCTEXTLEN];
789 strcpy(string, text);
790 ptr = strrchr(string, ':');
800 output_w->handle_event();
801 output_h->handle_event();
806 ColormodelItem::ColormodelItem(const char *text, int value)
807 : BC_ListBoxItem(text)
812 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
813 BC_TextBox *output_text,
822 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
829 this->mwindow = mwindow;
830 this->output_text = output_text;
831 this->output_value = output_value;
832 output_text->update(colormodel_to_text());
835 int ColormodelPulldown::handle_event()
837 output_text->update(get_selection(0, 0)->get_text());
838 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
842 const char* ColormodelPulldown::colormodel_to_text()
844 for(int i = 0; i < mwindow->colormodels.total; i++)
845 if(mwindow->colormodels.values[i]->value == *output_value)
846 return mwindow->colormodels.values[i]->get_text();
850 void ColormodelPulldown::update_value(int value)
852 *output_value = value;
853 output_text->update(colormodel_to_text());
857 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
858 : BC_ListBoxItem(text)
863 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
864 BC_TextBox *output_text,
866 ArrayList<BC_ListBoxItem*> *data,
869 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
871 this->mwindow = mwindow;
872 this->output_text = output_text;
873 this->output_value = output_value;
874 output_text->update(interlacemode_to_text());
877 int InterlacemodePulldown::handle_event()
879 output_text->update(get_selection(0, 0)->get_text());
880 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
884 const char* InterlacemodePulldown::interlacemode_to_text()
886 ilacemode_to_text(this->string,*output_value);
887 return (this->string);
890 int InterlacemodePulldown::update(int interlace_mode)
892 *output_value = interlace_mode;
893 output_text->update(interlacemode_to_text());
898 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
899 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
901 this->nwindow = nwindow;
903 NewAspectAuto::~NewAspectAuto()
906 int NewAspectAuto::handle_event()
908 nwindow->new_thread->auto_aspect = get_value();
909 nwindow->new_thread->update_aspect();
920 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
921 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
923 this->mwindow = mwindow;
925 set_tooltip(_("Swap dimensions"));
928 int NewSwapExtents::handle_event()
930 int w = gui->new_edl->session->output_w;
931 int h = gui->new_edl->session->output_h;
932 gui->new_edl->session->output_w = h;
933 gui->new_edl->session->output_h = w;
934 gui->output_w_text->update((int64_t)h);
935 gui->output_h_text->update((int64_t)w);
936 gui->new_thread->update_aspect();