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->cwindow->playback_engine->que->send_command(STOP,
100 for( int i=0; i<mwindow->vwindows.size(); ++i ) {
101 VWindow *vwindow = mwindow->vwindows.get(i);
102 if( !vwindow->is_running() ) continue;
103 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
104 vwindow->playback_engine->interrupt_playback(0);
107 mwindow->cwindow->playback_engine->interrupt_playback(0);
109 mwindow->gui->lock_window();
110 mwindow->reset_caches();
112 memcpy(new_edl->session->achannel_positions,
113 &mwindow->preferences->channel_positions[
114 MAXCHANNELS * (new_edl->session->audio_channels - 1)],
115 sizeof(int) * MAXCHANNELS);
116 new_edl->session->boundaries();
117 new_edl->create_default_tracks();
119 mwindow->undo->update_undo_before();
120 mwindow->set_filename("");
122 mwindow->hide_plugins();
123 mwindow->edl->Garbage::remove_user();
124 mwindow->edl = new_edl;
126 mwindow->save_defaults();
128 // Load file sequence
129 mwindow->update_project(LOADMODE_REPLACE);
130 mwindow->session->changes_made = 0;
131 mwindow->undo->update_undo_after(_("New Project"), LOAD_ALL);
132 mwindow->gui->unlock_window();
136 NewThread::NewThread(MWindow *mwindow, New *new_project)
139 this->mwindow = mwindow;
140 this->new_project = new_project;
144 NewThread::~NewThread()
149 BC_Window* NewThread::new_gui()
151 mwindow->edl->save_defaults(mwindow->defaults);
152 new_project->create_new_edl();
155 mwindow->gui->lock_window("NewThread::new_gui");
156 int x = mwindow->gui->get_pop_cursor_x(0);
157 int y = mwindow->gui->get_pop_cursor_y(0);
159 nwindow = new NewWindow(mwindow, this, x, y);
160 nwindow->create_objects();
161 mwindow->gui->unlock_window();
165 void NewThread::handle_close_event(int result)
167 if( !new_project->new_edl ) return;
168 new_project->new_edl->save_defaults(mwindow->defaults);
169 mwindow->defaults->save();
173 if( !new_project->new_edl->Garbage::remove_user() )
174 new_project->new_edl = 0;
177 new_project->create_new_project();
181 int NewThread::load_defaults()
183 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
187 int NewThread::save_defaults()
189 mwindow->defaults->update("AUTOASPECT", auto_aspect);
193 int NewThread::update_aspect()
196 char string[BCTEXTLEN];
197 mwindow->create_aspect_ratio(new_project->new_edl->session->aspect_w,
198 new_project->new_edl->session->aspect_h,
199 new_project->new_edl->session->output_w,
200 new_project->new_edl->session->output_h);
201 sprintf(string, "%.02f", new_project->new_edl->session->aspect_w);
202 nwindow->aspect_w_text->update(string);
203 sprintf(string, "%.02f", new_project->new_edl->session->aspect_h);
204 nwindow->aspect_h_text->update(string);
210 NewWindow::NewWindow(MWindow *mwindow, NewThread *new_thread, int x, int y)
211 : BC_Window(_(PROGRAM_NAME ": New Project"), x, y, WIDTH, HEIGHT,
214 this->mwindow = mwindow;
215 this->new_thread = new_thread;
216 this->new_edl = new_thread->new_project->new_edl;
220 NewWindow::~NewWindow()
222 lock_window("NewWindow::~NewWindow");
223 if( format_presets ) delete format_presets;
227 void NewWindow::create_objects()
229 int x = 10, y = 10, x1, y1;
232 lock_window("NewWindow::create_objects");
233 mwindow->theme->draw_new_bg(this);
235 add_subwindow(new BC_Title(x, y, _("Parameters for the new project:")));
238 format_presets = new NewPresets(mwindow,
242 format_presets->create_objects();
243 x = format_presets->x;
244 y = format_presets->y;
248 add_subwindow(new BC_Title(x, y, _("Audio"), LARGEFONT));
252 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
254 add_subwindow(atracks = new NewATracks(this, "", x1, y));
255 x1 += atracks->get_w();
256 add_subwindow(new NewATracksTumbler(this, x1, y));
257 y += atracks->get_h() + 5;
260 add_subwindow(new BC_Title(x1, y, _("Channels:")));
262 add_subwindow(achannels = new NewAChannels(this, "", x1, y));
263 x1 += achannels->get_w();
264 add_subwindow(new NewAChannelsTumbler(this, x1, y));
265 y += achannels->get_h() + 5;
268 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
270 add_subwindow(sample_rate = new NewSampleRate(this, "", x1, y));
271 x1 += sample_rate->get_w();
272 add_subwindow(new SampleRatePulldown(mwindow, sample_rate, x1, y));
276 add_subwindow(new BC_Title(x, y, _("Video"), LARGEFONT));
279 add_subwindow(new BC_Title(x1, y, _("Tracks:")));
281 add_subwindow(vtracks = new NewVTracks(this, "", x1, y));
282 x1 += vtracks->get_w();
283 add_subwindow(new NewVTracksTumbler(this, x1, y));
284 y += vtracks->get_h() + 5;
287 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
289 // add_subwindow(vchannels = new NewVChannels(this, "", x1, y));
290 // x1 += vchannels->get_w();
291 // add_subwindow(new NewVChannelsTumbler(this, x1, y));
292 // y += vchannels->get_h() + 5;
294 add_subwindow(new BC_Title(x1, y, _("Framerate:")));
296 add_subwindow(frame_rate = new NewFrameRate(this, "", x1, y));
297 x1 += frame_rate->get_w();
298 add_subwindow(new FrameRatePulldown(mwindow, frame_rate, x1, y));
299 y += frame_rate->get_h() + 5;
302 // add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
304 // add_subwindow(canvas_w_text = new NewTrackW(this, x1, y));
305 // x1 += canvas_w_text->get_w() + 2;
306 // add_subwindow(new BC_Title(x1, y, "x"));
308 // add_subwindow(canvas_h_text = new NewTrackH(this, x1, y));
309 // x1 += canvas_h_text->get_w();
310 // add_subwindow(new FrameSizePulldown(mwindow,
316 // add_subwindow(new NewCloneToggle(mwindow, this, x1, y));
317 // y += canvas_h_text->get_h() + 5;
320 add_subwindow(new BC_Title(x1, y, _("Canvas size:")));
322 add_subwindow(output_w_text = new NewOutputW(this, x1, y));
323 x1 += output_w_text->get_w() + 2;
324 add_subwindow(new BC_Title(x1, y, "x"));
326 add_subwindow(output_h_text = new NewOutputH(this, x1, y));
327 x1 += output_h_text->get_w();
328 FrameSizePulldown *pulldown;
329 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
334 x1 += pulldown->get_w() + 10;
335 add_subwindow(new NewSwapExtents(mwindow, this, x1, y));
336 y += output_h_text->get_h() + 5;
339 add_subwindow(new BC_Title(x1, y, _("Aspect ratio:")));
341 add_subwindow(aspect_w_text = new NewAspectW(this, "", x1, y));
342 x1 += aspect_w_text->get_w() + 2;
343 add_subwindow(new BC_Title(x1, y, ":"));
345 add_subwindow(aspect_h_text = new NewAspectH(this, "", x1, y));
346 x1 += aspect_h_text->get_w();
347 add_subwindow(new AspectPulldown(mwindow,
348 aspect_w_text, aspect_h_text, x1, y));
350 x1 = aspect_w_text->get_x();
351 y += aspect_w_text->get_h() + 5;
352 add_subwindow(new NewAspectAuto(this, x1, y));
355 add_subwindow(title = new BC_Title(x, y, _("Color model:")));
356 x1 = x + title->get_w();
357 y1 = y; y += title->get_h() + 10;
358 add_subwindow(title = new BC_Title(x, y, _("Interlace mode:")));
359 int x2 = x + title->get_w();
360 int y2 = y; y += title->get_h() + 10;
361 if( x1 < x2 ) x1 = x2;
363 add_subwindow(textbox = new BC_TextBox(x1, y1, 150, 1, ""));
364 add_subwindow(color_model = new ColormodelPulldown(mwindow,
365 textbox, &new_edl->session->color_model, x1+textbox->get_w(), y1));
366 add_subwindow(textbox = new BC_TextBox(x1, y2, 150, 1, ""));
367 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
368 textbox, &new_edl->session->interlace_mode,
369 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
370 x1+textbox->get_w(), y2));
372 add_subwindow(new BC_OKButton(this,
373 mwindow->theme->get_image_set("new_ok_images")));
374 add_subwindow(new BC_CancelButton(this,
375 mwindow->theme->get_image_set("new_cancel_images")));
382 int NewWindow::update()
384 atracks->update((int64_t)new_edl->session->audio_tracks);
385 achannels->update((int64_t)new_edl->session->audio_channels);
386 sample_rate->update((int64_t)new_edl->session->sample_rate);
387 vtracks->update((int64_t)new_edl->session->video_tracks);
388 frame_rate->update((float)new_edl->session->frame_rate);
389 output_w_text->update((int64_t)new_edl->session->output_w);
390 output_h_text->update((int64_t)new_edl->session->output_h);
391 aspect_w_text->update((float)new_edl->session->aspect_w);
392 aspect_h_text->update((float)new_edl->session->aspect_h);
393 interlace_pulldown->update(new_edl->session->interlace_mode);
394 color_model->update_value(new_edl->session->color_model);
399 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
400 : FormatPresets(mwindow, gui, 0, x, y)
404 NewPresets::~NewPresets()
408 int NewPresets::handle_event()
414 EDL* NewPresets::get_edl()
416 return new_gui->new_edl;
420 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
421 : BC_TextBox(x, y, 90, 1, text)
423 this->nwindow = nwindow;
426 int NewATracks::handle_event()
428 nwindow->new_edl->session->audio_tracks = atol(get_text());
432 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
435 this->nwindow = nwindow;
437 int NewATracksTumbler::handle_up_event()
439 nwindow->new_edl->session->audio_tracks++;
440 nwindow->new_edl->boundaries();
444 int NewATracksTumbler::handle_down_event()
446 nwindow->new_edl->session->audio_tracks--;
447 nwindow->new_edl->boundaries();
453 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
454 : BC_TextBox(x, y, 90, 1, text)
456 this->nwindow = nwindow;
459 int NewAChannels::handle_event()
461 nwindow->new_edl->session->audio_channels = atol(get_text());
466 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
469 this->nwindow = nwindow;
471 int NewAChannelsTumbler::handle_up_event()
473 nwindow->new_edl->session->audio_channels++;
474 nwindow->new_edl->boundaries();
478 int NewAChannelsTumbler::handle_down_event()
480 nwindow->new_edl->session->audio_channels--;
481 nwindow->new_edl->boundaries();
487 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
488 : BC_TextBox(x, y, 90, 1, text)
490 this->nwindow = nwindow;
493 int NewSampleRate::handle_event()
495 nwindow->new_edl->session->sample_rate = atol(get_text());
500 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
501 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
502 &mwindow->theme->sample_rates, 0, 0, 1, 0, 1)
504 this->mwindow = mwindow;
505 this->output = output;
507 int SampleRatePulldown::handle_event()
509 char *text = get_selection(0, 0)->get_text();
510 output->update(text);
511 output->handle_event();
516 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
517 : BC_TextBox(x, y, 90, 1, text)
519 this->nwindow = nwindow;
522 int NewVTracks::handle_event()
524 nwindow->new_edl->session->video_tracks = atol(get_text());
529 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
532 this->nwindow = nwindow;
534 int NewVTracksTumbler::handle_up_event()
536 nwindow->new_edl->session->video_tracks++;
537 nwindow->new_edl->boundaries();
541 int NewVTracksTumbler::handle_down_event()
543 nwindow->new_edl->session->video_tracks--;
544 nwindow->new_edl->boundaries();
550 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
551 : BC_TextBox(x, y, 90, 1, text)
553 this->nwindow = nwindow;
556 int NewVChannels::handle_event()
558 nwindow->new_edl->session->video_channels = atol(get_text());
563 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
566 this->nwindow = nwindow;
568 int NewVChannelsTumbler::handle_up_event()
570 nwindow->new_edl->session->video_channels++;
571 nwindow->new_edl->boundaries();
575 int NewVChannelsTumbler::handle_down_event()
577 nwindow->new_edl->session->video_channels--;
578 nwindow->new_edl->boundaries();
584 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
585 : BC_TextBox(x, y, 90, 1, text)
587 this->nwindow = nwindow;
590 int NewFrameRate::handle_event()
592 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
597 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
598 BC_TextBox *output, int x, int y)
599 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
600 &mwindow->theme->frame_rates, 0, 0, 1, 0, 1)
602 this->mwindow = mwindow;
603 this->output = output;
605 int FrameRatePulldown::handle_event()
607 char *text = get_selection(0, 0)->get_text();
608 output->update(text);
609 output->handle_event();
613 FrameSizePulldown::FrameSizePulldown(Theme *theme,
614 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
615 : BC_ListBox(x, y, 150, 250, LISTBOX_TEXT,
616 &theme->frame_sizes, 0, 0, 1, 0, 1)
619 this->output_w = output_w;
620 this->output_h = output_h;
623 int FrameSizePulldown::handle_event()
625 char *text = get_selection(0, 0)->get_text();
626 char string[BCTEXTLEN];
630 strcpy(string, text);
631 ptr = strrchr(string, 'x');
640 output_w->handle_event();
641 output_h->handle_event();
647 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
648 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
650 this->nwindow = nwindow;
652 int NewOutputW::handle_event()
654 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
655 nwindow->new_thread->update_aspect();
660 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
661 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
663 this->nwindow = nwindow;
665 int NewOutputH::handle_event()
667 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
668 nwindow->new_thread->update_aspect();
673 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
674 : BC_TextBox(x, y, 70, 1, text)
676 this->nwindow = nwindow;
679 int NewAspectW::handle_event()
681 nwindow->new_edl->session->aspect_w = atof(get_text());
686 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
687 : BC_TextBox(x, y, 70, 1, text)
689 this->nwindow = nwindow;
692 int NewAspectH::handle_event()
694 nwindow->new_edl->session->aspect_h = atof(get_text());
699 AspectPulldown::AspectPulldown(MWindow *mwindow,
700 BC_TextBox *output_w, BC_TextBox *output_h, int x, int y)
701 : BC_ListBox(x, y, 100, 200, LISTBOX_TEXT,
702 &mwindow->theme->aspect_ratios, 0, 0, 1, 0, 1)
704 this->mwindow = mwindow;
705 this->output_w = output_w;
706 this->output_h = output_h;
709 int AspectPulldown::handle_event()
711 char *text = get_selection(0, 0)->get_text();
712 char string[BCTEXTLEN];
716 strcpy(string, text);
717 ptr = strrchr(string, ':');
726 output_w->handle_event();
727 output_h->handle_event();
733 ColormodelItem::ColormodelItem(const char *text, int value)
734 : BC_ListBoxItem(text)
739 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
740 BC_TextBox *output_text, int *output_value, int x, int y)
741 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT,
742 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels, 0, 0, 1, 0, 1)
744 this->mwindow = mwindow;
745 this->output_text = output_text;
746 this->output_value = output_value;
747 output_text->update(colormodel_to_text());
750 int ColormodelPulldown::handle_event()
752 output_text->update(get_selection(0, 0)->get_text());
753 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
757 const char* ColormodelPulldown::colormodel_to_text()
759 for( int i=0; i<mwindow->colormodels.total; ++i )
760 if( mwindow->colormodels.values[i]->value == *output_value )
761 return mwindow->colormodels.values[i]->get_text();
765 void ColormodelPulldown::update_value(int value)
767 *output_value = value;
768 output_text->update(colormodel_to_text());
772 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
773 : BC_ListBoxItem(text)
778 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
779 BC_TextBox *output_text,
781 ArrayList<BC_ListBoxItem*> *data,
784 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
786 this->mwindow = mwindow;
787 this->output_text = output_text;
788 this->output_value = output_value;
789 output_text->update(interlacemode_to_text());
792 int InterlacemodePulldown::handle_event()
794 output_text->update(get_selection(0, 0)->get_text());
795 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
799 const char* InterlacemodePulldown::interlacemode_to_text()
801 ilacemode_to_text(this->string,*output_value);
802 return (this->string);
805 int InterlacemodePulldown::update(int interlace_mode)
807 *output_value = interlace_mode;
808 output_text->update(interlacemode_to_text());
813 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
814 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
816 this->nwindow = nwindow;
818 NewAspectAuto::~NewAspectAuto()
821 int NewAspectAuto::handle_event()
823 nwindow->new_thread->auto_aspect = get_value();
824 nwindow->new_thread->update_aspect();
829 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
830 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
832 this->mwindow = mwindow;
834 set_tooltip(_("Swap dimensions"));
837 int NewSwapExtents::handle_event()
839 int w = gui->new_edl->session->output_w;
840 int h = gui->new_edl->session->output_h;
841 gui->new_edl->session->output_w = h;
842 gui->new_edl->session->output_h = w;
843 gui->output_w_text->update((int64_t)h);
844 gui->output_h_text->update((int64_t)w);
845 gui->new_thread->update_aspect();