r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / cinelerra / zoombar.C
bloba35734efa9fb3c37084a1951e70ee1023786a302
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "language.h"
4 #include "localsession.h"
5 #include "maincursor.h"
6 #include "mwindow.h"
7 #include "mwindowgui.h"
8 #include "mainsession.h"
9 #include "mtimebar.h"
10 #include "preferences.h"
11 #include "theme.h"
12 #include "trackcanvas.h"
13 #include "tracks.h"
14 #include "units.h"
15 #include "zoombar.h"
20 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
21  : BC_SubWindow(mwindow->theme->mzoom_x,
22         mwindow->theme->mzoom_y,
23         mwindow->theme->mzoom_w,
24         mwindow->theme->mzoom_h) 
26         this->gui = gui;
27         this->mwindow = mwindow;
28         old_position = 0;
31 ZoomBar::~ZoomBar()
33         delete sample_zoom;
34         delete amp_zoom;
35         delete track_zoom;
38 int ZoomBar::create_objects()
40         int x = 3, y = 1;
42         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
43         sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
44         sample_zoom->create_objects();
45         x += sample_zoom->get_w();
46         amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
47         amp_zoom->create_objects();
48         x += amp_zoom->get_w();
49         track_zoom = new TrackZoomPanel(mwindow, this, x, y);
50         track_zoom->create_objects();
51         x += track_zoom->get_w() + 5;
53 // FIXME
54         add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
55         x += from_value->get_w() + 5;
56         add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
57         x += length_value->get_w() + 5;
58         add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
59         x += to_value->get_w() + 5;
61         update_formatting(from_value);
62         update_formatting(length_value);
63         update_formatting(to_value);
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::update_formatting(BC_TextBox *dst)
75         dst->set_separators(
76                 Units::format_to_separators(mwindow->edl->session->time_format));
79 void ZoomBar::resize_event()
81         reposition_window(mwindow->theme->mzoom_x,
82                 mwindow->theme->mzoom_y,
83                 mwindow->theme->mzoom_w,
84                 mwindow->theme->mzoom_h);
86         draw_top_background(get_parent(), 0, 0, get_w(), get_h());
87         int x = 3, y = 1;
88         sample_zoom->reposition_window(x, y);
89         x += sample_zoom->get_w();
90         amp_zoom->reposition_window(x, y);
91         x += amp_zoom->get_w();
92         track_zoom->reposition_window(x, y);
93         flash();
96 void ZoomBar::redraw_time_dependancies()
98 // Recalculate sample zoom menu
99         sample_zoom->update_menu();
100         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
101         update_formatting(from_value);
102         update_formatting(length_value);
103         update_formatting(to_value);
104         update_clocks();
107 int ZoomBar::draw()
109         update();
110         return 0;
113 int ZoomBar::update()
115 //printf("ZoomBar::update 1 %f\n", mwindow->edl->local_session->selectionstart);
116         sample_zoom->update(mwindow->edl->local_session->zoom_sample);
117         amp_zoom->update(mwindow->edl->local_session->zoom_y);
118         track_zoom->update(mwindow->edl->local_session->zoom_track);
119         update_clocks();
120         return 0;
123 int ZoomBar::update_clocks()
125 //printf("ZoomBar::update_clocks 1 %f\n", mwindow->edl->local_session->selectionstart);
126         from_value->update_position(mwindow->edl->local_session->selectionstart);
127         length_value->update_position(mwindow->edl->local_session->selectionend - 
128                 mwindow->edl->local_session->selectionstart);
129         to_value->update_position(mwindow->edl->local_session->selectionend);
130         return 0;
133 int ZoomBar::update_playback(int64_t new_position)
135         if(new_position != old_position)
136         {
137                 Units::totext(string, 
138                                 new_position, 
139                                 mwindow->edl->session->sample_rate, 
140                                 mwindow->edl->session->time_format, 
141                                 mwindow->edl->session->frame_rate,
142                                 mwindow->edl->session->frames_per_foot);
143                 playback_value->update(string);
144                 old_position = new_position;
145         }
146         return 0;
149 int ZoomBar::resize_event(int w, int h)
151 // don't change anything but y and width
152         reposition_window(0, h - this->get_h(), w, this->get_h());
153         return 0;
157 // Values for which_one
158 #define SET_FROM 1
159 #define SET_LENGTH 2
160 #define SET_TO 3
163 int ZoomBar::set_selection(int which_one)
165         double start_position = mwindow->edl->local_session->selectionstart;
166         double end_position = mwindow->edl->local_session->selectionend;
167         double length = end_position - start_position;
169 // Fix bogus results
170 // printf("ZoomBar::set_selection 1 %f %f %f\n", 
171 // mwindow->edl->local_session->selectionstart, 
172 // mwindow->edl->local_session->selectionend, 
173 // length);
175         switch(which_one)
176         {
177                 case SET_LENGTH:
178                         start_position = Units::text_to_seconds(from_value->get_text(), 
179                                 mwindow->edl->session->sample_rate, 
180                                 mwindow->edl->session->time_format, 
181                                 mwindow->edl->session->frame_rate,
182                                 mwindow->edl->session->frames_per_foot);
183                         length = Units::text_to_seconds(length_value->get_text(), 
184                                 mwindow->edl->session->sample_rate, 
185                                 mwindow->edl->session->time_format, 
186                                 mwindow->edl->session->frame_rate,
187                                 mwindow->edl->session->frames_per_foot);
188                         end_position = start_position + length;
190                         if(end_position < start_position)
191                         {
192                                 start_position = end_position;
193                                 mwindow->edl->local_session->selectionend = mwindow->edl->local_session->selectionstart;
194                         }
195                         break;
197                 case SET_FROM:
198                         start_position = Units::text_to_seconds(from_value->get_text(), 
199                                 mwindow->edl->session->sample_rate, 
200                                 mwindow->edl->session->time_format, 
201                                 mwindow->edl->session->frame_rate,
202                                 mwindow->edl->session->frames_per_foot);
203                         end_position = Units::text_to_seconds(to_value->get_text(), 
204                                 mwindow->edl->session->sample_rate, 
205                                 mwindow->edl->session->time_format, 
206                                 mwindow->edl->session->frame_rate,
207                                 mwindow->edl->session->frames_per_foot);
209                         if(end_position < start_position)
210                         {
211                                 end_position = start_position;
212                                 mwindow->edl->local_session->selectionend = mwindow->edl->local_session->selectionstart;
213                         }
214                         break;
216                 case SET_TO:
217                         start_position = Units::text_to_seconds(from_value->get_text(), 
218                                 mwindow->edl->session->sample_rate, 
219                                 mwindow->edl->session->time_format, 
220                                 mwindow->edl->session->frame_rate,
221                                 mwindow->edl->session->frames_per_foot);
222                         end_position = Units::text_to_seconds(to_value->get_text(), 
223                                 mwindow->edl->session->sample_rate, 
224                                 mwindow->edl->session->time_format, 
225                                 mwindow->edl->session->frame_rate,
226                                 mwindow->edl->session->frames_per_foot);
228                         if(end_position < start_position)
229                         {
230                                 start_position = end_position;
231                                 mwindow->edl->local_session->selectionend = mwindow->edl->local_session->selectionstart;
232                         }
233                         break;
234         }
236         mwindow->edl->local_session->selectionstart = 
237                 mwindow->edl->align_to_frame(start_position, 1);
238         mwindow->edl->local_session->selectionend = 
239                 mwindow->edl->align_to_frame(end_position, 1);
241 // printf("ZoomBar::set_selection 2 %f %f\n", 
242 // mwindow->edl->local_session->selectionstart, 
243 // mwindow->edl->local_session->selectionend);
245         mwindow->gui->timebar->update_highlights();
246         mwindow->gui->cursor->hide();
247         mwindow->gui->cursor->show();
248         update();
249         mwindow->sync_parameters(CHANGE_PARAMS);
250         mwindow->gui->canvas->flash();
252         return 0;
266 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, 
267         ZoomBar *zoombar, 
268         int x, 
269         int y)
270  : ZoomPanel(mwindow, 
271         zoombar, 
272         mwindow->edl->local_session->zoom_sample, 
273         x, 
274         y, 
275         120, 
276         MIN_ZOOM_TIME, 
277         MAX_ZOOM_TIME, 
278         ZOOM_TIME)
280         this->mwindow = mwindow;
281         this->zoombar = zoombar;
283 SampleZoomPanel::~SampleZoomPanel()
286 int SampleZoomPanel::handle_event()
288         mwindow->zoom_sample((int64_t)get_value());
289         return 1;
302 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
303  : ZoomPanel(mwindow, 
304         zoombar, 
305         mwindow->edl->local_session->zoom_y, 
306         x, 
307         y, 
308         90,
309         MIN_AMP_ZOOM, 
310         MAX_AMP_ZOOM, 
311         ZOOM_LONG)
313         this->mwindow = mwindow;
314         this->zoombar = zoombar;
316 AmpZoomPanel::~AmpZoomPanel()
319 int AmpZoomPanel::handle_event()
321         mwindow->zoom_amp((int64_t)get_value());
322         return 1;
325 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
326  : ZoomPanel(mwindow, 
327         zoombar, 
328         mwindow->edl->local_session->zoom_track, 
329         x, 
330         y, 
331         80,
332         MIN_TRACK_ZOOM, 
333         MAX_TRACK_ZOOM, 
334         ZOOM_LONG)
336         this->mwindow = mwindow;
337         this->zoombar = zoombar;
339 TrackZoomPanel::~TrackZoomPanel()
342 int TrackZoomPanel::handle_event()
344         mwindow->zoom_track((int64_t)get_value());
345         zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
346         return 1;
354 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
355  : BC_TextBox(x, y, 90, 1, "")
357         this->mwindow = mwindow;
358         this->zoombar = zoombar;
361 int FromTextBox::handle_event()
363         if(get_keypress() == 13)
364         {
365                 zoombar->set_selection(SET_FROM);
366                 return 1;
367         }
368         return 0;
371 int FromTextBox::update_position(double new_position)
373         Units::totext(string, 
374                 new_position, 
375                 mwindow->edl->session->time_format, 
376                 mwindow->edl->session->sample_rate, 
377                 mwindow->edl->session->frame_rate,
378                 mwindow->edl->session->frames_per_foot);
379 //printf("FromTextBox::update_position %f %s\n", new_position, string);
380         update(string);
381         return 0;
389 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
390  : BC_TextBox(x, y, 90, 1, "")
392         this->mwindow = mwindow;
393         this->zoombar = zoombar;
396 int LengthTextBox::handle_event()
398         if(get_keypress() == 13)
399         {
400                 zoombar->set_selection(SET_LENGTH);
401                 return 1;
402         }
403         return 0;
406 int LengthTextBox::update_position(double new_position)
408         Units::totext(string, 
409                 new_position, 
410                 mwindow->edl->session->time_format, 
411                 mwindow->edl->session->sample_rate, 
412                 mwindow->edl->session->frame_rate,
413                 mwindow->edl->session->frames_per_foot);
414         update(string);
415         return 0;
422 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
423  : BC_TextBox(x, y, 90, 1, "")
425         this->mwindow = mwindow;
426         this->zoombar = zoombar;
429 int ToTextBox::handle_event()
431         if(get_keypress() == 13)
432         {
433                 zoombar->set_selection(SET_TO);
434                 return 1;
435         }
436         return 0;
439 int ToTextBox::update_position(double new_position)
441         Units::totext(string, 
442                 new_position, 
443                 mwindow->edl->session->time_format, 
444                 mwindow->edl->session->sample_rate, 
445                 mwindow->edl->session->frame_rate,
446                 mwindow->edl->session->frames_per_foot);
447         update(string);
448         return 0;