void Instance_Stopped(object sender, EventArgs e) { ((BackgroundLayerDelegate)BackgroundLayer.Delegate).BlinkingCountdown = 0; BackgroundLayer.SetNeedsDisplay(); BeatIndex = 0; CurrentBpmInterval = Layer.OffsetBpm; while (StreamInfoProvider.IsSilence(Layer.Beat[BeatIndex].StreamInfo)) { CurrentBpmInterval += Layer.Beat[BeatIndex++].Bpm; BeatIndex %= Layer.Beat.Count; } }
public void Progress() { if (Metronome.Instance.PlayState == Metronome.PlayStates.Stopped) { return; } CurrentBpmInterval -= GraphingHelper.ElapsedBpm; var bgDelegate = (BackgroundLayerDelegate)BackgroundLayer.Delegate; // see if a cell played while (CurrentBpmInterval <= 0) { CurrentBpmInterval += Layer.Beat[BeatIndex++].Bpm; BeatIndex %= Layer.Beat.Count; // fold in the silent cells while (StreamInfoProvider.IsSilence(Layer.Beat[BeatIndex].StreamInfo)) { CurrentBpmInterval += Layer.Beat[BeatIndex++].Bpm; BeatIndex %= Layer.Beat.Count; } //CurrentBpmInterval += Layer.Beat[BeatIndex].Bpm; // tell the ring to start a blink bgDelegate.BlinkingCountdown = BackgroundLayerDelegate.BlinkCount; } // trigger blink animation if enabled if (UserSettings.GetSettings().BlinkingEnabled&& bgDelegate.BlinkingCountdown > 0) { BackgroundLayer.SetNeedsDisplay(); } }
public Ring(Layer layer, CALayer superLayer, double startPoint, double endPoint, double beatLength) { Layer = layer; _superLayer = superLayer; // init the CALayers BackgroundLayer = new CALayer() { ContentsScale = NSScreen.MainScreen.BackingScaleFactor, //Frame = superLayer.Frame, Delegate = new BackgroundLayerDelegate(this) }; TickMarksLayer = new CALayer() { ContentsScale = NSScreen.MainScreen.BackingScaleFactor, //Frame = superLayer.Frame, Delegate = new TickLayerDelegate(this, beatLength, layer), ZPosition = 5 }; superLayer.AddSublayer(BackgroundLayer); superLayer.AddSublayer(TickMarksLayer); // find the tick rotations TickRotations = new LinkedList <nfloat>(); if (!Layer.GetAllStreams().All(x => StreamInfoProvider.IsSilence(x.Info))) { nfloat frontOffset = 0; foreach (BeatCell bc in layer.Beat) { if (StreamInfoProvider.IsSilence(bc.StreamInfo)) { // add a silent value to the previous cell value if (TickRotations.Last != null) { TickRotations.Last.Value += (nfloat)(bc.Bpm / beatLength * TWOPI); } else { frontOffset = (nfloat)(bc.Bpm / beatLength * TWOPI); } } else { TickRotations.AddLast((nfloat)(bc.Bpm / beatLength * TWOPI)); } } if (frontOffset > 0) { TickRotations.Last.Value += frontOffset; } } InnerRadiusLocation = (nfloat)startPoint * superLayer.Frame.Width; OuterRadiusLocation = (nfloat)endPoint * superLayer.Frame.Width; StartPoint = startPoint; EndPoint = endPoint; //DrawStaticElements(); // set the offset CurrentBpmInterval = Layer.OffsetBpm; while (StreamInfoProvider.IsSilence(Layer.Beat[BeatIndex].StreamInfo)) { CurrentBpmInterval += Layer.Beat[BeatIndex++].Bpm; BeatIndex %= Layer.Beat.Count; } // do some reseting when playback stops Metronome.Instance.Stopped += Instance_Stopped; }
public void DrawLayer(CALayer layer, CGContext context) { context.SaveState(); context.SetLineWidth(2); // draw each tickmark int center = (int)(layer.Frame.Width / 2); context.TranslateCTM(center, center); nfloat initialRotation = (nfloat)((Layer.OffsetBpm + Layer.Beat.TakeWhile(x => StreamInfoProvider.IsSilence(x.StreamInfo)).Select(x => x.Bpm).Sum()) / BeatLength * -TWOPI); context.RotateCTM(initialRotation); double total = 0; int start = (int)(Ring.InnerRadiusLocation); int end = (int)(Ring.OuterRadiusLocation); if (Ring.TickRotations.Any()) { var rotation = Ring.TickRotations.First; while (total < TWOPI) { if (rotation == null) { rotation = Ring.TickRotations.First; } context.MoveTo(0, start); context.AddLineToPoint(0, end); context.RotateCTM(-rotation.Value); total += rotation.Value; rotation = rotation.Next; } context.ReplacePathWithStrokedPath(); } context.Clip(); // clipped gradient var gradient = new CGGradient( CGColorSpace.CreateDeviceRGB(), new CGColor[] { NSColor.Gray.CGColor, NSColor.White.CGColor } ); context.DrawRadialGradient( gradient, new CGPoint(0, 0), Ring.InnerRadiusLocation, new CGPoint(0, 0), Ring.OuterRadiusLocation, CGGradientDrawingOptions.None ); context.RestoreState(); }