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"
56 New::New(MWindow *mwindow)
57 : BC_MenuItem(_("New Project..."), "n", 'n')
59 this->mwindow = mwindow;
70 void New::create_objects()
72 thread = new NewThread(mwindow, this);
75 int New::handle_event()
77 mwindow->gui->unlock_window();
78 mwindow->edl->save_defaults(mwindow->defaults);
82 mwindow->gui->lock_window("New::handle_event");
87 void New::create_new_edl()
92 new_edl->create_objects();
93 new_edl->load_defaults(mwindow->defaults);
98 int New::create_new_project()
100 mwindow->cwindow->playback_engine->que->send_command(STOP,
105 for(int i = 0; i < mwindow->vwindows.size(); i++)
107 VWindow *vwindow = mwindow->vwindows.get(i);
108 if( !vwindow->is_running() ) continue;
109 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
110 vwindow->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 Project"), 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);
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:")));
387 add_subwindow(textbox = new BC_TextBox(x + 100, y, 200, 1, ""));
388 add_subwindow(color_model = new ColormodelPulldown(mwindow,
390 &new_edl->session->color_model,
391 x + 100 + textbox->get_w(),
393 y += textbox->get_h() + 5;
395 // --------------------
396 add_subwindow(new BC_Title(x, y, _("Interlace mode:")));
397 add_subwindow(textbox = new BC_TextBox(x + 100, y, 140, 1, ""));
398 add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
400 &new_edl->session->interlace_mode,
401 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
402 x + 100 + textbox->get_w(),
404 y += textbox->get_h() + 5;
406 add_subwindow(new BC_OKButton(this,
407 mwindow->theme->get_image_set("new_ok_images")));
408 add_subwindow(new BC_CancelButton(this,
409 mwindow->theme->get_image_set("new_cancel_images")));
416 int NewWindow::update()
418 atracks->update((int64_t)new_edl->session->audio_tracks);
419 achannels->update((int64_t)new_edl->session->audio_channels);
420 sample_rate->update((int64_t)new_edl->session->sample_rate);
421 vtracks->update((int64_t)new_edl->session->video_tracks);
422 frame_rate->update((float)new_edl->session->frame_rate);
423 output_w_text->update((int64_t)new_edl->session->output_w);
424 output_h_text->update((int64_t)new_edl->session->output_h);
425 aspect_w_text->update((float)new_edl->session->aspect_w);
426 aspect_h_text->update((float)new_edl->session->aspect_h);
427 interlace_pulldown->update(new_edl->session->interlace_mode);
428 color_model->update_value(new_edl->session->color_model);
438 NewPresets::NewPresets(MWindow *mwindow, NewWindow *gui, int x, int y)
439 : FormatPresets(mwindow, gui, 0, x, y)
443 NewPresets::~NewPresets()
447 int NewPresets::handle_event()
453 EDL* NewPresets::get_edl()
455 return new_gui->new_edl;
460 NewATracks::NewATracks(NewWindow *nwindow, const char *text, int x, int y)
461 : BC_TextBox(x, y, 90, 1, text)
463 this->nwindow = nwindow;
466 int NewATracks::handle_event()
468 nwindow->new_edl->session->audio_tracks = atol(get_text());
472 NewATracksTumbler::NewATracksTumbler(NewWindow *nwindow, int x, int y)
475 this->nwindow = nwindow;
477 int NewATracksTumbler::handle_up_event()
479 nwindow->new_edl->session->audio_tracks++;
480 nwindow->new_edl->boundaries();
484 int NewATracksTumbler::handle_down_event()
486 nwindow->new_edl->session->audio_tracks--;
487 nwindow->new_edl->boundaries();
492 NewAChannels::NewAChannels(NewWindow *nwindow, const char *text, int x, int y)
493 : BC_TextBox(x, y, 90, 1, text)
495 this->nwindow = nwindow;
498 int NewAChannels::handle_event()
500 nwindow->new_edl->session->audio_channels = atol(get_text());
504 NewAChannelsTumbler::NewAChannelsTumbler(NewWindow *nwindow, int x, int y)
507 this->nwindow = nwindow;
509 int NewAChannelsTumbler::handle_up_event()
511 nwindow->new_edl->session->audio_channels++;
512 nwindow->new_edl->boundaries();
516 int NewAChannelsTumbler::handle_down_event()
518 nwindow->new_edl->session->audio_channels--;
519 nwindow->new_edl->boundaries();
525 NewSampleRate::NewSampleRate(NewWindow *nwindow, const char *text, int x, int y)
526 : BC_TextBox(x, y, 90, 1, text)
528 this->nwindow = nwindow;
531 int NewSampleRate::handle_event()
533 nwindow->new_edl->session->sample_rate = atol(get_text());
537 SampleRatePulldown::SampleRatePulldown(MWindow *mwindow, BC_TextBox *output, int x, int y)
543 &mwindow->theme->sample_rates,
550 this->mwindow = mwindow;
551 this->output = output;
553 int SampleRatePulldown::handle_event()
555 char *text = get_selection(0, 0)->get_text();
556 output->update(text);
557 output->handle_event();
575 NewVTracks::NewVTracks(NewWindow *nwindow, const char *text, int x, int y)
576 : BC_TextBox(x, y, 90, 1, text)
578 this->nwindow = nwindow;
581 int NewVTracks::handle_event()
583 nwindow->new_edl->session->video_tracks = atol(get_text());
587 NewVTracksTumbler::NewVTracksTumbler(NewWindow *nwindow, int x, int y)
590 this->nwindow = nwindow;
592 int NewVTracksTumbler::handle_up_event()
594 nwindow->new_edl->session->video_tracks++;
595 nwindow->new_edl->boundaries();
599 int NewVTracksTumbler::handle_down_event()
601 nwindow->new_edl->session->video_tracks--;
602 nwindow->new_edl->boundaries();
607 NewVChannels::NewVChannels(NewWindow *nwindow, const char *text, int x, int y)
608 : BC_TextBox(x, y, 90, 1, text)
610 this->nwindow = nwindow;
613 int NewVChannels::handle_event()
615 nwindow->new_edl->session->video_channels = atol(get_text());
619 NewVChannelsTumbler::NewVChannelsTumbler(NewWindow *nwindow, int x, int y)
622 this->nwindow = nwindow;
624 int NewVChannelsTumbler::handle_up_event()
626 nwindow->new_edl->session->video_channels++;
627 nwindow->new_edl->boundaries();
631 int NewVChannelsTumbler::handle_down_event()
633 nwindow->new_edl->session->video_channels--;
634 nwindow->new_edl->boundaries();
639 NewFrameRate::NewFrameRate(NewWindow *nwindow, const char *text, int x, int y)
640 : BC_TextBox(x, y, 90, 1, text)
642 this->nwindow = nwindow;
645 int NewFrameRate::handle_event()
647 nwindow->new_edl->session->frame_rate = Units::atoframerate(get_text());
651 FrameRatePulldown::FrameRatePulldown(MWindow *mwindow,
660 &mwindow->theme->frame_rates,
667 this->mwindow = mwindow;
668 this->output = output;
670 int FrameRatePulldown::handle_event()
672 char *text = get_selection(0, 0)->get_text();
673 output->update(text);
674 output->handle_event();
678 FrameSizePulldown::FrameSizePulldown(Theme *theme,
679 BC_TextBox *output_w,
680 BC_TextBox *output_h,
696 this->output_w = output_w;
697 this->output_h = output_h;
699 int FrameSizePulldown::handle_event()
701 char *text = get_selection(0, 0)->get_text();
702 char string[BCTEXTLEN];
706 strcpy(string, text);
707 ptr = strrchr(string, 'x');
717 output_w->handle_event();
718 output_h->handle_event();
723 NewOutputW::NewOutputW(NewWindow *nwindow, int x, int y)
724 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_w)
726 this->nwindow = nwindow;
728 int NewOutputW::handle_event()
730 nwindow->new_edl->session->output_w = MAX(1,atol(get_text()));
731 nwindow->new_thread->update_aspect();
735 NewOutputH::NewOutputH(NewWindow *nwindow, int x, int y)
736 : BC_TextBox(x, y, 70, 1, nwindow->new_edl->session->output_h)
738 this->nwindow = nwindow;
740 int NewOutputH::handle_event()
742 nwindow->new_edl->session->output_h = MAX(1, atol(get_text()));
743 nwindow->new_thread->update_aspect();
747 NewAspectW::NewAspectW(NewWindow *nwindow, const char *text, int x, int y)
748 : BC_TextBox(x, y, 70, 1, text)
750 this->nwindow = nwindow;
753 int NewAspectW::handle_event()
755 nwindow->new_edl->session->aspect_w = atof(get_text());
759 NewAspectH::NewAspectH(NewWindow *nwindow, const char *text, int x, int y)
760 : BC_TextBox(x, y, 70, 1, text)
762 this->nwindow = nwindow;
765 int NewAspectH::handle_event()
767 nwindow->new_edl->session->aspect_h = atof(get_text());
771 AspectPulldown::AspectPulldown(MWindow *mwindow,
772 BC_TextBox *output_w,
773 BC_TextBox *output_h,
781 &mwindow->theme->aspect_ratios,
788 this->mwindow = mwindow;
789 this->output_w = output_w;
790 this->output_h = output_h;
792 int AspectPulldown::handle_event()
794 char *text = get_selection(0, 0)->get_text();
795 char string[BCTEXTLEN];
799 strcpy(string, text);
800 ptr = strrchr(string, ':');
810 output_w->handle_event();
811 output_h->handle_event();
816 ColormodelItem::ColormodelItem(const char *text, int value)
817 : BC_ListBoxItem(text)
822 ColormodelPulldown::ColormodelPulldown(MWindow *mwindow,
823 BC_TextBox *output_text,
832 (ArrayList<BC_ListBoxItem*>*)&mwindow->colormodels,
839 this->mwindow = mwindow;
840 this->output_text = output_text;
841 this->output_value = output_value;
842 output_text->update(colormodel_to_text());
845 int ColormodelPulldown::handle_event()
847 output_text->update(get_selection(0, 0)->get_text());
848 *output_value = ((ColormodelItem*)get_selection(0, 0))->value;
852 const char* ColormodelPulldown::colormodel_to_text()
854 for(int i = 0; i < mwindow->colormodels.total; i++)
855 if(mwindow->colormodels.values[i]->value == *output_value)
856 return mwindow->colormodels.values[i]->get_text();
860 void ColormodelPulldown::update_value(int value)
862 *output_value = value;
863 output_text->update(colormodel_to_text());
867 InterlacemodeItem::InterlacemodeItem(const char *text, int value)
868 : BC_ListBoxItem(text)
873 InterlacemodePulldown::InterlacemodePulldown(MWindow *mwindow,
874 BC_TextBox *output_text,
876 ArrayList<BC_ListBoxItem*> *data,
879 : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
881 this->mwindow = mwindow;
882 this->output_text = output_text;
883 this->output_value = output_value;
884 output_text->update(interlacemode_to_text());
887 int InterlacemodePulldown::handle_event()
889 output_text->update(get_selection(0, 0)->get_text());
890 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
894 const char* InterlacemodePulldown::interlacemode_to_text()
896 ilacemode_to_text(this->string,*output_value);
897 return (this->string);
900 int InterlacemodePulldown::update(int interlace_mode)
902 *output_value = interlace_mode;
903 output_text->update(interlacemode_to_text());
908 NewAspectAuto::NewAspectAuto(NewWindow *nwindow, int x, int y)
909 : BC_CheckBox(x, y, nwindow->new_thread->auto_aspect, _("Auto aspect ratio"))
911 this->nwindow = nwindow;
913 NewAspectAuto::~NewAspectAuto()
916 int NewAspectAuto::handle_event()
918 nwindow->new_thread->auto_aspect = get_value();
919 nwindow->new_thread->update_aspect();
930 NewSwapExtents::NewSwapExtents(MWindow *mwindow, NewWindow *gui, int x, int y)
931 : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
933 this->mwindow = mwindow;
935 set_tooltip(_("Swap dimensions"));
938 int NewSwapExtents::handle_event()
940 int w = gui->new_edl->session->output_w;
941 int h = gui->new_edl->session->output_h;
942 gui->new_edl->session->output_w = h;
943 gui->new_edl->session->output_h = w;
944 gui->output_w_text->update((int64_t)h);
945 gui->output_h_text->update((int64_t)w);
946 gui->new_thread->update_aspect();