public static IEnumerable <RhythmicDuration> Parse(params int[] durations) { return(durations.Select(i => { var denominatorAsPowerOfTwo = UsefulMath.Log2(i); return new RhythmicDuration(denominatorAsPowerOfTwo); }).ToArray()); }
public static bool TryParse(string s, out RhythmicDuration duration) { int val; if (!int.TryParse(s, out val)) { duration = default(RhythmicDuration); return(false); } var denominatorAsPowerOfTwo = UsefulMath.Log2(val); duration = new RhythmicDuration(denominatorAsPowerOfTwo); return(true); }
/// <summary> /// Parses RhythmicDuration from a string /// </summary> /// <param name="s"></param> /// <returns></returns> public static RhythmicDuration Parse(string s) { var numberOfDots = s.ToCharArray().Count(c => c == '.'); int denominator; if (!int.TryParse(s.Replace(".", ""), out denominator)) { throw new Exception("Could not parse string. Unrecognized duration."); } var denominatorAsPowerOfTwo = UsefulMath.Log2(denominator); return(new RhythmicDuration(denominatorAsPowerOfTwo, numberOfDots)); }