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

tracking.C

Go to the documentation of this file.
00001 #include "arender.h"
00002 #include "condition.h"
00003 #include "cplayback.h"
00004 #include "cwindow.h"
00005 #include "cwindowgui.h"
00006 #include "edl.h"
00007 #include "edlsession.h"
00008 #include "levelwindow.h"
00009 #include "levelwindowgui.h"
00010 #include "localsession.h"
00011 #include "mainclock.h"
00012 #include "meterpanel.h"
00013 #include "mwindow.h"
00014 #include "mwindowgui.h"
00015 #include "tracking.h"
00016 #include "patchbay.h"
00017 #include "playbackengine.h"
00018 #include "renderengine.h"
00019 #include "mainsession.h"
00020 #include "trackcanvas.h"
00021 
00022 
00023 
00024 // States
00025 #define PLAYING 0
00026 #define DONE 1
00027 
00028 
00029 
00030 Tracking::Tracking(MWindow *mwindow)
00031  : Thread(1, 0, 0)
00032 {
00033         this->gui = mwindow->gui;
00034         this->mwindow = mwindow; 
00035         follow_loop = 0; 
00036         visible = 0;
00037         pixel = 0;
00038         state = DONE;
00039         startup_lock = new Condition(0, "Tracking::startup_lock");
00040 }
00041 
00042 Tracking::~Tracking()
00043 {
00044         if(state == PLAYING)
00045         {
00046 // Stop loop
00047                 state = DONE;
00048 // Not working in NPTL for some reason
00049 //              Thread::cancel();
00050                 Thread::join();
00051         }
00052 
00053 
00054         delete startup_lock;
00055 }
00056 
00057 void Tracking::create_objects()
00058 {
00059 //      start();
00060 }
00061 
00062 int Tracking::start_playback(double new_position)
00063 {
00064         if(state != PLAYING)
00065         {
00066                 last_position = new_position;
00067                 state = PLAYING;
00068                 draw();
00069                 Thread::start();
00070                 startup_lock->lock("Tracking::start_playback");
00071         }
00072         return 0;
00073 }
00074 
00075 int Tracking::stop_playback()
00076 {
00077         if(state != DONE)
00078         {
00079 // Stop loop
00080                 state = DONE;
00081 // Not working in NPTL for some reason
00082 //              Thread::cancel();
00083                 Thread::join();
00084 
00085 // Final position is updated continuously during playback
00086 // Get final position
00087                 double position = get_tracking_position();
00088 // Update cursor
00089                 update_tracker(position);
00090         
00091                 stop_meters();
00092                 state = DONE;
00093         }
00094         return 0;
00095 }
00096 
00097 PlaybackEngine* Tracking::get_playback_engine()
00098 {
00099         return mwindow->cwindow->playback_engine;
00100 }
00101 
00102 double Tracking::get_tracking_position()
00103 {
00104         return get_playback_engine()->get_tracking_position();
00105 }
00106 
00107 int Tracking::get_pixel(double position)
00108 {
00109         return (int64_t)((position - mwindow->edl->local_session->view_start) *
00110                 mwindow->edl->session->sample_rate / 
00111                 mwindow->edl->local_session->zoom_sample + 
00112                 0.5);
00113 }
00114 
00115 
00116 void Tracking::update_meters(int64_t position)
00117 {
00118         double output_levels[MAXCHANNELS];
00119         int do_audio = get_playback_engine()->get_output_levels(output_levels, position);
00120 
00121         if(do_audio)
00122         {
00123                 module_levels.remove_all();
00124                 get_playback_engine()->get_module_levels(&module_levels, position);
00125 
00126                 mwindow->cwindow->gui->lock_window("Tracking::update_meters 1");
00127                 mwindow->cwindow->gui->meters->update(output_levels);
00128                 mwindow->cwindow->gui->unlock_window();
00129 
00130                 mwindow->lwindow->gui->lock_window("Tracking::update_meters 2");
00131                 mwindow->lwindow->gui->panel->update(output_levels);
00132                 mwindow->lwindow->gui->unlock_window();
00133 
00134                 mwindow->gui->lock_window("Tracking::update_meters 3");
00135                 mwindow->gui->patchbay->update_meters(&module_levels);
00136                 mwindow->gui->unlock_window();
00137         }
00138 }
00139 
00140 void Tracking::stop_meters()
00141 {
00142         mwindow->cwindow->gui->lock_window("Tracking::stop_meters 1");
00143         mwindow->cwindow->gui->meters->stop_meters();
00144         mwindow->cwindow->gui->unlock_window();
00145 
00146         mwindow->gui->lock_window("Tracking::stop_meters 2");
00147         mwindow->gui->patchbay->stop_meters();
00148         mwindow->gui->unlock_window();
00149 
00150         mwindow->lwindow->gui->lock_window("Tracking::stop_meters 3");
00151         mwindow->lwindow->gui->panel->stop_meters();
00152         mwindow->lwindow->gui->unlock_window();
00153 }
00154 
00155 
00156 
00157 
00158 void Tracking::update_tracker(double position)
00159 {
00160 }
00161 
00162 void Tracking::draw()
00163 {
00164         gui->lock_window("Tracking::draw");
00165         if(!visible)
00166         {
00167                 pixel = get_pixel(last_position);
00168         }
00169 
00170         gui->canvas->set_color(GREEN);
00171         gui->canvas->set_inverse();
00172         gui->canvas->draw_line(pixel, 0, pixel, gui->canvas->get_h());
00173         gui->canvas->set_opaque();
00174         gui->canvas->flash(pixel, 0, pixel + 1, gui->canvas->get_h());
00175         visible ^= 1;
00176         gui->unlock_window();
00177 }
00178 
00179 
00180 void Tracking::run()
00181 {
00182         startup_lock->unlock();
00183 
00184         double position;
00185         while(state != DONE)
00186         {
00187                 Thread::enable_cancel();
00188                 timer.delay(1000 / TRACKING_RATE);
00189                 Thread::disable_cancel();
00190 
00191                 if(state != DONE)
00192                 {
00193 
00194 // can be stopped during wait
00195                         if(get_playback_engine()->tracking_active)
00196                         {
00197 // Get position of cursor
00198                                 position = get_tracking_position();
00199 
00200 // Update cursor
00201                                 update_tracker(position);
00202                         }
00203                 }
00204         }
00205 }
00206 
00207 
00208 
00209 
00210 

Generated on Sun Jan 8 13:39:01 2006 for Cinelerra-svn by  doxygen 1.4.4