# Bryan Schumaker (11/07/2010)

import libsaria
import playlist
import next

# Function pointers for convenience
add_ids = playlist.add_ids

playlist.load()
visible = playlist.as_set()

def add_ids(ids):
	for id in ids:
		if libsaria.sources.is_visible(id):
			visible.add(id)
	playlist.add_ids(ids)

def rm_ids(ids):
	global visible
	visible = visible - set(ids)
	playlist.rm_ids(ids)

def reset():
	global visible
	visible = set()
	playlist.reset()

def list_ids():
	for id in playlist.song_list:
		yield id

def set_visible(vset):
	global visible
	visible = playlist.as_set().intersection(vset)

def num_visible():
	return len(visible)

def get_next(cur_id):
	id = None
	if libsaria.prefs.get("libsaria.random") == True:
		index = next.rand_next(list(visible))
	else:
		index = next.seq_next(cur_id)
	if index != None:
		id = playlist.get(index)
	if id != None:
		artist, title = libsaria.sources.get_attrs_id(id, "artist", "title")
		next.track_recent(artist, title)
		return id
