Exemplo n.º 1
0
        public void BuildConfigFromDir(string subDirName)
        {
            if (Directory.Exists(subDirName))
            {
                var cfg = $".\\{subDirName}\\{subDirName}.json";
                if (File.Exists(cfg))
                {
                    Load(cfg);
                }
                else
                {
                    DisposeAudioCache();
                    ActiveConfig = new SoundConfig();
                    ActiveConfig.SourceFileName = cfg;
                }

                var filesFound = Directory.GetFiles(Environment.CurrentDirectory + "\\" + subDirName, "*.*")
                                 .Where(s => s.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".wav", StringComparison.OrdinalIgnoreCase));

                var y = 0;
                foreach (var f in filesFound)
                {
                    var localFile = f.ToLower().Replace(Environment.CurrentDirectory.ToLower(), ".");

                    if (!ActiveConfig.Sounds.Any((x) => x.FilePath.Equals(localFile, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var s = new Sound
                        {
                            FilePath = f.ToLower().Replace(Environment.CurrentDirectory.ToLower(), "."),
                            Id       = (new FileInfo(f)).Name,
                            Loop     = false
                        };

                        for (var x = 0; x < 8; x++)
                        {
                            s.Cues.Add(
                                new SoundCue
                            {
                                CueName       = $"Grid({x},{y})",
                                FadeInTime    = 0,
                                FadeOutTime   = 0,
                                PitchFactor   = x == 0.0f ? 1.0f : ((x / 7.0f) * 2.0f),
                                StartPosition = 0,
                                StartSilent   = false
                            }
                                );
                        }

                        ActiveConfig.Sounds.Add(s);
                        y++;
                    }
                }

                ActiveConfig.Save();
            }
            else
            {
                Log($"Director not found {subDirName}");
            }
        }
Exemplo n.º 2
0
 public void Load(string fileName)
 {
     if (File.Exists(fileName))
     {
         DisposeAudioCache();
         try
         {
             ActiveConfig = SoundConfig.Load(fileName);
         } catch (Exception ex)
         {
             Log($"Failed to load cfg {fileName}, reason: {ex.Message}");
             ActiveConfig = new SoundConfig();
         }
     }
 }