Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

mtimebar.C

Go to the documentation of this file.
00001 #include "cwindow.h"
00002 #include "edl.h"
00003 #include "edlsession.h"
00004 #include "localsession.h"
00005 #include "maincursor.h"
00006 #include "mainsession.h"
00007 #include "mbuttons.h"
00008 #include "mtimebar.h"
00009 #include "mwindowgui.h"
00010 #include "mwindow.h"
00011 #include "preferences.h"
00012 #include "theme.h"
00013 #include "trackcanvas.h"
00014 #include "tracks.h"
00015 #include "transportque.h"
00016 #include "zoombar.h"
00017 
00018 
00019 
00020 MTimeBar::MTimeBar(MWindow *mwindow, 
00021         MWindowGUI *gui,
00022         int x, 
00023         int y,
00024         int w,
00025         int h)
00026  : TimeBar(mwindow, gui, x, y, w, h)
00027 {
00028         this->gui = gui;
00029 }
00030 
00031 
00032 int64_t MTimeBar::position_to_pixel(double position)
00033 {
00034         return (int64_t)(position * 
00035                 mwindow->edl->session->sample_rate / 
00036                 mwindow->edl->local_session->zoom_sample - 
00037                 mwindow->edl->local_session->view_start);
00038 }
00039 
00040 
00041 void MTimeBar::stop_playback()
00042 {
00043         gui->unlock_window();
00044         gui->mbuttons->transport->handle_transport(STOP, 1);
00045         gui->lock_window();
00046 }
00047 
00048 
00049 void MTimeBar::draw_time()
00050 {
00051         draw_range();
00052 
00053 // fit the time
00054         int64_t windowspan = 0;
00055         int64_t timescale1 = 0;
00056         int64_t timescale2 = 0;
00057         int64_t sample_rate = 0;
00058         int64_t sample = 0;
00059         float timescale3 = 0;
00060         int pixel = 0;
00061         char string[BCTEXTLEN];
00062 #define TIMESPACING 100
00063 
00064         sample_rate = mwindow->edl->session->sample_rate;
00065         windowspan = mwindow->edl->local_session->zoom_sample * get_w();
00066         timescale2 = TIMESPACING * mwindow->edl->local_session->zoom_sample;
00067 
00068         if(timescale2 <= sample_rate / 4) timescale1 = sample_rate / 4;
00069         else
00070         if(timescale2 <= sample_rate / 2) timescale1 = sample_rate / 2;
00071         else
00072         if(timescale2 <= sample_rate) timescale1 = sample_rate;
00073         else
00074         if(timescale2 <= sample_rate * 10) timescale1 = sample_rate * 10;
00075         else
00076         if(timescale2 <= sample_rate * 60) timescale1 = sample_rate * 60;
00077         else
00078         if(timescale2 <= sample_rate * 600) timescale1 = sample_rate * 600;
00079         else
00080         timescale1 = sample_rate * 3600;
00081 
00082         for(timescale3 = timescale1; timescale3 > timescale2; timescale3 /= 2)
00083                 ;
00084 
00085         timescale1 = (int64_t)(timescale3 * 2);
00086 
00087         sample = (int64_t)(mwindow->edl->local_session->view_start * 
00088                 mwindow->edl->local_session->zoom_sample + 
00089                 0.5);
00090 
00091         sample /= timescale1;
00092         sample *= timescale1;
00093         pixel = (int64_t)(sample / 
00094                 mwindow->edl->local_session->zoom_sample - 
00095                 mwindow->edl->local_session->view_start);
00096         sample += (int64_t) ((mwindow->edl->session->get_frame_offset() /
00097                                                                 mwindow->edl->session->frame_rate) *
00098                                                                 48000 /
00099                                                                 timescale1 *
00100                                                                 timescale1);
00101 
00102         for( ; pixel < get_w(); pixel += timescale1 / mwindow->edl->local_session->zoom_sample, sample += timescale1)
00103         {
00104                 Units::totext(string, 
00105                         sample, 
00106                         sample_rate, 
00107                         mwindow->edl->session->time_format, 
00108                         mwindow->edl->session->frame_rate,
00109                         mwindow->edl->session->frames_per_foot);
00110                 set_color(get_resources()->default_text_color);
00111                 set_font(MEDIUMFONT);
00112                 draw_text(pixel + 4, get_text_ascent(MEDIUMFONT), string);
00113                 draw_line(pixel, 3, pixel, get_h() - 4);
00114         }
00115 }
00116 
00117 void MTimeBar::draw_range()
00118 {
00119         int x1 = 0, x2 = 0;
00120         if(mwindow->edl->tracks->total_playable_vtracks() &&
00121                 mwindow->preferences->use_brender)
00122         {
00123                 double time_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
00124                         mwindow->edl->session->sample_rate;
00125                 x1 = (int)(mwindow->edl->session->brender_start / time_per_pixel) - 
00126                         mwindow->edl->local_session->view_start;
00127                 x2 = (int)(mwindow->session->brender_end / time_per_pixel) - 
00128                         mwindow->edl->local_session->view_start;
00129         }
00130 
00131         if(x2 > x1 && 
00132                 x1 < get_w() && 
00133                 x2 > 0)
00134         {
00135                 draw_top_background(get_parent(), 0, 0, x1, get_h());
00136                 draw_3segmenth(x1, 0, x2 - x1, mwindow->theme->get_image("timebar_brender"));
00137                 draw_top_background(get_parent(), x2, 0, get_w() - x2, get_h());
00138         }
00139         else
00140                 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
00141 //printf("MTimeBar::draw_range %f %f\n", mwindow->session->brender_end, time_per_pixel);
00142 }
00143 
00144 void MTimeBar::select_label(double position)
00145 {
00146         EDL *edl = mwindow->edl;
00147 
00148         mwindow->gui->unlock_window();
00149         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1);
00150         mwindow->gui->lock_window();
00151 
00152         position = mwindow->edl->align_to_frame(position, 1);
00153 
00154         if(shift_down())
00155         {
00156                 if(position > edl->local_session->get_selectionend(1) / 2 + 
00157                         edl->local_session->get_selectionstart(1) / 2)
00158                 {
00159                 
00160                         edl->local_session->set_selectionend(position);
00161                 }
00162                 else
00163                 {
00164                         edl->local_session->set_selectionstart(position);
00165                 }
00166         }
00167         else
00168         {
00169                 edl->local_session->set_selectionstart(position);
00170                 edl->local_session->set_selectionend(position);
00171         }
00172 
00173 // Que the CWindow
00174         mwindow->cwindow->update(1, 0, 0);
00175         mwindow->gui->cursor->hide();
00176         mwindow->gui->cursor->draw();
00177         mwindow->gui->canvas->activate();
00178         mwindow->gui->zoombar->update();
00179         update_highlights();
00180         mwindow->gui->canvas->flash();
00181 }
00182 
00183 
00184 int MTimeBar::resize_event()
00185 {
00186         reposition_window(mwindow->theme->mtimebar_x,
00187                 mwindow->theme->mtimebar_y,
00188                 mwindow->theme->mtimebar_w,
00189                 mwindow->theme->mtimebar_h);
00190         update();
00191         return 1;
00192 }
00193 
00194 int MTimeBar::test_preview(int buttonpress)
00195 {
00196         int result = 0;
00197         return result;
00198 }
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 

Generated on Sun Jan 8 13:38:57 2006 for Cinelerra-svn by  doxygen 1.4.4