X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftimeline.cc;h=e1b507383e87523550279940d61608d9dca632b8;hb=76f601f5edbdfceec91ff6f6ce4b310e0d3a6ce9;hp=87070b35edb485d0003f5a971590d349a38a87e3;hpb=10318029c4c3ab46d10aa945bc147d3b11354587;p=dcpomatic.git diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 87070b35e..e1b507383 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -33,7 +33,9 @@ using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; using boost::bind; +using boost::optional; +/** Parent class for components of the timeline (e.g. a piece of content or an axis) */ class View : public boost::noncopyable { public: @@ -62,9 +64,9 @@ public: protected: virtual void do_paint (wxGraphicsContext *) = 0; - int time_x (Time t) const + int time_x (DCPTime t) const { - return _timeline.tracks_position().x + t * _timeline.pixels_per_time_unit(); + return _timeline.tracks_position().x + t.seconds() * _timeline.pixels_per_second (); } Timeline& _timeline; @@ -73,6 +75,8 @@ private: dcpomatic::Rect _last_paint_bbox; }; + +/** Parent class for views of pieces of content */ class ContentView : public View { public: @@ -96,7 +100,7 @@ public: return dcpomatic::Rect ( time_x (content->position ()) - 8, y_pos (_track) - 8, - content->length_after_trim () * _timeline.pixels_per_time_unit() + 16, + content->length_after_trim().seconds() * _timeline.pixels_per_second() + 16, _timeline.track_height() + 16 ); } @@ -135,8 +139,8 @@ private: return; } - Time const position = cont->position (); - Time const len = cont->length_after_trim (); + DCPTime const position = cont->position (); + DCPTime const len = cont->length_after_trim (); wxColour selected (colour().Red() / 2, colour().Green() / 2, colour().Blue() / 2); @@ -158,14 +162,14 @@ private: gc->StrokePath (path); gc->FillPath (path); - wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->path().filename().string()).data(), type().data()); + wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->path_summary()).data(), type().data()); wxDouble name_width; wxDouble name_height; wxDouble name_descent; wxDouble name_leading; gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading); - gc->Clip (wxRegion (time_x (position), y_pos (_track), len * _timeline.pixels_per_time_unit(), _timeline.track_height())); + gc->Clip (wxRegion (time_x (position), y_pos (_track), len.seconds() * _timeline.pixels_per_second(), _timeline.track_height())); gc->DrawText (name, time_x (position) + 12, y_pos (_track + 1) - name_height - 4); gc->ResetClip (); } @@ -184,7 +188,7 @@ private: } if (!frequent) { - _timeline.setup_pixels_per_time_unit (); + _timeline.setup_pixels_per_second (); _timeline.Refresh (); } } @@ -239,6 +243,25 @@ private: } }; +class SubtitleContentView : public ContentView +{ +public: + SubtitleContentView (Timeline& tl, shared_ptr c) + : ContentView (tl, c) + {} + +private: + wxString type () const + { + return _("subtitles"); + } + + wxColour colour () const + { + return wxColour (163, 255, 154, 255); + } +}; + class TimeAxisView : public View { public: @@ -264,18 +287,18 @@ private: { gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID)); - int mark_interval = rint (128 / (TIME_HZ * _timeline.pixels_per_time_unit ())); + double mark_interval = rint (128 / _timeline.pixels_per_second ()); if (mark_interval > 5) { - mark_interval -= mark_interval % 5; + mark_interval -= int (rint (mark_interval)) % 5; } if (mark_interval > 10) { - mark_interval -= mark_interval % 10; + mark_interval -= int (rint (mark_interval)) % 10; } if (mark_interval > 60) { - mark_interval -= mark_interval % 60; + mark_interval -= int (rint (mark_interval)) % 60; } if (mark_interval > 3600) { - mark_interval -= mark_interval % 3600; + mark_interval -= int (rint (mark_interval)) % 3600; } if (mark_interval < 1) { @@ -287,14 +310,15 @@ private: path.AddLineToPoint (_timeline.width(), _y); gc->StrokePath (path); - Time t = 0; - while ((t * _timeline.pixels_per_time_unit()) < _timeline.width()) { + /* Time in seconds */ + DCPTime t; + while ((t.seconds() * _timeline.pixels_per_second()) < _timeline.width()) { wxGraphicsPath path = gc->CreatePath (); path.MoveToPoint (time_x (t), _y - 4); path.AddLineToPoint (time_x (t), _y + 4); gc->StrokePath (path); - int tc = t / TIME_HZ; + double tc = t.seconds (); int const h = tc / 3600; tc -= h * 3600; int const m = tc / 60; @@ -308,12 +332,12 @@ private: wxDouble str_leading; gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading); - int const tx = _timeline.x_offset() + t * _timeline.pixels_per_time_unit(); + int const tx = _timeline.x_offset() + t.seconds() * _timeline.pixels_per_second(); if ((tx + str_width) < _timeline.width()) { gc->DrawText (str, time_x (t), _y + 16); } - t += mark_interval * TIME_HZ; + t += DCPTime::from_seconds (mark_interval); } } @@ -321,17 +345,19 @@ private: int _y; }; + Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr film) : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE) , _film_editor (ed) , _film (film) , _time_axis_view (new TimeAxisView (*this, 32)) , _tracks (0) - , _pixels_per_time_unit (0) + , _pixels_per_second (0) , _left_down (false) , _down_view_position (0) , _first_move (false) - , _menu (film, this) + , _menu (this) + , _snap (true) { #ifndef __WXOSX__ SetDoubleBuffered (true); @@ -392,48 +418,68 @@ Timeline::playlist_changed () if (dynamic_pointer_cast (*i)) { _views.push_back (shared_ptr (new AudioContentView (*this, *i))); } + if (dynamic_pointer_cast (*i)) { + _views.push_back (shared_ptr (new SubtitleContentView (*this, *i))); + } } assign_tracks (); - setup_pixels_per_time_unit (); + setup_pixels_per_second (); Refresh (); } void Timeline::assign_tracks () { + list > video; + list > audio; + list > subtitle; + for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr cv = dynamic_pointer_cast (*i); - if (cv) { - cv->set_track (0); - _tracks = 1; + shared_ptr v = dynamic_pointer_cast (*i); + if (v) { + video.push_back (v); + } + + shared_ptr a = dynamic_pointer_cast (*i); + if (a) { + audio.push_back (a); + } + + shared_ptr s = dynamic_pointer_cast (*i); + if (s) { + subtitle.push_back (s); } } - for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr acv = dynamic_pointer_cast (*i); - if (!acv) { - continue; + _tracks = 0; + if (!video.empty ()) { + for (list >::iterator i = video.begin(); i != video.end(); ++i) { + (*i)->set_track (_tracks); } + ++_tracks; + } - shared_ptr acv_content = acv->content(); + if (!subtitle.empty ()) { + for (list >::iterator i = subtitle.begin(); i != subtitle.end(); ++i) { + (*i)->set_track (_tracks); + } + ++_tracks; + } - int t = 1; + int const audio_start = _tracks; + + for (list >::iterator i = audio.begin(); i != audio.end(); ++i) { + shared_ptr acv_content = (*i)->content(); + + int t = audio_start; while (1) { - ViewList::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(); - - if (test && test->track() == t) { + list >::iterator j = audio.begin (); + while (j != audio.end()) { + if ((*j)->track() == t) { bool const no_overlap = - (acv_content->position() < test_content->position() && acv_content->end() < test_content->position()) || - (acv_content->position() > test_content->end() && acv_content->end() > test_content->end()); + (acv_content->position() < (*j)->content()->position() && acv_content->end() < (*j)->content()->position()) || + (acv_content->position() > (*j)->content()->end() && acv_content->end() > (*j)->content()->end()); if (!no_overlap) { /* we have an overlap on track `t' */ @@ -445,13 +491,13 @@ Timeline::assign_tracks () ++j; } - if (j == _views.end ()) { + if (j == audio.end ()) { /* no overlap on `t' */ break; } } - acv->set_track (t); + (*i)->set_track (t); _tracks = max (_tracks, t + 1); } @@ -465,14 +511,14 @@ Timeline::tracks () const } void -Timeline::setup_pixels_per_time_unit () +Timeline::setup_pixels_per_second () { shared_ptr film = _film.lock (); - if (!film) { + if (!film || film->length() == DCPTime ()) { return; } - _pixels_per_time_unit = static_cast(width() - x_offset() * 2) / film->length (); + _pixels_per_second = static_cast(width() - x_offset() * 2) / film->length().seconds (); } shared_ptr @@ -568,7 +614,7 @@ Timeline::right_down (wxMouseEvent& ev) cv->set_selected (true); } - _menu.popup (selected_content (), ev.GetPosition ()); + _menu.popup (_film, selected_content (), ev.GetPosition ()); } void @@ -577,6 +623,9 @@ Timeline::set_position_from_event (wxMouseEvent& ev) wxPoint const p = ev.GetPosition(); if (!_first_move) { + /* We haven't moved yet; in that case, we must move the mouse some reasonable distance + before the drag is considered to have started. + */ int const dist = sqrt (pow (p.x - _down_point.x, 2) + pow (p.y - _down_point.y, 2)); if (dist < 8) { return; @@ -584,14 +633,66 @@ Timeline::set_position_from_event (wxMouseEvent& ev) _first_move = true; } - Time const time_diff = (p.x - _down_point.x) / _pixels_per_time_unit; - if (_down_view) { - _down_view->content()->set_position (max (static_cast