AlphaTab.Rendering.Utils.BoundsLookup.GetBeatAtPos C# (CSharp) Method

GetBeatAtPos() public method

public GetBeatAtPos ( float x, float y ) : Beat
x float
y float
return AlphaTab.Model.Beat
        public Beat GetBeatAtPos(float x, float y)
        {
            //
            // find a bar which matches in y-axis
            var bottom = 0;
            var top = StaveGroups.Count - 1;

            var staveGroupIndex = -1;
            while (bottom <= top)
            {
                var middle = (top + bottom) / 2;
                var group = StaveGroups[middle];

                // found?
                if (y >= group.RealBounds.Y && y <= (group.RealBounds.Y + group.RealBounds.H))
                {
                    staveGroupIndex = middle;
                    break;
                }
                // search in lower half
                if (y < group.RealBounds.Y)
                {
                    top = middle - 1;
                }
                // search in upper half
                else
                {
                    bottom = middle + 1;
                }
            }

            // no bar found
            if (staveGroupIndex == -1) return null;

            //
            // Find the matching bar in the row
            var staveGroup = StaveGroups[staveGroupIndex];

            var bar = staveGroup.FindBarAtPos(x);

            if (bar != null)
            {
                return bar.FindBeatAtPos(x, y);
            }

            return null;
        }