Initial Gain Coefficient tweaks
[ardour.git] / gtk2_ardour / editor_drag.cc
index b1a1ba62d031dd6c533cc410a8bcd5358bb1438f..9fbf2efce809682e5b5964ba6dc7fbb131b706af 100644 (file)
@@ -651,11 +651,12 @@ RegionDrag::apply_track_delta (const int start, const int delta, const int skip,
                return start;
        }
 
+       const int tavsize  = _time_axis_views.size();
        const int dt = delta > 0 ? +1 : -1;
-       int current = start;
-       int target  = start + delta - skip;
+       int current  = start;
+       int target   = start + delta - skip;
 
-       assert (current < 0 || current >= _time_axis_views.size() || !_time_axis_views[current]->hidden());
+       assert (current < 0 || current >= tavsize || !_time_axis_views[current]->hidden());
        assert (skip == 0 || (skip < 0 && delta < 0) || (skip > 0 && delta > 0));
 
        while (current >= 0 && current != target) {
@@ -663,10 +664,10 @@ RegionDrag::apply_track_delta (const int start, const int delta, const int skip,
                if (current < 0 && dt < 0) {
                        break;
                }
-               if (current >= _time_axis_views.size() && dt > 0) {
+               if (current >= tavsize && dt > 0) {
                        break;
                }
-               if (current < 0 || current >= _time_axis_views.size()) {
+               if (current < 0 || current >= tavsize) {
                        continue;
                }
 
@@ -689,11 +690,12 @@ RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer, int s
                return false;
        }
 
+       const int tavsize  = _time_axis_views.size();
        for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                int n = apply_track_delta (i->time_axis_view, delta_track, skip_invisible);
-               assert (n < 0 || n >= _time_axis_views.size() || !_time_axis_views[n]->hidden());
+               assert (n < 0 || n >= tavsize || !_time_axis_views[n]->hidden());
 
-               if (i->time_axis_view < 0 || i->time_axis_view >= _time_axis_views.size()) {
+               if (i->time_axis_view < 0 || i->time_axis_view >= tavsize) {
                        /* already in the drop zone */
                        if (delta_track >= 0) {
                                /* downward motion - OK if others are still not in the dropzone */
@@ -705,7 +707,7 @@ RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer, int s
                if (n < 0) {
                        /* off the top */
                        return false;
-               } else if (n >= int (_time_axis_views.size())) {
+               } else if (n >= tavsize) {
                        /* downward motion into drop zone. That's fine. */
                        continue;
                }
@@ -798,7 +800,10 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
 
                /* Work out the change in y */
 
-               if (_last_pointer_time_axis_view < 0) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
+               if (!rtv || !rtv->is_track()) {
+                       /* ignore busses early on. we can't move any regions on them */
+               } else if (_last_pointer_time_axis_view < 0) {
                        /* Was in the drop-zone, now over a track.
                         * Hence it must be an upward move (from the bottom)
                         *
@@ -814,11 +819,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                         */
                        delta_time_axis_view = current_pointer_time_axis_view - _time_axis_views.size () + _ddropzone - _pdropzone;
                } else {
-                       /* ignore busses early on. we can't move any regions on them */
-                       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
-                       if (rtv && rtv->is_track()) {
-                               delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
-                       }
+                       delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
                }
 
                /* TODO needs adjustment per DraggingView,
@@ -897,15 +898,17 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                 * distance calculation is not needed (and would not work, either
                 * because the dropzone is "packed").
                 *
-                * Except when partially(!) moving regions out of dropzone in a large step.
+                * Except when [partially] moving regions out of dropzone in a large step.
                 * (the mouse may or may not remain in the DZ)
                 * Hidden tracks at the bottom of the TAV need to be skipped.
+                *
+                * This also handles the case if the mouse entered the DZ
+                * in a large step (exessive delta), either due to fast-movement,
+                * autoscroll, laggy UI. _ddropzone copensates for that (see "move into dz" above)
                 */
-               assert(_pdropzone >= _ddropzone);
-               if (delta_time_axis_view < 0 && -delta_time_axis_view >= _pdropzone - _ddropzone)
-               {
-                       const int dt = delta_time_axis_view + _pdropzone - _ddropzone;
-                       assert (dt <= 0);
+               if (delta_time_axis_view < 0 && (int)_ddropzone - delta_time_axis_view >= (int)_pdropzone) {
+                       const int dt = delta_time_axis_view + (int)_pdropzone - (int)_ddropzone;
+                       assert(dt <= 0);
                        delta_skip = apply_track_delta(_time_axis_views.size(), dt, 0, true)
                                -_time_axis_views.size() - dt;
                }
@@ -1007,8 +1010,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                        this_delta_layer = - i->layer;
                }
 
-               int this_delta_time_axis_view = delta_time_axis_view;
-               this_delta_time_axis_view = apply_track_delta(i->time_axis_view, delta_time_axis_view, delta_skip) - i->time_axis_view;
+               int this_delta_time_axis_view = apply_track_delta(i->time_axis_view, delta_time_axis_view, delta_skip) - i->time_axis_view;
 
                int track_index = i->time_axis_view + this_delta_time_axis_view;
                assert(track_index >= 0);
@@ -1017,7 +1019,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                        /* Track is in the Dropzone */
 
                        i->time_axis_view = track_index;
-                       assert(i->time_axis_view >= _time_axis_views.size());
+                       assert(i->time_axis_view >= (int) _time_axis_views.size());
                        if (cur_y >= 0) {
 
                                double yposition = 0;
@@ -1028,13 +1030,9 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                                /* store index of each new playlist as a negative count, starting at -1 */
 
                                if (pdz == playlist_dropzone_map.end()) {
-
-                                       int n = playlist_dropzone_map.size() + 1;
-
                                        /* compute where this new track (which doesn't exist yet) will live
                                           on the y-axis.
                                        */
-
                                        yposition = last_track_bottom_edge; /* where to place the top edge of the regionview */
 
                                        /* How high is this region view ? */
@@ -1163,13 +1161,20 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                                 * DZ by grabbing the region in the bottom track.
                                 */
                                assert(current_pointer_time_axis_view >= 0);
-                               dtz = std::min((int)_pdropzone, -delta_time_axis_view);
+                               dtz = std::min((int)_pdropzone, (int)_ddropzone - delta_time_axis_view);
                                _pdropzone -= dtz;
                        }
 
                        /* only move out of the zone if the movement is OK */
                        if (_pdropzone == 0 && delta_time_axis_view != 0) {
+                               assert(delta_time_axis_view < 0);
                                _last_pointer_time_axis_view = current_pointer_time_axis_view;
+                               /* if all logic and maths are correct, there is no need to assign the 'current' pointer.
+                                * the current position can be calculated as follows:
+                                */
+                               // a well placed oofus attack can still throw this off.
+                               // likley auto-scroll related, printf() debugging may tell, commented out for now.
+                               //assert (current_pointer_time_axis_view == _time_axis_views.size() - dtz + _ddropzone + delta_time_axis_view);
                        }
                } else {
                        /* last motion event was also over a time axis view */
@@ -1352,7 +1357,11 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region,
        try {
                if (boost::dynamic_pointer_cast<AudioRegion> (region)) {
                        list<boost::shared_ptr<AudioTrack> > audio_tracks;
-                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), region->n_channels(), ARDOUR::Normal, 0, 1, region->name());
+                       uint32_t output_chan = region->n_channels();
+                       if ((Config->get_output_auto_connect() & AutoConnectMaster) && _editor->session()->master_out()) {
+                               output_chan =  _editor->session()->master_out()->n_inputs().n_audio();
+                       }
+                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, ARDOUR::Normal, 0, 1, region->name());
                        RouteTimeAxisView* rtav = _editor->axis_view_from_route (audio_tracks.front());
                        if (rtav) {
                                rtav->set_height (original->current_height());
@@ -1412,7 +1421,7 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed
                        where = i->view->region()->position();
                }
 
-               if (i->time_axis_view < 0 || i->time_axis_view >= _time_axis_views.size()) {
+               if (i->time_axis_view < 0 || i->time_axis_view >= (int)_time_axis_views.size()) {
                        /* dragged to drop zone */
 
                        PlaylistMapping::iterator pm;
@@ -1494,7 +1503,7 @@ RegionMoveDrag::finished_no_copy (
                        continue;
                }
 
-               if (i->time_axis_view < 0 || i->time_axis_view >= _time_axis_views.size()) {
+               if (i->time_axis_view < 0 || i->time_axis_view >= (int)_time_axis_views.size()) {
                        /* dragged to drop zone */
 
                        PlaylistMapping::iterator pm;
@@ -1841,7 +1850,7 @@ void
 RegionInsertDrag::finished (GdkEvent *, bool)
 {
        int pos = _views.front().time_axis_view;
-       assert(pos >= 0 && pos < _time_axis_views.size());
+       assert(pos >= 0 && pos < (int)_time_axis_views.size());
 
        RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[pos]);