public static SoundInfo LoadSound(XElement soundNode, string basePath) { SoundInfo sound = new SoundInfo { Name = soundNode.RequireAttribute("name").Value }; sound.Loop = soundNode.TryAttribute<bool>("loop"); sound.Volume = soundNode.TryAttribute<float>("volume", 1); XAttribute pathattr = soundNode.Attribute("path"); XAttribute trackAttr = soundNode.Attribute("track"); if (pathattr != null) { sound.Type = AudioType.Wav; sound.Path = FilePath.FromRelative(pathattr.Value, basePath); } else if (trackAttr != null) { sound.Type = AudioType.NSF; int track; if (!trackAttr.Value.TryParse(out track) || track <= 0) throw new GameXmlException(trackAttr, "Sound track attribute must be an integer greater than zero."); sound.NsfTrack = track; sound.Priority = soundNode.TryAttribute<byte>("priority", 100); } else { sound.Type = AudioType.Unknown; } return sound; }
public SoundInfo GetInfo(string basePath) { SoundInfo info = new SoundInfo {Type = type}; if (type == AudioType.NSF) { info.NsfTrack = (int)trackNumeric.Value; } else if (type == AudioType.Wav) { info.Path = FilePath.FromAbsolute(pathText.Text, basePath); } info.Priority = (byte)priorityNumeric.Value; return info; }
public static SoundInfo FromXml(XElement soundNode, string basePath) { SoundInfo sound = new SoundInfo {Name = soundNode.RequireAttribute("name").Value}; bool loop; soundNode.TryBool("loop", out loop); sound.Loop = loop; float vol; if (!soundNode.TryFloat("volume", out vol)) vol = 1; sound.Volume = vol; XAttribute pathattr = soundNode.Attribute("path"); XAttribute trackAttr = soundNode.Attribute("track"); if (pathattr != null) { sound.Type = AudioType.Wav; sound.Path = FilePath.FromRelative(pathattr.Value, basePath); } else if (trackAttr != null) { sound.Type = AudioType.NSF; int track; if (!trackAttr.Value.TryParse(out track) || track <= 0) throw new GameXmlException(trackAttr, "Sound track attribute must be an integer greater than zero."); sound.NsfTrack = track; int priority; if (!soundNode.TryInteger("priority", out priority)) priority = 100; sound.Priority = (byte)priority; } else { sound.Type = AudioType.Unknown; } return sound; }
public string EffectFromInfo(SoundInfo info) { if (loadedSounds.ContainsKey(info.Name)) return info.Name; ISoundEffect sound; if (info.Type == AudioType.Wav) { sound = new WavEffect(soundSystem, info.Path.Absolute, info.Loop, info.Volume); } else if (info.Type == AudioType.NSF) { sound = new NsfEffect(sfx, info.NsfTrack, info.Priority, info.Loop); } else return info.Name; loadedSounds[info.Name] = sound; return info.Name; }
public void RemoveSound(SoundInfo sound) { _sounds.Remove(sound); }
public void AddSound(SoundInfo sound) { _sounds.Add(sound); }