r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mtimebar.C
blob992987dbf4e3081b55a2fb804983b7756ea12c33
1 #include "cwindow.h"
2 #include "edl.h"
3 #include "edlsession.h"
4 #include "localsession.h"
5 #include "maincursor.h"
6 #include "mainsession.h"
7 #include "mbuttons.h"
8 #include "mtimebar.h"
9 #include "mwindowgui.h"
10 #include "mwindow.h"
11 #include "preferences.h"
12 #include "theme.h"
13 #include "trackcanvas.h"
14 #include "tracks.h"
15 #include "transportque.h"
16 #include "zoombar.h"
20 MTimeBar::MTimeBar(MWindow *mwindow, 
21         MWindowGUI *gui,
22         int x, 
23         int y,
24         int w,
25         int h)
26  : TimeBar(mwindow, gui, x, y, w, h)
28         this->gui = gui;
32 int64_t MTimeBar::position_to_pixel(double position)
34         return (int64_t)(position * 
35                 mwindow->edl->session->sample_rate / 
36                 mwindow->edl->local_session->zoom_sample - 
37                 mwindow->edl->local_session->view_start);
41 void MTimeBar::stop_playback()
43         gui->unlock_window();
44         gui->mbuttons->transport->handle_transport(STOP, 1);
45         gui->lock_window();
49 void MTimeBar::draw_time()
51 //printf("TimeBar::draw_time 1\n");
52         draw_range();
53 //printf("TimeBar::draw_time 2\n");
55 // fit the time
56         int64_t windowspan = 0;
57         int64_t timescale1 = 0;
58         int64_t timescale2 = 0;
59         int64_t sample_rate = 0;
60         int64_t sample = 0;
61         float timescale3 = 0;
62         int pixel = 0;
63         char string[BCTEXTLEN];
64 #define TIMESPACING 100
66         sample_rate = mwindow->edl->session->sample_rate;
67         windowspan = mwindow->edl->local_session->zoom_sample * get_w();
68         timescale2 = TIMESPACING * mwindow->edl->local_session->zoom_sample;
69 //printf("TimeBar::draw_time 2\n");
71         if(timescale2 <= sample_rate / 4) timescale1 = sample_rate / 4;
72         else
73         if(timescale2 <= sample_rate / 2) timescale1 = sample_rate / 2;
74         else
75         if(timescale2 <= sample_rate) timescale1 = sample_rate;
76         else
77         if(timescale2 <= sample_rate * 10) timescale1 = sample_rate * 10;
78         else
79         if(timescale2 <= sample_rate * 60) timescale1 = sample_rate * 60;
80         else
81         if(timescale2 <= sample_rate * 600) timescale1 = sample_rate * 600;
82         else
83         timescale1 = sample_rate * 3600;
84 //printf("TimeBar::draw_time 2\n");
86         for(timescale3 = timescale1; timescale3 > timescale2; timescale3 /= 2)
87                 ;
88 //printf("TimeBar::draw_time 2\n");
90         timescale1 = (int64_t)(timescale3 * 2);
91 //printf("TimeBar::draw_time 2\n");
93         sample = (int64_t)(mwindow->edl->local_session->view_start * 
94                 mwindow->edl->local_session->zoom_sample + 
95                 0.5);
96 //printf("TimeBar::draw_time 2 %lld %lld %lld\n", mwindow->edl->local_session->zoom_sample, sample_rate, timescale1);
98         sample /= timescale1;
99         sample *= timescale1;
100         pixel = (int64_t)(sample / 
101                 mwindow->edl->local_session->zoom_sample - 
102                 mwindow->edl->local_session->view_start);
103 //printf("TimeBar::draw_time 2\n");
104         sample += (int64_t) ((mwindow->edl->session->get_frame_offset() /
105                                                                 mwindow->edl->session->frame_rate) *
106                                                                 48000 /
107                                                                 timescale1 *
108                                                                 timescale1);
110         for( ; pixel < get_w(); pixel += timescale1 / mwindow->edl->local_session->zoom_sample, sample += timescale1)
111         {
112                 Units::totext(string, 
113                         sample, 
114                         sample_rate, 
115                         mwindow->edl->session->time_format, 
116                         mwindow->edl->session->frame_rate,
117                         mwindow->edl->session->frames_per_foot);
118                 set_color(BLACK);
119                 set_font(MEDIUMFONT);
120                 draw_text(pixel + 4, get_text_ascent(MEDIUMFONT), string);
121                 draw_line(pixel, 3, pixel, get_h() - 4);
122         }
123 //printf("TimeBar::draw_time 200\n");
126 void MTimeBar::draw_range()
128         int x1 = 0, x2 = 0;
129         if(mwindow->edl->tracks->total_playable_vtracks() &&
130                 mwindow->preferences->use_brender)
131         {
132                 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
133                         mwindow->edl->session->sample_rate;
134                 x1 = (int)(mwindow->edl->session->brender_start / time_per_pixel) - 
135                         mwindow->edl->local_session->view_start;
136                 x2 = (int)(mwindow->session->brender_end / time_per_pixel) - 
137                         mwindow->edl->local_session->view_start;
138         }
140 //printf("MTimeBar::draw_range 1 %f %f\n", mwindow->edl->session->brender_start, mwindow->session->brender_end);
141         if(x2 > x1 && 
142                 x1 < get_w() && 
143                 x2 > 0)
144         {
145                 draw_top_background(get_parent(), 0, 0, x1, get_h());
146                 draw_3segmenth(x1, 0, x2 - x1, mwindow->theme->timebar_brender_data);
147                 draw_top_background(get_parent(), x2, 0, get_w() - x2, get_h());
148         }
149         else
150                 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
151 //printf("MTimeBar::draw_range %f %f\n", mwindow->session->brender_end, time_per_pixel);
154 void MTimeBar::select_label(double position)
156         EDL *edl = mwindow->edl;
158         mwindow->gui->unlock_window();
159         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1);
160         mwindow->gui->lock_window();
162         position = mwindow->edl->align_to_frame(position, 1);
164         if(shift_down())
165         {
166                 if(position > edl->local_session->selectionend / 2 + edl->local_session->selectionstart / 2)
167                 {
168                 
169                         edl->local_session->selectionend = position;
170                 }
171                 else
172                 {
173                         edl->local_session->selectionstart = position;
174                 }
175         }
176         else
177         {
178                 edl->local_session->selectionstart = edl->local_session->selectionend = position;
179         }
181 // Que the CWindow
182         mwindow->cwindow->update(1, 0, 0);
183         mwindow->gui->cursor->hide();
184         mwindow->gui->cursor->draw();
185         mwindow->gui->canvas->activate();
186         mwindow->gui->zoombar->update();
187         update_highlights();
188         mwindow->gui->canvas->flash();
192 int MTimeBar::resize_event()
194         reposition_window(mwindow->theme->mtimebar_x,
195                 mwindow->theme->mtimebar_y,
196                 mwindow->theme->mtimebar_w,
197                 mwindow->theme->mtimebar_h);
198         update();
199         return 1;
202 int MTimeBar::test_preview(int buttonpress)
204         int result = 0;
205         return result;