add new boxblur plugin, mods to videoscope, fix segv for menu btns kfrm-tweak/kfrm...
[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  *
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->stop_plugin_guis();
69         mwindow->edl->local_session->set_playback_end(get_tracking_position());
70         return 0;
71 }
72
73 #define SCROLL_THRESHOLD .5
74
75
76 int CTracking::update_scroll(double position)
77 {
78         int updated_scroll = 0;
79
80         if(mwindow->edl->session->view_follows_playback)
81         {
82                 TimelinePane *pane = mwindow->gui->get_focused_pane();
83                 double seconds_per_pixel = (double)mwindow->edl->local_session->zoom_sample /
84                         mwindow->edl->session->sample_rate;
85                 double half_canvas = seconds_per_pixel *
86                         pane->canvas->get_w() / 2;
87                 double midpoint = mwindow->edl->local_session->view_start[pane->number] *
88                         seconds_per_pixel +
89                         half_canvas;
90
91                 if(get_playback_engine()->command->get_direction() == PLAY_FORWARD)
92                 {
93                         double left_boundary = midpoint + SCROLL_THRESHOLD * half_canvas;
94                         double right_boundary = midpoint + half_canvas;
95
96                         if(position > left_boundary &&
97                                 position < right_boundary)
98                         {
99                                 int pixels = Units::to_int64((position - left_boundary) *
100                                                 mwindow->edl->session->sample_rate /
101                                                 mwindow->edl->local_session->zoom_sample);
102                                 if(pixels)
103                                 {
104                                         mwindow->move_right(pixels);
105 //printf("CTracking::update_scroll 1 %d\n", pixels);
106                                         updated_scroll = 1;
107                                 }
108                         }
109                 }
110                 else
111                 {
112                         double right_boundary = midpoint - SCROLL_THRESHOLD * half_canvas;
113                         double left_boundary = midpoint - half_canvas;
114
115                         if(position < right_boundary &&
116                                 position > left_boundary &&
117                                 mwindow->edl->local_session->view_start[pane->number] > 0)
118                         {
119                                 int pixels = Units::to_int64((right_boundary - position) *
120                                                 mwindow->edl->session->sample_rate /
121                                                 mwindow->edl->local_session->zoom_sample);
122                                 if(pixels)
123                                 {
124                                         mwindow->move_left(pixels);
125                                         updated_scroll = 1;
126                                 }
127                         }
128                 }
129         }
130
131         return updated_scroll;
132 }
133
134 void CTracking::update_tracker(double position)
135 {
136         int updated_scroll = 0;
137         cwindow->gui->lock_window("CTracking::update_tracker 1");
138
139 // This is going to boost the latency but we need to update the timebar
140         cwindow->gui->timebar->update(1);
141 //      cwindow->gui->timebar->flash();
142         cwindow->gui->unlock_window();
143
144 // Update mwindow cursor
145         mwindow->gui->lock_window("CTracking::update_tracker 2");
146
147         mwindow->edl->local_session->set_selectionstart(position);
148         mwindow->edl->local_session->set_selectionend(position);
149
150         updated_scroll = update_scroll(position);
151
152         mwindow->gui->mainclock->update(position);
153         mwindow->gui->update_patchbay();
154         mwindow->gui->update_timebar(0);
155
156         if(!updated_scroll)
157         {
158                 mwindow->gui->update_cursor();
159                 // we just need to update clocks, not everything
160                 mwindow->gui->zoombar->update_clocks();
161
162                 for(int i = 0; i < TOTAL_PANES; i++)
163                         if(mwindow->gui->pane[i])
164                                 mwindow->gui->pane[i]->canvas->flash(0);
165         }
166
167         mwindow->gui->flush();
168         mwindow->gui->unlock_window();
169
170 // Plugin GUI's hold lock on mwindow->gui here during user interface handlers.
171         mwindow->update_plugin_guis();
172
173
174         update_meters((int64_t)(position * mwindow->edl->session->sample_rate));
175 }
176
177 void CTracking::draw()
178 {
179 }