Example #1
0
        private Point GetPointFromPosition(TimedPosition position)
        {
            double x = PositionToX(position.TimeStamp);
            double y = PositionToY(position.Position);

            return(new Point(x, y));
        }
Example #2
0
        private void UpdateSelectedPosition()
        {
            TimedPosition pos = GetPositionFromPoint(_mousePos);

            _position.TimeStamp = pos.TimeStamp;
            _position.Position  = pos.Position;
        }
Example #3
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (IsReadOnly)
            {
                return;
            }

            _mousePos = e.GetPosition(this);

            TimeSpan timeFrom = Progress - TotalDisplayedDuration.Multiply(Midpoint);
            TimeSpan timeTo   = Progress + TotalDisplayedDuration.Multiply(1 - Midpoint);

            List <TimedPosition> absoluteBeatPositions = Positions.GetPositions(timeFrom, timeTo).ToList();

            double        minDist = double.MaxValue;
            TimedPosition closest = null;

            foreach (TimedPosition position in absoluteBeatPositions)
            {
                double distance = GetPointFromPosition(position).DistanceTo(_mousePos);
                if (distance < minDist)
                {
                    closest = position;
                    minDist = distance;
                }
            }

            if (closest == null)
            {
                return;
            }

            if (minDist > 20)
            {
                return;
            }

            _position = closest;
            _down     = true;

            CaptureMouse();
        }
Example #4
0
        public static void GetMinMaxPositions(List <TimedPosition> positions, out List <TimedPosition> min, out List <TimedPosition> max)
        {
            min = new List <TimedPosition>();
            max = new List <TimedPosition>();

            if (positions == null || positions.Count < 1)
            {
                return;
            }

            TimeSpan start    = positions[0].TimeStamp;
            TimeSpan duration = positions.Last().TimeStamp - start;

            int  lastExtremeIndex = -1;
            byte lastValue        = positions[0].Position;
            byte lastExtremeValue = lastValue;

            byte lowest  = lastValue;
            byte highest = lastValue;

            bool?goingUp = null;

            for (int index = 0; index < positions.Count; index++)
            {
                // Direction unknown
                if (goingUp == null)
                {
                    if (positions[index].Position < lastExtremeValue)
                    {
                        goingUp = false;
                    }
                    else if (positions[index].Position > lastExtremeValue)
                    {
                        goingUp = true;
                    }
                }
                else
                {
                    if ((positions[index].Position < lastValue && (bool)goingUp) ||  //previous was highpoint
                        (positions[index].Position > lastValue && (bool)!goingUp) || //previous was lowpoint
                        (index == positions.Count - 1))                              //last action
                    {
                        for (int i = lastExtremeIndex + 1; i < index; i++)
                        {
                            TimedPosition action = positions[i].Duplicate();

                            if (positions[i].Position == lowest)
                            {
                                min.Add(action);
                            }
                            else if (positions[i].Position == highest)
                            {
                                max.Add(action);
                            }

                            // Only extreme Values for now ...
                        }

                        lastExtremeValue = positions[index - 1].Position;
                        lastExtremeIndex = index - 1;

                        highest = lastExtremeValue;
                        lowest  = lastExtremeValue;

                        goingUp ^= true;
                    }
                }

                lastValue = positions[index].Position;
                if (lastValue > highest)
                {
                    highest = lastValue;
                }
                if (lastValue < lowest)
                {
                    lowest = lastValue;
                }
            }

            var last = positions.Last();

            if (lastExtremeValue < last.Position)
            {
                max.Add(last.Duplicate());
            }
            else
            {
                min.Add(last.Duplicate());
            }
        }