Revert "Revert "patch for waflib internals to allow tarball to be created even when...
[ardour.git] / gtk2_ardour / editor_drag.cc
index 212c02513fd05a87df1071e6be26f806a6310e9a..0c046e56ab1eb188144e6edf6882619417760672 100644 (file)
@@ -44,7 +44,7 @@
 #include "canvas/scroll_group.h"
 
 #include "editor.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 #include "keyboard.h"
 #include "audio_region_view.h"
 #include "automation_region_view.h"
@@ -237,6 +237,7 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only)
        , _grab_frame (0)
        , _last_pointer_frame (0)
        , _snap_delta (0)
+       , _constraint_pressed (false)
 {
 
 }
@@ -261,6 +262,7 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
 {
 
        /* we set up x/y dragging constraints on first move */
+       _constraint_pressed = ArdourKeyboard::indicates_constraint (event->button.state);
 
        _raw_grab_frame = _editor->canvas_event_sample (event, &_grab_x, &_grab_y);
 
@@ -420,14 +422,14 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
                                if (Config->get_edit_mode() != Lock) {
                                        if (event->motion.state & Gdk::BUTTON2_MASK) {
                                                // if dragging with button2, the motion is x constrained, with constraint modifier it is y constrained
-                                               if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+                                               if (_constraint_pressed) {
                                                        _x_constrained = false;
                                                        _y_constrained = true;
                                                } else {
                                                        _x_constrained = true;
                                                        _y_constrained = false;
                                                }
-                                       } else if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+                                       } else if (_constraint_pressed) {
                                                // if dragging normally, the motion is constrained to the first direction of movement.
                                                if (_initially_vertical) {
                                                        _x_constrained = true;
@@ -510,7 +512,7 @@ Drag::show_verbose_cursor_text (string const & text)
 }
 
 boost::shared_ptr<Region>
-Drag::add_midi_region (MidiTimeAxisView* view, bool commit, const int32_t& sub_num)
+Drag::add_midi_region (MidiTimeAxisView* view, bool commit, const int32_t sub_num)
 {
        if (_editor->session()) {
                const TempoMap& map (_editor->session()->tempo_map());
@@ -518,7 +520,7 @@ Drag::add_midi_region (MidiTimeAxisView* view, bool commit, const int32_t& sub_n
                /* not that the frame rate used here can be affected by pull up/down which
                   might be wrong.
                */
-               framecnt_t len = map.frame_at_beat (map.beat_at_frame (pos) + 1.0) - pos;
+               framecnt_t len = map.frame_at_beat (max (0.0, map.beat_at_frame (pos)) + 1.0) - pos;
                return view->add_region (grab_frame(), len, commit, sub_num);
        }
 
@@ -1741,7 +1743,7 @@ RegionMoveDrag::insert_region_into_playlist (
        layer_t dest_layer,
        framecnt_t where,
        PlaylistSet& modified_playlists,
-       const int32_t& sub_num
+       const int32_t sub_num
        )
 {
        boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
@@ -2856,7 +2858,6 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
 
                for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                        RegionView* rv = i->view;
-                       rv->enable_display (false);
                        rv->region()->playlist()->clear_owned_changes ();
 
                        if (_operation == StartTrim) {
@@ -3189,6 +3190,10 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
                        const double beat = map.beat_at_bbt (bbt);
                        _real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor())
                                                       , beat, bbt, map.frame_at_bbt (bbt), _real_section->position_lock_style());
+                       if (!_real_section) {
+                               aborted (true);
+                               return;
+                       }
 
                }
                /* only snap to bars. leave snap mode alone for audio locked meters.*/
@@ -3320,20 +3325,27 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                        _editor->begin_reversible_command (_("move tempo mark"));
 
                } else {
+                       const Tempo tempo (_marker->tempo());
                        const framepos_t frame = adjusted_current_frame (event) + 1;
+                       const TempoSection::Type type = _real_section->type();
 
                        _editor->begin_reversible_command (_("copy tempo mark"));
 
                        if (_real_section->position_lock_style() == MusicTime) {
-                               _real_section = map.add_tempo (_marker->tempo(), map.pulse_at_frame (frame), 0, _real_section->type(), MusicTime);
+                               _real_section = map.add_tempo (tempo, map.pulse_at_frame (frame), 0, type, MusicTime);
                        } else {
-                               _real_section = map.add_tempo (_marker->tempo(), 0.0, frame, _real_section->type(), AudioTime);
+                               _real_section = map.add_tempo (tempo, 0.0, frame, type, AudioTime);
+                       }
+
+                       if (!_real_section) {
+                               aborted (true);
+                               return;
                        }
                }
 
        }
 
-       if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+       if (ArdourKeyboard::indicates_constraint (event->button.state)) {
                /* use vertical movement to alter tempo .. should be log */
                double new_bpm = _real_section->beats_per_minute() + ((last_pointer_y() - current_pointer_y()) / 5.0);
                stringstream strs;
@@ -3343,11 +3355,21 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                show_verbose_cursor_text (strs.str());
 
        } else if (_movable && !_real_section->locked_to_meter()) {
-               const framepos_t pf = adjusted_current_frame (event);
+               framepos_t pf;
+
+               if (_editor->snap_musical()) {
+                       /* we can't snap to a grid that we are about to move.
+                        * gui_move_tempo() will sort out snap using the supplied beat divisions.
+                       */
+                       pf = adjusted_current_frame (event, false);
+               } else {
+                       pf = adjusted_current_frame (event);
+               }
+
                TempoMap& map (_editor->session()->tempo_map());
 
                /* snap to beat is 1, snap to bar is -1 (sorry) */
-               int sub_num = _editor->get_grid_music_divisions (event->button.state);
+               const int sub_num = _editor->get_grid_music_divisions (event->button.state);
 
                map.gui_move_tempo (_real_section, pf, sub_num);
 
@@ -3420,7 +3442,7 @@ void
 BBTRulerDrag::setup_pointer_frame_offset ()
 {
        TempoMap& map (_editor->session()->tempo_map());
-       const double beat_at_frame = map.beat_at_frame (raw_grab_frame());
+       const double beat_at_frame = max (0.0, map.beat_at_frame (raw_grab_frame()));
        const uint32_t divisions = _editor->get_grid_beat_divisions (0);
        double beat = 0.0;
 
@@ -3459,7 +3481,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
                pf = adjusted_current_frame (event);
        }
 
-       if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
+       if (ArdourKeyboard::indicates_constraint (event->button.state)) {
                /* adjust previous tempo to match pointer frame */
                _editor->session()->tempo_map().gui_dilate_tempo (_tempo, map.frame_at_pulse (_pulse), pf, _pulse);
        }
@@ -4233,6 +4255,10 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
                        } else {
                                location->set (((*x).location)->start(), ((*x).location)->end());
                        }
+
+                       if (location->is_session_range()) {
+                               _editor->session()->set_end_is_free (false);
+                       }
                }
        }
 
