Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten.zip
BSE.Platten
BSE.Platten.vssscc
mssccprj.scc
vssver2.scc
BSE.CoverFlow.WPFLib
BSE.CoverFlow.WPFLib.csproj.user
BSE.CoverFlow.WPFLib.csproj.vspscc
mssccprj.scc
vssver2.scc
Images
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp
BSE.Platten.Admin.WinApp.csproj.user
BSE.Platten.Admin.WinApp.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
BSEadmin.ico
vssver2.scc
BSE.Platten.Audio
bse.ico
BSE.Platten.Audio.csproj.vspscc
mssccprj.scc
vssver2.scc
Options
vssver2.scc
Player
vssver2.scc
Properties
vssver2.scc
Resources
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
WinControls
vssver2.scc
WMFSDK
vssver2.scc
BSE.Platten.BO
BSE.Platten.BO.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Common
BSE.Platten.Common.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers
BSE.Platten.Covers.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
BSE.Platten.FreeDb
BSE.Platten.FreeDb.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
vssver2.scc
BSE.Platten.Ripper
BSE.Platten.Ripper.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik
BSE.Platten.Statistik.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Tunes
BSE.Platten.Tunes.csproj.user
BSE.Platten.Tunes.csproj.vspscc
mssccprj.scc
vssver2.scc
Filters
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup
BSEadminSetup.vdproj
BSEadminSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
BSEtunesSetup
BSEtunesSetup.vdproj
BSEtunesSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
dll
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.Windows.Forms.DLL
Lame
lame_enc.dll
vssver2.scc
lame-3.97
BSE.Platten_en.zip
BSE.CoverFlow.WPFLib.csproj.user
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Settings.settings
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
Settings.settings
vssver2.scc
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp.csproj.user
Settings.settings
vssver2.scc
BSEadmin.ico
vssver2.scc
bse.ico
BSE.Platten.Audio.csproj.user
vssver2.scc
vssver2.scc
vssver2.scc
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.BO.csproj.user
vssver2.scc
BSE.Platten.Common.csproj.user
vssver2.scc
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers.csproj.user
Settings.settings
vssver2.scc
BSE.Platten.FreeDb.csproj.user
vssver2.scc
OpenCD.png
vssver2.scc
AudioWriter
vssver2.scc
BSE.Platten.Ripper.csproj.user
Lame
vssver2.scc
vssver2.scc
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik.csproj.user
vssver2.scc
BSE.Platten.Tunes.csproj.user
vssver2.scc
Settings.settings
vssver2.scc
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup.vdproj
BSEtunesSetup.vdproj
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.ThreadedShell.DLL
BSE.Windows.Forms.DLL
lame_enc.dll
MySQL.chm.zip
MySQL.chm
MySqlCreateDataBase5x.sql.zip
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.IO;
using BSE.CoverFlow.WPFLib.Properties;
using System.Windows.Media.Media3D;
using System.Windows.Threading;
using System.Windows.Resources;
using BSE.Platten.Audio;
using BSE.Platten.BO;
using System.Globalization;

namespace BSE.CoverFlow.WPFLib
{
    /// <summary>
    /// Interaction logic for CoverFlow.xaml
    /// </summary>
    public partial class CoverFlowItem : UserControl
    {
        #region Delegates
        /// <summary>
        /// Occurs when the close button on coverflow is clicked. 
        /// </summary>
        public event EventHandler<EventArgs> CloseClick;
        private delegate void ViewStatePlayerPlaysHandler(PlayMode eMode);
        private delegate void ViewStatePlayerPausedHandler(PlayMode eMode);
        private delegate void ViewStatePlayerStoppedHandler(PlayMode eMode);
        private delegate void ViewStatePlayerTrackChangedHandler(PlayMode eMode);
        #endregion

        #region Constants
        #endregion

