-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathplaylist.cc
More file actions
325 lines (245 loc) · 10.7 KB
/
playlist.cc
File metadata and controls
325 lines (245 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* =====================================================================================
*
* Filename: playlist.cc
*
* Description: Bindings for the playlist submodule
*
* Version: 1.0
* Created: 30/03/2013 11:58:58
* Revision: none
* Compiler: gcc
*
* Author: Iain Cole, iaincole1@gmail.com
* Company: Iain Cole
*
* =====================================================================================
*/
#include "common.h"
#include "playlistcallbacks.cc"
#include <stdlib.h>
using namespace v8;
using namespace nsp;
/*
* PLAYLIST CONTAINER
*/
/**
* JS playlistcontainer_is_loaded implementation. checks if a given playlistcontainer is loaded
*/
static Handle<Value> PlaylistContainer_Is_Loaded(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlistcontainer>* playlistcontainer = ObjectHandle<sp_playlistcontainer>::Unwrap(args[0]);
// actually call sp_playlistcontainer_is_loaded
bool loaded = sp_playlistcontainer_is_loaded(playlistcontainer->pointer);
return scope.Close(Boolean::New(loaded));
}
/**
* JS num playlists implementation.
*/
static Handle<Value> PlaylistContainer_Num_Playlists(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlistcontainer>* playlistcontainer = ObjectHandle<sp_playlistcontainer>::Unwrap(args[0]);
// actually call sp_playlistcontainer_num_playlists
int numPlaylists = sp_playlistcontainer_num_playlists(playlistcontainer->pointer);
return scope.Close(Number::New(numPlaylists));
}
/**
* JS playlist type implementation.
*/
static Handle<Value> PlaylistContainer_Playlist_Type(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 2);
assert(args[0]->IsObject());
assert(args[1]->IsNumber());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlistcontainer>* playlistcontainer = ObjectHandle<sp_playlistcontainer>::Unwrap(args[0]);
int index = args[1]->ToNumber()->Int32Value();
// actually call sp_playlistcontainer_playlist_type
sp_playlist_type playlistType = sp_playlistcontainer_playlist_type(playlistcontainer->pointer, index);
return scope.Close(Number::New(static_cast<int>(playlistType)));
}
/**
* JS playlist folder id implementation.
*/
static Handle<Value> PlaylistContainer_Playlist_Folder_ID(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 2);
assert(args[0]->IsObject());
assert(args[1]->IsNumber());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlistcontainer>* playlistcontainer = ObjectHandle<sp_playlistcontainer>::Unwrap(args[0]);
int index = args[1]->ToNumber()->Int32Value();
// actually call sp_playlistcontainer_playlist_folder_id
sp_uint64 playlistFolderId = sp_playlistcontainer_playlist_folder_id(playlistcontainer->pointer, index);
return scope.Close(Number::New(playlistFolderId));
}
/**
* JS playlist folder name implementation.
*/
static Handle<Value> PlaylistContainer_Playlist_Folder_Name(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 2);
assert(args[0]->IsObject());
assert(args[1]->IsNumber());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlistcontainer>* playlistcontainer = ObjectHandle<sp_playlistcontainer>::Unwrap(args[0]);
int index = args[1]->ToNumber()->Int32Value();
char nameChars[256];
// actually call sp_playlistcontainer_playlist_folder_name
sp_error error = sp_playlistcontainer_playlist_folder_name(playlistcontainer->pointer, index, nameChars, sizeof(nameChars));
NSP_THROW_IF_ERROR(error);
return scope.Close(String::New(nameChars));
}
/**
* JS playlist implementation. Gets the playlist at index for the playlist container
*/
static Handle<Value> PlaylistContainer_Playlist(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 3);
assert(args[0]->IsObject());
assert(args[1]->IsObject());
assert(args[2]->IsNumber());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlistcontainer>* playlistcontainer = ObjectHandle<sp_playlistcontainer>::Unwrap(args[0]);
// gets sp_session pointer from given object
ObjectHandle<sp_session>* session = ObjectHandle<sp_session>::Unwrap(args[1]);
int index = args[2]->ToNumber()->Int32Value();
assert(index >= 0);
assert(index < sp_playlistcontainer_num_playlists(playlistcontainer->pointer));
// actually call sp_playlistcontainer_playlist
sp_playlist* spplaylist = sp_playlistcontainer_playlist(playlistcontainer->pointer, index);
// Set the playlist in RAM
sp_playlist_set_in_ram(session->pointer, spplaylist, true);
ObjectHandle<sp_playlist>* playlist = new ObjectHandle<sp_playlist>("sp_playlist");
playlist->pointer = spplaylist;
sp_error error = sp_playlist_add_callbacks(spplaylist, &nsp_playlist_callbacks, playlist);
NSP_THROW_IF_ERROR(error);
return scope.Close(playlist->object);
}
void nsp::init_playlistcontainer(Handle<Object> target) {
NODE_SET_METHOD(target, "playlistcontainer_is_loaded", PlaylistContainer_Is_Loaded);
NODE_SET_METHOD(target, "playlistcontainer_num_playlists", PlaylistContainer_Num_Playlists);
NODE_SET_METHOD(target, "playlistcontainer_playlist_type", PlaylistContainer_Playlist_Type);
NODE_SET_METHOD(target, "playlistcontainer_playlist_folder_id", PlaylistContainer_Playlist_Folder_ID);
NODE_SET_METHOD(target, "playlistcontainer_playlist_folder_name", PlaylistContainer_Playlist_Folder_Name);
NODE_SET_METHOD(target, "playlistcontainer_playlist", PlaylistContainer_Playlist);
target->Set(v8::String::NewSymbol("SP_PLAYLIST_TYPE_PLAYLIST"), v8::Int32::New(static_cast<int>(SP_PLAYLIST_TYPE_PLAYLIST)), ReadOnly);
target->Set(v8::String::NewSymbol("SP_PLAYLIST_TYPE_START_FOLDER"), v8::Int32::New(static_cast<int>(SP_PLAYLIST_TYPE_START_FOLDER)), ReadOnly);
target->Set(v8::String::NewSymbol("SP_PLAYLIST_TYPE_END_FOLDER"), v8::Int32::New(static_cast<int>(SP_PLAYLIST_TYPE_END_FOLDER)), ReadOnly);
target->Set(v8::String::NewSymbol("SP_PLAYLIST_TYPE_PLACEHOLDER"), v8::Int32::New(static_cast<int>(SP_PLAYLIST_TYPE_PLACEHOLDER)), ReadOnly);
}
/*
* PLAYLIST
*/
/**
* JS playlist_is_loaded implementation. checks if a given playlist is loaded
*/
static Handle<Value> Playlist_Is_Loaded(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlist>* playlist = ObjectHandle<sp_playlist>::Unwrap(args[0]);
// actually call sp_playlistcontainer_is_loaded
bool loaded = sp_playlist_is_loaded(playlist->pointer);
return scope.Close(Boolean::New(loaded));
}
/**
* JS playlist_name implementation. return the playlist name
*/
static Handle<Value> Playlist_Name(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject());
// gets sp_playlistcontainer pointer from given object
ObjectHandle<sp_playlist>* playlist = ObjectHandle<sp_playlist>::Unwrap(args[0]);
// actually call sp_playlist_name
const char* name = sp_playlist_name(playlist->pointer);
return scope.Close(String::New(name));
}
/**
* JS num tracks implementation.
*/
static Handle<Value> Playlist_Num_Tracks(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject());
// gets sp_playlist pointer from given object
ObjectHandle<sp_playlist>* playlist = ObjectHandle<sp_playlist>::Unwrap(args[0]);
// actually call sp_playlist_num_tracks
int numTracks = sp_playlist_num_tracks(playlist->pointer);
return scope.Close(Number::New(numTracks));
}
/**
* JS playlist track implementation. Gets the track at index for the playlist
*/
static Handle<Value> Playlist_Track(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 2);
assert(args[0]->IsObject());
assert(args[1]->IsNumber());
// gets sp_playlist pointer from given object
ObjectHandle<sp_playlist>* playlist = ObjectHandle<sp_playlist>::Unwrap(args[0]);
int index = args[1]->ToNumber()->Int32Value();
assert(index >= 0);
assert(index < sp_playlist_num_tracks(playlist->pointer));
// actually call sp_playlist_track
sp_track* sptrack = sp_playlist_track(playlist->pointer, index);
ObjectHandle<sp_track>* track = new ObjectHandle<sp_track>("sp_track");
track->pointer = sptrack;
return scope.Close(track->object);
}
/**
* JS playlist num subscribers. Gets the number of subscribers for the playlist
*/
static Handle<Value> Playlist_Update_Subscribers(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 2);
assert(args[0]->IsObject());
assert(args[1]->IsObject());
// gets sp_session pointer from given object
ObjectHandle<sp_session>* session = ObjectHandle<sp_session>::Unwrap(args[0]);
// gets sp_playlist pointer from given object
ObjectHandle<sp_playlist>* playlist = ObjectHandle<sp_playlist>::Unwrap(args[1]);
sp_error error = sp_playlist_update_subscribers(session->pointer, playlist->pointer);
NSP_THROW_IF_ERROR(error);
return scope.Close(Undefined());
}
/**
* JS playlist num subscribers. Gets the number of subscribers for the playlist
*/
static Handle<Value> Playlist_Num_Subscribers(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject());
// gets sp_playlist pointer from given object
ObjectHandle<sp_playlist>* playlist = ObjectHandle<sp_playlist>::Unwrap(args[0]);
int numSubscribers = sp_playlist_num_subscribers(playlist->pointer);
return scope.Close(Number::New(numSubscribers));
}
void nsp::init_playlist(Handle<Object> target) {
NODE_SET_METHOD(target, "playlist_is_loaded", Playlist_Is_Loaded);
NODE_SET_METHOD(target, "playlist_name", Playlist_Name);
NODE_SET_METHOD(target, "playlist_num_tracks", Playlist_Num_Tracks);
NODE_SET_METHOD(target, "playlist_track", Playlist_Track);
NODE_SET_METHOD(target, "playlist_update_subscribers", Playlist_Update_Subscribers);
NODE_SET_METHOD(target, "playlist_num_subscribers", Playlist_Num_Subscribers);
}