/// <summary>
        /// Loads audio settings from the specified XML element.
        /// </summary>
        /// <param name="xml">The XML element that contains the audio settings to load.</param>
        /// <returns>The audio settings that were loaded from the specified XML element or <see langword="null"/> if
        /// settings could not be loaded correctly.</returns>
        public static UltravioletActivityAudioSettings Load(XElement xml)
        {
            if (xml == null)
            {
                return(null);
            }

            try
            {
                var settings = new UltravioletActivityAudioSettings();

                settings.PlaybackDeviceName       = xml.ElementValue <String>(nameof(PlaybackDeviceName));
                settings.AudioMasterVolume        = xml.ElementValue <Single>(nameof(AudioMasterVolume));
                settings.AudioMuted               = xml.ElementValue <Boolean>(nameof(AudioMuted));
                settings.SongsMasterVolume        = xml.ElementValue <Single>(nameof(SongsMasterVolume));
                settings.SongsMuted               = xml.ElementValue <Boolean>(nameof(SongsMuted));
                settings.SoundEffectsMasterVolume = xml.ElementValue <Single>(nameof(SoundEffectsMasterVolume));
                settings.SoundEffectsMuted        = xml.ElementValue <Boolean>(nameof(SoundEffectsMuted));

                return(settings);
            }
            catch (FormatException)
            {
                return(null);
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is FormatException)
                {
                    return(null);
                }
                throw;
            }
        }
        /// <summary>
        /// Saves the specified application settings to the specified file.
        /// </summary>
        /// <param name="path">The path to the file in which to save the application settings.</param>
        /// <param name="settings">The <see cref="UltravioletApplicationSettings"/> to serialize to the specified file.</param>
        public static void Save(String path, UltravioletActivitySettings settings)
        {
            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                    new XElement("Settings",
                                                 UltravioletActivityAudioSettings.Save(settings.Audio)
                                                 ));

            xml.Save(path);
        }
        /// <summary>
        /// Creates a set of application settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The <see cref="UltravioletApplicationSettings"/> which was retrieved.</returns>
        public static UltravioletActivitySettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var settings = new UltravioletActivitySettings();

            settings.Audio = UltravioletActivityAudioSettings.FromCurrentSettings(uv);

            return(settings);
        }
        /// <summary>
        /// Saves the specified audio settings to XML.
        /// </summary>
        /// <param name="settings">The audio settings to save.</param>
        /// <returns>An XML element that represents the specified audio settings.</returns>
        public static XElement Save(UltravioletActivityAudioSettings settings)
        {
            Contract.Require(settings, nameof(settings));

            return(new XElement("Audio",
                                new XElement(nameof(PlaybackDeviceName), settings.PlaybackDeviceName),
                                new XElement(nameof(AudioMasterVolume), settings.AudioMasterVolume),
                                new XElement(nameof(AudioMuted), settings.AudioMuted),
                                new XElement(nameof(SongsMasterVolume), settings.SongsMasterVolume),
                                new XElement(nameof(SongsMuted), settings.SongsMuted),
                                new XElement(nameof(SoundEffectsMasterVolume), settings.SoundEffectsMasterVolume),
                                new XElement(nameof(SoundEffectsMuted), settings.SoundEffectsMuted)
                                ));
        }
        /// <summary>
        /// Loads a set of application settings from the specified file.
        /// </summary>
        /// <param name="path">The path to the file from which to load the application settings.</param>
        /// <returns>The <see cref="UltravioletApplicationSettings"/> which were deserialized from the specified file.</returns>
        public static UltravioletActivitySettings Load(String path)
        {
            var xml = XDocument.Load(path);

            var settings = new UltravioletActivitySettings();

            settings.Audio = UltravioletActivityAudioSettings.Load(xml.Root.Element("Audio"));

            if (settings.Audio == null)
            {
                return(null);
            }

            return(settings);
        }
        /// <summary>
        /// Creates a set of audio settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The audio settings which were retrieved.</returns>
        public static UltravioletActivityAudioSettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var audio    = uv.GetAudio();
            var settings = new UltravioletActivityAudioSettings();

            settings.PlaybackDeviceName       = audio.PlaybackDevice?.Name;
            settings.AudioMasterVolume        = audio.AudioMasterVolume;
            settings.AudioMuted               = audio.AudioMuted;
            settings.SongsMasterVolume        = audio.SongsMasterVolume;
            settings.SongsMuted               = audio.SongsMuted;
            settings.SoundEffectsMasterVolume = audio.SoundEffectsMasterVolume;
            settings.SoundEffectsMuted        = audio.SoundEffectsMuted;

            return(settings);
        }