Allow repeat of multiple stuff.
authorCarl Hetherington <cth@carlh.net>
Fri, 19 Jul 2013 12:39:14 +0000 (13:39 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 19 Jul 2013 12:39:14 +0000 (13:39 +0100)
src/lib/playlist.cc
src/lib/playlist.h
src/wx/timeline.cc
src/wx/timeline.h

index 31b16b646f9237cdbaca486d88257722f691dd02..e4494acb052b74f6ef545dcf8568a290a1918137 100644 (file)
@@ -42,6 +42,7 @@ using std::min;
 using std::max;
 using std::string;
 using std::stringstream;
+using std::pair;
 using boost::optional;
 using boost::shared_ptr;
 using boost::weak_ptr;
@@ -291,14 +292,24 @@ Playlist::content () const
 }
 
 void
-Playlist::repeat (shared_ptr<Content> c, int n)
+Playlist::repeat (list<shared_ptr<Content> > c, int n)
 {
-       Time pos = c->end ();
+       pair<Time, Time> range (TIME_MAX, 0);
+       for (list<shared_ptr<Content> >::iterator i = c.begin(); i != c.end(); ++i) {
+               range.first = min (range.first, (*i)->start ());
+               range.second = max (range.second, (*i)->start ());
+               range.first = min (range.first, (*i)->end ());
+               range.second = max (range.second, (*i)->end ());
+       }
+
+       Time pos = range.second;
        for (int i = 0; i < n; ++i) {
-               shared_ptr<Content> copy = c->clone ();
-               copy->set_start (pos);
-               _content.push_back (copy);
-               pos = copy->end ();
+               for (list<shared_ptr<Content> >::iterator i = c.begin(); i != c.end(); ++i) {
+                       shared_ptr<Content> copy = (*i)->clone ();
+                       copy->set_start (pos + copy->start() - range.first);
+                       _content.push_back (copy);
+               }
+               pos += range.second - range.first;
        }
 
        reconnect ();
index e949de0ea077b231a8acba935bdb7616fbad749f..1d69c34baee71bde82ee950cf9f5854e88f0fbf9 100644 (file)
@@ -77,7 +77,7 @@ public:
        void set_sequence_video (bool);
        void maybe_sequence_video ();
 
-       void repeat (boost::shared_ptr<Content>, int);
+       void repeat (std::list<boost::shared_ptr<Content> >, int);
 
        mutable boost::signals2::signal<void ()> Changed;
        /** Third parameter is true if signals are currently being emitted frequently */
index e3eca8a1d4f31efab0aac1af38a89b5100ad5156..f9205fc5d74264dc7315a7abd1b27b95b21ea2e2 100644 (file)
@@ -489,25 +489,32 @@ void
 Timeline::left_down (wxMouseEvent& ev)
 {
        shared_ptr<View> view = event_to_view (ev);
+       shared_ptr<ContentView> content_view = dynamic_pointer_cast<ContentView> (view);
 
        _down_view.reset ();
 
-       if (view) {
-               shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (view);
-               if (cv) {
-                       _down_view = cv;
-                       _down_view_start = cv->content()->start ();
-               }
+       if (content_view) {
+               _down_view = content_view;
+               _down_view_start = content_view->content()->start ();
        }
 
        for (list<shared_ptr<View> >::iterator i = _views.begin(); i != _views.end(); ++i) {
                shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
-               if (cv) {
+               if (!cv) {
+                       continue;
+               }
+               
+               if (!ev.ShiftDown ()) {
                        cv->set_selected (view == *i);
-                       if (view == *i) {
-                               _film_editor->set_selection (cv->content ());
-                       }
                }
+               
+               if (view == *i) {
+                       _film_editor->set_selection (cv->content ());
+               }
+       }
+
+       if (content_view && ev.ShiftDown ()) {
+               content_view->set_selected (!content_view->selected ());
        }
 
        _left_down = true;
@@ -618,8 +625,8 @@ Timeline::clear_selection ()
 void
 Timeline::repeat (wxCommandEvent &)
 {
-       shared_ptr<ContentView> sel = selected ();
-       if (!sel) {
+       list<shared_ptr<ContentView> > sel = selected ();
+       if (sel.empty ()) {
                return;
        }
                
@@ -631,20 +638,27 @@ Timeline::repeat (wxCommandEvent &)
                return;
        }
 
-       film->playlist()->repeat (sel->content (), d.number ());
+       list<shared_ptr<Content> > content;
+       for (list<shared_ptr<ContentView> >::iterator i = sel.begin(); i != sel.end(); ++i) {
+               content.push_back ((*i)->content ());
+       }
+
+       film->playlist()->repeat (content, d.number ());
        d.Destroy ();
 }
 
-shared_ptr<ContentView>
+list<shared_ptr<ContentView> >
 Timeline::selected () const
 {
+       list<shared_ptr<ContentView> > sel;
+       
        for (list<shared_ptr<View> >::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
                if (cv && cv->selected()) {
-                       return cv;
+                       sel.push_back (cv);
                }
        }
 
-       return shared_ptr<ContentView> ();
+       return sel;
 }
                
index a50f8e6923da720fa30b1519bf444f3ab1e117b0..99094788f1aded6593143e12113be47f3c7d3282 100644 (file)
@@ -76,7 +76,7 @@ private:
        void repeat (wxCommandEvent &);
 
        boost::shared_ptr<View> event_to_view (wxMouseEvent &);
-       boost::shared_ptr<ContentView> selected () const;
+       std::list<boost::shared_ptr<ContentView> > selected () const;
 
        FilmEditor* _film_editor;
        boost::weak_ptr<Film> _film;