r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / cinelerra / zoombar.C
blobcfe7cb464262a602cb1c08ee5049741e62558196
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "localsession.h"
4 #include "mwindow.h"
5 #include "mwindowgui.h"
6 #include "mainsession.h"
7 #include "mtimebar.h"
8 #include "preferences.h"
9 #include "theme.h"
10 #include "trackcanvas.h"
11 #include "tracks.h"
12 #include "units.h"
13 #include "zoombar.h"
16 #include <libintl.h>
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
24 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
25  : BC_SubWindow(mwindow->theme->mzoom_x,
26         mwindow->theme->mzoom_y,
27         mwindow->theme->mzoom_w,
28         mwindow->theme->mzoom_h) 
30         this->gui = gui;
31         this->mwindow = mwindow;
32         old_position = 0;
35 ZoomBar::~ZoomBar()
37         delete sample_zoom;
38         delete amp_zoom;
39         delete track_zoom;
42 int ZoomBar::create_objects()
44         int x = 3, y = 1;
46         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
47         sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
48         sample_zoom->create_objects();
49         x += sample_zoom->get_w();
50         amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
51         amp_zoom->create_objects();
52         x += amp_zoom->get_w();
53         track_zoom = new TrackZoomPanel(mwindow, this, x, y);
54         track_zoom->create_objects();
55         x += track_zoom->get_w() + 5;
57 // FIXME
58         add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
59         x += from_value->get_w() + 5;
60         add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
61         x += length_value->get_w() + 5;
62         add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
63         x += to_value->get_w() + 5;
65         add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
67         add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
68         update();
69         return 0;
73 void ZoomBar::resize_event()
75         reposition_window(mwindow->theme->mzoom_x,
76                 mwindow->theme->mzoom_y,
77                 mwindow->theme->mzoom_w,
78                 mwindow->theme->mzoom_h);
80         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
81         int x = 3, y = 1;
82         sample_zoom->reposition_window(x, y);
83         x += sample_zoom->get_w();
84         amp_zoom->reposition_window(x, y);
85         x += amp_zoom->get_w();
86         track_zoom->reposition_window(x, y);
87         flash();
90 void ZoomBar::redraw_time_dependancies()
92 // Recalculate sample zoom menu
93         sample_zoom->update_menu();
94         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
95         update_clocks();
98 int ZoomBar::draw()
100         update();
101         return 0;
104 int ZoomBar::update()
106 //printf("ZoomBar::update 1 %f\n", mwindow->edl->local_session->selectionstart);
107         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
108         amp_zoom->update(mwindow->edl->local_session->zoom_y);
109         track_zoom->update(mwindow->edl->local_session->zoom_track);
110         update_clocks();
111         return 0;
114 int ZoomBar::update_clocks()
116 //printf("ZoomBar::update_clocks 1 %f\n", mwindow->edl->local_session->selectionstart);
117         from_value->update_position(mwindow->edl->local_session->selectionstart);
118         length_value->update_position(mwindow->edl->local_session->selectionend - 
119                 mwindow->edl->local_session->selectionstart);
120         to_value->update_position(mwindow->edl->local_session->selectionend);
121         return 0;
124 int ZoomBar::update_playback(int64_t new_position)
126         if(new_position != old_position)
127         {
128                 Units::totext(string, 
129                                 new_position, 
130                                 mwindow->edl->session->sample_rate, 
131                                 mwindow->edl->session->time_format, 
132                                 mwindow->edl->session->frame_rate,
133                                 mwindow->edl->session->frames_per_foot);
134                 playback_value->update(string);
135                 old_position = new_position;
136         }
137         return 0;
140 int ZoomBar::resize_event(int w, int h)
142 // don't change anything but y and width
143         reposition_window(0, h - this->get_h(), w, this->get_h());
144         return 0;
148 // Values for which_one
149 #define SET_FROM 1
150 #define SET_LENGTH 2
151 #define SET_TO 3
154 int ZoomBar::set_selection(int which_one)
156         double start_position = mwindow->edl->local_session->selectionstart;
157         double end_position = mwindow->edl->local_session->selectionend;
158         double length = end_position - start_position;
160 // Fix bogus results
161 // printf("ZoomBar::set_selection 1 %f %f %f\n", 
162 // mwindow->edl->local_session->selectionstart, 
163 // mwindow->edl->local_session->selectionend, 
164 // length);
166         switch(which_one)
167         {
168                 case SET_LENGTH:
169                         start_position = Units::text_to_seconds(from_value->get_text(), 
170                                 mwindow->edl->session->sample_rate, 
171                                 mwindow->edl->session->time_format, 
172                                 mwindow->edl->session->frame_rate,
173                                 mwindow->edl->session->frames_per_foot);
174                         length = Units::text_to_seconds(length_value->get_text(), 
175                                 mwindow->edl->session->sample_rate, 
176                                 mwindow->edl->session->time_format, 
177                                 mwindow->edl->session->frame_rate,
178                                 mwindow->edl->session->frames_per_foot);
179                         end_position = start_position + length;
181                         if(end_position < start_position)
182                         {
183                                 start_position = end_position;
184                                 mwindow->edl->local_session->selectionend = mwindow->edl->local_session->selectionstart;
185                         }
186                         break;
188                 case SET_FROM:
189                         start_position = Units::text_to_seconds(from_value->get_text(), 
190                                 mwindow->edl->session->sample_rate, 
191                                 mwindow->edl->session->time_format, 
192                                 mwindow->edl->session->frame_rate,
193                                 mwindow->edl->session->frames_per_foot);
194                         end_position = Units::text_to_seconds(to_value->get_text(), 
195                                 mwindow->edl->session->sample_rate, 
196                                 mwindow->edl->session->time_format, 
197                                 mwindow->edl->session->frame_rate,
198                                 mwindow->edl->session->frames_per_foot);
200                         if(end_position < start_position)
201                         {
202                                 end_position = start_position;
203                                 mwindow->edl->local_session->selectionend = mwindow->edl->local_session->selectionstart;
204                         }
205                         break;
207                 case SET_TO:
208                         start_position = Units::text_to_seconds(from_value->get_text(), 
209                                 mwindow->edl->session->sample_rate, 
210                                 mwindow->edl->session->time_format, 
211                                 mwindow->edl->session->frame_rate,
212                                 mwindow->edl->session->frames_per_foot);
213                         end_position = Units::text_to_seconds(to_value->get_text(), 
214                                 mwindow->edl->session->sample_rate, 
215                                 mwindow->edl->session->time_format, 
216                                 mwindow->edl->session->frame_rate,
217                                 mwindow->edl->session->frames_per_foot);
219                         if(end_position < start_position)
220                         {
221                                 start_position = end_position;
222                                 mwindow->edl->local_session->selectionend = mwindow->edl->local_session->selectionstart;
223                         }
224                         break;
225         }
227         mwindow->edl->local_session->selectionstart = 
228                 mwindow->edl->align_to_frame(start_position, 1);
229         mwindow->edl->local_session->selectionend = 
230                 mwindow->edl->align_to_frame(end_position, 1);
232 // printf("ZoomBar::set_selection 2 %f %f\n", 
233 // mwindow->edl->local_session->selectionstart, 
234 // mwindow->edl->local_session->selectionend);
236         mwindow->gui->timebar->update_highlights();
237         mwindow->gui->cursor->hide();
238         mwindow->gui->cursor->show();
239         update();
240         mwindow->sync_parameters(CHANGE_PARAMS);
241         mwindow->gui->canvas->flash();
243         return 0;
257 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, 
258         ZoomBar *zoombar, 
259         int x, 
260         int y)
261  : ZoomPanel(mwindow, 
262         zoombar, 
263         mwindow->edl->local_session->zoom_sample, 
264         x, 
265         y, 
266         120, 
267         MIN_ZOOM_TIME, 
268         MAX_ZOOM_TIME, 
269         ZOOM_TIME)
271         this->mwindow = mwindow;
272         this->zoombar = zoombar;
274 SampleZoomPanel::~SampleZoomPanel()
277 int SampleZoomPanel::handle_event()
279         mwindow->zoom_sample((int64_t)get_value());
280         return 1;
293 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
294  : ZoomPanel(mwindow, 
295         zoombar, 
296         mwindow->edl->local_session->zoom_y, 
297         x, 
298         y, 
299         90,
300         MIN_AMP_ZOOM, 
301         MAX_AMP_ZOOM, 
302         ZOOM_LONG)
304         this->mwindow = mwindow;
305         this->zoombar = zoombar;
307 AmpZoomPanel::~AmpZoomPanel()
310 int AmpZoomPanel::handle_event()
312         mwindow->zoom_amp((int64_t)get_value());
313         return 1;
316 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
317  : ZoomPanel(mwindow, 
318         zoombar, 
319         mwindow->edl->local_session->zoom_track, 
320         x, 
321         y, 
322         80,
323         MIN_TRACK_ZOOM, 
324         MAX_TRACK_ZOOM, 
325         ZOOM_LONG)
327         this->mwindow = mwindow;
328         this->zoombar = zoombar;
330 TrackZoomPanel::~TrackZoomPanel()
333 int TrackZoomPanel::handle_event()
335         mwindow->zoom_track((int64_t)get_value());
336         zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
337         return 1;
345 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
346  : BC_TextBox(x, y, 90, 1, "")
348         this->mwindow = mwindow;
349         this->zoombar = zoombar;
352 int FromTextBox::handle_event()
354         if(get_keypress() == 13)
355         {
356                 zoombar->set_selection(SET_FROM);
357                 return 1;
358         }
359         return 0;
362 int FromTextBox::update_position(double new_position)
364         Units::totext(string, 
365                 new_position, 
366                 mwindow->edl->session->time_format, 
367                 mwindow->edl->session->sample_rate, 
368                 mwindow->edl->session->frame_rate,
369                 mwindow->edl->session->frames_per_foot);
370 //printf("FromTextBox::update_position %f %s\n", new_position, string);
371         update(string);
372         return 0;
380 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
381  : BC_TextBox(x, y, 90, 1, "")
383         this->mwindow = mwindow;
384         this->zoombar = zoombar;
387 int LengthTextBox::handle_event()
389         if(get_keypress() == 13)
390         {
391                 zoombar->set_selection(SET_LENGTH);
392                 return 1;
393         }
394         return 0;
397 int LengthTextBox::update_position(double new_position)
399         Units::totext(string, 
400                 new_position, 
401                 mwindow->edl->session->time_format, 
402                 mwindow->edl->session->sample_rate, 
403                 mwindow->edl->session->frame_rate,
404                 mwindow->edl->session->frames_per_foot);
405         update(string);
406         return 0;
413 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
414  : BC_TextBox(x, y, 90, 1, "")
416         this->mwindow = mwindow;
417         this->zoombar = zoombar;
420 int ToTextBox::handle_event()
422         if(get_keypress() == 13)
423         {
424                 zoombar->set_selection(SET_TO);
425                 return 1;
426         }
427         return 0;
430 int ToTextBox::update_position(double new_position)
432         Units::totext(string, 
433                 new_position, 
434                 mwindow->edl->session->time_format, 
435                 mwindow->edl->session->sample_rate, 
436                 mwindow->edl->session->frame_rate,
437                 mwindow->edl->session->frames_per_foot);
438         update(string);
439         return 0;