Paste uses exact beats. rework _start_beats calculation in copy-with-offset ctor.
authornick_m <mainsbridge@gmail.com>
Thu, 16 Jun 2016 17:20:37 +0000 (03:20 +1000)
committernick_m <mainsbridge@gmail.com>
Sat, 9 Jul 2016 16:18:36 +0000 (02:18 +1000)
20 files changed:
gtk2_ardour/automation_time_axis.cc
gtk2_ardour/automation_time_axis.h
gtk2_ardour/editor.h
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_drag.h
gtk2_ardour/editor_keys.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_region_view.h
gtk2_ardour/midi_streamview.cc
gtk2_ardour/midi_streamview.h
gtk2_ardour/midi_time_axis.cc
gtk2_ardour/midi_time_axis.h
gtk2_ardour/route_time_axis.cc
gtk2_ardour/route_time_axis.h
gtk2_ardour/time_axis_view.h
libs/ardour/ardour/playlist.h
libs/ardour/ardour/region.h
libs/ardour/midi_region.cc
libs/ardour/playlist.cc

index 3a1dbf3c0cf64d1eac8a33995816ec6bbae267be..7a8e8ac5b32d346e1ccb810603bdb3426bb4f69f 100644 (file)
@@ -658,7 +658,7 @@ AutomationTimeAxisView::add_automation_event (GdkEvent* event, framepos_t when,
 }
 
 bool
-AutomationTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx)
+AutomationTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t& sub_num)
 {
        if (_line) {
                return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
index d073890061453c0c6ce7a5858b291847162a02c6..f352dae1ed10f8bf08f5899aeae5581dec797087 100644 (file)
@@ -97,7 +97,7 @@ class AutomationTimeAxisView : public TimeAxisView {
        /* editing operations */
 
        void cut_copy_clear (Selection&, Editing::CutCopyOp);
-       bool paste (ARDOUR::framepos_t, const Selection&, PasteContext&);
+       bool paste (ARDOUR::framepos_t, const Selection&, PasteContext&, const int32_t& sub_num);
 
        int  set_state (const XMLNode&, int version);
 
index af781f019c7d1ff94f81cda3c3ae21dfe5cac9cf..7c224a1d0c1b7548ae92ece57fec5056790f1b76 100644 (file)
@@ -1190,7 +1190,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void cut_copy_midi (Editing::CutCopyOp);
 
        void mouse_paste ();
-       void paste_internal (framepos_t position, float times);
+       void paste_internal (framepos_t position, float times, const int32_t& sub_num);
 
        /* EDITING OPERATIONS */
 
@@ -1283,7 +1283,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void delete_ ();
        void cut ();
        void copy ();
-       void paste (float times, bool from_context_menu = false);
+       void paste (float times, bool from_context_menu);
 
        void place_transient ();
        void remove_transient (ArdourCanvas::Item* item);
index 11809af788730dc9141b7abb471aa7b6dc648e65..212c02513fd05a87df1071e6be26f806a6310e9a 100644 (file)
@@ -1256,8 +1256,8 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move)
                        MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
 
                        const boost::shared_ptr<const Region> original = rv->region();
-                       boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true);
-                       region_copy->set_position (original->position(), _editor->get_grid_music_divisions (event->button.state));
+                       boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true
+                                                                                      , _editor->get_grid_music_divisions (event->button.state));
                        /* need to set this so that the drop zone code can work. This doesn't
                           actually put the region into the playlist, but just sets a weak pointer
                           to it.
@@ -1478,7 +1478,9 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed
                }
 
                if (dest_rtv != 0) {
-                       RegionView* new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, modified_playlists);
+                       RegionView* new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where,
+                                                                           modified_playlists, _editor->get_grid_music_divisions (ev_state));
+
                        if (new_view != 0) {
                                new_views.push_back (new_view);
                        }
@@ -1574,7 +1576,8 @@ RegionMoveDrag::finished_no_copy (
                        /* insert into new playlist */
 
                        RegionView* new_view = insert_region_into_playlist (
-                               RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists
+                               RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where,
+                               modified_playlists, _editor->get_grid_music_divisions (ev_state)
                                );
 
                        if (new_view == 0) {
@@ -1737,7 +1740,8 @@ RegionMoveDrag::insert_region_into_playlist (
        RouteTimeAxisView* dest_rtv,
        layer_t dest_layer,
        framecnt_t where,
-       PlaylistSet& modified_playlists
+       PlaylistSet& modified_playlists,
+       const int32_t& sub_num
        )
 {
        boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
@@ -1754,8 +1758,7 @@ RegionMoveDrag::insert_region_into_playlist (
        if (r.second) {
                dest_playlist->clear_changes ();
        }
-
-       dest_playlist->add_region (region, where);
+       dest_playlist->add_region (region, where, 1.0, false, sub_num);
 
        if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
                dest_playlist->set_layer (region, dest_layer);
index d9ac49cfd40e9d73b498d0aaf53e0cfd90861f06..911b8fbf3582ad80ad45f1576ad354414b5dafdd 100644 (file)
@@ -423,7 +423,8 @@ private:
                RouteTimeAxisView*,
                ARDOUR::layer_t,
                ARDOUR::framecnt_t,
-               PlaylistSet&
+               PlaylistSet&,
+               const int32_t& sub_num
                );
 
        void remove_region_from_playlist (
index 8b1e46e0b70882379b3070188db114cf4e14ea49..1edcd16c9e017f4221cb479c375c67c742711905 100644 (file)
@@ -105,5 +105,5 @@ Editor::keyboard_selection_begin (Editing::EditIgnoreOption ign)
 void
 Editor::keyboard_paste ()
 {
-       paste (1);
+       paste (1, false);
 }
index 80a5ee399ea9bba7981303ed1b84284193376759..b7809f0394e0e283a6be211ae19c644806ea296c 100644 (file)
@@ -4635,7 +4635,7 @@ Editor::paste (float times, bool from_context)
 {
         DEBUG_TRACE (DEBUG::CutNPaste, "paste to preferred edit pos\n");
 
-       paste_internal (get_preferred_edit_position (EDIT_IGNORE_NONE, from_context), times);
+       paste_internal (get_preferred_edit_position (EDIT_IGNORE_NONE, from_context), times, get_grid_music_divisions (0));
 }
 
 void
@@ -4649,11 +4649,11 @@ Editor::mouse_paste ()
        }
 
        snap_to (where);
-       paste_internal (where, 1);
+       paste_internal (where, 1, get_grid_music_divisions (0));
 }
 
 void
-Editor::paste_internal (framepos_t position, float times)
+Editor::paste_internal (framepos_t position, float times, const int32_t& sub_num)
 {
         DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("apparent paste position is %1\n", position));
 
@@ -4746,7 +4746,7 @@ Editor::paste_internal (framepos_t position, float times)
               "greedy" paste from one automation type to another. */
 
            PasteContext ctx(paste_count, times, ItemCounts(), true);
-           ts.front()->paste (position, *cut_buffer, ctx);
+           ts.front()->paste (position, *cut_buffer, ctx, sub_num);
 
        } else {
 
@@ -4754,7 +4754,7 @@ Editor::paste_internal (framepos_t position, float times)
 
                PasteContext ctx(paste_count, times, ItemCounts(), false);
                for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
-                       (*i)->paste (position, *cut_buffer, ctx);
+                       (*i)->paste (position, *cut_buffer, ctx, sub_num);
                }
        }
 
