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(); }
private IList ReadStreamAsList(TextReader reader, int maxRecords, DataTable dt) { if (reader == null) { throw new ArgumentNullException(nameof(reader), "The reader of the Stream can´t be null"); } HeaderText = string.Empty; FooterText = string.Empty; IList result; using (var recordReader = new TextReaderWrapper(reader)) { ResetFields(); if (_objectEngine) { result = new ArrayList(); } else { result = new List <T>(); } var currentRecord = 0; var streamInfo = new StreamInfoProvider(reader); using (var freader = new ForwardReader(recordReader, RecordInfo.IgnoreLast)) { freader.DiscardForward = true; string currentLine, completeLine; LineNumber = 1; completeLine = freader.ReadNextLine(); currentLine = completeLine; if (MustNotifyProgress) // Avoid object creation { OnProgress(new ProgressEventArgs(0, -1, streamInfo.Position, streamInfo.TotalBytes)); } if (RecordInfo.IgnoreFirst > 0) { for (var i = 0; i < RecordInfo.IgnoreFirst && currentLine != null; i++) { HeaderText += currentLine + Environment.NewLine; currentLine = freader.ReadNextLine(); LineNumber++; } } var byPass = false; if (maxRecords < 0) { maxRecords = int.MaxValue; } var line = new LineInfo(currentLine) { mReader = freader }; var values = new object[RecordInfo.FieldCount]; while (currentLine != null && currentRecord < maxRecords) { completeLine = currentLine; try { TotalRecords++; currentRecord++; line.ReLoad(currentLine); var skip = false; var record = (T)RecordInfo.Operations.CreateRecordHandler(); if (MustNotifyProgress) // Avoid object creation { OnProgress(new ProgressEventArgs(currentRecord, -1, streamInfo.Position, streamInfo.TotalBytes)); } Events.BeforeReadEventArgs <T> e = null; if (MustNotifyRead) { e = new BeforeReadEventArgs <T>(this, record, currentLine, LineNumber); skip = OnBeforeReadRecord(e); if (e.RecordLineChanged) { line.ReLoad(e.RecordLine); } } if (skip == false) { if (RecordInfo.Operations.StringToRecord(record, line, values)) { if (MustNotifyRead) // Avoid object creation { skip = OnAfterReadRecord(currentLine, record, e.RecordLineChanged, LineNumber); } if (skip == false) { if (dt == null) { result.Add(record); } else { dt.Rows.Add(RecordInfo.Operations.RecordToValues(record)); } } } } } catch (Exception ex) { switch (ErrorManager.ErrorMode) { case ErrorMode.ThrowException: byPass = true; throw; case ErrorMode.IgnoreAndContinue: break; case ErrorMode.SaveAndContinue: var err = new ErrorInfo { LineNumber = freader.LineNumber, ExceptionInfo = ex, Text = completeLine }; ErrorManager.AddError(err); break; } } finally { if (byPass == false) { currentLine = freader.ReadNextLine(); LineNumber++; } } } if (RecordInfo.IgnoreLast > 0) { FooterText = freader.RemainingText; } } } return(result); }