5 #include "edlsession.h"
6 #include "localsession.h"
7 #include "maincursor.h"
8 #include "mainsession.h"
11 #include "mwindowgui.h"
14 #include "preferences.h"
16 #include "trackcanvas.h"
18 #include "transportque.h"
23 MTimeBar::MTimeBar(MWindow *mwindow,
29 : TimeBar(mwindow, gui, x, y, w, h)
35 int64_t MTimeBar::position_to_pixel(double position)
37 return (int64_t)(position *
38 mwindow->edl->session->sample_rate /
39 mwindow->edl->local_session->zoom_sample -
40 mwindow->edl->local_session->view_start);
44 void MTimeBar::stop_playback()
47 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
52 #define TICK_SPACING 5
54 #define TICK_MARGIN 16
55 void MTimeBar::draw_time()
58 char string[BCTEXTLEN];
59 int sample_rate = mwindow->edl->session->sample_rate;
60 double frame_rate = mwindow->edl->session->frame_rate;
61 int64_t windowspan = 0;
62 // Seconds between text markings
63 double text_interval = 3600.0;
64 // Seconds between tick marks
65 double tick_interval = 3600.0;
66 int64_t timescale2 = 0;
71 // Calculate tick mark spacing, number spacing, and starting point based
72 // on zoom, time format, project settings.
74 // If the time format is for audio, mark round numbers of samples based on
76 // Fow low zoom, mark tens of samples.
78 // If the time format is for video, mark round number of frames based on
80 // For low zoom, mark individual frames.
82 windowspan = mwindow->edl->local_session->zoom_sample * get_w();
91 // Number of seconds per pixel
92 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
94 // Seconds in each frame
95 double frame_seconds = (double)1.0 / frame_rate;
96 // Starting time of view in seconds.
97 double view_start = mwindow->edl->local_session->view_start * time_per_pixel;
98 // Ending time of view in seconds
99 double view_end = (double)(mwindow->edl->local_session->view_start +
100 get_w()) * time_per_pixel;
101 // Get minimum distance between text marks
102 int min_pixels1 = get_text_width(MEDIUMFONT,
103 Units::totext(string,
105 mwindow->edl->session->time_format,
107 mwindow->edl->session->frame_rate,
108 mwindow->edl->session->frames_per_foot)) + TEXT_MARGIN;
109 int min_pixels2 = get_text_width(MEDIUMFONT,
110 Units::totext(string,
112 mwindow->edl->session->time_format,
114 mwindow->edl->session->frame_rate,
115 mwindow->edl->session->frames_per_foot)) + TEXT_MARGIN;
116 int min_pixels = (int)MAX(min_pixels1, min_pixels2);
119 // Minimum seconds between text marks
120 double min_time = (double)min_pixels *
121 mwindow->edl->local_session->zoom_sample /
125 // Get first text mark on or before window start
126 int64_t starting_mark = 0;
130 // Default text spacing
132 double prev_text_interval = 1.0;
134 while(text_interval >= min_time)
136 prev_text_interval = text_interval;
151 text_interval /= 2.5;
156 text_interval = prev_text_interval;
192 text_interval = 1200;
195 text_interval = 1800;
198 text_interval = 3600;
201 switch(mwindow->edl->session->time_format)
203 case TIME_FEET_FRAMES:
205 double foot_seconds = frame_seconds * mwindow->edl->session->frames_per_foot;
206 if(frame_seconds >= min_time)
207 text_interval = frame_seconds;
209 if(foot_seconds / 8.0 > min_time)
210 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot / 8.0;
212 if(foot_seconds / 4.0 > min_time)
213 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot / 4.0;
215 if(foot_seconds / 2.0 > min_time)
216 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot / 2.0;
218 if(foot_seconds > min_time)
219 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot;
221 if(foot_seconds * 2 >= min_time)
222 text_interval = foot_seconds * 2;
224 if(foot_seconds * 5 >= min_time)
225 text_interval = foot_seconds * 5;
229 for(int factor = 10, progression = 0; factor <= 100000; )
231 if(foot_seconds * factor >= min_time)
233 text_interval = foot_seconds * factor;
239 factor = (int)(factor * 2.5);
245 factor = (int)(factor * 2);
251 factor = (int)(factor * 2);
262 // One frame per text mark
263 if(frame_seconds >= min_time)
264 text_interval = frame_seconds;
266 if(frame_seconds * 2 >= min_time)
267 text_interval = frame_seconds * 2;
269 if(frame_seconds * 5 >= min_time)
270 text_interval = frame_seconds * 5;
274 for(int factor = 10, progression = 0; factor <= 100000; )
276 if(frame_seconds * factor >= min_time)
278 text_interval = frame_seconds * factor;
284 factor = (int)(factor * 2.5);
290 factor = (int)(factor * 2);
296 factor = (int)(factor * 2);
309 while(text_interval < min_time)
315 tick_interval = text_interval;
317 switch(mwindow->edl->session->time_format)
320 case TIME_FEET_FRAMES:
322 if(frame_seconds / time_per_pixel > TICK_SPACING)
323 tick_interval = frame_seconds;
327 // Get first text mark on or before window start
328 starting_mark = (int64_t)((double)mwindow->edl->local_session->view_start *
329 time_per_pixel / text_interval);
331 double start_position = (double)starting_mark * text_interval;
332 int64_t iteration = 0;
335 //printf("text_interval=%f\n", text_interval);
336 while(start_position + text_interval * iteration < view_end)
338 double position1 = start_position + text_interval * iteration;
339 int pixel = (int64_t)(position1 / time_per_pixel) -
340 mwindow->edl->local_session->view_start;
343 Units::totext(string,
345 mwindow->edl->session->time_format,
347 mwindow->edl->session->frame_rate,
348 mwindow->edl->session->frames_per_foot);
349 set_color(get_resources()->default_text_color);
350 set_font(MEDIUMFONT);
352 draw_text(pixel + TEXT_MARGIN, get_text_ascent(MEDIUMFONT), string);
353 draw_line(pixel, LINE_MARGIN, pixel, get_h() - 2);
355 double position2 = start_position + text_interval * (iteration + 1);
356 int pixel2 = (int64_t)(position2 / time_per_pixel) -
357 mwindow->edl->local_session->view_start;
359 for(double tick_position = position1;
360 tick_position < position2;
361 tick_position += tick_interval)
363 pixel = (int64_t)(tick_position / time_per_pixel) -
364 mwindow->edl->local_session->view_start;
365 if(labs(pixel - pixel1) > 1 &&
366 labs(pixel - pixel2) > 1)
367 draw_line(pixel, TICK_MARGIN, pixel, get_h() - 2);
375 void MTimeBar::draw_range()
378 if(mwindow->edl->tracks->total_playable_vtracks() &&
379 mwindow->preferences->use_brender)
381 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
382 mwindow->edl->session->sample_rate;
383 x1 = (int)(mwindow->edl->session->brender_start / time_per_pixel) -
384 mwindow->edl->local_session->view_start;
385 x2 = (int)(mwindow->session->brender_end / time_per_pixel) -
386 mwindow->edl->local_session->view_start;
393 draw_top_background(get_parent(), 0, 0, x1, get_h());
395 draw_3segmenth(x1, 0, x2 - x1, mwindow->theme->get_image("timebar_brender"));
397 draw_top_background(get_parent(), x2, 0, get_w() - x2, get_h());
400 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
401 //printf("MTimeBar::draw_range %f %f\n", mwindow->session->brender_end, time_per_pixel);
404 void MTimeBar::select_label(double position)
406 EDL *edl = mwindow->edl;
408 mwindow->gui->unlock_window();
409 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
410 mwindow->gui->lock_window();
412 position = mwindow->edl->align_to_frame(position, 1);
416 if(position > edl->local_session->get_selectionend(1) / 2 +
417 edl->local_session->get_selectionstart(1) / 2)
420 edl->local_session->set_selectionend(position);
424 edl->local_session->set_selectionstart(position);
429 edl->local_session->set_selectionstart(position);
430 edl->local_session->set_selectionend(position);
434 mwindow->cwindow->update(1, 0, 0, 0, 1);
435 mwindow->gui->cursor->hide(0);
436 mwindow->gui->cursor->draw(1);
437 mwindow->gui->canvas->activate();
438 mwindow->gui->zoombar->update();
439 mwindow->gui->patchbay->update();
440 mwindow->update_plugin_guis();
442 mwindow->gui->canvas->flash();
446 int MTimeBar::resize_event()
448 reposition_window(mwindow->theme->mtimebar_x,
449 mwindow->theme->mtimebar_y,
450 mwindow->theme->mtimebar_w,
451 mwindow->theme->mtimebar_h);
456 int MTimeBar::test_preview(int buttonpress)
475 // c-file-style: "linux"