working but still confusing fix for ensuring that playlist shared-with data is correc...
[ardour.git] / gtk2_ardour / editor_drag.cc
index 9d36b28e1b468f4863ca9148fe24a9edaaa74509..ebc5d97bb7a612e827f06f0ab7faf67c28000971 100644 (file)
@@ -293,16 +293,9 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
                _was_rolling = false;
        }
 
-       switch (_editor->snap_type()) {
-       case SnapToRegionStart:
-       case SnapToRegionEnd:
-       case SnapToRegionSync:
-       case SnapToRegionBoundary:
-               _editor->build_region_boundary_cache ();
-               break;
-       default:
-               break;
-       }
+//     if ( UIConfiguration::instance().get_snap_to_region_start() || UIConfiguration::instance().get_snap_to_region_end() || UIConfiguration::instance().get_snap_to_region_sync() ) {
+//             _editor->build_region_boundary_cache ();
+//     }
 }
 
 /** Call to end a drag `successfully'.  Ungrabs item and calls
@@ -388,7 +381,7 @@ Drag::setup_snap_delta (MusicSample pos)
 {
        TempoMap& map (_editor->session()->tempo_map());
        MusicSample snap (pos);
-       _editor->snap_to (snap, ARDOUR::RoundNearest, false, true);
+       _editor->snap_to (snap, ARDOUR::RoundNearest, ARDOUR::SnapToAny_Visual, true);
        _snap_delta = snap.sample - pos.sample;
 
        _snap_delta_music = 0.0;
@@ -719,6 +712,8 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, MusicSample* pending_
                }
        }
 
+       _editor->set_snapped_cursor_position(pending_region_position->sample);
+
        return dx;
 }
 
@@ -1433,6 +1428,10 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
 RouteTimeAxisView*
 RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region, TimeAxisView* original)
 {
+       if (!ARDOUR_UI_UTILS::engine_is_running ()) {
+               return NULL;
+       }
+
        /* Add a new track of the correct type, and return the RouteTimeAxisView that is created to display the
           new track.
         */
