Exemple #1
0
        public static void setupPlay(Mp3_Container container)
        {
            if (container.gui.songList.SelectedRows.Count == 0)
            {
                return;
            }
            if (container.songlists.nowPlaying != null && container.songlists.nowPlaying.equals(Create.createSelectedSong(container)))
            {
                SongControl.play_pause(container);
                return;
            }

            if (container.trackers.nowPlayingRow == -1 || (container.trackers.nowPlayingRow != container.gui.songList.SelectedRows[0].Index))
            {
                container.trackers.nowPlayingRow = container.gui.songList.SelectedRows[0].Index;
            }

            if (container.gui.shuffle.Checked)
            {
                SongControl.shuffleSong(container);
            }
            else if (container.gui.songList.SelectedRows.Count == 0)
            {
                DataGridViewRow row = container.gui.songList.Rows[0];
                row.Selected = true;
                if (Miscellaneous.checkNull(row))
                {
                    return;
                }
                container.trackers.nowPlayingRow = row.Index;
            }
            stop(container);
            SongControl.play(container);
            GuiControl.fillLabels(container);
        }
Exemple #2
0
        public static void changePlaylist(Mp3_Container container)
        {
            if (container.gui.playlistList.SelectedNode.IsSelected && container.gui.playlistList.SelectedNode.Nodes.Count == 0)
            {
                List <SongDetails> songListTemp = container.songlists.playlistDictionary[container.gui.playlistList.SelectedNode.Text];
                container.songlists.currentPlaylist.Clear();
                container.songlists.currentPlaylist.AddRange(songListTemp);
                container.gui.songList.Rows.Clear();

                List <DataGridViewRow> rows = new List <DataGridViewRow>();
                foreach (SongDetails song in songListTemp)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(container.gui.songList);
                    row.Cells[0].Value  = 0;
                    row.Cells[1].Value  = song.SongName;
                    row.Cells[2].Value  = song.Length;
                    row.Cells[3].Value  = song.Artist;
                    row.Cells[4].Value  = song.Album;
                    row.Cells[5].Value  = song.Track;
                    row.Cells[6].Value  = song.Year;
                    row.Cells[7].Value  = song.Genre;
                    row.Cells[8].Value  = song.Plays;
                    row.Cells[9].Value  = song.Rating;
                    row.Cells[10].Value = song.Path;
                    rows.Add(row);
                }

                container.gui.songList.Rows.InsertRange(0, rows.ToArray());
                container.labels.playlistLabel.Text = container.gui.playlistList.SelectedNode.Text;
            }
            container.gui.playlistList.SelectedNode = null;
        }
Exemple #3
0
 public static void next(Mp3_Container container)
 {
     stop(container);
     container.gui.songList.SelectedRows[0].Selected = false;
     if (container.gui.shuffle.Checked)
     {
         SongControl.shuffleSong(container);
     }
     else
     {
         container.trackers.nowPlayingRow++;
         if (container.trackers.nowPlayingRow >= container.gui.songList.RowCount && container.gui.repeatAll.Checked)
         {
             container.trackers.nowPlayingRow = 0;
         }
         else if (container.gui.repeat.Checked)
         {
             container.trackers.nowPlayingRow--;
         }
         else if (container.trackers.nowPlayingRow >= container.gui.songList.RowCount && !container.gui.repeatAll.Checked)
         {
             return;
         }
         else
         {
             SongControl.play(container);
         }
     }
     SongControl.play(container);
     if (container.songlists.nowPlaying != null)
     {
         GuiControl.fillLabels(container);
     }
 }
Exemple #4
0
        public static void updateTimer(Mp3_Container container)
        {
            container.trackers.time++;
            container.player.progressBar.Value++;
            if (container.trackers.time.Equals(Miscellaneous.totalTime(container.songlists.nowPlaying.Length)))
            {
                SongControl.stop(container);
                if (container.gui.repeatAll.Checked && (container.trackers.nowPlayingRow == container.gui.songList.RowCount - 1))
                {
                    container.gui.songList.SelectedRows[0].Selected = false;
                    container.gui.songList.Rows[0].Selected         = true;
                }
                else if (container.gui.shuffle.Checked || container.gui.repeat.Checked)
                {
                }
                else
                {
                    container.trackers.nowPlayingRow++;
                    container.gui.songList.SelectedRows[0].Selected = false;
                    container.gui.songList.Rows[container.trackers.nowPlayingRow].Selected = true;
                }
                SongControl.setupPlay(container);
                return;
            }

            container.player.timeLabel.Text = getTimeLabel(container.trackers.time) + " / " + container.songlists.nowPlaying.Length;
        }
Exemple #5
0
 public static bool xmlContainsPlaylist(Mp3_Container container, String playlist)
 {
     bool isFound = false;
     if (container.xmlFile.xml.ChildNodes[1].ChildNodes[0].HasChildNodes)
     {
         foreach (XmlNode xn in container.xmlFile.xml.ChildNodes[1].ChildNodes[0])
         {
             if (xn.HasChildNodes)
             {
                 foreach (XmlNode xcn in xn)
                 {
                     if (xcn.Name.Equals("Song"))
                     {
                         break;
                     }
                     if (xcn.Attributes["name"].Value == playlist)
                     {
                         isFound = true;
                         break;
                     }
                 }
             }
             if (isFound)
             {
                 break;
             }
         }
     }
     return isFound;
 }
Exemple #6
0
 public static bool isPlaylistContained(Mp3_Container container, string playlist)
 {
     foreach (TreeNode xn in container.gui.playlistList.Nodes)
     {
         if (xn.Text.Equals(playlist))
         {
             string name = "";
             if (xn.Nodes.Count == 0)
             {
                 name = "Playlist Name";
             }
             else
             {
                 name = "Playlist Group Name";
             }
             MessageBox.Show(playlist + " has already been added as a " + name,
                             "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
             return true;
         }
         if (xn.Nodes.Count > 0)
         {
             foreach (TreeNode xcn in xn.Nodes)
             {
                 if (xcn.Text.Equals(playlist))
                 {
                     MessageBox.Show(playlist + " has already been added as a Playlist Name",
                                     "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #7
0
 public static void play_pause(Mp3_Container container)
 {
     if (container.trackers.nowPlayingRow < 0)
     {
         return;
     }
     if (container.booleans.isPlaying && !container.booleans.isPaused)
     {
         container.player.wmplayer.controls.pause();
         container.booleans.isPaused  = true;
         container.booleans.isPlaying = false;
         container.player.timer.Stop();
         if (container.songlists.nowPlaying.equals(Create.createSelectedSong(container)))
         {
             GuiControl.changePlayPicture(container);
         }
     }
     else if (!container.booleans.isPlaying && container.booleans.isPaused)
     {
         container.player.wmplayer.controls.play();
         container.booleans.isPaused  = false;
         container.booleans.isPlaying = true;
         container.player.timer.Start();
         if (container.songlists.nowPlaying.equals(Create.createSelectedSong(container)))
         {
             GuiControl.changePlayPicture(container);
         }
     }
 }
Exemple #8
0
        /*******************  Start Up Functions  ***************************************************/

        public Mp3PlayerForm(string user)
        {
            InitializeComponent();

            container = new Mp3_Container();
            setupContainer(user);

            fieldComboBox.SelectedIndex = 0;
        }
Exemple #9
0
        public static SongDetails createAsong(Mp3_Container container, DataGridViewRow row)
        {
            SongDetails song = new SongDetails(row.Cells[1].Value.ToString(), row.Cells[3].Value.ToString(), null,
                                               row.Cells[4].Value.ToString(), row.Cells[7].Value.ToString(), row.Cells[2].Value.ToString(),
                                               int.Parse(row.Cells[9].Value.ToString()), long.Parse(row.Cells[8].Value.ToString()),
                                               row.Cells[10].Value.ToString(), row.Cells[5].Value.ToString(), row.Cells[6].Value.ToString());

            return(song);
        }
Exemple #10
0
 public static void changePlayPicture(Mp3_Container container)
 {
     if ((container.booleans.isPlaying && !container.booleans.isPaused))
     {
         container.buttons.play.BackgroundImage = Mp3.Properties.Resources.pause2;
     }
     else if (container.booleans.isPaused && !container.booleans.isPlaying || (!container.booleans.isPlaying && !container.booleans.isPaused))
     {
         container.buttons.play.BackgroundImage = Mp3.Properties.Resources.play2;
     }
 }
Exemple #11
0
        public static SongDetails createSelectedSong(Mp3_Container container)
        {
            SongDetails song = new SongDetails(container.gui.songList.SelectedRows[0].Cells[1].Value.ToString(),
                                               container.gui.songList.SelectedRows[0].Cells[3].Value.ToString(), null,
                                               container.gui.songList.SelectedRows[0].Cells[4].Value.ToString(), container.gui.songList.SelectedRows[0].Cells[7].Value.ToString(),
                                               container.gui.songList.SelectedRows[0].Cells[2].Value.ToString(),
                                               Convert.ToInt32(container.gui.songList.SelectedRows[0].Cells[9].Value.ToString()),
                                               Convert.ToInt64(container.gui.songList.SelectedRows[0].Cells[8].Value.ToString()), container.gui.songList.SelectedRows[0].Cells[10].Value.ToString(),
                                               container.gui.songList.SelectedRows[0].Cells[5].Value.ToString(), container.gui.songList.SelectedRows[0].Cells[6].Value.ToString());

            return(song);
        }
Exemple #12
0
        public static void previous(Mp3_Container container, MouseEventArgs e)
        {
            if (container.trackers.listPosition == -1)
            {
                return;
            }
            container.trackers.listPosition--;

            if (e.Clicks > 1)
            {
                if (container.trackers.listPosition < 0 && container.gui.repeat.Checked)
                {
                    container.trackers.listPosition  = 0;
                    container.trackers.nowPlayingRow = container.songlists.previousSongsPlaylist.ElementAt(container.trackers.listPosition).Item2;
                }
                else if (container.trackers.listPosition >= 0 && container.gui.repeat.Checked)
                {
                    container.trackers.listPosition++;
                }
                else if (container.trackers.listPosition < 0)
                {
                    stop(container);
                    return;
                }
                container.trackers.nowPlayingRow = container.songlists.previousSongsPlaylist.ElementAt(container.trackers.listPosition).Item2;

                stop(container);
                SongControl.play(container);
            }
            else
            {
                if ((container.trackers.listPosition < 0 && container.gui.repeat.Checked) || container.gui.repeat.Checked || container.player.progressBar.Value >= 3)
                {
                    container.trackers.listPosition++;
                }
                else if (container.trackers.listPosition < 0)
                {
                    stop(container);
                    return;
                }
                container.trackers.nowPlayingRow = container.songlists.previousSongsPlaylist.ElementAt(container.trackers.listPosition).Item2;
                stop(container);
                SongControl.play(container);
            }

            if (container.songlists.nowPlaying != null)
            {
                GuiControl.fillLabels(container);
            }
        }
Exemple #13
0
 public static bool addSong(Mp3_Container container)
 {
     using (OpenFileDialog dlgOpen = new OpenFileDialog())
     {
         dlgOpen.Filter           = "Mp3 File|*.mp3";
         dlgOpen.InitialDirectory = "C:\\";
         if (dlgOpen.ShowDialog() == DialogResult.OK)
         {
             Create.createSong(container, dlgOpen.FileName);
             return(true);
         }
         return(false);
     }
 }
Exemple #14
0
 public static void addPlaylistGroup(Mp3_Container container)
 {
     Mp3.Mp3_Player_and_Controls.AddPlaylistGroup toAdd = new Mp3.Mp3_Player_and_Controls.AddPlaylistGroup();
     if (toAdd.ShowDialog() == DialogResult.OK)
     {
         if (Contains.xmlContainsPlaylistGroup(container, toAdd.getPlaylistName()))
         {
             toAdd.Dispose();
             addPlaylistGroup(container);
             return;
         }
         Load_Save.savePlaylistGroupToXml(container, toAdd.getPlaylistName());
     }
     toAdd.Dispose();
 }
Exemple #15
0
        public static void addPlaylist(Mp3_Container container)
        {
            List <string> comboBoxItems = new List <string>();

            comboBoxItems.Add("");
            foreach (XmlNode xn in container.xmlFile.xml.ChildNodes[1].ChildNodes[0])
            {
                if (!container.songlists.playlistDictionary.ContainsKey(xn.Attributes["name"].Value))
                {
                    comboBoxItems.Add(xn.Attributes["name"].Value);
                }
            }
            Mp3.Mp3_Player_and_Controls.AddPlaylist toAdd = new Mp3.Mp3_Player_and_Controls.AddPlaylist(comboBoxItems);
            if (toAdd.ShowDialog() == DialogResult.OK)
            {
                if (Contains.isPlaylistContained(container, toAdd.getPlaylist()))
                {
                    toAdd.Dispose();
                    addPlaylist(container);
                    return;
                }

                container.gui.playlistList.BeginUpdate();
                if (toAdd.getPlaylistGroup().Equals(""))
                {
                    if (!Contains.xmlContainsPlaylistGroup(container, toAdd.getPlaylist()))
                    {
                        Load_Save.savePlaylistGroupToXml(container, toAdd.getPlaylist());
                    }
                    List <SongDetails> songs = new List <SongDetails>();
                    container.songlists.playlistDictionary.Add(toAdd.getPlaylist(), songs);
                }
                else
                {
                    if (!addSubPlaylist(container, toAdd.getPlaylist(), toAdd.getPlaylistGroup()))
                    {
                        Load_Save.savePlaylistGroupToXml(container, toAdd.getPlaylistGroup());
                        if (!addSubPlaylist(container, toAdd.getPlaylist(), toAdd.getPlaylistGroup()))
                        {
                            MessageBox.Show("Error in adding Playlist to tree see system administrator",
                                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }
                    }
                }
                container.gui.playlistList.EndUpdate();
            }
            toAdd.Dispose();
        }
Exemple #16
0
 public static bool xmlContainsSong(Mp3_Container container, SongDetails song)
 {
     bool isFound = false;
     if (container.xmlFile.xml.ChildNodes[1].ChildNodes[0].ChildNodes[0].HasChildNodes)
     {
         foreach (XmlNode xn in container.xmlFile.xml.ChildNodes[1].ChildNodes[0].ChildNodes[0])
         {
             if (xn.ChildNodes[9].InnerText.Equals(song.Path))
             {
                 isFound = true;
                 break;
             }
         }
     }
     return isFound;
 }
Exemple #17
0
        public static bool addSubPlaylist(Mp3_Container container, string playlist, string playlistGroup)
        {
            bool found = false;

            foreach (TreeNode xn in container.gui.playlistList.Nodes)
            {
                if (xn.Text.Equals(playlistGroup))
                {
                    found = true;
                    xn.Nodes.Add(playlist);
                    Load_Save.savePlaylistToXml(container, playlist, playlistGroup);
                    List <SongDetails> songs = new List <SongDetails>();
                    container.songlists.playlistDictionary.Add(playlist, songs);
                }
            }
            return(found);
        }
Exemple #18
0
 public static void stop(Mp3_Container container)
 {
     container.player.wmplayer.controls.stop();
     container.player.timeLabel.Text = "00:00:00 / 00:00:00";
     container.player.timer.Enabled  = false;
     container.player.timer.Stop();
     container.trackers.time            = 0;
     container.player.progressBar.Value = 0;
     container.booleans.isPlaying       = false;
     container.booleans.isPaused        = false;
     GuiControl.changePlayPicture(container);
     container.songlists.nowPlaying  = null;
     container.labels.songTitle.Text = "";
     container.labels.arist.Text     = "";
     container.labels.album.Text     = "";
     container.labels.genre.Text     = "";
 }
Exemple #19
0
        public static void savePlaylistGroupToXml(Mp3_Container container, string playlistName)
        {
            container.gui.playlistList.BeginUpdate();
            container.gui.playlistList.Nodes.Add(playlistName);
            container.gui.playlistList.EndUpdate();

            if (!Contains.xmlContainsPlaylistGroup(container, playlistName))
            {
                XmlElement parent = container.xmlFile.xml.CreateElement("PlaylistGroupNames");
                parent.SetAttribute("name", playlistName);
                container.xmlFile.xml.ChildNodes[1].ChildNodes[0].AppendChild(parent);

                XmlTextWriter writer = new XmlTextWriter(container.xmlFile.userPath, null);
                writer.Formatting = Formatting.Indented;
                container.xmlFile.xml.Save(writer);
                writer.Close();
            }
        }
Exemple #20
0
 public static bool addFolder(Mp3_Container container)
 {
     using (FolderBrowserDialog dlgOpen = new FolderBrowserDialog())
     {
         dlgOpen.RootFolder = System.Environment.SpecialFolder.Desktop;
         List <string> songs = new List <string>();
         if (dlgOpen.ShowDialog() == DialogResult.OK)
         {
             Miscellaneous.ProcessDirectory(dlgOpen.SelectedPath, songs);
             foreach (string fileName in songs)
             {
                 Create.createSong(container, fileName);
             }
             return(true);
         }
         return(false);
     }
 }
Exemple #21
0
        public static void progressBarUpdate(Mp3_Container container, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                container.player.timer.Stop();
                decimal pos = 0M;
                pos = ((decimal)e.X / (decimal)container.player.progressBar.Width) * container.player.progressBar.Maximum;
                pos = Convert.ToInt32(pos);

                if (pos >= container.player.progressBar.Minimum && pos <= container.player.progressBar.Maximum)
                {
                    container.player.progressBar.Value = (int)pos;
                    container.trackers.time            = container.player.progressBar.Value;
                    container.player.timeLabel.Text    = getTimeLabel(container.trackers.time) + " / " + container.songlists.nowPlaying.Length;
                    container.player.wmplayer.controls.currentPosition = (double)container.trackers.time;
                }
                container.player.timer.Start();
            }
        }
Exemple #22
0
        public static void play(Mp3_Container container)
        {
            DataGridViewRow row = container.gui.songList.Rows[container.trackers.nowPlayingRow];

            if (Miscellaneous.checkNull(row))
            {
                return;
            }
            container.gui.songList.CurrentCell = container.gui.songList[1, row.Index];
            row.Selected = true;
            container.songlists.nowPlaying = Create.createAsong(container, row);

            if (container.trackers.listPosition != -1)
            {
                if (container.songlists.previousSongsPlaylist.ElementAt(container.trackers.listPosition).Item1.equals(container.songlists.nowPlaying))
                {
                }
                else
                {
                    container.trackers.listPosition++;
                    container.songlists.previousSongsPlaylist.Add(new Tuple <SongDetails, int>(container.songlists.nowPlaying, row.Index));
                }
            }
            else
            {
                container.trackers.listPosition++;
                container.songlists.previousSongsPlaylist.Add(new Tuple <SongDetails, int>(container.songlists.nowPlaying, row.Index));
            }

            container.player.wmplayer.URL        = container.songlists.nowPlaying.Path;
            container.player.timeLabel.Text      = "00:00:00 / " + container.songlists.nowPlaying.Length;
            container.player.progressBar.Maximum = Miscellaneous.totalTime(container.songlists.nowPlaying.Length);
            container.player.progressBar.Value   = 0;
            container.player.timer.Enabled       = false;
            container.player.timer.Stop();
            container.player.wmplayer.controls.play();
            container.player.timer.Enabled = true;
            container.player.timer.Start();
            container.booleans.isPlaying = true;
            container.booleans.isPaused  = false;
            GuiControl.changePlayPicture(container);
        }
Exemple #23
0
        public static void setupSearch(Mp3_Container container)
        {
            container.songlists.searchList.Clear();
            Tuple <String, int> field = null;

            switch (container.gui.searchFieldComboBox.SelectedItem.ToString())
            {
            case "Song Name":
                field = container.positionVariables.NAME;
                break;

            case "Length":
                field = container.positionVariables.LENGTH;
                break;

            case "Artist":
                field = container.positionVariables.ARTIST;
                break;

            case "Album":
                field = container.positionVariables.ALBUM;
                break;

            case "Genre":
                field = container.positionVariables.GENRE;
                break;

            case "Plays":
                field = container.positionVariables.PLAYS;
                break;

            case "Rating":
                field = container.positionVariables.RATING;
                break;

            case "Year":
                field = container.positionVariables.YEAR;
                break;
            }

            search(container, field);
        }
Exemple #24
0
        public static bool songListContains(Mp3_Container container, SongDetails song)
        {
            bool isFound = false;
            foreach (DataGridViewRow row in container.gui.songList.Rows)
            {
                if (row.Cells[0].Value == null && row.Cells[1].Value == null && row.Cells[2].Value == null &&
                    row.Cells[3].Value == null && row.Cells[4].Value == null && row.Cells[5].Value == null &&
                    row.Cells[6].Value == null && row.Cells[7].Value == null && row.Cells[8].Value == null)
                {
                    break;
                }
                if (row.Cells[1].Value.ToString() == song.SongName && row.Cells[2].Value.ToString() == song.Length && row.Cells[3].Value.ToString() == song.Artist && row.Cells[4].Value.ToString() == song.Genre)
                {
                    isFound = true;
                    break;
                }
            }

            return isFound;
        }
Exemple #25
0
        public static void savePlaylistToXml(Mp3_Container container, string playlist, string playlistGroup)
        {
            if (!Contains.xmlContainsPlaylist(container, playlist))
            {
                foreach (XmlNode xcn in container.xmlFile.xml.ChildNodes[1].ChildNodes[0])
                {
                    if (xcn.Attributes["name"].Value.Equals(playlistGroup))
                    {
                        XmlElement child = container.xmlFile.xml.CreateElement("Playlist");
                        child.SetAttribute("name", playlist);
                        xcn.AppendChild(child);

                        XmlTextWriter writer = new XmlTextWriter(container.xmlFile.userPath, null);
                        writer.Formatting = Formatting.Indented;
                        container.xmlFile.xml.Save(writer);
                        writer.Close();
                    }
                }
            }
        }
Exemple #26
0
        public static void shuffleSong(Mp3_Container container)
        {
            int    rowCount  = container.gui.songList.Rows.Count - 1;
            Random rand      = new Random();
            int    rowChoice = container.trackers.nowPlayingRow;

            while (rowChoice == container.trackers.nowPlayingRow)
            {
                rowChoice = rand.Next() % rowCount;
            }
            DataGridViewRow row = container.gui.songList.Rows[rowChoice];

            row.Selected = true;
            if (row.Cells[0].Value == null && row.Cells[1].Value == null && row.Cells[2].Value == null &&
                row.Cells[3].Value == null && row.Cells[4].Value == null && row.Cells[5].Value == null &&
                row.Cells[6].Value == null && row.Cells[7].Value == null && row.Cells[8].Value == null)
            {
                return;
            }
            container.trackers.nowPlayingRow = row.Index;
        }
Exemple #27
0
        public static void ratingDescending(Mp3_Container container)
        {
            container.gui.sortOptions.ratingDescending.Checked = true;

            container.gui.sortOptions.nameAscending.Checked    = false;
            container.gui.sortOptions.nameDescending.Checked   = false;
            container.gui.sortOptions.lengthAscending.Checked  = false;
            container.gui.sortOptions.lengthDescending.Checked = false;
            container.gui.sortOptions.artistAscending.Checked  = false;
            container.gui.sortOptions.artistDescending.Checked = false;
            container.gui.sortOptions.albumAscending.Checked   = false;
            container.gui.sortOptions.albumDescending.Checked  = false;
            container.gui.sortOptions.yearAscending.Checked    = false;
            container.gui.sortOptions.yearDescending.Checked   = false;
            container.gui.sortOptions.genreAscending.Checked   = false;
            container.gui.sortOptions.genreDescending.Checked  = false;
            container.gui.sortOptions.playsAscending.Checked   = false;
            container.gui.sortOptions.playsDescending.Checked  = false;
            container.gui.sortOptions.ratingAscending.Checked  = false;

            GuiControl.sort(container, "Rating");
        }
Exemple #28
0
 public static void deleteSong(Mp3_Container container)
 {
     if (MessageBox.Show("Are you sure you want to delete " + container.gui.songList.SelectedRows[0].Cells[1].Value.ToString() + " by " +
                         container.gui.songList.SelectedRows[0].Cells[3].Value.ToString() + "?", "Delete Song",
                         MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                         MessageBoxDefaultButton.Button1) == DialogResult.Yes)
     {
         if (container.xmlFile.xml.ChildNodes[1].ChildNodes[1].HasChildNodes)
         {
             foreach (XmlNode xn in container.xmlFile.xml.ChildNodes[1].ChildNodes[1])
             {
                 if (xn.ChildNodes[9].InnerText.Equals(container.gui.songList.SelectedRows[0].Cells[10].Value.ToString()))
                 {
                     container.xmlFile.xml.ChildNodes[1].ChildNodes[1].RemoveChild(xn);
                     int rowIndex = container.gui.songList.SelectedRows[0].Index;
                     container.gui.songList.SelectedRows[0].Selected = false;
                     container.gui.songList.Rows.RemoveAt(rowIndex);
                     break;
                 }
             }
         }
         container.xmlFile.xml.Save(container.xmlFile.userPath);
     }
 }
Exemple #29
0
        public static void createSong(Mp3_Container container, String file)
        {
            TagLib.File f = TagLib.File.Create(file);
            SongDetails song;

            if (f.Tag.Performers.Length == 0)
            {
                song = new SongDetails(f.Tag.Title, f.Tag.AlbumArtists[0], null,
                                       f.Tag.Album, f.Tag.Genres[0], f.Properties.Duration.ToString(),
                                       0, 0, file, f.Tag.Track.ToString(), f.Tag.Year.ToString());
            }
            else
            {
                song = new SongDetails(f.Tag.Title, f.Tag.AlbumArtists[0], f.Tag.
                                       Performers,
                                       f.Tag.Album, f.Tag.Genres[0], f.Properties.Duration.ToString(),
                                       0, 0, file, f.Tag.Track.ToString(), f.Tag.Year.ToString());
            }

            if (!Contains.xmlContainsSong(container, song))
            {
                container.gui.songList.Rows.Insert(0, 0, song.SongName, song.Length, song.Artist, song.Album, song.Track, song.Year, song.Genre, song.Plays, song.Rating, song.Path);
                container.songlists.masterSongList.Add(song);
                container.songlists.currentPlaylist.Add(song);

                XmlElement parent = container.xmlFile.xml.CreateElement("Song");

                XmlElement userElem = container.xmlFile.xml.CreateElement("name");
                XmlText    text     = container.xmlFile.xml.CreateTextNode(song.SongName);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("artist");
                text     = container.xmlFile.xml.CreateTextNode(song.Artist);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("album");
                text     = container.xmlFile.xml.CreateTextNode(song.Album);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("track");
                text     = container.xmlFile.xml.CreateTextNode(song.Track);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("year");
                text     = container.xmlFile.xml.CreateTextNode(song.Year);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("genre");
                text     = container.xmlFile.xml.CreateTextNode(song.Genre);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("length");
                text     = container.xmlFile.xml.CreateTextNode(song.Length);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("rating");
                text     = container.xmlFile.xml.CreateTextNode(song.Rating.ToString());
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("plays");
                text     = container.xmlFile.xml.CreateTextNode(song.Plays.ToString());
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                userElem = container.xmlFile.xml.CreateElement("path");
                text     = container.xmlFile.xml.CreateTextNode(song.Path);
                parent.AppendChild(userElem);
                parent.LastChild.AppendChild(text);

                container.xmlFile.xml.ChildNodes[1].ChildNodes[0].ChildNodes[0].AppendChild(parent);

                XmlTextWriter writer = new XmlTextWriter(container.xmlFile.userPath, null);
                writer.Formatting = Formatting.Indented;
                container.xmlFile.xml.Save(writer);
                writer.Close();
            }
            else
            {
                MessageBox.Show("The Song" + '\n' + file + '\n' + "has already been added", "Song has been added");
            }
            GuiControl.sort(container, container.trackers.lastSortParam);
        }
Exemple #30
0
        public static void sort(Mp3_Container container, string value)
        {
            container.trackers.lastSortParam = value;
            switch (value)
            {
            case "Name":
                if (container.gui.sortOptions.nameAscending.Checked)
                {
                    container.gui.songList.Sort(new NameComparer(SortOrder.Ascending));
                }
                else if (container.gui.sortOptions.nameDescending.Checked)
                {
                    container.gui.songList.Sort(new NameComparer(SortOrder.Descending));
                }
                break;

            case "Length":
                if (container.gui.sortOptions.lengthAscending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Ascending, 2));
                }
                else if (container.gui.sortOptions.lengthDescending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Descending, 2));
                }
                break;

            case "Artist":
                if (container.gui.sortOptions.artistAscending.Checked)
                {
                    container.gui.songList.Sort(new ArtistComparer(SortOrder.Ascending));
                }
                else if (container.gui.sortOptions.artistDescending.Checked)
                {
                    container.gui.songList.Sort(new ArtistComparer(SortOrder.Descending));
                }
                break;

            case "Album":
                if (container.gui.sortOptions.albumAscending.Checked)
                {
                    container.gui.songList.Sort(new AlbumComparer(SortOrder.Ascending));
                }
                else if (container.gui.sortOptions.albumDescending.Checked)
                {
                    container.gui.songList.Sort(new AlbumComparer(SortOrder.Descending));
                }
                break;

            case "Year":
                if (container.gui.sortOptions.yearAscending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Ascending, 6));
                }
                else if (container.gui.sortOptions.yearDescending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Descending, 6));
                }
                break;

            case "Genre":
                if (container.gui.sortOptions.genreAscending.Checked)
                {
                    container.gui.songList.Sort(new GenreComparer(SortOrder.Ascending));
                }
                else if (container.gui.sortOptions.genreDescending.Checked)
                {
                    container.gui.songList.Sort(new GenreComparer(SortOrder.Descending));
                }
                break;

            case "Plays":
                if (container.gui.sortOptions.playsAscending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Ascending, 8));
                }
                else if (container.gui.sortOptions.playsDescending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Descending, 8));
                }
                break;

            case "Rating":
                if (container.gui.sortOptions.ratingAscending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Ascending, 9));
                }
                else if (container.gui.sortOptions.ratingDescending.Checked)
                {
                    container.gui.songList.Sort(new PositionComparer(SortOrder.Descending, 9));
                }
                break;
            }
        }