title color fader/tweaks, bg_color bcbitmap fix, inst.sh fix, lang fr pref tweaks
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / zoombar.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 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 "apatchgui.inc"
23 #include "clip.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "language.h"
27 #include "localsession.h"
28 #include "maincursor.h"
29 #include "mwindow.h"
30 #include "mwindowgui.h"
31 #include "mainsession.h"
32 #include "mtimebar.h"
33 #include "preferences.h"
34 #include "theme.h"
35 #include "trackcanvas.h"
36 #include "tracks.h"
37 #include "units.h"
38 #include "vpatchgui.inc"
39 #include "zoombar.h"
40
41
42 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
43  : BC_SubWindow(mwindow->theme->mzoom_x,
44         mwindow->theme->mzoom_y,
45         mwindow->theme->mzoom_w,
46         mwindow->theme->mzoom_h)
47 {
48         this->gui = gui;
49         this->mwindow = mwindow;
50 }
51
52 ZoomBar::~ZoomBar()
53 {
54         delete sample_zoom;
55         delete amp_zoom;
56         delete track_zoom;
57 }
58
59 void ZoomBar::create_objects()
60 {
61         int x = 3;
62         int y = get_h() / 2 -
63                 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
64
65         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
66         sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
67         sample_zoom->create_objects();
68         sample_zoom->set_tooltip(_("Duration visible in the timeline"));
69         x += sample_zoom->get_w();
70         amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
71         amp_zoom->create_objects();
72         amp_zoom->set_tooltip(_("Audio waveform scale"));
73         x += amp_zoom->get_w();
74         track_zoom = new TrackZoomPanel(mwindow, this, x, y);
75         track_zoom->create_objects();
76         track_zoom->set_tooltip(_("Height of tracks in the timeline"));
77         x += track_zoom->get_w() + 10;
78
79         int wid = 120;
80         for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
81                 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
82                 if( ww > wid ) wid = ww;
83         }
84         add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
85         auto_type->create_objects();
86         x += auto_type->get_w() + 10;
87 #define DEFAULT_TEXT "000.00 to 000.00"
88         add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
89         x += auto_zoom->get_w();
90         add_subwindow(auto_zoom_text = new ZoomTextBox(
91                 mwindow,
92                 this,
93                 x,
94                 y,
95                 DEFAULT_TEXT));
96         x += auto_zoom_text->get_w() + 5;
97         add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
98         update_autozoom();
99         x += auto_zoom->get_w() + 5;
100
101         add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
102         x += from_value->get_w() + 5;
103         add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
104         x += length_value->get_w() + 5;
105         add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
106         x += to_value->get_w() + 5;
107         add_subwindow(title_alpha = new TitleBarAlpha(mwindow, this, x, y));
108
109         update_formatting(from_value);
110         update_formatting(length_value);
111         update_formatting(to_value);
112
113         update();
114 }
115
116
117 void ZoomBar::update_formatting(BC_TextBox *dst)
118 {
119         dst->set_separators(
120                 Units::format_to_separators(mwindow->edl->session->time_format));
121 }
122
123 void ZoomBar::resize_event()
124 {
125         reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
126                 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
127         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
128 }
129
130 void ZoomBar::redraw_time_dependancies()
131 {
132 // Recalculate sample zoom menu
133         sample_zoom->update_menu();
134         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
135         update_formatting(from_value);
136         update_formatting(length_value);
137         update_formatting(to_value);
138         update_autozoom();
139         update_clocks();
140 }
141
142 int ZoomBar::draw()
143 {
144         update();
145         return 0;
146 }
147
148 void ZoomBar::update_autozoom()
149 {
150         char string[BCTEXTLEN];
151         int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
152         switch( autogroup_type ) {
153         case AUTOGROUPTYPE_AUDIO_FADE:
154         case AUTOGROUPTYPE_VIDEO_FADE:
155                 sprintf(string, "%0.01f to %0.01f\n",
156                         mwindow->edl->local_session->automation_mins[autogroup_type],
157                         mwindow->edl->local_session->automation_maxs[autogroup_type]);
158                 break;
159         case AUTOGROUPTYPE_ZOOM:
160         case AUTOGROUPTYPE_SPEED:
161                 sprintf(string, "%0.03f to %0.03f\n",
162                         mwindow->edl->local_session->automation_mins[autogroup_type],
163                         mwindow->edl->local_session->automation_maxs[autogroup_type]);
164                 break;
165         case AUTOGROUPTYPE_X:
166         case AUTOGROUPTYPE_Y:
167                 sprintf(string, "%0.0f to %.0f\n",
168                         mwindow->edl->local_session->automation_mins[autogroup_type],
169                         mwindow->edl->local_session->automation_maxs[autogroup_type]);
170                 break;
171         }
172         auto_zoom_text->update(string);
173         const char *group_name = AutoTypeMenu::to_text(autogroup_type);
174         auto_type->set_text(group_name);
175 }
176
177 int ZoomBar::update()
178 {
179         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
180         amp_zoom->update(mwindow->edl->local_session->zoom_y);
181         track_zoom->update(mwindow->edl->local_session->zoom_track);
182         update_autozoom();
183         update_clocks();
184         return 0;
185 }
186
187 int ZoomBar::update_clocks()
188 {
189         from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
190         length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
191                 mwindow->edl->local_session->get_selectionstart(1));
192         to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
193         return 0;
194 }
195
196 TitleBarAlpha::TitleBarAlpha(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
197  : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, mwindow->session->title_bar_alpha, 0)
198 {
199         this->mwindow = mwindow;
200         this->zoombar = zoombar;
201         set_precision(0.01);
202         set_tooltip(_("TitleBar Alpha"));
203 }
204
205 int TitleBarAlpha::handle_event()
206 {
207         mwindow->session->title_bar_alpha = get_value();
208         mwindow->gui->draw_trackmovement();
209         mwindow->gui->flush();
210         return 1;
211 }
212
213 int ZoomBar::resize_event(int w, int h)
214 {
215 // don't change anything but y and width
216         reposition_window(0, h - this->get_h(), w, this->get_h());
217         return 0;
218 }
219
220
221 // Values for which_one
222 #define SET_FROM 1
223 #define SET_LENGTH 2
224 #define SET_TO 3
225
226
227 int ZoomBar::set_selection(int which_one)
228 {
229         double start_position = mwindow->edl->local_session->get_selectionstart(1);
230         double end_position = mwindow->edl->local_session->get_selectionend(1);
231         double length = end_position - start_position;
232
233 // Fix bogus results
234
235         switch(which_one)
236         {
237                 case SET_LENGTH:
238                         start_position = Units::text_to_seconds(from_value->get_text(),
239                                 mwindow->edl->session->sample_rate,
240                                 mwindow->edl->session->time_format,
241                                 mwindow->edl->session->frame_rate,
242                                 mwindow->edl->session->frames_per_foot);
243                         length = Units::text_to_seconds(length_value->get_text(),
244                                 mwindow->edl->session->sample_rate,
245                                 mwindow->edl->session->time_format,
246                                 mwindow->edl->session->frame_rate,
247                                 mwindow->edl->session->frames_per_foot);
248                         end_position = start_position + length;
249
250                         if(end_position < start_position)
251                         {
252                                 start_position = end_position;
253                                 mwindow->edl->local_session->set_selectionend(
254                                         mwindow->edl->local_session->get_selectionstart(1));
255                         }
256                         break;
257
258                 case SET_FROM:
259                         start_position = Units::text_to_seconds(from_value->get_text(),
260                                 mwindow->edl->session->sample_rate,
261                                 mwindow->edl->session->time_format,
262                                 mwindow->edl->session->frame_rate,
263                                 mwindow->edl->session->frames_per_foot);
264                         end_position = Units::text_to_seconds(to_value->get_text(),
265                                 mwindow->edl->session->sample_rate,
266                                 mwindow->edl->session->time_format,
267                                 mwindow->edl->session->frame_rate,
268                                 mwindow->edl->session->frames_per_foot);
269
270                         if(end_position < start_position)
271                         {
272                                 end_position = start_position;
273                                 mwindow->edl->local_session->set_selectionend(
274                                         mwindow->edl->local_session->get_selectionstart(1));
275                         }
276                         break;
277
278                 case SET_TO:
279                         start_position = Units::text_to_seconds(from_value->get_text(),
280                                 mwindow->edl->session->sample_rate,
281                                 mwindow->edl->session->time_format,
282                                 mwindow->edl->session->frame_rate,
283                                 mwindow->edl->session->frames_per_foot);
284                         end_position = Units::text_to_seconds(to_value->get_text(),
285                                 mwindow->edl->session->sample_rate,
286                                 mwindow->edl->session->time_format,
287                                 mwindow->edl->session->frame_rate,
288                                 mwindow->edl->session->frames_per_foot);
289
290                         if(end_position < start_position)
291                         {
292                                 start_position = end_position;
293                                 mwindow->edl->local_session->set_selectionend(
294                                         mwindow->edl->local_session->get_selectionstart(1));
295                         }
296                         break;
297         }
298
299         mwindow->edl->local_session->set_selectionstart(
300                 mwindow->edl->align_to_frame(start_position, 1));
301         mwindow->edl->local_session->set_selectionend(
302                 mwindow->edl->align_to_frame(end_position, 1));
303
304
305         mwindow->gui->update_timebar_highlights();
306         mwindow->gui->hide_cursor(1);
307         mwindow->gui->show_cursor(1);
308         update();
309         mwindow->sync_parameters(CHANGE_PARAMS);
310         mwindow->gui->flash_canvas(1);
311
312         return 0;
313 }
314
315
316
317
318
319
320
321
322
323
324
325
326 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
327  : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
328                 x, y, 110, MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
329 {
330         this->mwindow = mwindow;
331         this->zoombar = zoombar;
332 }
333 int SampleZoomPanel::handle_event()
334 {
335         mwindow->zoom_sample((int64_t)get_value());
336         return 1;
337 }
338
339
340 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
341  : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
342                 x, y, 80, MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
343 {
344         this->mwindow = mwindow;
345         this->zoombar = zoombar;
346 }
347 int AmpZoomPanel::handle_event()
348 {
349         mwindow->zoom_amp((int64_t)get_value());
350         return 1;
351 }
352
353 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
354  : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
355                 x, y, 70, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
356 {
357         this->mwindow = mwindow;
358         this->zoombar = zoombar;
359 }
360 int TrackZoomPanel::handle_event()
361 {
362         mwindow->zoom_track((int64_t)get_value());
363         zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
364         return 1;
365 }
366
367
368
369
370 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
371  : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
372 {
373         this->mwindow = mwindow;
374         this->zoombar = zoombar;
375         this->changemax = changemax;
376         if (changemax)
377                 set_tooltip(_("Automation range maximum"));
378         else
379                 set_tooltip(_("Automation range minimum"));
380 }
381
382 int AutoZoom::handle_up_event()
383 {
384         mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
385
386         mwindow->gui->zoombar->update_autozoom();
387         mwindow->gui->draw_overlays(0);
388         mwindow->gui->update_patchbay();
389         mwindow->gui->flash_canvas(1);
390         return 1;
391 }
392
393 int AutoZoom::handle_down_event()
394 {
395         mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
396
397         mwindow->gui->zoombar->update_autozoom();
398         mwindow->gui->draw_overlays(0);
399         mwindow->gui->update_patchbay();
400         mwindow->gui->flash_canvas(1);
401         return 1;
402 }
403
404
405
406 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
407         : BC_PopupMenu(x, y, wid, to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
408 {
409         this->mwindow = mwindow;
410         this->zoombar = zoombar;
411         set_tooltip(_("Automation Type"));
412 }
413
414 void AutoTypeMenu::create_objects()
415 {
416         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
417         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
418         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
419         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
420         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
421         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
422 }
423
424 const char* AutoTypeMenu::to_text(int mode)
425 {
426         switch(mode) {
427         case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
428         case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
429         case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
430         case AUTOGROUPTYPE_SPEED: return _("Speed:");
431         case AUTOGROUPTYPE_X: return "X:";
432         case AUTOGROUPTYPE_Y: return "Y:";
433         }
434         return "??";
435 }
436
437 int AutoTypeMenu::from_text(char *text)
438 {
439         if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
440         if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
441         if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
442         if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
443         if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
444         if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
445         return AUTOGROUPTYPE_INT255;
446 }
447
448 int AutoTypeMenu::handle_event()
449 {
450         mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
451         this->zoombar->update_autozoom();
452         return 1;
453 }
454
455
456 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
457  : BC_TextBox(x, y, 130, 1, text)
458 {
459         this->mwindow = mwindow;
460         this->zoombar = zoombar;
461         set_tooltip(_("Automation range"));
462 }
463
464 int ZoomTextBox::button_press_event()
465 {
466         if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
467                 BC_TextBox::button_press_event();
468                 return 0;
469         }
470         if (!is_event_win()) return 0;
471
472         int changemax = 1;
473         if (get_relative_cursor_x() < get_w()/2)
474                 changemax = 0;
475
476         // increment
477         if (get_buttonpress() == 4)
478                 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
479
480         // decrement
481         if (get_buttonpress() == 5)
482                 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
483
484         mwindow->gui->zoombar->update_autozoom();
485         mwindow->gui->draw_overlays(0);
486         mwindow->gui->update_patchbay();
487         mwindow->gui->flash_canvas(1);
488         return 1;
489 }
490
491 int ZoomTextBox::handle_event()
492 {
493         float min, max;
494         if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
495         {
496                 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
497                 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
498                 if (max > min)
499                 {
500                         mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
501                         mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
502                         mwindow->gui->zoombar->update_autozoom();
503                         mwindow->gui->draw_overlays(0);
504                         mwindow->gui->update_patchbay();
505                         mwindow->gui->flash_canvas(1);
506                 }
507         }
508         // TODO: Make the text turn red when it's a bad range..
509         return 0;
510 }
511
512
513
514
515
516 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
517  : BC_TextBox(x, y, 90, 1, "")
518 {
519         this->mwindow = mwindow;
520         this->zoombar = zoombar;
521         set_tooltip(_("Selection start time"));
522 }
523
524 int FromTextBox::handle_event()
525 {
526         if(get_keypress() == 13)
527         {
528                 zoombar->set_selection(SET_FROM);
529                 return 1;
530         }
531         return 0;
532 }
533
534 int FromTextBox::update_position(double new_position)
535 {
536         Units::totext(string,
537                 new_position,
538                 mwindow->edl->session->time_format,
539                 mwindow->edl->session->sample_rate,
540                 mwindow->edl->session->frame_rate,
541                 mwindow->edl->session->frames_per_foot);
542 //printf("FromTextBox::update_position %f %s\n", new_position, string);
543         update(string);
544         return 0;
545 }
546
547
548
549
550
551
552 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
553  : BC_TextBox(x, y, 90, 1, "")
554 {
555         this->mwindow = mwindow;
556         this->zoombar = zoombar;
557         set_tooltip(_("Selection length"));
558 }
559
560 int LengthTextBox::handle_event()
561 {
562         if(get_keypress() == 13)
563         {
564                 zoombar->set_selection(SET_LENGTH);
565                 return 1;
566         }
567         return 0;
568 }
569
570 int LengthTextBox::update_position(double new_position)
571 {
572         Units::totext(string,
573                 new_position,
574                 mwindow->edl->session->time_format,
575                 mwindow->edl->session->sample_rate,
576                 mwindow->edl->session->frame_rate,
577                 mwindow->edl->session->frames_per_foot);
578         update(string);
579         return 0;
580 }
581
582
583
584
585
586 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
587  : BC_TextBox(x, y, 90, 1, "")
588 {
589         this->mwindow = mwindow;
590         this->zoombar = zoombar;
591         set_tooltip(_("Selection end time"));
592 }
593
594 int ToTextBox::handle_event()
595 {
596         if(get_keypress() == 13)
597         {
598                 zoombar->set_selection(SET_TO);
599                 return 1;
600         }
601         return 0;
602 }
603
604 int ToTextBox::update_position(double new_position)
605 {
606         Units::totext(string, new_position,
607                 mwindow->edl->session->time_format,
608                 mwindow->edl->session->sample_rate,
609                 mwindow->edl->session->frame_rate,
610                 mwindow->edl->session->frames_per_foot);
611         update(string);
612         return 0;
613 }