public List <Token> GetTokens(IPatternProducer p)
        {
            var tokenStrings = parser.PreprocessAndSplit(p.ToString());

            return(tokenStrings.Select(tokenString => new Token(tokenString, GetTokenType(tokenString)))
                   .ToList());
        }
예제 #2
0
 /// <summary>
 /// Saves pattern produced by the <paramref name="patternProducer"/> to a MIDI file
 /// </summary>
 /// <param name="patternProducer">Producer from which the pattern should be saved</param>
 /// <param name="filePath">Path to the MIDI file</param>
 public static void SavePatternToMidi(IPatternProducer patternProducer, string filePath)
 {
     using (var player = new Player())
     {
         player.GetSequence(patternProducer)
         .Save(filePath);
     }
 }
예제 #3
0
 public Pattern Add(IPatternProducer producer, int repetitions = 1)
 {
     for (int i = 0; i < repetitions; i++)
     {
         Add(producer.GetPattern().ToString());
     }
     return(this);
 }
예제 #4
0
 public TrackTable Add(int track, int start, int end, IPatternProducer producer)
 {
     for (int i = start; i <= end; i++)
     {
         Add(track, i, producer);
     }
     return(this);
 }
예제 #5
0
 /// <summary>
 /// Puts the given pattern in the track table at every 'nth' position, starting with
 /// position 'first' and ending with 'end'
 /// </summary>
 public TrackTable AddAtIntervals(int track, int first, int nth, int end, IPatternProducer producer)
 {
     for (int position = first; position < Math.Min(Length, end); position += nth)
     {
         Add(track, position, producer);
     }
     return(this);
 }
예제 #6
0
 /// <summary>
 /// Puts the given pattern in the track table at every 'nth' position
 /// </summary>
 public TrackTable AddAtIntervals(int track, int nth, IPatternProducer producer)
 {
     for (int position = 0; position < Length; position += nth)
     {
         Add(track, position, producer);
     }
     return(this);
 }
예제 #7
0
        public Pattern GetPatternAt(int column)
        {
            var columnPattern = new Pattern();

            foreach (var track in tracks)
            {
                IPatternProducer producer = track[column];
                columnPattern.Add(new Pattern(producer).SetVoice(tracks.IndexOf(track)));
            }
            return(columnPattern);
        }
예제 #8
0
        public TrackTable Add(int track, int position, IPatternProducer producer)
        {
            var trackList = tracks[track];

            if (trackList == null)
            {
                trackList = new List <IPatternProducer>();
                tracks.Insert(track, trackList);
            }
            trackList.Insert(position, producer.GetPattern());
            return(this);
        }
예제 #9
0
 /// <summary>
 /// Lets you specify which cells in the TrackTable should be populated with the given PatternProducer by using a String
 /// in which a period means "not in this cell" and any other character means "in this cell".
 /// Example: put(1, pattern, "...XXXX..XX....XXXX..XX....");
 /// </summary>
 public TrackTable Add(int track, string periodSelector, IPatternProducer producer)
 {
     for (int i = 0; i < periodSelector.Length; i++)
     {
         if (periodSelector[i] == '.')
         {
             // No op
         }
         else if (periodSelector[i] == '-')
         {
             Add(track, i, new Pattern(""));
         }
         else
         {
             Add(track, i, producer);
         }
     }
     return(this);
 }
예제 #10
0
 public void AddInstruction(string key, IPatternProducer value)
 {
     AddInstruction(key, value.GetPattern().ToString());
 }
예제 #11
0
 public void DelayPlay(long millisToDelay, IPatternProducer patternProducer)
 {
     DelayPlay(millisToDelay, patternProducer.GetPattern().ToString());
 }
예제 #12
0
 public void Play(IPatternProducer patternProducer)
 {
     Play(patternProducer.GetPattern().ToString());
 }
예제 #13
0
 public Sequence GetSequence(IPatternProducer patternProducer)
 {
     return(GetSequence(patternProducer.GetPattern().ToString()));
 }
예제 #14
0
 public TrackTable SetTrackSettings(int track, IPatternProducer producer)
 {
     trackSettings.Insert(track, producer);
     return(this);
 }
