Example #1
0
 public Beam(BaseNoteValue beatNoteValue, Voice ownerVoice, bool isRoot)
 {
     this.BeatNoteValue = beatNoteValue;
     this.OwnerVoice    = ownerVoice;
     this.IsRoot        = isRoot;
     this.Elements      = new List <IBeatElement>();
 }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        public static BaseNoteValue Double(this BaseNoteValue value)
        {
            if (value.GetIsLongestSupported())
            {
                throw new ArgumentOutOfRangeException(nameof(value));
            }

            return(value + 1);
        }
Example #5
0
        public static BaseNoteValue Half(this BaseNoteValue value)
        {
            if (value.GetIsShortestSupported())
            {
                throw new ArgumentOutOfRangeException(nameof(value));
            }

            return(value - 1);
        }
Example #6
0
 public BeatArranger(BaseNoteValue beamNoteValue, Voice ownerVoice)
 {
     _beamNoteValue   = beamNoteValue;
     _ownerVoice      = ownerVoice;
     _beamStack       = new Stack <Beam>();
     _rootBeats       = new List <IBeatElement>();
     _currentCapacity = PreciseDuration.Zero;
     _duration        = PreciseDuration.Zero;
 }
Example #7
0
        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));
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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;
        }
Example #12
0
 public double GetBeats(BaseNoteValue beatLength)
 {
     return(this.GetDuration() / beatLength.GetDuration());
 }
Example #13
0
 public Task <Rect> DrawTempoSignature(double x, double y, BaseNoteValue noteValue, int beats)
 => this.InvokeRenderMethodReturnBoundingBox("drawTempoSignature", x, y, noteValue, beats);
Example #14
0
 public Time(int beats, BaseNoteValue noteValue)
 {
     this.Beats     = beats;
     this.NoteValue = noteValue;
 }
Example #15
0
 public static bool GetIsShortestSupported(this BaseNoteValue value)
 {
     return(value == BaseNoteValue.TwoHundredFiftySixth);
 }
Example #16
0
 public static bool GetIsLongestSupported(this BaseNoteValue value)
 {
     return(value == BaseNoteValue.Large);
 }
Example #17
0
 public Tempo(int beats, BaseNoteValue noteValue = BaseNoteValue.Quater)
 {
     this.Beats     = beats;
     this.NoteValue = noteValue;
 }
Example #18
0
 public Task <Rect> DrawRest(BaseNoteValue noteValue, double position, double stringIndex)
 {
     return(this.PrimitiveRenderer.DrawRest(noteValue, this.Location.X + position, this.Owner.GetStringPosition(stringIndex)));
 }
Example #19
0
 public Task <Rect> MeasureRest(BaseNoteValue noteValue)
 {
     return(this.PrimitiveRenderer.MeasureRest(noteValue));
 }
Example #20
0
 public static PreciseDuration GetDuration(this BaseNoteValue value)
 {
     return(new PreciseDuration(Math.Pow(2, (int)value)));
 }
Example #21
0
 internal Beam(Beam owner, BaseNoteValue beatNoteValue, Voice ownerVoice)
     : this(beatNoteValue, ownerVoice, false)
 {
     this.BeatElementOwner = owner;
 }
Example #22
0
 public Task <Rect> DrawFlag(BaseNoteValue noteValue, double x, double y, VerticalDirection direction)
 => this.InvokeAsyncRenderMethodReturnBoundingBox("drawFlag", (int)noteValue, x, y, (int)direction);
Example #23
0
 public Task <Rect> DrawRest(BaseNoteValue noteValue, double x, double y)
 => this.InvokeAsyncRenderMethodReturnBoundingBox("drawRest", (int)noteValue, x, y);
Example #24
0
 public Task <Rect> MeasureRest(BaseNoteValue noteValue)
 => this.InvokeAsyncRenderMethodReturnBoundingBox("measureRest", noteValue);