public Beam(BaseNoteValue beatNoteValue, Voice ownerVoice, bool isRoot) { this.BeatNoteValue = beatNoteValue; this.OwnerVoice = ownerVoice; this.IsRoot = isRoot; this.Elements = new List <IBeatElement>(); }
private async Task DrawSemiBeam(BaseNoteValue noteValue, VoicePart voicePart, BeamSlope beamSlope, bool isLastOfBeam) { BeatRenderer beatRenderer1, beatRenderer2; if (isLastOfBeam) { beatRenderer1 = this.Root.GetRenderer <Beat, BeatRenderer>(this.Element.PreviousBeat); beatRenderer2 = this; } else { beatRenderer1 = this; beatRenderer2 = this.Root.GetRenderer <Beat, BeatRenderer>(this.Element.NextBeat); } var position1 = beatRenderer1.GetStemPosition(); var position2 = beatRenderer2.GetStemPosition(); var beamWidth = Math.Min(this.RenderingContext.Style.MaximumSemiBeamWidth, (position2 - position1) / 2); double x0, x1; if (isLastOfBeam) { x0 = position2 - beamWidth; x1 = position2; } else { x0 = position1; x1 = position1 + beamWidth; } await this.RenderingContext.DrawBeam(noteValue, x0, beamSlope.GetY(x0), x1, beamSlope.GetY(x1), voicePart); }
public static bool TryParse(int reciprocalValue, out BaseNoteValue value) { switch (reciprocalValue) { case 1: value = BaseNoteValue.Whole; break; case 2: value = BaseNoteValue.Half; break; case 4: value = BaseNoteValue.Quater; break; case 8: value = BaseNoteValue.Eighth; break; case 16: value = BaseNoteValue.Sixteenth; break; case 32: value = BaseNoteValue.ThirtySecond; break; case 64: value = BaseNoteValue.SixtyFourth; break; case 128: value = BaseNoteValue.HundredTwentyEighth; break; case 256: value = BaseNoteValue.TwoHundredFiftySixth; break; default: value = BaseNoteValue.Whole; return(false); } return(true); }
public static BaseNoteValue Double(this BaseNoteValue value) { if (value.GetIsLongestSupported()) { throw new ArgumentOutOfRangeException(nameof(value)); } return(value + 1); }
public static BaseNoteValue Half(this BaseNoteValue value) { if (value.GetIsShortestSupported()) { throw new ArgumentOutOfRangeException(nameof(value)); } return(value - 1); }
public BeatArranger(BaseNoteValue beamNoteValue, Voice ownerVoice) { _beamNoteValue = beamNoteValue; _ownerVoice = ownerVoice; _beamStack = new Stack <Beam>(); _rootBeats = new List <IBeatElement>(); _currentCapacity = PreciseDuration.Zero; _duration = PreciseDuration.Zero; }
public static int GetInvertedDuration(this BaseNoteValue value) { var intValue = (int)value; if (intValue > 0) { throw new ArgumentOutOfRangeException(nameof(value), "only whole or shorter values are supported"); } return((int)Math.Pow(2, -intValue)); }
private double GetBeamOffset(BaseNoteValue noteValue, VoicePart voicePart) { if (noteValue > BaseNoteValue.Eighth) { throw new ArgumentException("notes with a base note value longer than eighth can't be beamed", nameof(noteValue)); } var offset = (BaseNoteValue.Eighth - noteValue) * (this.Style.BeamThickness + this.Style.BeamSpacing) + 0.5 * this.Style.BeamThickness; return(voicePart == VoicePart.Treble ? offset : -offset); }
public async Task DrawFlag(BaseNoteValue noteValue, double x, double y, VoicePart voicePart) { if (noteValue > BaseNoteValue.Eighth) { return; } var bounds = await this.PrimitiveRenderer.DrawFlag(noteValue, this.Location.X + x, this.Location.Y + y, voicePart.ToDirection()); this.Owner.EnsureHeight(voicePart, bounds.Left - this.Style.NoteStemHorizontalMargin, bounds.Right, bounds.Top, bounds.Bottom); }
public async Task DrawBeam(BaseNoteValue noteValue, double x0, double y0, double x1, double y1, VoicePart voicePart) { var offset = this.GetBeamOffset(noteValue, voicePart); x0 = x0 + this.Location.X; y0 = y0 + this.Location.Y + offset; x1 = x1 + this.Location.X; y1 = y1 + this.Location.Y + offset; var bounds = await this.PrimitiveRenderer.DrawBeam(x0, y0, x1, y1); var beamHalfThickness = voicePart == VoicePart.Treble ? Math.Min(y0, y1) - bounds.Top : bounds.Bottom - Math.Max(y0, y1); this.Owner.EnsureHeightSloped(voicePart, x0, x1, y0, y1, this.Style.NoteTailVerticalMargin + beamHalfThickness, this.Style.NoteStemHorizontalMargin); }
public NoteValue(BaseNoteValue baseValue, NoteValueAugment augment = NoteValueAugment.None, int?tuplet = null) { if (tuplet != null) { if (!NoteValue.IsValidTuplet(tuplet.Value)) { throw new ArgumentOutOfRangeException(nameof(tuplet), "invalid tuplet value"); } if (baseValue >= 0) { throw new ArgumentOutOfRangeException(nameof(tuplet), "tuplet not supported for notes equal or longer than a whole"); } } this.Base = baseValue; this.Augment = augment; this.Tuplet = tuplet; }
public double GetBeats(BaseNoteValue beatLength) { return(this.GetDuration() / beatLength.GetDuration()); }
public Task <Rect> DrawTempoSignature(double x, double y, BaseNoteValue noteValue, int beats) => this.InvokeRenderMethodReturnBoundingBox("drawTempoSignature", x, y, noteValue, beats);
public Time(int beats, BaseNoteValue noteValue) { this.Beats = beats; this.NoteValue = noteValue; }
public static bool GetIsShortestSupported(this BaseNoteValue value) { return(value == BaseNoteValue.TwoHundredFiftySixth); }
public static bool GetIsLongestSupported(this BaseNoteValue value) { return(value == BaseNoteValue.Large); }
public Tempo(int beats, BaseNoteValue noteValue = BaseNoteValue.Quater) { this.Beats = beats; this.NoteValue = noteValue; }
public Task <Rect> DrawRest(BaseNoteValue noteValue, double position, double stringIndex) { return(this.PrimitiveRenderer.DrawRest(noteValue, this.Location.X + position, this.Owner.GetStringPosition(stringIndex))); }
public Task <Rect> MeasureRest(BaseNoteValue noteValue) { return(this.PrimitiveRenderer.MeasureRest(noteValue)); }
public static PreciseDuration GetDuration(this BaseNoteValue value) { return(new PreciseDuration(Math.Pow(2, (int)value))); }
internal Beam(Beam owner, BaseNoteValue beatNoteValue, Voice ownerVoice) : this(beatNoteValue, ownerVoice, false) { this.BeatElementOwner = owner; }
public Task <Rect> DrawFlag(BaseNoteValue noteValue, double x, double y, VerticalDirection direction) => this.InvokeAsyncRenderMethodReturnBoundingBox("drawFlag", (int)noteValue, x, y, (int)direction);
public Task <Rect> DrawRest(BaseNoteValue noteValue, double x, double y) => this.InvokeAsyncRenderMethodReturnBoundingBox("drawRest", (int)noteValue, x, y);
public Task <Rect> MeasureRest(BaseNoteValue noteValue) => this.InvokeAsyncRenderMethodReturnBoundingBox("measureRest", noteValue);