示例#1
0
        public static string GenerateTab(Phrase phrase, string tuning = "E,B,G,D,A,E", bool oneLineIfPossible = false)
        {
            phrase = phrase.Clone();
            while (PhraseHelper.IsPhraseDuplicated(phrase))
            {
                PhraseHelper.TrimPhrase(phrase, phrase.PhraseLength / 2);
            }

            var tabParser = new TabParser(tuning);

            while (phrase.Elements.Min(x => x.Note) > tabParser.TabLines.Last().Number)
            {
                NoteHelper.ShiftNotesDirect(phrase, 1, Interval.Octave, Direction.Down);
            }

            while (phrase.Elements.Min(x => x.Note) < tabParser.TabLines.Last().Number)
            {
                NoteHelper.ShiftNotesDirect(phrase, 1, Interval.Octave);
            }



            tabParser.LoadTabFromPhrase(phrase, oneLineIfPossible);


            return(BuildTab(tabParser));
        }
示例#2
0
        /// <summary>
        /// Speaks the <see cref="Phrase" /> passed using the current voice if the phrase doesn't
        /// specify a voice.
        /// </summary>
        /// <param name="phrase">The phrase to be spoken.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="phrase" /> is <c>null</c>.</exception>
        public void Speak(Phrase phrase)
        {
            if (phrase == null)
            {
                throw new ArgumentNullException("phrase");
            }

            if (phrase.Voice == null && this.Voice != null)
            {
                phrase = phrase.Clone(Voice);
            }

            ActionRenderingContext.Execute(new PlayAudioAction(CallID, AudioSource.Speech(phrase)));
        }
示例#3
0
        /// <summary>
        /// Adds the genrated phrase audio file passed to the cache.
        /// </summary>
        /// <param name="phrase">The phrase being added.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="phrase" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown if the <paramref name="phrase" />.<see cref="Path"/> property is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the cache has been stopped or if a one-time phrase is passed.</exception>
        public void AddPhrase(Phrase phrase)
        {
            Phrase existing;

            if (phrase == null)
            {
                throw new ArgumentNullException("phrase");
            }

            if (phrase.Path == null)
            {
                throw new ArgumentException("[Path] property cannot be NULL.", "phrase");
            }

            if (phrase.IsOneTime)
            {
                throw new InvalidOperationException("[AddPhrase] cannot accept a one-time phrase.");
            }

            phrase = phrase.Clone();

            // The requested voice might not exist, so get the actual
            // voice that can be used.

            phrase.ActualVoice = SpeechEngine.GetVoice(phrase.Voice);
            if (phrase.ActualVoice == null)
            {
                return;     // No installed voices
            }
            lock (syncLock)
            {
                if (!isRunning)
                {
                    throw new InvalidOperationException("[PhraseCache] is stopped.");
                }

                phrase.LastAccessUtc = DateTime.UtcNow;

                if (index.TryGetValue(GetCacheKey(phrase), out existing))
                {
                    // The phrase is already in the index.

                    existing.LastAccessUtc = phrase.LastAccessUtc;
                }
                else
                {
                    index.Add(GetCacheKey(phrase), phrase);
                }
            }
        }
示例#4
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);
        }