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);
80 mwindow->gui->lock_window("New::handle_event");
85 void New::create_new_edl()
89 new_edl->create_objects();
90 new_edl->load_defaults(mwindow->defaults);
95 int New::create_new_project()
97 mwindow->stop_playback(0);
98 mwindow->gui->lock_window();
99 mwindow->reset_caches();
101 memcpy(new_edl->session->achannel_positions,
102 &mwindow->preferences->channel_positions[
103 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
104 sizeof(int) * MAXCHANNELS);
105 new_edl->session->boundaries();
106 new_edl->create_default_tracks();
108 mwindow->undo->update_undo_before();
109 mwindow->set_filename("");
111 mwindow->hide_plugins();
112 mwindow->edl->Garbage::remove_user();
113 mwindow->edl = new_edl;
115 mwindow->save_defaults();
117 // Load file sequence
118 mwindow->update_project(LOADMODE_REPLACE);
119 mwindow->session->changes_made = 0;
120 mwindow->undo->update_undo_after(_("New Project"), LOAD_ALL);
121 mwindow->gui->unlock_window();
125 NewThread::NewThread(MWindow *mwindow, New *new_project)
128 this->mwindow = mwindow;
129 this->new_project = new_project;
133 NewThread::~NewThread()
138 BC_Window* NewThread::new_gui()
140 mwindow->edl->save_defaults(mwindow->defaults);
141 new_project->create_new_edl();
144 mwindow->gui->lock_window("NewThread::new_gui");
145 int x = mwindow->gui->get_pop_cursor_x(0);
146 int y = mwindow->gui->get_pop_cursor_y(0);
148 nwindow = new NewWindow(mwindow, this, x, y);
149 nwindow->create_objects();
150 mwindow->gui->unlock_window();
154 void NewThread::handle_close_event(int result)
156 if( !new_project->new_edl ) return;
157 new_project->new_edl->save_defaults(mwindow->defaults);
158 mwindow->defaults->save();
162 if( !new_project->new_edl->Garbage::remove_user() )
163 new_project->new_edl = 0;
166 new_project->create_new_project();
170 int NewThread::load_defaults()
172 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
176 int NewThread::save_defaults()
178 mwindow->defaults->update("AUTOASPECT", auto_aspect);
182 int NewThread::update_aspect()
185 char string[BCTEXTLEN];
186 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
187 new_project->new_edl->session->aspect_h,
188 new_project->new_edl->session->output_w,
189 new_project->new_edl->session->output_h);
190 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
191 nwindow->aspect_w_text->update(string);
192 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
193 nwindow->aspect_h_text->update(string);
199 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
200 : BC_Window(_(PROGRAM_NAME ": New Project"), x, y, WIDTH, HEIGHT,
203 this->mwindow = mwindow;
204 this->new_thread = new_thread;
205 this->new_edl = new_thread->new_project->new_edl;
209 NewWindow::~NewWindow()
211 lock_window("NewWindow::~NewWindow");
212 if( format_presets ) delete format_presets;
216 void NewWindow::create_objects()
218 int x = 10, y = 10, x1, y1;
221 lock_window("NewWindow::create_objects");
222 mwindow->theme->draw_new_bg(this);
224 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
227 format_presets = new NewPresets(mwindow,
231 format_presets->create_objects();
232 x = format_presets->x;
233 y = format_presets->y;
237 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
241 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
243 add_subwindow(atracks = new NewATracks(this, "", x1, y));
244 x1 += atracks->get_w();
245 add_subwindow(new NewATracksTumbler(this, x1, y));
246 y += atracks->get_h() + 5;
249 add_subwindow(new BC_Title(x1, y, _("Channels:")));
251 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
252 x1 += achannels->get_w();
253 add_subwindow(new NewAChannelsTumbler(this, x1, y));
254 y += achannels->get_h() + 5;
257 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
259 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
260 x1 += sample_rate->get_w();
261 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
265 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
268 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
270 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
271 x1 += vtracks->get_w();
272 add_subwindow(new NewVTracksTumbler(this, x1, y));
273 y += vtracks->get_h() + 5;
276 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
278 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
279 // x1 += vchannels->get_w();
280 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
281 // y += vchannels->get_h() + 5;
283 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
285 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
286 x1 += frame_rate->get_w();
287 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
288 y += frame_rate->get_h() + 5;
291 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
293 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
294 // x1 += canvas_w_text->get_w() + 2;
295 // add_subwindow(new BC_Title(x1, y, "x"));
297 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
298 // x1 += canvas_h_text->get_w();
299 // add_subwindow(new FrameSizePulldown(mwindow,
305 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
306 // y += canvas_h_text->get_h() + 5;
309 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
311 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
312 x1 += output_w_text->get_w() + 2;
313 add_subwindow(new BC_Title(x1, y, "x"));
315 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
316 x1 += output_h_text->get_w();
317 FrameSizePulldown *pulldown;
318 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
323 x1 += pulldown->get_w() + 10;
324 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
325 y += output_h_text->get_h() + 5;
328 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
330 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
331 x1 += aspect_w_text->get_w() + 2;
332 add_subwindow(new BC_Title(x1, y, ":"));
334 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
335 x1 += aspect_h_text->get_w();
336 add_subwindow(new AspectPulldown(mwindow,
337 aspect_w_text, aspect_h_text, x1, y));
339 x1 = aspect_w_text->get_x();
340 y += aspect_w_text->get_h() + 5;
341 add_subwindow(new NewAspectAuto(this, x1, y));
344 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
345 x1 = x + title->get_w();
346 y1 = y; y += title->get_h() + 10;
347 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
348 int x2 = x + title->get_w();
349 int y2 = y; y += title->get_h() + 10;
350 if( x1 < x2 ) x1 = x2;
352 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
353 add_subwindow(color_model = new ColormodelPulldown(mwindow,
354 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
355 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
356 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
357 textbox, &new_edl->session->interlace_mode,
358 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
359 x1+textbox->get_w(), y2));
361 add_subwindow(new BC_OKButton(this,
362 mwindow->theme->get_image_set("new_ok_images")));
363 add_subwindow(new BC_CancelButton(this,
364 mwindow->theme->get_image_set("new_cancel_images")));
371 int NewWindow::update()
373 atracks->update((int64_t)new_edl->session->audio_tracks);
374 achannels->update((int64_t)new_edl->session->audio_channels);
375 sample_rate->update((int64_t)new_edl->session->sample_rate);
376 vtracks->update((int64_t)new_edl->session->video_tracks);
377 frame_rate->update((float)new_edl->session->frame_rate);
378 output_w_text->update((int64_t)new_edl->session->output_w);
379 output_h_text->update((int64_t)new_edl->session->output_h);
380 aspect_w_text->update((float)new_edl->session->aspect_w);
381 aspect_h_text->update((float)new_edl->session->aspect_h);
382 interlace_pulldown->update(new_edl->session->interlace_mode);
383 color_model->update_value(new_edl->session->color_model);
388 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
389 : FormatPresets(mwindow, gui, 0, x, y)
393 NewPresets::~NewPresets()
397 int NewPresets::handle_event()
403 EDL* NewPresets::get_edl()
405 return new_gui->new_edl;
409 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
410 : BC_TextBox(x, y, 90, 1, text)
412 this->nwindow = nwindow;
415 int NewATracks::handle_event()
417 nwindow->new_edl->session->audio_tracks = atol(get_text());
421 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
424 this->nwindow = nwindow;
426 int NewATracksTumbler::handle_up_event()
428 nwindow->new_edl->session->audio_tracks++;
429 nwindow->new_edl->boundaries();
433 int NewATracksTumbler::handle_down_event()
435 nwindow->new_edl->session->audio_tracks--;
436 nwindow->new_edl->boundaries();
442 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
443 : BC_TextBox(x, y, 90, 1, text)
445 this->nwindow = nwindow;
448 int NewAChannels::handle_event()
450 nwindow->new_edl->session->audio_channels = atol(get_text());
455 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
458 this->nwindow = nwindow;
460 int NewAChannelsTumbler::handle_up_event()
462 nwindow->new_edl->session->audio_channels++;
463 nwindow->new_edl->boundaries();
467 int NewAChannelsTumbler::handle_down_event()
469 nwindow->new_edl->session->audio_channels--;
470 nwindow->new_edl->boundaries();
476 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
477 : BC_TextBox(x, y, 90, 1, text)
479 this->nwindow = nwindow;
482 int NewSampleRate::handle_event()
484 nwindow->new_edl->session->sample_rate = atol(get_text());
489 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
490 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
491 &mwindow->theme->sample_rates, 0, 0, 1, 0, 1)
493 this->mwindow = mwindow;
494 this->output = output;
496 int SampleRatePulldown::handle_event()
498 char *text = get_selection(0, 0)->get_text();
499 output->update(text);
500 output->handle_event();
505 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
506 : BC_TextBox(x, y, 90, 1, text)
508 this->nwindow = nwindow;
511 int NewVTracks::handle_event()
513 nwindow->new_edl->session->video_tracks = atol(get_text());
518 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
521 this->nwindow = nwindow;
523 int NewVTracksTumbler::handle_up_event()
525 nwindow->new_edl->session->video_tracks++;
526 nwindow->new_edl->boundaries();
530 int NewVTracksTumbler::handle_down_event()
532 nwindow->new_edl->session->video_tracks--;
533 nwindow->new_edl->boundaries();
539 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
540 : BC_TextBox(x, y, 90, 1, text)
542 this->nwindow = nwindow;
545 int NewVChannels::handle_event()
547 nwindow->new_edl->session->video_channels = atol(get_text());
552 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
555 this->nwindow = nwindow;
557 int NewVChannelsTumbler::handle_up_event()
559 nwindow->new_edl->session->video_channels++;
560 nwindow->new_edl->boundaries();
564 int NewVChannelsTumbler::handle_down_event()
566 nwindow->new_edl->session->video_channels--;
567 nwindow->new_edl->boundaries();
573 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
574 : BC_TextBox(x, y, 90, 1, text)
576 this->nwindow = nwindow;
579 int NewFrameRate::handle_event()
581 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
586 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
587 BC_TextBox *output, int x, int y)
588 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
589 &mwindow->theme->frame_rates, 0, 0, 1, 0, 1)
591 this->mwindow = mwindow;
592 this->output = output;
594 int FrameRatePulldown::handle_event()
596 char *text = get_selection(0, 0)->get_text();
597 output->update(text);
598 output->handle_event();
602 FrameSizePulldown::FrameSizePulldown(Theme *theme,
603 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
604 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
605 &theme->frame_sizes, 0, 0, 1, 0, 1)
608 this->output_w = output_w;
609 this->output_h = output_h;
612 int FrameSizePulldown::handle_event()
614 char *text = get_selection(0, 0)->get_text();
615 char string[BCTEXTLEN];
619 strcpy(string, text);
620 ptr = strrchr(string, 'x');
629 output_w->handle_event();
630 output_h->handle_event();
636 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
637 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
639 this->nwindow = nwindow;
641 int NewOutputW::handle_event()
643 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
644 nwindow->new_thread->update_aspect();
649 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
650 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
652 this->nwindow = nwindow;
654 int NewOutputH::handle_event()
656 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
657 nwindow->new_thread->update_aspect();
662 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
663 : BC_TextBox(x, y, 70, 1, text)
665 this->nwindow = nwindow;
668 int NewAspectW::handle_event()
670 nwindow->new_edl->session->aspect_w = atof(get_text());
675 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
676 : BC_TextBox(x, y, 70, 1, text)
678 this->nwindow = nwindow;
681 int NewAspectH::handle_event()
683 nwindow->new_edl->session->aspect_h = atof(get_text());
688 AspectPulldown::AspectPulldown(MWindow *mwindow,
689 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
690 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
691 &mwindow->theme->aspect_ratios, 0, 0, 1, 0, 1)
693 this->mwindow = mwindow;
694 this->output_w = output_w;
695 this->output_h = output_h;
698 int AspectPulldown::handle_event()
700 char *text = get_selection(0, 0)->get_text();
701 char string[BCTEXTLEN];
705 strcpy(string, text);
706 ptr = strrchr(string, ':');
715 output_w->handle_event();
716 output_h->handle_event();
722 ColormodelItem::ColormodelItem(const char *text, int value)
723 : BC_ListBoxItem(text)
728 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
729 BC_TextBox *output_text, int *output_value, int x, int y)
730 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT,
731 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels, 0, 0, 1, 0, 1)
733 this->mwindow = mwindow;
734 this->output_text = output_text;
735 this->output_value = output_value;
736 output_text->update(colormodel_to_text());
739 int ColormodelPulldown::handle_event()
741 output_text->update(get_selection(0, 0)->get_text());
742 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
746 const char* ColormodelPulldown::colormodel_to_text()
748 for( int i=0; i<mwindow->colormodels.total; ++i )
749 if( mwindow->colormodels.values[i]->value == *output_value )
750 return mwindow->colormodels.values[i]->get_text();
754 void ColormodelPulldown::update_value(int value)
756 *output_value = value;
757 output_text->update(colormodel_to_text());
761 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
762 : BC_ListBoxItem(text)
767 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
768 BC_TextBox *output_text,
770 ArrayList<BC_ListBoxItem*> *data,
773 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
775 this->mwindow = mwindow;
776 this->output_text = output_text;
777 this->output_value = output_value;
778 output_text->update(interlacemode_to_text());
781 int InterlacemodePulldown::handle_event()
783 output_text->update(get_selection(0, 0)->get_text());
784 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
788 const char* InterlacemodePulldown::interlacemode_to_text()
790 ilacemode_to_text(this->string,*output_value);
791 return (this->string);
794 int InterlacemodePulldown::update(int interlace_mode)
796 *output_value = interlace_mode;
797 output_text->update(interlacemode_to_text());
802 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
803 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
805 this->nwindow = nwindow;
807 NewAspectAuto::~NewAspectAuto()
810 int NewAspectAuto::handle_event()
812 nwindow->new_thread->auto_aspect = get_value();
813 nwindow->new_thread->update_aspect();
818 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
819 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
821 this->mwindow = mwindow;
823 set_tooltip(_("Swap dimensions"));
826 int NewSwapExtents::handle_event()
828 int w = gui->new_edl->session->output_w;
829 int h = gui->new_edl->session->output_h;
830 gui->new_edl->session->output_w = h;
831 gui->new_edl->session->output_h = w;
832 gui->output_w_text->update((int64_t)h);
833 gui->output_h_text->update((int64_t)w);
834 gui->new_thread->update_aspect();