예제 #15
0
 /// <summary>
 /// This util takes replacement strings with dollar signs, like "$0q $1h $2w", and replaces each $ index with a
 /// value from the array of candidates. $_ is replaced with the underscoreReplacement. Returns the resulting Pattern.
 /// Current known users include ChordProgression and Intervals and BrokenChordPreprocessor.
 /// </summary>
 public static Pattern ReplaceDollarsWithCandidates(string sequence,
                                                    IList <IPatternProducer> candidates, IPatternProducer underscoreReplacement)
 {
     return(ReplaceDollarsWithCandidates(sequence, candidates, underscoreReplacement, null, " ", " ", null));
 }
예제 #16
0
        public static Pattern ReplaceDollarsWithCandidates(string sequence, IList <IPatternProducer> candidates,
                                                           IPatternProducer underscoreReplacement, IDictionary <string, IPatternProducer> specialReplacers,
                                                           string inputSeparator, string outputSeparator, string finalThingToAppend)
        {
            var buddy = new StringBuilder();

            // Understand the contents of the special replacer map.
            // Specifically, find the longest-length item in the map.
            int maxSpecialReplacerKeyLength = 0;

            if (specialReplacers != null)
            {
                foreach (string replacerKey in specialReplacers.Keys)
                {
                    if (replacerKey.Length > maxSpecialReplacerKeyLength)
                    {
                        maxSpecialReplacerKeyLength = replacerKey.Length;
                    }
                }
            }

            // Split the input into individual elements and parse each one.
            foreach (var elementWithSeparator in SplitElementsWithSeparators(sequence))
            {
                string element            = elementWithSeparator.Element;
                string innerSeparator     = elementWithSeparator.Separator.ToString();
                string distributionNeeded = null;
                string appender           = "";
                bool   replacementFound   = false;
                if (element.StartsWith("$"))
                {
                    int indexForAppender = element.Length;
                    for (int len = Math.Min(maxSpecialReplacerKeyLength + 1, element.Length); len > 1 && !replacementFound; len--)
                    {
                        string selectionString = element.Substring(1, len - 1);
                        if (specialReplacers.ContainsKey(selectionString))
                        {
                            distributionNeeded = specialReplacers[selectionString].ToString();
                            indexForAppender   = len;
                            replacementFound   = true;
                        }
                    }
                    if (!replacementFound)
                    {
                        if (element[1] >= '0' && element[1] <= '9')
                        {
                            int index = int.Parse(element.Substring(1, 1));
                            distributionNeeded = candidates[index].ToString();
                            indexForAppender   = 2;
                            replacementFound   = true;
                        }
                        else if (element[1] == '!')
                        {
                            distributionNeeded = underscoreReplacement.ToString();
                            indexForAppender   = 2;
                            replacementFound   = true;
                        }
                    }
                    if (indexForAppender < element.Length)
                    {
                        appender         = element.Substring(indexForAppender, element.Length - indexForAppender);
                        replacementFound = true;
                    }
                }
                else
                {
                    distributionNeeded = element;
                    replacementFound   = true;
                }

                if (replacementFound)
                {
                    if (finalThingToAppend != null)
                    {
                        appender = appender + finalThingToAppend;
                    }
                    Distribute(buddy, distributionNeeded, appender);
                }

                buddy.Append(innerSeparator.Equals(",") ? " " : innerSeparator);
            }

            buddy.Remove(buddy.Length - 1, 1);

            return(new Pattern(buddy.ToString()));
        }
예제 #17
0
 public void Parse(IPatternProducer producer)
 {
     Parse(producer.GetPattern().ToString());
 }
예제 #18
0
 public string Preprocess(IPatternProducer producer)
 {
     return(Preprocess(producer.ToString()));
 }
예제 #19
0
 /// <summary>
 /// Saves pattern produced by the <paramref name="patternProducer"/> to a MIDI file
 /// </summary>
 /// <param name="patternProducer">Producer from which the pattern should be saved</param>
 /// <param name="filePath">Path to the MIDI file</param>
 public static void SaveAsMidi(this IPatternProducer patternProducer, string filePath)
 {
     MidiFileConverter.SavePatternToMidi(patternProducer, filePath);
 }