コード例 #1
0
ファイル: NoteValue.cs プロジェクト: hillinworks/tabml
        public static bool TryResolveFromDuration(PreciseDuration duration, out NoteValue noteValue, bool complex = false)
        {
            for (var baseNoteValue = BaseNoteValue.Large; baseNoteValue >= BaseNoteValue.TwoHundredFiftySixth; --baseNoteValue)
            {
                if (duration == baseNoteValue.GetDuration())
                {
                    continue;
                }

                noteValue = new NoteValue(baseNoteValue);
                return(true);
            }

            if (complex)
            {
                var searchAugments = new[] { NoteValueAugment.Dot, NoteValueAugment.TwoDots, NoteValueAugment.ThreeDots };
                var searchTuplets  = new[] { 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15 };

                for (var baseNoteValue = BaseNoteValue.Large; baseNoteValue >= BaseNoteValue.TwoHundredFiftySixth; --baseNoteValue)
                {
                    var baseDuration         = baseNoteValue.GetDuration();
                    var baseInvertedDuration = (double)baseNoteValue.GetInvertedDuration();

                    foreach (var augment in searchAugments)
                    {
                        var augmentedDuration = baseDuration * augment.GetDurationMultiplier();
                        if (duration == augmentedDuration)
                        {
                            noteValue = new NoteValue(baseNoteValue, augment);
                            return(true);
                        }

                        foreach (var tuplet in searchTuplets)
                        {
                            if (duration == augmentedDuration * (baseInvertedDuration / tuplet))
                            {
                                noteValue = new NoteValue(baseNoteValue, augment, tuplet);
                                return(true);
                            }
                        }
                    }
                }
            }

            noteValue = default(NoteValue);
            return(false);
        }
コード例 #2
0
ファイル: BaseNoteValues.cs プロジェクト: hillinworks/tabml
        public static bool TryFactorize(PreciseDuration duration, out BaseNoteValue[] values)
        {
            var valueList        = new List <BaseNoteValue>();
            var currentNoteValue = BaseNoteValue.Large;
            var currentDuration  = currentNoteValue.GetDuration();

            while (currentNoteValue >= BaseNoteValue.TwoHundredFiftySixth)
            {
                if (duration < currentDuration)
                {
                    --currentNoteValue;
                    currentDuration = currentNoteValue.GetDuration();
                    continue;
                }

                valueList.Add(currentNoteValue);
                duration -= currentDuration;
            }

            values = valueList.ToArray();

            return(duration == 0);
        }