update SVT-AV1 to latest version of 2.3.0 from 2.2.1
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / ctracking.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "bcsignals.h"
24 #include "cplayback.h"
25 #include "ctimebar.h"
26 #include "ctracking.h"
27 #include "cwindow.h"
28 #include "cwindowgui.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "localsession.h"
32 #include "mainclock.h"
33 #include "maincursor.h"
34 #include "mtimebar.h"
35 #include "mwindow.h"
36 #include "mwindowgui.h"
37 #include "patchbay.h"
38 #include "trackcanvas.h"
39 #include "transportque.h"
40 #include "zoombar.h"
41
42 CTracking::CTracking(MWindow *mwindow, CWindow *cwindow)
43  : Tracking(mwindow)
44 {
45         this->cwindow = cwindow;
46 }
47
48 CTracking::~CTracking()
49 {
50 }
51
52 PlaybackEngine* CTracking::get_playback_engine()
53 {
54         return cwindow->playback_engine;
55 }
56
57 int CTracking::start_playback(double new_position, int active)
58 {
59         mwindow->gui->set_playing_back(1);
60         if( active )
61                 mwindow->edl->local_session->set_playback_start(new_position);
62         return Tracking::start_playback(new_position);
63 }
64
65 int CTracking::stop_playback()
66 {
67         mwindow->gui->set_playing_back(0);
68         Tracking::stop_playback();
69         mwindow->stop_plugin_guis();
70         mwindow->edl->local_session->set_playback_end(get_tracking_position());
71         return 0;
72 }
73
74 #define SCROLL_THRESHOLD .5
75
76
77 int CTracking::update_scroll(double position)
78 {
79         int updated_scroll = 0;
80
81         if(mwindow->edl->session->view_follows_playback)
82         {
83                 TimelinePane *pane = mwindow->gui->get_focused_pane();
84                 double seconds_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
85                         mwindow->edl->session->sample_rate;
86                 double half_canvas = seconds_per_pixel *
87                         pane->canvas->get_w() / 2;
88                 double midpoint = mwindow->edl->local_session->view_start[pane->number] *
89                         seconds_per_pixel +
90                         half_canvas;
91
92                 if(get_playback_engine()->command->get_direction() == PLAY_FORWARD)
93                 {
94                         double left_boundary = midpoint + SCROLL_THRESHOLD * half_canvas;
95                         double right_boundary = midpoint + half_canvas;
96
97                         if(position > left_boundary &&
98                                 position < right_boundary)
99                         {
100                                 int pixels = Units::to_int64((position - left_boundary) *
101                                                 mwindow->edl->session->sample_rate /
102                                                 mwindow->edl->local_session->zoom_sample);
103                                 if(pixels)
104                                 {
105                                         mwindow->move_right(pixels);
106 //printf("CTracking::update_scroll 1 %d\n", pixels);
107                                         updated_scroll = 1;
108                                 }
109                         }
110                 }
111                 else
112                 {
113                         double right_boundary = midpoint - SCROLL_THRESHOLD * half_canvas;
114                         double left_boundary = midpoint - half_canvas;
115
116                         if(position < right_boundary &&
117                                 position > left_boundary &&
118                                 mwindow->edl->local_session->view_start[pane->number] > 0)
119                         {
120                                 int pixels = Units::to_int64((right_boundary - position) *
121                                                 mwindow->edl->session->sample_rate /
122                                                 mwindow->edl->local_session->zoom_sample);
123                                 if(pixels)
124                                 {
125                                         mwindow->move_left(pixels);
126                                         updated_scroll = 1;
127                                 }
128                         }
129                 }
130         }
131
132         return updated_scroll;
133 }
134
135 void CTracking::update_tracker(double position)
136 {
137         int updated_scroll = 0;
138         cwindow->gui->lock_window("CTracking::update_tracker 1");
139
140 // This is going to boost the latency but we need to update the timebar
141         cwindow->gui->timebar->update(1);
142 //      cwindow->gui->timebar->flash();
143         cwindow->gui->unlock_window();
144
145 // Update mwindow cursor
146         mwindow->gui->lock_window("CTracking::update_tracker 2");
147
148         mwindow->edl->local_session->set_selectionstart(position);
149         mwindow->edl->local_session->set_selectionend(position);
150
151         updated_scroll = update_scroll(position);
152
153         mwindow->gui->mainclock->update(position);
154         mwindow->gui->update_patchbay();
155         mwindow->gui->update_timebar(0);
156
157         if(!updated_scroll)
158         {
159                 mwindow->gui->update_cursor();
160                 // we just need to update clocks, not everything
161                 mwindow->gui->zoombar->update_clocks();
162
163                 for(int i = 0; i < TOTAL_PANES; i++)
164                         if(mwindow->gui->pane[i])
165                                 mwindow->gui->pane[i]->canvas->flash(0);
166         }
167
168         mwindow->gui->flush();
169         mwindow->gui->unlock_window();
170
171 // Plugin GUI's hold lock on mwindow->gui here during user interface handlers.
172         mwindow->update_plugin_guis();
173
174
175         update_meters((int64_t)(position * mwindow->edl->session->sample_rate));
176 }
177
178 void CTracking::draw()
179 {
180 }