5 #include "cwindowgui.h"
7 #include "edlsession.h"
8 #include "levelwindow.h"
9 #include "levelwindowgui.h"
10 #include "localsession.h"
11 #include "mainclock.h"
12 #include "meterpanel.h"
14 #include "mwindowgui.h"
17 #include "playbackengine.h"
18 #include "renderengine.h"
19 #include "mainsession.h"
20 #include "trackcanvas.h"
30 Tracking::Tracking(MWindow *mwindow)
33 this->gui = mwindow->gui;
34 this->mwindow = mwindow;
39 startup_lock = new Condition(0, "Tracking::startup_lock");
48 // Not working in NPTL for some reason
57 void Tracking::create_objects()
62 int Tracking::start_playback(double new_position)
66 last_position = new_position;
70 startup_lock->lock("Tracking::start_playback");
75 int Tracking::stop_playback()
81 // Not working in NPTL for some reason
85 // Final position is updated continuously during playback
87 double position = get_tracking_position();
89 update_tracker(position);
97 PlaybackEngine* Tracking::get_playback_engine()
99 return mwindow->cwindow->playback_engine;
102 double Tracking::get_tracking_position()
104 return get_playback_engine()->get_tracking_position();
107 int Tracking::get_pixel(double position)
109 return (int64_t)((position - mwindow->edl->local_session->view_start) *
110 mwindow->edl->session->sample_rate /
111 mwindow->edl->local_session->zoom_sample +
116 void Tracking::update_meters(int64_t position)
118 double output_levels[MAXCHANNELS];
119 int do_audio = get_playback_engine()->get_output_levels(output_levels, position);
123 module_levels.remove_all();
124 get_playback_engine()->get_module_levels(&module_levels, position);
126 mwindow->cwindow->gui->lock_window("Tracking::update_meters 1");
127 mwindow->cwindow->gui->meters->update(output_levels);
128 mwindow->cwindow->gui->unlock_window();
130 mwindow->lwindow->gui->lock_window("Tracking::update_meters 2");
131 mwindow->lwindow->gui->panel->update(output_levels);
132 mwindow->lwindow->gui->unlock_window();
134 mwindow->gui->lock_window("Tracking::update_meters 3");
135 mwindow->gui->patchbay->update_meters(&module_levels);
136 mwindow->gui->unlock_window();
140 void Tracking::stop_meters()
142 mwindow->cwindow->gui->lock_window("Tracking::stop_meters 1");
143 mwindow->cwindow->gui->meters->stop_meters();
144 mwindow->cwindow->gui->unlock_window();
146 mwindow->gui->lock_window("Tracking::stop_meters 2");
147 mwindow->gui->patchbay->stop_meters();
148 mwindow->gui->unlock_window();
150 mwindow->lwindow->gui->lock_window("Tracking::stop_meters 3");
151 mwindow->lwindow->gui->panel->stop_meters();
152 mwindow->lwindow->gui->unlock_window();
158 void Tracking::update_tracker(double position)
162 void Tracking::draw()
164 gui->lock_window("Tracking::draw");
167 pixel = get_pixel(last_position);
170 gui->canvas->set_color(GREEN);
171 gui->canvas->set_inverse();
172 gui->canvas->draw_line(pixel, 0, pixel, gui->canvas->get_h());
173 gui->canvas->set_opaque();
174 gui->canvas->flash(pixel, 0, pixel + 1, gui->canvas->get_h());
176 gui->unlock_window();
182 startup_lock->unlock();
187 Thread::enable_cancel();
188 timer.delay(1000 / TRACKING_RATE);
189 Thread::disable_cancel();
194 // can be stopped during wait
195 if(get_playback_engine()->tracking_active)
197 // Get position of cursor
198 position = get_tracking_position();
201 update_tracker(position);