4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
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.
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.
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
23 #include "bcsignals.h"
24 #include "cplayback.h"
26 #include "ctracking.h"
28 #include "cwindowgui.h"
30 #include "edlsession.h"
31 #include "localsession.h"
32 #include "mainclock.h"
33 #include "maincursor.h"
36 #include "mwindowgui.h"
38 #include "trackcanvas.h"
39 #include "transportque.h"
42 CTracking::CTracking(MWindow *mwindow, CWindow *cwindow)
45 this->cwindow = cwindow;
48 CTracking::~CTracking()
52 PlaybackEngine* CTracking::get_playback_engine()
54 return cwindow->playback_engine;
57 int CTracking::start_playback(double new_position, int active)
59 mwindow->gui->set_playing_back(1);
61 mwindow->edl->local_session->set_playback_start(new_position);
62 return Tracking::start_playback(new_position);
65 int CTracking::stop_playback()
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());
74 #define SCROLL_THRESHOLD .5
77 int CTracking::update_scroll(double position)
79 int updated_scroll = 0;
81 if(mwindow->edl->session->view_follows_playback)
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] *
92 if(get_playback_engine()->command->get_direction() == PLAY_FORWARD)
94 double left_boundary = midpoint + SCROLL_THRESHOLD * half_canvas;
95 double right_boundary = midpoint + half_canvas;
97 if(position > left_boundary &&
98 position < right_boundary)
100 int pixels = Units::to_int64((position - left_boundary) *
101 mwindow->edl->session->sample_rate /
102 mwindow->edl->local_session->zoom_sample);
105 mwindow->move_right(pixels);
106 //printf("CTracking::update_scroll 1 %d\n", pixels);
113 double right_boundary = midpoint - SCROLL_THRESHOLD * half_canvas;
114 double left_boundary = midpoint - half_canvas;
116 if(position < right_boundary &&
117 position > left_boundary &&
118 mwindow->edl->local_session->view_start[pane->number] > 0)
120 int pixels = Units::to_int64((right_boundary - position) *
121 mwindow->edl->session->sample_rate /
122 mwindow->edl->local_session->zoom_sample);
125 mwindow->move_left(pixels);
132 return updated_scroll;
135 void CTracking::update_tracker(double position)
137 int updated_scroll = 0;
138 cwindow->gui->lock_window("CTracking::update_tracker 1");
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();
145 // Update mwindow cursor
146 mwindow->gui->lock_window("CTracking::update_tracker 2");
148 mwindow->edl->local_session->set_selectionstart(position);
149 mwindow->edl->local_session->set_selectionend(position);
151 updated_scroll = update_scroll(position);
153 mwindow->gui->mainclock->update(position);
154 mwindow->gui->update_patchbay();
155 mwindow->gui->update_timebar(0);
159 mwindow->gui->update_cursor();
160 // we just need to update clocks, not everything
161 mwindow->gui->zoombar->update_clocks();
163 for(int i = 0; i < TOTAL_PANES; i++)
164 if(mwindow->gui->pane[i])
165 mwindow->gui->pane[i]->canvas->flash(0);
168 mwindow->gui->flush();
169 mwindow->gui->unlock_window();
171 // Plugin GUI's hold lock on mwindow->gui here during user interface handlers.
172 mwindow->update_plugin_guis();
175 update_meters((int64_t)(position * mwindow->edl->session->sample_rate));
178 void CTracking::draw()