more verbose debug output for slave debugging
[ardour.git] / gtk2_ardour / automation_region_view.cc
index f1f9d68b987f8af60b3df5c067dea5cb9e643bf8..4a16177d29ca884ec95471428bef80c3e24c08a5 100644 (file)
@@ -38,7 +38,7 @@
 #include "public_editor.h"
 #include "ui_config.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 AutomationRegionView::AutomationRegionView (ArdourCanvas::Container*                  parent,
                                             AutomationTimeAxisView&                   time_axis,
@@ -52,6 +52,8 @@ AutomationRegionView::AutomationRegionView (ArdourCanvas::Container*
        , _source_relative_time_converter(region->session().tempo_map(), region->position() - region->start())
        , _parameter(param)
 {
+       TimeAxisViewItem::set_position (_region->position(), this);
+
        if (list) {
                assert(list->parameter() == param);
                create_line(list);
@@ -66,6 +68,7 @@ AutomationRegionView::AutomationRegionView (ArdourCanvas::Container*
 
 AutomationRegionView::~AutomationRegionView ()
 {
+       in_destructor = true;
        RegionViewGoingAway (this); /* EMIT_SIGNAL */
 }
 
@@ -134,6 +137,7 @@ AutomationRegionView::canvas_group_event (GdkEvent* ev)
 
        if (trackview.editor().internal_editing() &&
            ev->type == GDK_BUTTON_RELEASE &&
+           ev->button.button == 1 &&
            e.current_mouse_mode() == Editing::MouseDraw &&
            !e.drags()->active()) {
 
@@ -180,7 +184,7 @@ AutomationRegionView::add_automation_event (GdkEvent *, framepos_t when, double
 
        /* snap frame */
 
-       when = snap_frame_to_frame (when - _region->start ()) + _region->start ();
+       when = snap_frame_to_frame (when - _region->start ()).frame + _region->start ();
 
        /* map using line */
 
@@ -207,6 +211,8 @@ AutomationRegionView::paste (framepos_t                                      pos
                              float                                           times,
                              boost::shared_ptr<const ARDOUR::AutomationList> slist)
 {
+       using namespace ARDOUR;
+
        AutomationTimeAxisView* const             view    = automation_view();
        boost::shared_ptr<ARDOUR::AutomationList> my_list = _line->the_list();
 
@@ -215,15 +221,24 @@ AutomationRegionView::paste (framepos_t                                      pos
                return false;
        }
 
+       AutomationType src_type = (AutomationType)slist->parameter().type ();
+       double len = slist->length();
+
        /* add multi-paste offset if applicable */
-       pos += view->editor().get_paste_offset(
-               pos, paste_count, _source_relative_time_converter.to(slist->length()));
+       if (parameter_is_midi (src_type)) {
+               // convert length to samples (incl tempo-ramps)
+               len = DoubleBeatsFramesConverter (view->session()->tempo_map(), pos).to (len * paste_count);
+               pos += view->editor ().get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
+       } else {
+               pos += view->editor ().get_paste_offset (pos, paste_count, len);
+       }
 
-       const double model_pos = _source_relative_time_converter.from(
+       /* convert sample-position to model's unit and position */
+       const double model_pos = _source_relative_time_converter.from (
                pos - _source_relative_time_converter.origin_b());
 
        XMLNode& before = my_list->get_state();
-       my_list->paste(*slist, model_pos, times);
+       my_list->paste(*slist, model_pos, DoubleBeatsFramesConverter (view->session()->tempo_map(), pos));
        view->session()->add_command(
                new MementoCommand<ARDOUR::AutomationList>(_line->memento_command_binder(), &before, &my_list->get_state()));