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