public void StartTagging() { wndMainWindow = this.Owner as MainWindow; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(pbProgress.SetValue); UpdateProgressTextDelegate updatePtDelegate = new UpdateProgressTextDelegate(txtResults.SetValue); double i = 0.0; int total = wndMainWindow.AudioEngine.Playlist.Count; pbProgress.Minimum = i; pbProgress.Maximum = total; string t = "Initializing..."; int idx = 0; int c = wndMainWindow.AudioEngine.Playlist.Count(); Database.Song[] temp = new Database.Song[c]; wndMainWindow.AudioEngine.Playlist.CopyTo(temp, 0); // can't modify the playlist if its the subject of the foreach, so we have to make a copy. foreach (Database.Song row in temp) { i++; t += "\n" + "Processing file " + i.ToString() + " of " + total.ToString() + " | " + row.Filename; Dispatcher.Invoke(updatePtDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBox.TextProperty, t }); AudioEngine.Fingerprint(row); wndMainWindow.AudioEngine.Playlist.RemoveAt(idx); wndMainWindow.AudioEngine.Playlist.Insert(idx, row); Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, i }); idx++; } this.btnClose.IsEnabled = true; }
/// <summary> /// Loads a .m3u playlist. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_open_Click(object sender, RoutedEventArgs e) { this.wndMainWindow = this.Owner as MainWindow; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".m3u"; dlg.Multiselect = true; dlg.Filter = "MP3 Audio Playlist(.m3u)|*.m3u|Windows Media Playlist (.wpl)|*.wpl|Mpeg Audio Layer 3 File|*.mp3|Windows Media Audio File|*.wma"; Nullable<bool> result = dlg.ShowDialog(); if (result == true) { switch (dlg.FilterIndex) { case 1: foreach (string fn in dlg.FileNames) { this.wndMainWindow.AudioEngine.Playlist.Load(fn); } break; case 2: foreach (string fn in dlg.FileNames) { this.wndMainWindow.AudioEngine.Playlist.Load(fn); } break; case 3: foreach (string fn in dlg.FileNames) { Database.Song s = this.wndMainWindow.AudioEngine.Datastore.Songs.AddFile(new System.IO.FileInfo(fn)); this.wndMainWindow.AudioEngine.Playlist.Add(s); //this.wndMainWindow.AudioEngine.Playlist.AddFile(new System.IO.FileInfo(fn)); } break; case 4: foreach (string fn in dlg.FileNames) { this.wndMainWindow.AudioEngine.Playlist.AddFile(new System.IO.FileInfo(fn)); } break; } this.DataContext = this.wndMainWindow.AudioEngine.Playlist; #region OldStuff /* switch (dlg.FilterIndex) { case 1: string f = ""; foreach (string fn in dlg.FileNames) { System.IO.FileInfo fi = new System.IO.FileInfo(fn); string[] lines = System.IO.File.ReadAllLines(fn); // this is a .m3u file, so we want to ignore any lines that begin with a '#' character foreach (string line in lines) { if (line.Length > 0) { if (line.Substring(0, 1) != "#") { // M3U can have fullpaths or just filenames, so we have to check for this. if (line.Contains("\\") || line.Contains("/")) { f = line; } else { f = fi.DirectoryName + "\\" + line; } System.IO.FileInfo fileinfo = new System.IO.FileInfo(f); if (fileinfo.Exists) { this.AddToPlaylist(fileinfo); } } } } } break; case 2: foreach (string fn in dlg.FileNames) { System.IO.FileInfo fileinfo = new System.IO.FileInfo(fn); if (fileinfo.Exists) { this.AddToPlaylist(fileinfo); } } break; case 3: foreach (string fn in dlg.FileNames) { System.IO.FileInfo fileinfo = new System.IO.FileInfo(fn); if (fileinfo.Exists) { this.AddToPlaylist(fileinfo); } } break; } */ #endregion } }
/// <summary> /// Handles the ContentRendered event and wires up a pointer to the main window. /// </summary> /// <param name="e"></param> protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); this.wndMainWindow = this.Owner as MainWindow; }