r1053: Add Russian translation.
[cinelerra_cv.git] / cinelerra / zoombar.C
blob03857e5445704a753654349df66259fdba999d83
1 #include "clip.h"
2 #include "edl.h"
3 #include "edlsession.h"
4 #include "language.h"
5 #include "localsession.h"
6 #include "maincursor.h"
7 #include "mwindow.h"
8 #include "mwindowgui.h"
9 #include "mainsession.h"
10 #include "mtimebar.h"
11 #include "preferences.h"
12 #include "patchbay.h"
13 #include "theme.h"
14 #include "trackcanvas.h"
15 #include "tracks.h"
16 #include "units.h"
17 #include "zoombar.h"
22 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
23  : BC_SubWindow(mwindow->theme->mzoom_x,
24         mwindow->theme->mzoom_y,
25         mwindow->theme->mzoom_w,
26         mwindow->theme->mzoom_h) 
28         this->gui = gui;
29         this->mwindow = mwindow;
30         old_position = 0;
33 ZoomBar::~ZoomBar()
35         delete sample_zoom;
36         delete amp_zoom;
37         delete track_zoom;
40 int ZoomBar::create_objects()
42         int x = 3;
43         int y = get_h() / 2 - 
44                 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
46         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
47         sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
48         sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
49         sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
50         sample_zoom->create_objects();
51         sample_zoom->zoom_text->set_tooltip(_("Duration visible in the timeline"));
52         sample_zoom->zoom_tumbler->set_tooltip(_("Duration visible in the timeline"));
53         x += sample_zoom->get_w();
54         amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
55         amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
56         amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
57         amp_zoom->create_objects();
58         amp_zoom->zoom_text->set_tooltip(_("Audio waveform scale"));
59         amp_zoom->zoom_tumbler->set_tooltip(_("Audio waveform scale"));
60         x += amp_zoom->get_w();
61         track_zoom = new TrackZoomPanel(mwindow, this, x, y);
62         track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
63         track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
64         track_zoom->create_objects();
65         track_zoom->zoom_text->set_tooltip(_("Height of tracks in the timeline"));
66         track_zoom->zoom_tumbler->set_tooltip(_("Height of tracks in the timeline"));
67         x += track_zoom->get_w() + 10;
69         add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y));
70         auto_type->create_objects();
71         x += auto_type->get_w() + 10;
72 #define DEFAULT_TEXT "000.00 to 000.00"
73         add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
74         x += auto_zoom->get_w();
75         add_subwindow(auto_zoom_text = new ZoomTextBox(
76                 mwindow, 
77                 this, 
78                 x, 
79                 y,
80                 DEFAULT_TEXT));
81         x += auto_zoom_text->get_w() + 5;
82         add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
83         update_autozoom();
84         x += auto_zoom->get_w() + 5;
86         add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
87         x += from_value->get_w() + 5;
88         add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
89         x += length_value->get_w() + 5;
90         add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
91         x += to_value->get_w() + 5;
93         update_formatting(from_value);
94         update_formatting(length_value);
95         update_formatting(to_value);
97         add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
99         add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
100         update();
101         return 0;
105 void ZoomBar::update_formatting(BC_TextBox *dst)
107         dst->set_separators(
108                 Units::format_to_separators(mwindow->edl->session->time_format));
111 void ZoomBar::resize_event()
113         reposition_window(mwindow->theme->mzoom_x,
114                 mwindow->theme->mzoom_y,
115                 mwindow->theme->mzoom_w,
116                 mwindow->theme->mzoom_h);
118         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
119         int x = 3, y = 1;
120         if (sample_zoom) delete sample_zoom;
121         sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
122         sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
123         sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
124         sample_zoom->create_objects();
125 //      x += sample_zoom->get_w();
126 //      amp_zoom->reposition_window(x, y);
127 //      x += amp_zoom->get_w();
128 //      track_zoom->reposition_window(x, y);
129         flash();
132 void ZoomBar::redraw_time_dependancies()
134 // Recalculate sample zoom menu
135         sample_zoom->update_menu();
136         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
137         update_formatting(from_value);
138         update_formatting(length_value);
139         update_formatting(to_value);
140         update_autozoom();
141         update_clocks();
144 int ZoomBar::draw()
146         update();
147         return 0;
150 void ZoomBar::update_autozoom()
152         char string[BCTEXTLEN];
153         switch (mwindow->edl->local_session->zoombar_showautotype) {
154         case AUTOGROUPTYPE_AUDIO_FADE:
155         case AUTOGROUPTYPE_VIDEO_FADE:
156                 sprintf(string, "%0.01f to %0.01f\n", 
157                         mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
158                         mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
159                 break;
160         case AUTOGROUPTYPE_ZOOM:
161                 sprintf(string, "%0.03f to %0.03f\n", 
162                         mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
163                         mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
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[mwindow->edl->local_session->zoombar_showautotype],
169                         mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
170                 break;
171         }
172         auto_zoom_text->update(string);
175 int ZoomBar::update()
177         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
178         amp_zoom->update(mwindow->edl->local_session->zoom_y);
179         track_zoom->update(mwindow->edl->local_session->zoom_track);
180         update_autozoom();
181         update_clocks();
182         return 0;
185 int ZoomBar::update_clocks()
187         from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
188         length_value->update_position(mwindow->edl->local_session->get_selectionend(1) - 
189                 mwindow->edl->local_session->get_selectionstart(1));
190         to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
191         return 0;
194 int ZoomBar::update_playback(int64_t new_position)
196         if(new_position != old_position)
197         {
198                 Units::totext(string, 
199                                 new_position, 
200                                 mwindow->edl->session->sample_rate, 
201                                 mwindow->edl->session->time_format, 
202                                 mwindow->edl->session->frame_rate,
203                                 mwindow->edl->session->frames_per_foot);
204                 playback_value->update(string);
205                 old_position = new_position;
206         }
207         return 0;
210 int ZoomBar::resize_event(int w, int h)
212 // don't change anything but y and width
213         reposition_window(0, h - this->get_h(), w, this->get_h());
214         return 0;
218 // Values for which_one
219 #define SET_FROM 1
220 #define SET_LENGTH 2
221 #define SET_TO 3
224 int ZoomBar::set_selection(int which_one)
226         double start_position = mwindow->edl->local_session->get_selectionstart(1);
227         double end_position = mwindow->edl->local_session->get_selectionend(1);
228         double length = end_position - start_position;
230 // Fix bogus results
232         switch(which_one)
233         {
234                 case SET_LENGTH:
235                         start_position = Units::text_to_seconds(from_value->get_text(), 
236                                 mwindow->edl->session->sample_rate, 
237                                 mwindow->edl->session->time_format, 
238                                 mwindow->edl->session->frame_rate,
239                                 mwindow->edl->session->frames_per_foot);
240                         length = Units::text_to_seconds(length_value->get_text(), 
241                                 mwindow->edl->session->sample_rate, 
242                                 mwindow->edl->session->time_format, 
243                                 mwindow->edl->session->frame_rate,
244                                 mwindow->edl->session->frames_per_foot);
245                         end_position = start_position + length;
247                         if(end_position < start_position)
248                         {
249                                 start_position = end_position;
250                                 mwindow->edl->local_session->set_selectionend(
251                                         mwindow->edl->local_session->get_selectionstart(1));
252                         }
253                         break;
255                 case SET_FROM:
256                         start_position = Units::text_to_seconds(from_value->get_text(), 
257                                 mwindow->edl->session->sample_rate, 
258                                 mwindow->edl->session->time_format, 
259                                 mwindow->edl->session->frame_rate,
260                                 mwindow->edl->session->frames_per_foot);
261                         end_position = Units::text_to_seconds(to_value->get_text(), 
262                                 mwindow->edl->session->sample_rate, 
263                                 mwindow->edl->session->time_format, 
264                                 mwindow->edl->session->frame_rate,
265                                 mwindow->edl->session->frames_per_foot);
267                         if(end_position < start_position)
268                         {
269                                 end_position = start_position;
270                                 mwindow->edl->local_session->set_selectionend(
271                                         mwindow->edl->local_session->get_selectionstart(1));
272                         }
273                         break;
275                 case SET_TO:
276                         start_position = Units::text_to_seconds(from_value->get_text(), 
277                                 mwindow->edl->session->sample_rate, 
278                                 mwindow->edl->session->time_format, 
279                                 mwindow->edl->session->frame_rate,
280                                 mwindow->edl->session->frames_per_foot);
281                         end_position = Units::text_to_seconds(to_value->get_text(), 
282                                 mwindow->edl->session->sample_rate, 
283                                 mwindow->edl->session->time_format, 
284                                 mwindow->edl->session->frame_rate,
285                                 mwindow->edl->session->frames_per_foot);
287                         if(end_position < start_position)
288                         {
289                                 start_position = end_position;
290                                 mwindow->edl->local_session->set_selectionend(
291                                         mwindow->edl->local_session->get_selectionstart(1));
292                         }
293                         break;
294         }
296         mwindow->edl->local_session->set_selectionstart(
297                 mwindow->edl->align_to_frame(start_position, 1));
298         mwindow->edl->local_session->set_selectionend(
299                 mwindow->edl->align_to_frame(end_position, 1));
302         mwindow->gui->timebar->update_highlights();
303         mwindow->gui->cursor->hide();
304         mwindow->gui->cursor->show();
305         update();
306         mwindow->sync_parameters(CHANGE_PARAMS);
307         mwindow->gui->canvas->flash();
309         return 0;
323 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, 
324         ZoomBar *zoombar, 
325         int x, 
326         int y)
327  : ZoomPanel(mwindow, 
328         zoombar, 
329         mwindow->edl->local_session->zoom_sample, 
330         x, 
331         y, 
332         110, 
333         MIN_ZOOM_TIME, 
334         MAX_ZOOM_TIME, 
335         ZOOM_TIME)
337         this->mwindow = mwindow;
338         this->zoombar = zoombar;
340 int SampleZoomPanel::handle_event()
342         mwindow->zoom_sample((int64_t)get_value());
343         return 1;
356 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
357  : ZoomPanel(mwindow, 
358         zoombar, 
359         mwindow->edl->local_session->zoom_y, 
360         x, 
361         y, 
362         80,
363         MIN_AMP_ZOOM, 
364         MAX_AMP_ZOOM, 
365         ZOOM_LONG)
367         this->mwindow = mwindow;
368         this->zoombar = zoombar;
370 int AmpZoomPanel::handle_event()
372         mwindow->zoom_amp((int64_t)get_value());
373         return 1;
376 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
377  : ZoomPanel(mwindow, 
378         zoombar, 
379         mwindow->edl->local_session->zoom_track, 
380         x, 
381         y, 
382         70,
383         MIN_TRACK_ZOOM, 
384         MAX_TRACK_ZOOM, 
385         ZOOM_LONG)
387         this->mwindow = mwindow;
388         this->zoombar = zoombar;
390 int TrackZoomPanel::handle_event()
392         mwindow->zoom_track((int64_t)get_value());
393         zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
394         return 1;
400 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
401  : BC_Tumbler(x,
402         y,
403         mwindow->theme->get_image_set("zoombar_tumbler"))
405         this->mwindow = mwindow;
406         this->zoombar = zoombar;
407         this->changemax = changemax;
408         if (changemax)
409                 set_tooltip(_("Automation range maximum"));
410         else
411                 set_tooltip(_("Automation range minimum"));
414 int AutoZoom::handle_up_event()
416         mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
418         mwindow->gui->zoombar->update_autozoom();
419         mwindow->gui->canvas->draw_overlays();
420         mwindow->gui->patchbay->update();
421         mwindow->gui->canvas->flash();
422         return 1;
425 int AutoZoom::handle_down_event()
427         mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
429         mwindow->gui->zoombar->update_autozoom();
430         mwindow->gui->canvas->draw_overlays();
431         mwindow->gui->patchbay->update();
432         mwindow->gui->canvas->flash();
433         return 1;
438 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
439         : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
441         this->mwindow = mwindow;
442         this->zoombar = zoombar;
443         set_tooltip(_("Automation Type"));
446 void AutoTypeMenu::create_objects()
448         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
449         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
450         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
451         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
452         add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
455 char* AutoTypeMenu::to_text(int mode)
457         switch(mode)
458         {
459         case AUTOGROUPTYPE_AUDIO_FADE:
460                 return _("Audio Fade:");
461         case AUTOGROUPTYPE_VIDEO_FADE:
462                 return _("Video Fade:");
463         case AUTOGROUPTYPE_ZOOM:
464                 return _("Zoom:");
465         case AUTOGROUPTYPE_X:
466                 return _("X:");
467         case AUTOGROUPTYPE_Y:
468                 return _("Y:");
469         default:
470                 return _("??");
471         }
474 int AutoTypeMenu::from_text(char *text)
476         if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
477                 return AUTOGROUPTYPE_AUDIO_FADE;
478         if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
479                 return AUTOGROUPTYPE_VIDEO_FADE;
480         if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
481                 return AUTOGROUPTYPE_ZOOM;
482         if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
483                 return AUTOGROUPTYPE_X;
484         if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
485                 return AUTOGROUPTYPE_Y;
488 int AutoTypeMenu::handle_event()
490         mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
491         this->zoombar->update_autozoom();
495 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, char *text)
496  : BC_TextBox(x, y, 130, 1, text)
498         this->mwindow = mwindow;
499         this->zoombar = zoombar;
500         set_tooltip(_("Automation range"));
503 int ZoomTextBox::button_press_event()
505         if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
506                 BC_TextBox::button_press_event();
507                 return 0;
508         }
509         if (!is_event_win()) return 0;
511         int changemax = 1;
512         if (get_relative_cursor_x() < get_w()/2)
513                 changemax = 0;
515         // increment
516         if (get_buttonpress() == 4)
517                 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
519         // decrement
520         if (get_buttonpress() == 5)
521                 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
523         mwindow->gui->zoombar->update_autozoom();
524         mwindow->gui->canvas->draw_overlays();
525         mwindow->gui->patchbay->update();
526         mwindow->gui->canvas->flash();
527         return 1;
530 int ZoomTextBox::handle_event()
532         float min, max;
533         if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
534         {
535                 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
536                 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
537                 if (max > min) 
538                 {
539                         mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
540                         mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
541                         mwindow->gui->zoombar->update_autozoom();
542                         mwindow->gui->canvas->draw_overlays();
543                         mwindow->gui->patchbay->update();
544                         mwindow->gui->canvas->flash();
545                 }
546         }
547         // TODO: Make the text turn red when it's a bad range..
548         return 0;
555 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
556  : BC_TextBox(x, y, 90, 1, "")
558         this->mwindow = mwindow;
559         this->zoombar = zoombar;
560         set_tooltip(_("Selection start time"));
563 int FromTextBox::handle_event()
565         if(get_keypress() == 13)
566         {
567                 zoombar->set_selection(SET_FROM);
568                 return 1;
569         }
570         return 0;
573 int FromTextBox::update_position(double new_position)
575         new_position += mwindow->edl->session->get_frame_offset() / 
576                                                  mwindow->edl->session->frame_rate;;
577         Units::totext(string, 
578                 new_position, 
579                 mwindow->edl->session->time_format, 
580                 mwindow->edl->session->sample_rate, 
581                 mwindow->edl->session->frame_rate,
582                 mwindow->edl->session->frames_per_foot);
583 //printf("FromTextBox::update_position %f %s\n", new_position, string);
584         update(string);
585         return 0;
593 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
594  : BC_TextBox(x, y, 90, 1, "")
596         this->mwindow = mwindow;
597         this->zoombar = zoombar;
598         set_tooltip(_("Selection length"));
601 int LengthTextBox::handle_event()
603         if(get_keypress() == 13)
604         {
605                 zoombar->set_selection(SET_LENGTH);
606                 return 1;
607         }
608         return 0;
611 int LengthTextBox::update_position(double new_position)
613         Units::totext(string, 
614                 new_position, 
615                 mwindow->edl->session->time_format, 
616                 mwindow->edl->session->sample_rate, 
617                 mwindow->edl->session->frame_rate,
618                 mwindow->edl->session->frames_per_foot);
619         update(string);
620         return 0;
627 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
628  : BC_TextBox(x, y, 90, 1, "")
630         this->mwindow = mwindow;
631         this->zoombar = zoombar;
632         set_tooltip(_("Selection end time"));
635 int ToTextBox::handle_event()
637         if(get_keypress() == 13)
638         {
639                 zoombar->set_selection(SET_TO);
640                 return 1;
641         }
642         return 0;
645 int ToTextBox::update_position(double new_position)
647         new_position += mwindow->edl->session->get_frame_offset() /
648                                                  mwindow->edl->session->frame_rate;
649         Units::totext(string, 
650                 new_position, 
651                 mwindow->edl->session->time_format, 
652                 mwindow->edl->session->sample_rate, 
653                 mwindow->edl->session->frame_rate,
654                 mwindow->edl->session->frames_per_foot);
655         update(string);
656         return 0;