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);
231 N_("Cinelerra: New Project");
234 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
235 : BC_Window(_(_(PROGRAM_NAME ": New Project")),
246 this->mwindow = mwindow;
247 this->new_thread = new_thread;
248 this->new_edl = new_thread->new_project->new_edl;
252 NewWindow::~NewWindow()
254 lock_window("NewWindow::~NewWindow");
255 if(format_presets) delete format_presets;
259 void NewWindow::create_objects()
261 int x = 10, y = 10, x1, y1;
264 lock_window("NewWindow::create_objects");
265 mwindow->theme->draw_new_bg(this);
267 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
270 format_presets = new NewPresets(mwindow,
274 format_presets->create_objects();
275 x = format_presets->x;
276 y = format_presets->y;
282 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
286 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
288 add_subwindow(atracks = new NewATracks(this, "", x1, y));
289 x1 += atracks->get_w();
290 add_subwindow(new NewATracksTumbler(this, x1, y));
291 y += atracks->get_h() + 5;
294 add_subwindow(new BC_Title(x1, y, _("Channels:")));
296 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
297 x1 += achannels->get_w();
298 add_subwindow(new NewAChannelsTumbler(this, x1, y));
299 y += achannels->get_h() + 5;
302 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
304 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
305 x1 += sample_rate->get_w();
306 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
310 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
313 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
315 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
316 x1 += vtracks->get_w();
317 add_subwindow(new NewVTracksTumbler(this, x1, y));
318 y += vtracks->get_h() + 5;
321 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
323 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
324 // x1 += vchannels->get_w();
325 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
326 // y += vchannels->get_h() + 5;
328 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
330 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
331 x1 += frame_rate->get_w();
332 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
333 y += frame_rate->get_h() + 5;
336 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
338 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
339 // x1 += canvas_w_text->get_w() + 2;
340 // add_subwindow(new BC_Title(x1, y, "x"));
342 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
343 // x1 += canvas_h_text->get_w();
344 // add_subwindow(new FrameSizePulldown(mwindow,
350 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
351 // y += canvas_h_text->get_h() + 5;
354 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
356 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
357 x1 += output_w_text->get_w() + 2;
358 add_subwindow(new BC_Title(x1, y, "x"));
360 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
361 x1 += output_h_text->get_w();
362 FrameSizePulldown *pulldown;
363 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
368 x1 += pulldown->get_w() + 5;
369 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
370 y += output_h_text->get_h() + 5;
373 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
375 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
376 x1 += aspect_w_text->get_w() + 2;
377 add_subwindow(new BC_Title(x1, y, ":"));
379 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
380 x1 += aspect_h_text->get_w();
381 add_subwindow(new AspectPulldown(mwindow,
387 x1 = aspect_w_text->get_x();
388 y += aspect_w_text->get_h() + 5;
389 add_subwindow(new NewAspectAuto(this, x1, y));
391 add_subwindow(new BC_Title(x, y, _("Color model:")));
392 add_subwindow(textbox = new BC_TextBox(x + 100, y, 200, 1, ""));
393 add_subwindow(color_model = new ColormodelPulldown(mwindow,
395 &new_edl->session->color_model,
396 x + 100 + textbox->get_w(),
398 y += textbox->get_h() + 5;
400 // --------------------
401 add_subwindow(new BC_Title(x, y, _("Interlace mode:")));
402 add_subwindow(textbox = new BC_TextBox(x + 100, y, 140, 1, ""));
403 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
405 &new_edl->session->interlace_mode,
406 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
407 x + 100 + textbox->get_w(),
409 y += textbox->get_h() + 5;
411 add_subwindow(new BC_OKButton(this,
412 mwindow->theme->get_image_set("new_ok_images")));
413 add_subwindow(new BC_CancelButton(this,
414 mwindow->theme->get_image_set("new_cancel_images")));
421 int NewWindow::update()
423 atracks->update((int64_t)new_edl->session->audio_tracks);
424 achannels->update((int64_t)new_edl->session->audio_channels);
425 sample_rate->update((int64_t)new_edl->session->sample_rate);
426 vtracks->update((int64_t)new_edl->session->video_tracks);
427 frame_rate->update((float)new_edl->session->frame_rate);
428 output_w_text->update((int64_t)new_edl->session->output_w);
429 output_h_text->update((int64_t)new_edl->session->output_h);
430 aspect_w_text->update((float)new_edl->session->aspect_w);
431 aspect_h_text->update((float)new_edl->session->aspect_h);
432 interlace_pulldown->update(new_edl->session->interlace_mode);
433 color_model->update_value(new_edl->session->color_model);
443 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
444 : FormatPresets(mwindow, gui, 0, x, y)
448 NewPresets::~NewPresets()
452 int NewPresets::handle_event()
458 EDL* NewPresets::get_edl()
460 return new_gui->new_edl;
465 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
466 : BC_TextBox(x, y, 90, 1, text)
468 this->nwindow = nwindow;
471 int NewATracks::handle_event()
473 nwindow->new_edl->session->audio_tracks = atol(get_text());
477 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
480 this->nwindow = nwindow;
482 int NewATracksTumbler::handle_up_event()
484 nwindow->new_edl->session->audio_tracks++;
485 nwindow->new_edl->boundaries();
489 int NewATracksTumbler::handle_down_event()
491 nwindow->new_edl->session->audio_tracks--;
492 nwindow->new_edl->boundaries();
497 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
498 : BC_TextBox(x, y, 90, 1, text)
500 this->nwindow = nwindow;
503 int NewAChannels::handle_event()
505 nwindow->new_edl->session->audio_channels = atol(get_text());
509 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
512 this->nwindow = nwindow;
514 int NewAChannelsTumbler::handle_up_event()
516 nwindow->new_edl->session->audio_channels++;
517 nwindow->new_edl->boundaries();
521 int NewAChannelsTumbler::handle_down_event()
523 nwindow->new_edl->session->audio_channels--;
524 nwindow->new_edl->boundaries();
530 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
531 : BC_TextBox(x, y, 90, 1, text)
533 this->nwindow = nwindow;
536 int NewSampleRate::handle_event()
538 nwindow->new_edl->session->sample_rate = atol(get_text());
542 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
548 &mwindow->theme->sample_rates,
555 this->mwindow = mwindow;
556 this->output = output;
558 int SampleRatePulldown::handle_event()
560 char *text = get_selection(0, 0)->get_text();
561 output->update(text);
562 output->handle_event();
580 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
581 : BC_TextBox(x, y, 90, 1, text)
583 this->nwindow = nwindow;
586 int NewVTracks::handle_event()
588 nwindow->new_edl->session->video_tracks = atol(get_text());
592 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
595 this->nwindow = nwindow;
597 int NewVTracksTumbler::handle_up_event()
599 nwindow->new_edl->session->video_tracks++;
600 nwindow->new_edl->boundaries();
604 int NewVTracksTumbler::handle_down_event()
606 nwindow->new_edl->session->video_tracks--;
607 nwindow->new_edl->boundaries();
612 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
613 : BC_TextBox(x, y, 90, 1, text)
615 this->nwindow = nwindow;
618 int NewVChannels::handle_event()
620 nwindow->new_edl->session->video_channels = atol(get_text());
624 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
627 this->nwindow = nwindow;
629 int NewVChannelsTumbler::handle_up_event()
631 nwindow->new_edl->session->video_channels++;
632 nwindow->new_edl->boundaries();
636 int NewVChannelsTumbler::handle_down_event()
638 nwindow->new_edl->session->video_channels--;
639 nwindow->new_edl->boundaries();
644 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
645 : BC_TextBox(x, y, 90, 1, text)
647 this->nwindow = nwindow;
650 int NewFrameRate::handle_event()
652 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
656 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
665 &mwindow->theme->frame_rates,
672 this->mwindow = mwindow;
673 this->output = output;
675 int FrameRatePulldown::handle_event()
677 char *text = get_selection(0, 0)->get_text();
678 output->update(text);
679 output->handle_event();
683 FrameSizePulldown::FrameSizePulldown(Theme *theme,
684 BC_TextBox *output_w,
685 BC_TextBox *output_h,
701 this->output_w = output_w;
702 this->output_h = output_h;
704 int FrameSizePulldown::handle_event()
706 char *text = get_selection(0, 0)->get_text();
707 char string[BCTEXTLEN];
711 strcpy(string, text);
712 ptr = strrchr(string, 'x');
722 output_w->handle_event();
723 output_h->handle_event();
728 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
729 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
731 this->nwindow = nwindow;
733 int NewOutputW::handle_event()
735 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
736 nwindow->new_thread->update_aspect();
740 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
741 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
743 this->nwindow = nwindow;
745 int NewOutputH::handle_event()
747 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
748 nwindow->new_thread->update_aspect();
752 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
753 : BC_TextBox(x, y, 70, 1, text)
755 this->nwindow = nwindow;
758 int NewAspectW::handle_event()
760 nwindow->new_edl->session->aspect_w = atof(get_text());
764 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
765 : BC_TextBox(x, y, 70, 1, text)
767 this->nwindow = nwindow;
770 int NewAspectH::handle_event()
772 nwindow->new_edl->session->aspect_h = atof(get_text());
776 AspectPulldown::AspectPulldown(MWindow *mwindow,
777 BC_TextBox *output_w,
778 BC_TextBox *output_h,
786 &mwindow->theme->aspect_ratios,
793 this->mwindow = mwindow;
794 this->output_w = output_w;
795 this->output_h = output_h;
797 int AspectPulldown::handle_event()
799 char *text = get_selection(0, 0)->get_text();
800 char string[BCTEXTLEN];
804 strcpy(string, text);
805 ptr = strrchr(string, ':');
815 output_w->handle_event();
816 output_h->handle_event();
821 ColormodelItem::ColormodelItem(const char *text, int value)
822 : BC_ListBoxItem(text)
827 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
828 BC_TextBox *output_text,
837 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
844 this->mwindow = mwindow;
845 this->output_text = output_text;
846 this->output_value = output_value;
847 output_text->update(colormodel_to_text());
850 int ColormodelPulldown::handle_event()
852 output_text->update(get_selection(0, 0)->get_text());
853 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
857 const char* ColormodelPulldown::colormodel_to_text()
859 for(int i = 0; i < mwindow->colormodels.total; i++)
860 if(mwindow->colormodels.values[i]->value == *output_value)
861 return mwindow->colormodels.values[i]->get_text();
865 void ColormodelPulldown::update_value(int value)
867 *output_value = value;
868 output_text->update(colormodel_to_text());
872 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
873 : BC_ListBoxItem(text)
878 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
879 BC_TextBox *output_text,
881 ArrayList<BC_ListBoxItem*> *data,
884 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
886 this->mwindow = mwindow;
887 this->output_text = output_text;
888 this->output_value = output_value;
889 output_text->update(interlacemode_to_text());
892 int InterlacemodePulldown::handle_event()
894 output_text->update(get_selection(0, 0)->get_text());
895 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
899 const char* InterlacemodePulldown::interlacemode_to_text()
901 ilacemode_to_text(this->string,*output_value);
902 return (this->string);
905 int InterlacemodePulldown::update(int interlace_mode)
907 *output_value = interlace_mode;
908 output_text->update(interlacemode_to_text());
913 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
914 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
916 this->nwindow = nwindow;
918 NewAspectAuto::~NewAspectAuto()
921 int NewAspectAuto::handle_event()
923 nwindow->new_thread->auto_aspect = get_value();
924 nwindow->new_thread->update_aspect();
935 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
936 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
938 this->mwindow = mwindow;
940 set_tooltip(_("Swap dimensions"));
943 int NewSwapExtents::handle_event()
945 int w = gui->new_edl->session->output_w;
946 int h = gui->new_edl->session->output_h;
947 gui->new_edl->session->output_w = h;
948 gui->new_edl->session->output_h = w;
949 gui->output_w_text->update((int64_t)h);
950 gui->output_h_text->update((int64_t)w);
951 gui->new_thread->update_aspect();