index 6ffba154f4c8fe9e0e7f2adb48572273afd25220..5c460cdf483d43675fbc3454e4c9ff2aaa414dcc 100644 (file)
@@ -3491,7 +3491,7 @@ MidiRegionView::selection_as_cut_buffer () const
 
 /** This method handles undo */
 bool
-MidiRegionView::paste (framepos_t pos, const ::Selection& selection, PasteContext& ctx)
+MidiRegionView::paste (framepos_t pos, const ::Selection& selection, PasteContext& ctx, const int32_t& sub_num)
 {
        bool commit = false;
        // Paste notes, if available
@@ -3506,7 +3506,7 @@ MidiRegionView::paste (framepos_t pos, const ::Selection& selection, PasteContex
        typedef RouteTimeAxisView::AutomationTracks ATracks;
        const ATracks& atracks = midi_view()->automation_tracks();
        for (ATracks::const_iterator a = atracks.begin(); a != atracks.end(); ++a) {
-               if (a->second->paste(pos, selection, ctx)) {
+               if (a->second->paste(pos, selection, ctx, sub_num)) {
                        commit = true;
                }
        }
index b24b76798126383ff7674753a1c405bb5ae82608..fd423a3d0c0783afc603dc2651f49f076f35cd26 100644 (file)
@@ -122,7 +122,7 @@ public:
        void resolve_note(uint8_t note_num, Evoral::Beats end_time);
 
        void cut_copy_clear (Editing::CutCopyOp);
-       bool paste (framepos_t pos, const ::Selection& selection, PasteContext& ctx);
+       bool paste (framepos_t pos, const ::Selection& selection, PasteContext& ctx, const int32_t& sub_num);
        void paste_internal (framepos_t pos, unsigned paste_count, float times, const MidiCutBuffer&);
 
        void add_canvas_patch_change (ARDOUR::MidiModel::PatchChangePtr patch, const std::string& displaytext, bool);
index 88947e7e3d56b215b1a6477c502fc9132c10169b..24328148d476c8b483f951ae8c3b62824d6e60c3 100644 (file)
@@ -662,7 +662,7 @@ struct RegionPositionSorter {
 };
 
 bool
-MidiStreamView::paste (ARDOUR::framepos_t pos, const Selection& selection, PasteContext& ctx)
+MidiStreamView::paste (ARDOUR::framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t& sub_num)
 {
        /* Paste into the first region which starts on or before pos.  Only called when
           using an internal editing tool. */
@@ -690,5 +690,5 @@ MidiStreamView::paste (ARDOUR::framepos_t pos, const Selection& selection, Paste
        }
 
        MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*prev);
-       return mrv ? mrv->paste(pos, selection, ctx) : false;
+       return mrv ? mrv->paste(pos, selection, ctx, sub_num) : false;
 }
index 9be3b34d9ce1b779e7d034630e4852217f047768..582c72fc1ff0ca1b9a48bf2ca9a7b9d22656fd79 100644 (file)
@@ -98,7 +98,7 @@ class MidiStreamView : public StreamView
 
        RegionView* create_region_view (boost::shared_ptr<ARDOUR::Region>, bool, bool);
 
-       bool paste (ARDOUR::framepos_t pos, const Selection& selection, PasteContext& ctx);
+       bool paste (ARDOUR::framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t& sub_num);
 
        void apply_note_range(uint8_t lowest, uint8_t highest, bool to_region_views);
 
index 4b709c4e5ca57b74c9cc0eed3c28de94e81aa4ad..fcb073aed983271122bacd68543bb34fed7c3993 100644 (file)
@@ -1635,12 +1635,12 @@ MidiTimeAxisView::capture_channel_mode_changed ()
 }
 
 bool
-MidiTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx)
+MidiTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t& sub_num)
 {
        if (!_editor.internal_editing()) {
                // Non-internal paste, paste regions like any other route
-               return RouteTimeAxisView::paste(pos, selection, ctx);
+               return RouteTimeAxisView::paste(pos, selection, ctx, sub_num);
        }
 
-       return midi_view()->paste(pos, selection, ctx);
+       return midi_view()->paste(pos, selection, ctx, sub_num);
 }
