Exciting new Alt/h help key provided by sge (Georgy) with many thanks!
[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  *
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[new_channels - 1],
155                 new_settings->session->achannel_positions,
156                 sizeof(mwindow->preferences->channel_positions[new_channels - 1]));
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         auto_aspect = 0;
179         window->auto_aspect->update(0);
180
181         constrain_ratio = 0;
182         dimension[0] = new_settings->session->output_w;
183         window->dimension[0]->update((int64_t)dimension[0]);
184         dimension[1] = new_settings->session->output_h;
185         window->dimension[1]->update((int64_t)dimension[1]);
186
187         ratio[0] = (float)dimension[0] / orig_dimension[0];
188         window->ratio[0]->update(ratio[0]);
189         ratio[1] = (float)dimension[1] / orig_dimension[1];
190         window->ratio[1]->update(ratio[1]);
191
192         window->aspect_w->update(new_settings->session->aspect_w);
193         window->aspect_h->update(new_settings->session->aspect_h);
194         window->interlace_pulldown->update(new_settings->session->interlace_mode);
195         window->color_model->update_value(new_settings->session->color_model);
196
197         window->canvas->draw();
198 }
199
200 void SetFormatThread::update_window()
201 {
202         int i, result, modified_item = 0, dimension_modified = 0, ratio_modified = 0;
203
204         for(i = 0, result = 0; i < 2 && !result; i++)
205         {
206                 if(dimension[i] < 0)
207                 {
208                         dimension[i] *= -1;
209                         result = 1;
210                         modified_item = i;
211                         dimension_modified = 1;
212                 }
213                 if(ratio[i] < 0)
214                 {
215                         ratio[i] *= -1;
216                         result = 1;
217                         modified_item = i;
218                         ratio_modified = 1;
219                 }
220         }
221
222         if(result)
223         {
224                 if(dimension_modified)
225                         ratio[modified_item] = (float)dimension[modified_item] / orig_dimension[modified_item];
226
227                 if(ratio_modified && !constrain_ratio)
228                 {
229                         dimension[modified_item] = (int)(orig_dimension[modified_item] * ratio[modified_item]);
230                         window->dimension[modified_item]->update((int64_t)dimension[modified_item]);
231                 }
232
233                 for(i = 0; i < 2; i++)
234                 {
235                         if(dimension_modified ||
236                                 (i != modified_item && ratio_modified))
237                         {
238                                 if(constrain_ratio) ratio[i] = ratio[modified_item];
239                                 window->ratio[i]->update(ratio[i]);
240                         }
241
242                         if(ratio_modified ||
243                                 (i != modified_item && dimension_modified))
244                         {
245                                 if(constrain_ratio)
246                                 {
247                                         dimension[i] = (int)(orig_dimension[i] * ratio[modified_item]);
248                                         window->dimension[i]->update((int64_t)dimension[i]);
249                                 }
250                         }
251                 }
252         }
253
254         update_aspect();
255 }
256
257 void SetFormatThread::update_aspect()
258 {
259         if(auto_aspect)
260         {
261                 char string[BCTEXTLEN];
262                 MWindow::create_aspect_ratio(new_settings->session->aspect_w,
263                         new_settings->session->aspect_h,
264                         dimension[0],
265                         dimension[1]);
266                 sprintf(string, "%.02f", new_settings->session->aspect_w);
267                 window->aspect_w->update(string);
268                 sprintf(string, "%.02f", new_settings->session->aspect_h);
269                 window->aspect_h->update(string);
270         }
271 }
272
273
274 SetFormatWindow::SetFormatWindow(MWindow *mwindow,
275         SetFormatThread *thread, int x, int y)
276  : BC_Window(_(PROGRAM_NAME ": Set Format"), x, y,
277         mwindow->theme->setformat_w, mwindow->theme->setformat_h,
278         -1, -1, 0, 0, 1)
279 {
280         this->mwindow = mwindow;
281         this->thread = thread;
282         presets = 0;
283 // *** CONTEXT_HELP ***
284         context_help_set_keyword("Project and Media Attributes");
285 }
286 SetFormatWindow::~SetFormatWindow()
287 {
288         delete presets;
289 }
290
291 void SetFormatWindow::create_objects()
292 {
293         lock_window("SetFormatWindow::create_objects");
294         int x = xS(10), y = mwindow->theme->setformat_y1;
295         BC_TextBox *textbox;
296         BC_Title *title;
297         mwindow->theme->draw_setformat_bg(this);
298
299         presets = new SetFormatPresets(mwindow, this, x, y);
300         presets->create_objects();
301         x = presets->x; //  y = presets->y;
302         y = mwindow->theme->setformat_y2;
303
304         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, y,
305                 _("Audio"), LARGEFONT));
306         y = mwindow->theme->setformat_y3;
307
308         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, y,
309                 _("Samplerate:")));
310         add_subwindow(sample_rate = new SetSampleRateTextBox(thread,
311                 mwindow->theme->setformat_x2,
312                 y));
313         add_subwindow(new SampleRatePulldown(mwindow, sample_rate,
314                 mwindow->theme->setformat_x2 + sample_rate->get_w(), y));
315
316         y += mwindow->theme->setformat_margin;
317         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, y,
318                 _("Channels:")));
319         add_subwindow(channels = new SetChannelsTextBox(thread,
320                 mwindow->theme->setformat_x2, y));
321         add_subwindow(new BC_ITumbler(channels, 0, MAXCHANNELS,
322                 mwindow->theme->setformat_x2 + channels->get_w(), y));
323
324         y += mwindow->theme->setformat_margin;
325         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, y,
326                 _("Channel positions:")));
327         y += mwindow->theme->setformat_margin;
328         add_subwindow(channels_reset = new SetChannelsReset(thread,
329                 mwindow->theme->setformat_x1, y,
330                 _("Reset")));
331         add_subwindow(canvas = new SetChannelsCanvas(mwindow,
332                 thread,
333                 mwindow->theme->setformat_channels_x,
334                 mwindow->theme->setformat_channels_y,
335                 mwindow->theme->setformat_channels_w,
336                 mwindow->theme->setformat_channels_h));
337         canvas->draw();
338
339
340
341         y = mwindow->theme->setformat_y2;
342         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
343                 y,
344                 _("Video"),
345                 LARGEFONT));
346
347         y = mwindow->theme->setformat_y3;
348         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
349                 y,
350                 _("Frame rate:")));
351         add_subwindow(frame_rate = new SetFrameRateTextBox(thread,
352                 mwindow->theme->setformat_x4,
353                 y));
354         add_subwindow(new FrameRatePulldown(mwindow,
355                 frame_rate,
356                 mwindow->theme->setformat_x4 + frame_rate->get_w(),
357                 y));
358
359         y += mwindow->theme->setformat_margin;
360         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
361                 y,
362                 _("Canvas size:")));
363
364         y += mwindow->theme->setformat_margin;
365         add_subwindow(title = new BC_Title(mwindow->theme->setformat_x3, y, _("Width:")));
366         add_subwindow(dimension[0] = new ScaleSizeText(mwindow->theme->setformat_x4,
367                 y,
368                 thread,
369                 &(thread->dimension[0])));
370
371         y += mwindow->theme->setformat_margin;
372         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, y, _("Height:")));
373         add_subwindow(dimension[1] = new ScaleSizeText(mwindow->theme->setformat_x4,
374                 y,
375                 thread,
376                 &(thread->dimension[1])));
377
378         x = mwindow->theme->setformat_x4 + dimension[0]->get_w();
379         FrameSizePulldown *pulldown;
380         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
381                 dimension[0],
382                 dimension[1],
383                 x,
384                 y - mwindow->theme->setformat_margin));
385
386         add_subwindow(new FormatSwapExtents(mwindow,
387                 thread,
388                 this,
389                 x + pulldown->get_w() + 5,
390                 y - mwindow->theme->setformat_margin));
391
392         y += mwindow->theme->setformat_margin;
393         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
394                 y,
395                 _("W Ratio:")));
396         add_subwindow(ratio[0] = new ScaleRatioText(mwindow->theme->setformat_x4,
397                 y,
398                 thread,
399                 &(thread->ratio[0])));
400
401         y += mwindow->theme->setformat_margin;
402         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
403                 y,
404                 _("H Ratio:")));
405         add_subwindow(ratio[1] = new ScaleRatioText(mwindow->theme->setformat_x4,
406                 y,
407                 thread,
408                 &(thread->ratio[1])));
409
410         y += mwindow->theme->setformat_margin;
411         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
412                 y,
413                 _("Color model:")));
414         x = mwindow->theme->setformat_x4;
415         add_subwindow(textbox = new BC_TextBox(x, y, xS(100), 1, ""));
416         x += textbox->get_w();
417         add_subwindow(color_model = new ColormodelPulldown(mwindow, textbox,
418                 &thread->new_settings->session->color_model, x, y));
419
420         y += mwindow->theme->setformat_margin;
421         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
422                 y,
423                 _("Aspect ratio:")));
424         y += mwindow->theme->setformat_margin;
425         x = mwindow->theme->setformat_x3;
426         add_subwindow(aspect_w = new ScaleAspectText(x, y, thread,
427                 &(thread->new_settings->session->aspect_w)));
428         x += aspect_w->get_w() + xS(5);
429         add_subwindow(new BC_Title(x, y, ":"));
430         x += xS(10);
431         add_subwindow(aspect_h = new ScaleAspectText(x,
432                 y,
433                 thread,
434                 &(thread->new_settings->session->aspect_h)));
435         x += aspect_h->get_w();
436         add_subwindow(new AspectPulldown(mwindow,
437                 aspect_w,
438                 aspect_h,
439                 x,
440                 y));
441         x += xS(30);
442         add_subwindow(auto_aspect = new ScaleAspectAuto(x, y, thread));
443         y += mwindow->theme->setformat_margin;
444
445         // --------------------
446         add_subwindow(new BC_Title(mwindow->theme->setformat_x3,
447                 y,
448                 _("Interlace mode:")));
449         add_subwindow(textbox = new BC_TextBox(mwindow->theme->setformat_x4, y,
450                 xS(140), 1, ""));
451         add_subwindow(interlace_pulldown = new InterlacemodePulldown(mwindow,
452                 textbox, &(thread->new_settings->session->interlace_mode),
453                 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_project_modes,
454                 mwindow->theme->setformat_x4 + textbox->get_w(), y));
455         y += mwindow->theme->setformat_margin;
456
457         BC_OKTextButton *ok;
458         BC_CancelTextButton *cancel;
459         add_subwindow(ok = new BC_OKTextButton(this));
460         add_subwindow(cancel = new BC_CancelTextButton(this));
461         add_subwindow(new SetFormatApply((ok->get_x() + cancel->get_x()) / 2,
462                 ok->get_y(), thread));
463         flash();
464         show_window();
465         unlock_window();
466 }
467
468 const char* SetFormatWindow::get_preset_text()
469 {
470         return "";
471 }
472
473
474 SetFormatPresets::SetFormatPresets(MWindow *mwindow,
475         SetFormatWindow *gui,
476         int x,
477         int y)
478  : FormatPresets(mwindow, 0, gui, x, y)
479 {
480
481 }
482
483 SetFormatPresets::~SetFormatPresets()
484 {
485 }
486
487 int SetFormatPresets::handle_event()
488 {
489         format_gui->thread->update();
490         return format_gui->channels_reset->handle_event();
491 }
492
493 EDL* SetFormatPresets::get_edl()
494 {
495         return format_gui->thread->new_settings;
496 }
497
498
499
500 SetSampleRateTextBox::SetSampleRateTextBox(SetFormatThread *thread, int x, int y)
501  : BC_TextBox(x, y, xS(100), 1, (int64_t)thread->new_settings->session->sample_rate)
502 {
503         this->thread = thread;
504 }
505 int SetSampleRateTextBox::handle_event()
506 {
507         thread->new_settings->session->sample_rate = CLIP(atol(get_text()), 1, 1000000);
508         return 1;
509 }
510
511 SetChannelsTextBox::SetChannelsTextBox(SetFormatThread *thread, int x, int y)
512  : BC_TextBox(x, y, xS(100), 1, thread->new_settings->session->audio_channels)
513 {
514         this->thread = thread;
515 }
516 int SetChannelsTextBox::handle_event()
517 {
518         int new_channels = CLIP(atoi(get_text()), 0, MAXCHANNELS);
519         thread->new_settings->session->audio_channels = new_channels;
520         if(new_channels > 0) {
521                 memcpy(thread->new_settings->session->achannel_positions,
522                         &thread->mwindow->preferences->channel_positions[new_channels - 1],
523                         sizeof(thread->new_settings->session->achannel_positions));
524         }
525
526         thread->window->canvas->draw();
527         return 1;
528 }
529
530 SetChannelsReset::SetChannelsReset(SetFormatThread *thread, int x, int y, const char *text)
531  : BC_GenericButton(x, y, text)
532 {
533         this->thread = thread;
534 }
535
536 int SetChannelsReset::handle_event()
537 {
538         int channels = thread->new_settings->session->audio_channels;
539         int *achannels = thread->new_settings->session->achannel_positions;
540         for( int i=0; i<MAX_CHANNELS; ++i )
541                 achannels[i] = default_audio_channel_position(i, channels);
542         thread->window->canvas->draw();
543         return 1;
544 }
545
546 SetChannelsCanvas::SetChannelsCanvas(MWindow *mwindow,
547         SetFormatThread *thread, int x, int y, int w, int h)
548  : BC_SubWindow(x, y, w, h)
549 {
550         this->thread = thread;
551         this->mwindow = mwindow;
552         active_channel = -1;
553         box_r = mwindow->theme->channel_position_data->get_w() / 2;
554         temp_picon = new VFrame(
555                 mwindow->theme->channel_position_data->get_w(),
556                 mwindow->theme->channel_position_data->get_h(),
557                 mwindow->theme->channel_position_data->get_color_model(),
558                 0);
559         rotater = new RotateFrame(mwindow->preferences->processors,
560                 mwindow->theme->channel_position_data->get_w(),
561                 mwindow->theme->channel_position_data->get_h());
562 }
563 SetChannelsCanvas::~SetChannelsCanvas()
564 {
565         delete temp_picon;
566         delete rotater;
567 }
568
569 int SetChannelsCanvas::draw(int angle)
570 {
571         set_color(RED);
572         //int real_w = get_w() - box_r * 2;
573         //int real_h = get_h() - box_r * 2;
574         //int real_x = box_r;
575         //int real_y = box_r;
576
577         draw_top_background(get_top_level(), 0, 0, get_w(), get_h());
578 //      draw_vframe(mwindow->theme->channel_bg_data, 0, 0);
579
580
581
582
583         int x, y, w, h;
584         char string[32];
585         set_color(mwindow->theme->channel_position_color);
586         for(int i = 0; i < thread->new_settings->session->audio_channels; i++)
587         {
588                 get_dimensions(thread->new_settings->session->achannel_positions[i],
589                         x, y, w, h);
590                 double rotate_angle = thread->new_settings->session->achannel_positions[i];
591                 rotate_angle = -rotate_angle;
592                 while(rotate_angle < 0) rotate_angle += 360;
593                 rotater->rotate(temp_picon,
594                         mwindow->theme->channel_position_data,
595                         rotate_angle,
596                         0);
597
598                 BC_Pixmap temp_pixmap(this,
599                         temp_picon,
600                         PIXMAP_ALPHA,
601                         0);
602                 draw_pixmap(&temp_pixmap, x, y);
603                 sprintf(string, "%d", i + 1);
604                 draw_text(x + 2, y + box_r * 2 - 2, string);
605         }
606
607         if(angle > -1)
608         {
609                 sprintf(string, _("%d degrees"), angle);
610                 draw_text(this->get_w() / 2 - 40, this->get_h() / 2, string);
611         }
612
613         flash();
614         return 0;
615 }
616
617 int SetChannelsCanvas::get_dimensions(int channel_position,
618                 int &x, int &y, int &w, int &h)
619 {
620         int xs10 = xS(10), ys10 = yS(10);
621         int real_w = this->get_w() - box_r * 2 - xs10;
622         int real_h = this->get_h() - box_r * 2 - ys10;
623         float corrected_position = channel_position;
624         if(corrected_position < 0) corrected_position += 360;
625         Units::polar_to_xy((float)corrected_position, real_w / 2, x, y);
626         x += real_w / 2 + xs10 / 2;
627         y += real_h / 2 + ys10 / 2;
628         w = box_r * 2;
629         h = box_r * 2;
630         return 0;
631 }
632
633 int SetChannelsCanvas::button_press_event()
634 {
635         if(!cursor_inside()) return 0;
636 // get active channel
637         for( int i = 0; i < thread->new_settings->session->audio_channels; i++ ) {
638                 int x, y, w, h;
639                 get_dimensions(thread->new_settings->session->achannel_positions[i], x, y, w, h);
640                 if( get_cursor_x() > x && get_cursor_y() > y &&
641                     get_cursor_x() < x + w && get_cursor_y() < y + h ) {
642                         active_channel = i;
643                         degree_offset = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
644                         degree_offset += 90;
645                         if(degree_offset >= 360) degree_offset -= 360;
646                         degree_offset -= thread->new_settings->session->achannel_positions[i];
647                         draw(thread->new_settings->session->achannel_positions[i]);
648                         return 1;
649                 }
650         }
651         return 0;
652 }
653
654 int SetChannelsCanvas::button_release_event()
655 {
656         if(active_channel >= 0)
657         {
658                 active_channel = -1;
659                 draw(-1);
660                 return 1;
661         }
662         return 0;
663 }
664
665 int SetChannelsCanvas::cursor_motion_event()
666 {
667         if(active_channel >= 0)
668         {
669 // get degrees of new channel
670                 int new_d;
671                 new_d = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
672                 new_d += 90;
673                 new_d -= degree_offset;
674
675                 while(new_d >= 360) new_d -= 360;
676                 while(new_d < 0) new_d += 360;
677
678                 if(thread->new_settings->session->achannel_positions[active_channel] != new_d)
679                 {
680                         thread->new_settings->session->achannel_positions[active_channel] = new_d;
681                         int new_channels = thread->new_settings->session->audio_channels;
682                         memcpy(&thread->mwindow->preferences->channel_positions[new_channels - 1],
683                                 thread->new_settings->session->achannel_positions,
684                                 sizeof(thread->mwindow->preferences->channel_positions[new_channels - 1]));
685                         draw(thread->new_settings->session->achannel_positions[active_channel]);
686                 }
687                 return 1;
688         }
689         return 0;
690 }
691
692
693 SetFrameRateTextBox::SetFrameRateTextBox(SetFormatThread *thread, int x, int y)
694  : BC_TextBox(x, y, xS(100), 1, (float)thread->new_settings->session->frame_rate)
695 {
696         this->thread = thread;
697 }
698
699 int SetFrameRateTextBox::handle_event()
700 {
701         thread->new_settings->session->frame_rate = Units::atoframerate(get_text());
702         return 1;
703 }
704
705
706 //
707 // SetVChannels::SetVChannels(SetFormatThread *thread, int x, int y)
708 //  : BC_TextBox(x, y, xS(100), 1, thread->channels)
709 // {
710 //      this->thread = thread;
711 // }
712 // int SetVChannels::handle_event()
713 // {
714 //      thread->channels = atol(get_text());
715 //      return 1;
716 // }
717
718
719
720
721 ScaleSizeText::ScaleSizeText(int x, int y, SetFormatThread *thread, int *output)
722  : BC_TextBox(x, y, xS(100), 1, *output)
723 {
724         this->thread = thread;
725         this->output = output;
726 }
727 ScaleSizeText::~ScaleSizeText()
728 {
729 }
730 int ScaleSizeText::handle_event()
731 {
732         *output = atol(get_text());
733         *output /= 2;  *output *= 2;
734         if(*output <= 0) *output = 2;
735         if(*output > 10000) *output = 10000;
736         *output *= -1;
737         thread->update_window();
738         return 1;
739 }
740
741
742
743 ScaleRatioText::ScaleRatioText(int x,
744         int y,
745         SetFormatThread *thread,
746         float *output)
747  : BC_TextBox(x, y, xS(100), 1, *output)
748 {
749         this->thread = thread;
750         this->output = output;
751 }
752 ScaleRatioText::~ScaleRatioText()
753 {
754 }
755 int ScaleRatioText::handle_event()
756 {
757         *output = atof(get_text());
758         //if(*output <= 0) *output = 1;
759         if(*output > 10000) *output = 10000;
760         if(*output < -10000) *output = -10000;
761         *output *= -1;
762         thread->update_window();
763         return 1;
764 }
765
766
767 ScaleAspectAuto::ScaleAspectAuto(int x, int y, SetFormatThread *thread)
768  : BC_CheckBox(x, y, thread->auto_aspect, _("Auto"))
769 {
770         this->thread = thread;
771 }
772
773 ScaleAspectAuto::~ScaleAspectAuto()
774 {
775 }
776
777 int ScaleAspectAuto::handle_event()
778 {
779         thread->auto_aspect = get_value();
780         thread->update_aspect();
781         return 1;
782 }
783
784 ScaleAspectText::ScaleAspectText(int x, int y, SetFormatThread *thread, float *output)
785  : BC_TextBox(x, y, xS(70), 1, *output)
786 {
787         this->output = output;
788         this->thread = thread;
789 }
790 ScaleAspectText::~ScaleAspectText()
791 {
792 }
793
794 int ScaleAspectText::handle_event()
795 {
796         *output = atof(get_text());
797         return 1;
798 }
799
800
801 SetFormatApply::SetFormatApply(int x, int y, SetFormatThread *thread)
802  : BC_GenericButton(x, y, _("Apply"))
803 {
804         this->thread = thread;
805 }
806
807 int SetFormatApply::handle_event()
808 {
809         thread->apply_changes();
810         return 1;
811 }
812
813
814 FormatSwapExtents::FormatSwapExtents(MWindow *mwindow,
815         SetFormatThread *thread,
816         SetFormatWindow *gui,
817         int x,
818         int y)
819  : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
820 {
821         this->mwindow = mwindow;
822         this->thread = thread;
823         this->gui = gui;
824         set_tooltip(_("Swap dimensions"));
825 }
826
827 int FormatSwapExtents::handle_event()
828 {
829         int w = thread->dimension[0];
830         int h = thread->dimension[1];
831         thread->dimension[0] = -h;
832         gui->dimension[0]->update((int64_t)h);
833         gui->dimension[1]->update((int64_t)w);
834         thread->update_window();
835         thread->dimension[1] = -w;
836         thread->update_window();
837         return 1;
838 }
839