Exemplo n.º 1
0
 /// <summary>Attempts to parse a string representation of a timing point into a <seealso cref="TimingPoint"/> and returns the resulting parsed object, or <see langword="null"/>.</summary>
 /// <param name="s">The string representation of a timing point to parse.</param>
 public static TimingPoint Parse(string s)
 {
     if (AbsoluteTimingPoint.TryParse(s, out var absolute))
     {
         return(absolute);
     }
     if (RelativeTimingPoint.TryParse(s, out var relative))
     {
         return(relative);
     }
     return(null);
 }
Exemplo n.º 2
0
        /// <summary>Attempts to parse a string representation of a relative timing point into a <seealso cref="RelativeTimingPoint"/> and returns a <seealso cref="bool"/> indicating whether the operation was successful or not.</summary>
        /// <param name="s">The string representation of a relative timing point to parse.</param>
        /// <param name="timingPoint">The <seealso cref="RelativeTimingPoint"/> that will be parsed. If the string is unparsable, the value is <see langword="null"/>.</param>
        public static bool TryParse(string s, out RelativeTimingPoint timingPoint)
        {
            timingPoint = null;
            var split = s.Split('|');

            if (!MeasuredTimePosition.TryParse(split[0], out var timePosition))
            {
                return(false);
            }
            if (!double.TryParse(split[1], out double bpm))
            {
                return(false);
            }
            if (!TimeSignature.TryParse(split[2], out var timeSignature))
            {
                return(false);
            }
            timingPoint = new RelativeTimingPoint(timePosition, bpm, timeSignature);
            return(true);
        }