Пример #1
0
        private TrackCollection CreateChildrenFromParents(TrackCollection parent1, TrackCollection parent2)
        {
            var children = new TrackCollection();

            for (var k = 0; k < (parent1.Count) / 2; k++)
            {
                children.Add(parent1[k]);
            }

            for (var i = (parent1.Count) / 2; i < parent1.Count; i++)
            {
                if (children.Contains(parent2[i]))
                {
                    foreach (var t in parent1)
                    {
                        if ((!children.Contains(t)) && (!parent2.GetRange((parent1.Count) / 2, (parent1.Count) / 2).Contains(t)))
                        {
                            children.Add(t);
                        }
                    }
                }
                else
                {
                    children.Add(parent2[i]);
                }
            }
            return(children);
        }
        private static TrackCollection CreatePotentialTrackCollection(TrackCollection current)
        {
            var random = new Random();
            var track1 = random.Next(current.Count);
            var track2 = random.Next(current.Count);

            if (current[track1].IsFixed || current[track2].IsFixed)
            {
                return(current);
            }
            var newTrackCollection = new TrackCollection();

            for (var i = 0; i < current.Count; i++)
            {
                if (i == track1)
                {
                    newTrackCollection.Add(current[track2]);
                }
                else
                {
                    newTrackCollection.Add(i == track2 ? current[track1] : current[i]);
                }
            }
            return(newTrackCollection);
        }
        private TrackCollection LoadTracks()
        {
            TrackCollection tracks = new TrackCollection();
            Track track = new Track() { StartTime = new DateTime(2012, 3, 1, 11, 11, 12), EndTime = new DateTime(2012, 3, 1, 11, 11, 59) };
            tracks.Add(track);

            track = new Track() { StartTime = new DateTime(2012, 3, 1, 11, 1, 0), EndTime = new DateTime(2012, 3, 1, 11, 1, 59) };
            tracks.Add(track);

            return tracks;
        }
        public void LengthTest()
        {
            TrackCollection target = new TrackCollection();
            Track track = new Track() { StartTime = new DateTime(2012, 3, 1, 0, 0, 0) };
            target.Add(track);

            long actual = target.Length;
            Assert.AreEqual(1, actual);

            track = new Track() { StartTime = new DateTime(2012, 3, 2, 3, 1, 0) };
            target.Add(track);

            actual = target.Length;
            Assert.AreEqual(24 * 60 + 3 * 60 + 2, actual);
        }
Пример #5
0
        public TrackCollection GetPlaylistTracks(Playlist playlist, int revision)
        {
            DataSet ds = MakeDataSet("SELECT data FROM [playlist], [users] WHERE [users].[id] = [playlist].[user] AND [playlist].[identifier] = '" + playlist.Identifier + "' AND [users].[identifier] = '" + playlist.User.Identifier + "'");
            String  d  = "";

            try
            {
                d = (String)ds.Tables[0].Rows[0]["data"];
            }
            catch (Exception e)
            {
            }

            String[]        tracks = d.Split('&');
            TrackCollection tc     = new TrackCollection(this, playlist, new List <Track>());

            if (String.IsNullOrEmpty(d))
            {
                return(tc);
            }
            foreach (String strtrack in tracks)
            {
                if (String.IsNullOrEmpty(strtrack))
                {
                    continue;
                }
                Track pt = MakeUserTrackFromString(strtrack);
                tc.Add((Track)pt);
            }
            return(tc);
        }
Пример #6
0
        private TrackCollection LoadTracks()
        {
            TrackCollection tracks = new TrackCollection();

            Track track;
            for (int i = 0; i < 30; i++) {
                track = new Track() { StartTime = new DateTime(2012, 3, 1, 11, i, 0), EndTime = new DateTime(2012, 3, 1, 11, i, 59) };
                tracks.Add(track);
            }

            for (int i = 0; i < 20; i++) {
                track = new Track() { StartTime = new DateTime(2012, 3, 1, 12, 10 + i, 0), EndTime = new DateTime(2012, 3, 1, 12, 10 + i, 59) };
                tracks.Add(track);
            }

            for (int i = 0; i < 20; i++) {
                track = new Track() { StartTime = new DateTime(2012, 3, 1, 13, 11 + i, 0), EndTime = new DateTime(2012, 3, 1, 13, 11 + i, 59) };
                track.TrackType = TrackType.Event;
                tracks.Add(track);
            }

            for (int i = 0; i < 20; i++) {
                track = new Track() { StartTime = new DateTime(2012, 3, 1, 13, 31 + i, 0), EndTime = new DateTime(2012, 3, 1, 13, 31 + i, 59) };
                tracks.Add(track);
            }

            return tracks;
        }
