diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs index 6ca68f9e..771ccee8 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs @@ -1586,7 +1586,7 @@ namespace StardewSymphonyRemastered.Framework.Menus if (this.currentMusicPackAlbum == null || this.currentSelectedSong == null) return false; var info = (KeyValuePair)this.currentMusicPackAlbum.buttonFunctionality.leftClick.paramaters[0]; //Check for generic festival music. - if (this.drawMode == DrawMode.FestivalSelection) + if (this.drawMode == DrawMode.SelectedFestival) { var festivalSonglist = info.Value.songInformation.festivalSongs; if (festivalSonglist == null) return false; @@ -1594,9 +1594,9 @@ namespace StardewSymphonyRemastered.Framework.Menus else return true; } //Check for generic event music. - if (this.drawMode == DrawMode.EventSelection) + if (this.drawMode == DrawMode.SelectedEvent) { - var eventSonglist = info.Value.songInformation.festivalSongs; + var eventSonglist = info.Value.songInformation.eventSongs; if (eventSonglist == null) return false; if (!eventSonglist.Contains(info.Value.songInformation.getSongFromList(eventSonglist, this.currentSelectedSong.name))) return false; else return true; @@ -1894,6 +1894,7 @@ namespace StardewSymphonyRemastered.Framework.Menus this.currentMusicPackAlbum.draw(b); this.currentSelectedSong.draw(b); this.currentlySelectedOption.draw(b); + /* if (!doesPackContainMusic()) { this.addButton.draw(b); @@ -1902,6 +1903,7 @@ namespace StardewSymphonyRemastered.Framework.Menus { this.deleteButton.draw(b); } + */ this.playButton.draw(b); this.stopButton.draw(b); @@ -1952,6 +1954,7 @@ namespace StardewSymphonyRemastered.Framework.Menus this.currentMusicPackAlbum.draw(b); this.currentSelectedSong.draw(b); this.currentlySelectedOption.draw(b); + /* if (!doesPackContainMusic()) { this.addButton.draw(b); @@ -1960,6 +1963,7 @@ namespace StardewSymphonyRemastered.Framework.Menus { this.deleteButton.draw(b); } + */ this.playButton.draw(b); this.stopButton.draw(b); @@ -2010,6 +2014,7 @@ namespace StardewSymphonyRemastered.Framework.Menus this.currentMusicPackAlbum.draw(b); this.currentSelectedSong.draw(b); this.currentlySelectedOption.draw(b); + /* if (!doesPackContainMusic()) { this.addButton.draw(b); @@ -2018,6 +2023,7 @@ namespace StardewSymphonyRemastered.Framework.Menus { this.deleteButton.draw(b); } + */ this.playButton.draw(b); this.stopButton.draw(b); @@ -2161,13 +2167,16 @@ namespace StardewSymphonyRemastered.Framework.Menus { if (this.drawMode == DrawMode.WeatherSelection || this.drawMode == DrawMode.TimeSelection || this.drawMode == DrawMode.LocationSelection || this.drawMode == DrawMode.DaySelection || this.drawMode == DrawMode.NothingElseToDisplay) { - if (!doesPackContainMusic()) + if (this.selectedJustLocation==false) { - this.addButton.draw(b); - } - else - { - this.deleteButton.draw(b); + if (!doesPackContainMusic()) + { + this.addButton.draw(b); + } + else + { + this.deleteButton.draw(b); + } } } this.playButton.draw(b); @@ -2248,19 +2257,18 @@ namespace StardewSymphonyRemastered.Framework.Menus var info = (KeyValuePair)this.currentMusicPackAlbum.buttonFunctionality.leftClick.paramaters[0]; - StardewSymphony.ModMonitor.Log(generateSongTriggerKeyFromSelection()); + //StardewSymphony.ModMonitor.Log(generateSongTriggerKeyFromSelection()); //Add generic festival music. - if (this.drawMode == DrawMode.FestivalSelection) + if (this.drawMode == DrawMode.SelectedFestival) { - - info.Value.songInformation.addSongToFestivalList(this.currentlySelectedFestival.label); + info.Value.songInformation.addSongToFestivalList(this.currentSelectedSong.label); return; } //Add generic event music. - if(this.drawMode== DrawMode.EventSelection) + if(this.drawMode== DrawMode.SelectedEvent) { - info.Value.songInformation.addSongToEventList(this.currentlySelectedEvent.label); + info.Value.songInformation.addSongToEventList(this.currentSelectedSong.label); return; } @@ -2274,7 +2282,25 @@ namespace StardewSymphonyRemastered.Framework.Menus /// public void deleteSong() { + + + var info = (KeyValuePair)this.currentMusicPackAlbum.buttonFunctionality.leftClick.paramaters[0]; + + + if (this.drawMode == DrawMode.SelectedFestival) + { + info.Value.songInformation.removeSongFromFestivalList(this.currentSelectedSong.label); + return; + } + + //Add generic event music. + if (this.drawMode == DrawMode.SelectedEvent) + { + info.Value.songInformation.removeSongFromEventList(this.currentSelectedSong.label); + return; + } + info.Value.songInformation.removeSongFromTriggerList(generateSongTriggerKeyFromSelection(), this.currentSelectedSong.label); } @@ -2318,13 +2344,13 @@ namespace StardewSymphonyRemastered.Framework.Menus else if (this.currentlySelectedOption.name == "WinterButton") key += "winter"; else { - StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert); + //StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert); return ""; } } else { - StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert); + //StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert); return ""; } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs index e4f928f4..572780c1 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs @@ -65,26 +65,55 @@ namespace StardewSymphonyRemastered.Framework } } + /// + /// Updtes the timer every second to check if a song is playing or not. + /// public void updateTimer() { + if (this.currentMusicPack == null) return; - if (this.currentMusicPack.isPlaying()) return; + if (this.currentMusicPack.isPlaying()) + { + return; + } else { - Random r = new Random(Game1.random.Next()); - - int val = r.Next(StardewSymphony.Config.MinimumDelayBetweenSongsInMilliseconds, StardewSymphony.Config.MaximumDelayBetweenSongsInMilliseconds + 1); - timer = new Timer(val); - timer.Elapsed += onTimerFinished; - timer.Enabled = true; + if (timer == null) + { + Random r = new Random(Game1.random.Next()); + int val = r.Next(StardewSymphony.Config.MinimumDelayBetweenSongsInMilliseconds, StardewSymphony.Config.MaximumDelayBetweenSongsInMilliseconds + 1); + //StardewSymphony.ModMonitor.Log("Music Pack is not playing! Generate a new timer! Delay: "+val.ToString()); + timer = new Timer(val); + timer.Elapsed += onTimerFinished; + timer.Enabled = true; + } + else + { + timer.Enabled = true; + timer.Elapsed += onTimerFinished; + } } } + /// + /// Selects a new song when the timer delay runs out. + /// + /// + /// public void onTimerFinished(System.Object source, ElapsedEventArgs e) { + if (this.currentMusicPack.isPlaying()) + { + timer.Enabled = false; + timer = null; + return; + } + //StardewSymphony.ModMonitor.Log("AHH THE TIMER FINISHED!"); timer.Enabled = false; + timer.Elapsed -= onTimerFinished; selectMusic(SongSpecifics.getCurrentConditionalString()); + timer = null; } /// @@ -269,6 +298,11 @@ namespace StardewSymphonyRemastered.Framework /// public void selectMusic(string songListKey) { + //Nullify the timer when new music is selected. + if (this.timer != null) + { + this.timer = null; + } var listOfValidMusicPacks = getListOfApplicableMusicPacks(songListKey); diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs index 5617926b..8c06798f 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs @@ -63,16 +63,19 @@ namespace StardewSymphonyRemastered.Framework { string json = Path.Combine(path, "MusicPackInformation.json"); var meta=StardewSymphony.ModHelper.ReadJsonFile(json); + + string[] pathParse = path.Split(new String[] { StardewSymphony.ModHelper.DirectoryPath },StringSplitOptions.None); + try { try { - meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest, StardewSymphony.getRelativeDirectory(Path.Combine(path, meta.pathToMusicPackIcon + ".png"))); + meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest, Path.Combine(pathParse[1], meta.pathToMusicPackIcon + ".png")); } catch(Exception errr) { errr.ToString(); - meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest ,StardewSymphony.getRelativeDirectory(Path.Combine(path, meta.pathToMusicPackIcon))); + meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest ,Path.Combine(pathParse[1], meta.pathToMusicPackIcon)); } } catch(Exception err) diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/SongSpecifics.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/SongSpecifics.cs index 5115a59a..e0b1b0b3 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/SongSpecifics.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/SongSpecifics.cs @@ -625,7 +625,6 @@ namespace StardewSymphonyRemastered.Framework public void addSongToFestivalList(string songName) { - var songKeyPair = this.festivalSongs; var song = getSongFromList(listOfSongsWithoutTriggers, songName); //Get the song from the master song pool if (song == null) @@ -634,7 +633,7 @@ namespace StardewSymphonyRemastered.Framework StardewSymphony.ModMonitor.Log("For some reason you are trying to add a song that is null. The name of the song is " + songName); return; } - songKeyPair.Add(song); //add the song from master pool to the trigger list + this.festivalSongs.Add(song); //add the song from master pool to the trigger list } public void addSongToEventList(string songName) @@ -664,6 +663,28 @@ namespace StardewSymphonyRemastered.Framework songKeyPair.Value.Remove(song); } + /// + /// Remove a song from the event list. + /// + /// + /// + public void removeSongFromEventList( string songName) + { + var song = getSongFromList(this.eventSongs, songName); + this.eventSongs.Remove(song); + } + + /// + /// Remove a song from the festival list. + /// + /// + /// + public void removeSongFromFestivalList( string songName) + { + var song = getSongFromList(this.festivalSongs, songName); + this.festivalSongs.Remove(song); + } + /// /// Get the Song instance that is referenced with the song's name. /// @@ -672,8 +693,10 @@ namespace StardewSymphonyRemastered.Framework /// public Song getSongFromList(List songList,string songName) { + //StardewSymphony.ModMonitor.Log("Get the song: " + songName); foreach (var song in songList) { + //StardewSymphony.ModMonitor.Log("Looking at song: " + song.name); if (song.name == songName) { return song; diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs index bfdc4b05..6f240133 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs @@ -18,26 +18,12 @@ namespace StardewSymphonyRemastered.Framework public Song currentSong; public string songsDirectory; - /// - /// Used to actually play the song. - /// - DynamicSoundEffectInstance dynamicSound; - /// - /// Used to keep track of where in the song we are. - /// - int position; - /// - /// ??? - /// - int count; - /// - /// Used to store the info for the song. - /// - byte[] byteArray; - + public SoundEffectInstance sound; bool loop; + + public Dictionary sounds; /// /// Constructor. /// @@ -50,6 +36,7 @@ namespace StardewSymphonyRemastered.Framework this.songInformation = new SongSpecifics(); this.musicPackInformation = MusicPackMetaData.readFromJson(directoryToMusicPack); this.loop = Loop; + this.sounds = new Dictionary(); /* if (this.musicPackInformation == null) { @@ -80,83 +67,21 @@ namespace StardewSymphonyRemastered.Framework } } + /* /// /// Load a wav file into the stream to be played. /// - public void LoadWavFromFileToStream(string p) + public void LoadWavFromFileToStream(string file) { // Create a new SpriteBatch, which can be used to draw textures. - string file =p; System.IO.Stream waveFileStream = File.OpenRead(file); //TitleContainer.OpenStream(file); - - BinaryReader reader = new BinaryReader(waveFileStream); - - int chunkID = reader.ReadInt32(); - int fileSize = reader.ReadInt32(); - int riffType = reader.ReadInt32(); - int fmtID = reader.ReadInt32(); - int fmtSize = reader.ReadInt32(); - int fmtCode = reader.ReadInt16(); - int channels = reader.ReadInt16(); - int sampleRate = reader.ReadInt32(); - int fmtAvgBPS = reader.ReadInt32(); - int fmtBlockAlign = reader.ReadInt16(); - int bitDepth = reader.ReadInt16(); - - if (fmtSize == 18) - { - // Read any extra values - int fmtExtraSize = reader.ReadInt16(); - reader.ReadBytes(fmtExtraSize); - } - - int dataID = reader.ReadInt32(); - int dataSize = reader.ReadInt32(); - - byteArray = reader.ReadBytes(dataSize); - - - dynamicSound = new DynamicSoundEffectInstance(sampleRate, (AudioChannels)channels); - count = dynamicSound.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(10000)); - if (count > byteArray.Length) - { - count = byteArray.Length; - } - dynamicSound.BufferNeeded += new EventHandler(DynamicSound_BufferNeeded); - this.currentSong = new Song(p); + this.effect = SoundEffect.FromStream(waveFileStream); + this.sound=this.effect.CreateInstance(); + this.currentSong = new Song(file); + waveFileStream.Dispose(); } - - void DynamicSound_BufferNeeded(object sender, EventArgs e) - { - //StardewSymphony.ModMonitor.Log(byteArray.Length.ToString()); - //StardewSymphony.ModMonitor.Log(position.ToString()); - //StardewSymphony.ModMonitor.Log(count.ToString()); - try - { - dynamicSound.SubmitBuffer(byteArray, position, count); - } - catch(Exception err) - { - } - - //dynamicSound.SubmitBuffer(byteArray); - //dynamicSound.SubmitBuffer(byteArray, position + count / 2, count / 2); - - position += count; - if (position + count > byteArray.Length) - { - if (loop) - { - position = 0; - } - else - { - - } - } - } - + */ /// /// Returns the name of the currently playing song. @@ -177,10 +102,18 @@ namespace StardewSymphonyRemastered.Framework List listOfSongs = new List(); foreach(var wav in wavFiles) { + + System.IO.Stream waveFileStream = File.OpenRead(wav); //TitleContainer.OpenStream(file); + SoundEffect eff = SoundEffect.FromStream(waveFileStream); + SoundEffectInstance instance = eff.CreateInstance(); + string name = Path.GetFileNameWithoutExtension(wav); + this.sounds.Add(name, instance); + + waveFileStream.Dispose(); Song song = new Song(wav); - listOfSongs.Add(song); + this.songInformation.listOfSongsWithoutTriggers.Add(song); + //listOfSongs.Add(song); } - this.songInformation.listOfSongsWithoutTriggers = listOfSongs; } /// @@ -188,7 +121,7 @@ namespace StardewSymphonyRemastered.Framework /// public override void pauseSong() { - if (dynamicSound != null) dynamicSound.Pause(); + if (this.sound != null) sound.Pause(); } /// @@ -198,8 +131,19 @@ namespace StardewSymphonyRemastered.Framework public override void playSong(string name) { string pathToSong = getSongPathFromName(name); - LoadWavFromFileToStream(pathToSong); - dynamicSound.Play(); + + bool exists=this.sounds.TryGetValue(name,out this.sound); + + if (exists) + { + this.currentSong = new Song(name); + sound.Play(); + } + else + { + StardewSymphony.ModMonitor.Log("An error occured where we can't find the song anymore. Weird. Please contact Omegasis with a SMAPI Log and describe when/how the event occured."); + } + } public override void playRandomSong() @@ -215,8 +159,8 @@ namespace StardewSymphonyRemastered.Framework /// public override void resumeSong() { - if (dynamicSound == null) return; - dynamicSound.Resume(); + if (sound == null) return; + sound.Resume(); } /// @@ -226,15 +170,10 @@ namespace StardewSymphonyRemastered.Framework { if (Game1.currentSong != null) Game1.currentSong.Stop(AudioStopOptions.Immediate); if (this.currentSong == null) return; - if (dynamicSound != null) + if (sound != null) { - dynamicSound.Stop(true); - dynamicSound.BufferNeeded -= new EventHandler(DynamicSound_BufferNeeded); - dynamicSound = null; + sound.Stop(true); this.currentSong = null; - position = 0; - count = 0; - byteArray = new byte[0]; } } @@ -252,7 +191,7 @@ namespace StardewSymphonyRemastered.Framework /// Get the son's name from the path. /// /// - /// + /// 11111111111111 public string getSongNameFromPath(string path) { foreach(var song in this.songInformation.listOfSongsWithoutTriggers) @@ -278,8 +217,8 @@ namespace StardewSymphonyRemastered.Framework public override bool isPlaying() { - if (this.dynamicSound == null) return false; - if (this.dynamicSound.State == SoundState.Playing) return true; + if (this.sound == null) return false; + if (this.sound.State == SoundState.Playing) return true; else return false; } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs index d420bb41..dd239ed5 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs @@ -508,36 +508,6 @@ namespace StardewSymphonyRemastered Game1.soundBank = DefaultSoundBank; } - /// - /// Used to splice the mod directory to get relative paths. - /// - /// - /// - public static string getShortenedDirectory(string path) - { - string lol = (string)path.Clone(); - string[] spliter = lol.Split(new string[] { ModHelper.DirectoryPath }, StringSplitOptions.None); - try - { - return spliter[1]; - } - catch (Exception err) - { - err.ToString(); - return spliter[0]; - } - } - - /// - /// Used to finish cleaning up absolute asset paths into a shortened relative path. - /// - /// - /// - public static string getRelativeDirectory(string path) - { - string s = getShortenedDirectory(path); - return s.Remove(0, 1); - } public static void DebugLog(string s) { diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json index 3236cb88..74efdc77 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json @@ -1,7 +1,7 @@ { "Name": "Stardew Symphony Remastered", "Author": "Alpha_Omegasis", - "Version": "2.1.5", + "Version": "2.1.6", "Description": "Adding more music to the game one beep at a time. Now with streaming!", "UniqueID": "Omegasis.StardewSymphonyRemastered", "EntryDll": "StardewSymphonyRemastered.dll", diff --git a/GeneralMods/StardustCore/NetCode/Graphics/NetAnimationManager.cs b/GeneralMods/StardustCore/NetCode/Graphics/NetAnimationManager.cs index 7ca7d234..db348c3c 100644 --- a/GeneralMods/StardustCore/NetCode/Graphics/NetAnimationManager.cs +++ b/GeneralMods/StardustCore/NetCode/Graphics/NetAnimationManager.cs @@ -23,12 +23,7 @@ namespace StardustCore.NetCode.Graphics } - public NetString currentAnimationName; - public NetInt currentAnimationListIndex; - public NetTexture2DExtended objectTexture; - public NetAnimation defaultDrawFrame; - public NetBool enabled; - public NetString animationDataString; + protected override void ReadDelta(BinaryReader reader, NetVersion version) { @@ -64,13 +59,13 @@ namespace StardustCore.NetCode.Graphics } else { - Value.currentAnimation = defaultDrawFrame.Value; + Value.currentAnimation = defaultAnimation.Value; } } protected override void WriteDelta(BinaryWriter writer) { - NetString curentAnimationName = new NetString(Value.currentAnimationName); + NetString currentAnimationName = new NetString(Value.currentAnimationName); currentAnimationName.Write(writer);