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()
155 BC_Window* NewThread::new_gui()
157 mwindow->edl->save_defaults(mwindow->defaults);
158 new_project->create_new_edl();
161 mwindow->gui->lock_window("NewThread::new_gui");
162 int x = mwindow->gui->get_abs_cursor_x(0) - WIDTH / 2;
163 int y = mwindow->gui->get_abs_cursor_y(0) - HEIGHT / 2;
165 nwindow = new NewWindow(mwindow, this, x, y);
166 nwindow->create_objects();
167 mwindow->gui->unlock_window();
173 void NewThread::handle_close_event(int result)
176 new_project->new_edl->save_defaults(mwindow->defaults);
177 mwindow->defaults->save();
182 if( !new_project->new_edl->Garbage::remove_user() )
183 new_project->new_edl = 0;
187 new_project->create_new_project();
193 int NewThread::load_defaults()
195 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
199 int NewThread::save_defaults()
201 mwindow->defaults->update("AUTOASPECT", auto_aspect);
205 int NewThread::update_aspect()
209 char string[BCTEXTLEN];
210 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
211 new_project->new_edl->session->aspect_h,
212 new_project->new_edl->session->output_w,
213 new_project->new_edl->session->output_h);
214 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
215 nwindow->aspect_w_text->update(string);
216 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
217 nwindow->aspect_h_text->update(string);
226 N_("Cinelerra: New Project");
229 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
230 : BC_Window(_(_(PROGRAM_NAME ": New Project")),
241 this->mwindow = mwindow;
242 this->new_thread = new_thread;
243 this->new_edl = new_thread->new_project->new_edl;
247 NewWindow::~NewWindow()
249 lock_window("NewWindow::~NewWindow");
250 if(format_presets) delete format_presets;
254 void NewWindow::create_objects()
256 int x = 10, y = 10, x1, y1;
259 lock_window("NewWindow::create_objects");
260 mwindow->theme->draw_new_bg(this);
262 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
265 format_presets = new NewPresets(mwindow,
269 format_presets->create_objects();
270 x = format_presets->x;
271 y = format_presets->y;
277 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
281 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
283 add_subwindow(atracks = new NewATracks(this, "", x1, y));
284 x1 += atracks->get_w();
285 add_subwindow(new NewATracksTumbler(this, x1, y));
286 y += atracks->get_h() + 5;
289 add_subwindow(new BC_Title(x1, y, _("Channels:")));
291 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
292 x1 += achannels->get_w();
293 add_subwindow(new NewAChannelsTumbler(this, x1, y));
294 y += achannels->get_h() + 5;
297 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
299 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
300 x1 += sample_rate->get_w();
301 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
305 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
308 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
310 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
311 x1 += vtracks->get_w();
312 add_subwindow(new NewVTracksTumbler(this, x1, y));
313 y += vtracks->get_h() + 5;
316 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
318 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
319 // x1 += vchannels->get_w();
320 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
321 // y += vchannels->get_h() + 5;
323 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
325 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
326 x1 += frame_rate->get_w();
327 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
328 y += frame_rate->get_h() + 5;
331 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
333 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
334 // x1 += canvas_w_text->get_w() + 2;
335 // add_subwindow(new BC_Title(x1, y, "x"));
337 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
338 // x1 += canvas_h_text->get_w();
339 // add_subwindow(new FrameSizePulldown(mwindow,
345 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
346 // y += canvas_h_text->get_h() + 5;
349 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
351 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
352 x1 += output_w_text->get_w() + 2;
353 add_subwindow(new BC_Title(x1, y, "x"));
355 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
356 x1 += output_h_text->get_w();
357 FrameSizePulldown *pulldown;
358 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
363 x1 += pulldown->get_w() + 5;
364 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
365 y += output_h_text->get_h() + 5;
368 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
370 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
371 x1 += aspect_w_text->get_w() + 2;
372 add_subwindow(new BC_Title(x1, y, ":"));
374 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
375 x1 += aspect_h_text->get_w();
376 add_subwindow(new AspectPulldown(mwindow,
382 x1 = aspect_w_text->get_x();
383 y += aspect_w_text->get_h() + 5;
384 add_subwindow(new NewAspectAuto(this, x1, y));
386 add_subwindow(new BC_Title(x, y, _("Color model:")));
388 add_subwindow(textbox = new BC_TextBox(x, y, 200, 1, ""));
389 x += textbox->get_w();
390 add_subwindow(new ColormodelPulldown(mwindow,
392 &new_edl->session->color_model,
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);
426 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
427 : FormatPresets(mwindow, gui, 0, x, y)
431 NewPresets::~NewPresets()
435 int NewPresets::handle_event()
441 EDL* NewPresets::get_edl()
443 return new_gui->new_edl;
448 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
449 : BC_TextBox(x, y, 90, 1, text)
451 this->nwindow = nwindow;
454 int NewATracks::handle_event()
456 nwindow->new_edl->session->audio_tracks = atol(get_text());
460 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
463 this->nwindow = nwindow;
465 int NewATracksTumbler::handle_up_event()
467 nwindow->new_edl->session->audio_tracks++;
468 nwindow->new_edl->boundaries();
472 int NewATracksTumbler::handle_down_event()
474 nwindow->new_edl->session->audio_tracks--;
475 nwindow->new_edl->boundaries();
480 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
481 : BC_TextBox(x, y, 90, 1, text)
483 this->nwindow = nwindow;
486 int NewAChannels::handle_event()
488 nwindow->new_edl->session->audio_channels = atol(get_text());
492 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
495 this->nwindow = nwindow;
497 int NewAChannelsTumbler::handle_up_event()
499 nwindow->new_edl->session->audio_channels++;
500 nwindow->new_edl->boundaries();
504 int NewAChannelsTumbler::handle_down_event()
506 nwindow->new_edl->session->audio_channels--;
507 nwindow->new_edl->boundaries();
513 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
514 : BC_TextBox(x, y, 90, 1, text)
516 this->nwindow = nwindow;
519 int NewSampleRate::handle_event()
521 nwindow->new_edl->session->sample_rate = atol(get_text());
525 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
531 &mwindow->theme->sample_rates,
538 this->mwindow = mwindow;
539 this->output = output;
541 int SampleRatePulldown::handle_event()
543 char *text = get_selection(0, 0)->get_text();
544 output->update(text);
545 output->handle_event();
563 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
564 : BC_TextBox(x, y, 90, 1, text)
566 this->nwindow = nwindow;
569 int NewVTracks::handle_event()
571 nwindow->new_edl->session->video_tracks = atol(get_text());
575 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
578 this->nwindow = nwindow;
580 int NewVTracksTumbler::handle_up_event()
582 nwindow->new_edl->session->video_tracks++;
583 nwindow->new_edl->boundaries();
587 int NewVTracksTumbler::handle_down_event()
589 nwindow->new_edl->session->video_tracks--;
590 nwindow->new_edl->boundaries();
595 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
596 : BC_TextBox(x, y, 90, 1, text)
598 this->nwindow = nwindow;
601 int NewVChannels::handle_event()
603 nwindow->new_edl->session->video_channels = atol(get_text());
607 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
610 this->nwindow = nwindow;
612 int NewVChannelsTumbler::handle_up_event()
614 nwindow->new_edl->session->video_channels++;
615 nwindow->new_edl->boundaries();
619 int NewVChannelsTumbler::handle_down_event()
621 nwindow->new_edl->session->video_channels--;
622 nwindow->new_edl->boundaries();
627 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
628 : BC_TextBox(x, y, 90, 1, text)
630 this->nwindow = nwindow;
633 int NewFrameRate::handle_event()
635 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
639 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
648 &mwindow->theme->frame_rates,
655 this->mwindow = mwindow;
656 this->output = output;
658 int FrameRatePulldown::handle_event()
660 char *text = get_selection(0, 0)->get_text();
661 output->update(text);
662 output->handle_event();
666 FrameSizePulldown::FrameSizePulldown(Theme *theme,
667 BC_TextBox *output_w,
668 BC_TextBox *output_h,
684 this->output_w = output_w;
685 this->output_h = output_h;
687 int FrameSizePulldown::handle_event()
689 char *text = get_selection(0, 0)->get_text();
690 char string[BCTEXTLEN];
694 strcpy(string, text);
695 ptr = strrchr(string, 'x');
705 output_w->handle_event();
706 output_h->handle_event();
711 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
712 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
714 this->nwindow = nwindow;
716 int NewOutputW::handle_event()
718 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
719 nwindow->new_thread->update_aspect();
723 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
724 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
726 this->nwindow = nwindow;
728 int NewOutputH::handle_event()
730 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
731 nwindow->new_thread->update_aspect();
735 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
736 : BC_TextBox(x, y, 70, 1, text)
738 this->nwindow = nwindow;
741 int NewAspectW::handle_event()
743 nwindow->new_edl->session->aspect_w = atof(get_text());
747 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
748 : BC_TextBox(x, y, 70, 1, text)
750 this->nwindow = nwindow;
753 int NewAspectH::handle_event()
755 nwindow->new_edl->session->aspect_h = atof(get_text());
759 AspectPulldown::AspectPulldown(MWindow *mwindow,
760 BC_TextBox *output_w,
761 BC_TextBox *output_h,
769 &mwindow->theme->aspect_ratios,
776 this->mwindow = mwindow;
777 this->output_w = output_w;
778 this->output_h = output_h;
780 int AspectPulldown::handle_event()
782 char *text = get_selection(0, 0)->get_text();
783 char string[BCTEXTLEN];
787 strcpy(string, text);
788 ptr = strrchr(string, ':');
798 output_w->handle_event();
799 output_h->handle_event();
804 ColormodelItem::ColormodelItem(const char *text, int value)
805 : BC_ListBoxItem(text)
810 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
811 BC_TextBox *output_text,
820 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
827 this->mwindow = mwindow;
828 this->output_text = output_text;
829 this->output_value = output_value;
830 output_text->update(colormodel_to_text());
833 int ColormodelPulldown::handle_event()
835 output_text->update(get_selection(0, 0)->get_text());
836 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
840 const char* ColormodelPulldown::colormodel_to_text()
842 for(int i = 0; i < mwindow->colormodels.total; i++)
843 if(mwindow->colormodels.values[i]->value == *output_value)
844 return mwindow->colormodels.values[i]->get_text();
857 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
858 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
860 this->nwindow = nwindow;
862 NewAspectAuto::~NewAspectAuto()
865 int NewAspectAuto::handle_event()
867 nwindow->new_thread->auto_aspect = get_value();
868 nwindow->new_thread->update_aspect();
879 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
880 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
882 this->mwindow = mwindow;
884 set_tooltip(_("Swap dimensions"));
887 int NewSwapExtents::handle_event()
889 int w = gui->new_edl->session->output_w;
890 int h = gui->new_edl->session->output_h;
891 gui->new_edl->session->output_w = h;
892 gui->new_edl->session->output_h = w;
893 gui->output_w_text->update((int64_t)h);
894 gui->output_h_text->update((int64_t)w);
895 gui->new_thread->update_aspect();