r753: Add raise_window() commands when making various windows
[cinelerra_cv/mob.git] / cinelerra / mtimebar.C
blob4fa66b74464a1c8d9f08357dbfe377355db23736
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         draw_range();
53 // fit the time
54         int64_t windowspan = 0;
55         int64_t timescale1 = 0;
56         int64_t timescale2 = 0;
57         int64_t sample_rate = 0;
58         int64_t sample = 0;
59         float timescale3 = 0;
60         int pixel = 0;
61         char string[BCTEXTLEN];
62 #define TIMESPACING 100
64         sample_rate = mwindow->edl->session->sample_rate;
65         windowspan = mwindow->edl->local_session->zoom_sample * get_w();
66         timescale2 = TIMESPACING * mwindow->edl->local_session->zoom_sample;
68         if(timescale2 <= sample_rate / 4) timescale1 = sample_rate / 4;
69         else
70         if(timescale2 <= sample_rate / 2) timescale1 = sample_rate / 2;
71         else
72         if(timescale2 <= sample_rate) timescale1 = sample_rate;
73         else
74         if(timescale2 <= sample_rate * 10) timescale1 = sample_rate * 10;
75         else
76         if(timescale2 <= sample_rate * 60) timescale1 = sample_rate * 60;
77         else
78         if(timescale2 <= sample_rate * 600) timescale1 = sample_rate * 600;
79         else
80         timescale1 = sample_rate * 3600;
82         for(timescale3 = timescale1; timescale3 > timescale2; timescale3 /= 2)
83                 ;
85         timescale1 = (int64_t)(timescale3 * 2);
87         sample = (int64_t)(mwindow->edl->local_session->view_start * 
88                 mwindow->edl->local_session->zoom_sample + 
89                 0.5);
91         sample /= timescale1;
92         sample *= timescale1;
93         pixel = (int64_t)(sample / 
94                 mwindow->edl->local_session->zoom_sample - 
95                 mwindow->edl->local_session->view_start);
96         sample += (int64_t) ((mwindow->edl->session->get_frame_offset() /
97                                                                 mwindow->edl->session->frame_rate) *
98                                                                 48000 /
99                                                                 timescale1 *
100                                                                 timescale1);
102         for( ; pixel < get_w(); pixel += timescale1 / mwindow->edl->local_session->zoom_sample, sample += timescale1)
103         {
104                 Units::totext(string, 
105                         sample, 
106                         sample_rate, 
107                         mwindow->edl->session->time_format, 
108                         mwindow->edl->session->frame_rate,
109                         mwindow->edl->session->frames_per_foot);
110                 set_color(get_resources()->default_text_color);
111                 set_font(MEDIUMFONT);
112                 draw_text(pixel + 4, get_text_ascent(MEDIUMFONT), string);
113                 draw_line(pixel, 3, pixel, get_h() - 4);
114         }
117 void MTimeBar::draw_range()
119         int x1 = 0, x2 = 0;
120         if(mwindow->edl->tracks->total_playable_vtracks() &&
121                 mwindow->preferences->use_brender)
122         {
123                 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
124                         mwindow->edl->session->sample_rate;
125                 x1 = (int)(mwindow->edl->session->brender_start / time_per_pixel) - 
126                         mwindow->edl->local_session->view_start;
127                 x2 = (int)(mwindow->session->brender_end / time_per_pixel) - 
128                         mwindow->edl->local_session->view_start;
129         }
131         if(x2 > x1 && 
132                 x1 < get_w() && 
133                 x2 > 0)
134         {
135                 draw_top_background(get_parent(), 0, 0, x1, get_h());
136                 draw_3segmenth(x1, 0, x2 - x1, mwindow->theme->get_image("timebar_brender"));
137                 draw_top_background(get_parent(), x2, 0, get_w() - x2, get_h());
138         }
139         else
140                 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
141 //printf("MTimeBar::draw_range %f %f\n", mwindow->session->brender_end, time_per_pixel);
144 void MTimeBar::select_label(double position)
146         EDL *edl = mwindow->edl;
148         mwindow->gui->unlock_window();
149         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1);
150         mwindow->gui->lock_window();
152         position = mwindow->edl->align_to_frame(position, 1);
154         if(shift_down())
155         {
156                 if(position > edl->local_session->get_selectionend(1) / 2 + 
157                         edl->local_session->get_selectionstart(1) / 2)
158                 {
159                 
160                         edl->local_session->set_selectionend(position);
161                 }
162                 else
163                 {
164                         edl->local_session->set_selectionstart(position);
165                 }
166         }
167         else
168         {
169                 edl->local_session->set_selectionstart(position);
170                 edl->local_session->set_selectionend(position);
171         }
173 // Que the CWindow
174         mwindow->cwindow->update(1, 0, 0);
175         mwindow->gui->cursor->hide();
176         mwindow->gui->cursor->draw();
177         mwindow->gui->canvas->activate();
178         mwindow->gui->zoombar->update();
179         update_highlights();
180         mwindow->gui->canvas->flash();
184 int MTimeBar::resize_event()
186         reposition_window(mwindow->theme->mtimebar_x,
187                 mwindow->theme->mtimebar_y,
188                 mwindow->theme->mtimebar_w,
189                 mwindow->theme->mtimebar_h);
190         update();
191         return 1;
194 int MTimeBar::test_preview(int buttonpress)
196         int result = 0;
197         return result;