Пример #7
0
 public void AddTrack(List <MusicLibraryViewModel.TrackItem> tracks)
 {
     foreach (MusicLibraryViewModel.TrackItem track in tracks)
     {
         TrackCollection.Add(track);
     }
 }
        public void TestIsPresent()
        {
            var originalCollection = new TrackCollection();

            Assert.IsFalse(originalCollection.IsPresent(_testTrack));
            originalCollection.Add(_testTrack);
            Assert.IsTrue(originalCollection.IsPresent(_testTrack));
        }
Пример #9
0
    public static void PopulateTrackCollection(TrackLayout layout, TrackCollection target)
    {
        target.Clear();
        foreach (TrackSectionSerializer serializedTrack in layout.trackSections)
        {
            TrackSection track = serializedTrack.ToTrackSection();
            if (!target.Add(track, track.index))
            {
                Debug.LogError("Could not add track section to collection at index " + track.index);
            }
        }

        foreach (TrackJunctionSerializer serializedJunction in layout.trackJunctions)
        {
            TrackJunction track = serializedJunction.ToTrackJunction();
            if (!target.Add(track, track.index))
            {
                Debug.LogError("Could not add track junction to collection at index " + track.index);
            }
        }
    }
Пример #10
0
 public CDEntry(CDEntry src)
 {
     m_Discid       = src.m_Discid;
     m_Artist       = src.m_Artist;
     m_Title        = src.m_Title;
     m_Year         = src.m_Year;
     m_Genre        = src.m_Genre;
     m_ExtendedData = src.m_ExtendedData;
     m_PlayOrder    = src.m_PlayOrder;
     m_Tracks       = new TrackCollection();
     foreach (Track tr in src.m_Tracks)
     {
         m_Tracks.Add(new Track(tr));
     }
 }
Пример #11
0
        public TrackCollection LoadTracksForGivenRelease(Release release)
        {
            String sql = "SELECT * FROM track, release, artist WHERE (release.ID = track.album) AND (artist.ID = track.artist) AND (artist.ID = track.artist)  AND " +
                         "release.identifier = '" + release.Identifier + "' ORDER BY trackNumber ASC";
            DataSet         result = MakeDataSet(sql);
            TrackCollection tc     = new TrackCollection(this, release, new List <Track>());

            foreach (DataRow row in result.Tables[0].Rows)
            {
                Track t = TrackFromDataRow(row);
                tc.Add(t);
            }

            return(tc);
        }
Пример #12
0
 public TrackCollection GetCollection(string type, string identifier)
 {
     switch (type)
     {
     case "own":
     {
         TrackCollection TC = new TrackCollection(this, null, new List <Track>());
         DataSet         DS = MakeDataSet("SELECT * FROM track, artist, release, users WHERE release.id = track.album AND track.artist = artist.id AND users.artist = artist.id ORDER BY release.release_date DESC");
         foreach (DataRow dr in DS.Tables[0].Rows)
         {
             Track t = TrackFromDataRow(dr);
             TC.Add(t);
         }
         return(TC);
     }
     }
     return(null);
 }
Пример #13
0
        public TrackCollection LoadTracksForPlaylist(Playlist playlist)
        {
            Thread.Sleep(1000);
            TrackCollection tc = new TrackCollection(this, playlist, new List <Track>());

            for (var i = 0; i < 3; i++)
            {
                Track track = new Track(this)
                {
                    Identifier = "5124525ffs12",
                    Name       = "Test",
                    Artists    = new Artist[] { new Artist(this)
                                                {
                                                    Name = "TestArtist", Identifier = "2FOU"
                                                } }
                };
                tc.Add(track);
            }
            return(tc);
        }
