Exemple #1
0
        public static SoundFileInformation GetSoundFileInformation(DataBase db, Track track)
        {
            SoundFileInformation soundFileInfo = new SoundFileInformation();

            if (track.CD != null)
            {
                soundFileInfo.Album = track.CD.Title;
                if (!track.CD.Sampler)
                {
                    soundFileInfo.Artist = track.CD.Artist;
                }
            }

            soundFileInfo.Artist        = track.Artist;
            soundFileInfo.Title         = track.Title;
            soundFileInfo.Rating        = track.Rating;
            soundFileInfo.StartPosition = track.StartPosition;
            soundFileInfo.Length        = track.Length;
            soundFileInfo.Filename      = track.Soundfile;
            try
            {
                string cdcoverFrontFilename = db.GetFrontCoverByCdId(track.CDID);
                if (!string.IsNullOrEmpty(cdcoverFrontFilename))
                {
                    byte[] filefrontcover = File.ReadAllBytes(Misc.FindCover(cdcoverFrontFilename));
                    soundFileInfo.Images = new List <byte[]>();
                    soundFileInfo.Images.Add(filefrontcover);
                }
            }
            catch { }

            return(soundFileInfo);
        }
Exemple #2
0
        public static SoundFileInformation GetSoundFileInformation(string filename)
        {
            SoundFileInformation soundFileInfo = new SoundFileInformation();

            GetSoundFileInformation(soundFileInfo, filename);

            return(soundFileInfo);
        }
Exemple #3
0
        private PlaylistItem GetPlaylistItem(string filename)
        {
            PlaylistItem playlistItem = new PlaylistItem(this);

            playlistItem.Info = SoundFileInformation.GetSoundFileInformation(filename);

            return(playlistItem);
        }
Exemple #4
0
        private PlaylistItem GetPlaylistItem(DataBase db, Track track)
        {
            PlaylistItem playlistItem = new PlaylistItem(this);

            playlistItem.ID   = track.ID;
            playlistItem.Info = SoundFileInformation.GetSoundFileInformation(db, track);

            return(playlistItem);
        }
Exemple #5
0
        private System.Windows.Media.ImageSource GetTrackImage(bool highQuality)
        {
            try
            {
                byte[] imageBytes = null;
                if (Info.Images != null && Info.Images.Count > 0)
                {
                    imageBytes = Info.Images[0];
                }
                else
                {
                    SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(Info.Filename);
                    if (sfi.Images != null && sfi.Images.Count > 0)
                    {
                        imageBytes = sfi.Images[0];
                    }
                }

                if (imageBytes != null)
                {
                    BitmapImage image = new BitmapImage();
                    image.BeginInit();
                    MemoryStream ms = new MemoryStream(imageBytes);
                    image.StreamSource = ms;
                    if (!highQuality)
                    {
                        image.DecodePixelWidth  = 100;
                        image.DecodePixelHeight = 100;
                    }
                    image.CacheOption = BitmapCacheOption.OnLoad;
                    image.EndInit();
                    image.Freeze();
                    return(image);
                }
            }
            catch
            {
                // Dann ist wohl das Bild kaputt.....
            }

            return(DefaultTrackImage);
        }
