Module: Hallon::Observable::Playlist

Included in:
Playlist
Defined in:
lib/hallon/observable/playlist.rb

Overview

Callbacks related to Playlist objects.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(other) ⇒ Object

Includes Hallon::Observable for you.


5
6
7
# File 'lib/hallon/observable/playlist.rb', line 5

def self.extended(other)
  other.send(:include, Hallon::Observable)
end

Instance Method Details

#description_changed_callback(pointer, description, userdata) {|description| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:description_changed) do |description, playlist|
  puts "#{playlist.name} new description: #{description}"
end

Yields:

  • (description)

    description_changed

Yield Parameters:

  • description (String)

148
149
150
# File 'lib/hallon/observable/playlist.rb', line 148

def description_changed_callback(pointer, description, userdata)
  trigger(pointer, :description_changed, description)
end

#image_changed_callback(pointer, image, userdata) {|image| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:image_changed) do |image, playlist|
  puts "#{playlist.name} has got a new image: #{image.to_link}"
end

Yields:

  • (image)

    image_changed

Yield Parameters:

  • image (Image, nil)

    or nil


159
160
161
162
# File 'lib/hallon/observable/playlist.rb', line 159

def image_changed_callback(pointer, image, userdata)
  image = Hallon::Image.from(image)
  trigger(pointer, :image_changed, image)
end

#initialize_callbacksSpotify::PlaylistCallbacks (protected)

Returns:

  • (Spotify::PlaylistCallbacks)

12
13
14
15
16
17
18
# File 'lib/hallon/observable/playlist.rb', line 12

def initialize_callbacks
  struct = Spotify::PlaylistCallbacks.new
  struct.members.each do |member|
    struct[member] = callback_for(member)
  end
  struct
end

#playlist_metadata_updated_callback(pointer, userdata) { ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:playlist_metadata_updated) do |playlist|
  puts "#{playlist.name} metadata updated"
end

Yields:

  • [] playlist_metadata_updated


97
98
99
# File 'lib/hallon/observable/playlist.rb', line 97

def (pointer, userdata)
  trigger(pointer, :playlist_metadata_updated)
end

#playlist_renamed_callback(pointer, userdata) { ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:playlist_renamed) do |playlist|
  puts "#{playlist.name} was now previously named something else \o/"
end

Yields:

  • [] playlist_renamed


66
67
68
# File 'lib/hallon/observable/playlist.rb', line 66

def playlist_renamed_callback(pointer, userdata)
  trigger(pointer, :playlist_renamed)
end

#playlist_state_changed_callback(pointer, userdata) { ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:playlist_state_changed) do |playlist|
  puts "playlist state changed… to what? from what? D:"
end

Yields:

  • [] playlist_state_changed


76
77
78
# File 'lib/hallon/observable/playlist.rb', line 76

def playlist_state_changed_callback(pointer, userdata)
  trigger(pointer, :playlist_state_changed)
end

#playlist_update_in_progress_callback(pointer, done, userdata) {|is_done| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:playlist_update_in_progress) do |is_done, playlist|
  puts(is_done ? "DONE!" : "not done :(")
end

Yields:

  • (is_done)

    playlist_update_in_progress

Yield Parameters:

  • is_done (Boolean)

87
88
89
# File 'lib/hallon/observable/playlist.rb', line 87

def playlist_update_in_progress_callback(pointer, done, userdata)
  trigger(pointer, :playlist_update_in_progress, done)
end

#subscribers_changed_callback(pointer, userdata) { ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:subscribers_changed) do |playlist|
  puts "#{playlist.name} updated its’ subscribers"
end

Yields:

  • [] subscribers_changed


170
171
172
# File 'lib/hallon/observable/playlist.rb', line 170

def subscribers_changed_callback(pointer, userdata)
  trigger(pointer, :subscribers_changed)
end

