Skip to content

Commit

Permalink
Continued work on playlist. Still not implemented, but compiles again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alxandr committed Feb 9, 2011
1 parent b6cc761 commit 74f8ee7
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 30 deletions.
4 changes: 1 addition & 3 deletions SpotiFire.SpotifyLib/DelegateList.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpotiFire.SpotifyLib
{
Expand All @@ -15,6 +12,7 @@ public DelegateList(Func<int> getLength, Func<int, T> getIndex, Action<T> addFun
{
this.addFunc = addFunc;
this.removeFunc = removeFunc;
this.readonlyFunc = readonlyFunc;
}

public void Add(T item)
Expand Down
13 changes: 13 additions & 0 deletions SpotiFire.SpotifyLib/EventArgs/DescriptionEventArgs.cs
@@ -0,0 +1,13 @@
using System;

namespace SpotiFire.SpotifyLib
{
public class DescriptionEventArgs : EventArgs
{
private string description;
public DescriptionEventArgs(string description)
{
this.description = description;
}
}
}
13 changes: 13 additions & 0 deletions SpotiFire.SpotifyLib/EventArgs/ImageEventArgs.cs
@@ -0,0 +1,13 @@
using System;

namespace SpotiFire.SpotifyLib
{
public class ImageEventArgs : EventArgs
{
string imageId;
public ImageEventArgs(string imageId)
{
this.imageId = imageId;
}
}
}
13 changes: 13 additions & 0 deletions SpotiFire.SpotifyLib/EventArgs/PlaylistUpdateEventArgs.cs
@@ -0,0 +1,13 @@
using System;

namespace SpotiFire.SpotifyLib
{
public class PlaylistUpdateEventArgs : EventArgs
{
private bool complete;
public PlaylistUpdateEventArgs(bool complete)
{
this.complete = complete;
}
}
}
16 changes: 16 additions & 0 deletions SpotiFire.SpotifyLib/EventArgs/TrackCreatedChangedEventArgs.cs
@@ -0,0 +1,16 @@

using System;
namespace SpotiFire.SpotifyLib
{
public class TrackCreatedChangedEventArgs : TrackEventArgs
{
private DateTime when;
//TODO: Implement user private User who
public TrackCreatedChangedEventArgs(ITrack track, DateTime when/*, User who*/)
: base(track)
{
this.when = when;
//this.who = who;
}
}
}
13 changes: 13 additions & 0 deletions SpotiFire.SpotifyLib/EventArgs/TrackEventArgs.cs
@@ -0,0 +1,13 @@
using System;

namespace SpotiFire.SpotifyLib
{
public class TrackEventArgs : EventArgs
{
private ITrack track;
public TrackEventArgs(ITrack track)
{
this.track = track;
}
}
}
13 changes: 13 additions & 0 deletions SpotiFire.SpotifyLib/EventArgs/TrackSeenEventArgs.cs
@@ -0,0 +1,13 @@

namespace SpotiFire.SpotifyLib
{
public class TrackSeenEventArgs : TrackEventArgs
{
bool seen;
public TrackSeenEventArgs(ITrack track, bool seen)
: base(track)
{
this.seen = seen;
}
}
}
23 changes: 15 additions & 8 deletions SpotiFire.SpotifyLib/SpotiFire.SpotifyLib.csproj
Expand Up @@ -40,39 +40,46 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Album.cs" />
<Compile Include="Artist.cs" />
<Compile Include="SpotifyTypes\Album.cs" />
<Compile Include="SpotifyTypes\Artist.cs" />
<Compile Include="CountedDisposeableSpotifyObject.cs" />
<Compile Include="DelegateArray.cs" />
<Compile Include="DelegateList.cs" />
<Compile Include="EventArgs\DescriptionEventArgs.cs" />
<Compile Include="DisposeableSpotifyObject.cs" />
<Compile Include="EventWorkerItem.cs" />
<Compile Include="Interfaces\IAlbum.cs" />
<Compile Include="Interfaces\IArray.cs" />
<Compile Include="Interfaces\IArtist.cs" />
<Compile Include="Interfaces\IEditableArray.cs" />
<Compile Include="Interfaces\IImage.cs" />
<Compile Include="Image.cs" />
<Compile Include="SpotifyTypes\Image.cs" />
<Compile Include="Interfaces\IPlaylist.cs" />
<Compile Include="Interfaces\IPlaylistContainer.cs" />
<Compile Include="Interfaces\ISearch.cs" />
<Compile Include="Interfaces\ISpotifyObject.cs" />
<Compile Include="Interfaces\ITrack.cs" />
<Compile Include="libspotify.cs" />
<Compile Include="EventArgs\MusicDeliveryEventArgs.cs" />
<Compile Include="Playlist.cs" />
<Compile Include="PlaylistContainer.cs" />
<Compile Include="EventArgs\ImageEventArgs.cs" />
<Compile Include="SpotifyTypes\Playlist.cs" />
<Compile Include="SpotifyTypes\PlaylistContainer.cs" />
<Compile Include="EventArgs\PlaylistEventArgs.cs" />
<Compile Include="EventArgs\PlaylistMovedEventArgs.cs" />
<Compile Include="EventArgs\PlaylistUpdateEventArgs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Search.cs" />
<Compile Include="SpotifyTypes\Search.cs" />
<Compile Include="EventArgs\SearchEventArgs.cs" />
<Compile Include="Session.cs" />
<Compile Include="SpotifyTypes\Session.cs" />
<Compile Include="EventArgs\SessionEventArgs.cs" />
<Compile Include="SpotifyException.cs" />
<Compile Include="Track.cs" />
<Compile Include="SpotifyTypes\Track.cs" />
<Compile Include="EventArgs\TracksEventArgs.cs" />
<Compile Include="EventArgs\TracksAddedEventArgs.cs" />
<Compile Include="EventArgs\TracksMovedEventArgs.cs" />
<Compile Include="EventArgs\TrackCreatedChangedEventArgs.cs" />
<Compile Include="EventArgs\TrackEventArgs.cs" />
<Compile Include="EventArgs\TrackSeenEventArgs.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="libspotify.dll">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -10,13 +10,29 @@ namespace SpotiFire.SpotifyLib
internal class Playlist : CountedDisposeableSpotifyObject, IPlaylist
{
#region Wrapper
private class PlaylistWrapper: DisposeableSpotifyObject, IPlaylist
private class PlaylistWrapper : DisposeableSpotifyObject, IPlaylist
{
internal Playlist playlist;
public PlaylistWrapper(Playlist playlist)
{
this.playlist = playlist;
}

protected override void OnDispose()
{
Playlist.Delete(playlist.playlistPtr);
playlist = null;
}

protected override int IntPtrHashCode()
{
return IsAlive() ? playlist.IntPtrHashCode() : 0;
}

public Session Session
{
get { IsAlive(true); return playlist.Session; }
}
}
internal static IntPtr GetPointer(IPlaylist playlist)
{
Expand Down Expand Up @@ -87,17 +103,17 @@ private struct sp_playlist_callbacks
#endregion

#region Spotify Callbacks
private tracks_added_cb tracks_added;
private tracks_removed_cb tracks_removed;
private tracks_moved_cd tracks_moved;
private playlist_renamed_cb playlist_renamed;
private playlist_state_changed_cb playlist_state_changed;
private playlist_update_in_progress_cb playlist_update_in_progress;
private playlist_metadata_updated_cb playlist_metadata_updated;
private track_created_changed_cb track_created_changed;
private track_seen_changed_cb track_seen_changed;
private description_changed_cb description_changed;
private image_changed_cb image_changed;
private tracks_added_cb tracks_added;
private tracks_removed_cb tracks_removed;
private tracks_moved_cd tracks_moved;
private playlist_renamed_cb playlist_renamed;
private playlist_state_changed_cb playlist_state_changed;
private playlist_update_in_progress_cb playlist_update_in_progress;
private playlist_metadata_updated_cb playlist_metadata_updated;
private track_created_changed_cb track_created_changed;
private track_seen_changed_cb track_seen_changed;
private description_changed_cb description_changed;
private image_changed_cb image_changed;
#endregion

#region Spotify Callback Implementations
Expand Down Expand Up @@ -147,6 +163,68 @@ private void RenamedCallback(IntPtr playlistPtr, IntPtr userdataPtr)
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<EventArgs>(p => p.OnRenamed, this), new EventArgs()));
}
}

