+void
+Timeline::assign_tracks ()
+{
+ for (list<shared_ptr<View> >::iterator i = _views.begin(); i != _views.end(); ++i) {
+ shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
+ if (cv) {
+ cv->set_track (0);
+ _tracks = 1;
+ }
+ }
+
+ for (list<shared_ptr<View> >::iterator i = _views.begin(); i != _views.end(); ++i) {
+ shared_ptr<AudioContentView> acv = dynamic_pointer_cast<AudioContentView> (*i);
+ if (!acv) {
+ continue;
+ }
+
+ shared_ptr<Content> acv_content = acv->content().lock ();
+ assert (acv_content);
+
+ int t = 1;
+ while (1) {
+ list<shared_ptr<View> >::iterator j = _views.begin();
+ while (j != _views.end()) {
+ shared_ptr<AudioContentView> test = dynamic_pointer_cast<AudioContentView> (*j);
+ if (!test) {
+ ++j;
+ continue;
+ }
+
+ shared_ptr<Content> test_content = test->content().lock ();
+ assert (test_content);
+
+ if (test && test->track() == t) {
+ if ((acv_content->start() <= test_content->start() && test_content->start() <= acv_content->end()) ||
+ (acv_content->start() <= test_content->end() && test_content->end() <= acv_content->end())) {
+ /* we have an overlap on track `t' */
+ ++t;
+ break;
+ }
+ }
+
+ ++j;
+ }
+
+ if (j == _views.end ()) {
+ /* no overlap on `t' */
+ break;
+ }
+ }
+
+ acv->set_track (t);
+ _tracks = max (_tracks, t + 1);
+ }
+
+ _time_axis_view->set_y (tracks() * track_height() + 32);
+}
+