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