r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / ctracking.C
blob561169fd9e018a8656107cab8d61eb147d9941f4
1 #include "cplayback.h"
2 #include "ctimebar.h"
3 #include "ctracking.h"
4 #include "cwindow.h"
5 #include "cwindowgui.h"
6 #include "edl.h"
7 #include "edlsession.h"
8 #include "localsession.h"
9 #include "mainclock.h"
10 #include "mwindow.h"
11 #include "mwindowgui.h"
12 #include "patchbay.h"
13 #include "trackcanvas.h"
14 #include "transportque.h"
15 #include "zoombar.h"
17 CTracking::CTracking(MWindow *mwindow, CWindow *cwindow)
18  : Tracking(mwindow)
20         this->cwindow = cwindow;
23 CTracking::~CTracking()
27 PlaybackEngine* CTracking::get_playback_engine()
29         return cwindow->playback_engine;
32 int CTracking::start_playback(double new_position)
34         mwindow->gui->cursor->playing_back = 1;
36         Tracking::start_playback(new_position);
37         return 0;
40 int CTracking::stop_playback()
42         mwindow->gui->cursor->playing_back = 0;
45         Tracking::stop_playback();
46         return 0;
49 #define SCROLL_THRESHOLD 0
52 int CTracking::update_scroll(double position)
54         int updated_scroll = 0;
56         if(mwindow->edl->session->view_follows_playback)
57         {
58                 double seconds_per_pixel = (double)mwindow->edl->local_session->zoom_sample / 
59                         mwindow->edl->session->sample_rate;
60                 double half_canvas = seconds_per_pixel * 
61                         mwindow->gui->canvas->get_w() / 2;
62                 double midpoint = mwindow->edl->local_session->view_start * 
63                         seconds_per_pixel +
64                         half_canvas;
66                 if(get_playback_engine()->command->get_direction() == PLAY_FORWARD)
67                 {
68                         double left_boundary = midpoint + SCROLL_THRESHOLD * half_canvas;
69                         double right_boundary = midpoint + half_canvas;
71                         if(position > left_boundary &&
72                                 position < right_boundary)
73                         {
74                                 int pixels = Units::to_int64((position - midpoint) * 
75                                         mwindow->edl->session->sample_rate /
76                                         mwindow->edl->local_session->zoom_sample);
77                                 if(pixels) 
78                                 {
79                                         mwindow->move_right(pixels);
80 //printf("CTracking::update_scroll 1 %d\n", pixels);
81                                         updated_scroll = 1;
82                                 }
83                         }
84                 }
85                 else
86                 {
87                         double right_boundary = midpoint - SCROLL_THRESHOLD * half_canvas;
88                         double left_boundary = midpoint - half_canvas;
90                         if(position < right_boundary &&
91                                 position > left_boundary && 
92                                 mwindow->edl->local_session->view_start > 0)
93                         {
94                                 int pixels = Units::to_int64((midpoint - position) * 
95                                                 mwindow->edl->session->sample_rate /
96                                                 mwindow->edl->local_session->zoom_sample);
97                                 if(pixels) 
98                                 {
99                                         mwindow->move_left(pixels);
100                                         updated_scroll = 1;
101                                 }
102                         }
103                 }
104         }
106         return updated_scroll;
109 void CTracking::update_tracker(double position)
111         int updated_scroll = 0;
112 // Update cwindow slider
113         cwindow->gui->lock_window();
114         cwindow->gui->slider->update(position);
116 // This is going to boost the latency but we need to update the timebar
117         cwindow->gui->timebar->draw_range();
118         cwindow->gui->timebar->flash();
119         cwindow->gui->unlock_window();
121 // Update mwindow cursor
122         mwindow->gui->lock_window();
124         mwindow->edl->local_session->selectionstart = 
125                 mwindow->edl->local_session->selectionend = 
126                 position;
128         updated_scroll = update_scroll(position);
130         mwindow->gui->mainclock->update(position);
131         mwindow->gui->patchbay->update();
133         if(!updated_scroll)
134         {
135                 mwindow->gui->cursor->update();
136                 mwindow->gui->zoombar->update();
139                 mwindow->gui->canvas->flash();
140                 mwindow->gui->flush();
141         }
142         mwindow->gui->unlock_window();
144 // Plugin GUI's hold lock on mwindow->gui here during user interface handlers.
145         mwindow->update_plugin_guis();
148         update_meters((int64_t)(position * mwindow->edl->session->sample_rate));
151 void CTracking::draw()