private static List<Playlist> LoadStockPlaylist() { Utils.Log("Loading stock playlists."); List<Playlist> playlists = new List<Playlist>(); playlists.Add(new Playlist { name = "Construction", loop = true, shuffle = true, preloadTime = 5, tracks = new List<string> { "KSP_Construction01", "KSP_Construction02", "KSP_Construction03", "Groove Grove", "Brittle Rille" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.VAB | Enums.Scenes.SPH } }); playlists.Add(new Playlist { name = "Space", loop = true, shuffle = true, preloadTime = 5, tracks = new List<string> { "KSP_SpaceAmbience01", "KSP_SpaceAmbience02", "KSP_SpaceAmbience03", "KSP_SpaceAmbience04", "Arcadia", "Bathed in the Light", "Dreamy Flashback", "Frost Waltz", "Frost Waltz (Alternate)", "Frozen Star", "Impact Lento", "Wizardtorium", "KSP_MainTheme", }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.Flight, inAtmosphere = Enums.Selector.False } }); playlists.Add(new Playlist { name = "Astronaut Complex", loop = true, tracks = new List<string> { "KSP_AstronautComplexAmbience" }, playWhen = new Playlist.Prerequisites { //scene = Enums.Scene.AstronautComplex TODO scene = Enums.Scenes.PSystem } }); playlists.Add(new Playlist { name = "Credits", loop = true, tracks = new List<string> { "KSP_Credits" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.Credits } }); playlists.Add(new Playlist { name = "Menu ambience", loop = true, preloadTime = 5, enabled = false, tracks = new List<string> { "KSP_MenuAmbience" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.MainMenu } }); Playlist spaceCentreAmbience = new Playlist { name = "Space centre", loop = true, preloadTime = 5, tracks = new List<string> { "KSP_SpaceCenterAmbience" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.SpaceCentre } }; playlists.Add(spaceCentreAmbience); playlists.Add(new Playlist { name = "Menu theme", loop = false, preloadTime = 5, disableAfterPlay = true, playNext = "Menu ambience", tracks = new List<string> { "KSP_MainTheme" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.MainMenu } }); playlists.Add(new Playlist { name = "Mission control ambience", loop = true, tracks = new List<string> { "KSP_MissionControlAmbience" // TODO - Verify this }, playWhen = new Playlist.Prerequisites { // scene = Enums.Scene.MissionControl TODO scene = Enums.Scenes.Loading } }); playlists.Add(new Playlist { name = "Research complex ambience", loop = true, tracks = new List<string> { "KSP_ResearchAndDevelopment" // TODO - Verify this }, playWhen = new Playlist.Prerequisites { //scene = Enums.Scene.ResearchComplex TODO scene = Enums.Scenes.LoadingBuffer } }); playlists.Add(new Playlist { name = "Space center ambience", loop = true, tracks = new List<string> { "KSP_SpaceCenterAmbience" // TODO - Verify this }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.SpaceCentre } }); playlists.Add(new Playlist { name = "SPH ambience", loop = true, tracks = new List<string> { "KSP_SPHAmbience" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.SPH } }); playlists.Add(new Playlist { name = "Tracking station ambience", loop = true, tracks = new List<string> { "KSP_TrackingStation" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.TrackingStation } }); playlists.Add(new Playlist { name = "VAB ambience", loop = true, tracks = new List<string> { "KSP_VABAmbience" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.VAB } }); return playlists; }
//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")); } } 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(); } }
// TODO: This now fades poorly, and interferes with the Player GUI volume control. public void Fade() { float time = Time.realtimeSinceStartup; if (_fadingOut) { if (time >= _fadeOutEnd) { _fadingOut = false; Speaker.volume = GameSettings.MUSIC_VOLUME; } else { if (!_wasFadingOut) { _fadeOutStart = Time.realtimeSinceStartup; } Utils.Log("Fading out to " + GameSettings.MUSIC_VOLUME + " from " + _fadeOutStart + " to " + _fadeOutEnd + " at " + time + " = " + Mathf.InverseLerp(_fadeOutEnd, _fadeOutStart, time)); Speaker.volume = Mathf.InverseLerp(_fadeOutEnd, _fadeOutStart, time) * GameSettings.MUSIC_VOLUME; } _wasFadingOut = true; } else { _wasFadingOut = false; } // TODO: Deal with simultaneous fading out and in. if (_fadingIn) { if (time >= _fadeInEnd) { _fadingIn = false; Speaker.volume = GameSettings.MUSIC_VOLUME; } else { if (!_wasFadingIn) { _fadeInStart = Time.realtimeSinceStartup; } Utils.Log("Fading in to " + GameSettings.MUSIC_VOLUME + " from " + _fadeInStart + " to " + _fadeInEnd + " at " + time + " = " + Mathf.InverseLerp(_fadeInStart, _fadeInEnd, time)); Speaker.volume = Mathf.InverseLerp(_fadeInStart, _fadeInEnd, time) * GameSettings.MUSIC_VOLUME; } _wasFadingIn = true; } else { _wasFadingIn = false; } /*/ TODO: Preload * if (CurrentPlaylist != null) * { * float preloadTime = CurrentPlaylist.preloadTime + CurrentPlaylist.trackFade.fadeOut; * }*/ }
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 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(); } }
public static void CreatePlaylists(List <Playlist> Playlists) { Utils.Log("Creating test playlists"); Playlists.Add(new Playlist { name = "Main menu", loop = false, //fade = new Playlist.Fade { fadeIn = 5, fadeOut = 5 }, preloadTime = 5, tracks = new List <string> { "KSP_MainTheme", "KSP_MenuAmbience" }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.MainMenu } }); Playlists.Add(new Playlist { name = "Space centre", loop = true, preloadTime = 5, tracks = new List <string> { "dobroide-forest"/*, * "KSP_SpaceCenterAmbience"*/ }, playWhen = new Playlist.Prerequisites { scene = Enums.Scenes.SpaceCentre } }); /* TODO * Playlist astroComplexAmbience = new Playlist * { * name = "Astronaut Complex", * loop = true, * tracks = new List<string> { * "KSP_AstronautComplexAmbience" * }, * playWhen = new Playlist.Prerequisites * { * scene = Playlist.Prerequisites.Scene. AstronautComplex * } * }; * Playlists.Add(astroComplexAmbience); * * * credits = KSP_Credits * researchComplexAmbience = KSP_ResearchAndDevelopment * spaceCenterAmbience = SoundtrackEditor/Music/dobroide-forest * SPHAmbience = KSP_SPHAmbience * trackingAmbience = KSP_TrackingStation * VABAmbience = KSP_VABAmbience* / * * * Playlists.Add(new Playlist * { * name = "Editor", * loop = true, * shuffle = true, * preloadTime = 5, * tracks = new List<string> { * "KSP_Construction01", * "KSP_Construction02", * "KSP_Construction03", * "KSP - VAB_SPH_SneakyAdventure", * "Groove Grove", * "Brittle Rille" * }, * playWhen = new Playlist.Prerequisites * { * scene = Enums.Scene.VAB | Enums.Scene.SPH * } * }); * * Playlists.Add(new Playlist * { * name = "Space", * loop = true, * shuffle = true, * preloadTime = 5, * //trackFade = new Playlist.Fade { fadeIn = 5, fadeOut = 5 }, * tracks = new List<string> { * "KSP_SpaceAmbience01", * "KSP_SpaceAmbience02", * "KSP_SpaceAmbience03", * "KSP_SpaceAmbience04", * "Arcadia", * "Bathed in the Light", * "Dreamy Flashback", * "Frost Waltz", * "Frost Waltz (Alternate)", * "Frozen Star", * "Impact Lento", * "Wizardtorium", * "KSP_MainTheme", * }, * playWhen = new Playlist.Prerequisites * { * scene = Enums.Scene.Flight, * inAtmosphere = Enums.Selector.No * } * }); * * /*Playlists.Add(new Playlist * { * name = "Atmosphere", * loop = true, * shuffle = true, * tracks = new List<string> { * "05 Dayvan Cowboy" * }, * playWhen = new Playlist.Prerequisites * { * scene = Enums.Scene.Flight, * inAtmosphere = Enums.Selector.Yes * } * });*/ /*Playlist any = new Playlist * { * name = "Any", * loop = false, * tracks = new List<string> { * "Mysterioso March", * }, * playWhen = new Playlist.Prerequisites * { * scene = Scene.Any * } * }; * Playlists.Add(any);*/ /* * astroComplexAmbience = KSP_AstronautComplexAmbience * credits = KSP_Credits * menuAmbience = KSP_MenuAmbience * menuTheme = SoundtrackEditor/Music/Space/Peaceful Desolation * researchComplexAmbience = KSP_ResearchAndDevelopment * spaceCenterAmbience = SoundtrackEditor/Music/dobroide-forest * SPHAmbience = KSP_SPHAmbience * trackingAmbience = KSP_TrackingStation * VABAmbience = KSP_VABAmbience */ /*Playlist p1 = new Playlist * { * disableAfterPlay = false, * enabled = true, * loop = true, * name = "Test Playlist", * shuffle = false, * tracks = new List<string> { * "Arcadia", * "Bathed in the Light", * "Dreamy Flashback", * "Frost Waltz", * "Frost Waltz (Alternate)", * "Frozen Star", * "Impact Lento", * "Wizardtorium", * "KSP_MainTheme", * "KSP_SpaceCenterAmbience" * //"Darkest Child", * //"Dragon and Toast", * //"Fairytale Waltz", * //"Martian Cowboy", * //"Mysterioso March", * //"Numinous Shine", * //"On The Shore", * //"Peaceful Desolation", * //"The Other Side of the Door", * //"Stand Up For Rock N Roll" * }, * playWhen = new Playlist.Prerequisites * { * scene = GameScenes.MAINMENU * } * }; * Playlists.Add(p1); * CurrentPlaylist = p1;*/ /*Playlist p2 = new Playlist * { * disableAfterPlay = false, * enabled = true, * loop = true, * name = "Test Playlist 2", * shuffle = false, * tracks = new List<string> { * "KSP_SpaceAmbience01", * "KSP_SpaceAmbience02", * "KSP_SpaceAmbience03", * "KSP_SpaceAmbience04" * }, * playWhen = new Playlist.Prerequisites * { * scene = GameScenes.SPACECENTER * } * }; * Playlists.Add(p2);*/ }