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"
30 #include "levelwindow.h"
35 #include "mwindowgui.h"
37 #include "newpresets.h"
38 #include "mainsession.h"
40 #include "preferences.h"
42 #include "transportque.h"
43 #include "videowindow.h"
44 #include "vplayback.h"
55 New::New(MWindow *mwindow)
56 : BC_MenuItem(_("New"), "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 mwindow->vwindows.get(i)->playback_engine->que->send_command(STOP,
110 mwindow->vwindows.get(i)->playback_engine->interrupt_playback(0);
113 mwindow->cwindow->playback_engine->interrupt_playback(0);
115 mwindow->gui->lock_window();
116 mwindow->reset_caches();
120 memcpy(new_edl->session->achannel_positions,
121 &mwindow->preferences->channel_positions[
122 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
123 sizeof(int) * MAXCHANNELS);
124 new_edl->session->boundaries();
125 new_edl->create_default_tracks();
127 mwindow->undo->update_undo_before();
128 mwindow->set_filename("");
130 mwindow->hide_plugins();
131 mwindow->edl->Garbage::remove_user();
132 mwindow->edl = new_edl;
134 mwindow->save_defaults();
136 // Load file sequence
137 mwindow->update_project(LOADMODE_REPLACE);
138 mwindow->session->changes_made = 0;
139 mwindow->undo->update_undo_after(_("New"), LOAD_ALL);
140 mwindow->gui->unlock_window();
144 NewThread::NewThread(MWindow *mwindow, New *new_project)
147 this->mwindow = mwindow;
148 this->new_project = new_project;
152 NewThread::~NewThread()
159 BC_Window* NewThread::new_gui()
161 mwindow->edl->save_defaults(mwindow->defaults);
162 new_project->create_new_edl();
165 mwindow->gui->lock_window("NewThread::new_gui");
166 int x = mwindow->gui->get_abs_cursor_x(0) - WIDTH / 2;
167 int y = mwindow->gui->get_abs_cursor_y(0) - HEIGHT / 2;
169 nwindow = new NewWindow(mwindow, this, x, y);
170 nwindow->create_objects();
171 mwindow->gui->unlock_window();
177 void NewThread::handle_close_event(int result)
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);
230 N_("Cinelerra: New Project");
233 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
234 : BC_Window(_(_(PROGRAM_NAME ": New Project")),
245 this->mwindow = mwindow;
246 this->new_thread = new_thread;
247 this->new_edl = new_thread->new_project->new_edl;
251 NewWindow::~NewWindow()
253 lock_window("NewWindow::~NewWindow");
254 if(format_presets) delete format_presets;
258 void NewWindow::create_objects()
260 int x = 10, y = 10, x1, y1;
263 lock_window("NewWindow::create_objects");
264 mwindow->theme->draw_new_bg(this);
266 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
269 format_presets = new NewPresets(mwindow,
273 format_presets->create_objects();
274 x = format_presets->x;
275 y = format_presets->y;
281 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
285 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
287 add_subwindow(atracks = new NewATracks(this, "", x1, y));
288 x1 += atracks->get_w();
289 add_subwindow(new NewATracksTumbler(this, x1, y));
290 y += atracks->get_h() + 5;
293 add_subwindow(new BC_Title(x1, y, _("Channels:")));
295 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
296 x1 += achannels->get_w();
297 add_subwindow(new NewAChannelsTumbler(this, x1, y));
298 y += achannels->get_h() + 5;
301 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
303 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
304 x1 += sample_rate->get_w();
305 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
309 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
312 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
314 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
315 x1 += vtracks->get_w();
316 add_subwindow(new NewVTracksTumbler(this, x1, y));
317 y += vtracks->get_h() + 5;
320 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
322 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
323 // x1 += vchannels->get_w();
324 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
325 // y += vchannels->get_h() + 5;
327 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
329 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
330 x1 += frame_rate->get_w();
331 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
332 y += frame_rate->get_h() + 5;
335 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
337 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
338 // x1 += canvas_w_text->get_w() + 2;
339 // add_subwindow(new BC_Title(x1, y, "x"));
341 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
342 // x1 += canvas_h_text->get_w();
343 // add_subwindow(new FrameSizePulldown(mwindow,
349 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
350 // y += canvas_h_text->get_h() + 5;
353 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
355 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
356 x1 += output_w_text->get_w() + 2;
357 add_subwindow(new BC_Title(x1, y, "x"));
359 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
360 x1 += output_h_text->get_w();
361 FrameSizePulldown *pulldown;
362 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
367 x1 += pulldown->get_w() + 5;
368 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
369 y += output_h_text->get_h() + 5;
372 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
374 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
375 x1 += aspect_w_text->get_w() + 2;
376 add_subwindow(new BC_Title(x1, y, ":"));
378 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
379 x1 += aspect_h_text->get_w();
380 add_subwindow(new AspectPulldown(mwindow,
386 x1 = aspect_w_text->get_x();
387 y += aspect_w_text->get_h() + 5;
388 add_subwindow(new NewAspectAuto(this, x1, y));
390 add_subwindow(new BC_Title(x, y, _("Color model:")));
392 add_subwindow(textbox = new BC_TextBox(x, y, 200, 1, ""));
393 x += textbox->get_w();
394 add_subwindow(new ColormodelPulldown(mwindow,
396 &new_edl->session->color_model,
400 add_subwindow(new BC_OKButton(this,
401 mwindow->theme->get_image_set("new_ok_images")));
402 add_subwindow(new BC_CancelButton(this,
403 mwindow->theme->get_image_set("new_cancel_images")));
410 int NewWindow::update()
412 atracks->update((int64_t)new_edl->session->audio_tracks);
413 achannels->update((int64_t)new_edl->session->audio_channels);
414 sample_rate->update((int64_t)new_edl->session->sample_rate);
415 vtracks->update((int64_t)new_edl->session->video_tracks);
416 frame_rate->update((float)new_edl->session->frame_rate);
417 output_w_text->update((int64_t)new_edl->session->output_w);
418 output_h_text->update((int64_t)new_edl->session->output_h);
419 aspect_w_text->update((float)new_edl->session->aspect_w);
420 aspect_h_text->update((float)new_edl->session->aspect_h);
430 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
431 : FormatPresets(mwindow, gui, 0, x, y)
435 NewPresets::~NewPresets()
439 int NewPresets::handle_event()
445 EDL* NewPresets::get_edl()
447 return new_gui->new_edl;
452 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
453 : BC_TextBox(x, y, 90, 1, text)
455 this->nwindow = nwindow;
458 int NewATracks::handle_event()
460 nwindow->new_edl->session->audio_tracks = atol(get_text());
464 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
467 this->nwindow = nwindow;
469 int NewATracksTumbler::handle_up_event()
471 nwindow->new_edl->session->audio_tracks++;
472 nwindow->new_edl->boundaries();
476 int NewATracksTumbler::handle_down_event()
478 nwindow->new_edl->session->audio_tracks--;
479 nwindow->new_edl->boundaries();
484 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
485 : BC_TextBox(x, y, 90, 1, text)
487 this->nwindow = nwindow;
490 int NewAChannels::handle_event()
492 nwindow->new_edl->session->audio_channels = atol(get_text());
496 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
499 this->nwindow = nwindow;
501 int NewAChannelsTumbler::handle_up_event()
503 nwindow->new_edl->session->audio_channels++;
504 nwindow->new_edl->boundaries();
508 int NewAChannelsTumbler::handle_down_event()
510 nwindow->new_edl->session->audio_channels--;
511 nwindow->new_edl->boundaries();
517 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
518 : BC_TextBox(x, y, 90, 1, text)
520 this->nwindow = nwindow;
523 int NewSampleRate::handle_event()
525 nwindow->new_edl->session->sample_rate = atol(get_text());
529 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
535 &mwindow->theme->sample_rates,
542 this->mwindow = mwindow;
543 this->output = output;
545 int SampleRatePulldown::handle_event()
547 char *text = get_selection(0, 0)->get_text();
548 output->update(text);
549 output->handle_event();
567 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
568 : BC_TextBox(x, y, 90, 1, text)
570 this->nwindow = nwindow;
573 int NewVTracks::handle_event()
575 nwindow->new_edl->session->video_tracks = atol(get_text());
579 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
582 this->nwindow = nwindow;
584 int NewVTracksTumbler::handle_up_event()
586 nwindow->new_edl->session->video_tracks++;
587 nwindow->new_edl->boundaries();
591 int NewVTracksTumbler::handle_down_event()
593 nwindow->new_edl->session->video_tracks--;
594 nwindow->new_edl->boundaries();
599 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
600 : BC_TextBox(x, y, 90, 1, text)
602 this->nwindow = nwindow;
605 int NewVChannels::handle_event()
607 nwindow->new_edl->session->video_channels = atol(get_text());
611 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
614 this->nwindow = nwindow;
616 int NewVChannelsTumbler::handle_up_event()
618 nwindow->new_edl->session->video_channels++;
619 nwindow->new_edl->boundaries();
623 int NewVChannelsTumbler::handle_down_event()
625 nwindow->new_edl->session->video_channels--;
626 nwindow->new_edl->boundaries();
631 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
632 : BC_TextBox(x, y, 90, 1, text)
634 this->nwindow = nwindow;
637 int NewFrameRate::handle_event()
639 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
643 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
652 &mwindow->theme->frame_rates,
659 this->mwindow = mwindow;
660 this->output = output;
662 int FrameRatePulldown::handle_event()
664 char *text = get_selection(0, 0)->get_text();
665 output->update(text);
666 output->handle_event();
670 FrameSizePulldown::FrameSizePulldown(Theme *theme,
671 BC_TextBox *output_w,
672 BC_TextBox *output_h,
688 this->output_w = output_w;
689 this->output_h = output_h;
691 int FrameSizePulldown::handle_event()
693 char *text = get_selection(0, 0)->get_text();
694 char string[BCTEXTLEN];
698 strcpy(string, text);
699 ptr = strrchr(string, 'x');
709 output_w->handle_event();
710 output_h->handle_event();
715 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
716 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
718 this->nwindow = nwindow;
720 int NewOutputW::handle_event()
722 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
723 nwindow->new_thread->update_aspect();
727 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
728 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
730 this->nwindow = nwindow;
732 int NewOutputH::handle_event()
734 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
735 nwindow->new_thread->update_aspect();
739 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
740 : BC_TextBox(x, y, 70, 1, text)
742 this->nwindow = nwindow;
745 int NewAspectW::handle_event()
747 nwindow->new_edl->session->aspect_w = atof(get_text());
751 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
752 : BC_TextBox(x, y, 70, 1, text)
754 this->nwindow = nwindow;
757 int NewAspectH::handle_event()
759 nwindow->new_edl->session->aspect_h = atof(get_text());
763 AspectPulldown::AspectPulldown(MWindow *mwindow,
764 BC_TextBox *output_w,
765 BC_TextBox *output_h,
773 &mwindow->theme->aspect_ratios,
780 this->mwindow = mwindow;
781 this->output_w = output_w;
782 this->output_h = output_h;
784 int AspectPulldown::handle_event()
786 char *text = get_selection(0, 0)->get_text();
787 char string[BCTEXTLEN];
791 strcpy(string, text);
792 ptr = strrchr(string, ':');
802 output_w->handle_event();
803 output_h->handle_event();
808 ColormodelItem::ColormodelItem(const char *text, int value)
809 : BC_ListBoxItem(text)
814 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
815 BC_TextBox *output_text,
824 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
831 this->mwindow = mwindow;
832 this->output_text = output_text;
833 this->output_value = output_value;
834 output_text->update(colormodel_to_text());
837 int ColormodelPulldown::handle_event()
839 output_text->update(get_selection(0, 0)->get_text());
840 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
844 const char* ColormodelPulldown::colormodel_to_text()
846 for(int i = 0; i < mwindow->colormodels.total; i++)
847 if(mwindow->colormodels.values[i]->value == *output_value)
848 return mwindow->colormodels.values[i]->get_text();
861 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
862 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
864 this->nwindow = nwindow;
866 NewAspectAuto::~NewAspectAuto()
869 int NewAspectAuto::handle_event()
871 nwindow->new_thread->auto_aspect = get_value();
872 nwindow->new_thread->update_aspect();
883 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
884 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
886 this->mwindow = mwindow;
888 set_tooltip(_("Swap dimensions"));
891 int NewSwapExtents::handle_event()
893 int w = gui->new_edl->session->output_w;
894 int h = gui->new_edl->session->output_h;
895 gui->new_edl->session->output_w = h;
896 gui->new_edl->session->output_h = w;
897 gui->output_w_text->update((int64_t)h);
898 gui->output_h_text->update((int64_t)w);
899 gui->new_thread->update_aspect();