4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcsignals.h"
23 #include "cplayback.h"
25 #include "ctracking.h"
27 #include "cwindowgui.h"
29 #include "edlsession.h"
30 #include "localsession.h"
31 #include "mainclock.h"
32 #include "maincursor.h"
35 #include "mwindowgui.h"
37 #include "trackcanvas.h"
38 #include "transportque.h"
41 CTracking::CTracking(MWindow *mwindow, CWindow *cwindow)
44 this->cwindow = cwindow;
47 CTracking::~CTracking()
51 PlaybackEngine* CTracking::get_playback_engine()
53 return cwindow->playback_engine;
56 int CTracking::start_playback(double new_position, int active)
58 mwindow->gui->set_playing_back(1);
60 mwindow->edl->local_session->set_playback_start(new_position);
61 return Tracking::start_playback(new_position);
64 int CTracking::stop_playback()
66 mwindow->gui->set_playing_back(0);
67 Tracking::stop_playback();
68 mwindow->edl->local_session->set_playback_end(get_tracking_position());
72 #define SCROLL_THRESHOLD .5
75 int CTracking::update_scroll(double position)
77 int updated_scroll = 0;
79 if(mwindow->edl->session->view_follows_playback)
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] *
90 if(get_playback_engine()->command->get_direction() == PLAY_FORWARD)
92 double left_boundary = midpoint + SCROLL_THRESHOLD * half_canvas;
93 double right_boundary = midpoint + half_canvas;
95 if(position > left_boundary &&
96 position < right_boundary)
98 int pixels = Units::to_int64((position - left_boundary) *
99 mwindow->edl->session->sample_rate /
100 mwindow->edl->local_session->zoom_sample);
103 mwindow->move_right(pixels);
104 //printf("CTracking::update_scroll 1 %d\n", pixels);
111 double right_boundary = midpoint - SCROLL_THRESHOLD * half_canvas;
112 double left_boundary = midpoint - half_canvas;
114 if(position < right_boundary &&
115 position > left_boundary &&
116 mwindow->edl->local_session->view_start[pane->number] > 0)
118 int pixels = Units::to_int64((right_boundary - position) *
119 mwindow->edl->session->sample_rate /
120 mwindow->edl->local_session->zoom_sample);
123 mwindow->move_left(pixels);
130 return updated_scroll;
133 void CTracking::update_tracker(double position)
135 int updated_scroll = 0;
136 cwindow->gui->lock_window("CTracking::update_tracker 1");
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();
143 // Update mwindow cursor
144 mwindow->gui->lock_window("CTracking::update_tracker 2");
146 mwindow->edl->local_session->set_selectionstart(position);
147 mwindow->edl->local_session->set_selectionend(position);
149 updated_scroll = update_scroll(position);
151 mwindow->gui->mainclock->update(position);
152 mwindow->gui->update_patchbay();
153 mwindow->gui->update_timebar(0);
157 mwindow->gui->update_cursor();
158 // we just need to update clocks, not everything
159 mwindow->gui->zoombar->update_clocks();
161 for(int i = 0; i < TOTAL_PANES; i++)
162 if(mwindow->gui->pane[i])
163 mwindow->gui->pane[i]->canvas->flash(0);
166 mwindow->gui->flush();
167 mwindow->gui->unlock_window();
169 // Plugin GUI's hold lock on mwindow->gui here during user interface handlers.
170 mwindow->update_plugin_guis();
173 update_meters((int64_t)(position * mwindow->edl->session->sample_rate));
176 void CTracking::draw()