index b8e60660b407b6d8ebab46aa2534480638689952..4b78553d8cb5636f9b77d43f14ea2c1dfe175e3a 100644 (file)
@@ -88,7 +88,7 @@ public:
        void show_existing_automation (bool apply_to_selection = false);
        void create_automation_child (const Evoral::Parameter& param, bool show);
 
-       bool paste (ARDOUR::framepos_t, const Selection&, PasteContext& ctx);
+       bool paste (ARDOUR::framepos_t, const Selection&, PasteContext& ctx, const int32_t& sub_num);
 
        ARDOUR::NoteMode  note_mode() const { return _note_mode; }
        ARDOUR::ColorMode color_mode() const { return _color_mode; }
index 7b73f36532a7f316cf7d8c579462de33dcbc111c..6d377df96b2ab734c007c7f15f7b14347f300013 100644 (file)
@@ -1585,7 +1585,7 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
 }
 
 bool
-RouteTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx)
+RouteTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t& sub_num)
 {
        if (!is_track()) {
                return false;
@@ -1619,7 +1619,7 @@ RouteTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteConte
                framecnt_t amount = extent.second - extent.first;
                pl->ripple(pos, amount * ctx.times, boost::shared_ptr<Region>());
        }
-       pl->paste (*p, pos, ctx.times);
+       pl->paste (*p, pos, ctx.times, sub_num);
 
        vector<Command*> cmds;
        pl->rdiff (cmds);
index 3af3f1e08eb178eeb7d993cd2c50147a6dee377a..efa2bfafb86f194989bfba4dd15a2f0dbe4fe043 100644 (file)
@@ -107,7 +107,7 @@ public:
 
        /* Editing operations */
        void cut_copy_clear (Selection&, Editing::CutCopyOp);
-       bool paste (ARDOUR::framepos_t, const Selection&, PasteContext& ctx);
+       bool paste (ARDOUR::framepos_t, const Selection&, PasteContext& ctx, const int32_t& sub_num);
        RegionView* combine_regions ();
        void uncombine_regions ();
        void uncombine_region (RegionView*);
index aed4576f20d7793ebdeccc30138414a5c6913528..2ad221495207db60dee646a06755818377f9769f 100644 (file)
@@ -185,7 +185,8 @@ class TimeAxisView : public virtual AxisView
         */
        virtual bool paste (ARDOUR::framepos_t pos,
                            const Selection&   selection,
-                           PasteContext&      ctx) { return false; }
+                           PasteContext&      ctx,
+                           const int32_t& sub_num) { return false; }
 
        virtual void set_selected_regionviews (RegionSelection&) {}
        virtual void set_selected_points (PointSelection&) {}
