3 #include "cwindowgui.h"
7 #include "edlsession.h"
8 #include "formatpresets.h"
10 #include "levelwindow.h"
11 #include "levelwindowgui.h"
15 #include "mwindowgui.h"
17 #include "preferences.h"
18 #include "rotateframe.h"
19 #include "setformat.h"
23 #include "vwindowgui.h"
27 SetFormat::SetFormat(MWindow *mwindow)
28 : BC_MenuItem(_("Format..."), "Shift-F", 'F')
31 this->mwindow = mwindow;
32 thread = new SetFormatThread(mwindow);
35 int SetFormat::handle_event()
37 if(!thread->running())
43 // window_lock has to be locked but window can't be locked until after
44 // it is known to exist, so we neglect window_lock for now
47 thread->window_lock->lock("SetFormat::handle_event");
48 thread->window->lock_window("SetFormat::handle_event");
49 thread->window->raise_window();
50 thread->window->unlock_window();
51 thread->window_lock->unlock();
57 SetFormatThread::SetFormatThread(MWindow *mwindow)
60 this->mwindow = mwindow;
61 window_lock = new Mutex("SetFormatThread::window_lock");
65 void SetFormatThread::run()
67 orig_dimension[0] = dimension[0] = mwindow->edl->session->output_w;
68 orig_dimension[1] = dimension[1] = mwindow->edl->session->output_h;
69 auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
71 ratio[0] = ratio[1] = 1;
73 new_settings = new EDL;
74 new_settings->create_objects();
75 new_settings->copy_session(mwindow->edl);
77 // This locks mwindow, so it must be done outside window_lock
78 int x = mwindow->gui->get_abs_cursor_x(1) - mwindow->theme->setformat_w / 2;
79 int y = mwindow->gui->get_abs_cursor_y(1) - mwindow->theme->setformat_h / 2;
81 window_lock->lock("SetFormatThread::run 1");
82 window = new SetFormatWindow(mwindow, this, x, y);
83 window->create_objects();
84 window_lock->unlock();
86 int result = window->run_window();
89 window_lock->lock("SetFormatThread::run 2");
92 window_lock->unlock();
100 mwindow->defaults->update("AUTOASPECT", auto_aspect);
104 void SetFormatThread::apply_changes()
106 double new_samplerate = new_settings->session->sample_rate;
107 double old_samplerate = mwindow->edl->session->sample_rate;
108 double new_framerate = new_settings->session->frame_rate;
109 double old_framerate = mwindow->edl->session->frame_rate;
110 int new_channels = new_settings->session->audio_channels;
113 mwindow->edl->copy_session(new_settings);
114 mwindow->edl->session->output_w = dimension[0];
115 mwindow->edl->session->output_h = dimension[1];
116 mwindow->edl->rechannel();
117 mwindow->edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
118 mwindow->edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
119 mwindow->save_backup();
120 mwindow->undo->update_undo(_("set format"), LOAD_ALL);
123 mwindow->restart_brender();
124 mwindow->gui->lock_window("SetFormatThread::apply_changes");
125 mwindow->gui->update(1,
132 mwindow->gui->unlock_window();
134 mwindow->cwindow->gui->lock_window("SetFormatThread::apply_changes");
135 mwindow->cwindow->gui->resize_event(mwindow->cwindow->gui->get_w(),
136 mwindow->cwindow->gui->get_h());
137 mwindow->cwindow->gui->meters->set_meters(new_channels, 1);
138 mwindow->cwindow->gui->slider->set_position();
139 mwindow->cwindow->gui->flush();
140 mwindow->cwindow->gui->unlock_window();
142 mwindow->vwindow->gui->lock_window("SetFormatThread::apply_changes");
143 mwindow->vwindow->gui->resize_event(mwindow->vwindow->gui->get_w(),
144 mwindow->vwindow->gui->get_h());
145 mwindow->vwindow->gui->meters->set_meters(new_channels, 1);
146 mwindow->vwindow->gui->flush();
147 mwindow->vwindow->gui->unlock_window();
149 mwindow->lwindow->gui->lock_window("SetFormatThread::apply_changes");
150 mwindow->lwindow->gui->panel->set_meters(new_channels, 1);
151 mwindow->lwindow->gui->flush();
152 mwindow->lwindow->gui->unlock_window();
155 mwindow->sync_parameters(CHANGE_ALL);
158 void SetFormatThread::update()
160 window->sample_rate->update(new_settings->session->sample_rate);
161 window->channels->update((int64_t)new_settings->session->audio_channels);
162 window->frame_rate->update((float)new_settings->session->frame_rate);
165 window->auto_aspect->update(0);
168 dimension[0] = new_settings->session->output_w;
169 window->dimension[0]->update((int64_t)dimension[0]);
170 dimension[1] = new_settings->session->output_h;
171 window->dimension[1]->update((int64_t)dimension[1]);
173 ratio[0] = (float)dimension[0] / orig_dimension[0];
174 window->ratio[0]->update(ratio[0]);
175 ratio[1] = (float)dimension[1] / orig_dimension[1];
176 window->ratio[1]->update(ratio[1]);
178 window->aspect_w->update(new_settings->session->aspect_w);
179 window->aspect_h->update(new_settings->session->aspect_h);
181 window->canvas->draw();
184 void SetFormatThread::update_window()
186 int i, result, modified_item, dimension_modified = 0, ratio_modified = 0;
188 for(i = 0, result = 0; i < 2 && !result; i++)
195 dimension_modified = 1;
208 if(dimension_modified)
209 ratio[modified_item] = (float)dimension[modified_item] / orig_dimension[modified_item];
211 if(ratio_modified && !constrain_ratio)
213 dimension[modified_item] = (int)(orig_dimension[modified_item] * ratio[modified_item]);
214 window->dimension[modified_item]->update((int64_t)dimension[modified_item]);
217 for(i = 0; i < 2; i++)
219 if(dimension_modified ||
220 (i != modified_item && ratio_modified))
222 if(constrain_ratio) ratio[i] = ratio[modified_item];
223 window->ratio[i]->update(ratio[i]);
227 (i != modified_item && dimension_modified))
231 dimension[i] = (int)(orig_dimension[i] * ratio[modified_item]);
232 window->dimension[i]->update((int64_t)dimension[i]);
241 void SetFormatThread::update_aspect()
245 char string[BCTEXTLEN];
246 MWindow::create_aspect_ratio(new_settings->session->aspect_w,
247 new_settings->session->aspect_h,
250 sprintf(string, "%.02f", new_settings->session->aspect_w);
251 window->aspect_w->update(string);
252 sprintf(string, "%.02f", new_settings->session->aspect_h);
253 window->aspect_h->update(string);
265 SetFormatWindow::SetFormatWindow(MWindow *mwindow,
266 SetFormatThread *thread,
269 : BC_Window(PROGRAM_NAME ": Set Format",
272 mwindow->theme->setformat_w,
273 mwindow->theme->setformat_h,
280 this->mwindow = mwindow;
281 this->thread = thread;
284 void SetFormatWindow::create_objects()
286 int x = 10, y = mwindow->theme->setformat_y1;
290 mwindow->theme->draw_setformat_bg(this);
294 presets = new SetFormatPresets(mwindow,
298 presets->create_objects();
302 y = mwindow->theme->setformat_y2;
304 add_subwindow(new BC_Title(mwindow->theme->setformat_x1,
308 y = mwindow->theme->setformat_y3;
309 add_subwindow(new BC_Title(mwindow->theme->setformat_x1,
313 y += mwindow->theme->setformat_margin;
314 add_subwindow(new BC_Title(mwindow->theme->setformat_x1,
317 add_subwindow(sample_rate = new SetSampleRateTextBox(thread,
318 mwindow->theme->setformat_x2,
320 add_subwindow(new SampleRatePulldown(mwindow,
322 mwindow->theme->setformat_x2 + sample_rate->get_w(),
325 y += mwindow->theme->setformat_margin;
326 add_subwindow(new BC_Title(mwindow->theme->setformat_x1,
329 add_subwindow(channels = new SetChannelsTextBox(thread,
330 mwindow->theme->setformat_x2,
332 add_subwindow(new BC_ITumbler(channels,
335 mwindow->theme->setformat_x2 + channels->get_w(),
338 y += mwindow->theme->setformat_margin;
339 add_subwindow(new BC_Title(mwindow->theme->setformat_x1,
341 _("Channel positions:")));
342 y += mwindow->theme->setformat_margin;
343 add_subwindow(canvas = new SetChannelsCanvas(mwindow,
345 mwindow->theme->setformat_channels_x,
346 mwindow->theme->setformat_channels_y,
347 mwindow->theme->setformat_channels_w,
348 mwindow->theme->setformat_channels_h));
359 y = mwindow->theme->setformat_y2;
360 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
365 y = mwindow->theme->setformat_y3;
366 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
369 add_subwindow(frame_rate = new SetFrameRateTextBox(thread,
370 mwindow->theme->setformat_x4,
372 add_subwindow(new FrameRatePulldown(mwindow,
374 mwindow->theme->setformat_x4 + frame_rate->get_w(),
377 y += mwindow->theme->setformat_margin;
378 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
382 y += mwindow->theme->setformat_margin;
383 add_subwindow(new BC_Title(mwindow->theme->setformat_x3, y, _("Width:")));
384 add_subwindow(dimension[0] = new ScaleSizeText(mwindow->theme->setformat_x4,
387 &(thread->dimension[0])));
389 y += mwindow->theme->setformat_margin;
390 add_subwindow(new BC_Title(mwindow->theme->setformat_x3, y, _("Height:")));
391 add_subwindow(dimension[1] = new ScaleSizeText(mwindow->theme->setformat_x4,
394 &(thread->dimension[1])));
395 add_subwindow(new FrameSizePulldown(mwindow,
398 mwindow->theme->setformat_x4 + dimension[0]->get_w(),
399 y - mwindow->theme->setformat_margin));
401 y += mwindow->theme->setformat_margin;
402 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
405 add_subwindow(ratio[0] = new ScaleRatioText(mwindow->theme->setformat_x4,
408 &(thread->ratio[0])));
410 y += mwindow->theme->setformat_margin;
411 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
414 add_subwindow(ratio[1] = new ScaleRatioText(mwindow->theme->setformat_x4,
417 &(thread->ratio[1])));
419 y += mwindow->theme->setformat_margin;
420 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
423 x = mwindow->theme->setformat_x4;
424 add_subwindow(color_model = new BC_TextBox(x,
429 x += color_model->get_w();
430 add_subwindow(new ColormodelPulldown(mwindow,
432 &thread->new_settings->session->color_model,
436 y += mwindow->theme->setformat_margin;
437 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
439 _("Aspect ratio:")));
440 y += mwindow->theme->setformat_margin;
441 x = mwindow->theme->setformat_x3;
442 add_subwindow(aspect_w = new ScaleAspectText(x,
445 &(thread->new_settings->session->aspect_w)));
446 x += aspect_w->get_w() + 5;
447 add_subwindow(new BC_Title(x, y, _(":")));
449 add_subwindow(aspect_h = new ScaleAspectText(x,
452 &(thread->new_settings->session->aspect_h)));
453 x += aspect_h->get_w();
454 add_subwindow(new AspectPulldown(mwindow,
460 add_subwindow(auto_aspect = new ScaleAspectAuto(x, y, thread));
461 y += mwindow->theme->setformat_margin;
463 // --------------------
464 add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
466 _("Interlace mode:")));
467 add_subwindow(textbox = new BC_TextBox(mwindow->theme->setformat_x4,
472 add_subwindow(new InterlacemodePulldown(mwindow,
474 &(thread->new_settings->session->interlace_mode),
475 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
476 mwindow->theme->setformat_x4 + textbox->get_w(),
478 y += mwindow->theme->setformat_margin;
482 BC_CancelTextButton *cancel;
483 add_subwindow(ok = new BC_OKTextButton(this));
484 add_subwindow(cancel = new BC_CancelTextButton(this));
485 add_subwindow(new SetFormatApply((ok->get_x() + cancel->get_x()) / 2,
492 char* SetFormatWindow::get_preset_text()
511 SetFormatPresets::SetFormatPresets(MWindow *mwindow,
512 SetFormatWindow *gui,
515 : FormatPresets(mwindow, 0, gui, x, y)
520 SetFormatPresets::~SetFormatPresets()
524 int SetFormatPresets::handle_event()
526 format_gui->thread->update();
530 EDL* SetFormatPresets::get_edl()
532 return format_gui->thread->new_settings;
549 SetSampleRateTextBox::SetSampleRateTextBox(SetFormatThread *thread, int x, int y)
550 : BC_TextBox(x, y, 100, 1, (int64_t)thread->new_settings->session->sample_rate)
552 this->thread = thread;
554 int SetSampleRateTextBox::handle_event()
556 thread->new_settings->session->sample_rate = CLIP(atol(get_text()), 1, 1000000);
560 SetChannelsTextBox::SetChannelsTextBox(SetFormatThread *thread, int x, int y)
561 : BC_TextBox(x, y, 100, 1, thread->new_settings->session->audio_channels)
563 this->thread = thread;
565 int SetChannelsTextBox::handle_event()
567 thread->new_settings->session->audio_channels = CLIP(atol(get_text()), 1, MAXCHANNELS - 1);
568 thread->window->canvas->draw();
573 SetChannelsCanvas::SetChannelsCanvas(MWindow *mwindow,
574 SetFormatThread *thread,
584 this->thread = thread;
585 this->mwindow = mwindow;
587 box_r = mwindow->theme->channel_position_data->get_w() / 2;
588 temp_picon = new VFrame(0,
589 mwindow->theme->channel_position_data->get_w(),
590 mwindow->theme->channel_position_data->get_h(),
591 mwindow->theme->channel_position_data->get_color_model());
592 rotater = new RotateFrame(mwindow->preferences->processors,
593 mwindow->theme->channel_position_data->get_w(),
594 mwindow->theme->channel_position_data->get_h());
596 SetChannelsCanvas::~SetChannelsCanvas()
602 int SetChannelsCanvas::draw(int angle)
605 int real_w = get_w() - box_r * 2;
606 int real_h = get_h() - box_r * 2;
610 draw_top_background(get_top_level(), 0, 0, get_w(), get_h());
611 // draw_vframe(mwindow->theme->channel_bg_data, 0, 0);
618 set_color(mwindow->theme->channel_position_color);
619 for(int i = 0; i < thread->new_settings->session->audio_channels; i++)
621 get_dimensions(thread->new_settings->session->achannel_positions[i],
626 double rotate_angle = thread->new_settings->session->achannel_positions[i];
627 rotate_angle = -rotate_angle;
628 while(rotate_angle < 0) rotate_angle += 360;
629 rotater->rotate(temp_picon,
630 mwindow->theme->channel_position_data,
634 BC_Pixmap temp_pixmap(this,
638 draw_pixmap(&temp_pixmap, x, y);
639 sprintf(string, "%d", i + 1);
640 draw_text(x + 2, y + box_r * 2 - 2, string);
645 sprintf(string, _("%d degrees"), angle);
646 draw_text(this->get_w() / 2 - 40, this->get_h() / 2, string);
653 int SetChannelsCanvas::get_dimensions(int channel_position,
660 int real_w = this->get_w() - box_r * 2 - MARGIN;
661 int real_h = this->get_h() - box_r * 2 - MARGIN;
662 float corrected_position = channel_position;
663 if(corrected_position < 0) corrected_position += 360;
664 Units::polar_to_xy((float)corrected_position, real_w / 2, x, y);
665 x += real_w / 2 + MARGIN / 2;
666 y += real_h / 2 + MARGIN / 2;
672 int SetChannelsCanvas::button_press_event()
674 if(!cursor_inside()) return 0;
675 // get active channel
677 i < thread->new_settings->session->audio_channels;
681 get_dimensions(thread->new_settings->session->achannel_positions[i],
686 if(get_cursor_x() > x && get_cursor_y() > y &&
687 get_cursor_x() < x + w && get_cursor_y() < y + h)
690 degree_offset = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
692 if(degree_offset >= 360) degree_offset -= 360;
693 degree_offset -= thread->new_settings->session->achannel_positions[i];
694 draw(thread->new_settings->session->achannel_positions[i]);
701 int SetChannelsCanvas::button_release_event()
703 if(active_channel >= 0)
712 int SetChannelsCanvas::cursor_motion_event()
714 if(active_channel >= 0)
716 // get degrees of new channel
718 new_d = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
720 new_d -= degree_offset;
722 while(new_d >= 360) new_d -= 360;
723 while(new_d < 0) new_d += 360;
725 if(thread->new_settings->session->achannel_positions[active_channel] != new_d)
727 thread->new_settings->session->achannel_positions[active_channel] = new_d;
728 draw(thread->new_settings->session->achannel_positions[active_channel]);
743 SetFrameRateTextBox::SetFrameRateTextBox(SetFormatThread *thread, int x, int y)
744 : BC_TextBox(x, y, 100, 1, (float)thread->new_settings->session->frame_rate)
746 this->thread = thread;
749 int SetFrameRateTextBox::handle_event()
751 thread->new_settings->session->frame_rate = Units::atoframerate(get_text());
757 // SetVChannels::SetVChannels(SetFormatThread *thread, int x, int y)
758 // : BC_TextBox(x, y, 100, 1, thread->channels)
760 // this->thread = thread;
762 // int SetVChannels::handle_event()
764 // thread->channels = atol(get_text());
771 ScaleSizeText::ScaleSizeText(int x, int y, SetFormatThread *thread, int *output)
772 : BC_TextBox(x, y, 100, 1, *output)
774 this->thread = thread;
775 this->output = output;
777 ScaleSizeText::~ScaleSizeText()
780 int ScaleSizeText::handle_event()
782 *output = atol(get_text());
785 if(*output <= 0) *output = 2;
786 if(*output > 10000) *output = 10000;
788 thread->update_window();
793 ScaleRatioText::ScaleRatioText(int x,
795 SetFormatThread *thread,
797 : BC_TextBox(x, y, 100, 1, *output)
799 this->thread = thread;
800 this->output = output;
802 ScaleRatioText::~ScaleRatioText()
805 int ScaleRatioText::handle_event()
807 *output = atof(get_text());
808 //if(*output <= 0) *output = 1;
809 if(*output > 10000) *output = 10000;
810 if(*output < -10000) *output = -10000;
812 thread->update_window();
818 ScaleAspectAuto::ScaleAspectAuto(int x, int y, SetFormatThread *thread)
819 : BC_CheckBox(x, y, thread->auto_aspect, _("Auto"))
821 this->thread = thread;
824 ScaleAspectAuto::~ScaleAspectAuto()
828 int ScaleAspectAuto::handle_event()
830 thread->auto_aspect = get_value();
831 thread->update_aspect();
834 ScaleAspectText::ScaleAspectText(int x, int y, SetFormatThread *thread, float *output)
835 : BC_TextBox(x, y, 70, 1, *output)
837 this->output = output;
838 this->thread = thread;
840 ScaleAspectText::~ScaleAspectText()
844 int ScaleAspectText::handle_event()
846 *output = atof(get_text());
853 SetFormatApply::SetFormatApply(int x, int y, SetFormatThread *thread)
854 : BC_GenericButton(x, y, _("Apply"))
856 this->thread = thread;
859 int SetFormatApply::handle_event()
861 thread->apply_changes();