private bool IsFlightSituationChanged()
        {
            bool   changed = false;
            Vessel v       = SoundtrackEditor.InitialLoadingComplete ? FlightGlobals.ActiveVessel : null;

            if (v != null)
            {
                Enums.Selector inAtmosphere = v.atmDensity > 0 ? Enums.Selector.True : Enums.Selector.False;
                if (SoundtrackEditor.CurrentSituation.inAtmosphere != inAtmosphere)
                {
                    SoundtrackEditor.CurrentSituation.inAtmosphere = inAtmosphere;
                    if (MonitorInAtmosphere)
                    {
                        Utils.Log("In atmosphere changed");
                        changed = true;
                    }
                }

                // For surface velocity, orbital velocity and altitude, check if we crossed the monitored point going in either direction.
                if (MonitorSurfaceVelocity)
                {
                    if ((v.srf_velocity.magnitude > _maxSrfVel && v.srf_velocity.magnitude < _previousSrfVel) ||
                        (v.srf_velocity.magnitude < _maxSrfVel && v.srf_velocity.magnitude > _previousSrfVel))
                    {
                        changed = true;
                    }
                    if ((v.srf_velocity.magnitude > _minSrfVel && v.srf_velocity.magnitude < _previousSrfVel) ||
                        (v.srf_velocity.magnitude < _minSrfVel && v.srf_velocity.magnitude > _previousSrfVel))
                    {
                        changed = true;
                    }
                    _previousSrfVel = v.srf_velocity.magnitude;
                }
                if (MonitorOrbitalVelocity)
                {
                    if ((v.obt_velocity.magnitude > _maxObtVel && v.obt_velocity.magnitude < _previousObtVel) ||
                        (v.obt_velocity.magnitude < _maxObtVel && v.obt_velocity.magnitude > _previousObtVel))
                    {
                        changed = true;
                    }
                    if ((v.obt_velocity.magnitude > _minObtVel && v.obt_velocity.magnitude < _previousObtVel) ||
                        (v.obt_velocity.magnitude < _minObtVel && v.obt_velocity.magnitude > _previousObtVel))
                    {
                        changed = true;
                    }
                    _previousObtVel = v.obt_velocity.magnitude;
                }

                if (MonitorAltitude)
                {
                    if ((v.altitude > _maxAlt && v.altitude < _previousAlt) ||
                        (v.altitude < _maxAlt && v.altitude > _previousAlt))
                    {
                        changed = true;
                    }
                    if ((v.altitude > _minAlt && v.altitude < _previousAlt) ||
                        (v.altitude < _minAlt && v.altitude > _previousAlt))
                    {
                        changed = true;
                    }
                    _previousAlt = v.altitude;
                }

                if (MonitorNearestVessel)
                {
                    Vessel newVessel = Utils.GetNearestVessel(_minVesselDist, _maxVesselDist, v);
                    if (newVessel != null && NearestVessel != newVessel)
                    {
                        NearestVessel = newVessel;
                        changed       = true;
                    }
                }

                if (MonitorVesselState)
                {
                    if (_previousVesselState != Enums.ConvertVesselState(v.state))
                    {
                        Utils.Log("Vessel state changed");
                        _previousVesselState = Enums.ConvertVesselState(v.state);
                        changed = true;
                    }
                }
            }
            return(changed);
        }
        //private static string _configSavePath2 = "GameData/SoundtrackEditor/PluginData/settings2.cfg";
        public static List <Playlist> LoadPlaylists()
        {
            try
            {
                List <Playlist> playlists = new List <Playlist>();
                _config = ConfigNode.Load(_configSavePath);
                if (_config == null)
                {
                    Debug.LogWarning("[STED] No config file present at " + _configSavePath + ". Loading stock tracks.");
                    return(LoadStockPlaylist());
                }
                Utils.Log("Loading playlists: " + _configSavePath);

                foreach (ConfigNode node in _config.nodes)
                {
                    if (node.name.Equals("playlist"))
                    {
                        Playlist p = new Playlist();
                        if (!node.HasValue("name"))
                        {
                            continue;
                        }
                        p.name = node.GetValue("name");

                        Utils.Log("Loading playlist " + p.name);

                        if (node.HasValue("enabled"))
                        {
                            p.enabled = bool.Parse(node.GetValue("enabled"));
                        }
                        if (node.HasValue("loop"))
                        {
                            p.loop = bool.Parse(node.GetValue("loop"));
                        }
                        if (node.HasValue("shuffle"))
                        {
                            p.shuffle = bool.Parse(node.GetValue("shuffle"));
                        }
                        if (node.HasValue("pauseOnGamePause"))
                        {
                            p.pauseOnGamePause = bool.Parse(node.GetValue("pauseOnGamePause"));
                            if (p.pauseOnGamePause)
                            {
                                EventManager.Instance.MonitorPause = true;
                            }
                        }
                        if (node.HasValue("disableAfterPlay"))
                        {
                            p.disableAfterPlay = bool.Parse(node.GetValue("disableAfterPlay"));
                        }
                        if (node.HasValue("playNext"))
                        {
                            p.playNext = node.GetValue("playNext");
                        }
                        if (node.HasValue("playBefore"))
                        {
                            p.playBefore = node.GetValue("playBefore");
                        }
                        if (node.HasValue("playAfter"))
                        {
                            p.playAfter = node.GetValue("playAfter");
                        }
                        if (node.HasValue("channel"))
                        {
                            p.channel = int.Parse(node.GetValue("channel"));
                        }
                        if (node.HasValue("preloadTime"))
                        {
                            p.preloadTime = float.Parse(node.GetValue("preloadTime"));
                        }

                        /* Not yet implemented.
                         * if (node.HasNode("fade"))
                         * {
                         *  p.fade = new Playlist.Fade();
                         *  ConfigNode fade = node.GetNode("fade");
                         *  if (fade.HasNode("fadeIn"))
                         *  {
                         *      p.fade.fadeIn = float.Parse(node.GetValue("fadeIn"));
                         *  }
                         *  if (fade.HasNode("fadeOut"))
                         *      p.fade.fadeOut = float.Parse(node.GetValue("fadeOut"));
                         *  if (fade.HasNode("crossfade"))
                         *      p.fade.crossfade = bool.Parse(node.GetValue("crossfade"));
                         * }
                         * if (node.HasValue("trackFade"))
                         * {
                         *  p.trackFade = new Playlist.Fade();
                         *  ConfigNode trackFade = node.GetNode("trackFade");
                         *  if (trackFade.HasNode("fadeIn"))
                         *      p.trackFade.fadeIn = float.Parse(node.GetValue("fadeIn"));
                         *  if (trackFade.HasNode("fadeOut"))
                         *      p.trackFade.fadeOut = float.Parse(node.GetValue("fadeOut"));
                         *  if (trackFade.HasNode("crossfade"))
                         *      p.trackFade.crossfade = bool.Parse(node.GetValue("crossfade"));
                         * }*/

                        if (node.HasNode("tracks"))
                        {
                            ConfigNode tracks = node.GetNode("tracks");
                            foreach (string t in tracks.GetValues("track"))
                            {
                                p.tracks.Add(Utils.RemoveQuotes(t));
                            }
                        }
                        if (node.HasNode("playWhen"))
                        {
                            p.playWhen = new Playlist.Prerequisites();
                            ConfigNode playWhen = node.GetNode("playWhen");

                            if (playWhen.HasValue("paused"))
                            {
                                p.playWhen.paused = Enums.Parse <Enums.Selector>(playWhen.GetValue("paused"));
                            }
                            if (playWhen.HasValue("inAtmosphere"))
                            {
                                p.playWhen.inAtmosphere = Enums.Parse <Enums.Selector>(playWhen.GetValue("inAtmosphere"));
                            }
                            if (playWhen.HasValue("timeOfDay"))
                            {
                                p.playWhen.timeOfDay = Enums.Parse <Enums.TimesOfDay>(playWhen.GetValue("timeOfDay"));
                            }
                            if (playWhen.HasValue("scene"))
                            {
                                p.playWhen.scene = Enums.Parse <Enums.Scenes>(playWhen.GetValue("scene"));
                            }
                            if (playWhen.HasValue("situation"))
                            {
                                p.playWhen.situation = Enums.Parse <Vessel.Situations>(playWhen.GetValue("situation"));
                            }
                            if (playWhen.HasValue("cameraMode"))
                            {
                                p.playWhen.cameraMode = Enums.Parse <Enums.CameraModes>(playWhen.GetValue("cameraMode"));
                            }
                            if (playWhen.HasValue("bodyName"))
                            {
                                p.playWhen.bodyName = playWhen.GetValue("bodyName");
                            }
                            if (playWhen.HasValue("maxVelocitySurface"))
                            {
                                p.playWhen.maxVelocitySurface = float.Parse(playWhen.GetValue("maxVelocitySurface"));
                            }
                            if (playWhen.HasValue("minVelocitySurface"))
                            {
                                p.playWhen.minVelocitySurface = float.Parse(playWhen.GetValue("minVelocitySurface"));
                            }
                            if (playWhen.HasValue("maxVelocityOrbital"))
                            {
                                p.playWhen.maxVelocityOrbital = float.Parse(playWhen.GetValue("maxVelocityOrbital"));
                            }
                            if (playWhen.HasValue("minVelocityOrbital"))
                            {
                                p.playWhen.minVelocityOrbital = float.Parse(playWhen.GetValue("minVelocityOrbital"));
                            }
                            if (playWhen.HasValue("maxAltitude"))
                            {
                                p.playWhen.maxAltitude = float.Parse(playWhen.GetValue("maxAltitude"));
                            }
                            if (playWhen.HasValue("minAltitude"))
                            {
                                p.playWhen.minAltitude = float.Parse(playWhen.GetValue("minAltitude"));
                            }
                            if (playWhen.HasValue("maxVesselDistance"))
                            {
                                p.playWhen.maxVesselDistance = float.Parse(playWhen.GetValue("maxVesselDistance"));
                            }
                            if (playWhen.HasValue("minVesselDistance"))
                            {
                                p.playWhen.minVesselDistance = float.Parse(playWhen.GetValue("minAltitude"));
                            }
                            if (playWhen.HasValue("vesselState"))
                            {
                                p.playWhen.vesselState = Enums.Parse <Enums.VesselState>(playWhen.GetValue("vesselState"));
                            }
                            if (playWhen.HasValue("vesselType"))
                            {
                                p.playWhen.vesselType = Enums.Parse <Enums.CustomVesselType>(playWhen.GetValue("vesselType"));
                            }
                        }

                        playlists.Add(p);
                        EventManager.Instance.TrackEventsForPlaylist(p);
                    }
                }

                Utils.Log("Done loading playlists.");

                return(playlists);
            }
            catch (Exception ex)
            {
                Debug.LogError("[STED] LoadPlaylists Error: " + ex.Message);
                return(LoadStockPlaylist());
            }
        }
        private void UpdateSituation()
        {
            bool changed = false;

            // Throws exceptions before the initial loading screen is completed.
            if (SoundtrackEditor.CurrentSituation.scene == Enums.Scenes.Flight)
            {
                Vessel v = SoundtrackEditor.InitialLoadingComplete ? FlightGlobals.ActiveVessel : null;
                if (v != null)
                {
                    Enums.Selector inAtmosphere = v.atmDensity > 0 ? Enums.Selector.True : Enums.Selector.False;
                    if (SoundtrackEditor.CurrentSituation.inAtmosphere != inAtmosphere)
                    {
                        SoundtrackEditor.CurrentSituation.inAtmosphere = inAtmosphere;
                        if (MonitorInAtmosphere)
                        {
                            Utils.Log("In atmosphere changed");
                            changed = true;
                        }
                    }

                    // For surface velocity, orbital velocity and altitude, check if we crossed the monitored point going in either direction.
                    if (MonitorSurfaceVelocity)
                    {
                        if ((v.srf_velocity.magnitude > _maxSrfVel && v.srf_velocity.magnitude < _previousSrfVel) ||
                            (v.srf_velocity.magnitude < _maxSrfVel && v.srf_velocity.magnitude > _previousSrfVel))
                        {
                            changed = true;
                        }
                        if ((v.srf_velocity.magnitude > _minSrfVel && v.srf_velocity.magnitude < _previousSrfVel) ||
                            (v.srf_velocity.magnitude < _minSrfVel && v.srf_velocity.magnitude > _previousSrfVel))
                        {
                            changed = true;
                        }
                        _previousSrfVel = v.srf_velocity.magnitude;
                    }
                    if (MonitorOrbitalVelocity)
                    {
                        if ((v.obt_velocity.magnitude > _maxObtVel && v.obt_velocity.magnitude < _previousObtVel) ||
                            (v.obt_velocity.magnitude < _maxObtVel && v.obt_velocity.magnitude > _previousObtVel))
                        {
                            changed = true;
                        }
                        if ((v.obt_velocity.magnitude > _minObtVel && v.obt_velocity.magnitude < _previousObtVel) ||
                            (v.obt_velocity.magnitude < _minObtVel && v.obt_velocity.magnitude > _previousObtVel))
                        {
                            changed = true;
                        }
                        _previousObtVel = v.obt_velocity.magnitude;
                    }

                    if (MonitorAltitude)
                    {
                        if ((v.altitude > _maxAlt && v.altitude < _previousAlt) ||
                            (v.altitude < _maxAlt && v.altitude > _previousAlt))
                        {
                            changed = true;
                        }
                        if ((v.altitude > _minAlt && v.altitude < _previousAlt) ||
                            (v.altitude < _minAlt && v.altitude > _previousAlt))
                        {
                            changed = true;
                        }
                        _previousAlt = v.altitude;
                    }

                    if (MonitorNearestVessel)
                    {
                        Vessel newVessel = Utils.GetNearestVessel(_minVesselDist, _maxVesselDist, v);
                        if (newVessel != null && NearestVessel != newVessel)
                        {
                            NearestVessel = newVessel;
                            changed       = true;
                        }
                    }

                    if (MonitorVesselState)
                    {
                        if (_previousVesselState != Enums.ConvertVesselState(v.state))
                        {
                            Utils.Log("Vessel state changed");
                            _previousVesselState = Enums.ConvertVesselState(v.state);
                            changed = true;
                        }
                    }
                }
            }
            else if (SoundtrackEditor.CurrentSituation.scene == Enums.Scenes.SpaceCentre)
            {
                if (MonitorTimeOfDay)
                {
                    if (_homeBody == null)
                    {
                        _homeBody = FlightGlobals.GetHomeBody();
                    }
                    double           localTime = Sun.Instance.GetLocalTimeAtPosition(Utils.KscLatitude, Utils.KscLongitude, _homeBody);
                    Enums.TimesOfDay tod       = Enums.TimeToTimeOfDay(localTime);

                    if (SoundtrackEditor.CurrentSituation.timeOfDay != tod)
                    {
                        SoundtrackEditor.CurrentSituation.timeOfDay = tod;
                        changed = true;
                    }
                }
            }
            else
            {
                SoundtrackEditor.CurrentSituation.paused = Enums.Selector.False;
            }

            if (changed)
            {
                SoundtrackEditor.Instance.OnSituationChanged();
            }
        }
        private void UpdateSituation()
        {
            bool changed = false;

            // Throws exceptions before the initial loading screen is completed.
            if (SoundtrackEditor.CurrentSituation.scene == Enums.Scenes.Flight)
            {
                Vessel v = SoundtrackEditor.InitialLoadingComplete ? FlightGlobals.ActiveVessel : null;
                if (v != null)
                {
                    Enums.Selector inAtmosphere = v.atmDensity > 0 ? Enums.Selector.True : Enums.Selector.False;
                    if (SoundtrackEditor.CurrentSituation.inAtmosphere != inAtmosphere)
                    {
                        SoundtrackEditor.CurrentSituation.inAtmosphere = inAtmosphere;
                        if (MonitorInAtmosphere)
                        {
                            Utils.Log("In atmosphere changed");
                            changed = true;
                        }
                    }

                    //FlightGlobals.currentMainBody.maxAtmosphereAltitude

                    if (MonitorSurfaceVelocity)
                    {
                        if (_maxSrfVel < v.srf_velocity.magnitude)
                        {
                            //Utils.Log("Above maximum surface velocity");
                            changed = true;
                        }
                        if (_minSrfVel > v.srf_velocity.magnitude)
                        {
                            //Utils.Log("Below minimum surface velocity");
                            changed = true;
                        }
                    }
                    if (MonitorOrbitalVelocity)
                    {
                        if (_maxObtVel < v.obt_velocity.magnitude)
                        {
                            //Utils.Log("Above maximum orbital velocity");
                            changed = true;
                        }
                        if (_minObtVel > v.obt_velocity.magnitude)
                        {
                            //Utils.Log("Below minimum orbital velocity");
                            changed = true;
                        }
                    }

                    if (MonitorAltitude)
                    {
                        if (_maxAlt < v.altitude)
                        {
                            //Utils.Log("Above maximum altitude");
                            changed = true;
                        }
                        if (_minAlt > v.altitude)
                        {
                            //Utils.Log("Below minimum altitude");
                            changed = true;
                        }
                    }

                    if (MonitorNearestVessel)
                    {
                        Vessel newVessel = Utils.GetNearestVessel(_minVesselDist, _maxVesselDist, v);
                        if (NearestVessel != newVessel)
                        {
                            NearestVessel = newVessel;
                            changed       = true;
                        }
                    }
                }
            }
            else if (SoundtrackEditor.CurrentSituation.scene == Enums.Scenes.SpaceCentre)
            {
                if (MonitorTimeOfDay)
                {
                    if (_homeBody == null)
                    {
                        _homeBody = FlightGlobals.GetHomeBody();
                    }
                    double           localTime = Sun.Instance.GetLocalTimeAtPosition(Utils.KscLatitude, Utils.KscLongitude, _homeBody);
                    Enums.TimesOfDay tod       = Enums.TimeToTimeOfDay(localTime);

                    if (SoundtrackEditor.CurrentSituation.timeOfDay != tod)
                    {
                        SoundtrackEditor.CurrentSituation.timeOfDay = tod;
                        changed = true;
                    }
                }
            }
            else
            {
                SoundtrackEditor.CurrentSituation.paused = Enums.Selector.False;
            }

            if (changed)
            {
                SoundtrackEditor.Instance.OnSituationChanged();
            }
        }