Exemple #1
0
        private int AddSong(int songId)
        {
            // Keep queue trimmed
            if (LookupMap.Count >= MAX_QUEUE_SIZE)
            {
                PlayQueueEntryModel head = null;

                if (PlaybackQueue.Count > 0)
                {
                    head = PlaybackQueue.First();
                }

                if (head != null)
                {
                    if (CurrentPlaybackQueueEntryId == head.RowId)
                    {
                        // TODO: #6 raise alert about queue being full
                        return(-1);
                    }
                    else
                    {
                        RemoveEntry(head.RowId);
                    }
                }
            }

            PlayQueueEntryModel currentTail = null;

            if (PlaybackQueue.Count > 0)
            {
                currentTail = PlaybackQueue.Last();
            }

            PlayQueueEntryTable newPlayQueueEntry;

            if (currentTail == null)
            {
                newPlayQueueEntry = new PlayQueueEntryTable(songId, 0, 0);

                DatabaseManager.Current.AddPlayQueueEntry(newPlayQueueEntry);
            }
            else
            {
                newPlayQueueEntry = new PlayQueueEntryTable(songId, 0, currentTail.RowId);

                DatabaseManager.Current.AddPlayQueueEntry(newPlayQueueEntry);

                currentTail.NextId = newPlayQueueEntry.RowId;
            }

            PlayQueueEntryModel newEntry = new PlayQueueEntryModel(newPlayQueueEntry);

            LookupMap.Add(newEntry.RowId, newEntry);
            PlaybackQueue.Add(newEntry);

            NotifyPropertyChanged(Properties.NextTrack);
            NotifyPropertyChanged(Properties.PrevTrack);

            return(newEntry.RowId);
        }
Exemple #2
0
        public void ResetPlayerToStart()
        {
            if (PlaybackQueue.Count > 0)
            {
                PlayQueueEntryModel playQueueEntry = PlaybackQueue.First();

                CurrentPlaybackQueueEntryId = playQueueEntry.RowId;
            }
        }
Exemple #3
0
        public void MoveSong(int oldIndex, int newIndex)
        {
            if (oldIndex == newIndex)
            {
                return;
            }

            PlayQueueEntryModel songToMove = PlaybackQueue[oldIndex];
            PlayQueueEntryModel target     = null;

            if (newIndex > 0)
            {
                if (newIndex < oldIndex)
                {
                    target = PlaybackQueue[newIndex - 1];
                }
                else
                {
                    target = PlaybackQueue[newIndex];
                }
            }

            // Remove from old spot
            PlayQueueEntryModel previousModel = null;

            if (LookupMap.TryGetValue(songToMove.PrevId, out previousModel))
            {
                previousModel.NextId = songToMove.NextId;
            }

            PlayQueueEntryModel nextModel = null;

            if (LookupMap.TryGetValue(songToMove.NextId, out nextModel))
            {
                nextModel.PrevId = songToMove.PrevId;
            }

            // Insert after new spot
            if (target == null)
            {
                PlayQueueEntryModel head = null;

                if (PlaybackQueue.Count > 0)
                {
                    head = PlaybackQueue.First();
                }

                if (head != null)
                {
                    songToMove.NextId = head.RowId;
                    head.PrevId       = songToMove.RowId;
                    songToMove.PrevId = 0;
                }
                else
                {
                    // Should be redundant
                    songToMove.NextId = 0;
                    songToMove.PrevId = 0;
                }
            }
            else
            {
                PlayQueueEntryModel newNextModel = null;

                if (LookupMap.TryGetValue(target.NextId, out newNextModel))
                {
                    newNextModel.PrevId = songToMove.RowId;
                }

                songToMove.NextId = target.NextId;
                target.NextId     = songToMove.RowId;
                songToMove.PrevId = target.RowId;
            }

            PlaybackQueue.Move(oldIndex, newIndex);

            NotifyPropertyChanged(Properties.NextTrack);
            NotifyPropertyChanged(Properties.PrevTrack);
        }