00001 #include "bcsignals.h"
00002 #include "clip.h"
00003 #include "cwindow.h"
00004 #include "edl.h"
00005 #include "edlsession.h"
00006 #include "localsession.h"
00007 #include "maincursor.h"
00008 #include "mainsession.h"
00009 #include "mbuttons.h"
00010 #include "mtimebar.h"
00011 #include "mwindowgui.h"
00012 #include "mwindow.h"
00013 #include "patchbay.h"
00014 #include "preferences.h"
00015 #include "theme.h"
00016 #include "trackcanvas.h"
00017 #include "tracks.h"
00018 #include "transportque.h"
00019 #include "zoombar.h"
00020
00021
00022
00023 MTimeBar::MTimeBar(MWindow *mwindow,
00024 MWindowGUI *gui,
00025 int x,
00026 int y,
00027 int w,
00028 int h)
00029 : TimeBar(mwindow, gui, x, y, w, h)
00030 {
00031 this->gui = gui;
00032 }
00033
00034
00035 int64_t MTimeBar::position_to_pixel(double position)
00036 {
00037 return (int64_t)(position *
00038 mwindow->edl->session->sample_rate /
00039 mwindow->edl->local_session->zoom_sample -
00040 mwindow->edl->local_session->view_start);
00041 }
00042
00043
00044 void MTimeBar::stop_playback()
00045 {
00046 gui->unlock_window();
00047 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
00048 gui->lock_window();
00049 }
00050
00051 #define TEXT_MARGIN 4
00052 #define TICK_SPACING 5
00053 #define LINE_MARGIN 3
00054 #define TICK_MARGIN 16
00055 void MTimeBar::draw_time()
00056 {
00057
00058 char string[BCTEXTLEN];
00059 int sample_rate = mwindow->edl->session->sample_rate;
00060 double frame_rate = mwindow->edl->session->frame_rate;
00061 int64_t windowspan = 0;
00062
00063 double text_interval = 3600.0;
00064
00065 double tick_interval = 3600.0;
00066 int64_t timescale2 = 0;
00067 float timescale3 = 0;
00068 int pixel = 0;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 windowspan = mwindow->edl->local_session->zoom_sample * get_w();
00083
00084
00085 draw_range();
00086
00087
00088
00089
00090
00091
00092 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
00093 sample_rate;
00094
00095 double frame_seconds = (double)1.0 / frame_rate;
00096
00097 double view_start = mwindow->edl->local_session->view_start * time_per_pixel;
00098
00099 double view_end = (double)(mwindow->edl->local_session->view_start +
00100 get_w()) * time_per_pixel;
00101
00102 int min_pixels1 = get_text_width(MEDIUMFONT,
00103 Units::totext(string,
00104 view_start,
00105 mwindow->edl->session->time_format,
00106 sample_rate,
00107 mwindow->edl->session->frame_rate,
00108 mwindow->edl->session->frames_per_foot)) + TEXT_MARGIN;
00109 int min_pixels2 = get_text_width(MEDIUMFONT,
00110 Units::totext(string,
00111 view_end,
00112 mwindow->edl->session->time_format,
00113 sample_rate,
00114 mwindow->edl->session->frame_rate,
00115 mwindow->edl->session->frames_per_foot)) + TEXT_MARGIN;
00116 int min_pixels = (int)MAX(min_pixels1, min_pixels2);
00117
00118
00119
00120 double min_time = (double)min_pixels *
00121 mwindow->edl->local_session->zoom_sample /
00122 sample_rate;
00123
00124
00125
00126 int64_t starting_mark = 0;
00127
00128 int progression = 1;
00129
00130
00131 text_interval = 0.5;
00132 double prev_text_interval = 1.0;
00133
00134 while(text_interval >= min_time)
00135 {
00136 prev_text_interval = text_interval;
00137 if(progression == 0)
00138 {
00139 text_interval /= 2;
00140 progression++;
00141 }
00142 else
00143 if(progression == 1)
00144 {
00145 text_interval /= 2;
00146 progression++;
00147 }
00148 else
00149 if(progression == 2)
00150 {
00151 text_interval /= 2.5;
00152 progression = 0;
00153 }
00154 }
00155
00156 text_interval = prev_text_interval;
00157
00158 if(1 >= min_time)
00159 ;
00160 else
00161 if(2 >= min_time)
00162 text_interval = 2;
00163 else
00164 if(5 >= min_time)
00165 text_interval = 5;
00166 else
00167 if(10 >= min_time)
00168 text_interval = 10;
00169 else
00170 if(15 >= min_time)
00171 text_interval = 15;
00172 else
00173 if(20 >= min_time)
00174 text_interval = 20;
00175 else
00176 if(30 >= min_time)
00177 text_interval = 30;
00178 else
00179 if(60 >= min_time)
00180 text_interval = 60;
00181 else
00182 if(120 >= min_time)
00183 text_interval = 120;
00184 else
00185 if(300 >= min_time)
00186 text_interval = 300;
00187 else
00188 if(600 >= min_time)
00189 text_interval = 600;
00190 else
00191 if(1200 >= min_time)
00192 text_interval = 1200;
00193 else
00194 if(1800 >= min_time)
00195 text_interval = 1800;
00196 else
00197 if(3600 >= min_time)
00198 text_interval = 3600;
00199
00200
00201 switch(mwindow->edl->session->time_format)
00202 {
00203 case TIME_FEET_FRAMES:
00204 {
00205 double foot_seconds = frame_seconds * mwindow->edl->session->frames_per_foot;
00206 if(frame_seconds >= min_time)
00207 text_interval = frame_seconds;
00208 else
00209 if(foot_seconds / 8.0 > min_time)
00210 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot / 8.0;
00211 else
00212 if(foot_seconds / 4.0 > min_time)
00213 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot / 4.0;
00214 else
00215 if(foot_seconds / 2.0 > min_time)
00216 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot / 2.0;
00217 else
00218 if(foot_seconds > min_time)
00219 text_interval = frame_seconds * mwindow->edl->session->frames_per_foot;
00220 else
00221 if(foot_seconds * 2 >= min_time)
00222 text_interval = foot_seconds * 2;
00223 else
00224 if(foot_seconds * 5 >= min_time)
00225 text_interval = foot_seconds * 5;
00226 else
00227 {
00228
00229 for(int factor = 10, progression = 0; factor <= 100000; )
00230 {
00231 if(foot_seconds * factor >= min_time)
00232 {
00233 text_interval = foot_seconds * factor;
00234 break;
00235 }
00236
00237 if(progression == 0)
00238 {
00239 factor = (int)(factor * 2.5);
00240 progression++;
00241 }
00242 else
00243 if(progression == 1)
00244 {
00245 factor = (int)(factor * 2);
00246 progression++;
00247 }
00248 else
00249 if(progression == 2)
00250 {
00251 factor = (int)(factor * 2);
00252 progression = 0;
00253 }
00254 }
00255
00256 }
00257 break;
00258 }
00259
00260 case TIME_FRAMES:
00261 case TIME_HMSF:
00262
00263 if(frame_seconds >= min_time)
00264 text_interval = frame_seconds;
00265 else
00266 if(frame_seconds * 2 >= min_time)
00267 text_interval = frame_seconds * 2;
00268 else
00269 if(frame_seconds * 5 >= min_time)
00270 text_interval = frame_seconds * 5;
00271 else
00272 {
00273
00274 for(int factor = 10, progression = 0; factor <= 100000; )
00275 {
00276 if(frame_seconds * factor >= min_time)
00277 {
00278 text_interval = frame_seconds * factor;
00279 break;
00280 }
00281
00282 if(progression == 0)
00283 {
00284 factor = (int)(factor * 2.5);
00285 progression++;
00286 }
00287 else
00288 if(progression == 1)
00289 {
00290 factor = (int)(factor * 2);
00291 progression++;
00292 }
00293 else
00294 if(progression == 2)
00295 {
00296 factor = (int)(factor * 2);
00297 progression = 0;
00298 }
00299 }
00300
00301 }
00302 break;
00303
00304 default:
00305 break;
00306 }
00307
00308
00309 while(text_interval < min_time)
00310 {
00311 text_interval *= 2;
00312 }
00313
00314
00315 tick_interval = text_interval;
00316
00317 switch(mwindow->edl->session->time_format)
00318 {
00319 case TIME_HMSF:
00320 case TIME_FEET_FRAMES:
00321 case TIME_FRAMES:
00322 if(frame_seconds / time_per_pixel > TICK_SPACING)
00323 tick_interval = frame_seconds;
00324 break;
00325 }
00326
00327
00328 starting_mark = (int64_t)((double)mwindow->edl->local_session->view_start *
00329 time_per_pixel / text_interval);
00330
00331 double start_position = (double)starting_mark * text_interval;
00332 int64_t iteration = 0;
00333
00334
00335
00336 while(start_position + text_interval * iteration < view_end)
00337 {
00338 double position1 = start_position + text_interval * iteration;
00339 int pixel = (int64_t)(position1 / time_per_pixel) -
00340 mwindow->edl->local_session->view_start;
00341 int pixel1 = pixel;
00342
00343 Units::totext(string,
00344 position1,
00345 mwindow->edl->session->time_format,
00346 sample_rate,
00347 mwindow->edl->session->frame_rate,
00348 mwindow->edl->session->frames_per_foot);
00349 set_color(get_resources()->default_text_color);
00350 set_font(MEDIUMFONT);
00351
00352 draw_text(pixel + TEXT_MARGIN, get_text_ascent(MEDIUMFONT), string);
00353 draw_line(pixel, LINE_MARGIN, pixel, get_h() - 2);
00354
00355 double position2 = start_position + text_interval * (iteration + 1);
00356 int pixel2 = (int64_t)(position2 / time_per_pixel) -
00357 mwindow->edl->local_session->view_start;
00358
00359 for(double tick_position = position1;
00360 tick_position < position2;
00361 tick_position += tick_interval)
00362 {
00363 pixel = (int64_t)(tick_position / time_per_pixel) -
00364 mwindow->edl->local_session->view_start;
00365 if(labs(pixel - pixel1) > 1 &&
00366 labs(pixel - pixel2) > 1)
00367 draw_line(pixel, TICK_MARGIN, pixel, get_h() - 2);
00368 }
00369 iteration++;
00370 }
00371
00372
00373 }
00374
00375 void MTimeBar::draw_range()
00376 {
00377 int x1 = 0, x2 = 0;
00378 if(mwindow->edl->tracks->total_playable_vtracks() &&
00379 mwindow->preferences->use_brender)
00380 {
00381 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
00382 mwindow->edl->session->sample_rate;
00383 x1 = (int)(mwindow->edl->session->brender_start / time_per_pixel) -
00384 mwindow->edl->local_session->view_start;
00385 x2 = (int)(mwindow->session->brender_end / time_per_pixel) -
00386 mwindow->edl->local_session->view_start;
00387 }
00388
00389 if(x2 > x1 &&
00390 x1 < get_w() &&
00391 x2 > 0)
00392 {
00393 draw_top_background(get_parent(), 0, 0, x1, get_h());
00394
00395 draw_3segmenth(x1, 0, x2 - x1, mwindow->theme->get_image("timebar_brender"));
00396
00397 draw_top_background(get_parent(), x2, 0, get_w() - x2, get_h());
00398 }
00399 else
00400 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
00401
00402 }
00403
00404 void MTimeBar::select_label(double position)
00405 {
00406 EDL *edl = mwindow->edl;
00407
00408 mwindow->gui->unlock_window();
00409 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
00410 mwindow->gui->lock_window();
00411
00412 position = mwindow->edl->align_to_frame(position, 1);
00413
00414 if(shift_down())
00415 {
00416 if(position > edl->local_session->get_selectionend(1) / 2 +
00417 edl->local_session->get_selectionstart(1) / 2)
00418 {
00419
00420 edl->local_session->set_selectionend(position);
00421 }
00422 else
00423 {
00424 edl->local_session->set_selectionstart(position);
00425 }
00426 }
00427 else
00428 {
00429 edl->local_session->set_selectionstart(position);
00430 edl->local_session->set_selectionend(position);
00431 }
00432
00433
00434 mwindow->cwindow->update(1, 0, 0, 0, 1);
00435 mwindow->gui->cursor->hide(0);
00436 mwindow->gui->cursor->draw(1);
00437 mwindow->gui->canvas->activate();
00438 mwindow->gui->zoombar->update();
00439 mwindow->gui->patchbay->update();
00440 mwindow->update_plugin_guis();
00441 update_highlights();
00442 mwindow->gui->canvas->flash();
00443 }
00444
00445
00446 int MTimeBar::resize_event()
00447 {
00448 reposition_window(mwindow->theme->mtimebar_x,
00449 mwindow->theme->mtimebar_y,
00450 mwindow->theme->mtimebar_w,
00451 mwindow->theme->mtimebar_h);
00452 update();
00453 return 1;
00454 }
00455
00456 int MTimeBar::test_preview(int buttonpress)
00457 {
00458 int result = 0;
00459 return result;
00460 }
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471