public Scale(Note tonic, IntervalPattern pattern, int octaves) { if (tonic == null) { throw new ArgumentNullException("tonic"); } if (pattern == null) { throw new ArgumentNullException("pattern"); } if (octaves <= 0) { throw new ArgumentOutOfRangeException("octaves"); } this.scale.Add(tonic); Note current = tonic; for (int octave = 0; octave < octaves; ++octave) { foreach (Interval v in pattern.Values) { current = current + v; this.scale.Add(current); } } }
public IntervalPattern this[WellKnownIntervalPattern pattern] { get { if (!this.scaleLookup.ContainsKey(pattern)) { throw new ArgumentOutOfRangeException("pattern", "Unknown interval pattern"); } return(IntervalPattern.FromString(this.scaleLookup[pattern])); } }
public IntervalPattern Pattern() { var pattern = new IntervalPattern(); var previous = this.Root(); foreach (var note in this.chord.Skip(1)) { var interval = note - previous; pattern.Add(interval); previous = note; } return(pattern); }
public static IntervalPattern FromString(string pattern) { if (string.IsNullOrEmpty(pattern)) { throw new ArgumentNullException("pattern"); } string[] words = pattern.Split(new char[] { ',' }); var ip = new IntervalPattern(); foreach (string word in words.Where(w => !String.IsNullOrWhiteSpace(w))) { string candidate = word.Trim(); Accidental accidental = Accidental.FromString(candidate); if (accidental != null) { candidate = candidate.Substring(1); } int value = Convert.ToInt32(candidate, CultureInfo.CurrentCulture); if (value > 0) { if (accidental != null) { value += accidental.Value; } ip.Add(new Interval(value)); } } return(ip); }
public Scale(Note tonic, IntervalPattern pattern) : this(tonic, pattern, 1) { }
public Scale(IntervalPattern pattern) : this(new Note(40), pattern, 1) // TODO : default to middle c ??? { }