#track_created_changed_callback(pointer, position, user, created_at, userdata) {|position, user, created_at| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:track_created_changed) do |position, user, created_at, playlist|
  track = playlist.tracks[position]
  puts "#{track.name} created-info changed"
end

Yields:

  • (position, user, created_at)

    track_created_changed

Yield Parameters:

  • position (Integer)
  • user (User)
  • created_at (Time)

111
112
113
# File 'lib/hallon/observable/playlist.rb', line 111

def track_created_changed_callback(pointer, position, user, created_at, userdata)
  trigger(pointer, :track_created_changed, position, Hallon::User.from(user), Time.at(created_at))
end

#track_message_changed_callback(pointer, position, message, userdata) {|position, message| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:track_message_changed) do |position, message, playlist|
  track = playlist.tracks[position]
  puts "#{track.name} new message: #{message}"
end

Yields:

  • (position, message)

    track_message_changed

Yield Parameters:

  • position (Integer)
  • message (String)

137
138
139
# File 'lib/hallon/observable/playlist.rb', line 137

def track_message_changed_callback(pointer, position, message, userdata)
  trigger(pointer, :track_message_changed, position, message)
end

#track_seen_changed_callback(pointer, position, seen, userdata) {|position, is_seen| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:track_seen_changed) do |position, seen, playlist|
  track = playlist.tracks[position]
  puts "#{track.name}#seen? is #{seen}"
end

Yields:

  • (position, is_seen)

    track_seen_changed

Yield Parameters:

  • position (Integer)
  • is_seen (Boolean)

124
125
126
# File 'lib/hallon/observable/playlist.rb', line 124

def track_seen_changed_callback(pointer, position, seen, userdata)
  trigger(pointer, :track_seen_changed, position, seen)
end

#tracks_added_callback(pointer, tracks, num_tracks, position, userdata) {|tracks, position| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:tracks_added) do |tracks, position, playlist|
  puts "#{tracks.map(&:name).join(', ')} added at #{position} to #{playlist.name}"
end

Yields:

  • (tracks, position)

    tracks_added

Yield Parameters:

  • tracks (Array<Track>)
  • position (Integer)

28
29
30
31
32
33
34
35
# File 'lib/hallon/observable/playlist.rb', line 28

def tracks_added_callback(pointer, tracks, num_tracks, position, userdata)
  tracks_ary = tracks.read_array_of_pointer(num_tracks).map do |track|
    ptr = Spotify::Track.retaining_class.new(track)
    Hallon::Track.new(ptr)
  end

  trigger(pointer, :tracks_added, tracks_ary, position)
end

#tracks_moved_callback(pointer, track_indices, num_indices, new_position, userdata) {|tracks, new_position| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:tracks_moved) do |tracks, new_position, playlist|
  puts "#{tracks.map(&:name).join(', ')} moved to #{new_position} to #{playlist.name}"
end

Yields:

  • (tracks, new_position)

    tracks_moved

Yield Parameters:

  • tracks (Array<Track>)
  • new_position (Integer)

56
57
58
# File 'lib/hallon/observable/playlist.rb', line 56

def tracks_moved_callback(pointer, track_indices, num_indices, new_position, userdata)
  trigger(pointer, :tracks_moved, track_indices.read_array_of_int(num_indices), new_position)
end

#tracks_removed_callback(pointer, track_indices, num_indices, userdata) {|tracks| ... } ⇒ Object (protected)

Examples:

listening to this event

playlist.on(:tracks_removed) do |tracks, playlist|
  puts "#{tracks.map(&:name).join(', ') removed from #{playlist.name}"
end

Yields:

  • (tracks)

    tracks_removed

Yield Parameters:


44
45
46
# File 'lib/hallon/observable/playlist.rb', line 44

def tracks_removed_callback(pointer, track_indices, num_indices, userdata)
  trigger(pointer, :tracks_removed, track_indices.read_array_of_int(num_indices))
end