예제 #1
0
        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());
        }
예제 #2
0
        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();
        }
예제 #3
0
        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;
        }
예제 #4
0
        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);
        }
예제 #5
0
        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;
                    }
                }
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        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++;
            }
        }
예제 #8
0
        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();
        }