ocarina/libsaria/sources/queue/queue.py
Bryan Schumaker c4629024a6 libsaria: Add ids to queue visible set
When adding songs to the queue, we also need to add the ids to the
visible set if they are visible.  Without this step, we won't have an
easy way of knowing how many IDs are visible.
2011-05-23 09:18:30 -04:00

45 lines
761 B
Python

# Bryan Schumaker (5 / 7 / 2011)
import threading
from libsaria import callbacks
queue_lock = threading.Lock()
lock_queue = queue_lock.acquire
unlock_queue = queue_lock.release
# List of queued songs
queue_list = []
def add_ids(id_list):
lock_queue()
queue_list.extend(id_list)
unlock_queue()
def rm_ids(id_list):
lock_queue()
for id in id_list:
if id in queue_list:
queue_list.remove(id)
unlock_queue()
callbacks.queue_changed()
def pop():
lock_queue()
id = None
if len(queue_list) > 0:
id = queue_list.pop(0)
unlock_queue()
callbacks.queue_changed()
return id
def reset():
global queue_list
lock_queue()
queue_list = []
unlock_queue()
def as_set():
lock_queue()
song_set = set(queue_list)
unlock_queue()
return song_set