private void StateChangedCallback(IntPtr playlistPtr, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<EventArgs>(p => p.OnStateChanged, this), new EventArgs()));
}
}

private void UdateInProgressCallback(IntPtr playlistPtr, bool complete, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<PlaylistUpdateEventArgs>(p => p.OnUpdateInProgress, this), new PlaylistUpdateEventArgs(complete)));
}
}

private void MetadataUpdatedCallback(IntPtr playlistPtr, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<EventArgs>(p => p.OnMetadataUpdated, this), new EventArgs()));
}
}

private void TrackCreatedChangedCallback(IntPtr playlistPtr, int position, IntPtr userPtr, int when, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
ITrack track = Track.Get(session, libspotify.sp_playlist_track(playlistPtr, position));
//IUser user = User.Get(session, userPtr);
DateTime dtWhen = new DateTime(TimeSpan.FromSeconds(when).Ticks, DateTimeKind.Utc);
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<TrackCreatedChangedEventArgs>(p => p.OnTrackCreatedChanged, this), new TrackCreatedChangedEventArgs(track, dtWhen)));
}
}

private void TrackSeenChangedCallback(IntPtr playlistPtr, int position, bool seen, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
ITrack track = Track.Get(session, libspotify.sp_playlist_track(playlistPtr, position));
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<TrackSeenEventArgs>(p => p.OnTrackSeenChanged, this), new TrackSeenEventArgs(track, seen)));
}
}

