public List <Token> GetTokens(IPatternProducer p) { var tokenStrings = parser.PreprocessAndSplit(p.ToString()); return(tokenStrings.Select(tokenString => new Token(tokenString, GetTokenType(tokenString))) .ToList()); }
/// <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); } }
public Pattern Add(IPatternProducer producer, int repetitions = 1) { for (int i = 0; i < repetitions; i++) { Add(producer.GetPattern().ToString()); } return(this); }
public TrackTable Add(int track, int start, int end, IPatternProducer producer) { for (int i = start; i <= end; i++) { Add(track, i, producer); } return(this); }
/// <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); }
/// <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); }
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); }
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); }
/// <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); }
public void AddInstruction(string key, IPatternProducer value) { AddInstruction(key, value.GetPattern().ToString()); }
public void DelayPlay(long millisToDelay, IPatternProducer patternProducer) { DelayPlay(millisToDelay, patternProducer.GetPattern().ToString()); }
public void Play(IPatternProducer patternProducer) { Play(patternProducer.GetPattern().ToString()); }
public Sequence GetSequence(IPatternProducer patternProducer) { return(GetSequence(patternProducer.GetPattern().ToString())); }
public TrackTable SetTrackSettings(int track, IPatternProducer producer) { trackSettings.Insert(track, producer); return(this); }
/// <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)); }
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())); }
public void Parse(IPatternProducer producer) { Parse(producer.GetPattern().ToString()); }
public string Preprocess(IPatternProducer producer) { return(Preprocess(producer.ToString())); }
/// <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); }