4 * Copyright (C) 1997-2014 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
23 #include "condition.h"
24 #include "cplayback.h"
26 #include "cwindowgui.h"
28 #include "edlsession.h"
29 #include "levelwindow.h"
30 #include "levelwindowgui.h"
31 #include "localsession.h"
32 #include "mainclock.h"
33 #include "meterpanel.h"
35 #include "mwindowgui.h"
38 #include "playbackengine.h"
39 #include "renderengine.h"
40 #include "mainsession.h"
41 #include "trackcanvas.h"
51 Tracking::Tracking(MWindow *mwindow)
54 this->gui = mwindow->gui;
55 this->mwindow = mwindow;
60 startup_lock = new Condition(0, "Tracking::startup_lock");
69 // Not working in NPTL for some reason
78 void Tracking::create_objects()
83 int Tracking::start_playback(double new_position)
87 last_position = new_position;
91 startup_lock->lock("Tracking::start_playback");
96 int Tracking::stop_playback()
102 // Not working in NPTL for some reason
106 // Final position is updated continuously during playback
107 // Get final position
108 double position = get_tracking_position();
110 update_tracker(position);
118 PlaybackEngine* Tracking::get_playback_engine()
120 return mwindow->cwindow->playback_engine;
123 double Tracking::get_tracking_position()
125 return get_playback_engine()->get_tracking_position();
128 //int Tracking::get_pixel(double position)
130 // return (int64_t)((position - mwindow->edl->local_session->view_start) *
131 // mwindow->edl->session->sample_rate /
132 // mwindow->edl->local_session->zoom_sample +
137 void Tracking::update_meters(int64_t position)
139 double output_levels[MAXCHANNELS];
140 int do_audio = get_playback_engine()->get_output_levels(output_levels, position);
144 module_levels.remove_all();
145 get_playback_engine()->get_module_levels(&module_levels, position);
147 mwindow->cwindow->gui->lock_window("Tracking::update_meters 1");
148 mwindow->cwindow->gui->meters->update(output_levels);
149 mwindow->cwindow->gui->unlock_window();
151 mwindow->lwindow->gui->lock_window("Tracking::update_meters 2");
152 mwindow->lwindow->gui->panel->update(output_levels);
153 mwindow->lwindow->gui->unlock_window();
155 mwindow->gui->lock_window("Tracking::update_meters 3");
156 mwindow->gui->update_meters(&module_levels);
157 mwindow->gui->unlock_window();
161 void Tracking::stop_meters()
163 mwindow->cwindow->gui->lock_window("Tracking::stop_meters 1");
164 mwindow->cwindow->gui->meters->stop_meters();
165 mwindow->cwindow->gui->unlock_window();
167 mwindow->gui->lock_window("Tracking::stop_meters 2");
168 mwindow->gui->stop_meters();
169 mwindow->gui->unlock_window();
171 mwindow->lwindow->gui->lock_window("Tracking::stop_meters 3");
172 mwindow->lwindow->gui->panel->stop_meters();
173 mwindow->lwindow->gui->unlock_window();
179 void Tracking::update_tracker(double position)
183 void Tracking::draw()
185 // gui->lock_window("Tracking::draw");
188 // pixel = get_pixel(last_position);
191 // gui->canvas->set_color(GREEN);
192 // gui->canvas->set_inverse();
193 // gui->canvas->draw_line(pixel, 0, pixel, gui->canvas->get_h());
194 // gui->canvas->set_opaque();
195 // gui->canvas->flash(pixel, 0, pixel + 1, gui->canvas->get_h());
197 // gui->unlock_window();
203 startup_lock->unlock();
208 Thread::enable_cancel();
209 timer.delay(1000 / TRACKING_RATE);
210 Thread::disable_cancel();
215 // can be stopped during wait
216 if(get_playback_engine()->tracking_active)
218 // Get position of cursor
219 position = get_tracking_position();
222 update_tracker(position);