3 #include "edlsession.h"
4 #include "localsession.h"
5 #include "maincursor.h"
6 #include "mainsession.h"
9 #include "mwindowgui.h"
11 #include "preferences.h"
13 #include "trackcanvas.h"
15 #include "transportque.h"
20 MTimeBar::MTimeBar(MWindow *mwindow,
26 : TimeBar(mwindow, gui, x, y, w, h)
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()
44 gui->mbuttons->transport->handle_transport(STOP, 1);
49 void MTimeBar::draw_time()
51 //printf("TimeBar::draw_time 1\n");
53 //printf("TimeBar::draw_time 2\n");
56 int64_t windowspan = 0;
57 int64_t timescale1 = 0;
58 int64_t timescale2 = 0;
59 int64_t sample_rate = 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;
73 if(timescale2 <= sample_rate / 2) timescale1 = sample_rate / 2;
75 if(timescale2 <= sample_rate) timescale1 = sample_rate;
77 if(timescale2 <= sample_rate * 10) timescale1 = sample_rate * 10;
79 if(timescale2 <= sample_rate * 60) timescale1 = sample_rate * 60;
81 if(timescale2 <= sample_rate * 600) timescale1 = sample_rate * 600;
83 timescale1 = sample_rate * 3600;
84 //printf("TimeBar::draw_time 2\n");
86 for(timescale3 = timescale1; timescale3 > timescale2; timescale3 /= 2)
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 +
96 //printf("TimeBar::draw_time 2 %lld %lld %lld\n", mwindow->edl->local_session->zoom_sample, sample_rate, 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) *
110 for( ; pixel < get_w(); pixel += timescale1 / mwindow->edl->local_session->zoom_sample, sample += timescale1)
112 Units::totext(string,
115 mwindow->edl->session->time_format,
116 mwindow->edl->session->frame_rate,
117 mwindow->edl->session->frames_per_foot);
119 set_font(MEDIUMFONT);
120 draw_text(pixel + 4, get_text_ascent(MEDIUMFONT), string);
121 draw_line(pixel, 3, pixel, get_h() - 4);
123 //printf("TimeBar::draw_time 200\n");
126 void MTimeBar::draw_range()
129 if(mwindow->edl->tracks->total_playable_vtracks() &&
130 mwindow->preferences->use_brender)
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;
140 //printf("MTimeBar::draw_range 1 %f %f\n", mwindow->edl->session->brender_start, mwindow->session->brender_end);
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());
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);
166 if(position > edl->local_session->selectionend / 2 + edl->local_session->selectionstart / 2)
169 edl->local_session->selectionend = position;
173 edl->local_session->selectionstart = position;
178 edl->local_session->selectionstart = edl->local_session->selectionend = position;
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();
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);
202 int MTimeBar::test_preview(int buttonpress)