Esempio n. 1
0
        public void Parse()
        {
            bool success = TimeSignature.TryParse("4/4", out var commonTimeSignature);

            Assert.IsTrue(success, "Cannot parse the string representation of the time signature which literally is splitting two values by this character: /");
            Assert.AreEqual(new TimeSignature(4, 4), commonTimeSignature, "Apparently this is not 4/4, even if correctly parsed");
        }
Esempio 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);
        }