public WavEditor(AudioPatternSetting setting) { InitializeComponent(); _setting = setting; _player = new SoundPlayer(); MouseWheel += WavEditor_MouseWheel; if (_setting != null) { var data = File.ReadAllBytes(_setting.FileName); _viewer.Data = data; } }
private void AddOrUpdateAudioPattern(AudioPatternSetting setting) { string lengthStr = _audioFileService.GetLength(setting.FileName).ToString(@"mm\:ss\.fff"); ListViewItem item = _audioPatterns.Items.Cast<ListViewItem>().FirstOrDefault(lvi => string.Equals(((AudioPatternSetting)lvi.Tag).FileName, setting.FileName, StringComparison.InvariantCultureIgnoreCase)); if (item != null) { item.Text = setting.Name; item.SubItems[1].Text = lengthStr; } else { item = new ListViewItem { Text = setting.Name, Tag = setting }; item.SubItems.Add(lengthStr); _audioPatterns.Items.Add(item); } }
private void _audioAdd_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog(this) == DialogResult.OK) { try { string outputFileName = Path.Combine(Path.GetDirectoryName(_settings.FileName), Path.GetFileNameWithoutExtension(dlg.FileName) + ".u8"); _audioFileService.Convert(dlg.FileName).WriteToFile(outputFileName); var setting = new AudioPatternSetting { FileName = outputFileName, Name = Path.GetFileNameWithoutExtension(outputFileName) }; AddOrUpdateAudioPattern(setting); } catch (Exception ex) { ExceptionMessageBox.Show(this, "Error Adding Audio Pattern", "Could not add audio pattern.", ex); } } }