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

BSEtunes

, 24 Apr 2010
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.Media.Media3D;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Point2D = System.Windows.Point;
using System.IO;
using BSE.CoverFlow.WPFLib.Properties;
using System.Diagnostics;
using System.Windows.Markup;
using System.Windows.Threading;
using BSE.Platten.BO;

namespace BSE.CoverFlow.WPFLib
{
    /// <summary>
    /// Contains the cover images and the animation properties for one coverflow object.
    /// </summary>
    public class CoverItem : IDisposable
    {
        #region FieldsPrivate
        private readonly string m_strCacheDirectoryName;
        private CreateImageSourceThread m_createImageSourceThread;
        private ImageSource m_defaultImageSource;
        // Track whether Dispose has been called.
        private bool m_bDisposed;

        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the current position of the coveritem in the Visual3DCollection.
        /// </summary>
        public int Position
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the AlbumId for the cover.
        /// </summary>
        public int TitelId
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the <see cref="ModelVisual3D"/>.
        /// </summary>
        public ModelVisual3D ModelVisual3D
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the Viewport3DIndex for the animation.
        /// </summary>
        public int Viewport3DIndex
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the <see cref="Storyboard"/>.
        /// </summary>
        public Storyboard Storyboard
        {
            get;
            set;
        }
        #endregion

