private TickPair snapRightTick(TickPair tickPair, GridPoint gridPoint,
            IEnumerable<TickPair> closeToRight,
            IEnumerable<TickPair> closeToRight5, SnapConfig config)
        {
            var gridTick = Int32.MinValue;
            var tickPair5 = Int32.MinValue;
            var tickPair6 = Int32.MinValue;

            if (gridPoint != null && config.SnapGrid)
            {
                if (tickPair.Up.IsCloseTick(gridPoint.Tick))
                    gridTick = gridPoint.Tick;
            }
            if (config.SnapG5 && closeToRight5 != null && closeToRight5.Any())
            {
                var closeDown = closeToRight5.Where(x => x.Down.IsCloseTick(tickPair.Up)).ToList();
                var closeUp = closeToRight5.Where(x => x.Up.IsCloseTick(tickPair.Up)).ToList();

                if (closeDown.Any())
                {
                    var minDown = closeDown.Select(x => new { Dist = (tickPair.Up - x.Down).Abs(), Val = x.Down }).OrderBy(x => x.Dist).FirstOrDefault().Val;

                    if (tickPair.Up.IsCloseTick(minDown))
                    {
                        tickPair5 = minDown;
                    }
                    else if (gridPoint != null && config.SnapGrid && gridTick.IsNotNull())
                    {
                        var gd = gridTick.DistSq(tickPair.Up);
                        if (gd < minDown.DistSq(tickPair.Up))
                        {
                            if (tickPair.Up.IsCloseTick(gridTick))
                                tickPair5 = gridTick;
                        }
                        else
                        {
                            if (tickPair.Up.IsCloseTick(minDown))
                                tickPair5 = minDown;
                        }
                    }

                }
                if (closeUp.Any())
                {
                    var maxUp = closeUp.Select(x => new { Dist = (tickPair.Up - x.Up).Abs(), Val = x.Up }).OrderBy(x => x.Dist).FirstOrDefault().Val;

                    if (tickPair.Up.IsCloseTick(maxUp))
                    {
                        tickPair5 = maxUp;
                    }
                    else if (gridPoint != null && config.SnapGrid && gridTick.IsNotNull())
                    {
                        var gd = gridTick.DistSq(tickPair.Up);
                        if (gd < maxUp.DistSq(tickPair.Up))
                        {
                            if (tickPair.Up.IsCloseTick(gridTick))
                                tickPair5 = gridTick;
                        }
                        else
                        {
                            if (tickPair.Up.IsCloseTick(maxUp))
                                tickPair5 = maxUp;
                        }
                    }

                }

            }
            if (config.SnapG6 && closeToRight != null && closeToRight.Any())
            {
                var closeDown = closeToRight.Where(x => x.Down.IsCloseTick(tickPair.Up)).ToList();
                var closeUp = closeToRight.Where(x => x.Up.IsCloseTick(tickPair.Up)).ToList();

                if (closeDown.Any())
                {
                    var minDown = closeDown.Select(x => new { Dist = (tickPair.Up - x.Down).Abs(), Val = x.Down }).OrderBy(x => x.Dist).FirstOrDefault().Val;

                    if (tickPair.Up.IsCloseTick(minDown))
                    {
                        tickPair6 = minDown;
                    }
                    else if (gridPoint != null && config.SnapGrid && gridTick.IsNotNull())
                    {
                        var gd = gridTick.DistSq(tickPair.Up);
                        if (gd < minDown.DistSq(tickPair.Up))
                        {
                            if (tickPair.Up.IsCloseTick(gridTick))
                                tickPair6 = gridTick;
                        }
                        else
                        {
                            if (tickPair.Up.IsCloseTick(minDown))
                                tickPair6 = minDown;
                        }
                    }

                }
                if (closeUp.Any())
                {
                    var maxUp = closeUp.Select(x => new { Dist = (tickPair.Up - x.Up).Abs(), Val = x.Up }).OrderBy(x => x.Dist).FirstOrDefault().Val;

                    if (tickPair.Up.IsCloseTick(maxUp))
                    {
                        tickPair6 = maxUp;
                    }
                    else if (gridPoint != null && config.SnapGrid && gridTick.IsNotNull())
                    {
                        var gd = gridTick.DistSq(tickPair.Up);
                        if (gd < maxUp.DistSq(tickPair.Up))
                        {
                            if (tickPair.Up.IsCloseTick(gridTick))
                                tickPair6 = gridTick;
                        }
                        else
                        {
                            if (tickPair.Up.IsCloseTick(maxUp))
                                tickPair6 = maxUp;
                        }
                    }

                }
            }
            else if (gridPoint != null && config.SnapGrid && gridTick.IsNotNull())
            {
                if (tickPair.Up.IsCloseTick(gridTick))
                    tickPair.Up = gridTick;
            }
            var ret = new[] { tickPair6, tickPair5, gridTick }.Where(x => x.IsNotNull());
            if (ret.Any())
            {
                tickPair.Up = ret.Select(x => new { Dist = (x - tickPair.Up).Abs(), Val = x }).OrderBy(x => x.Dist).FirstOrDefault().Val;
            }
            if (tickPair.Up.IsNull() == false &&
                tickPair.Up < tickPair.Down)
            {
                tickPair.Up = tickPair.Down;
            }
            return tickPair;
        }
        public TickPair SnapLeftRightTicks(TickPair tickPair, SnapConfig config)
        {
            GridPoint gridPointDown = null;
            GridPoint gridPointUp = null;

            if (config.SnapGrid)
            {
                gridPointDown = guitarTrack.GetCloseGridPointToTick(tickPair.Down);
                gridPointUp = guitarTrack.GetCloseGridPointToTick(tickPair.Up);
            }

            IEnumerable<TickPair> closeLeft6 = null;
            IEnumerable<TickPair> closeRight6 = null;

            IEnumerable<TickPair> closeLeft5 = null;
            IEnumerable<TickPair> closeRight5 = null;

            if (config.SnapG6 && EditorPro.IsLoaded)
            {
                var closeChords6 = Messages.Chords.GetBetweenTick(tickPair.Expand(Utility.TickCloseWidth)).ToList();
                closeLeft6 = closeChords6.Where(x => x.TickPair.IsClose(tickPair.Down)).Select(x => x.TickPair);
                closeRight6 = closeChords6.Where(x => x.TickPair.IsClose(tickPair.Up)).Select(x => x.TickPair);

                var closePowerups = Messages.Powerups.GetBetweenTick(tickPair.Expand(Utility.TickCloseWidth)).ToList();
                if (closePowerups.Any())
                {
                    closeLeft6 = closeLeft6.Concat(closePowerups.Where(x => x.TickPair.IsClose(tickPair.Down)).Select(x => x.TickPair));
                    closeRight6 = closeRight6.Concat(closePowerups.Where(x => x.TickPair.IsClose(tickPair.Up)).Select(x => x.TickPair));
                }

                var closeSolo = Messages.Solos.GetBetweenTick(tickPair.Expand(Utility.TickCloseWidth)).ToList();
                if (closeSolo.Any())
                {
                    closeLeft6 = closeLeft6.Concat(closeSolo.Where(x => x.TickPair.IsClose(tickPair.Down)).Select(x => x.TickPair));
                    closeRight6 = closeRight6.Concat(closeSolo.Where(x => x.TickPair.IsClose(tickPair.Up)).Select(x => x.TickPair));
                }
            }
            if (IsPro && config.SnapG5 && Editor5.IsLoaded)
            {
                var closeChords5 = Editor5.Messages.Chords.GetBetweenTick(tickPair.Expand(Utility.TickCloseWidth)).ToList();
                closeLeft5 = closeChords5.Where(x => x.TickPair.IsClose(tickPair.Down)).Select(x => x.TickPair);
                closeRight5 = closeChords5.Where(x => x.TickPair.IsClose(tickPair.Up)).Select(x => x.TickPair);

                var closePowerups = Editor5.Messages.Powerups.GetBetweenTick(tickPair.Expand(Utility.TickCloseWidth)).ToList();
                if (closePowerups.Any())
                {
                    closeLeft5 = closeLeft5.Concat(closePowerups.Where(x => x.TickPair.IsClose(tickPair.Down)).Select(x => x.TickPair));
                    closeRight5 = closeRight5.Concat(closePowerups.Where(x => x.TickPair.IsClose(tickPair.Up)).Select(x => x.TickPair));
                }

                var closeSolo = Editor5.Messages.Solos.GetBetweenTick(tickPair.Expand(Utility.TickCloseWidth)).ToList();
                if (closeSolo.Any())
                {
                    closeLeft5 = closeLeft5.Concat(closeSolo.Where(x => x.TickPair.IsClose(tickPair.Down)).Select(x => x.TickPair));
                    closeRight5 = closeRight5.Concat(closeSolo.Where(x => x.TickPair.IsClose(tickPair.Up)).Select(x => x.TickPair));
                }
            }

            var oldPair = tickPair;

            var tickPairDown = snapLeftTick(oldPair, gridPointDown, closeLeft6, closeLeft5, config);
            var tickPairUp = snapRightTick(oldPair, gridPointUp, closeRight6, closeRight5, config);

            if (tickPairDown.Down != tickPair.Down)
            {
                AddSnapPointToRender(GetClientPointFromTick(tickPairDown.Down));
            }
            if (tickPairUp.Up != tickPair.Up)
            {
                AddSnapPointToRender(GetClientPointFromTick(tickPairUp.Up));
            }
            return new TickPair(tickPairDown.Down, tickPairUp.Up);
        }