private IRPulseMessage(IReadOnlyPulseSpaceUnitList pulsesAndSpacesAsNumberOfUnits, int unitDuration, bool makeCopy)
        {
            if (pulsesAndSpacesAsNumberOfUnits == null)
            {
                throw new ArgumentNullException(nameof(pulsesAndSpacesAsNumberOfUnits));
            }
            if (unitDuration < Utility.UnitDurationMinimum || unitDuration > Utility.UnitDurationMaximum)
            {
                throw new ArgumentOutOfRangeException(nameof(unitDuration), unitDuration, "Unit duration is invalid.");
            }

            UnitDuration = unitDuration;

            if (makeCopy)
            {
                _units = pulsesAndSpacesAsNumberOfUnits.Copy();
            }
            else
            {
                _units = (PulseSpaceUnitList)pulsesAndSpacesAsNumberOfUnits;
            }

            _durations = new PulseSpaceDurationList(unitDuration, pulsesAndSpacesAsNumberOfUnits);

            UnitCount = _units.UnitCount;
        }
        /// <summary>
        /// Create a new buffer with the same data, but rounded off.
        /// </summary>
        public PulseSpaceDurationList Copy(int roundTo)
        {
            if (roundTo <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(roundTo));
            }

            var copy = new PulseSpaceDurationList(Count);

            foreach (var original in this)
            {
                copy.Add(RoundMicrosecs(original, roundTo));
            }
            return(copy);
        }
        /// <param name="pulsesAndSpacesAsDurations">The pulse/space durations. These will be rounded to multiples of the <paramref name="unitDuration"/>.</param>
        /// <param name="unitDuration">How long each unit lasts, in microseconds.</param>
        public IRPulseMessage(IReadOnlyPulseSpaceDurationList pulsesAndSpacesAsDurations, int unitDuration)
        {
            if (pulsesAndSpacesAsDurations == null)
            {
                throw new ArgumentNullException(nameof(pulsesAndSpacesAsDurations));
            }
            if (unitDuration < Utility.UnitDurationMinimum || unitDuration > Utility.UnitDurationMaximum)
            {
                throw new ArgumentOutOfRangeException(nameof(unitDuration), unitDuration, "Unit duration is invalid.");
            }

            UnitDuration = unitDuration;

            _durations = pulsesAndSpacesAsDurations.Copy(unitDuration); // Create a copy because the original buffer might be modified by the caller after we return.

            _units    = new PulseSpaceUnitList(unitDuration, pulsesAndSpacesAsDurations);
            UnitCount = _units.UnitCount;
        }