Beispiel #1
0
        public void RemoveTrack(BGMLTrack track)
        {
            int id = track.Index;

            Tracks.Remove(track);

            // Resort playlists
            foreach (var playlist in Playlists)
            {
                if (playlist.TrackIndexes.Contains(id))
                {
                    playlist.TrackIndexes.Remove(id);
                }

                for (int i = 0; i < playlist.TrackIndexes.Count; i++)
                {
                    if (playlist.TrackIndexes[i] >= id)
                    {
                        playlist.TrackIndexes[i]--;
                    }
                }
            }

            // And Tracks
            for (int i = 0; i < Tracks.Count; i++)
            {
                Tracks[i].Index = i;
            }
        }
Beispiel #2
0
        public static BGML ReadFromFile(string path)
        {
            using (var fs = new FileStream(path, FileMode.Open))
                using (var br = new BinaryStream(fs))
                {
                    var magic = br.ReadString(4);
                    if (magic != MAGIC)
                    {
                        throw new Exception($"Invalid file magic (Need {MAGIC}, got {magic})");
                    }

                    br.BaseStream.Position += 4;
                    uint fileSize = br.ReadUInt32();
                    if (fileSize != br.Length)
                    {
                        throw new Exception($"Invalid file size in file (File says {fileSize}b, but is actually {br.Length}b)");
                    }

                    br.Position += 4;

                    BGML bgml = new BGML();

                    int trackCount = br.ReadInt32();
                    bgml.Tracks = new List <BGMLTrack>(trackCount);
                    int trackTreeOffset = br.ReadInt32();

                    int playlistCount = br.ReadInt32();
                    bgml.Playlists = new List <BGML_Playlist>(playlistCount);
                    int playlistTreeOffset = br.ReadInt32();

                    // Read Tracks
                    for (int i = 0; i < trackCount; i++)
                    {
                        BGMLTrack track = new BGMLTrack();
                        br.Position = trackTreeOffset + (i * 0x30);
                        int fileNameOffset = br.ReadInt32();
                        bgml.Format = (LibraryTrackFormat)br.ReadInt32();
                        int idStringOffset = br.ReadInt32();
                        br.Position += 4;

                        // Don't make use of it yet
                        int trackHeaderOffset = br.ReadInt32();
                        if (!bgml.HasExtraTrackMetadata)
                        {
                            bgml.HasExtraTrackMetadata = trackHeaderOffset != 0;
                        }

                        track.Format = bgml.Format;

                        int trackNameOffset  = br.ReadInt32();
                        int artistNameOffset = br.ReadInt32();
                        int genreNameoffset  = br.ReadInt32();

                        if (fileNameOffset != 0)
                        {
                            br.Position = fileNameOffset;
                            track.Label = br.ReadString(StringCoding.ZeroTerminated);
                        }

                        if (idStringOffset != 0)
                        {
                            br.Position    = idStringOffset;
                            track.FileName = br.ReadString(StringCoding.ZeroTerminated);
                        }

                        if (trackNameOffset != 0)
                        {
                            br.Position     = trackNameOffset;
                            track.TrackName = br.ReadString(StringCoding.ZeroTerminated);
                        }

                        if (artistNameOffset != 0)
                        {
                            br.Position  = artistNameOffset;
                            track.Artist = br.ReadString(StringCoding.ZeroTerminated);
                        }

                        if (genreNameoffset != 0)
                        {
                            br.Position = genreNameoffset;
                            track.Genre = br.ReadString(StringCoding.ZeroTerminated);
                        }

                        bgml.Tracks.Add(track);
                        track.Index = i;
                    }

                    // Read Playlists
                    for (int i = 0; i < playlistCount; i++)
                    {
                        BGML_Playlist playlist = new BGML_Playlist();
                        br.Position = playlistTreeOffset + (i * 0x04);
                        br.Position = br.ReadInt32();

                        int nameOffset = br.ReadInt32();
                        br.Position += 12;
                        int pTrackCount = br.ReadInt32();

                        List <int> trackIndexes = new List <int>();
                        for (int j = 0; j < pTrackCount; j++)
                        {
                            trackIndexes.Add(br.ReadInt32());
                        }

                        playlist.TrackIndexes = trackIndexes;

                        br.Position   = nameOffset;
                        playlist.Name = br.ReadString(StringCoding.ZeroTerminated, Encoding.UTF8);

                        bgml.Playlists.Add(playlist);
                    }

                    return(bgml);
                }
        }
Beispiel #3
0
 public void RemoveTrack(BGMLTrack track)
 => TrackIndexes.Remove(track.Index);
Beispiel #4
0
 public void AddTrack(BGMLTrack track)
 => TrackIndexes.Add(track.Index);