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();
78 mwindow->gui->lock_window("New::handle_event");
83 void New::create_new_edl()
88 new_edl->create_objects();
89 new_edl->load_defaults(mwindow->defaults);
94 int New::create_new_project()
96 mwindow->cwindow->playback_engine->que->send_command(STOP,
101 for(int i = 0; i < mwindow->vwindows.size(); i++)
103 mwindow->vwindows.get(i)->playback_engine->que->send_command(STOP,
107 mwindow->vwindows.get(i)->playback_engine->interrupt_playback(0);
110 mwindow->cwindow->playback_engine->interrupt_playback(0);
112 mwindow->gui->lock_window();
113 mwindow->reset_caches();
117 memcpy(new_edl->session->achannel_positions,
118 &mwindow->preferences->channel_positions[
119 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
120 sizeof(int) * MAXCHANNELS);
121 new_edl->session->boundaries();
122 new_edl->create_default_tracks();
124 mwindow->undo->update_undo_before();
125 mwindow->set_filename("");
127 mwindow->hide_plugins();
128 mwindow->edl->Garbage::remove_user();
129 mwindow->edl = new_edl;
131 mwindow->save_defaults();
133 // Load file sequence
134 mwindow->update_project(LOADMODE_REPLACE);
135 mwindow->session->changes_made = 0;
136 mwindow->undo->update_undo_after(_("New"), LOAD_ALL);
137 mwindow->gui->unlock_window();
141 NewThread::NewThread(MWindow *mwindow, New *new_project)
144 this->mwindow = mwindow;
145 this->new_project = new_project;
148 NewThread::~NewThread()
154 BC_Window* NewThread::new_gui()
156 mwindow->edl->save_defaults(mwindow->defaults);
157 new_project->create_new_edl();
160 mwindow->gui->lock_window("NewThread::new_gui");
161 int x = mwindow->gui->get_abs_cursor_x(0) - WIDTH / 2;
162 int y = mwindow->gui->get_abs_cursor_y(0) - HEIGHT / 2;
164 nwindow = new NewWindow(mwindow, this, x, y);
165 nwindow->create_objects();
166 mwindow->gui->unlock_window();
172 void NewThread::handle_close_event(int result)
175 new_project->new_edl->save_defaults(mwindow->defaults);
176 mwindow->defaults->save();
181 if( !new_project->new_edl->Garbage::remove_user() )
182 new_project->new_edl = 0;
186 new_project->create_new_project();
192 int NewThread::load_defaults()
194 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
198 int NewThread::save_defaults()
200 mwindow->defaults->update("AUTOASPECT", auto_aspect);
204 int NewThread::update_aspect()
208 char string[BCTEXTLEN];
209 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
210 new_project->new_edl->session->aspect_h,
211 new_project->new_edl->session->output_w,
212 new_project->new_edl->session->output_h);
213 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
214 nwindow->aspect_w_text->update(string);
215 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
216 nwindow->aspect_h_text->update(string);
225 N_("Cinelerra: New Project");
228 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
229 : BC_Window(_(_(PROGRAM_NAME ": New Project")),
240 this->mwindow = mwindow;
241 this->new_thread = new_thread;
242 this->new_edl = new_thread->new_project->new_edl;
246 NewWindow::~NewWindow()
248 lock_window("NewWindow::~NewWindow");
249 if(format_presets) delete format_presets;
253 void NewWindow::create_objects()
255 int x = 10, y = 10, x1, y1;
258 lock_window("NewWindow::create_objects");
259 mwindow->theme->draw_new_bg(this);
261 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
264 format_presets = new NewPresets(mwindow,
268 format_presets->create_objects();
269 x = format_presets->x;
270 y = format_presets->y;
276 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
280 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
282 add_subwindow(atracks = new NewATracks(this, "", x1, y));
283 x1 += atracks->get_w();
284 add_subwindow(new NewATracksTumbler(this, x1, y));
285 y += atracks->get_h() + 5;
288 add_subwindow(new BC_Title(x1, y, _("Channels:")));
290 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
291 x1 += achannels->get_w();
292 add_subwindow(new NewAChannelsTumbler(this, x1, y));
293 y += achannels->get_h() + 5;
296 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
298 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
299 x1 += sample_rate->get_w();
300 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
304 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
307 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
309 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
310 x1 += vtracks->get_w();
311 add_subwindow(new NewVTracksTumbler(this, x1, y));
312 y += vtracks->get_h() + 5;
315 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
317 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
318 // x1 += vchannels->get_w();
319 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
320 // y += vchannels->get_h() + 5;
322 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
324 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
325 x1 += frame_rate->get_w();
326 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
327 y += frame_rate->get_h() + 5;
330 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
332 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
333 // x1 += canvas_w_text->get_w() + 2;
334 // add_subwindow(new BC_Title(x1, y, "x"));
336 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
337 // x1 += canvas_h_text->get_w();
338 // add_subwindow(new FrameSizePulldown(mwindow,
344 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
345 // y += canvas_h_text->get_h() + 5;
348 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
350 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
351 x1 += output_w_text->get_w() + 2;
352 add_subwindow(new BC_Title(x1, y, "x"));
354 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
355 x1 += output_h_text->get_w();
356 FrameSizePulldown *pulldown;
357 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
362 x1 += pulldown->get_w() + 5;
363 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
364 y += output_h_text->get_h() + 5;
367 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
369 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
370 x1 += aspect_w_text->get_w() + 2;
371 add_subwindow(new BC_Title(x1, y, ":"));
373 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
374 x1 += aspect_h_text->get_w();
375 add_subwindow(new AspectPulldown(mwindow,
381 x1 = aspect_w_text->get_x();
382 y += aspect_w_text->get_h() + 5;
383 add_subwindow(new NewAspectAuto(this, x1, y));
385 add_subwindow(new BC_Title(x, y, _("Color model:")));
387 add_subwindow(textbox = new BC_TextBox(x, y, 200, 1, ""));
388 x += textbox->get_w();
389 add_subwindow(new ColormodelPulldown(mwindow,
391 &new_edl->session->color_model,
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);
425 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
426 : FormatPresets(mwindow, gui, 0, x, y)
430 NewPresets::~NewPresets()
434 int NewPresets::handle_event()
440 EDL* NewPresets::get_edl()
442 return new_gui->new_edl;
447 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
448 : BC_TextBox(x, y, 90, 1, text)
450 this->nwindow = nwindow;
453 int NewATracks::handle_event()
455 nwindow->new_edl->session->audio_tracks = atol(get_text());
459 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
462 this->nwindow = nwindow;
464 int NewATracksTumbler::handle_up_event()
466 nwindow->new_edl->session->audio_tracks++;
467 nwindow->new_edl->boundaries();
471 int NewATracksTumbler::handle_down_event()
473 nwindow->new_edl->session->audio_tracks--;
474 nwindow->new_edl->boundaries();
479 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
480 : BC_TextBox(x, y, 90, 1, text)
482 this->nwindow = nwindow;
485 int NewAChannels::handle_event()
487 nwindow->new_edl->session->audio_channels = atol(get_text());
491 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
494 this->nwindow = nwindow;
496 int NewAChannelsTumbler::handle_up_event()
498 nwindow->new_edl->session->audio_channels++;
499 nwindow->new_edl->boundaries();
503 int NewAChannelsTumbler::handle_down_event()
505 nwindow->new_edl->session->audio_channels--;
506 nwindow->new_edl->boundaries();
512 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
513 : BC_TextBox(x, y, 90, 1, text)
515 this->nwindow = nwindow;
518 int NewSampleRate::handle_event()
520 nwindow->new_edl->session->sample_rate = atol(get_text());
524 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
530 &mwindow->theme->sample_rates,
537 this->mwindow = mwindow;
538 this->output = output;
540 int SampleRatePulldown::handle_event()
542 char *text = get_selection(0, 0)->get_text();
543 output->update(text);
544 output->handle_event();
562 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
563 : BC_TextBox(x, y, 90, 1, text)
565 this->nwindow = nwindow;
568 int NewVTracks::handle_event()
570 nwindow->new_edl->session->video_tracks = atol(get_text());
574 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
577 this->nwindow = nwindow;
579 int NewVTracksTumbler::handle_up_event()
581 nwindow->new_edl->session->video_tracks++;
582 nwindow->new_edl->boundaries();
586 int NewVTracksTumbler::handle_down_event()
588 nwindow->new_edl->session->video_tracks--;
589 nwindow->new_edl->boundaries();
594 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
595 : BC_TextBox(x, y, 90, 1, text)
597 this->nwindow = nwindow;
600 int NewVChannels::handle_event()
602 nwindow->new_edl->session->video_channels = atol(get_text());
606 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
609 this->nwindow = nwindow;
611 int NewVChannelsTumbler::handle_up_event()
613 nwindow->new_edl->session->video_channels++;
614 nwindow->new_edl->boundaries();
618 int NewVChannelsTumbler::handle_down_event()
620 nwindow->new_edl->session->video_channels--;
621 nwindow->new_edl->boundaries();
626 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
627 : BC_TextBox(x, y, 90, 1, text)
629 this->nwindow = nwindow;
632 int NewFrameRate::handle_event()
634 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
638 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
647 &mwindow->theme->frame_rates,
654 this->mwindow = mwindow;
655 this->output = output;
657 int FrameRatePulldown::handle_event()
659 char *text = get_selection(0, 0)->get_text();
660 output->update(text);
661 output->handle_event();
665 FrameSizePulldown::FrameSizePulldown(Theme *theme,
666 BC_TextBox *output_w,
667 BC_TextBox *output_h,
683 this->output_w = output_w;
684 this->output_h = output_h;
686 int FrameSizePulldown::handle_event()
688 char *text = get_selection(0, 0)->get_text();
689 char string[BCTEXTLEN];
693 strcpy(string, text);
694 ptr = strrchr(string, 'x');
704 output_w->handle_event();
705 output_h->handle_event();
710 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
711 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
713 this->nwindow = nwindow;
715 int NewOutputW::handle_event()
717 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
718 nwindow->new_thread->update_aspect();
722 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
723 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
725 this->nwindow = nwindow;
727 int NewOutputH::handle_event()
729 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
730 nwindow->new_thread->update_aspect();
734 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
735 : BC_TextBox(x, y, 70, 1, text)
737 this->nwindow = nwindow;
740 int NewAspectW::handle_event()
742 nwindow->new_edl->session->aspect_w = atof(get_text());
746 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
747 : BC_TextBox(x, y, 70, 1, text)
749 this->nwindow = nwindow;
752 int NewAspectH::handle_event()
754 nwindow->new_edl->session->aspect_h = atof(get_text());
758 AspectPulldown::AspectPulldown(MWindow *mwindow,
759 BC_TextBox *output_w,
760 BC_TextBox *output_h,
768 &mwindow->theme->aspect_ratios,
775 this->mwindow = mwindow;
776 this->output_w = output_w;
777 this->output_h = output_h;
779 int AspectPulldown::handle_event()
781 char *text = get_selection(0, 0)->get_text();
782 char string[BCTEXTLEN];
786 strcpy(string, text);
787 ptr = strrchr(string, ':');
797 output_w->handle_event();
798 output_h->handle_event();
803 ColormodelItem::ColormodelItem(const char *text, int value)
804 : BC_ListBoxItem(text)
809 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
810 BC_TextBox *output_text,
819 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
826 this->mwindow = mwindow;
827 this->output_text = output_text;
828 this->output_value = output_value;
829 output_text->update(colormodel_to_text());
832 int ColormodelPulldown::handle_event()
834 output_text->update(get_selection(0, 0)->get_text());
835 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
839 const char* ColormodelPulldown::colormodel_to_text()
841 for(int i = 0; i < mwindow->colormodels.total; i++)
842 if(mwindow->colormodels.values[i]->value == *output_value)
843 return mwindow->colormodels.values[i]->get_text();
856 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
857 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
859 this->nwindow = nwindow;
861 NewAspectAuto::~NewAspectAuto()
864 int NewAspectAuto::handle_event()
866 nwindow->new_thread->auto_aspect = get_value();
867 nwindow->new_thread->update_aspect();
878 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
879 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
881 this->mwindow = mwindow;
883 set_tooltip(_("Swap dimensions"));
886 int NewSwapExtents::handle_event()
888 int w = gui->new_edl->session->output_w;
889 int h = gui->new_edl->session->output_h;
890 gui->new_edl->session->output_w = h;
891 gui->new_edl->session->output_h = w;
892 gui->output_w_text->update((int64_t)h);
893 gui->output_h_text->update((int64_t)w);
894 gui->new_thread->update_aspect();