using Microsoft.Xna.Framework.Audio; using StardewValley; namespace SimpleSoundManager.Framework { public class XACTSound : Sound { public WaveBank waveBank; public ISoundBank soundBank; public string soundName; readonly WaveBank vanillaWaveBank; readonly ISoundBank vanillaSoundBank; readonly Cue song; /// Make a new Sound Manager to play and manage sounds in a modded wave bank. /// The reference to the wave bank in the mod's asset folder. /// The reference to the sound bank in the mod's asset folder. public XACTSound(WaveBank newWaveBank, ISoundBank newSoundBank, string soundName) { this.waveBank = newWaveBank; this.soundBank = newSoundBank; this.vanillaSoundBank = Game1.soundBank; this.vanillaWaveBank = Game1.waveBank; this.soundName = soundName; this.song = this.soundBank.GetCue(this.soundName); } /// Play a sound from the mod's wave bank. /// The name of the sound in the mod's wave bank. This will fail if the sound doesn't exists. This is also case sensitive. public void play(string soundName) { Game1.waveBank = this.waveBank; Game1.soundBank = this.soundBank; if (this.song == null) return; this.song.Play(); Game1.waveBank = this.vanillaWaveBank; Game1.soundBank = this.vanillaSoundBank; } /// Pauses the first instance of this sound. /// public void pause(string soundName) { this.song?.Pause(); } /// Resume the first instance of the sound that has this name. public void resume(string soundName) { this.song?.Resume(); } /// Stop the first instance of the sound that has this name. /// public void stop(string soundName) { this.song?.Stop(AudioStopOptions.Immediate); } /// Resumes a paused song. public void resume() { this.resume(this.soundName); } /// Plays this song. public void play() { this.play(this.soundName); } /// Plays this song. public void play(float volume) { this.play(this.soundName); } /// Pauses this song. public void pause() { this.pause(this.soundName); } /// Stops this somg. public void stop() { this.stop(this.soundName); } /// Restarts this song. public void restart() { this.stop(); this.play(); } /// Gets a clone of this song. public Sound clone() { return new XACTSound(this.waveBank, this.soundBank, this.soundName); } public string getSoundName() { return this.soundName; } public bool isStopped() { return this.song == null || this.song.IsStopped; } } }