@@ -2987,7 +2986,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
                        /* a MRV start trim may change the source length. ensure we cover all playlists here */
                        if (mrv && _operation == StartTrim) {
                                vector<boost::shared_ptr<Playlist> > all_playlists;
-                               _editor->session()->playlists->get (all_playlists);
+                               _editor->session()->playlists()->get (all_playlists);
                                for (vector<boost::shared_ptr<Playlist> >::iterator x = all_playlists.begin(); x != all_playlists.end(); ++x) {
 
                                        if ((*x)->uses_source (rv->region()->source(0))) {
@@ -3229,7 +3228,7 @@ TrimDrag::setup_pointer_sample_offset ()
 MeterMarkerDrag::MeterMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
        : Drag (e, i)
        , _copy (c)
-       , _old_snap_type (e->snap_type())
+       , _old_grid_type (e->grid_type())
        , _old_snap_mode (e->snap_mode())
        , before_state (0)
 {
@@ -3302,14 +3301,14 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
                }
                /* only snap to bars. leave snap mode alone for audio locked meters.*/
                if (_real_section->position_lock_style() != AudioTime) {
-                       _editor->set_snap_to (SnapToBar);
-                       _editor->set_snap_mode (SnapNormal);
+                       _editor->set_grid_to (GridTypeBar);
+                       _editor->set_snap_mode (SnapMagnetic);
                }
        }
 
        samplepos_t pf = adjusted_current_sample (event);
 
-       if (_real_section->position_lock_style() == AudioTime && _editor->snap_musical()) {
+       if (_real_section->position_lock_style() == AudioTime && _editor->grid_musical()) {
                /* never snap to music for audio locked */
                pf = adjusted_current_sample (event, false);
        }
@@ -3320,6 +3319,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
        _marker->set_position (adjusted_current_sample (event, false));
 
        show_verbose_cursor_time (_real_section->sample());
+       _editor->set_snapped_cursor_position(_real_section->sample());
 }
 
 void
@@ -3333,7 +3333,7 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
        }
 
        /* reinstate old snap setting */
-       _editor->set_snap_to (_old_snap_type);
+       _editor->set_grid_to (_old_grid_type);
        _editor->set_snap_mode (_old_snap_mode);
 
        TempoMap& map (_editor->session()->tempo_map());
@@ -3353,7 +3353,7 @@ MeterMarkerDrag::aborted (bool moved)
        _marker->set_position (_marker->meter().sample ());
        if (moved) {
                /* reinstate old snap setting */
-               _editor->set_snap_to (_old_snap_type);
+               _editor->set_grid_to (_old_grid_type);
                _editor->set_snap_mode (_old_snap_mode);
 
                _editor->session()->tempo_map().set_state (*before_state, Stateful::current_state_version);
@@ -3470,7 +3470,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
        } else if (_movable && !_real_section->locked_to_meter()) {
                samplepos_t pf;
 
-               if (_editor->snap_musical()) {
+               if (_editor->grid_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.
                        */
@@ -3485,6 +3485,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                map.gui_set_tempo_position (_real_section, pf, sub_num);
 
                show_verbose_cursor_time (_real_section->sample());
+               _editor->set_snapped_cursor_position(_real_section->sample());
        }
        _marker->set_position (adjusted_current_sample (event, false));
 }
@@ -3603,7 +3604,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
        TempoMap& map (_editor->session()->tempo_map());
        samplepos_t pf;
 
-       if (_editor->snap_musical()) {
+       if (_editor->grid_musical()) {
                pf = adjusted_current_sample (event, false);
        } else {
                pf = adjusted_current_sample (event);
@@ -3751,7 +3752,7 @@ TempoTwistDrag::motion (GdkEvent* event, bool first_move)
 
        samplepos_t pf;
 
-       if (_editor->snap_musical()) {
+       if (_editor->grid_musical()) {
                pf = adjusted_current_sample (event, false);
        } else {
                pf = adjusted_current_sample (event);
@@ -4609,6 +4610,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
        assert (!_copied_locations.empty());
 
        show_verbose_cursor_time (newframe);
+       _editor->set_snapped_cursor_position(newframe);
 }
 
 void
@@ -4686,7 +4688,7 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
                        }
 
                        if (location->is_session_range()) {
-                               _editor->session()->set_end_is_free (false);
+                               _editor->session()->set_session_range_is_free (false);
                        }
                }
        }
@@ -5094,7 +5096,7 @@ RubberbandSelectDrag::motion (GdkEvent* event, bool)
        MusicSample grab (grab_sample (), 0);
 
        if (UIConfiguration::instance().get_rubberbanding_snaps_to_grid ()) {
-               _editor->snap_to_with_modifier (grab, event);
+               _editor->snap_to_with_modifier (grab, event, RoundNearest, SnapToGrid_Scaled);
        } else {
                grab.sample = raw_grab_sample ();
        }
@@ -5677,12 +5679,16 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
 
                /* XXX what if its a music time selection? */
                if (s) {
-                       if (s->get_play_range() && s->transport_rolling()) {
-                               s->request_play_range (&_editor->selection->time, true);
-                       } else if (!s->config.get_external_sync()) {
-                               if (UIConfiguration::instance().get_follow_edits() && !s->transport_rolling()) {
-                                       s->request_locate (_editor->get_selection().time.start());
+
+                       //if Follow Edits is on, maybe try to follow the range selection  ... also consider range-audition mode
+                       if ( !s->config.get_external_sync() && s->transport_rolling() ) {
+                               if ( s->solo_selection_active() ) {
+                                       _editor->play_solo_selection(true);  //play the newly selected range, and move solos to match
+                               } else if ( UIConfiguration::instance().get_follow_edits() && s->get_play_range() ) {  //already rolling a selected range
+                                       s->request_play_range (&_editor->selection->time, true);  //play the newly selected range
                                }
+                       } else if ( !s->transport_rolling() && UIConfiguration::instance().get_follow_edits() ) {
+                               s->request_locate (_editor->get_selection().time.start());
                        }
 
                        if (_editor->get_selection().time.length() != 0) {
@@ -6073,7 +6079,7 @@ NoteDrag::total_dx (GdkEvent * event) const
 
        /* possibly snap and return corresponding delta in quarter notes */
        MusicSample snap (st, 0);
-       _editor->snap_to_with_modifier (snap, event);
+       _editor->snap_to_with_modifier (snap, event, RoundNearest, SnapToGrid_Unscaled);
        double ret = map.exact_qn_at_sample (snap.sample, snap.division) - n_qn - snap_delta_music (event->button.state);
 
        /* prevent the earliest note being dragged earlier than the region's start position */
@@ -6144,6 +6150,8 @@ NoteDrag::motion (GdkEvent * event, bool first_move)
                        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);
+
+                       _editor->set_snapped_cursor_position( _region->source_beats_to_absolute_samples(_primary->note()->time()) );
                }
        }
 }
@@ -6254,6 +6262,15 @@ AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lin
 
                pair<samplepos_t, samplepos_t> r = (*i)->get_point_x_range ();
 
+               //need a special detection for automation lanes (not region gain line)
+               //TODO:  if we implement automation regions, this check can probably be removed
+               AudioRegionGainLine *argl = dynamic_cast<AudioRegionGainLine*> ((*i).get());
+               if (!argl) {
+                       //in automation lanes, the EFFECTIVE range should be considered 0->max_samplepos (even if there is no line)
+                       r.first = 0;
+                       r.second = max_samplepos;
+               }
+               
                /* check this range against all the AudioRanges that we are using */
                list<AudioRange>::const_iterator k = _ranges.begin ();
                while (k != _ranges.end()) {
@@ -6956,16 +6973,11 @@ CrossfadeEdgeDrag::aborted (bool)
 
 RegionCutDrag::RegionCutDrag (Editor* e, ArdourCanvas::Item* item, samplepos_t pos)
        : Drag (e, item, true)
-       , line (new EditorCursor (*e))
 {
-       line->set_position (pos);
-       line->show ();
-       line->track_canvas_item().reparent (_editor->_drag_motion_group);
 }
 
 RegionCutDrag::~RegionCutDrag ()
 {
-       delete line;
 }
 
 void
@@ -6978,10 +6990,6 @@ RegionCutDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
 void
 RegionCutDrag::motion (GdkEvent* event, bool)
 {
-       MusicSample pos (_drags->current_pointer_sample(), 0);
-       _editor->snap_to_with_modifier (pos, event);
-
-       line->set_position (pos.sample);
 }
 
 void
@@ -6992,7 +7000,6 @@ RegionCutDrag::finished (GdkEvent* event, bool)
 
        MusicSample pos (_drags->current_pointer_sample(), 0);
        _editor->snap_to_with_modifier (pos, event);
-       line->hide ();
 
        RegionSelection rs = _editor->get_regions_from_selection_and_mouse (pos.sample);
 
@@ -7000,7 +7007,7 @@ RegionCutDrag::finished (GdkEvent* event, bool)
                return;
        }
 
-       _editor->split_regions_at (pos, rs, false);
+       _editor->split_regions_at (pos, rs);
 }
 
 void