        #region FieldsPrivate
        private List<CoverItem> m_listCoverFlowItems;
        private Collection<int> m_coverFlowCollection;
        private Queue<CoverItem> m_removeableCoverFlowItems = new Queue<CoverItem>();
        private Queue<CTrack> m_tracksToSelect = new Queue<CTrack>();
        //private int m_iVisibleCoversPerSide = 6;
        private int m_iVisibleCoversPerSide = 4;
        private ImageSource m_defaultImageSource;
        private int m_iStartPosition;
        private bool m_bDisableMouseHitTesting;
        private CoverItem m_currentCoverItem;
        private ImageSource m_imageSourceBtnPreviousEnabled;
        private ImageSource m_imageSourceBtnPreviousDisabled;
        private ImageSource m_imageSourceBtnNextEnabled;
        private ImageSource m_imageSourceBtnNextDisabled;
        private ImageSource m_imageSourceBtnPlay;
        private ImageSource m_imageSourceBtnPause;
        private MeshGeometry3D m_meshGeometry;
        private MeshGeometry3D m_meshGeometryMirror;
        private BSE.Platten.Audio.CPlayerManager m_playerManager;

        #endregion

        #region Properties
        //Gets or sets the connection string to the database
        public string ConnectionString
        {
            get;
            set;
        }
        /// <summary>
        /// Sets the CPlayerManager
        /// </summary>
        public CPlayerManager PlayerManager
        {
            private get { return this.m_playerManager; }
            set
            {
                this.m_playerManager = value;
                if (this.m_playerManager != null)
                {
                    this.m_playerManager.PlayerManagerTrackChanged += new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerTrackChanged);
                    this.m_playerManager.PlayerManagerSongFinished += new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerSongFinished);
                    this.m_playerManager.PlayerManagerPlays += new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerPlays);
                    this.m_playerManager.PlayerManagerPaused += new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerPaused);
                }
            }
        }
        private MeshGeometry3D MeshGeometry
        {
            get
            {
                if (this.m_meshGeometry == null)
                {
                    this.m_meshGeometry = this.FindResource("meshGeometry") as MeshGeometry3D;
                }
                return this.m_meshGeometry;
            }
        }
        private MeshGeometry3D MeshGeometryMirror
        {
            get
            {
                if (this.m_meshGeometryMirror == null)
                {
                    this.m_meshGeometryMirror = this.FindResource("meshGeometryMirror") as MeshGeometry3D;
                }
                return this.m_meshGeometryMirror;
            }
        }
        private ImageSource DefaultImageSource
        {
            get
            {
                if (this.m_defaultImageSource == null)
                {
                    System.Windows.Controls.Image image = this.FindResource("m_imgDefault") as System.Windows.Controls.Image;
                    this.m_defaultImageSource = image.Source;
                }
                return this.m_defaultImageSource;
            }
        }
        /// <summary>
        /// Gets or sets the <see cref="PlayMode"/> in which the player plays.
        /// </summary>
        internal BSE.Platten.Audio.PlayMode PlayMode
        {
            get;
            set;
        }
        /// <summary>
        /// Gets the PlayState enumeration type defines the possible operational states of the PlayerManager
        /// as it plays a digital media file.
        /// </summary>
        internal BSE.Platten.Audio.PlayState PlayState
        {
            get
            {
                if (this.m_playerManager != null)
                {
                    return this.m_playerManager.PlayState;
                }
                return PlayState.Undefined;
            }
        }
        #endregion

        #region MethodsPublic
        public CoverFlowItem()
        {
            string strAssemblyName = GetAssemblyName();
            this.m_imageSourceBtnNextEnabled = GetBitmapFromResource(
                string.Format(CultureInfo.InvariantCulture, "/{0}{1}", strAssemblyName, Constants.ImageSourceBtnNextEnabled));
            this.m_imageSourceBtnNextDisabled = GetBitmapFromResource(
                string.Format(CultureInfo.InvariantCulture, "/{0}{1}", strAssemblyName, Constants.ImageSourceBtnNextDisabled));
            this.m_imageSourceBtnPreviousEnabled = GetBitmapFromResource(
                string.Format(CultureInfo.InvariantCulture, "/{0}{1}", strAssemblyName, Constants.ImageSourceBtnPreviousEnabled));
            this.m_imageSourceBtnPreviousDisabled = GetBitmapFromResource(
                string.Format(CultureInfo.InvariantCulture, "/{0}{1}", strAssemblyName, Constants.ImageSourceBtnPreviousDisabled));
            this.m_imageSourceBtnPlay = GetBitmapFromResource(
                string.Format(CultureInfo.InvariantCulture, "/{0}{1}", strAssemblyName, Constants.ImageSourceBtnPlay));
            this.m_imageSourceBtnPause = GetBitmapFromResource(
                string.Format(CultureInfo.InvariantCulture, "/{0}{1}", strAssemblyName, Constants.ImageSourceBtnPause));

            InitializeComponent();
            
            this.m_btnStop.IsEnabled = false;
            this.m_btnPrevious.IsEnabled = false;
            this.m_btnNext.IsEnabled = false;

            this.m_coverFlowCollection = new Collection<int>();
            this.m_listCoverFlowItems = new List<CoverItem>();
        }

        public void LoadCovers()
        {
            if (string.IsNullOrEmpty(this.ConnectionString) == false)
            {
                this.Dispatcher.BeginInvoke(
                                System.Windows.Threading.DispatcherPriority.Normal,
                                (System.Threading.ThreadStart)delegate()
                            {
                                string strCacheDirectory = GetCacheDirectory();
                                CreateCacheFolder(strCacheDirectory);

                                foreach (BSE.Platten.BO.CTrack track in this.m_playerManager.TrackCollection)
                                {
                                    int iAlbumId = track.TitelId;
                                    if (this.m_coverFlowCollection.Contains(iAlbumId) == false)
                                    {
                                        this.m_coverFlowCollection.Add(iAlbumId);
                                    }
                                }

                                this.m_iVisibleCoversPerSide = 6;
                                if (this.m_coverFlowCollection.Count < 11)
                                {
                                    this.m_iVisibleCoversPerSide = this.m_coverFlowCollection.Count / 2;
                                }

                                int num = 0;
                                int num2 = this.m_iStartPosition + this.m_iVisibleCoversPerSide;

                                foreach (int iAlbumId in this.m_coverFlowCollection)
                                {
                                    if (((num >= this.m_iStartPosition) && (num <= (this.m_iStartPosition + (this.m_iVisibleCoversPerSide * 2)))) && (num < this.m_coverFlowCollection.Count))
                                    {
                                        if (num < num2)
                                        {
                                            this.CreateCoverItem(((this.m_iVisibleCoversPerSide - num) - this.m_iStartPosition) * -1, iAlbumId);

                                        }
                                        else if (num > num2)
                                        {
                                            CreateCoverItem((num - this.m_iStartPosition) - this.m_iVisibleCoversPerSide, iAlbumId);
                                        }
                                        else
                                        {
                                            CreateCoverItem(0, iAlbumId);
                                        }
                                    }
                                    num++;
                                }

                                Comparison<CoverItem> comparison = new Comparison<CoverItem>(this.CoverItemComparer);
                                this.m_listCoverFlowItems.Sort(comparison);

                                foreach (CoverItem coverItem in this.m_listCoverFlowItems)
                                {
                                    if (coverItem.Position == 0)
                                    {
                                        this.m_currentCoverItem = coverItem;
                                    }
                                }
                                BSE.Platten.BO.CTrack currentTrack = this.m_playerManager.CurrentTrack;
                                this.m_btnPlay.DisplayState = DisplayState.Playing;
                                this.PlayMode = this.m_playerManager.PlayMode;
                                switch (this.PlayState)
                                {
                                    case PlayState.Playing:
                                        this.m_btnPlay.DisplayState = DisplayState.Paused;
                                        PlayerManagerPlays(
                                            this, new PlayerManagerStatusChangedEventArgs(this.PlayMode));
                                        break;
                                    case PlayState.Paused:
                                        PlayerManagerPaused(
                                            this, new PlayerManagerStatusChangedEventArgs(this.PlayMode));
                                        break;
                                }

                                if (currentTrack != null)
                                {
                                    //SelectCurrentCover(currentTrack);
                                    this.m_tracksToSelect.Enqueue(currentTrack);
                                }

                                while (this.m_tracksToSelect.Count > 0)
                                {
                                    while (this.m_bDisableMouseHitTesting == true) ;
                                    CTrack dequeuedTrack = this.m_tracksToSelect.Dequeue();
                                    SelectCurrentCover(dequeuedTrack);
                                }
                            });
            }
        }
        /// <summary>
        /// Gets the name of the Coverflow assembly.
        /// </summary>
        /// <returns>the name of the Coverflow assembly as string</returns>
        public static string GetAssemblyName()
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            return assembly.GetName().Name;
        }
        /// <summary>
        /// Gets the name for the Coverflow cache directory
        /// </summary>
        /// <returns>The name for the Coverflow cache as string</returns>
        public static string GetCacheDirectory()
        {
            string strCacheDirectory = null;
            string strAssemblyName = GetAssemblyName();
            if (string.IsNullOrEmpty(strAssemblyName) == false)
            {
                string strApplicationDataPath = System.IO.Path.Combine(
                System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                Constants.ApplicationBaseDataDirectoryName);

                strCacheDirectory = System.IO.Path.Combine(strApplicationDataPath, strAssemblyName);
            }
            return strCacheDirectory;
        }
        /// <summary>
        /// Clears the Coverflow cache directory
        /// </summary>
        public static void ClearCoverFlowCache()
        {
            string strCacheDirectory = GetCacheDirectory();
            if (string.IsNullOrEmpty(strCacheDirectory) == false)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(strCacheDirectory);
                if (directoryInfo.Exists == true)
                {
                    directoryInfo.Delete(true);
                }
            }
        }

        #endregion

        #region MethodsProtected
        #endregion

        #region MethodsPrivate

        private void ViewPort3DMouseDown(object sender, MouseButtonEventArgs e)
        {
            //CoverItem selectedCoverItem = null;
            //Point positionPoint = e.GetPosition(this.m_viewPort3D);
            //var rayMeshGeometry3DHitTestResult = VisualTreeHelper.HitTest(this.m_viewPort3D, positionPoint) as RayMeshGeometry3DHitTestResult;
            //if (rayMeshGeometry3DHitTestResult != null)
            //{
            //    int iPosition = 0;

            //    foreach (Visual3D visual3D in this.m_visualModel.Children)
            //    {
            //        CoverItem coverItem = visual3D as CoverItem;
            //        if (coverItem != null)
            //        {
            //            if (coverItem.Matches(rayMeshGeometry3DHitTestResult.MeshHit) == true)
            //            {
            //                selectedCoverItem = coverItem;
            //                break;
            //            }
            //        }
            //    }

            //    if ((selectedCoverItem != null) && (this.m_bDisableMouseHitTesting == false))
            //    {
            //        this.m_bDisableMouseHitTesting = true;
            //        DispatcherTimer selectCoverTimer = new DispatcherTimer();
            //        selectCoverTimer.Tick += new EventHandler(this.SelectCoverTimerTick);
            //        selectCoverTimer.Tag = selectedCoverItem.Position;
            //        if (Math.Abs(iPosition) > 1)
            //        {
            //            selectCoverTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            //        }
            //        else
            //        {
            //            selectCoverTimer.Interval = new TimeSpan(0, 0, 0, 0, 0);
            //        }
            //        selectCoverTimer.Start();
            //    }
            //}
        }

        private void SelectCoverTimerTick(object sender, EventArgs e)
        {
            DispatcherTimer dispatcherTimer = sender as DispatcherTimer;
            int iPosition = (int)dispatcherTimer.Tag;
            if (iPosition < 0)
            {
                this.MoveLeft();
                iPosition++;
            }
            else if (iPosition > 0)
            {
                this.MoveRight();
                iPosition--;
            }
            dispatcherTimer.Tag = iPosition;
            if (iPosition == 0)
            {
                dispatcherTimer.Stop();
                dispatcherTimer = null;
                foreach (CoverItem coverItem in this.m_listCoverFlowItems)
                {
                    if (coverItem.Position == 0)
                    {
                        this.m_currentCoverItem = coverItem;
                        break;
                    }
                }
                this.m_bDisableMouseHitTesting = false;
            }
        }

        private void MoveLeft()
        {
            CleanUpOldItems();

            int iIndex = 0;
            int iNewAlbimId = -1;
            
            foreach (int iAlbumId in this.m_coverFlowCollection)
            {
                if (iIndex == (this.m_iStartPosition - 1))
                {
                    iNewAlbimId = iAlbumId;
                    break;
                }
                iIndex++;
            }

            CoverItem coverItemToRemove = null;
            if (this.m_listCoverFlowItems.Count > 0)
            {
                coverItemToRemove = this.m_listCoverFlowItems[this.m_listCoverFlowItems.Count - 1];
            }
            
            if (iNewAlbimId != -1)
            {
                this.CreateCoverItem(-(this.m_iVisibleCoversPerSide + 1), iNewAlbimId);
            }

            if (coverItemToRemove != null)
            {
                if ((this.m_iStartPosition >= (this.m_iVisibleCoversPerSide * -2)) &&
                (coverItemToRemove.Position < -(this.m_iVisibleCoversPerSide - 1)) || (coverItemToRemove.Position > (this.m_iVisibleCoversPerSide - 1)))
                {
                    this.m_removeableCoverFlowItems.Enqueue(coverItemToRemove);
                }
            }
            double yRotation = 0.0;
            double offsetX = 0.0;
            double dOffsetZ = 0.0;
            foreach (CoverItem coverItem in this.m_listCoverFlowItems)
            {
                CoverItem.GetOffsetsFromPosition(coverItem.Position + 1, out yRotation, out offsetX, out dOffsetZ);
                //coverItem.Animate(yRotation, offsetX, dOffsetZ);
                coverItem.Position++;
            }
            this.m_iStartPosition--;
        }
        
        private void MoveRight()
        {
                CleanUpOldItems();

                int iIndex = 0;
                int iNewAlbumId = -1;

                foreach (int iAlbumId in this.m_coverFlowCollection)
                {
                    if (iIndex == (this.m_iStartPosition + (2 * this.m_iVisibleCoversPerSide) + 1))
                    {
                        iNewAlbumId = iAlbumId;
                        break;
                    }
                    iIndex++;
                }
                CoverItem coverItemToRemove = null;
                if (this.m_listCoverFlowItems.Count > 0)
                {
                    coverItemToRemove = this.m_listCoverFlowItems[0];
                }
                if (iNewAlbumId != -1)
                {
                    this.CreateCoverItem(this.m_iVisibleCoversPerSide + 1, iNewAlbumId);
                }

                if (coverItemToRemove != null)
                {
                    if ((coverItemToRemove.Position < -(this.m_iVisibleCoversPerSide - 1)) ||
                    (coverItemToRemove.Position > (this.m_iVisibleCoversPerSide - 1)))
                    {
                        this.m_removeableCoverFlowItems.Enqueue(coverItemToRemove);
                    }
                }

                //double yRotation = 0.0;
                //double offsetX = 0.0;
                //double dOffsetZ = 0.0;
                //foreach (CoverItem coverItem in this.m_listCoverFlowItems)
                //{
                //    CoverItem.GetOffsetsFromPosition(coverItem.Position - 1, out yRotation, out offsetX, out dOffsetZ);
                //    coverItem.Animate(yRotation, offsetX, dOffsetZ);
                //    coverItem.Position--;
                //}
                this.m_iStartPosition++;
        }

        private void CleanUpOldItems()
        {
            while (this.m_removeableCoverFlowItems.Count > 0)
            {
                using (CoverItem removedItem = this.m_removeableCoverFlowItems.Dequeue())
                {
                    if (removedItem != null)
                    {
                        this.m_listCoverFlowItems.Remove(removedItem);
                        //int index = this.m_visualModel.Children.IndexOf(removedItem);
                        //if (index > -1)
                        //{
                        //    this.m_visualModel.Children.RemoveAt(index);
                        //}
                    }
                }
            }
        }
        
        private CoverItem CreateCoverItem(int iPosition, int iAlbumId)
        {
            string strCacheDirectory = GetCacheDirectory();
            //CoverItem coverItem = new CoverItem(this.MeshGeometry, this.MeshGeometryMirror, this.mod , strCacheDirectory, this.DefaultImageSource, iAlbumId, iPosition, this.ConnectionString);
            //this.m_visualModel.Children.Add(coverItem);
            
            //if (iPosition < 0)
            //{
            //    this.m_listCoverFlowItems.Insert(0, coverItem);
            //    return coverItem;
            //}
            
            //this.m_listCoverFlowItems.Add(coverItem);
            return null;
        }

        private int CoverItemComparer(CoverItem item1, CoverItem item2)
        {
            if (item1.Position < item2.Position)
            {
                return -1;
            }
            if (item1.Position > item2.Position)
            {
                return 1;
            }
            return 0;
        }

        private static void CreateCacheFolder(string strCacheDirectoryName)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(strCacheDirectoryName);
            if (directoryInfo.Exists == false)
            {
                directoryInfo.Create();
            }
        }

        private static BitmapImage GetBitmapFromResource(string relativeUriString)
        {
            BitmapImage bitmapImage = null;
            // Get the image stream at the specified URI that
            // is relative to the application package root.
            Uri uri = new Uri(relativeUriString, UriKind.Relative);
            StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uri);
            using (Stream stream = streamResourceInfo.Stream)
            {
                // Convert the stream to an Image object.
                bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = stream;
                bitmapImage.EndInit();
            }
            return bitmapImage;
        }

        private void PlayerManagerTrackChanged(object sender, PlayerManagerStatusChangedEventArgs e)
        {
            this.PlayMode = e.PlayMode;
            BSE.Platten.BO.CTrack currentTrack = e.CurrentTrack;
            SelectCurrentCover(currentTrack);
            Dispatcher.Invoke(
                new ViewStatePlayerTrackChangedHandler(ViewStatePlayerTrackChanged),
                e.PlayMode);
        }

        private void ViewStatePlayerTrackChanged(PlayMode eMode)
        {
            this.m_btnPlay.DisplayState = DisplayState.Playing;
            if (this.m_playerManager != null)
            {
                this.m_btnNext.IsEnabled = this.m_playerManager.IsNextTrackAvailable;
                this.m_btnPrevious.IsEnabled = this.m_playerManager.IsPreviousTrackAvailable;
            }
        }

        private void PlayerManagerSongFinished(object sender, PlayerManagerStatusChangedEventArgs e)
        {
        }

        private void PlayerManagerPlays(object sender, PlayerManagerStatusChangedEventArgs e)
        {
            Dispatcher.Invoke(
                new ViewStatePlayerPlaysHandler(ViewStatePlayerPlays),
                e.PlayMode);
        }
        
        private void ViewStatePlayerPlays(PlayMode eMode)
        {
            this.m_btnStop.IsEnabled = true;
            this.m_btnPlay.DisplayState = DisplayState.Playing;
            this.m_btnNext.IsEnabled = false;
            this.m_btnPrevious.IsEnabled = false;
            this.m_txtSong.Text = this.m_playerManager.GetSongTitle();

            switch (eMode)
            {
                case PlayMode.Playlist:
                case PlayMode.Random:
                    if (this.m_playerManager.IsNextTrackAvailable == true)
                    {
                        this.m_btnNext.IsEnabled = true;
                    }
                    if (this.m_playerManager.IsPreviousTrackAvailable == true)
                    {
                        this.m_btnPrevious.IsEnabled = true;
                    }
                        break;
            }
        }

        private void PlayerManagerPaused(object sender, PlayerManagerStatusChangedEventArgs e)
        {
            Dispatcher.Invoke(
                new ViewStatePlayerPausedHandler(ViewStatePlayerPaused),
                e.PlayMode);
        }

        private void ViewStatePlayerPaused(PlayMode eMode)
        {
            this.m_btnPlay.DisplayState = DisplayState.Paused;
        }

        private void SelectCurrentCover(BSE.Platten.BO.CTrack trackToSelect)
        {
            int iCurrentAlbumPosition = 0;
            int iCounter = 0;
            int iNewAlbumPosition = 0;

            int iNewAlbumId = trackToSelect.TitelId;
            if (iNewAlbumId != 0)
            {
                foreach (int iAlbumId in this.m_coverFlowCollection)
                {
                    if ((this.m_currentCoverItem != null) && (iAlbumId == this.m_currentCoverItem.AlbumId))
                    {
                        iCurrentAlbumPosition = iCounter;
                    }
                    if (iAlbumId == iNewAlbumId)
                    {
                        iNewAlbumPosition = iCounter;
                    }
                    iCounter++;
                }

                int iPosition = 0;
                {
                    iPosition = iNewAlbumPosition - iCurrentAlbumPosition;
                }

                this.m_bDisableMouseHitTesting = true;
                DispatcherTimer selectCoverItemTimer = new DispatcherTimer();
                selectCoverItemTimer.Tick += new EventHandler(this.SelectCoverTimerTick);
                selectCoverItemTimer.Tag = iPosition;
                if (Math.Abs(iPosition) > 1)
                {
                    selectCoverItemTimer.Interval = new TimeSpan(0, 0, 0, 0, 200);
                }
                else
                {
                    selectCoverItemTimer.Interval = new TimeSpan(0, 0, 0, 0, 0);
                }
                selectCoverItemTimer.Start();

            }
        }

        private void BtnPreviousIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.m_imgPrevious != null)
            {
                if (e.NewValue is bool)
                {
                    bool bIsEnabled = (bool)e.NewValue;
                    if (bIsEnabled == true)
                    {
                        this.m_imgPrevious.Source = this.m_imageSourceBtnPreviousEnabled;
                    }
                    else
                    {
                        this.m_imgPrevious.Source = this.m_imageSourceBtnPreviousDisabled;
                    }
                }
            }
        }

        private void BtnNextIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.m_imgNext != null)
            {
                if (e.NewValue is bool)
                {
                    bool bIsEnabled = (bool)e.NewValue;
                    if (bIsEnabled == true)
                    {
                        this.m_imgNext.Source = this.m_imageSourceBtnNextEnabled;
                    }
                    else
                    {
                        this.m_imgNext.Source = this.m_imageSourceBtnNextDisabled;
                    }
                }
            }
        }
        private void BtnCloseClick(object sender, RoutedEventArgs e)
        {
            if (this.CloseClick != null)
            {
                this.CloseClick(sender, EventArgs.Empty);
            }
        }
        private void BtnNextClick(object sender, RoutedEventArgs e)
        {
            if (this.m_playerManager.IsNextTrackAvailable == true)
            {
                this.m_playerManager.PlayNextTrack(PlayMode.Random);
            }
        }
        private void BtnPreviousClick(object sender, RoutedEventArgs e)
        {
            if (this.m_playerManager.IsPreviousTrackAvailable == true)
            {
                this.m_playerManager.PlayPreviousTrack(PlayMode.Random);
            }
        }
        private void BtnStopClick(object sender, RoutedEventArgs e)
        {
            if (this.m_playerManager != null)
            {
                this.m_playerManager.Stop();
            }
            if (this.CloseClick != null)
            {
                this.CloseClick(sender, EventArgs.Empty);
            }
        }
        
        private void BtnPlayClick(object sender, RoutedEventArgs e)
        {
            if (this.m_playerManager != null)
            {
                switch (this.m_btnPlay.DisplayState)
                {
                    case DisplayState.Paused:
                        this.m_playerManager.Play();
                        break;
                    case DisplayState.Playing:
                        this.m_playerManager.Pause();
                        break;
                }
            }
        }
        
        private void BtnPlayDisplayStateChanged(object sender, RoutedEventArgs e)
        {
            this.m_imgPlay.Source = this.m_imageSourceBtnPlay;
            if (this.m_btnPlay.DisplayState == DisplayState.Playing)
            {
                this.m_imgPlay.Source = this.m_imageSourceBtnPause;
            }
        }
        private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            Key key = e.Key;
            switch (key)
            {
                case Key.Escape:
                    this.BtnCloseClick(this, new RoutedEventArgs());
                    break;
                case Key.MediaNextTrack:
                    this.BtnNextClick(this, new RoutedEventArgs());
                    break;
                case Key.MediaPreviousTrack:
                    this.BtnPreviousClick(this, new RoutedEventArgs());
                    break;
                case Key.MediaPlayPause:
                    this.BtnPlayClick(this, new RoutedEventArgs());
                    break;
                case Key.MediaStop:
                    this.BtnStopClick(this, new RoutedEventArgs());
                    break;
                case Key.Play:
                    this.BtnPlayClick(this, new RoutedEventArgs());
                    break;
            }
        }
        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            if (this.m_playerManager != null)
            {
                this.m_playerManager.PlayerManagerTrackChanged -= new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerTrackChanged);
                this.m_playerManager.PlayerManagerSongFinished -= new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerSongFinished);
                this.m_playerManager.PlayerManagerPlays -= new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerPlays);
                this.m_playerManager.PlayerManagerPaused -= new EventHandler<PlayerManagerStatusChangedEventArgs>(PlayerManagerPaused);
            }
            if (this.m_viewPort3D != null)
            {
                Queue<CoverItem> coverItemsToRemove = new Queue<CoverItem>();
                foreach (CoverItem coverItem in this.m_listCoverFlowItems)
                {
                    coverItemsToRemove.Enqueue(coverItem);
                }

                while (coverItemsToRemove.Count > 0)
                {
                    CoverItem coverItemToRemove = null;
                    using (coverItemToRemove = coverItemsToRemove.Dequeue())
                    {
                        if (coverItemToRemove != null)
                        {
                            this.m_listCoverFlowItems.Remove(coverItemToRemove);
                            //this.m_visualModel.Children.Remove(coverItemToRemove);
                        }
                    }

                    if (coverItemToRemove != null)
                    {
                        coverItemToRemove = null;
                    }
                }
            }
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Eichkorn

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid