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->mwindow = mwindow;
56 startup_lock = new Condition(0, "Tracking::startup_lock");
65 // Not working in NPTL for some reason
73 void Tracking::create_objects()
78 int Tracking::start_playback(double new_position)
82 last_position = new_position;
86 startup_lock->lock("Tracking::start_playback");
91 int Tracking::stop_playback()
97 // Not working in NPTL for some reason
101 mwindow->stop_mixers();
102 // Final position is updated continuously during playback
103 // Get final position
104 double position = get_tracking_position();
106 update_tracker(position);
113 PlaybackEngine* Tracking::get_playback_engine()
115 return mwindow->cwindow->playback_engine;
118 double Tracking::get_tracking_position()
120 return get_playback_engine()->get_tracking_position();
123 void Tracking::update_meters(int64_t position)
125 double output_levels[MAXCHANNELS];
126 int do_audio = get_playback_engine()->get_output_levels(output_levels, position);
130 module_levels.remove_all();
131 get_playback_engine()->get_module_levels(&module_levels, position);
133 mwindow->cwindow->gui->lock_window("Tracking::update_meters 1");
134 mwindow->cwindow->gui->meters->update(output_levels);
135 mwindow->cwindow->gui->unlock_window();
137 mwindow->lwindow->gui->lock_window("Tracking::update_meters 2");
138 mwindow->lwindow->gui->panel->update(output_levels);
139 mwindow->lwindow->gui->unlock_window();
141 mwindow->gui->lock_window("Tracking::update_meters 3");
142 mwindow->gui->update_meters(&module_levels);
143 mwindow->gui->unlock_window();
147 void Tracking::stop_meters()
149 mwindow->cwindow->gui->lock_window("Tracking::stop_meters 1");
150 mwindow->cwindow->gui->meters->stop_meters();
151 mwindow->cwindow->gui->unlock_window();
153 mwindow->gui->lock_window("Tracking::stop_meters 2");
154 mwindow->gui->stop_meters();
155 mwindow->gui->unlock_window();
157 mwindow->lwindow->gui->lock_window("Tracking::stop_meters 3");
158 mwindow->lwindow->gui->panel->stop_meters();
159 mwindow->lwindow->gui->unlock_window();
165 void Tracking::update_tracker(double position)
169 void Tracking::draw()
171 // gui->lock_window("Tracking::draw");
174 // pixel = get_pixel(last_position);
177 // gui->canvas->set_color(GREEN);
178 // gui->canvas->set_inverse();
179 // gui->canvas->draw_line(pixel, 0, pixel, gui->canvas->get_h());
180 // gui->canvas->set_opaque();
181 // gui->canvas->flash(pixel, 0, pixel + 1, gui->canvas->get_h());
183 // gui->unlock_window();
189 startup_lock->unlock();
194 Thread::enable_cancel();
195 timer.delay(1000 / TRACKING_RATE);
196 Thread::disable_cancel();
201 // can be stopped during wait
202 if(get_playback_engine()->tracking_active)
204 // Get position of cursor
205 position = get_tracking_position();
208 update_tracker(position);