        #region MethodsPublic
        /// <summary>
        /// Constructor for an CoverItem.
        /// </summary>
        /// <param name="modelVisual3D"><see cref="Visual"/> that contains 3-D models.</param>
        /// <param name="storyboard">A container timeline that provides object and property targeting information for its child animations.</param>
        /// <param name="strCacheDirectoryName">The name of the cache directory.</param>
        /// <param name="defaultImageSource">The default imagesource if there is no other cover image</param>
        /// <param name="iAlbumId">The AlbimId of the cover record in the database.</param>
        /// <param name="iPosition">The position of the CoverItem in the Visual3DCollection.</param>
        public CoverItem(ModelVisual3D modelVisual3D, Storyboard storyboard, string strCacheDirectoryName, ImageSource defaultImageSource, int iAlbumId, int iPosition, string strConnection)
        {
            if (defaultImageSource == null)
            {
                throw new ArgumentException(
                    string.Format(
                    System.Globalization.CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    "defaultImageSource"));
            }

            using (MemoryStream memoryStream = new MemoryStream())
            {
                XamlWriter.Save(modelVisual3D, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                this.ModelVisual3D = XamlReader.Load(memoryStream) as ModelVisual3D;
            }

            using (MemoryStream memoryStream = new MemoryStream())
            {
                XamlWriter.Save(storyboard, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                this.Storyboard = XamlReader.Load(memoryStream) as Storyboard;
            }

            this.Position = iPosition;
            this.m_strCacheDirectoryName = strCacheDirectoryName;
            this.TitelId = iAlbumId;
            this.m_defaultImageSource = defaultImageSource;

            double dYRotation = 0.0;
            double dOffsetX = 0.0;
            double dOffsetY = 0.0;
            double dOffsetZ = 0.0;

            GetOffsetsFromPosition(this.Position, out dYRotation, out dOffsetX, out dOffsetY, out dOffsetZ);

            Model3DGroup model3DGroup = this.ModelVisual3D.Content as Model3DGroup;
            GeometryModel3D geometryModel3D = model3DGroup.Children[1] as GeometryModel3D;
            if (geometryModel3D != null)
            {
                if (geometryModel3D.Material != null)
                {
                    geometryModel3D.Material = null;
                    geometryModel3D.Material = LoadImageMirror(defaultImageSource);
                }
            }
            Transform3DGroup transform3DGroup = model3DGroup.Transform as Transform3DGroup;
            RotateTransform3D rotateTransform3D = transform3DGroup.Children[0] as RotateTransform3D;
            if (rotateTransform3D != null)
            {
                AxisAngleRotation3D axisAngleRotation3D = rotateTransform3D.Rotation as AxisAngleRotation3D;
                axisAngleRotation3D.Angle = dYRotation;
            }
            TranslateTransform3D translateTransform3D = transform3DGroup.Children[1] as TranslateTransform3D;
            if (translateTransform3D != null)
            {
                translateTransform3D.OffsetX = dOffsetX;
                translateTransform3D.OffsetZ = dOffsetZ;
            }
            
            string strImageFileName = Path.Combine(this.m_strCacheDirectoryName, this.TitelId + Constants.PngFileFormatSuffix);
            this.m_createImageSourceThread = new CreateImageSourceThread(
                strImageFileName, this.TitelId, strConnection);
            this.m_createImageSourceThread.ImageSourceCreated += new EventHandler<EventArgs>(ImageSourceCreated);
        }
        /// <summary>
        /// Matches the CoverItem with the clicked CoverItem
        /// </summary>
        /// <param name="modelVisual3D"><see cref="Visual"/>that contains 3-D models.</param>
        /// <returns>True if when match else false</returns>
        public bool Matches(ModelVisual3D modelVisual3D)
        {
            if (this.ModelVisual3D.Equals(modelVisual3D) == true)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// Gets the animation offsets for the CoverItem dependent to the position in its parent list
        /// </summary>
        /// <param name="iPosition">The position of the CoverItem in the Visual3DCollection.</param>
        /// <param name="dYRotation">The value for the rotation animation.</param>
        /// <param name="dOffsetX">The value for the x- axis animation.</param>
        /// <param name="dOffsetY">The value for the x- axis animation.</param>
        /// <param name="dOffsetZ">The value for the z- axis animation.</param>
        public static void GetOffsetsFromPosition(int iPosition, out double dYRotation, out double dOffsetX, out double dOffsetY,out double dOffsetZ)
        {
            dYRotation = 0.0;
            dOffsetX = 0.0;
            dOffsetY = 0.0;
            dOffsetZ = 1.0;

            int num = Math.Abs(iPosition) - 1;
            if (iPosition > 0)
            {
                dYRotation = -72.0;
                dOffsetX = 1.8 + num;
                dOffsetZ = -0.0;
            }
            if (iPosition < 0)
            {
                dYRotation = 72.0;
                dOffsetX = -1.8 - num;
                dOffsetZ = -0.0;
            }
        }
        /// <summary>
        /// Checks whether the image exists in the filesystem
        /// </summary>
        /// <param name="strFileName">The name of the image file</param>
        /// <returns>True if exits else false</returns>
        public static bool ExistsImageFile(string strFileName)
        {
            FileInfo fileInfo = new FileInfo(strFileName);
            if (fileInfo.Exists == true)
            {
                return true;
            }
            return false;
        }
        // Implement IDisposable.
        // Do not make this method virtual.
        // A derived class should not be able to override this method.
        public void Dispose()
        {
            Dispose(true);
            // This object will be cleaned up by the Dispose method.
            // Therefore, you should call GC.SupressFinalize to
            // take this object off the finalization queue
            // and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }
        #endregion

        #region MethodsProtected
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (this.m_bDisposed == false)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (this.m_createImageSourceThread != null)
                    {
                        this.m_createImageSourceThread.ImageSourceCreated -= new EventHandler<EventArgs>(ImageSourceCreated);
                        this.m_createImageSourceThread.Dispose();
                    }

                    if (this.ModelVisual3D != null)
                    {
                        Model3DGroup model3DGroup = this.ModelVisual3D.Content as Model3DGroup;
                        if (model3DGroup != null)
                        {
                            GeometryModel3D geometryModel3D = model3DGroup.Children[0] as GeometryModel3D;
                            if (geometryModel3D != null)
                            {
                                if (geometryModel3D.Material != null)
                                {
                                    geometryModel3D = null;
                                }
                                geometryModel3D = null;
                            }
                            GeometryModel3D geometryModel3DMirror = model3DGroup.Children[1] as GeometryModel3D;
                            if (geometryModel3DMirror != null)
                            {
                                if (geometryModel3DMirror.Material != null)
                                {
                                    geometryModel3DMirror = null;
                                }
                                geometryModel3DMirror = null;
                            }
                            Transform3DGroup transform3DGroup = model3DGroup.Transform as Transform3DGroup;
                            if (transform3DGroup != null)
                            {
                                RotateTransform3D rotateTransform3D = transform3DGroup.Children[0] as RotateTransform3D;
                                if (rotateTransform3D != null)
                                {
                                    rotateTransform3D = null;
                                }
                                TranslateTransform3D translateTransform3D = transform3DGroup.Children[1] as TranslateTransform3D;
                                if (translateTransform3D != null)
                                {
                                    translateTransform3D = null;
                                }
                                transform3DGroup = null;
                            }
                            model3DGroup = null;
                        }
                        this.ModelVisual3D = null;
                    }
                    if (this.Storyboard != null)
                    {
                        this.Storyboard = null;
                    }
                    if (this.m_defaultImageSource != null)
                    {
                        this.m_defaultImageSource = null;
                    }
                }
                this.m_bDisposed = true;
            }
        }
        #endregion

        #region MethodsPrivate

        private void ImageSourceCreated(object sender, EventArgs e)
        {
            using (CreateImageSourceThread createImageSourceThread = sender as CreateImageSourceThread)
            {
                if (createImageSourceThread != null)
                {
                    createImageSourceThread.ImageSourceCreated -= new EventHandler<EventArgs>(ImageSourceCreated);

                    System.Threading.ThreadStart threadStart = delegate()
                    {
                        string strImageFileName = Path.Combine(this.m_strCacheDirectoryName, this.TitelId + Constants.PngFileFormatSuffix);
                        ImageSource imageSource = GetImageSource(strImageFileName);
                        if (imageSource != null)
                        {
                            if (this.ModelVisual3D != null)
                            {
                                this.ModelVisual3D.Dispatcher.BeginInvoke(
                                    System.Windows.Threading.DispatcherPriority.Normal,
                                    (System.Threading.ThreadStart)delegate()
                                {
                                    LoadImageIntoModel3DGroup(imageSource);
                                });
                            }
                        }
                    };
                    new System.Threading.Thread(threadStart).Start();
                }
            }
        }

        private void LoadImageIntoModel3DGroup(ImageSource imageSource)
        {
            if (imageSource != null)
            {
                Model3DGroup content = this.ModelVisual3D.Content as Model3DGroup;
                GeometryModel3D geometryModel3D = content.Children[0] as GeometryModel3D;
                if (geometryModel3D != null)
                {
                    if (geometryModel3D.Material != null)
                    {
                        geometryModel3D.Material = null;
                        geometryModel3D.Material = LoadImage(imageSource);
                    }
                }
                GeometryModel3D geometryModel3DMirror = content.Children[1] as GeometryModel3D;
                if (geometryModel3DMirror != null)
                {
                    if (geometryModel3DMirror.Material != null)
                    {
                        geometryModel3DMirror.Material = null;
                        geometryModel3DMirror.Material = LoadImageMirror(imageSource);
                    }
                }
                imageSource = null;
            }
        }

        private static ImageSource GetImageSource(string strFileName)
        {
            if (ExistsImageFile(strFileName) == true)
            {
                try
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    Uri uri = new Uri(strFileName, UriKind.RelativeOrAbsolute);
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.UriSource = uri;
                    bitmapImage.EndInit();
                    bitmapImage.Freeze();
                    return bitmapImage;
                }
                catch (Exception exception)
                {
                    throw new Exception("GetImageSource" + exception.Message);
                }
            }
            return null;
        }

