Skip to content
This repository was archived by the owner on Jan 10, 2021. It is now read-only.

Commit b8e8bd0

Browse files
committed
Update to vs2013 and several fixes.
Updated build-scripts for Visual Studio 2013. Added some consistency-fixes and changed the API for Browse-methods. Resolves #49 Resolves #38
1 parent c4bcda0 commit b8e8bd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+33130
-408
lines changed

SpotiFire.LibSpotify/Album.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static __forceinline String^ HEX(const byte *bytes, int count)
1010
char result[41];
1111
result[40] = '\0';
1212
char *current = result;
13-
for(int i = 0; i < count; i++) {
13+
for (int i = 0; i < count; i++) {
1414
sprintf(current, "%02X", bytes[i]);
1515
current += 2;
1616
}
@@ -86,8 +86,7 @@ int Album::Year::get() {
8686
return sp_album_year(_ptr);
8787
}
8888

89-
AlbumBrowse ^Album::Browse() {
90-
SPLock lock; // don't think we need ALBUM_LOADED here. Should be tested.
89+
Task<AlbumBrowse ^> ^Album::Browse() {
9190
return AlbumBrowse::Create(_session, this);
9291
}
9392

SpotiFire.LibSpotify/Album.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using namespace System;
77
using namespace System::Collections::Generic;
88

99
namespace SpotiFire {
10-
1110
ref class Artist;
1211
ref class AlbumBrowse;
1312
ref class Link;
@@ -61,7 +60,7 @@ namespace SpotiFire {
6160
/// <summary> Gets the identifier of the cover. </summary>
6261
///
6362
/// <seealso cref="Image::FromId" />
64-
///
63+
///
6564
/// <value> The identifier of the cover. </value>
6665
///-------------------------------------------------------------------------------------------------
6766
virtual property PortraitId CoverId { PortraitId get() sealed; }
@@ -102,7 +101,7 @@ namespace SpotiFire {
102101
///
103102
/// <returns> null if it fails, else. </returns>
104103
///-------------------------------------------------------------------------------------------------
105-
virtual AlbumBrowse ^Browse() sealed;
104+
virtual Task<AlbumBrowse ^> ^Browse() sealed;
106105

107106
///-------------------------------------------------------------------------------------------------
108107
/// <summary> Create a <see cref="SpotiFire.Link"/> object representing the album. </summary>
@@ -132,7 +131,7 @@ namespace SpotiFire {
132131
///
133132
/// <returns> true if the given object is equal to the album, otherwise false. </returns>
134133
///-------------------------------------------------------------------------------------------------
135-
virtual bool Equals(Object^ other) override;
134+
virtual bool Equals(Object ^other) override;
136135

137136
///-------------------------------------------------------------------------------------------------
138137
/// <summary> Checks if the given albums should be considered equal. </summary>
@@ -144,7 +143,7 @@ namespace SpotiFire {
144143
///
145144
/// <returns> true if the given albums are equal, otherwise false. </returns>
146145
///-------------------------------------------------------------------------------------------------
147-
static bool operator== (Album^ left, Album^ right);
146+
static bool operator== (Album ^left, Album ^right);
148147

149148
///-------------------------------------------------------------------------------------------------
150149
/// <summary> Checks if the given albums should not be considered equal. </summary>
@@ -156,6 +155,6 @@ namespace SpotiFire {
156155
///
157156
/// <returns> true if the given albums are not equal, otherwise false. </returns>
158157
///-------------------------------------------------------------------------------------------------
159-
static bool operator!= (Album^ left, Album^ right);
158+
static bool operator!= (Album ^left, Album ^right);
160159
};
161160
}

SpotiFire.LibSpotify/Albumbrowse.cpp

+20-43
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "Albumbrowse.h"
44
#define SP_TYPE(type_name, ptrPtr) (type_name *)(void *)ptrPtr
55

6-
76
AlbumBrowse::AlbumBrowse(SpotiFire::Session ^session, sp_albumbrowse *ptr) {
87
SPLock lock;
98
_session = session;
@@ -64,7 +63,7 @@ ref class $AlbumBrowse$CopyrightsArray sealed : ReadOnlyList<String ^>
6463
};
6564

6665
IList<String ^> ^AlbumBrowse::Copyrights::get() {
67-
if(_copyrights == nullptr) {
66+
if (_copyrights == nullptr) {
6867
Interlocked::CompareExchange<IList<String ^> ^>(_copyrights, gcnew $AlbumBrowse$CopyrightsArray(this), nullptr);
6968
}
7069
return _copyrights;
@@ -94,66 +93,44 @@ ref class $AlbumBrowse$TracksArray sealed : ReadOnlyList<Track ^>
9493
};
9594

9695
IList<Track ^> ^AlbumBrowse::Tracks::get() {
97-
if(_tracks == nullptr) {
96+
if (_tracks == nullptr) {
9897
Interlocked::CompareExchange<IList<Track ^> ^>(_tracks, gcnew $AlbumBrowse$TracksArray(this), nullptr);
9998
}
10099
return _tracks;
101100
}
102101

103-
void SP_CALLCONV completed(sp_albumbrowse *browse, void *userdata);
104-
AlbumBrowse ^AlbumBrowse::Create(SpotiFire::Session ^session, SpotiFire::Album ^album) {
105-
SPLock lock;
106-
gcroot<AlbumBrowse ^> *box = new gcroot<AlbumBrowse ^>();
107-
sp_albumbrowse *ptr = sp_albumbrowse_create(session->_ptr, album->_ptr, &completed, box);
108-
AlbumBrowse ^ret = gcnew AlbumBrowse(session, ptr);
109-
sp_albumbrowse_release(ptr);
110-
*box = ret;
111-
return ret;
112-
}
102+
Task<AlbumBrowse ^> ^AlbumBrowse::Create(SpotiFire::Session ^session, SpotiFire::Album ^album) {
103+
typedef NativeTuple2<gcroot<TaskCompletionSource<AlbumBrowse ^> ^>, gcroot<SpotiFire::Session ^>> callbackdata;
113104

114-
//------------------------------------------
115-
// Await
116-
void SP_CALLCONV completed(sp_albumbrowse *albumbrowse, void *userdata) {
117-
TP0(SP_DATA_REM(AlbumBrowse, userdata), AlbumBrowse::complete);
118-
}
105+
auto tcs = gcnew TaskCompletionSource<AlbumBrowse ^>();
106+
auto tcs_box = new gcroot<TaskCompletionSource<AlbumBrowse ^> ^>(tcs);
107+
auto session_box = new gcroot<SpotiFire::Session ^>(session);
108+
auto data = new callbackdata(tcs_box, session_box);
119109

120-
void AlbumBrowse::complete() {
121-
TaskCompletionSource<AlbumBrowse ^> ^tcs = nullptr;
122-
{
123-
SPLock lock;
124-
tcs = _tcs;
125-
_complete = true;
126-
}
127-
if(tcs != nullptr)
128-
tcs->SetResult(this);
129-
}
110+
SPLock lock;
111+
sp_albumbrowse_create(session->_ptr, album->_ptr, [](sp_albumbrowse *albumbrowse, void *userdata) {
112+
auto data = static_cast<callbackdata *>(userdata);
113+
TaskCompletionSource<AlbumBrowse ^> ^tcs = *data->obj1;
114+
SpotiFire::Session ^session = *data->obj2;
115+
tcs->SetResult(gcnew AlbumBrowse(session, albumbrowse));
116+
delete data;
117+
}, data);
130118

131-
System::Runtime::CompilerServices::TaskAwaiter<AlbumBrowse ^> AlbumBrowse::GetAwaiter() {
132-
TaskCompletionSource<AlbumBrowse ^> ^tcs = nullptr;
133-
{
134-
SPLock lock;
135-
if(_tcs == nullptr) {
136-
_tcs = gcnew TaskCompletionSource<AlbumBrowse ^>();
137-
if(_complete)
138-
_tcs->SetResult(this);
139-
}
140-
tcs = _tcs;
141-
}
142-
return tcs->Task->GetAwaiter();
119+
return tcs->Task;
143120
}
144121

145122
int AlbumBrowse::GetHashCode() {
146123
return (new IntPtr(_ptr))->GetHashCode();
147124
}
148125

149-
bool AlbumBrowse::Equals(Object^ other) {
126+
bool AlbumBrowse::Equals(Object ^other) {
150127
return other != nullptr && GetType() == other->GetType() && GetHashCode() == other->GetHashCode();
151128
}
152129

153-
bool AlbumBrowse::operator== (AlbumBrowse^ left, AlbumBrowse^ right) {
130+
bool AlbumBrowse::operator== (AlbumBrowse ^left, AlbumBrowse ^right) {
154131
return Object::ReferenceEquals(left, right) || (!Object::ReferenceEquals(left, nullptr) && left->Equals(right));
155132
}
156133

157-
bool AlbumBrowse::operator!= (AlbumBrowse^ left, AlbumBrowse^ right) {
134+
bool AlbumBrowse::operator!= (AlbumBrowse ^left, AlbumBrowse ^right) {
158135
return !(left == right);
159136
}

SpotiFire.LibSpotify/Albumbrowse.h

+6-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using namespace System;
77
using namespace System::Collections::Generic;
88

99
namespace SpotiFire {
10-
1110
ref class AlbumBrowse;
1211
ref class Album;
1312
ref class Artist;
@@ -27,15 +26,12 @@ namespace SpotiFire {
2726
///
2827
/// <remarks> Aleksander, 30.01.2013. </remarks>
2928
///-------------------------------------------------------------------------------------------------
30-
public ref class AlbumBrowse sealed : ISpotifyObject, ISpotifyAwaitable<AlbumBrowse ^>
29+
public ref class AlbumBrowse sealed : ISpotifyObject
3130
{
3231
private:
3332
IList<String ^> ^_copyrights;
3433
IList<Track ^> ^_tracks;
3534

36-
volatile bool _complete;
37-
TaskCompletionSource<AlbumBrowse ^> ^_tcs;
38-
3935
internal:
4036
Session ^_session;
4137
sp_albumbrowse *_ptr;
@@ -44,8 +40,6 @@ namespace SpotiFire {
4440
!AlbumBrowse(); // finalizer
4541
~AlbumBrowse(); // destructor
4642

47-
48-
4943
public:
5044

5145
///-------------------------------------------------------------------------------------------------
@@ -103,7 +97,7 @@ namespace SpotiFire {
10397
/// <value> The review. </value>
10498
///-------------------------------------------------------------------------------------------------
10599
virtual property String ^Review { String ^get() sealed; }
106-
100+
107101
///-------------------------------------------------------------------------------------------------
108102
/// <summary> Gets the hash code for this albumbrowse object. </summary>
109103
///
@@ -124,7 +118,7 @@ namespace SpotiFire {
124118
/// <returns> true if the given object is equal to the albumbrowse object, otherwise
125119
/// false. </returns>
126120
///-------------------------------------------------------------------------------------------------
127-
virtual bool Equals(Object^ other) override;
121+
virtual bool Equals(Object ^other) override;
128122

129123
///-------------------------------------------------------------------------------------------------
130124
/// <summary> Checks if the given albumbrowse objects should be considered equal. </summary>
@@ -136,7 +130,7 @@ namespace SpotiFire {
136130
///
137131
/// <returns> true if the given albumbrowse objects are equal, otherwise false. </returns>
138132
///-------------------------------------------------------------------------------------------------
139-
static bool operator== (AlbumBrowse^ left, AlbumBrowse^ right);
133+
static bool operator== (AlbumBrowse ^left, AlbumBrowse ^right);
140134

141135
///-----------------------------------------------------------------------------------------------
142136
/// <summary> Checks if the given albumbrowse objects should not be considered equal. </summary>
@@ -148,15 +142,9 @@ namespace SpotiFire {
148142
///
149143
/// <returns> true if the given albumbrowse objects are not equal, otherwise false. </returns>
150144
///-------------------------------------------------------------------------------------------------
151-
static bool operator!= (AlbumBrowse^ left, AlbumBrowse^ right);
152-
153-
public:
154-
virtual System::Runtime::CompilerServices::TaskAwaiter<AlbumBrowse ^> GetAwaiter() sealed = ISpotifyAwaitable<AlbumBrowse ^>::GetAwaiter;
145+
static bool operator!= (AlbumBrowse ^left, AlbumBrowse ^right);
155146

156147
internal:
157-
static AlbumBrowse ^Create(SpotiFire::Session ^session, SpotiFire::Album ^album);
158-
159-
// Events
160-
void complete();
148+
static Task<AlbumBrowse ^> ^Create(SpotiFire::Session ^session, SpotiFire::Album ^album);
161149
};
162150
}

SpotiFire.LibSpotify/Artist.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ String ^Artist::Name::get() {
4343
return UTF8(sp_artist_name(_ptr));
4444
}
4545

46-
ArtistBrowse ^Artist::Browse(ArtistBrowseType type) {
46+
Task<ArtistBrowse ^> ^Artist::Browse(ArtistBrowseType type) {
4747
return ArtistBrowse::Create(_session, this, type);
4848
}
4949

SpotiFire.LibSpotify/Artist.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using namespace System;
77
using namespace System::Collections::Generic;
88

99
namespace SpotiFire {
10-
1110
ref class ArtistBrowse;
1211
ref class Link;
1312

@@ -65,7 +64,7 @@ namespace SpotiFire {
6564
///
6665
/// <returns> The newly created albumbrowse. </returns>
6766
///-------------------------------------------------------------------------------------------------
68-
virtual ArtistBrowse ^Browse(ArtistBrowseType type) sealed;
67+
virtual Task<ArtistBrowse ^> ^Browse(ArtistBrowseType type) sealed;
6968

7069
///-------------------------------------------------------------------------------------------------
7170
/// <summary> Create a <see cref="SpotiFire.Link"/> object representing the artist. </summary>
@@ -95,7 +94,7 @@ namespace SpotiFire {
9594
///
9695
/// <returns> true if the given object is equal to the artist, otherwise false. </returns>
9796
///-------------------------------------------------------------------------------------------------
98-
virtual bool Equals(Object^ other) override;
97+
virtual bool Equals(Object ^other) override;
9998

10099
///-------------------------------------------------------------------------------------------------
101100
/// <summary> Checks if the given artists should be considered equal. </summary>
@@ -107,9 +106,9 @@ namespace SpotiFire {
107106
///
108107
/// <returns> true if the given artists are equal, otherwise false. </returns>
109108
///-------------------------------------------------------------------------------------------------
110-
static bool operator== (Artist^ left, Artist^ right);
109+
static bool operator== (Artist ^left, Artist ^right);
111110

112-
///-------------------------------------------------------------------------------------------------
111+
///-------------------------------------------------------------------------------------------------
113112
/// <summary> Checks if the given artists should not be considered equal. </summary>
114113
///
115114
/// <remarks> Chris Brandhorst, 16.05.2013. </remarks>
@@ -119,6 +118,6 @@ namespace SpotiFire {
119118
///
120119
/// <returns> true if the given artists are not equal, otherwise false. </returns>
121120
///-------------------------------------------------------------------------------------------------
122-
static bool operator!= (Artist^ left, Artist^ right);
121+
static bool operator!= (Artist ^left, Artist ^right);
123122
};
124123
}

0 commit comments

Comments
 (0)