Class: GreenStripes::Playlist
- Inherits:
-
Object
- Object
- GreenStripes::Playlist
- Defined in:
- lib/greenstripes.rb,
ext/greenstripes/greenstripes.c
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#add_tracks(tracks, position) ⇒ Object
Add tracks at position in the playlist.
-
#collaborative=(true) ⇒ Boolean
Sets the collaborative status of the playlist.
-
#collaborative? ⇒ Boolean
Returns true if the playlist is collaborative, false otherwise.
-
#loaded? ⇒ Boolean
Returns true if the playlist is loaded, false otherwise.
-
#name ⇒ String?
Returns the playlist’s name.
-
#name=(new_name) ⇒ String?
Sets the playlist’s name to the value of new_name.
- #num_tracks ⇒ Fixnum?
-
#owner ⇒ nil
Returns the playlist’s owner.
-
#pending_changes? ⇒ Boolean
Returns true if the playlist has local changes that have not yet been acknowledged by the server, false otherwise.
-
#remove_tracks(indices) ⇒ Object
Remove the tracks at indices from the playlist.
-
#reorder_tracks(indices, new_position) ⇒ Object
Move the tracks at indices to new_position in the playlist.
- #to_link ⇒ Object
- #track(index) ⇒ nil
- #tracks ⇒ Object
Instance Method Details
#==(other) ⇒ Object
55 56 57 |
# File 'lib/greenstripes.rb', line 55 def ==(other) self.to_link == other.to_link end |
#add_tracks(tracks, position) ⇒ Object
Add tracks at position in the playlist.
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'ext/greenstripes/greenstripes.c', line 452
static VALUE playlist_add_tracks(VALUE self, VALUE tracks, VALUE position)
{
sp_playlist *p;
Data_Get_Struct(self, sp_playlist, p);
int n = rb_ary_length(tracks);
const sp_track **ts = malloc(n*sizeof(sp_track *));
int i;
for(i = 0; i < n; ++i)
{
sp_track *t;
Data_Get_Struct(rb_ary_entry(tracks, i), sp_track, t);
ts[i] = t;
}
sp_error e = sp_playlist_add_tracks(p, ts, n, FIX2INT(position));
free(ts);
return INT2FIX(e);
}
|
#collaborative=(true) ⇒ Boolean
Sets the collaborative status of the playlist.
400 401 402 403 404 405 406 |
# File 'ext/greenstripes/greenstripes.c', line 400
static VALUE playlist_collaborative_set(VALUE self, VALUE collaborative)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
sp_playlist_set_collaborative(playlist, collaborative != Qnil && collaborative != Qfalse);
return collaborative;
}
|
#collaborative? ⇒ Boolean
Returns true if the playlist is collaborative, false otherwise.
388 389 390 391 392 393 |
# File 'ext/greenstripes/greenstripes.c', line 388
static VALUE playlist_collaborative(VALUE self)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
return sp_playlist_is_collaborative(playlist) ? Qtrue : Qfalse;
}
|
#loaded? ⇒ Boolean
Returns true if the playlist is loaded, false otherwise.
330 331 332 333 334 335 |
# File 'ext/greenstripes/greenstripes.c', line 330
static VALUE playlist_loaded(VALUE self)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
return sp_playlist_is_loaded(playlist) ? Qtrue : Qfalse;
}
|
#name ⇒ String?
Returns the playlist’s name.
342 343 344 345 346 347 348 |
# File 'ext/greenstripes/greenstripes.c', line 342
static VALUE playlist_name(VALUE self)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
const char *name = sp_playlist_name(playlist);
return name ? rb_str_new2(name) : Qnil;
}
|
#name=(new_name) ⇒ String?
Sets the playlist’s name to the value of new_name.
355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'ext/greenstripes/greenstripes.c', line 355
static VALUE playlist_name_set(VALUE self, VALUE new_name)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
sp_error error = sp_playlist_rename(playlist, StringValuePtr(new_name));
// TODO: throw exception instead?
if(error != SP_ERROR_OK)
return Qnil;
return new_name;
}
|
#num_tracks ⇒ Fixnum?
412 413 414 415 416 417 418 |
# File 'ext/greenstripes/greenstripes.c', line 412
static VALUE playlist_num_tracks(VALUE self)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
int n = sp_playlist_num_tracks(playlist);
return (n >= 0) ? INT2FIX(n) : Qnil;
}
|
#owner ⇒ nil
Returns the playlist’s owner.
374 375 376 377 378 379 380 381 |
# File 'ext/greenstripes/greenstripes.c', line 374
static VALUE playlist_owner(VALUE self)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
sp_user *user = NULL;
user = sp_playlist_owner(playlist);
return user ? Data_Wrap_Struct(class_user, NULL, NULL, user) : Qnil;
}
|
#pending_changes? ⇒ Boolean
Returns true if the playlist has local changes that have not yet been acknowledged by the server, false otherwise.
440 441 442 443 444 445 |
# File 'ext/greenstripes/greenstripes.c', line 440
static VALUE playlist_pending_changes(VALUE self)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
return sp_playlist_has_pending_changes(playlist) ? Qtrue : Qfalse;
}
|
#remove_tracks(indices) ⇒ Object
Remove the tracks at indices from the playlist.
475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'ext/greenstripes/greenstripes.c', line 475
static VALUE playlist_remove_tracks(VALUE self, VALUE indices)
{
sp_playlist *p;
Data_Get_Struct(self, sp_playlist, p);
int n = rb_ary_length(indices);
int *is = malloc(n*sizeof(int));
int i;
for(i = 0; i < n; ++i)
is[i] = FIX2INT(rb_ary_entry(indices, i));
sp_error e = sp_playlist_remove_tracks(p, is, n);
free(is);
return INT2FIX(e);
}
|
#reorder_tracks(indices, new_position) ⇒ Object
Move the tracks at indices to new_position in the playlist.
494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'ext/greenstripes/greenstripes.c', line 494
static VALUE playlist_reorder_tracks(VALUE self, VALUE indices, VALUE new_position)
{
sp_playlist *p;
Data_Get_Struct(self, sp_playlist, p);
int n = rb_ary_length(indices);
int *is = malloc(n*sizeof(int));
int i;
for(i = 0; i < n; ++i)
is[i] = FIX2INT(rb_ary_entry(indices, i));
sp_error e = sp_playlist_reorder_tracks(p, is, n, FIX2INT(new_position));
free(is);
return INT2FIX(e);
}
|
#track(index) ⇒ nil
424 425 426 427 428 429 430 431 432 |
# File 'ext/greenstripes/greenstripes.c', line 424
static VALUE playlist_track(VALUE self, VALUE index)
{
sp_playlist *playlist;
Data_Get_Struct(self, sp_playlist, playlist);
int i = FIX2INT(index);
sp_track *track = NULL;
track = sp_playlist_track(playlist, i);
return track ? Data_Wrap_Struct(class_track, NULL, NULL, track) : Qnil;
}
|