2018-12-30 18:00:05 +08:00
using Microsoft.Xna.Framework.Audio ;
2018-06-01 05:38:24 +08:00
using StardewValley ;
2018-06-26 12:13:40 +08:00
namespace SimpleSoundManager.Framework
2018-06-01 05:38:24 +08:00
{
public class XACTSound : Sound
{
public WaveBank waveBank ;
public ISoundBank soundBank ;
public string soundName ;
2018-12-30 18:00:05 +08:00
readonly WaveBank vanillaWaveBank ;
readonly ISoundBank vanillaSoundBank ;
readonly Cue song ;
2018-06-01 05:38:24 +08:00
2018-12-30 18:00:05 +08:00
/// <summary>Make a new Sound Manager to play and manage sounds in a modded wave bank.</summary>
2018-06-01 05:38:24 +08:00
/// <param name="newWaveBank">The reference to the wave bank in the mod's asset folder.</param>
/// <param name="newSoundBank">The reference to the sound bank in the mod's asset folder.</param>
2018-12-30 18:00:05 +08:00
public XACTSound ( WaveBank newWaveBank , ISoundBank newSoundBank , string soundName )
2018-06-01 05:38:24 +08:00
{
this . waveBank = newWaveBank ;
this . soundBank = newSoundBank ;
2018-12-30 18:00:05 +08:00
this . vanillaSoundBank = Game1 . soundBank ;
this . vanillaWaveBank = Game1 . waveBank ;
2018-06-01 05:38:24 +08:00
this . soundName = soundName ;
2018-12-30 18:00:05 +08:00
this . song = this . soundBank . GetCue ( this . soundName ) ;
2018-06-01 05:38:24 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Play a sound from the mod's wave bank.</summary>
2018-06-01 05:38:24 +08:00
/// <param name="soundName">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.</param>
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 ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Pauses the first instance of this sound.</summary>
2018-06-01 05:38:24 +08:00
/// <param name="soundName"></param>
public void pause ( string soundName )
{
2018-12-30 18:00:05 +08:00
this . song ? . Pause ( ) ;
2018-06-01 05:38:24 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Resume the first instance of the sound that has this name.</summary>
2018-06-01 05:38:24 +08:00
public void resume ( string soundName )
{
2018-12-30 18:00:05 +08:00
this . song ? . Resume ( ) ;
2018-06-01 05:38:24 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Stop the first instance of the sound that has this name.</summary>
2018-06-01 05:38:24 +08:00
/// <param name="soundName"></param>
public void stop ( string soundName )
{
2018-12-30 18:00:05 +08:00
this . song ? . Stop ( AudioStopOptions . Immediate ) ;
2018-06-01 05:38:24 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Resumes a paused song.</summary>
2018-06-01 05:38:24 +08:00
public void resume ( )
{
2018-12-30 18:00:05 +08:00
this . resume ( this . soundName ) ;
2018-06-01 05:38:24 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Plays this song.</summary>
2018-06-01 05:38:24 +08:00
public void play ( )
{
this . play ( this . soundName ) ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Plays this song.</summary>
2018-08-17 02:50:50 +08:00
public void play ( float volume )
{
this . play ( this . soundName ) ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Pauses this song.</summary>
2018-06-01 05:38:24 +08:00
public void pause ( )
{
this . pause ( this . soundName ) ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Stops this somg.</summary>
2018-06-01 05:38:24 +08:00
public void stop ( )
{
this . stop ( this . soundName ) ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Restarts this song.</summary>
2018-06-01 05:38:24 +08:00
public void restart ( )
{
this . stop ( ) ;
this . play ( ) ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Gets a clone of this song.</summary>
2018-06-01 05:38:24 +08:00
public Sound clone ( )
{
return new XACTSound ( this . waveBank , this . soundBank , this . soundName ) ;
}
2018-08-07 05:01:44 +08:00
public string getSoundName ( )
{
return this . soundName ;
}
public bool isStopped ( )
{
2018-12-30 18:00:05 +08:00
return this . song = = null | | this . song . IsStopped ;
2018-08-07 05:01:44 +08:00
}
2018-06-01 05:38:24 +08:00
}
}