Example #1
0
        public void LoadAudioSamples()
        {
            try
            {
                if (Directory.Exists(ApplicationConfiguration.Instance.SoundboardSampleDirectory))
                {
                    foreach (string audioSamplePath in Directory.GetFiles(ApplicationConfiguration.Instance.SoundboardSampleDirectory, "*", SearchOption.AllDirectories))
                    {
                        string   relativePath   = Path.GetRelativePath(ApplicationConfiguration.Instance.SoundboardSampleDirectory, audioSamplePath);
                        string[] directorySplit = relativePath.Split('\\');
                        double   totalSeconds   = AudioAgent.GetFileAudioDuration(audioSamplePath).TotalSeconds;

                        string groupName = "Ungrouped";
                        if (directorySplit.Length > 1)
                        {
                            groupName = directorySplit[0];
                        }

                        _soundboardSampleCollection.Add(new SoundboardSample(audioSamplePath)
                        {
                            GroupName          = groupName,
                            FileTimeMax        = totalSeconds,
                            FileTimeMin        = 0,
                            FileTimeUpperValue = totalSeconds,
                            FileTimeLowerValue = 0,
                            HotkeyId           = _soundboardSampleCollection.Count
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationLogger.Log(ex.Message, ex.StackTrace);
            }
        }
Example #2
0
        public void SaveSample(SoundboardSample soundboardSample)
        {
            try
            {
                // Trimming
                if (soundboardSample.FileTimeUpperValue != soundboardSample.FileTimeMax || soundboardSample.FileTimeLowerValue != soundboardSample.FileTimeMin)
                {
                    AudioAgent.TrimFile(soundboardSample.FilePath, soundboardSample.FileTimeLowerValue * 1000, soundboardSample.FileTimeUpperValue * 1000);

                    soundboardSample.FileTimeMin        = 0;
                    soundboardSample.FileTimeMax        = AudioAgent.GetFileAudioDuration(soundboardSample.FilePath).TotalSeconds;
                    soundboardSample.FileTimeLowerValue = 0;
                    soundboardSample.FileTimeUpperValue = soundboardSample.FileTimeMax;
                }

                // File name
                if (Path.GetFileNameWithoutExtension(soundboardSample.FilePath) != soundboardSample.Name)
                {
                    string targetDirectory = Path.Combine(ApplicationConfiguration.Instance.SoundboardSampleDirectory, soundboardSample.GroupName == "Ungrouped" ? string.Empty : soundboardSample.GroupName);
                    string newFilePath     = soundboardSample.GetVirtualFilePath();

                    Directory.CreateDirectory(targetDirectory);
                    File.Move(soundboardSample.FilePath, newFilePath);

                    soundboardSample.FilePath = newFilePath;
                }

                soundboardSample.SaveMetadataProperties();
            }
            catch (Exception ex)
            {
                ApplicationLogger.Log(ex.Message, ex.StackTrace);
            }
        }
Example #3
0
        public void OnFileWritten(object sender, EventArgs e)
        {
            try
            {
                string filePath     = sender as string;
                double totalSeconds = AudioAgent.GetFileAudioDuration(filePath).TotalSeconds;

                SoundboardSample NewSoundboardSample = new SoundboardSample(filePath)
                {
                    GroupName          = "Ungrouped",
                    FileTimeMax        = totalSeconds,
                    FileTimeMin        = 0,
                    FileTimeUpperValue = totalSeconds,
                    FileTimeLowerValue = 0,
                    HotkeyId           = SoundboardSampleCollection.Count
                };

                SoundboardSampleCollection.Add(NewSoundboardSample);
            }
            catch (Exception ex)
            {
                ApplicationLogger.Log(ex.Message, ex.StackTrace);
            }
        }