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()
54 int64_t windowspan = 0;
55 int64_t timescale1 = 0;
56 int64_t timescale2 = 0;
57 int64_t sample_rate = 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;
70 if(timescale2 <= sample_rate / 2) timescale1 = sample_rate / 2;
72 if(timescale2 <= sample_rate) timescale1 = sample_rate;
74 if(timescale2 <= sample_rate * 10) timescale1 = sample_rate * 10;
76 if(timescale2 <= sample_rate * 60) timescale1 = sample_rate * 60;
78 if(timescale2 <= sample_rate * 600) timescale1 = sample_rate * 600;
80 timescale1 = sample_rate * 3600;
82 for(timescale3 = timescale1; timescale3 > timescale2; timescale3 /= 2)
85 timescale1 = (int64_t)(timescale3 * 2);
87 sample = (int64_t)(mwindow->edl->local_session->view_start *
88 mwindow->edl->local_session->zoom_sample +
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) *
102 for( ; pixel < get_w(); pixel += timescale1 / mwindow->edl->local_session->zoom_sample, sample += timescale1)
104 Units::totext(string,
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);
117 void MTimeBar::draw_range()
120 if(mwindow->edl->tracks->total_playable_vtracks() &&
121 mwindow->preferences->use_brender)
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;
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());
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);
156 if(position > edl->local_session->get_selectionend(1) / 2 +
157 edl->local_session->get_selectionstart(1) / 2)
160 edl->local_session->set_selectionend(position);
164 edl->local_session->set_selectionstart(position);
169 edl->local_session->set_selectionstart(position);
170 edl->local_session->set_selectionend(position);
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();
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);
194 int MTimeBar::test_preview(int buttonpress)