コード例 #1
0
        public static Patterns FindPatterns(Phrase phrase, PatternType patternType)
        {
            var elements       = phrase.Clone().Elements;
            var sequenceLength = elements.Count;

            if (patternType == PatternType.Tempo)
            {
                elements.ForEach(x => x.Note = 1);
            }

            var patterns = new Patterns();

            for (var windowSize = sequenceLength / 2; windowSize >= 1; windowSize--)
            {
                var lastWindowStart = sequenceLength - (windowSize * 2);

                for (var windowStart = 0; windowStart <= lastWindowStart; windowStart++)
                {
                    var windowEnd = windowStart + windowSize - 1;
                    for (var compareWindowStart = windowStart + windowSize; compareWindowStart + windowSize <= sequenceLength; compareWindowStart++)
                    {
                        var compareWindowEnd = compareWindowStart + windowSize - 1;
                        if (!Compare(elements, windowStart, windowEnd, compareWindowStart))
                        {
                            continue;
                        }

                        var patternKey = GetPatternKey(elements, windowStart, windowEnd, patternType);
                        patterns.AddPattern(patternKey, windowStart, windowEnd, compareWindowStart, compareWindowEnd, patternType);
                    }
                }
            }

            RemoverOverlapsWithinEachPattern(patterns);
            RemoveOverlappingPatterns(patterns);

            return(patterns);
        }