From ecbfa72a19756eab3fb1e3b0a9c5cab1c0b2ed39 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 26 May 2013 00:57:55 +0100 Subject: [PATCH] Allow multiple simultaneous audio tracks in the timeline. --- src/wx/film_editor.cc | 1 + src/wx/timeline.cc | 75 ++++++++++++++++++++++++++++++++++++++++--- src/wx/timeline.h | 2 ++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index b67b47b4e..d0522cf73 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -1164,6 +1164,7 @@ FilmEditor::content_selection_changed (wxListEvent &) { setup_content_sensitivity (); shared_ptr s = selected_content (); + film_content_changed (s, ContentProperty::START); film_content_changed (s, VideoContentProperty::VIDEO_CROP); film_content_changed (s, AudioContentProperty::AUDIO_GAIN); film_content_changed (s, AudioContentProperty::AUDIO_DELAY); diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 8c90c3d8c..54f3d75cf 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -111,6 +111,14 @@ public: return _content; } + void set_track (int t) { + _track = t; + } + + int track () const { + return _track; + } + virtual wxString type () const = 0; virtual wxColour colour () const = 0; @@ -307,6 +315,7 @@ private: Timeline::Timeline (wxWindow* parent, shared_ptr film) : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE) , _film (film) + , _tracks (0) , _pixels_per_time_unit (0) , _left_down (false) , _down_view_start (0) @@ -322,10 +331,10 @@ Timeline::Timeline (wxWindow* parent, shared_ptr film) Connect (wxID_ANY, wxEVT_MOTION, wxMouseEventHandler (Timeline::mouse_moved), 0, this); Connect (wxID_ANY, wxEVT_SIZE, wxSizeEventHandler (Timeline::resized), 0, this); - SetMinSize (wxSize (640, tracks() * track_height() + 96)); - playlist_changed (); + SetMinSize (wxSize (640, tracks() * track_height() + 96)); + _playlist_connection = film->playlist()->Changed.connect (bind (&Timeline::playlist_changed, this)); } @@ -365,20 +374,76 @@ Timeline::playlist_changed () _views.push_back (shared_ptr (new VideoContentView (*this, *i, 0))); } if (dynamic_pointer_cast (*i)) { - _views.push_back (shared_ptr (new AudioContentView (*this, *i, 1))); + _views.push_back (shared_ptr (new AudioContentView (*this, *i, 0))); } } + assign_tracks (); + _views.push_back (shared_ptr (new TimeAxisView (*this, tracks() * track_height() + 32))); Refresh (); } +void +Timeline::assign_tracks () +{ + for (list >::iterator i = _views.begin(); i != _views.end(); ++i) { + shared_ptr cv = dynamic_pointer_cast (*i); + if (cv) { + cv->set_track (0); + } + } + + for (list >::iterator i = _views.begin(); i != _views.end(); ++i) { + shared_ptr acv = dynamic_pointer_cast (*i); + if (!acv) { + continue; + } + + shared_ptr acv_content = acv->content().lock (); + assert (acv_content); + + int t = 1; + while (1) { + list >::iterator j = _views.begin(); + while (j != _views.end()) { + shared_ptr test = dynamic_pointer_cast (*j); + if (!test) { + ++j; + continue; + } + + shared_ptr 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); + } +} + int Timeline::tracks () const { - /* XXX */ - return 2; + return _tracks; } void diff --git a/src/wx/timeline.h b/src/wx/timeline.h index 52b29de86..566ca060a 100644 --- a/src/wx/timeline.h +++ b/src/wx/timeline.h @@ -66,9 +66,11 @@ private: void playlist_changed (); void setup_pixels_per_time_unit (); void resized (wxSizeEvent &); + void assign_tracks (); boost::weak_ptr _film; std::list > _views; + int _tracks; double _pixels_per_time_unit; bool _left_down; wxPoint _down_point; -- 2.30.2