Пример #1
0
        public List <TimeSpan> GetBeats()
        {
            List <TimeSpan> result = new List <TimeSpan>();

            TimeSpan threshold = TimeSpan.FromMilliseconds(10);

            TimeSpan position = TimePanel.GetPosition(_parent);
            TimeSpan duration = TimePanel.GetDuration(_parent);

            TimeSpan currentPosition = position;
            TimeSpan endposition     = position + duration;

            var pattern = BeatDefinition.Pattern;

            TimeSpan beatLength = PatternDuration.Divide(pattern.Length);

            while (endposition - currentPosition > threshold)
            {
                foreach (bool isactive in pattern)
                {
                    if (isactive)
                    {
                        result.Add(currentPosition);
                    }
                    currentPosition += beatLength;

                    if (endposition - currentPosition <= threshold)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public void SetBeatSegment(BeatSegment summary)
        {
            TimePanel.SetPosition(this, TimeSpan.FromTicks(summary.Position));
            TimePanel.SetDuration(this, TimeSpan.FromTicks(summary.Duration));

            BeatLine.SetBeatSegment(summary);
        }
Пример #3
0
        public void Snap()
        {
            EnsureParent();
            if (_parent == null)
            {
                return;
            }

            TimeSpan duration = TimePanel.GetDuration(_parent);

            if (duration <= TimeSpan.Zero)
            {
                return;
            }

            if (!TimeLock)
            {
                _patternRepeats = duration.Divide(PatternDuration);
            }

            int repeats = (int)Math.Round(_patternRepeats);

            if (repeats <= 0)
            {
                repeats = 1;
            }

            duration        = PatternDuration.Multiply(repeats);
            _patternRepeats = repeats;

            TimePanel.SetDuration(_parent, duration);
        }
Пример #4
0
        public BeatSegment GetBeatSegment()
        {
            BeatSegment summary = BeatLine.GetBeatSegment();

            summary.Duration = TimePanel.GetDuration(this).Ticks;
            summary.Position = TimePanel.GetPosition(this).Ticks;

            return(summary);
        }
Пример #5
0
        private TimeSpan PositionToTimeSpan(double position)
        {
            TimeSpan duration = TimePanel.GetDuration(this);
            TimeSpan start    = TimePanel.GetDuration(this);

            double relativePosition = position / ActualWidth;

            return(start + duration.Multiply(relativePosition));
        }
Пример #6
0
        private double TimeSpanToPosition(TimeSpan position)
        {
            TimeSpan duration = TimePanel.GetDuration(this);
            TimeSpan start    = TimePanel.GetDuration(this);

            TimeSpan relativePosition  = position - start;
            double   relativePositionX = relativePosition.Divide(duration);

            return(relativePositionX * ActualWidth);
        }
Пример #7
0
        public void SetBeatDuration(TimeSpan beatDuration)
        {
            EnsureParent();
            if (_parent == null)
            {
                return;
            }

            TimeSpan duration = TimePanel.GetDuration(_parent);

            if (duration <= TimeSpan.Zero)
            {
                return;
            }

            _timeLock       = false;
            _patternRepeats = duration.Divide(beatDuration);
            PatternDuration = beatDuration;

            InvalidateVisual();
        }
Пример #8
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(Brushes.Black, null, new Rect(new Point(0, 0), new Size(ActualWidth, ActualHeight)));
            TimeSpan span    = TimePanel.GetDuration(this);
            TimeSpan handled = TimeSpan.Zero;

            while (handled <= span)
            {
                double x = TimeSpanToPosition(handled);
                drawingContext.DrawLine(new Pen(Brushes.White, 1), new Point(x, 0), new Point(x, ActualHeight));
                handled = handled.Add(Intervall);
            }

            if (_downPos != _upPos)
            {
                double xFrom = TimeSpanToPosition(_downPos);
                double xTo   = TimeSpanToPosition(_upPos);

                drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(70, 255, 0, 0)), new Pen(Brushes.Red, 1), new Rect(new Point(xFrom, 0), new Point(xTo, ActualHeight)));
            }
        }
Пример #9
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(0, 0, ActualWidth, ActualHeight));

            if (BeatDefinition == null)
            {
                return;
            }
            if (PatternDuration == TimeSpan.Zero)
            {
                return;
            }
            if (BeatDefinition.Pattern == null)
            {
                return;
            }
            if (BeatDefinition.Pattern.Length == 0)
            {
                return;
            }

            EnsureParent();
            if (_parent == null)
            {
                return;
            }

            TimeSpan duration = TimePanel.GetDuration(_parent);

            if (duration <= TimeSpan.Zero)
            {
                return;
            }

            TimeSpan handledDuration = TimeSpan.Zero;
            double   widthPerBeat;

            if (!TimeLock)
            {
                widthPerBeat = ActualWidth / duration.Divide(PatternDuration) / BeatDefinition.Pattern.Length;
            }
            else
            {
                widthPerBeat    = ActualWidth / (BeatDefinition.Pattern.Length * _patternRepeats);
                PatternDuration = duration.Divide(_patternRepeats);
            }

            double x  = 0;
            bool   on = false;

            double widthPerCylce = ActualWidth / duration.Divide(PatternDuration);

            var typeface = new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Normal,
                                        FontStretches.Normal);

            int i = 1;

            while (handledDuration < duration)
            {
                on ^= true;

                if (on)
                {
                    drawingContext.DrawRectangle(Brushes.White, null, new Rect(x, 0, widthPerCylce, ActualHeight));
                }

                var text = new FormattedText(i.ToString("D"), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 12.0, Brushes.Black, new NumberSubstitution(), TextFormattingMode.Display);

                drawingContext.DrawText(text, new Point(x, 0));

                handledDuration += PatternDuration;
                x += widthPerCylce;
                i++;
            }

            handledDuration = TimeSpan.Zero;

            x = 0;
            while (handledDuration < duration)
            {
                foreach (bool isbeat in BeatDefinition.Pattern)
                {
                    if (isbeat)
                    {
                        drawingContext.DrawLine(new Pen(Brushes.Lime, 4), new Point(x, 0), new Point(x, ActualHeight));
                    }

                    x += widthPerBeat;
                }

                handledDuration += PatternDuration;
            }

            drawingContext.DrawEllipse(TimeLock?Brushes.Green:Brushes.Red, null, new Point(6, 6), 3, 3);
        }
Пример #10
0
        private static void OnDurationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TimePanel panel = VisualTreeHelper.GetParent(d) as TimePanel;

            panel?.ChildDurationChanged(d, (TimeSpan)e.OldValue, (TimeSpan)e.NewValue);
        }