public void AppendBeatGroup(BeatGroup beatGroup) { double start = 0; if (_beatGroups.Count > 0) { BeatGroup lastGroup = _beatGroups.Last(); start = lastGroup.Start + lastGroup.Duration; } beatGroup.Start = start; _beatGroups.Add(beatGroup); }
public static BeatTimeline FromTimestamps(List <double> beats) { var timeline = new BeatTimeline(); if (beats.Count < 2) { return(timeline); } timeline.AppendBeatGroup(BeatGroup.Pause(TimeSpan.FromSeconds(beats[0]))); for (int i = 1; i < beats.Count; i++) { timeline.AppendBeatGroup(BeatGroup.SingleBeat(TimeSpan.FromSeconds(beats[i] - beats[i - 1]))); } return(timeline); }
private void ProgressHasChanged() { BeatGroup activeGroup = FindActiveGroup(Progress); if (activeGroup != null) { BeatProgress = activeGroup.GetBeatProgress(Progress); } else { BeatProgress = BeatPattern.BeatEnd; } OnProgressChanged(new ProgressChangedEventArgs(Progress, BeatProgress)); if (activeGroup != _currentBeatGroup) { _currentBeatGroup = activeGroup; OnBeatGroupChanged(new BeatGroupChangedEventArgs(activeGroup)); } }
public BeatGroupChangedEventArgs(BeatGroup beatGroup) { BeatGroup = beatGroup; }
protected override void OnRender(DrawingContext drawingContext) { Rect fullRect = new Rect(new Point(), new Size(ActualWidth, ActualHeight)); drawingContext.PushClip(new RectangleGeometry(fullRect)); drawingContext.DrawRectangle(Background, null, fullRect); Pen linePen = new Pen(Brushes.White, 3); //drawingContext.DrawLine(linePen, new Point(0, ActualHeight / 2), new Point(ActualWidth, ActualHeight / 2)); drawingContext.DrawLine(new Pen(Brushes.Red, 11), new Point(Midpoint * ActualWidth, 0), new Point(Midpoint * ActualWidth, ActualHeight)); if (Timeline != null) { double timeFrom = _progress - Midpoint * TotalDisplayedDuration; double timeTo = _progress + (1 - Midpoint) * TotalDisplayedDuration; double position = Math.Floor(timeFrom); List <double> beatPositions = new List <double>(); while (position < timeTo) { BeatGroup group = Timeline.FindActiveGroup(position); if (group == null) { group = Timeline.FindNextGroup(position); if (group != null) { position = group.Start; } } if (group == null) { break; } position = group.FindStartingPoint(position); while (position < group.End && position < timeTo) { foreach (double beat in group.Pattern.BeatPositions) { double relativePosition = (((beat * group.ActualPatternDuration) + position - timeFrom) / (timeTo - timeFrom)); beatPositions.Add(relativePosition); } position += group.ActualPatternDuration; } } const double safeSpace = 30; double y = ActualHeight / 2.0; if (_simpleRendering) { DrawLine(drawingContext, Colors.Red, new Point(-safeSpace, y), new Point(ActualWidth + safeSpace, y)); foreach (double pos in beatPositions) { DrawLine(drawingContext, Colors.Lime, new Point(pos * ActualWidth, -5), new Point(pos * ActualWidth, ActualHeight + 5)); } } else { PathGeometry geometry = new PathGeometry(); if (beatPositions.Count > 0) { double start = Math.Min(0, beatPositions.First()); double end = Math.Max(1, beatPositions.Last()); PathFigure figure = new PathFigure { StartPoint = new Point(start * ActualWidth - safeSpace, y) }; geometry.Figures.Add(figure); foreach (double beatPosition in beatPositions) { AppendSwiggely(figure, new Point(beatPosition * ActualWidth, y)); } figure.Segments.Add(new LineSegment(new Point(end * ActualWidth + safeSpace, y), true)); } else { geometry.Figures.Add(new PathFigure(new Point(-safeSpace, y), new[] { new LineSegment(new Point(ActualWidth + safeSpace, y), true) }, false)); } drawingContext.DrawGeometry(null, new Pen(new SolidColorBrush(Colors.Red) { Opacity = 0.5 }, 4) { LineJoin = PenLineJoin.Round }, geometry); drawingContext.DrawGeometry(null, new Pen(new SolidColorBrush(Colors.White) { Opacity = 1.0 }, 2) { LineJoin = PenLineJoin.Round }, geometry); } } drawingContext.Pop(); }