private byte[] GetCoverFromTrack(CDQueryDataSet.TrackRow track) { byte[] imageArray = null; SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(track.SoundFile); if (sfi.Images != null && sfi.Images.Count > 0) { imageArray = sfi.Images[0]; } if (!string.IsNullOrEmpty(track.CDRow.FrontCover) && File.Exists(track.CDRow.FrontCover)) { imageArray = File.ReadAllBytes(track.CDRow.FrontCover); } if (imageArray == null) { return(null); } // Thumbnail generieren MemoryStream m = new MemoryStream(imageArray); Image img = Image.FromStream(m); MemoryStream msThumb = new MemoryStream(); EncoderParameters e = new EncoderParameters(); Image thumb = img.GetThumbnailImage(128, 128, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); thumb.Save(msThumb, ImageFormat.Jpeg); return(msThumb.ToArray()); }
private void UpdateSoundfiles(int oldId, string oldGenre, string newGenre, bool delete) { WaitProgressWindow waitProgress = new WaitProgressWindow(); waitProgress.Show(); waitProgress.progressControl.textBlockStatus.Text = StringTable.UpdatingGenres; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += delegate { DataTable dt = dataBase.ExecuteFreeSql("SELECT Soundfile from Track WHERE CategoryID = " + oldId); waitProgress.Dispatcher.Invoke((Action)(() => { waitProgress.progressControl.progressBar.Maximum = dt.Rows.Count; })); foreach (DataRow row in dt.Rows) { if (waitProgress.Canceled) { break; } string filename = row[0] as string; if (!string.IsNullOrEmpty(filename) && File.Exists(filename)) { SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(filename); if (string.Compare(sfi.Genre, oldGenre, true) == 0) { sfi.Genre = newGenre; SoundFileInformation.WriteMP3Tags(sfi, Field.TrackCategory); } } waitProgress.Dispatcher.Invoke((Action)(() => { waitProgress.progressControl.progressBar.Value++; })); } }; bw.RunWorkerCompleted += delegate { waitProgress.Close(); if (!waitProgress.Canceled) { if (delete) { dataBase.DeleteCategory(oldGenre, newGenre); } FillList(); SetOrderByList(); } }; bw.RunWorkerAsync(); }
/* public void Play(Track track) * { * currentTrack = track; * * try * { * if (string.IsNullOrEmpty(track.Soundfile) || !System.IO.File.Exists(track.Soundfile)) * return; * * SoundEngine.SoundEngine.PreListen.Play(track.Soundfile); * * SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(track.Soundfile); * TextBlockTrackName.Text = track.Artist + " - " + track.Title; * TextBlockTrackName.ToolTip = track.Artist + " - " + track.Title; * ProgressBar.Maximum = sfi.Length; * * BitmapImage bi = GetImage(track); * if (bi != null) * { * ImageCover.Source = bi; * } * else * { * ImageCover.Source = new BitmapImage(new Uri("pack://application:,,,/CatalogView3D;component/Images/CDCover.png")); * } * * ButtonPlay.Content = FindResource("PauseButtonPath"); * } * catch (Exception e) * { * TextBlockTrackName.Text = Big3.Hitbase.SharedResources.StringTable.Error; * TextBlockTrackName.ToolTip = e.Message; * } * }*/ /// <summary> /// Liefert das Bild der MP3-Datei zurück. Falls nicht vorhanden, wird noch gesucht, ob die CD ein Bild /// hat, um dann dieses zurückzuliefern. /// </summary> /// <returns></returns> private BitmapImage GetImage(SoundFileInformation sfi) { if (sfi.Images != null && sfi.Images.Count > 0) { MemoryStream ms = new MemoryStream(sfi.Images[0]); return(ImageLoader.GetBitmapImageFromMemoryStream(ms)); } return(null); }
void timer_Tick(object sender, EventArgs e) { if (this.Visibility != System.Windows.Visibility.Visible) { return; } if (SoundEngine.SoundEngine.PreListen.IsPlaying) { if (!lastIsPlaying || lastPlayingFilename != SoundEngine.SoundEngine.PreListen.Filename) { SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(SoundEngine.SoundEngine.PreListen.Filename); TextBlockTrackName.Text = sfi.Artist + " - " + sfi.Title; TextBlockTrackName.ToolTip = sfi.Artist + " - " + sfi.Title; ProgressBar.Maximum = sfi.Length; BitmapImage bi = GetImage(sfi); if (bi != null) { ImageCover.Source = bi; } else { ImageCover.Source = new BitmapImage(new Uri("pack://application:,,,/CatalogView3D;component/Images/CDCover.png")); } ButtonPlay.Content = FindResource("PauseButtonPath"); } int position = SoundEngine.SoundEngine.PreListen.PlayPosition; TextBlockStatus.Text = Misc.GetShortTimeString(position); ProgressBar.Value = position; } else { //Visibility = Visibility.Hidden; TextBlockStatus.Text = ""; //ImageCover.Source = null; ProgressBar.Value = 0; } lastIsPlaying = SoundEngine.SoundEngine.PreListen.IsPlaying; lastPlayingFilename = SoundEngine.SoundEngine.PreListen.Filename; }
private void EditTrackField(int column, Field field, MyMusicListItem musicItem) { #if false int cdId = DataBase.GetCDIDByTrackID(musicItem.ID); CD cd = DataBase.GetCDById(cdId); int trackIndex = cd.FindTrackIndexByTrackID(musicItem.ID); object newValue = musicItem.Items[column]; if (FieldHelper.IsCDField(field)) { cd.SetValueToField(field, newValue); } else { cd.SetTrackValueToField(trackIndex, field, newValue); } //cd.Save(DataBase, cd.Tracks[trackIndex]); Big3.Hitbase.SoundEngine.SoundFileInformation.WriteMP3Tags(cd, musicItem.ID); Big3.Hitbase.SoundFilesManagement.SynchronizeCatalogWorker.Instance.ScanFile(cd.Tracks[trackIndex].Soundfile); #endif SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(musicItem.Soundfile); object newValue = musicItem.Items[column]; if (newValue != null) { sfi.SetField(field, newValue.ToString()); } else { sfi.SetField(field, ""); } Big3.Hitbase.SoundEngine.SoundFileInformation.WriteMP3Tags(sfi, field); Big3.Hitbase.SoundFilesManagement.SynchronizeCatalogWorker.Instance.ScanFile(musicItem.Soundfile); }
private void ScanDataCDRecursive(string directory) { string[] files = Directory.GetFileSystemEntries(directory); foreach (string filename in files) { if (Directory.Exists(filename)) { ScanDataCDRecursive(filename); } else { if (Big3.Hitbase.SoundEngine.SoundEngine.IsSupportedFileType(filename)) { SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(filename); Track cdTrack = new Track(); SoundFileInformation.FillAlbumAndTrackFromSoundFileInformation(CD, cdTrack, sfi); CD.Tracks.AddItemFromThread(cdTrack); CD.TotalLength += cdTrack.Length; } } } }
/// <summary> /// Legt den Header der Track-Tabellenansicht an. /// </summary> /// <param name="fields"></param> private void CreateHeader(ColumnFieldCollection fields) { dataGrid.Columns.Clear(); CreatePlayControlColumn(); int i = 0; foreach (ColumnField field in fields) { Type columnType = DataBase.GetTypeByField(field.Field); int width = field.Width; string columnName = DataBase.GetNameOfFieldFull(field.Field, true); switch (field.Field) { case Field.Rating: case Field.TrackRating: { DataGridTemplateColumn nc = new DataGridTemplateColumn(); System.Windows.DataTemplate template = new System.Windows.DataTemplate(); System.Windows.FrameworkElementFactory factoryRatingControl = new System.Windows.FrameworkElementFactory(typeof(RatingUserControl)); System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Items[" + i + "]"); //binding.Converter = int32Conv; factoryRatingControl.SetBinding(RatingUserControl.RatingProperty, binding); factoryRatingControl.SetValue(RatingUserControl.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left); factoryRatingControl.AddHandler(RatingUserControl.MouseLeftButtonDownEvent, new MouseButtonEventHandler(RatingCell_MouseLeftButtonDown)); //factoryRatingControl.SetValue(RatingUserControl.ReadOnlyProperty, true); nc.SetValue(DataGridExtensions.FieldProperty, field.Field); template.VisualTree = factoryRatingControl; nc.CanUserSort = true; nc.CellTemplate = template; nc.Header = columnName; nc.Width = width; nc.SortMemberPath = "Items[" + i + "]"; //nc.IsReadOnly = true; dataGrid.Columns.Add(nc); break; } case Field.Comment: { DataGridTemplateColumn newMultilineColumn = new DataGridTemplateColumn(); newMultilineColumn.Width = field.Width; newMultilineColumn.Header = DataBase.GetNameOfField(field.Field); newMultilineColumn.SetValue(DataGridExtensions.FieldProperty, field.Field); DataTemplate multilineCelltemplate = this.FindResource("CommentTemplate") as DataTemplate; newMultilineColumn.CellTemplate = multilineCelltemplate; newMultilineColumn.CellEditingTemplate = multilineCelltemplate; dataGrid.Columns.Add(newMultilineColumn); break; } default: { DataGridMaxLengthTextColumn nc = new DataGridMaxLengthTextColumn(); nc.SetValue(DataGridExtensions.FieldProperty, field.Field); System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Items[" + i + "]"); if (field.Field == Field.TotalLength || field.Field == Field.TrackLength) { binding.Converter = new Big3.Hitbase.Miscellaneous.LengthConverter(); } else if (field.Field == Field.Price) { binding.Converter = new PriceConverter(); } else if (field.Field == Field.Date) { binding.Converter = new DataBaseDateConverter(); binding.ConverterParameter = this.DataBase; } else if (field.Field == Field.AlbumType) { binding.Converter = new AlbumTypeConverter(); nc.IsReadOnly = true; } else if (IsUserFieldDateFormat(field.Field)) { binding.Converter = new UserFieldDateConverter(); } else if (field.Field == Field.YearRecorded || field.Field == Field.TrackYearRecorded) { binding.Converter = new IntHideZeroConverter(); } else if (DataBase.GetTypeByField(field.Field) == typeof(int)) { binding.Converter = new MyInt32Converter(); } else if (DataBase.GetTypeByField(field.Field) == typeof(bool)) { binding.Converter = new BoolConverter(); } nc.Binding = binding; nc.Header = columnName; nc.Width = width; nc.IsReadOnly = !SoundFileInformation.CanChangeID3Tag(field.Field); if (DataBase.GetTypeByField(field.Field) == typeof(string)) { nc.MaxLength = DataBase.GetMaxStringLength(field.Field); } dataGrid.Columns.Add(nc); break; } } i++; } CurrentFields = fields; }
public bool ScanFile(string filename) { try { FileInfo fi = new FileInfo(filename); if (SoundEngine.SoundEngine.IsSupportedFileType(filename) && fi.Length / 1024 >= Settings.Current.ManageSoundFilesMinSize) { NumberOfItems++; // Prüfen, ob sich die Datei geändert hat //string sql = string.Format("Select SoundFileLastModified FROM Track where SoundFile = '{0}'", DataBase.SqlPrepare(filename)); //object lastModified = dataBase.ExecuteScalar(sql); // Fehler umgehen: http://connect.microsoft.com/SQLServer/feedback/details/683114/getting-exception-the-data-area-passed-to-a-system-call-is-too-small-in-sql-server-compact-4 string sql = string.Format("Select SoundFileLastModified FROM Track where SoundFile = @param1"); object lastModified = dataBase.ExecuteScalarWithParameter(sql, filename); allFiles.Add(filename); if (lastModified != null) { if (!(lastModified is DBNull) && (fi.LastWriteTime - (DateTime)lastModified).TotalSeconds < 1) { // Datei hat sich nicht geändert, also nichts tun. return(false); } } // Prüfen, ob die Datei in einer CD refernziert ist (also nicht in einem MP3-Album!) // Dann darf man damit auch nichts machen, da die Datei nicht synchronisiert wird. if (dataBase.IsSoundfileNotSynchronized(filename)) { return(false); } SoundFileInformation sfInfo = SoundFileInformation.GetSoundFileInformation(filename); NumberOfChangedItems++; if (sfInfo.ID3Version == 0) { string artist = ""; string title = ""; Misc.GetAlbumInfoByFilename(filename, "- ", out artist, out title); sfInfo.Artist = artist; sfInfo.Title = title; } if (string.IsNullOrEmpty(sfInfo.Artist)) { sfInfo.Artist = StringTable.UnknownArtist; } if (string.IsNullOrEmpty(sfInfo.Album)) { sfInfo.Album = StringTable.UnknownAlbum; } // CD suchen (Interpret und Album) int cdid = dataBase.GetCDIDByArtistAndTitle(!string.IsNullOrEmpty(sfInfo.AlbumArtist) ? sfInfo.AlbumArtist : sfInfo.Artist, sfInfo.Album); if (cdid == 0) { // CD ist noch nicht vorhanden. Jetzt also erst mal anlegen. CD newCD = new CD(); /*Zur Zeit nicht mehr! if (Settings.Current.ManageSoundFilesCreateOneCollection) * { * newCD.Artist = Settings.Current.ManageSoundFilesCreateOneCollectionTitle1; * newCD.Title = Settings.Current.ManageSoundFilesCreateOneCollectionTitle2; * newCD.Sampler = true; * } * else*/ { newCD.Artist = sfInfo.AlbumArtist.Left(100); if (string.IsNullOrEmpty(newCD.Artist)) { newCD.Artist = sfInfo.Artist.Left(100); } if (sfInfo.AlbumArtist != sfInfo.Artist) { newCD.Sampler = true; } newCD.Title = sfInfo.Album.Left(100); newCD.Category = sfInfo.Genre; newCD.YearRecorded = sfInfo.Year; } newCD.Type = AlbumType.ManagedSoundFiles; newCD.Tracks = new SafeObservableCollection <Track>(); newCD.Save(dataBase); cdid = newCD.ID; } // Prüfen, ob der Track schon vorhanden ist Track track; Track trackFound = dataBase.GetTrackBySoundfile(filename); if (trackFound != null) { track = trackFound; } else { track = new Track(); } track.TrackNumber = sfInfo.TrackNumber; track.Artist = sfInfo.Artist.Left(100); track.Title = sfInfo.Title.Left(100); track.Composer = sfInfo.Composer.Left(100); track.YearRecorded = sfInfo.Year; track.Category = sfInfo.Genre; track.Soundfile = filename; track.Length = sfInfo.Length; track.Rating = sfInfo.Rating; track.Language = sfInfo.Language; track.PlayCount = sfInfo.PlayCount; track.SoundFileLastModified = fi.LastWriteTime; track.CDID = cdid; if (sfInfo.Images != null && sfInfo.Images.Count > 0) { dataBase.UpdateFrontCover(cdid, sfInfo.Artist, sfInfo.Album, sfInfo.Images[0]); } track.Save(dataBase); return(true); } } catch { } return(false); }
private void SearchFiles(string directory, bool countOnly) { if (canceled) { return; } // Zuerst alle Unterverzeichnisse string[] subDirs = null; labelCurrentDirectory.Text = directory; if (sw.ElapsedMilliseconds >= 500) { Application.DoEvents(); sw.Reset(); sw.Start(); } try { subDirs = Directory.GetDirectories(directory); } catch { } if (subDirs != null) { foreach (string subDir in subDirs) { SearchFiles(subDir, countOnly); } } // und dann die Dateien string[] filenames; try { filenames = Directory.GetFiles(directory); } catch { // Wahrscheinlich ein Verzeichnis, auf das wir keinen Zugriff haben. return; } foreach (string filename in filenames) { if (canceled) { break; } if (!countOnly) { FileInfo fi = new FileInfo(filename); if (SoundEngine.SoundEngine.IsSupportedFileType(filename)) { SoundFileInformation sfInfo = SoundFileInformation.GetSoundFileInformation(filename); if (sfInfo.ID3Version == 0) { string artist = ""; string title = ""; Misc.GetAlbumInfoByFilename(filename, "- ", out artist, out title); sfInfo.Artist = artist; sfInfo.Title = title; } if (string.IsNullOrEmpty(sfInfo.Artist)) { sfInfo.Artist = StringTable.UnknownArtist; } if (string.IsNullOrEmpty(sfInfo.Album)) { sfInfo.Album = StringTable.UnknownAlbum; } //string cdKey; //if (Settings.Current.ManageSoundFilesCreateOneCollection) // cdKey = "DUMMY"; // Damit wandern alle Tracks in ein Album //else // cdKey = string.Format("{0}_{1}", sfInfo.Artist, sfInfo.Album); CD cd; //if (newCD.ContainsKey(cdKey)) { cd = newCD; } /*else * { * CD newCD = new CD(); * //if (Settings.Current.ManageSoundFilesCreateOneCollection) * { * newCD.Artist = Settings.Current.SamplerFixedArtistText; * newCD.Title = Big3.Hitbase.SharedResources.StringTable.SoundCollection; * newCD.Sampler = true; * } * else * { * newCD.Artist = sfInfo.Artist.Left(100); * newCD.Title = sfInfo.Album.Left(100); * newCD.Category = sfInfo.Genre; * } * newCD.Type = AlbumType.SoundFiles; * newCD.Tracks = new SafeObservableCollection<Track>(); * newCDs.Add(cdKey, newCD); * cd = newCD; * }*/ Track track = new Track(); track.TrackNumber = sfInfo.TrackNumber; track.Artist = sfInfo.Artist.Left(100); track.Title = sfInfo.Title.Left(100); track.Composer = sfInfo.Composer.Left(100); track.Category = sfInfo.Genre; track.Soundfile = filename; track.Length = sfInfo.Length; track.Rating = sfInfo.Rating; track.Language = sfInfo.Language; cd.TotalLength += track.Length; cd.Tracks.Add(track); if (string.IsNullOrEmpty(cd.Title)) { cd.Title = sfInfo.Album; } count++; Row row = new Row(); row.Cells.Add(new Cell(sfInfo.Artist)); row.Cells.Add(new Cell(sfInfo.Album)); row.Cells.Add(new Cell(sfInfo.Title)); int index = Table.TableModel.Rows.Add(row); Table.EnsureVisible(index, 0); labelAddedFiles.Text = count.ToString(); if (sw.ElapsedMilliseconds >= 500) { labelFoundFiles.Text = countAll.ToString(); Application.DoEvents(); sw.Reset(); sw.Start(); } } progressBar1.Value = countAll; } countAll++; } }
public static void UpdateSoundfiles(DataBase dataBase, int oldId, string oldPersonGroup, string newPersongroup, UpdateSoundfilesCompletedDelegate updateCompleted) { WaitProgressWindow waitProgress = new WaitProgressWindow(); waitProgress.Show(); waitProgress.progressControl.textBlockStatus.Text = StringTable.UpdatingPersonGroups; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += delegate { DataTable dt = dataBase.ExecuteFreeSql("SELECT Soundfile from Track inner join cd on track.cdid = cd.cdid WHERE track.artistID = " + oldId + " or track.composerId = " + oldId + " or cd.artistid = " + oldId + " or cd.composerid = " + oldId); waitProgress.Dispatcher.Invoke((Action)(() => { waitProgress.progressControl.progressBar.Maximum = dt.Rows.Count; })); foreach (DataRow row in dt.Rows) { if (waitProgress.Canceled) { break; } string filename = row[0] as string; if (!string.IsNullOrEmpty(filename) && File.Exists(filename)) { SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(filename); if (string.Compare(sfi.Artist, oldPersonGroup, true) == 0) { sfi.Artist = newPersongroup; SoundFileInformation.WriteMP3Tags(sfi, Field.ArtistTrackName); } if (string.Compare(sfi.Composer, oldPersonGroup, true) == 0) { sfi.Composer = newPersongroup; SoundFileInformation.WriteMP3Tags(sfi, Field.ComposerTrackName); } if (string.Compare(sfi.AlbumArtist, oldPersonGroup, true) == 0) { sfi.AlbumArtist = newPersongroup; SoundFileInformation.WriteMP3Tags(sfi, Field.ArtistCDName); } } waitProgress.Dispatcher.Invoke((Action)(() => { waitProgress.progressControl.progressBar.Value++; })); } }; bw.RunWorkerCompleted += delegate { waitProgress.Close(); if (!waitProgress.Canceled) { if (updateCompleted != null) { updateCompleted(); } } }; bw.RunWorkerAsync(); }