Пример #14
0
        public Track AddTrack(RawTrack track)
        {
            if (track == null)
            {
                throw new ArgumentNullException("track");
            }

            if (_trackDict.ContainsKey(track.FullFilename))
            {
                throw new ArgumentException(track.FullFilename + " is already in library - use Update instead.", "track");
            }

            Artist artist = _artists[track.ArtistName] ?? CreateArtist(track.ArtistName);
            Album  album  = _albums[track.AlbumTitle] ?? CreateAlbum(track.AlbumTitle, track.Year);

            var t = new Track(track, album, artist);

            _tracks.Add(t);
            album.Tracks.Add(t);

            _trackDict.Add(track.FullFilename, t);

            return(t);
        }
Пример #15
0
        public TrackCollection GetPlaylistTracks(Playlist playlist, int revision)
        {
            DataSet ds = MakeDataSet("SELECT data FROM [playlist], [users] WHERE [users].[id] = [playlist].[user] AND [playlist].[identifier] = '" + playlist.Identifier + "' AND [users].[identifier] = '" + playlist.User.Identifier + "'");
            String d = "";
            try
            {
                d = (String)ds.Tables[0].Rows[0]["data"];
            }
            catch (Exception e)
            {
            }

            String[] tracks = d.Split('&');
            TrackCollection tc = new TrackCollection(this, playlist, new List<Track>());
            if (String.IsNullOrEmpty(d))
                return tc;
            foreach (String strtrack in tracks)
            {
                if (String.IsNullOrEmpty(strtrack))
                    continue;
                Track pt = MakeUserTrackFromString(strtrack);
                tc.Add((Track)pt);
            }
            return tc;
        }
Пример #16
0
 // Tracks Collection Manager
 public void AddTrack(MusicLibraryViewModel.TrackItem track)
 {
     TrackCollection.Add(track);
 }
Пример #17
0
    public static void CreateTrackLayout()
    {
        TrackCollection trackCollection = TrackCollection.GetInstance();

        /*
         * TrackSection a = new TrackSection(new WorldPosition(0, 0, 20f, 20f), new WorldRotation(25, false), 750f, true, 90f);
         * trackCollection.Add(a);
         * TrackSection b = a.CreateNext(750f, true, 90f);
         * b = b.CreateNext(750f, true, 90f);
         * b = b.CreateNext(750f, true, 90f);
         *
         * b.NextSectionIndex = a.index;
         * a.PreviousSectionIndex = b.index;
         */



        // Create start section
        TrackSection start = new TrackSection(new WorldPosition(0, 0, 20f, 10f), new WorldRotation(-100.0f, false), 200.0f);

        trackCollection.Add(start);
        TrackSection currentSection = start;

        currentSection = currentSection.CreateNext(100.0f, false, 0.0f);

        // Create a new junction
        TrackJunction junction = new TrackJunction(currentSection.GetPositionOnTrack(currentSection.length), currentSection.GetRotationOnTrack(currentSection.length));

        trackCollection.Add(junction);
        // Attach it to the previous section
        junction.PreviousSectionIndex   = currentSection.index;
        currentSection.NextSectionIndex = junction.index;

        // Create the junction sections
        TrackSection switchSectionCurved = junction.CreateSection(200.0f, true, 90.0f);
        // 127.32395447351626861510701069801
        TrackSection switchSectionStraight = junction.CreateSection(2.0f * 127.32395f, false, 0.0f);

        // Create a loop
        currentSection = switchSectionStraight;
        // NOTE: It's split into two parts because junction sections from the same junction need at least 2 other section before they connect to eachother
        currentSection = currentSection.CreateNext(200.0f, true, 90.0f);
        currentSection = currentSection.CreateNext(400.0f, true, 180.0f);
        // Join it up
        currentSection.NextSectionIndex      = switchSectionCurved.index;
        switchSectionCurved.NextSectionIndex = currentSection.index;

        // Create a new piece of track on the other end of the start piece
        currentSection = new TrackSection(start.position, start.rotation.Oppisite, 20.0f);
        currentSection.PreviousSectionIndex = start.index;
        start.PreviousSectionIndex          = trackCollection.Add(currentSection);

        // Create a new junction
        junction = new TrackJunction(currentSection.GetPositionOnTrack(currentSection.length), currentSection.GetRotationOnTrack(currentSection.length));
        trackCollection.Add(junction);

        // Attach it to the previous section
        junction.PreviousSectionIndex   = currentSection.index;
        currentSection.NextSectionIndex = junction.index;
        // Create the junction sections
        switchSectionCurved = junction.CreateSection(200.0f, true, 90.0f);
        //127.32395447351626861510701069801
        switchSectionStraight = junction.CreateSection(2.0f * 127.32395f, false, 0.0f);

        // Create a loop
        currentSection = switchSectionStraight;
        // NOTE: It's split into two parts because junction sections from the same junction need at least 2 other section before they connect to eachother
        // Add a junction and attach it
        junction = new TrackJunction(currentSection.GetPositionOnTrack(currentSection.length), currentSection.GetRotationOnTrack(currentSection.length));
        trackCollection.Add(junction);

        junction.PreviousSectionIndex   = currentSection.index;
        currentSection.NextSectionIndex = junction.index;
        // Create the curved loop junction section
        currentSection = junction.CreateSection(200.0f, true, 90.0f);
        // Create the straight junction section
        TrackSection branch = junction.CreateSection(200.0f, false, 0.0f);

        // Finish the loop
        currentSection = currentSection.CreateNext(400.0f, true, 180.0f);
        // Join it up
        currentSection.NextSectionIndex      = switchSectionCurved.index;
        switchSectionCurved.NextSectionIndex = currentSection.index;

        branch = branch.CreateNext(400, true, 10);
        branch = branch.CreateNext(100, false, 0);
        branch = branch.CreateNext(500, true, -20);
        branch = branch.CreateNext(1000, false, 0);



        //Save it

        TrackLayout trackLayout = TrackLayout.CreateFromTrackCollection(trackCollection);

        AssetDatabase.CreateAsset(trackLayout, "Assets/Resources/DemoTrackLayout.asset");
        AssetDatabase.SaveAssets();

        EditorUtility.FocusProjectWindow();

        Selection.activeObject = trackLayout;
    }