private void DescriptionChangedCallback(IntPtr playlistPtr, IntPtr descriptionPtr, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
string description = libspotify.GetString(descriptionPtr, String.Empty);
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<DescriptionEventArgs>(p => p.OnDescriptionChanged, this), new DescriptionEventArgs(description)));
}
}

private void ImageChangedCallback(IntPtr playlistPtr, IntPtr imageIdPtr, IntPtr userdataPtr)
{
if (playlistPtr == this.playlistPtr)
{
string imgId = libspotify.ImageIdToString(imageIdPtr);
session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<ImageEventArgs>(p => p.OnImageChanged, this), new ImageEventArgs(imgId)));
}
}
#endregion

#region Event Functions
Expand Down Expand Up @@ -175,6 +253,36 @@ protected virtual void OnStateChanged(EventArgs args)
if (StateChanged != null)
StateChanged(this, args);
}
protected virtual void OnUpdateInProgress(PlaylistUpdateEventArgs args)
{
if (UpdateInProgress != null)
UpdateInProgress(this, args);
}
protected virtual void OnMetadataUpdated(EventArgs args)
{
if (MetadataUpdated != null)
MetadataUpdated(this, args);
}
protected virtual void OnTrackCreatedChanged(TrackCreatedChangedEventArgs args)
{
if (TrackCreatedChanged != null)
TrackCreatedChanged(this, args);
}
protected virtual void OnTrackSeenChanged(TrackSeenEventArgs args)
{
if (TrackSeenChanged != null)
TrackSeenChanged(this, args);
}
protected virtual void OnDescriptionChanged(DescriptionEventArgs args)
{
if (DescriptionChanged != null)
DescriptionChanged(this, args);
}
protected virtual void OnImageChanged(ImageEventArgs args)
{
if (ImageChanged != null)
ImageChanged(this, args);
}
#endregion

#region Events
Expand All @@ -185,8 +293,8 @@ protected virtual void OnStateChanged(EventArgs args)
public event PlaylistEventHandler StateChanged;
public event PlaylistEventHandler<PlaylistUpdateEventArgs> UpdateInProgress;
public event PlaylistEventHandler MetadataUpdated;
public event PlaylistEventHandler<TrackEventArgs> TrackCreatedChanged;
public event PlaylistEventHandler<TrackEventArgs> TrackSeenChanged;
public event PlaylistEventHandler<TrackCreatedChangedEventArgs> TrackCreatedChanged;
public event PlaylistEventHandler<TrackSeenEventArgs> TrackSeenChanged;
public event PlaylistEventHandler<DescriptionEventArgs> DescriptionChanged;
public event PlaylistEventHandler<ImageEventArgs> ImageChanged;
#endregion
Expand Down Expand Up @@ -228,11 +336,33 @@ void session_DisposeAll(Session sender, SessionEventArgs e)
{
return expr.Compile().Invoke(p);
}
//private void ImageLoadedCallback(IntPtr imagePtr, IntPtr userdataPtr)
//{
// if (imagePtr == this.imagePtr)
// session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate<EventArgs>(i => i.OnLoaded, this), new EventArgs()));
//}
#endregion

#region Properties
public Session Session
{
get { IsAlive(true); return session; }
}
#endregion

#region Cleanup
protected override void OnDispose()
{
session.DisposeAll -= new SessionEventHandler(session_DisposeAll);

if (!session.ProcExit)
lock (libspotify.Mutex)
{
libspotify.sp_playlist_release(playlistPtr);
}

playlistPtr = IntPtr.Zero;
}
#endregion

protected override int IntPtrHashCode()
{
return playlistPtr.GetHashCode();
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 74f8ee7

Please sign in to comment.