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