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