        private static Material LoadImage(ImageSource imageSource)
        {
            return new DiffuseMaterial(new ImageBrush(imageSource));
        }
        
        private static Material LoadImageMirror(ImageSource imageSource)
        {
            ImageBrush imageBrush = new ImageBrush(imageSource);
            imageBrush.Opacity = 0.9;

            System.Windows.Shapes.Rectangle imageRectangle = new System.Windows.Shapes.Rectangle();
            imageRectangle.Width = imageSource.Width;
            imageRectangle.Height = imageSource.Height;

            SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Colors.Black);

            LinearGradientBrush linearGradientBrush = new LinearGradientBrush();
            linearGradientBrush.StartPoint = new System.Windows.Point(0, 1);
            linearGradientBrush.EndPoint = new System.Windows.Point(0, 0);
            linearGradientBrush.GradientStops.Add(new GradientStop(Colors.White, 0));
            linearGradientBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 0.4));

            imageRectangle.Fill = solidColorBrush;
            imageRectangle.Arrange(
                new System.Windows.Rect(
                    new System.Windows.Point(0, 0),
                    new System.Windows.Size(imageSource.Width, imageSource.Height))
                    );

            solidColorBrush = null;
            
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)imageSource.Width, (int)imageSource.Height, 96, 96, PixelFormats.Pbgra32);
            renderBitmap.Render(imageRectangle);

            imageRectangle.OpacityMask = linearGradientBrush;
            imageRectangle.Fill = imageBrush;
            imageRectangle.UpdateLayout();

            linearGradientBrush = null;

            renderBitmap.Render(imageRectangle);

            imageRectangle = null;
            imageBrush = null;
            imageBrush = new ImageBrush(renderBitmap);
            renderBitmap = null;

            return new DiffuseMaterial(imageBrush);
        }

        #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 | Mobile
Web02 | 2.8.140922.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid