Esempio n. 1
0
        public void Add(Song song)
        {
            if (song == null)
                return;

            songs.Add(song);
            Sorting.AddSongToSortDictionaries(song, this.sortDictionaries);
        }
Esempio n. 2
0
        public SongPropertiesWindow(MainForm mainForm, Song song, int clickedIndex, PlaylistBase currentPlaylist, Library library)
        {
            this.mainForm = mainForm;
            this.song = song;
            this.currentIndex = clickedIndex;
            this.currentPlaylist = currentPlaylist;
            this.library = library;

            InitializeComponent();
        }
Esempio n. 3
0
        private void AddSongsToLibrary(Library lib)
        {
            var song = new Song(@"Songs\empty10sec.mp3");
            song.Rating = 3;
            lib.Add(song);

            song = new Song(@"Songs\empty10sec2.mp3");
            song.Rating = 1;
            lib.Add(song);
        }
Esempio n. 4
0
 public void SongLoad()
 {
     try
     {
         Song s = new Song(@"Songs\empty10sec.mp3");
     }
     catch
     {
         Assert.Fail();
     }
 }
Esempio n. 5
0
        public override void UpdateSongInfo(Song song)
        {
            RemoveFromSortDictionaries(song);

            bool allowed = Filters.All(f => f.Allowed(song));

            if (!allowed)
                songs.Remove(song);
            else
            {
                if (!songs.Contains(song))
                    songs.Add(song);
                Sorting.AddSongToSortDictionaries(song, this.sortDictionaries);
            }
        }
Esempio n. 6
0
        public void SongTag()
        {
            string titleExpected = "empty10sec - 1";
            string artistExpected = "artist";
            string albumExpected = "album";
            string genreExpected = "noise";
            int trackNumberExpected = 1;
            int discNumberExpected = 1;

            Song s = new Song(@"Songs\empty10sec.mp3");

            Assert.AreEqual(s.Title, titleExpected);
            Assert.AreEqual(s.Artist, artistExpected);
            Assert.AreEqual(s.Album, albumExpected);
            Assert.AreEqual(s.Genre, genreExpected);
            Assert.AreEqual(s.TrackNumber, trackNumberExpected);
            Assert.AreEqual(s.DiscNumber, discNumberExpected);
        }
Esempio n. 7
0
        public void SongReload()
        {
            Song s = null;
            try
            {
                s = new Song(@"Songs\empty10sec.mp3");
            }
            catch
            {
                Assert.Fail("Load fail");
            }

            try
            {
                s.ReloadTags();
            }
            catch
            {
                Assert.Fail("Reload fail");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Interval in ms
        /// </summary>
        /// <param name="song"></param>
        /// <param name="interval"></param>
        private SongInfoPopup(Song song, Image albumArt, int interval)
        {
            InitializeComponent();

            Screen currentScreen = Screen.PrimaryScreen;
            this.Left = currentScreen.WorkingArea.Right - this.Width;
            this.Top = currentScreen.WorkingArea.Bottom - this.Height;

            title_label.Text = song.Title;
            artist_label.Text = song.Artist;
            album_label.Text = song.Album;
            length_label.Text = song.LengthString;
            rating_label.Text = song.RatingString;
            pictureBox1.Image = albumArt;

            this.Show();

            popupTimer = new Timer();
            popupTimer.Interval = interval;
            popupTimer.Tick += popupTimer_Tick;
            popupTimer.Start();
        }
Esempio n. 9
0
        private void GetNextOrPrevious(bool getNext)
        {
            //Index juggling required as GetNext() and GetPrevious() increments playing playlist index
            //The methods also jump to the beginning/end of a playlist if you pass the end/beginning
            //So this way is probably more convenient
            int oldIndex = currentPlaylist.CurrentIndex;
            currentPlaylist.CurrentIndex = this.currentIndex;

            if (getNext)
                song = currentPlaylist.GetNext();
            else
                song = currentPlaylist.GetPrevious();

            this.currentIndex = currentPlaylist.CurrentIndex;
            currentPlaylist.CurrentIndex = oldIndex;
        }
Esempio n. 10
0
 /// <summary>
 /// Removes one song from a dictionary
 /// </summary>
 /// <param name="dictionary"></param>
 /// <param name="field"></param>
 /// <param name="song"></param>
 private static void RemoveSongFromFieldDictionary(Dictionary <string, List <Song> > dictionary, string field, Song song)
 {
     if (dictionary.ContainsKey(song[field]))
     {
         dictionary[song[field]].Remove(song);
         if (dictionary[song[field]].Count == 0)
         {
             dictionary.Remove(song[field]);
         }
     }
 }
Esempio n. 11
0
 private void OnSongChanged(Song song)
 {
     if (SongChanged != null)
         SongChanged(this, new SongChangedEventArgs(song));
 }
Esempio n. 12
0
 protected void RemoveFromSortDictionaries(Song song)
 {
     foreach (Dictionary<string, List<Song>> dictionary in this.sortDictionaries)
         foreach (List<Song> list in dictionary.Values)
             if (list.Contains(song))
                 list.Remove(song);
 }
Esempio n. 13
0
        private void PlaySong(Song song, PlaylistBase inPlaylist)
        {
            searchBarTimer.Stop();
            musicPlayer.Stop();
            musicPlayer.Volume = 0;

            // Check Last.fm scrobbling requirements
            if (currentSongTimePlayed.Ticks > 0.8 * musicPlayer.Length.Ticks ||
                currentSongTimePlayed.TotalMinutes > 4)
            {
                currentSongTimePlayed = TimeSpan.Zero;
                currentlyPlaying.LastPlayed = DateTime.Now;
                currentlyPlaying.PlayCount++;

                if (settings.ScrobblingEnabled)
                    if (currentlyPlaying.Length.TotalSeconds > 30)
                        lfmHandler.ScrobbleSong(currentlyPlaying);

                RefreshSongGridView();
            }

            if (!ReloadSong(song))
                return;

            ResetSearchBarTimer();
            searchBarTimer.Stop();

            try
            {
                 musicPlayer.Open(song.Path);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Play music exception: " + ex.ToString());
            }

            this.currentlyPlaying = song;
            this.playingPlaylist = inPlaylist;

            UpdateTrayIconText();
            UpdateSongImage();
            UpdateSongLengthLabel();
            UpdateSongInfoLabel();

            if (inPlaylist == shuffleQueue)
            {
                shuffleQueue.Populate();

                if (showingPlaylist == shuffleQueue)
                    UpdateShowingPlaylist();
            }

            // Saves changed from tag editing when song is not playing any more
            if (songToSave != null &&
                songToSave.Path != currentlyPlaying.Path)
            {
                songToSave.Save();
                songToSave = null;
            }

            // Show song popup according to settings
            if (settings.PopupOnSongChange)
                ShowCurrentSongPopup();

            inPlaylist.Save();
        }
Esempio n. 14
0
 private void UpdateSong(Song song)
 {
     foreach (PlaylistBase pl in playlists)
         pl.UpdateSongInfo(song);
 }
Esempio n. 15
0
 private void RateSong(Song s, int rating)
 {
     s.Rating = rating;
     library.UpdateSongInfo(currentlyPlaying);
     UpdateSong(s);
     RefreshSongGridView();
     if (showingPlaylist.GetType() == typeof(FilterPlaylist))
         UpdateShowingPlaylist();
 }
Esempio n. 16
0
 public SavePlayingSongEventArgs(Song savingSong)
     : base()
 {
     SavingSong = savingSong;
 }
Esempio n. 17
0
 /// <summary>
 /// Time in ms
 /// </summary>
 /// <param name="s"></param>
 /// <param name="time"></param>
 public static void ShowPopup(Song s, Image albumArt, int time)
 {
     SongInfoPopup popup = new SongInfoPopup(s, albumArt, time);
 }
Esempio n. 18
0
        private static void AddSongsToLibrary(Library lib)
        {
            var song = new Song(@"Songs\empty10sec.mp3");
            song.Rating = 3;
            song.DateAdded = DateTime.Now.AddDays(-1);
            lib.Add(song);

            song = new Song(@"Songs\empty10sec2.mp3");
            song.DateAdded = DateTime.Now.AddDays(-8);
            lib.Add(song);

            song = new Song(@"Songs\empty10sec3.mp3");
            song.DateAdded = DateTime.Now.AddMonths(-3);
            song.Rating = 5;
            lib.Add(song);
        }
Esempio n. 19
0
 public SongChangedEventArgs(Song changedSong)
     : base()
 {
     ChangedSong = changedSong;
 }
Esempio n. 20
0
 public override void Add(string path)
 {
     Song newSong = null;
     try
     {
         newSong = new Song(path);
     }
     catch
     {
         MessageBox.Show("File read error");
     }
     if (newSong != null)
         Add(newSong);
 }
Esempio n. 21
0
 private void popup_SavePlayingSong(object sender, SavePlayingSongEventArgs e)
 {
     songToSave = e.SavingSong;
 }
Esempio n. 22
0
 public void Add(Song song)
 {
     if (song != null)
         if (!pathDictionary.ContainsKey(song.Path))
         {
             songs.Add(song);
             this.pathDictionary.Add(song.Path, song);
             Sorting.AddSongToSortDictionaries(song, sortDictionaries);
             NotifyChanged();
         }
 }
Esempio n. 23
0
 /// <summary>
 /// True if reaload was successful
 /// </summary>
 /// <param name="song"></param>
 /// <returns></returns>
 private bool ReloadSong(Song song)
 {
     try
     {
         this.currentAlbumArt = song.ReloadAndGetImage();
         UpdateSong(song);
     }
     catch (SongReadException ex)
     {
         OnSongReadException(ex, song);
         return false;
     }
     return true;
 }
Esempio n. 24
0
 public void Remove(Song song)
 {
     Remove(song.Path);
 }
Esempio n. 25
0
 private void OnSongReadException(SongReadException ex, Song song)
 {
     MessageBox.Show("Song at " + song.Path +
         " could not be read and will be removed from the library.");
     library.Remove(song);
 }
Esempio n. 26
0
        public override void UpdateSongInfo(Song song)
        {
            //Remove from all dictionaries
            foreach (Dictionary<string, List<Song>> dictionary in this.sortDictionaries)
                foreach (List<Song> list in dictionary.Values)
                    if (list.Contains(song))
                        list.Remove(song);

            Sorting.AddSongToSortDictionaries(song, this.sortDictionaries);
        }
Esempio n. 27
0
 public void ScrobbleSong(Song song)
 {
     scrobbleQueue.Add(new Scrobble(song.Artist, song.Album, song.Title, song.LastPlayed));
     StartWorker();
 }
Esempio n. 28
0
        private void addFilesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            List<string> musicFiles = e.Argument as List<string>;
            int count = 0;
            foreach (string fileName in musicFiles)
            {
                if (!Exists(fileName))
                {
                    Song newSong;
                    try
                    {
                        newSong = new Song(fileName);
                    }
                    catch
                    {
                        newSong = null;
                        this.invalidSongPaths.Add(fileName);
                    }

                    if (newSong != null)
                    {
                        this.newSongs.Add(newSong);
                        if (count % 50 == 0)
                            worker.ReportProgress((int)(100 * count / musicFiles.Count));
                    }
                }
                count++;
            }

            worker.ReportProgress(100);
        }
Esempio n. 29
0
 private void OnSavePlayingSong(Song song)
 {
     if (SavePlayingSong != null)
         SavePlayingSong(this, new SavePlayingSongEventArgs(song));
 }
Esempio n. 30
0
 public abstract void UpdateSongInfo(Song song);
Esempio n. 31
0
        private void SaveSong(Song song)
        {
            if (this.saveProperties["Title"])
                song.Title = this.title_box.Text;
            if (this.saveProperties["Artist"])
                song.Artist = this.artist_box.Text;
            if (this.saveProperties["Album"])
                song.Album = this.album_box.Text;
            if (this.saveProperties["Track Number"])
                song.TrackNumber = Convert.ToInt32(this.tracknr_box.Text);
            if (this.saveProperties["Disc Number"])
                song.DiscNumber = Convert.ToInt32(this.discnr_box.Text);
            if (this.saveProperties["Genre"])
                song.Genre = this.genre_box.Text;
            if (this.saveProperties["Rating"])
                song.Rating = (int)this.rating_numupdownstring.Value;

            if (song != this.mainForm.CurrentlyPlaying)
                song.Save();
            else
                OnSavePlayingSong(song);

            OnSongChanged(song);

            this.library.UpdateSongInfo(song);
        }
Esempio n. 32
0
 /// <summary>
 /// Adds a single song to one of the dictionaries.
 /// </summary>
 /// <param name="dictionary"></param>
 /// <param name="field"></param>
 /// <param name="song"></param>
 private static void AddSongToFieldDictionary(Dictionary <string, List <Song> > dictionary, string field, Song song)
 {
     if (song[field] != null && dictionary.ContainsKey(song[field]))
     {
         dictionary[song[field]].Add(song);
     }
     else
     {
         var newEntry = new List <Song>();
         newEntry.Add(song);
         if (song[field] != null)
         {
             dictionary.Add(song[field], newEntry);
         }
     }
 }