index 0a5f5e4ddc5c015050d410cc7fc0cc1643ea0f89..09c31360eca86d01129e57c81e6d8d57edefd7c3 100644 (file)
@@ -128,7 +128,7 @@ public:
 
        /* Editing operations */
 
-       void add_region (boost::shared_ptr<Region>, framepos_t position, float times = 1, bool auto_partition = false);
+       void add_region (boost::shared_ptr<Region>, framepos_t position, float times = 1, bool auto_partition = false, const int32_t& sub_num = 0);
        void remove_region (boost::shared_ptr<Region>);
        void get_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
        void get_region_list_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
@@ -161,7 +161,7 @@ public:
 
        boost::shared_ptr<Playlist> cut  (std::list<AudioRange>&, bool result_is_hidden = true);
        boost::shared_ptr<Playlist> copy (std::list<AudioRange>&, bool result_is_hidden = true);
-       int                         paste (boost::shared_ptr<Playlist>, framepos_t position, float times);
+       int                         paste (boost::shared_ptr<Playlist>, framepos_t position, float times, const int32_t& sub_num);
 
        const RegionListProperty& region_list_property () const { return regions; }
        boost::shared_ptr<RegionList> region_list();
@@ -362,7 +362,7 @@ public:
 
        virtual XMLNode& state (bool);
 
-       bool add_region_internal (boost::shared_ptr<Region>, framepos_t position);
+       bool add_region_internal (boost::shared_ptr<Region>, framepos_t position, const int32_t& sub_num = 0);
 
        int remove_region_internal (boost::shared_ptr<Region>);
        void copy_regions (RegionList&) const;
index ec4f559a87e78563b4704a0f053dd25a6d4e139e..7f41cb6e5a7cf7b5e377730c6bc64e0d926ecf61 100644 (file)
@@ -171,10 +171,12 @@ class LIBARDOUR_API Region
        Trimmable::CanTrim can_trim () const;
 
        PositionLockStyle position_lock_style () const { return _position_lock_style; }
-       double beat () const { return _beat; }
        void set_position_lock_style (PositionLockStyle ps);
        void recompute_position_from_lock_style (const int32_t& sub_num);
 