Пример #18
0
 /// <summary>
 /// Returns a collection containing the tracks with the specified text. 
 /// <para>
 /// If searchFields is ITPlaylistSearchFieldVisible , this is identical to the list of
 /// tracks displayed if the user enters the search text in the Search edit field in
 /// iTunes when this playlist is being displayed.
 /// </para>
 /// </summary>
 /// <param name="searchText">
 /// The text to search for. This string cannot be longer than 255 characters.
 /// </param>
 /// <param name="searchFields">
 /// Specifies which fields of each track should be searched for searchText.
 /// </param>
 /// <returns>
 /// Collection of Track objects. This will be empty if no tracks meet the search
 /// criteria.
 /// </returns>
 public TrackCollection Search(string searchText, ITPlaylistSearchField searchFields)
 {
     return Invoke((Func<TrackCollection>)delegate
     {
         TrackCollection collection = new TrackCollection();
         IITTrackCollection results = playlist.Search(searchText, searchFields);
         if (results != null)
         {
             foreach (IITTrack track in results)
             {
                 if (track != null)
                 {
                     collection.Add(new Track(track));
                 }
             }
         }
         return collection;
     });
 }
Пример #19
0
        /// <summary>
        /// Get a lits of iTunes Tracks given a list of track IDs.
        /// </summary>
        /// <param name="trackIDs"></param>
        /// <returns></returns>
        protected TrackCollection GetTracks(PersistentIDCollection persistentIDs)
        {
            TrackCollection tracks = new TrackCollection();

            foreach (PersistentID persistentID in persistentIDs)
            {
                Track track = controller.LibraryPlaylist.GetTrack(persistentID);
                if (track != null)
                {
                    tracks.Add(track);
                }
            }

            return tracks;
        }
