PageRenderTime 112ms CodeModel.GetById 70ms app.highlight 3ms RepoModel.GetById 38ms app.codeStats 0ms

/ContentSystem/Multimedia/SoundData.cs

#
C# | 129 lines | 69 code | 9 blank | 51 comment | 0 complexity | 4045b644588cab116a67b417108d25b4 MD5 | raw file
  1namespace Delta.ContentSystem.Multimedia
  2{
  3	/// <summary>
  4	/// Abstract base sound class. Needs to be implemented in the platform
  5	/// multimedia module. Native data and properties are set in the derived
  6	/// classes.
  7	/// </summary>
  8	public class SoundData : Content
  9	{
 10		#region Get (Static)
 11		/// <summary>
 12		/// Get and load content based on the content name. This method makes sure
 13		/// we do not load the same content twice (the constructor is protected).
 14		/// </summary>
 15		/// <param name="contentName">Content name we want to load, this is
 16		/// passed onto the Content System, which will do the actual loading with
 17		/// help of the Load method in this class.</param>
 18		/// <returns>The loaded Content object, always unique for the same
 19		/// name, this helps comparing data.</returns>
 20		public static SoundData Get(string contentName)
 21		{
 22			return Get<SoundData>(contentName, ContentType.Sound);
 23		}
 24		#endregion
 25
 26		#region TimeLength (Public)
 27		/// <summary>
 28		/// The length in seconds this sound data plays.
 29		/// </summary>
 30		public float TimeLength
 31		{
 32			get
 33			{
 34				// Otherwise: (float)Samples / (float)SampleRate
 35				return data.TimeLength;
 36			}
 37		}
 38		#endregion
 39
 40		#region Pitch (Public)
 41		/// <summary>
 42		/// The pitch (speed) of the sound.
 43		/// </summary>
 44		public float Pitch
 45		{
 46			get
 47			{
 48				return data.SoundPitch;
 49			}
 50		}
 51		#endregion
 52
 53		#region Volume (Public)
 54		/// <summary>
 55		/// The volume of the sound.
 56		/// </summary>
 57		public float Volume
 58		{
 59			get
 60			{
 61				return data.SoundVolume;
 62			}
 63		}
 64		#endregion
 65
 66		#region Pan (Public)
 67		/// <summary>
 68		/// For sound we can specify a panning value which is the balance between
 69		/// left and right speaker.
 70		/// 0.0f = center (default)
 71		/// -1.0f = full left
 72		/// 1.0f = full right
 73		/// </summary>
 74		public float Pan
 75		{
 76			get
 77			{
 78				return data.SoundPan;
 79			}
 80		}
 81		#endregion
 82
 83		#region Constructors
 84		/// <summary>
 85		/// Create base sound class.
 86		/// </summary>
 87		/// <param name="contentName">Name of the content.</param>
 88		public SoundData(string contentName)
 89			: base(contentName, ContentType.Sound)
 90		{
 91		}
 92		#endregion
 93
 94		#region ToString (Public)
 95		/// <summary>
 96		/// Return an information string about this SoundData instance.
 97		/// </summary>
 98		/// <returns>String containing information about the sound data.</returns>
 99		public override string ToString()
100		{
101			return "SoundData(Name=" + Name + " TimeLength=" + TimeLength +
102			       " Pitch=" + Pitch + " Volume=" + Volume + " Pan=" + Pan +
103			       " FailedToLoad=" + FailedToLoad + ")";
104		}
105		#endregion
106
107		#region Methods (Private)
108
109		#region Load
110		/// <summary>
111		/// Load sound content data, does nothing. Only properties are assigned.
112		/// No loading happens here (it all happens in Sound), we can obviously
113		/// clone all SoundDatas with the same name as they are not loaded here.
114		/// Note: If a class is interested in the content reload functionality,
115		/// it can just attach itself to the ContentChanged event.
116		/// </summary>
117		/// <param name="alreadyLoadedNativeData">If we already have native data
118		/// loaded, clone it from this instance. Only used if not null. Please
119		/// note that this is only used for other objects that had the same
120		/// RawFileId and are already loaded and returned true for this method.
121		/// </param>
122		protected override void Load(Content alreadyLoadedNativeData)
123		{
124		}
125		#endregion
126
127		#endregion
128	}
129}