r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / ctracking.C
blobf5e58d8d83f979cd3766a419a4e0921e29db8a4e
1 #include "bcsignals.h"
2 #include "cplayback.h"
3 #include "ctimebar.h"
4 #include "ctracking.h"
5 #include "cwindow.h"
6 #include "cwindowgui.h"
7 #include "edl.h"
8 #include "edlsession.h"
9 #include "localsession.h"
10 #include "mainclock.h"
11 #include "mwindow.h"
12 #include "mwindowgui.h"
13 #include "patchbay.h"
14 #include "trackcanvas.h"
15 #include "transportque.h"
16 #include "zoombar.h"
18 CTracking::CTracking(MWindow *mwindow, CWindow *cwindow)
19  : Tracking(mwindow)
21         this->cwindow = cwindow;
24 CTracking::~CTracking()
28 PlaybackEngine* CTracking::get_playback_engine()
30         return cwindow->playback_engine;
33 int CTracking::start_playback(double new_position)
35         mwindow->gui->cursor->playing_back = 1;
37         Tracking::start_playback(new_position);
38         return 0;
41 int CTracking::stop_playback()
43         mwindow->gui->cursor->playing_back = 0;
46         Tracking::stop_playback();
47         return 0;
50 #define SCROLL_THRESHOLD 0
53 int CTracking::update_scroll(double position)
55         int updated_scroll = 0;
57         if(mwindow->edl->session->view_follows_playback)
58         {
59                 double seconds_per_pixel = (double)mwindow->edl->local_session->zoom_sample / 
60                         mwindow->edl->session->sample_rate;
61                 double half_canvas = seconds_per_pixel * 
62                         mwindow->gui->canvas->get_w() / 2;
63                 double midpoint = mwindow->edl->local_session->view_start * 
64                         seconds_per_pixel +
65                         half_canvas;
67                 if(get_playback_engine()->command->get_direction() == PLAY_FORWARD)
68                 {
69                         double left_boundary = midpoint + SCROLL_THRESHOLD * half_canvas;
70                         double right_boundary = midpoint + half_canvas;
72                         if(position > left_boundary &&
73                                 position < right_boundary)
74                         {
75                                 int pixels = Units::to_int64((position - midpoint) * 
76                                         mwindow->edl->session->sample_rate /
77                                         mwindow->edl->local_session->zoom_sample);
78                                 if(pixels) 
79                                 {
80                                         mwindow->move_right(pixels);
81 //printf("CTracking::update_scroll 1 %d\n", pixels);
82                                         updated_scroll = 1;
83                                 }
84                         }
85                 }
86                 else
87                 {
88                         double right_boundary = midpoint - SCROLL_THRESHOLD * half_canvas;
89                         double left_boundary = midpoint - half_canvas;
91                         if(position < right_boundary &&
92                                 position > left_boundary && 
93                                 mwindow->edl->local_session->view_start > 0)
94                         {
95                                 int pixels = Units::to_int64((midpoint - position) * 
96                                                 mwindow->edl->session->sample_rate /
97                                                 mwindow->edl->local_session->zoom_sample);
98                                 if(pixels) 
99                                 {
100                                         mwindow->move_left(pixels);
101                                         updated_scroll = 1;
102                                 }
103                         }
104                 }
105         }
107         return updated_scroll;
110 void CTracking::update_tracker(double position)
112         int updated_scroll = 0;
113 // Update cwindow slider
114 //TRACE("CTracking::update_tracker 1");
115         cwindow->gui->lock_window("CTracking::update_tracker 1");
116 //TRACE("CTracking::update_tracker 2");
117         cwindow->gui->slider->update(position);
119 // This is going to boost the latency but we need to update the timebar
120         cwindow->gui->timebar->draw_range();
121         cwindow->gui->timebar->flash();
122         cwindow->gui->unlock_window();
123 //TRACE("CTracking::update_tracker 3");
125 // Update mwindow cursor
126         mwindow->gui->lock_window("CTracking::update_tracker 2");
127 //TRACE("CTracking::update_tracker 4");
129         mwindow->edl->local_session->selectionstart = 
130                 mwindow->edl->local_session->selectionend = 
131                 position;
133         updated_scroll = update_scroll(position);
134 //TRACE("CTracking::update_tracker 5");
136         mwindow->gui->mainclock->update(position);
137 //TRACE("CTracking::update_tracker 5.5");
138         mwindow->gui->patchbay->update();
139 //TRACE("CTracking::update_tracker 6");
141         if(!updated_scroll)
142         {
143                 mwindow->gui->cursor->update();
144                 mwindow->gui->zoombar->update();
147                 mwindow->gui->canvas->flash();
148                 mwindow->gui->flush();
149         }
150         mwindow->gui->unlock_window();
151 //TRACE("CTracking::update_tracker 7");
153 // Plugin GUI's hold lock on mwindow->gui here during user interface handlers.
154         mwindow->update_plugin_guis();
155 //TRACE("CTracking::update_tracker 8");
158         update_meters((int64_t)(position * mwindow->edl->session->sample_rate));
159 //TRACE("CTracking::update_tracker 9");
162 void CTracking::draw()