Exemple #6
0
        public static void WriteMP3Tags(SoundFileInformation sfi, Field field)
        {
            // Im Moment nur MP3
            string ext = Path.GetExtension(sfi.Filename).ToLower();

            if (ext != ".mp3" && ext != ".flac" && ext != ".wma" && ext != ".ogg")
            {
                return;
            }

            using (TagLib.File tagFile = TagLib.File.Create(sfi.Filename))
            {
                int id3Version = Settings.Current.UseID3Version;

                switch (field)
                {
                case Field.ArtistTrackName:
                {
                    tagFile.Tag.Performers = new string[] { sfi.Artist };
                    break;
                }

                case Field.Title:
                {
                    tagFile.Tag.Album = sfi.Album;
                    break;
                }

                case Field.TrackNumber:
                {
                    tagFile.Tag.Track = (uint)sfi.TrackNumber;
                }

                break;

                case Field.TrackCategory:
                {
                    tagFile.Tag.Genres = new string[] { sfi.Genre };
                    break;
                }

                case Field.ArtistCDName:
                {
                    tagFile.Tag.AlbumArtists = new string[] { sfi.AlbumArtist };
                    break;
                }

                case Field.ComposerTrackName:
                {
                    tagFile.Tag.Composers = new string[] { sfi.Composer };
                    break;
                }

                case Field.TrackTitle:
                {
                    tagFile.Tag.Title = sfi.Title;
                    break;
                }

                case Field.TrackYearRecorded:
                {
                    tagFile.Tag.Year = (uint)sfi.Year;
                    break;
                }

                case Field.TrackComment:
                {
                    tagFile.Tag.Comment = sfi.Comment;
                    break;
                }

                case Field.TrackRating:
                {
                    if (sfi.Rating > 0 && ext == ".mp3")
                    {
                        TagLib.Id3v2.PopularimeterFrame popFrame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tagFile.GetTag(TagLib.TagTypes.Id3v2), "*****@*****.**", true);

                        popFrame.User      = "******";
                        popFrame.Rating    = (byte)sfi.Rating;
                        popFrame.PlayCount = (ulong)sfi.PlayCount;
                    }
                    break;
                }

                case Field.TrackPlayCount:
                {
                    /*id3Info.ID3v2Info.PlayCounter = new ID3.ID3v2Frames.OtherFrames.PlayCounterFrame((FrameFlags)0);
                     *
                     * id3Info.ID3v2Info.PlayCounter.Counter = sfi.PlayCount;*/

                    break;
                }
                }

                tagFile.Save();
            }
        }
Exemple #7
0
        public static void FillAlbumAndTrackFromSoundFileInformation(CD cd, Track track, SoundFileInformation sfi)
        {
            track.Artist        = sfi.Artist;
            track.Title         = sfi.Title;
            track.Category      = sfi.Genre;
            track.Comment       = sfi.Comment;
            track.Composer      = sfi.Composer;
            track.Lyrics        = sfi.Lyrics;
            track.Rating        = sfi.Rating;
            track.Length        = sfi.Length;
            track.TrackNumber   = sfi.TrackNumber;
            track.StartPosition = 0;
            track.Bpm           = sfi.BPM;
            track.CD            = cd;
            track.Soundfile     = sfi.Filename;

            cd.Artist = sfi.AlbumArtist;
            cd.Title  = sfi.Album;
        }
Exemple #8
0
        public static void GetSoundFileInformation(SoundFileInformation soundFileInfo, string filename)
        {
            soundFileInfo.Filename = filename;

            try
            {
                if (string.IsNullOrEmpty(filename) || !System.IO.File.Exists(filename))
                {
                    return;
                }

                string ext = Path.GetExtension(filename).ToLower();

                using (TagLib.File tagFile = TagLib.File.Create(filename))
                {
                    if (tagFile.Tag.Performers.Length > 0)
                    {
                        soundFileInfo.Artist = string.Join(";", tagFile.Tag.Performers).Trim();
                        // The AC/DC exception
                        if (soundFileInfo.Artist.Contains("AC;DC"))
                        {
                            soundFileInfo.Artist = soundFileInfo.Artist.Replace("AC;DC", "AC/DC");
                        }
                    }

                    if (tagFile.Tag.FirstAlbumArtist != null)
                    {
                        soundFileInfo.AlbumArtist = tagFile.Tag.FirstAlbumArtist.Trim();
                    }

                    if (tagFile.Tag.Album != null)
                    {
                        soundFileInfo.Album = tagFile.Tag.Album.Trim();
                    }

                    if (tagFile.Tag.Title != null)
                    {
                        soundFileInfo.Title = tagFile.Tag.Title.Trim();
                    }

                    if (tagFile.Tag.Comment != null)
                    {
                        soundFileInfo.Comment = tagFile.Tag.Comment.Trim();
                    }

                    soundFileInfo.Year        = (int)tagFile.Tag.Year;
                    soundFileInfo.TrackNumber = (int)tagFile.Tag.Track;

                    soundFileInfo.Genre = tagFile.Tag.FirstGenre;

                    if (tagFile.Tag.FirstComposer != null)
                    {
                        soundFileInfo.Composer = tagFile.Tag.FirstComposer.Trim();
                    }
                    // TODO!!!
                    //soundFileInfo.Language = tagFile.Tag.Language.Trim();

                    /*if (id3Info.ID3v2Info.PlayCounter != null)
                     * {
                     *  soundFileInfo.PlayCount = (int)id3Info.ID3v2Info.PlayCounter.Counter;
                     * }*/

                    if (tagFile.Tag.Lyrics != null)
                    {
                        soundFileInfo.Lyrics = tagFile.Tag.Lyrics.Trim();
                    }


                    // Rating ist eine Liste von Einträgen. Wir suchen hier nach dem Eintrag "*****@*****.**".
                    TagLib.Id3v2.Tag id3v2Tag = tagFile.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;
                    if (id3v2Tag != null)
                    {
                        TagLib.Id3v2.PopularimeterFrame popFrame = TagLib.Id3v2.PopularimeterFrame.Get(id3v2Tag, "*****@*****.**", false);

                        if (popFrame != null)
                        {
                            soundFileInfo.Rating    = popFrame.Rating;
                            soundFileInfo.PlayCount = (int)popFrame.PlayCount;
                        }
                    }

                    soundFileInfo.BPM = (int)tagFile.Tag.BeatsPerMinute;

                    soundFileInfo.Length = (int)tagFile.Properties.Duration.TotalMilliseconds;

                    soundFileInfo.Images = new List <byte[]>();
                    if (tagFile.Tag.Pictures.Length > 0)
                    {
                        foreach (TagLib.IPicture picture in tagFile.Tag.Pictures)
                        {
                            soundFileInfo.Images.Add(picture.Data.ToArray());
                        }
                    }

                    soundFileInfo.ID3Version = 2;

                    if (soundFileInfo.Length == 0)
                    {
                        // Wenn in den ID3-Tags nichts drin stand, dann ermitteln wir die Länge über diesen Weg.
                        soundFileInfo.Length = SoundEngine.GetLengthOfSoundfile(filename);
                    }
                }
            }
            catch
            {
                // Zuerst mal hier alle Fehler ignorieren.
            }
        }
