initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / setformat.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5  * 
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.
10  * 
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.
15  * 
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
19  * 
20  */
21
22 #include "clip.h"
23 #include "cwindow.h"
24 #include "cwindowgui.h"
25 #include "datatype.h"
26 #include "bchash.h"
27 #include "edl.h"
28 #include "edlsession.h"
29 #include "formatpresets.h"
30 #include "language.h"
31 #include "levelwindow.h"
32 #include "levelwindowgui.h"
33 #include "mainerror.h"
34 #include "mainundo.h"
35 #include "mutex.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "new.h"
39 #include "preferences.h"
40 #include "rotateframe.h"
41 #include "setformat.h"
42 #include "theme.h"
43 #include "vframe.h"
44 #include "vwindow.h"
45 #include "vwindowgui.h"
46
47
48
49 SetFormat::SetFormat(MWindow *mwindow)
50  : BC_MenuItem(_("Format..."), "Shift-F", 'F')
51 {
52         set_shift(1); 
53         this->mwindow = mwindow;
54         thread = new SetFormatThread(mwindow);
55 }
56
57 SetFormat::~SetFormat()
58 {
59         delete thread;
60 }
61
62
63 int SetFormat::handle_event()
64 {
65         if(!thread->running())
66         {
67                 thread->start();
68         }
69         else
70         {
71 // window_lock has to be locked but window can't be locked until after
72 // it is known to exist, so we neglect window_lock for now
73                 if(thread->window)
74                 {
75                         thread->window_lock->lock("SetFormat::handle_event");
76                         thread->window->lock_window("SetFormat::handle_event");
77                         thread->window->raise_window();
78                         thread->window->unlock_window();
79                         thread->window_lock->unlock();
80                 }
81         }
82         return 1;
83 }
84
85 SetFormatThread::SetFormatThread(MWindow *mwindow)
86  : Thread(1, 0, 0)
87 {
88         this->mwindow = mwindow;
89         window_lock = new Mutex("SetFormatThread::window_lock");
90         window = 0;
91 }
92
93 SetFormatThread::~SetFormatThread()
94 {
95         if( running() ) {
96                 cancel();
97                 join();
98         }
99         delete window_lock;
100 }
101
102 void SetFormatThread::run()
103 {
104         orig_dimension[0] = dimension[0] = mwindow->edl->session->output_w;
105         orig_dimension[1] = dimension[1] = mwindow->edl->session->output_h;
106         auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
107         constrain_ratio = 0;
108         ratio[0] = ratio[1] = 1;
109
110         new_settings = new EDL;
111         new_settings->create_objects();
112         new_settings->copy_session(mwindow->edl);
113
114 // This locks mwindow, so it must be done outside window_lock
115         int x = mwindow->gui->get_abs_cursor_x(1) - mwindow->theme->setformat_w / 2;
116         int y = mwindow->gui->get_abs_cursor_y(1) - mwindow->theme->setformat_h / 2;
117
118         window_lock->lock("SetFormatThread::run 1");
119         window = new SetFormatWindow(mwindow, this, x, y);
120         window->create_objects();
121         window_lock->unlock();
122
123         int result = window->run_window();
124
125
126         window_lock->lock("SetFormatThread::run 2");
127         delete window;
128         window = 0;
129         window_lock->unlock();
130
131
132         if(!result)
133         {
134                 apply_changes();
135         }
136
137         mwindow->defaults->update("AUTOASPECT", auto_aspect);
138         new_settings->Garbage::remove_user();
139 }
140
141 void SetFormatThread::apply_changes()
142 {
143         double new_samplerate = new_settings->session->sample_rate;
144         double old_samplerate = mwindow->edl->session->sample_rate;
145         double new_framerate = new_settings->session->frame_rate;
146         double old_framerate = mwindow->edl->session->frame_rate;
147         int new_channels = new_settings->session->audio_channels;
148         CLAMP(new_channels, 1, MAXCHANNELS);
149
150
151
152         mwindow->undo->update_undo_before();
153
154         memcpy(&mwindow->preferences->channel_positions[MAXCHANNELS * (new_channels - 1)],
155                 new_settings->session->achannel_positions,
156                 sizeof(int) * MAXCHANNELS);
157
158
159         mwindow->edl->copy_session(new_settings, 1);
160         mwindow->edl->session->output_w = dimension[0];
161         mwindow->edl->session->output_h = dimension[1];
162         mwindow->edl->rechannel();
163         mwindow->edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
164         mwindow->edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
165         mwindow->save_backup();
166         mwindow->undo->update_undo_after(_("set format"), LOAD_ALL);
167
168         mwindow->resync_guis();
169 }
170
171 void SetFormatThread::update()
172 {
173         window->sample_rate->update(new_settings->session->sample_rate);
174         window->channels->update((int64_t)new_settings->session->audio_channels);
175         window->frame_rate->update((float)new_settings->session->frame_rate);
176
177         auto_aspect = 0;
178         window->auto_aspect->update(0);
179
180         constrain_ratio = 0;
181         dimension[0] = new_settings->session->output_w;
182         window->dimension[0]->update((int64_t)dimension[0]);
183         dimension[1] = new_settings->session->output_h;
184         window->dimension[1]->update((int64_t)dimension[1]);
185
186         ratio[0] = (float)dimension[0] / orig_dimension[0];
187         window->ratio[0]->update(ratio[0]);
188         ratio[1] = (float)dimension[1] / orig_dimension[1];
189         window->ratio[1]->update(ratio[1]);
190
191         window->aspect_w->update(new_settings->session->aspect_w);
192         window->aspect_h->update(new_settings->session->aspect_h);
193
194         window->canvas->draw();
195 }
196
197 void SetFormatThread::update_window()
198 {
199         int i, result, modified_item = 0, dimension_modified = 0, ratio_modified = 0;
200
201         for(i = 0, result = 0; i < 2 && !result; i++)
202         {
203                 if(dimension[i] < 0)
204                 {
205                         dimension[i] *= -1;
206                         result = 1;
207                         modified_item = i;
208                         dimension_modified = 1;
209                 }
210                 if(ratio[i] < 0)
211                 {
212                         ratio[i] *= -1;
213                         result = 1;
214                         modified_item = i;
215                         ratio_modified = 1;
216                 }
217         }
218
219         if(result)
220         {
221                 if(dimension_modified)
222                         ratio[modified_item] = (float)dimension[modified_item] / orig_dimension[modified_item];
223
224                 if(ratio_modified && !constrain_ratio)
225                 {
226                         dimension[modified_item] = (int)(orig_dimension[modified_item] * ratio[modified_item]);
227                         window->dimension[modified_item]->update((int64_t)dimension[modified_item]);
228                 }
229
230                 for(i = 0; i < 2; i++)
231                 {
232                         if(dimension_modified ||
233                                 (i != modified_item && ratio_modified))
234                         {
235                                 if(constrain_ratio) ratio[i] = ratio[modified_item];
236                                 window->ratio[i]->update(ratio[i]);
237                         }
238
239                         if(ratio_modified ||
240                                 (i != modified_item && dimension_modified))
241                         {
242                                 if(constrain_ratio) 
243                                 {
244                                         dimension[i] = (int)(orig_dimension[i] * ratio[modified_item]);
245                                         window->dimension[i]->update((int64_t)dimension[i]);
246                                 }
247                         }
248                 }
249         }
250
251         update_aspect();
252 }
253
254 void SetFormatThread::update_aspect()
255 {
256         if(auto_aspect)
257         {
258                 char string[BCTEXTLEN];
259                 MWindow::create_aspect_ratio(new_settings->session->aspect_w, 
260                         new_settings->session->aspect_h, 
261                         dimension[0], 
262                         dimension[1]);
263                 sprintf(string, "%.02f", new_settings->session->aspect_w);
264                 window->aspect_w->update(string);
265                 sprintf(string, "%.02f", new_settings->session->aspect_h);
266                 window->aspect_h->update(string);
267         }
268 }
269
270
271
272
273
274
275
276
277
278 SetFormatWindow::SetFormatWindow(MWindow *mwindow, 
279         SetFormatThread *thread,
280         int x,
281         int y)
282  : BC_Window(PROGRAM_NAME ": Set Format",
283         x,
284         y,
285         mwindow->theme->setformat_w,
286         mwindow->theme->setformat_h,
287         -1,
288         -1,
289         0,
290         0,
291         1)
292 {
293         this->mwindow = mwindow;
294         this->thread = thread;
295 }
296
297 void SetFormatWindow::create_objects()
298 {
299         int x = 10, y = mwindow->theme->setformat_y1;
300         BC_Title *title;
301
302         lock_window("SetFormatWindow::create_objects");
303         mwindow->theme->draw_setformat_bg(this);
304
305
306
307         presets = new SetFormatPresets(mwindow, 
308                 this, 
309                 x, 
310                 y);
311         presets->create_objects();
312         x = presets->x;
313         y = presets->y;
314
315         y = mwindow->theme->setformat_y2;
316
317         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
318                 y, 
319                 _("Audio"), 
320                 LARGEFONT));
321         y = mwindow->theme->setformat_y3;
322         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
323                 y,
324                 _("Samplerate:")));
325
326         y += mwindow->theme->setformat_margin;
327         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
328                 y,
329                 _("Samplerate:")));
330         add_subwindow(sample_rate = new SetSampleRateTextBox(thread, 
331                 mwindow->theme->setformat_x2, 
332                 y));
333         add_subwindow(new SampleRatePulldown(mwindow, 
334                 sample_rate, 
335                 mwindow->theme->setformat_x2 + sample_rate->get_w(), 
336                 y));
337
338         y += mwindow->theme->setformat_margin;
339         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
340                 y, 
341                 _("Channels:")));
342         add_subwindow(channels = new SetChannelsTextBox(thread, 
343                 mwindow->theme->setformat_x2, 
344                 y));
345         add_subwindow(new BC_ITumbler(channels, 
346                 1, 
347                 MAXCHANNELS, 
348                 mwindow->theme->setformat_x2 + channels->get_w(), 
349                 y));
350
351         y += mwindow->theme->setformat_margin;
352         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
353                 y, 
354                 _("Channel positions:")));
355         y += mwindow->theme->setformat_margin;
356         add_subwindow(canvas = new SetChannelsCanvas(mwindow, 
357                 thread, 
358                 mwindow->theme->setformat_channels_x, 
359                 mwindow->theme->setformat_channels_y, 
360                 mwindow->theme->setformat_channels_w, 
361                 mwindow->theme->setformat_channels_h));
362         canvas->draw();
363
364
365
366
367
368
369
370
371
372         y = mwindow->theme->setformat_y2;
373         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
374                 y, 
375                 _("Video"), 
376                 LARGEFONT));
377
378         y = mwindow->theme->setformat_y3;
379         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
380                 y, 
381                 _("Frame rate:")));
382         add_subwindow(frame_rate = new SetFrameRateTextBox(thread, 
383                 mwindow->theme->setformat_x4, 
384                 y));
385         add_subwindow(new FrameRatePulldown(mwindow, 
386                 frame_rate, 
387                 mwindow->theme->setformat_x4 + frame_rate->get_w(), 
388                 y));
389
390         y += mwindow->theme->setformat_margin;
391         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
392                 y, 
393                 _("Canvas size:")));
394
395         y += mwindow->theme->setformat_margin;
396         add_subwindow(title = new BC_Title(mwindow->theme->setformat_x3, y, _("Width:")));
397         add_subwindow(dimension[0] = new ScaleSizeText(mwindow->theme->setformat_x4, 
398                 y, 
399                 thread, 
400                 &(thread->dimension[0])));
401
402         y += mwindow->theme->setformat_margin;
403         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, y, _("Height:")));
404         add_subwindow(dimension[1] = new ScaleSizeText(mwindow->theme->setformat_x4, 
405                 y, 
406                 thread, 
407                 &(thread->dimension[1])));
408
409         x = mwindow->theme->setformat_x4 + dimension[0]->get_w();
410         FrameSizePulldown *pulldown;
411         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, 
412                 dimension[0], 
413                 dimension[1], 
414                 x, 
415                 y - mwindow->theme->setformat_margin));
416
417         add_subwindow(new FormatSwapExtents(mwindow, 
418                 thread, 
419                 this, 
420                 x + pulldown->get_w() + 5,
421                 y - mwindow->theme->setformat_margin));
422                 
423         y += mwindow->theme->setformat_margin;
424         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
425                 y, 
426                 _("W Ratio:")));
427         add_subwindow(ratio[0] = new ScaleRatioText(mwindow->theme->setformat_x4, 
428                 y, 
429                 thread, 
430                 &(thread->ratio[0])));
431
432         y += mwindow->theme->setformat_margin;
433         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
434                 y, 
435                 _("H Ratio:")));
436         add_subwindow(ratio[1] = new ScaleRatioText(mwindow->theme->setformat_x4, 
437                 y, 
438                 thread, 
439                 &(thread->ratio[1])));
440
441         y += mwindow->theme->setformat_margin;
442         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
443                 y, 
444                 _("Color model:")));
445         x = mwindow->theme->setformat_x4;
446         add_subwindow(color_model = new BC_TextBox(x, 
447                 y, 
448                 100, 
449                 1, 
450                 ""));
451         x += color_model->get_w();
452         add_subwindow(new ColormodelPulldown(mwindow, 
453                 color_model, 
454                 &thread->new_settings->session->color_model,
455                 x, 
456                 y));
457
458         y += mwindow->theme->setformat_margin;
459         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
460                 y, 
461                 _("Aspect ratio:")));
462         y += mwindow->theme->setformat_margin;
463         x = mwindow->theme->setformat_x3;
464         add_subwindow(aspect_w = new ScaleAspectText(x, 
465                 y, 
466                 thread, 
467                 &(thread->new_settings->session->aspect_w)));
468         x += aspect_w->get_w() + 5;
469         add_subwindow(new BC_Title(x, y, _(":")));
470         x += 10;
471         add_subwindow(aspect_h = new ScaleAspectText(x, 
472                 y, 
473                 thread, 
474                 &(thread->new_settings->session->aspect_h)));
475         x += aspect_h->get_w();
476         add_subwindow(new AspectPulldown(mwindow, 
477                 aspect_w, 
478                 aspect_h, 
479                 x, 
480                 y));
481         x += 30;
482         add_subwindow(auto_aspect = new ScaleAspectAuto(x, y, thread));
483
484
485
486         BC_OKTextButton *ok;
487         BC_CancelTextButton *cancel;
488         add_subwindow(ok = new BC_OKTextButton(this));
489         add_subwindow(cancel = new BC_CancelTextButton(this));
490         add_subwindow(new SetFormatApply((ok->get_x() + cancel->get_x()) / 2, 
491                 ok->get_y(), 
492                 thread));
493         flash();
494         show_window();
495         unlock_window();
496 }
497
498 const char* SetFormatWindow::get_preset_text()
499 {
500         return "";
501 }
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517 SetFormatPresets::SetFormatPresets(MWindow *mwindow, 
518         SetFormatWindow *gui, 
519         int x, 
520         int y)
521  : FormatPresets(mwindow, 0, gui, x, y)
522 {
523         
524 }
525
526 SetFormatPresets::~SetFormatPresets()
527 {
528 }
529
530 int SetFormatPresets::handle_event()
531 {
532         format_gui->thread->update();
533         return 1;
534 }
535
536 EDL* SetFormatPresets::get_edl()
537 {
538         return format_gui->thread->new_settings;
539 }
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 SetSampleRateTextBox::SetSampleRateTextBox(SetFormatThread *thread, int x, int y)
556  : BC_TextBox(x, y, 100, 1, (int64_t)thread->new_settings->session->sample_rate)
557 {
558         this->thread = thread;
559 }
560 int SetSampleRateTextBox::handle_event()
561 {
562         thread->new_settings->session->sample_rate = CLIP(atol(get_text()), 1, 1000000);
563         return 1;
564 }
565
566 SetChannelsTextBox::SetChannelsTextBox(SetFormatThread *thread, int x, int y)
567  : BC_TextBox(x, y, 100, 1, thread->new_settings->session->audio_channels)
568 {
569         this->thread = thread;
570 }
571 int SetChannelsTextBox::handle_event()
572 {
573         int new_channels = CLIP(atoi(get_text()), 1, MAXCHANNELS);
574         
575         thread->new_settings->session->audio_channels = new_channels;
576
577
578         if(new_channels > 0)
579         {
580                 memcpy(thread->new_settings->session->achannel_positions,
581                         &thread->mwindow->preferences->channel_positions[MAXCHANNELS * (new_channels - 1)],
582                         sizeof(int) * MAXCHANNELS);
583         }
584
585
586         thread->window->canvas->draw();
587         return 1;
588 }
589
590
591 SetChannelsCanvas::SetChannelsCanvas(MWindow *mwindow, 
592         SetFormatThread *thread, 
593         int x, 
594         int y,
595         int w,
596         int h)
597  : BC_SubWindow(x, 
598         y, 
599         w,
600         h)
601 {
602         this->thread = thread;
603         this->mwindow = mwindow;
604         active_channel = -1;
605         box_r = mwindow->theme->channel_position_data->get_w() / 2;
606         temp_picon = new VFrame(0, 
607                 -1,
608                 mwindow->theme->channel_position_data->get_w(),
609                 mwindow->theme->channel_position_data->get_h(),
610                 mwindow->theme->channel_position_data->get_color_model(),
611                 -1);
612         rotater = new RotateFrame(mwindow->preferences->processors,
613                 mwindow->theme->channel_position_data->get_w(),
614                 mwindow->theme->channel_position_data->get_h());
615 }
616 SetChannelsCanvas::~SetChannelsCanvas()
617 {
618         delete temp_picon;
619         delete rotater;
620 }
621
622 int SetChannelsCanvas::draw(int angle)
623 {
624         set_color(RED);
625         //int real_w = get_w() - box_r * 2;
626         //int real_h = get_h() - box_r * 2;
627         //int real_x = box_r;
628         //int real_y = box_r;
629
630         draw_top_background(get_top_level(), 0, 0, get_w(), get_h());
631 //      draw_vframe(mwindow->theme->channel_bg_data, 0, 0);
632
633
634
635
636         int x, y, w, h;
637         char string[32];
638         set_color(mwindow->theme->channel_position_color);
639         for(int i = 0; i < thread->new_settings->session->audio_channels; i++)
640         {
641                 get_dimensions(thread->new_settings->session->achannel_positions[i], 
642                         x, 
643                         y, 
644                         w, 
645                         h);
646                 double rotate_angle = thread->new_settings->session->achannel_positions[i];
647                 rotate_angle = -rotate_angle;
648                 while(rotate_angle < 0) rotate_angle += 360;
649                 rotater->rotate(temp_picon, 
650                         mwindow->theme->channel_position_data, 
651                         rotate_angle, 
652                         0);
653
654                 BC_Pixmap temp_pixmap(this, 
655                         temp_picon, 
656                         PIXMAP_ALPHA,
657                         0);
658                 draw_pixmap(&temp_pixmap, x, y);
659                 sprintf(string, "%d", i + 1);
660                 draw_text(x + 2, y + box_r * 2 - 2, string);
661         }
662
663         if(angle > -1)
664         {
665                 sprintf(string, _("%d degrees"), angle);
666                 draw_text(this->get_w() / 2 - 40, this->get_h() / 2, string);
667         }
668
669         flash();
670         return 0;
671 }
672
673 int SetChannelsCanvas::get_dimensions(int channel_position, 
674         int &x, 
675         int &y, 
676         int &w, 
677         int &h)
678 {
679 #define MARGIN 10
680         int real_w = this->get_w() - box_r * 2 - MARGIN;
681         int real_h = this->get_h() - box_r * 2 - MARGIN;
682         float corrected_position = channel_position;
683         if(corrected_position < 0) corrected_position += 360;
684         Units::polar_to_xy((float)corrected_position, real_w / 2, x, y);
685         x += real_w / 2 + MARGIN / 2;
686         y += real_h / 2 + MARGIN / 2;
687         w = box_r * 2;
688         h = box_r * 2;
689         return 0;
690 }
691
692 int SetChannelsCanvas::button_press_event()
693 {
694         if(!cursor_inside()) return 0;
695 // get active channel
696         for(int i = 0; 
697                 i < thread->new_settings->session->audio_channels; 
698                 i++)
699         {
700                 int x, y, w, h;
701                 get_dimensions(thread->new_settings->session->achannel_positions[i], 
702                         x, 
703                         y, 
704                         w, 
705                         h);
706                 if(get_cursor_x() > x && get_cursor_y() > y && 
707                         get_cursor_x() < x + w && get_cursor_y() < y + h)
708                 {
709                         active_channel = i;
710                         degree_offset = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
711                         degree_offset += 90;
712                         if(degree_offset >= 360) degree_offset -= 360;
713                         degree_offset -= thread->new_settings->session->achannel_positions[i];
714                         draw(thread->new_settings->session->achannel_positions[i]);
715                         return 1;
716                 }
717         }
718         return 0;
719 }
720
721 int SetChannelsCanvas::button_release_event()
722 {
723         if(active_channel >= 0)
724         {
725                 active_channel = -1;
726                 draw(-1);
727                 return 1;
728         }
729         return 0;
730 }
731
732 int SetChannelsCanvas::cursor_motion_event()
733 {
734         if(active_channel >= 0)
735         {
736 // get degrees of new channel
737                 int new_d;
738                 new_d = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
739                 new_d += 90;
740                 new_d -= degree_offset;
741
742                 while(new_d >= 360) new_d -= 360;
743                 while(new_d < 0) new_d += 360;
744
745                 if(thread->new_settings->session->achannel_positions[active_channel] != new_d)
746                 {
747                         thread->new_settings->session->achannel_positions[active_channel] = new_d;
748                         int new_channels = thread->new_settings->session->audio_channels;
749                         memcpy(&thread->mwindow->preferences->channel_positions[MAXCHANNELS * (new_channels - 1)],
750                                 thread->new_settings->session->achannel_positions,
751                                 sizeof(int) * MAXCHANNELS);
752                         draw(thread->new_settings->session->achannel_positions[active_channel]);
753                 }
754                 return 1;
755         }
756         return 0;
757 }
758
759
760
761
762
763
764
765
766
767 SetFrameRateTextBox::SetFrameRateTextBox(SetFormatThread *thread, int x, int y)
768  : BC_TextBox(x, y, 100, 1, (float)thread->new_settings->session->frame_rate)
769 {
770         this->thread = thread;
771 }
772
773 int SetFrameRateTextBox::handle_event()
774 {
775         thread->new_settings->session->frame_rate = Units::atoframerate(get_text());
776         return 1;
777 }
778
779
780 // 
781 // SetVChannels::SetVChannels(SetFormatThread *thread, int x, int y)
782 //  : BC_TextBox(x, y, 100, 1, thread->channels)
783 // {
784 //      this->thread = thread;
785 // }
786 // int SetVChannels::handle_event()
787 // {
788 //      thread->channels = atol(get_text());
789 //      return 1;
790 // }
791
792
793
794
795 ScaleSizeText::ScaleSizeText(int x, int y, SetFormatThread *thread, int *output)
796  : BC_TextBox(x, y, 100, 1, *output)
797
798         this->thread = thread; 
799         this->output = output; 
800 }
801 ScaleSizeText::~ScaleSizeText()
802 {
803 }
804 int ScaleSizeText::handle_event()
805 {
806         *output = atol(get_text());
807         *output /= 2;
808         *output *= 2;
809         if(*output <= 0) *output = 2;
810         if(*output > 10000) *output = 10000;
811         *output *= -1;
812         thread->update_window();
813         return 1;
814 }
815
816
817
818 ScaleRatioText::ScaleRatioText(int x, 
819         int y, 
820         SetFormatThread *thread, 
821         float *output)
822  : BC_TextBox(x, y, 100, 1, *output)
823
824         this->thread = thread; 
825         this->output = output; 
826 }
827 ScaleRatioText::~ScaleRatioText()
828 {
829 }
830 int ScaleRatioText::handle_event()
831 {
832         *output = atof(get_text());
833         //if(*output <= 0) *output = 1;
834         if(*output > 10000) *output = 10000;
835         if(*output < -10000) *output = -10000;
836         *output *= -1;
837         thread->update_window();
838         return 1;
839 }
840
841
842
843 ScaleAspectAuto::ScaleAspectAuto(int x, int y, SetFormatThread *thread)
844  : BC_CheckBox(x, y, thread->auto_aspect, _("Auto"))
845 {
846         this->thread = thread; 
847 }
848
849 ScaleAspectAuto::~ScaleAspectAuto()
850 {
851 }
852
853 int ScaleAspectAuto::handle_event()
854 {
855         thread->auto_aspect = get_value();
856         thread->update_aspect();
857         return 0;
858 }
859
860 ScaleAspectText::ScaleAspectText(int x, int y, SetFormatThread *thread, float *output)
861  : BC_TextBox(x, y, 70, 1, *output)
862 {
863         this->output = output;
864         this->thread = thread;
865 }
866 ScaleAspectText::~ScaleAspectText()
867 {
868 }
869
870 int ScaleAspectText::handle_event()
871 {
872         *output = atof(get_text());
873         return 1;
874 }
875
876
877
878
879
880
881 SetFormatApply::SetFormatApply(int x, int y, SetFormatThread *thread)
882  : BC_GenericButton(x, y, _("Apply"))
883 {
884         this->thread = thread;
885 }
886
887 int SetFormatApply::handle_event()
888 {
889         thread->apply_changes();
890         return 1;
891 }
892
893
894
895
896
897
898
899
900
901
902
903
904
905 FormatSwapExtents::FormatSwapExtents(MWindow *mwindow, 
906         SetFormatThread *thread,
907         SetFormatWindow *gui, 
908         int x, 
909         int y)
910  : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
911 {
912         this->mwindow = mwindow;
913         this->thread = thread;
914         this->gui = gui;
915         set_tooltip("Swap dimensions");
916 }
917
918 int FormatSwapExtents::handle_event()
919 {
920         int w = thread->dimension[0];
921         int h = thread->dimension[1];
922         thread->dimension[0] = -h;
923         gui->dimension[0]->update((int64_t)h);
924         gui->dimension[1]->update((int64_t)w);
925         thread->update_window();
926         thread->dimension[1] = -w;
927         thread->update_window();
928         return 1;
929 }
930
931
932
933