+       double beat () const { return _beat; }
+       void set_beat (double beat) { _beat = beat; }
+
        void suspend_property_changes ();
 
        bool covers (framepos_t frame) const {
index 4d4c081c245219afb251bf71ab58684fcf5bec1c..035c17c9de3e90f42a036a57a5ed9614e38e39c9 100644 (file)
@@ -107,8 +107,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, frameoffset_t
        , _start_beats (Properties::start_beats, Evoral::Beats())
        , _length_beats (Properties::length_beats, other->_length_beats)
 {
-       const double offset_beat = _session.tempo_map().exact_beat_at_frame (other->_position + offset, sub_num) - other->beat();
-       _start_beats = Evoral::Beats (other->_start_beats.val().to_double() + offset_beat);
+       _start_beats = Evoral::Beats (_session.tempo_map().exact_beat_at_frame (other->_position + offset - other->_start, sub_num) - other->beat());
        update_length_beats (sub_num);
        register_properties ();
 
@@ -163,7 +162,10 @@ MidiRegion::clone (boost::shared_ptr<MidiSource> newsrc) const
        plist.add (Properties::length_beats, _length_beats);
        plist.add (Properties::layer, 0);
 
-       return boost::dynamic_pointer_cast<MidiRegion> (RegionFactory::create (newsrc, plist, true));
+       boost::shared_ptr<MidiRegion> ret (boost::dynamic_pointer_cast<MidiRegion> (RegionFactory::create (newsrc, plist, true)));
+       ret->set_beat (beat());
+
+       return ret;
 }
 
 void
index 3797f2f0c1118d19ec7e204d3d1a84dce5ce1241..924c3b61415cdf01eedb607de3f1fe91ebe48745 100644 (file)
@@ -665,7 +665,7 @@ Playlist::flush_notifications (bool from_undo)
 
 /** Note: this calls set_layer (..., DBL_MAX) so it will reset the layering index of region */
  void
- Playlist::add_region (boost::shared_ptr<Region> region, framepos_t position, float times, bool auto_partition)
+ Playlist::add_region (boost::shared_ptr<Region> region, framepos_t position, float times, bool auto_partition, const int32_t& sub_num)
  {
         RegionWriteLock rlock (this);
         times = fabs (times);
@@ -679,7 +679,7 @@ Playlist::flush_notifications (bool from_undo)
         }
 
         if (itimes >= 1) {
-                add_region_internal (region, pos);
+                add_region_internal (region, pos, sub_num);
                 set_layer (region, DBL_MAX);
                 pos += region->length();
                 --itimes;
@@ -692,7 +692,7 @@ Playlist::flush_notifications (bool from_undo)
 
         for (int i = 0; i < itimes; ++i) {
                 boost::shared_ptr<Region> copy = RegionFactory::create (region, true);
-                add_region_internal (copy, pos);
+                add_region_internal (copy, pos, sub_num);
                 set_layer (copy, DBL_MAX);
                 pos += region->length();
         }
@@ -713,7 +713,7 @@ Playlist::flush_notifications (bool from_undo)
                         plist.add (Properties::layer, region->layer());
 
                         boost::shared_ptr<Region> sub = RegionFactory::create (region, plist);
-                        add_region_internal (sub, pos);
+                        add_region_internal (sub, pos, sub_num);
                         set_layer (sub, DBL_MAX);
                 }
         }
@@ -734,7 +734,7 @@ Playlist::flush_notifications (bool from_undo)
  }
 
  bool
- Playlist::add_region_internal (boost::shared_ptr<Region> region, framepos_t position)
+ Playlist::add_region_internal (boost::shared_ptr<Region> region, framepos_t position, const int32_t& sub_num)
  {
         if (region->data_type() != _type) {
                 return false;
@@ -747,7 +747,7 @@ Playlist::flush_notifications (bool from_undo)
                 region->set_playlist (boost::weak_ptr<Playlist>(foo));
         }
 
-        region->set_position (position);
+        region->set_position (position, sub_num);
 
         regions.insert (upper_bound (regions.begin(), regions.end(), region, cmp), region);
         all_regions.insert (region);
@@ -1146,7 +1146,7 @@ Playlist::flush_notifications (bool from_undo)
                            chopped.
                         */
 
-                        ret->paste (pl, (*i).start - start, 1.0f);
+                        ret->paste (pl, (*i).start - start, 1.0f, 0);
                 }
         }
 
@@ -1208,7 +1208,7 @@ Playlist::flush_notifications (bool from_undo)
  }
 
  int
- Playlist::paste (boost::shared_ptr<Playlist> other, framepos_t position, float times)
+ Playlist::paste (boost::shared_ptr<Playlist> other, framepos_t position, float times, const int32_t& sub_num)
  {
         times = fabs (times);
 
@@ -1230,7 +1230,7 @@ Playlist::flush_notifications (bool from_undo)
                                            the ordering they had in the original playlist.
                                         */
 
-                                        add_region_internal (copy_of_region, (*i)->position() + pos);
+                                        add_region_internal (copy_of_region, (*i)->position() + pos, sub_num);
                                         set_layer (copy_of_region, copy_of_region->layer() + top);
                                 }
                                 pos += shift;
@@ -1321,7 +1321,7 @@ Playlist::duplicate_range (AudioRange& range, float times)
 {
        boost::shared_ptr<Playlist> pl = copy (range.start, range.length(), true);
        framecnt_t offset = range.end - range.start;
-       paste (pl, range.start + offset, times);
+       paste (pl, range.start + offset, times, 0);
 }
 
 void
@@ -1345,7 +1345,7 @@ Playlist::duplicate_ranges (std::list<AudioRange>& ranges, float /* times */)
 
        for (list<AudioRange>::iterator i = ranges.begin(); i != ranges.end(); ++i) {
                boost::shared_ptr<Playlist> pl = copy ((*i).start, (*i).length(), true);
-               paste (pl, (*i).start + offset, 1.0f); // times ??
+               paste (pl, (*i).start + offset, 1.0f, 0); // times ??
        }
 }