@@ -5548,6 +5574,10 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
 frameoffset_t
 NoteDrag::total_dx (const guint state) const
 {
+       if (_x_constrained) {
+               return 0;
+       }
+
        /* dx in frames */
        frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
 
@@ -5594,6 +5624,10 @@ NoteDrag::total_dx (const guint state) const
 int8_t
 NoteDrag::total_dy () const
 {
+       if (_y_constrained) {
+               return 0;
+       }
+
        MidiStreamView* msv = _region->midi_stream_view ();
        double const y = _region->midi_view()->y_position ();
        /* new current note */
@@ -5613,8 +5647,8 @@ NoteDrag::motion (GdkEvent * event, bool)
        int8_t const dy = total_dy ();
 
        /* Now work out what we have to do to the note canvas items to set this new drag delta */
-       double const tdx = _editor->sample_to_pixel (dx) - _cumulative_dx;
-       double const tdy = -dy * _note_height - _cumulative_dy;
+       double const tdx = _x_constrained ? 0 : _editor->sample_to_pixel (dx) - _cumulative_dx;
+       double const tdy = _y_constrained ? 0 : -dy * _note_height - _cumulative_dy;
 
        if (tdx || tdy) {
                _cumulative_dx += tdx;
@@ -5622,17 +5656,19 @@ NoteDrag::motion (GdkEvent * event, bool)
 
                int8_t note_delta = total_dy();
 
-               _region->move_selection (tdx, tdy, note_delta);
+               if (tdx || tdy) {
+                       _region->move_selection (tdx, tdy, note_delta);
 
-               /* the new note value may be the same as the old one, but we
-                * don't know what that means because the selection may have
-                * involved more than one note and we might be doing something
-                * odd with them. so show the note value anyway, always.
-                */
+                       /* the new note value may be the same as the old one, but we
+                        * don't know what that means because the selection may have
+                        * involved more than one note and we might be doing something
+                        * odd with them. so show the note value anyway, always.
+                        */
 
-               uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
+                       uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
 
-               _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note);
+                       _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note);
+               }
        }
 }