Example #1
0
            public Sound(string file, Mix mix, FMOD.System system)
            {
                this.system = system;
                FMOD.Sound ns    = null;
                var        data  = mix.GetBytes(file);
                var        fCSex = new FMOD.CreateSoundExInfo()
                {
                    Size   = 216,
                    Length = (uint)data.Length
                };

                SoundSystem.CheckError(system.CreateSound(data, FMOD.SoundMode.Default | FMOD.SoundMode.OpenMemory, ref fCSex, ref ns));
                InnerSound = ns;
            }
Example #2
0
        public void PlayMusic(Mix mix, string name)
        {
            if (!Enabled)
            {
                return;
            }

            if (mix.FileExists(name))
            {
                StopMusic();
                var data  = mix.GetBytes(name);
                var fCSex = new FMOD.CreateSoundExInfo()
                {
                    Size   = 216,
                    Length = (uint)data.Length
                };
                CheckError(system.CreateSound(data, FMOD.SoundMode.LoopNormal | FMOD.SoundMode.OpenMemory, ref fCSex, ref music));
                system.PlaySound(music, false, ref musicChannel);
                musicChannel.SetVolume(0.5f);
            }
        }
Example #3
0
        public void PlayMusic(string name, bool fade = true)
        {
            if (!Enabled || musicVolume == 0)
            {
                return;
            }

            var set = targetSet;

            if (name.StartsWith("set://"))
            {
                set = name.Substring(6);
                var setNode = musicLibrary.FirstOrDefault(x => x.Name == set);
                if (setNode == null)
                {
                    name = "-";
                }
                else
                {
                    name = "-";
                    var unmarked = new List <Token>();
                    foreach (var t in setNode.Tokens)
                    {
                        if (!t.HasToken("used"))
                        {
                            unmarked.Add(t);
                        }
                    }
                    if (unmarked.Count == 0)
                    {
                        foreach (var t in setNode.Tokens)
                        {
                            t.RemoveToken("used");
                            unmarked.Add(t);
                        }
                    }
                    while (unmarked.Count > 0)
                    {
                        var pick = Random.Next(unmarked.Count);
                        var file = unmarked[pick].Name;
                        if (!Mix.FileExists(file))
                        {
                            unmarked.RemoveAt(pick);
                        }
                        else
                        {
                            name = file;
                            unmarked[pick].AddToken("used");
                            break;
                        }
                    }
                }
            }

            if (set == currentSet)
            {
                return;
            }

            if (fade && string.IsNullOrEmpty(FadeTarget) && musicChannel != null && name != musicPlaying)
            {
                FadeTarget  = name;
                targetSet   = set;
                fadeProcess = 300;
                return;
            }
            FadeTarget = null;
            if (name == "-")
            {
                if (musicChannel != null)
                {
                    musicChannel.Stop();
                }
                if (music != null)
                {
                    music.Release();
                }
                currentSet   = string.Empty;
                musicPlaying = string.Empty;
            }
            else if (musicPlaying != name)
            {
                if (Mix.FileExists(name))
                {
                    if (musicChannel != null)
                    {
                        musicChannel.Stop();
                    }
                    if (music != null)
                    {
                        music.Release();
                    }
                    var data  = Mix.GetBytes(name);
                    var fCSex = new FMOD.CreateSoundExInfo()
                    {
                        Size   = 216,
                        Length = (uint)data.Length
                    };
                    CheckError(system.CreateSound(data, FMOD.SoundMode.LoopNormal | FMOD.SoundMode.OpenMemory, ref fCSex, ref music));
                    system.PlaySound(music, false, ref musicChannel);
                    musicPlaying = name;
                    currentSet   = set;
                    musicChannel.SetVolume(musicVolume);
                    //NoxicoGame.HostForm.Text = file;
                }
                else
                {
                    Program.WriteLine("PlayMusic: couldn't load song \"{0}\".", name);
                }
            }
        }