Пример #20
0
 public TrackCollection LoadTracksForPlaylist(Playlist playlist)
 {
     Thread.Sleep(1000);
     TrackCollection tc = new TrackCollection(this, playlist, new List<Track>());
     for (var i = 0; i < 3; i++)
     {
         Track track = new Track(this)
         {
             Identifier = "5124525ffs12",
             Name = "Test",
             Artists = new Artist[] { new Artist(this) { Name = "TestArtist", Identifier = "2FOU" } }
         };
         tc.Add(track);
     }
     return tc;
 }
Пример #21
0
        public TrackCollection LoadTracksForGivenRelease(Release release)
        {
            String sql = "SELECT * FROM track, release, artist WHERE (release.ID = track.album) AND (artist.ID = track.artist) AND (artist.ID = track.artist)  AND " +
                "release.identifier = '" + release.Identifier + "'";
            DataSet result = MakeDataSet(sql);
            TrackCollection tc = new TrackCollection(this, release, new List<Track>());
            foreach (DataRow row in result.Tables[0].Rows)
            {
                Track t = TrackFromDataRow(row);
                tc.Add(t);
            }

            return tc;
        }
Пример #22
0
        private bool Parse(StringCollection data)
        {
            foreach (string line in data)
            {
                // check for comment

                if (line[0] == '#')
                {
                    continue;
                }

                int index = line.IndexOf('=');
                if (index == -1)                 // couldn't find equal sign have no clue what the data is
                {
                    continue;
                }
                string field = line.Substring(0, index);
                index++;                 // move it past the equal sign

                switch (field)
                {
                case "DISCID":
                {
                    discId = line.Substring(index);
                    continue;
                }

                case "DTITLE":                         // artist / title
                {
                    artist += line.Substring(index);
                    continue;
                }

                case "DYEAR":
                {
                    year = line.Substring(index);
                    continue;
                }

                case "DGENRE":
                {
                    genre += line.Substring(index);
                    continue;
                }

                case "EXTD":
                {
                    // may be more than one - just concatenate them
                    extendedData += line.Substring(index);
                    continue;
                }

                case "PLAYORDER":
                {
                    playOrder += line.Substring(index);
                    continue;
                }


                default:

                    //get track info or extended track info
                    if (field.StartsWith("TTITLE"))
                    {
                        int trackNumber = -1;
                        // Parse could throw an exception
                        try
                        {
                            trackNumber = int.Parse(field.Substring("TTITLE".Length));
                        }

                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed to parse track Number. Reason: " + ex.Message);
                            continue;
                        }

                        //may need to concatenate track info
                        if (trackNumber < tracks.Count)
                        {
                            tracks[trackNumber].Title += line.Substring(index);
                        }
                        else
                        {
                            Track track = new Track(line.Substring(index));
                            tracks.Add(track);
                        }
                        continue;
                    }
                    else if (field.StartsWith("EXTT"))
                    {
                        int trackNumber = -1;
                        // Parse could throw an exception
                        try
                        {
                            trackNumber = int.Parse(field.Substring("EXTT".Length));
                        }

                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed to parse track Number. Reason: " + ex.Message);
                            continue;
                        }

                        if (trackNumber < 0 || trackNumber > tracks.Count - 1)
                        {
                            continue;
                        }

                        tracks[trackNumber].ExtendedData += line.Substring(index);
                    }
                    continue;
                }                 //end of switch
            }


            //split the title and artist from DTITLE;
            // see if we have a slash
            int slash = artist.IndexOf(" / ");

            if (slash == -1)
            {
                title = artist;
            }
            else
            {
                string titleArtist = artist;
                artist = titleArtist.Substring(0, slash);
                slash += 3;                 // move past " / "
                title  = titleArtist.Substring(slash);
            }

            return(true);
        }
Пример #23
0
        public TrackCollection GetCollection(string type, string identifier)
        {
            switch (type)
            {
                case "own":
                    TrackCollection TC = new TrackCollection(this, null, new List<Track>());
                    DataSet DS = MakeDataSet("SELECT * FROM track, artist, release, users WHERE release.id = track.album AND track.artist = artist.id AND users.artist = artist.id ORDER BY release.release_date DESC");
                    foreach (DataRow dr in DS.Tables[0].Rows)
                    {
                        Track t = TrackFromDataRow(dr);
                        TC.Add(t);
                    }
                    return TC;

            }
            return null;
        }