# Bryan Schumaker (12/12/2010)

import libsaria
from libsaria.sources import library
import queue

filtered = False
visible  = None

# Function pointers for convenience
add_ids = queue.add_ids
rm_ids  = queue.rm_ids
reset   = queue.reset

def list():
	for id in queue.queue_list:
		yield id

def filter(text):
	global visible, filtered
	if len(text) > 0:
		song_set = queue.as_set()
		visible  = song_set.intersection(library.test_filter(text))
		filtered = True
	else:
		visible  = None
		filtered = False

def is_visible(id):
	if filtered == True:
		return id in visible
	return True

def num_visible():
	if filtered == True:
		return len(visible)
	return len(queue.queue_list)

def next():
	return queue.pop()

