3 #include "cwindowgui.h"
7 #include "edlsession.h"
10 #include "mwindowgui.h"
12 #include "playbackengine.h"
14 #include "transportque.h"
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
21 SetVideo::SetVideo(MWindow *mwindow)
22 :BC_MenuItem(_("Video Setup..."))
24 this->mwindow = mwindow;
25 thread = new SetVideoThread(mwindow);
32 int SetVideo::handle_event()
34 if(!thread->running())
40 thread->window->raise_window();
52 SetVideoThread::SetVideoThread(MWindow *mwindow)
55 this->mwindow = mwindow;
58 SetVideoThread::~SetVideoThread()
68 void SetVideoThread::load_params()
70 orig_dimension[0] = dimension[0] = mwindow->edl->session->track_w;
71 orig_dimension[1] = dimension[1] = mwindow->edl->session->track_h;
72 orig_dimension[2] = dimension[2] = mwindow->edl->session->output_w;
73 orig_dimension[3] = dimension[3] = mwindow->edl->session->output_h;
74 offsets[0] = offsets[1] = offsets[2] = offsets[3] = 0;
75 ratio[0] = ratio[1] = ratio[2] = ratio[3] = 1;
76 aspect_w = mwindow->edl->session->aspect_w;
77 aspect_h = mwindow->edl->session->aspect_h;
78 color_model = mwindow->edl->session->color_model;
79 frame_rate = mwindow->edl->session->frame_rate;
80 channels = mwindow->edl->session->video_channels;
83 void SetVideoThread::save_params()
85 double old_rate = mwindow->edl->session->frame_rate;
86 mwindow->edl->session->track_w = dimension[0];
87 mwindow->edl->session->track_h = dimension[1];
88 mwindow->edl->session->output_w = dimension[2];
89 mwindow->edl->session->output_h = dimension[3];
90 mwindow->edl->session->aspect_w = aspect_w;
91 mwindow->edl->session->aspect_h = aspect_h;
92 mwindow->edl->session->color_model = color_model;
93 mwindow->edl->session->frame_rate = frame_rate;
94 mwindow->edl->session->video_channels = channels;
95 mwindow->edl->resample(old_rate, frame_rate, TRACK_VIDEO);
98 void SetVideoThread::run()
100 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
101 constrain_ratio = mwindow->defaults->get("SCALECONSTRAIN", 0);
104 window = new SetVideoWindow(mwindow, this);
105 window->create_objects();
106 int result = window->run_window();
108 mwindow->defaults->update("AUTOASPECT", auto_aspect);
109 mwindow->defaults->update("SCALECONSTRAIN", constrain_ratio);
113 mwindow->undo->update_undo_before(_("set video"), LOAD_ALL);
115 mwindow->undo->update_undo_after();
116 mwindow->save_backup();
118 mwindow->gui->lock_window();
119 mwindow->gui->update(1,
126 mwindow->gui->unlock_window();
128 mwindow->sync_parameters(CHANGE_EDL);
135 void SetVideoThread::update_window()
138 int i, result, modified_item, dimension_modified = 0, ratio_modified = 0;
140 for(i = 0, result = 0; i < 4 && !result; i++)
142 if(i == 2) pair_start = 2;
148 dimension_modified = 1;
161 if(dimension_modified)
162 ratio[modified_item] = (float)dimension[modified_item] / orig_dimension[modified_item];
164 if(ratio_modified && !constrain_ratio)
166 dimension[modified_item] = (int)(orig_dimension[modified_item] * ratio[modified_item]);
167 window->dimension[modified_item]->update((long)dimension[modified_item]);
170 for(i = pair_start; i < pair_start + 2/* && constrain_ratio */; i++)
172 if(dimension_modified ||
173 (i != modified_item && ratio_modified))
175 if(constrain_ratio) ratio[i] = ratio[modified_item];
176 window->ratio[i]->update(ratio[i]);
180 (i != modified_item && dimension_modified))
184 dimension[i] = (int)(orig_dimension[i] * ratio[modified_item]);
185 window->dimension[i]->update((long)dimension[i]);
194 void SetVideoThread::update_aspect()
199 MWindow::create_aspect_ratio(aspect_w,
203 sprintf(string, "%.02f", aspect_w);
204 window->aspect_w->update(string);
205 sprintf(string, "%.02f", aspect_h);
206 window->aspect_h->update(string);
220 SetVideoWindow::SetVideoWindow(MWindow *mwindow, SetVideoThread *thread)
221 : BC_Window(PROGRAM_NAME ": Video Setup",
222 mwindow->gui->get_abs_cursor_x(),
223 mwindow->gui->get_abs_cursor_y(),
232 this->mwindow = mwindow;
233 this->thread = thread;
236 SetVideoWindow::~SetVideoWindow()
240 int SetVideoWindow::create_objects()
242 int x = 10, y = 10, x1, y1, x2, y2;
246 add_subwindow(new BC_Title(x1, y, _("Frame rate:")));
248 add_subwindow(textbox = new SetFrameRateTextBox(thread, x1, y));
249 x1 += textbox->get_w();
250 add_subwindow(new FrameRatePulldown(mwindow, textbox, x1, y));
253 // y += textbox->get_h() + 5;
254 // add_subwindow(new BC_Title(x1, y, _("Channels:")));
256 // add_subwindow(textbox = new SetVChannels(thread, x1, y));
257 // x1 += textbox->get_w();
258 // add_subwindow(new BC_ITumbler(textbox, 1, MAXCHANNELS, x1, y));
260 y += textbox->get_h() + 40;
261 add_subwindow(new BC_Title(x, y, _("Default track size:")));
264 add_subwindow(new BC_Title(x + 200, y, _("Canvas size:")));
268 add_subwindow(new BC_Title(x, y, _("Width:")));
270 add_subwindow(dimension[0] = new ScaleSizeText(x, y, thread, &(thread->dimension[0])));
272 add_subwindow(new BC_Title(x, y, _("Width:")));
274 add_subwindow(dimension[2] = new ScaleSizeText(x, y, thread, &(thread->dimension[2])));
276 y += dimension[0]->get_h() + 5;
278 add_subwindow(new BC_Title(x, y, _("Height:")));
280 add_subwindow(dimension[1] = new ScaleSizeText(x, y, thread, &(thread->dimension[1])));
282 add_subwindow(new BC_Title(x, y, _("Height:")));
284 add_subwindow(dimension[3] = new ScaleSizeText(x, y, thread, &(thread->dimension[3])));
286 y += dimension[1]->get_h() + 5;
288 add_subwindow(new BC_Title(x, y, _("W Ratio:")));
290 add_subwindow(ratio[0] = new ScaleRatioText(x, y, thread, &(thread->ratio[0])));
292 add_subwindow(new BC_Title(x, y, _("W Ratio:")));
294 add_subwindow(ratio[2] = new ScaleRatioText(x, y, thread, &(thread->ratio[2])));
296 y += ratio[0]->get_h() + 5;
298 add_subwindow(new BC_Title(x, y, _("H Ratio:")));
300 add_subwindow(ratio[1] = new ScaleRatioText(x, y, thread, &(thread->ratio[1])));
302 add_subwindow(new BC_Title(x, y, _("H Ratio:")));
304 add_subwindow(ratio[3] = new ScaleRatioText(x, y, thread, &(thread->ratio[3])));
306 add_subwindow(new FrameSizePulldown(mwindow,
312 add_subwindow(new FrameSizePulldown(mwindow,
319 y += ratio[1]->get_h() + 40;
320 // add_subwindow(new ScaleConstrain(x, y, thread));
323 add_subwindow(new BC_Title(x, y, _("Aspect ratio:")));
325 add_subwindow(aspect_w = new ScaleAspectText(x,
328 &(thread->aspect_w)));
329 x += aspect_w->get_w() + 5;
330 add_subwindow(new BC_Title(x, y, _(":")));
332 add_subwindow(aspect_h = new ScaleAspectText(x,
335 &(thread->aspect_h)));
336 x += aspect_h->get_w() + 5;
337 add_subwindow(new AspectPulldown(mwindow,
343 add_subwindow(new ScaleAspectAuto(x, y - 5, thread));
347 add_subwindow(new BC_Title(x, y, _("Color model:")));
349 add_subwindow(textbox = new BC_TextBox(x, y, 200, 1, ""));
350 x += textbox->get_w();
351 add_subwindow(new ColormodelPulldown(mwindow,
353 &thread->color_model,
359 add_subwindow(new BC_OKButton(this));
360 add_subwindow(new BC_CancelButton(this));
366 SetFrameRateTextBox::SetFrameRateTextBox(SetVideoThread *thread, int x, int y)
367 : BC_TextBox(x, y, 100, 1, (float)thread->frame_rate)
369 this->thread = thread;
372 int SetFrameRateTextBox::handle_event()
374 thread->frame_rate = Units::atoframerate(get_text());
380 SetVChannels::SetVChannels(SetVideoThread *thread, int x, int y)
381 : BC_TextBox(x, y, 100, 1, thread->channels)
383 this->thread = thread;
385 int SetVChannels::handle_event()
387 thread->channels = atol(get_text());
394 ScaleSizeText::ScaleSizeText(int x, int y, SetVideoThread *thread, int *output)
395 : BC_TextBox(x, y, 100, 1, *output)
397 this->thread = thread;
398 this->output = output;
400 ScaleSizeText::~ScaleSizeText()
402 int ScaleSizeText::handle_event()
404 *output = atol(get_text());
407 if(*output <= 0) *output = 2;
408 if(*output > 10000) *output = 10000;
410 thread->update_window();
415 ScaleRatioText::ScaleRatioText(int x, int y, SetVideoThread *thread, float *output)
416 : BC_TextBox(x, y, 100, 1, *output)
418 this->thread = thread;
419 this->output = output;
421 ScaleRatioText::~ScaleRatioText()
423 int ScaleRatioText::handle_event()
425 *output = atof(get_text());
426 //if(*output <= 0) *output = 1;
427 if(*output > 10000) *output = 10000;
428 if(*output < -10000) *output = -10000;
430 thread->update_window();
435 ScaleConstrain::ScaleConstrain(int x, int y, SetVideoThread *thread)
436 : BC_CheckBox(x, y, thread->constrain_ratio, _("Constrain ratio"))
438 this->thread = thread;
440 ScaleConstrain::~ScaleConstrain() {}
441 int ScaleConstrain::handle_event()
443 thread->constrain_ratio = get_value();
447 ScaleAspectAuto::ScaleAspectAuto(int x, int y, SetVideoThread *thread)
448 : BC_CheckBox(x, y, thread->auto_aspect, _("Auto"))
450 this->thread = thread;
453 ScaleAspectAuto::~ScaleAspectAuto()
457 int ScaleAspectAuto::handle_event()
459 thread->auto_aspect = get_value();
460 thread->update_aspect();
463 ScaleAspectText::ScaleAspectText(int x, int y, SetVideoThread *thread, float *output)
464 : BC_TextBox(x, y, 70, 1, *output)
466 this->output = output;
467 this->thread = thread;
469 ScaleAspectText::~ScaleAspectText()
473 int ScaleAspectText::handle_event()
475 *output = atof(get_text());