r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mtimebar.C
blob9bfecb434a7e8ab7ba69c751f92b7ff0468d873a
1 #include "cwindow.h"
2 #include "edl.h"
3 #include "edlsession.h"
4 #include "localsession.h"
5 #include "mainsession.h"
6 #include "mbuttons.h"
7 #include "mtimebar.h"
8 #include "mwindowgui.h"
9 #include "mwindow.h"
10 #include "preferences.h"
11 #include "theme.h"
12 #include "trackcanvas.h"
13 #include "tracks.h"
14 #include "transportque.h"
15 #include "zoombar.h"
19 MTimeBar::MTimeBar(MWindow *mwindow, 
20         MWindowGUI *gui,
21         int x, 
22         int y,
23         int w,
24         int h)
25  : TimeBar(mwindow, gui, x, y, w, h)
27         this->gui = gui;
31 int64_t MTimeBar::position_to_pixel(double position)
33         return (int64_t)(position * 
34                 mwindow->edl->session->sample_rate / 
35                 mwindow->edl->local_session->zoom_sample - 
36                 mwindow->edl->local_session->view_start);
40 void MTimeBar::stop_playback()
42         gui->unlock_window();
43         gui->mbuttons->transport->handle_transport(STOP, 1);
44         gui->lock_window();
48 void MTimeBar::draw_time()
50 //printf("TimeBar::draw_time 1\n");
51         draw_range();
52 //printf("TimeBar::draw_time 2\n");
54 // fit the time
55         int64_t windowspan, timescale1, timescale2, sample_rate, sample;
56         float timescale3;
57         int pixel;
58         char string[256];
59 #define TIMESPACING 100
61         sample_rate = mwindow->edl->session->sample_rate;
62         windowspan = mwindow->edl->local_session->zoom_sample * get_w();
63         timescale2 = TIMESPACING * mwindow->edl->local_session->zoom_sample;
65         if(timescale2 <= sample_rate / 4) timescale1 = sample_rate / 4;
66         else
67         if(timescale2 <= sample_rate / 2) timescale1 = sample_rate / 2;
68         else
69         if(timescale2 <= sample_rate) timescale1 = sample_rate;
70         else
71         if(timescale2 <= sample_rate * 10) timescale1 = sample_rate * 10;
72         else
73         if(timescale2 <= sample_rate * 60) timescale1 = sample_rate * 60;
74         else
75         if(timescale2 <= sample_rate * 600) timescale1 = sample_rate * 600;
76         else
77         timescale1 = sample_rate * 3600;
79         for(timescale3 = timescale1; timescale3 > timescale2; timescale3 /= 2)
80                 ;
82         timescale1 = (int64_t)(timescale3 * 2);
84         sample = (int64_t)(mwindow->edl->local_session->view_start * 
85                 mwindow->edl->local_session->zoom_sample + 
86                 0.5);
88         sample /= timescale1;
89         sample *= timescale1;
90         pixel = (int64_t)(sample / 
91                 mwindow->edl->local_session->zoom_sample - 
92                 mwindow->edl->local_session->view_start);
94         for( ; pixel < get_w(); pixel += timescale1 / mwindow->edl->local_session->zoom_sample, sample += timescale1)
95         {
96                 Units::totext(string, 
97                         sample, 
98                         sample_rate, 
99                         mwindow->edl->session->time_format, 
100                         mwindow->edl->session->frame_rate,
101                         mwindow->edl->session->frames_per_foot);
102                 set_color(BLACK);
103                 set_font(MEDIUMFONT);
104                 draw_text(pixel + 4, get_text_ascent(MEDIUMFONT), string);
105                 draw_line(pixel, 3, pixel, get_h() - 4);
106         }
109 void MTimeBar::draw_range()
111         int x1 = 0, x2 = 0;
112         if(mwindow->edl->tracks->total_playable_vtracks() &&
113                 mwindow->preferences->use_brender)
114         {
115                 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
116                         mwindow->edl->session->sample_rate;
117                 x1 = (int)(mwindow->edl->session->brender_start / time_per_pixel) - 
118                         mwindow->edl->local_session->view_start;
119                 x2 = (int)(mwindow->session->brender_end / time_per_pixel) - 
120                         mwindow->edl->local_session->view_start;
121         }
123 //printf("MTimeBar::draw_range 1 %f %f\n", mwindow->edl->session->brender_start, mwindow->session->brender_end);
124         if(x2 > x1 && 
125                 x1 < get_w() && 
126                 x2 > 0)
127         {
128                 draw_top_background(get_parent(), 0, 0, x1, get_h());
129                 draw_3segmenth(x1, 0, x2 - x1, mwindow->theme->timebar_brender_data);
130                 draw_top_background(get_parent(), x2, 0, get_w() - x2, get_h());
131         }
132         else
133                 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
134 //printf("MTimeBar::draw_range %f %f\n", mwindow->session->brender_end, time_per_pixel);
137 void MTimeBar::select_label(double position)
139         EDL *edl = mwindow->edl;
141         mwindow->gui->unlock_window();
142         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1);
143         mwindow->gui->lock_window();
145         position = mwindow->edl->align_to_frame(position, 1);
147         if(shift_down())
148         {
149                 if(position > edl->local_session->selectionend / 2 + edl->local_session->selectionstart / 2)
150                 {
151                 
152                         edl->local_session->selectionend = position;
153                 }
154                 else
155                 {
156                         edl->local_session->selectionstart = position;
157                 }
158         }
159         else
160         {
161                 edl->local_session->selectionstart = edl->local_session->selectionend = position;
162         }
164 // Que the CWindow
165         mwindow->cwindow->update(1, 0, 0);
166         mwindow->gui->cursor->hide();
167         mwindow->gui->cursor->draw();
168         mwindow->gui->canvas->activate();
169         mwindow->gui->zoombar->update();
170         update_highlights();
171         mwindow->gui->canvas->flash();
175 int MTimeBar::resize_event()
177         reposition_window(mwindow->theme->mtimebar_x,
178                 mwindow->theme->mtimebar_y,
179                 mwindow->theme->mtimebar_w,
180                 mwindow->theme->mtimebar_h);
181         update();
182         return 1;
185 int MTimeBar::test_preview(int buttonpress)
187         int result = 0;
188         return result;