AlphaTab.Rendering.Utils.BeamingHelper.CheckBeat C# (CSharp) Method

CheckBeat() public method

public CheckBeat ( Beat beat ) : bool
beat AlphaTab.Model.Beat
return bool
        public bool CheckBeat(Beat beat)
        {
            if (beat.InvertBeamDirection)
            {
                InvertBeamDirection = true;
            }

            if (Voice == null)
            {
                Voice = beat.Voice;
            }
            // allow adding if there are no beats yet
            var add = false;
            if (Beats.Count == 0)
            {
                add = true;
            }
            else if (CanJoin(_lastBeat, beat))
            {
                add = true;
            }

            if (add)
            {
                _lastBeat = beat;
                Beats.Add(beat);

                if (beat.HasTuplet)
                {
                    HasTuplet = true;
                }

                int fingeringCount = 0;
                for (var n = 0; n < beat.Notes.Count; n++)
                {
                    var note = beat.Notes[n];
                    if (note.LeftHandFinger != Fingers.Unknown || note.RightHandFinger != Fingers.Unknown)
                    {
                        fingeringCount++;
                    }
                }

                if (fingeringCount > FingeringCount)
                {
                    FingeringCount = fingeringCount;
                }

                CheckNote(beat.MinNote);
                CheckNote(beat.MaxNote);
                if (ShortestDuration < beat.Duration)
                {
                    ShortestDuration = beat.Duration;
                }

                if (beat.HasTuplet)
                {
                    HasTuplet = true;
                }
            }

            return add;
        }

Usage Example

Example #1
0
        public BarHelpers(Bar bar)
        {
            BeamHelpers      = new FastList <FastList <BeamingHelper> >();
            BeamHelperLookup = new FastList <FastDictionary <int, BeamingHelper> >();
            TupletHelpers    = new FastList <FastList <TupletHelper> >();

            BeamingHelper currentBeamHelper   = null;
            TupletHelper  currentTupletHelper = null;

            if (bar != null)
            {
                for (int i = 0, j = bar.Voices.Count; i < j; i++)
                {
                    var v = bar.Voices[i];
                    BeamHelpers.Add(new FastList <BeamingHelper>());
                    BeamHelperLookup.Add(new FastDictionary <int, BeamingHelper>());
                    TupletHelpers.Add(new FastList <TupletHelper>());

                    for (int k = 0, l = v.Beats.Count; k < l; k++)
                    {
                        var b = v.Beats[k];
                        var forceNewTupletHelper = false;

                        // if a new beaming helper was started, we close our tuplet grouping as well
                        if (!b.IsRest)
                        {
                            // try to fit beam to current beamhelper
                            if (currentBeamHelper == null || !currentBeamHelper.CheckBeat(b))
                            {
                                if (currentBeamHelper != null)
                                {
                                    currentBeamHelper.Finish();
                                    forceNewTupletHelper = currentBeamHelper.Beats.Count > 1;
                                }
                                else
                                {
                                    forceNewTupletHelper = true;
                                }
                                // if not possible, create the next beaming helper
                                currentBeamHelper = new BeamingHelper(bar.Staff);
                                currentBeamHelper.CheckBeat(b);
                                BeamHelpers[v.Index].Add(currentBeamHelper);
                            }
                        }

                        if (b.HasTuplet)
                        {
                            // try to fit tuplet to current tuplethelper
                            // TODO: register tuplet overflow
                            var previousBeat = b.PreviousBeat;

                            // don't group if the previous beat isn't in the same voice
                            if (previousBeat != null && previousBeat.Voice != b.Voice)
                            {
                                previousBeat = null;
                            }

                            // if a new beaming helper was started, we close our tuplet grouping as well
                            if (forceNewTupletHelper && currentTupletHelper != null)
                            {
                                currentTupletHelper.Finish();
                            }

                            if (previousBeat == null || currentTupletHelper == null || !currentTupletHelper.Check(b))
                            {
                                currentTupletHelper = new TupletHelper(v.Index);
                                currentTupletHelper.Check(b);
                                TupletHelpers[v.Index].Add(currentTupletHelper);
                            }
                        }

                        BeamHelperLookup[v.Index][b.Index] = currentBeamHelper;
                    }

                    if (currentBeamHelper != null)
                    {
                        currentBeamHelper.Finish();
                    }

                    if (currentTupletHelper != null)
                    {
                        currentTupletHelper.Finish();
                    }

                    currentBeamHelper   = null;
                    currentTupletHelper = null;
                }
            }
        }
All Usage Examples Of AlphaTab.Rendering.Utils.BeamingHelper::CheckBeat