libsaria: Move actual queue to new file
I pulled out the queue and put it in a new file. I also created simple add, remove, pop and reset functions.
This commit is contained in:
parent
c35b452ec3
commit
2c185dec83
|
@ -1,39 +1,33 @@
|
|||
# Bryan Schumaker (12/12/2010)
|
||||
|
||||
import threading
|
||||
queue_lock = threading.Lock()
|
||||
lock_queue = queue_lock.acquire
|
||||
unlock_queue = queue_lock.release
|
||||
|
||||
import libsaria
|
||||
import queue
|
||||
|
||||
library = None
|
||||
source = None
|
||||
|
||||
queue = []
|
||||
song_set = set()
|
||||
|
||||
filtered = False
|
||||
visible = None
|
||||
|
||||
def add_id(id):
|
||||
if id not in song_set:
|
||||
queue.append(id)
|
||||
song_set.add(id)
|
||||
def add_ids(id_list):
|
||||
lock_queue()
|
||||
queue.add_ids(id_list)
|
||||
unlock_queue()
|
||||
|
||||
def add_ids(ids):
|
||||
for id in ids:
|
||||
add_id(id)
|
||||
|
||||
def rm_id(id):
|
||||
if id in queue:
|
||||
queue.remove(id)
|
||||
song_set.remove(id)
|
||||
|
||||
def rm_ids(ids):
|
||||
for id in ids:
|
||||
rm_id(id)
|
||||
def rm_ids(id_list):
|
||||
lock_queue()
|
||||
queue.rm_ids(id_list)
|
||||
unlock_queue()
|
||||
|
||||
def reset():
|
||||
global queue
|
||||
global song_set
|
||||
queue = []
|
||||
song_set = set()
|
||||
lock_queue()
|
||||
queue.reset()
|
||||
unlock_queue()
|
||||
|
||||
def init():
|
||||
global library
|
||||
|
@ -53,7 +47,7 @@ def init_bg():
|
|||
init()
|
||||
|
||||
def walk():
|
||||
for id in queue:
|
||||
for id in queue.queue_list:
|
||||
yield id
|
||||
|
||||
def walk_queue(*attrs):
|
||||
|
@ -82,7 +76,7 @@ def is_visible(id):
|
|||
def num_visible():
|
||||
if filtered == True:
|
||||
return len(visible)
|
||||
return len(queue)
|
||||
return len(queue.queue_list)
|
||||
|
||||
def load_id(id):
|
||||
global cur_id
|
||||
|
@ -99,10 +93,11 @@ def play_id(id):
|
|||
|
||||
def next():
|
||||
global cur_id
|
||||
if len(queue) == 0:
|
||||
if len(queue.queue_list) == 0:
|
||||
return None
|
||||
cur_id = queue.pop(0)
|
||||
song_set.remove(cur_id)
|
||||
lock_queue()
|
||||
cur_id = queue.pop()
|
||||
unlock_queue()
|
||||
source.set_current()
|
||||
return library.get_attrs(cur_id, "filepath")
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Bryan Schumaker (5 / 7 / 2011)
|
||||
# WARNING: THESE FUNCTIONS DIRECTLY MANIPULATE THE QUEUE.
|
||||
# YOU SHOULD BE HOLDING THE queue_lock LOCATED IN __init__.py
|
||||
# BEFORE CALLING ANYTHING HERE.
|
||||
|
||||
# List of queued songs
|
||||
queue_list = []
|
||||
|
||||
def add_ids(id_list):
|
||||
queue_list.extend(id_list)
|
||||
|
||||
def rm_ids(id_list):
|
||||
for id in id_list:
|
||||
if id in queue_list:
|
||||
queue_list.remove(id)
|
||||
|
||||
def pop():
|
||||
if len(queue_list) > 0:
|
||||
return queue_list.pop(0)
|
||||
return None
|
||||
|
||||
def reset():
|
||||
global queue_list
|
||||
queue_list = []
|
Loading…
Reference in New Issue