Exemple #9
0
        public static void GetSoundTags(string filename, SoundFileInformation soundFileInfo)
        {
            FMOD.Sound  sound = null;
            FMOD.RESULT res   = SoundEngine.Instance.system.createStream(filename, FMOD.MODE.OPENONLY, ref sound);

            if (sound != null)
            {
                int numtags  = 0;
                int num2tags = 0;
                sound.getNumTags(ref numtags, ref num2tags);

                for (int i = 0; i < numtags; i++)
                {
                    FMOD.TAG tag2 = new FMOD.TAG();
                    res = sound.getTag(null, i, ref tag2);
                    if (res != FMOD.RESULT.ERR_TAGNOTFOUND)
                    {
                        string tagName = tag2.name.ToLower();
                        if (tagName == "title")
                        {
                            soundFileInfo.Title = Marshal.PtrToStringAnsi(tag2.data);
                        }

                        if (tagName == "author" || tagName == "artist")
                        {
                            soundFileInfo.Artist = Marshal.PtrToStringAnsi(tag2.data);
                        }

                        if (tagName == "wm/tracknumber" || tagName == "tracknumber")
                        {
                            if (tag2.datatype == FMOD.TAGDATATYPE.STRING)
                            {
                                soundFileInfo.TrackNumber = Big3.Hitbase.Miscellaneous.Misc.Atoi(Marshal.PtrToStringAnsi(tag2.data));
                            }

                            if (tag2.datatype == FMOD.TAGDATATYPE.INT)
                            {
                                soundFileInfo.TrackNumber = Convert.ToInt32(Marshal.ReadInt32(tag2.data));
                            }
                        }

                        if (tagName == "wm/composer")
                        {
                            soundFileInfo.Composer = Marshal.PtrToStringAnsi(tag2.data);
                        }

                        if (tagName == "wm/albumtitle" || tagName == "album")
                        {
                            soundFileInfo.Album = Marshal.PtrToStringAnsi(tag2.data);
                        }

                        if (tagName == "wm/year")
                        {
                            soundFileInfo.Year = Big3.Hitbase.Miscellaneous.Misc.Atoi(Marshal.PtrToStringAnsi(tag2.data));
                        }

                        if (tagName == "wm/genre" || tagName == "genre")
                        {
                            soundFileInfo.Genre = Marshal.PtrToStringAnsi(tag2.data);
                        }
                    }
                }

                sound.release();
            }
        }