The Queue
class
- class audiomath.Queue(*sounds)
Bases:
object
A
list
-like container forSound
instances, which keeps track of, and allows manipulation of, which element is considered “current”.You probably do not need to create a
Queue
explicitly yourself. When you create aPlayer
instancep
, the propertyp.queue
will automatically be initialized as a newQueue
containing whatever sounds you specified in thePlayer
constructor call.- Back(count=1)
Move the
position
backward by the given count (defaults to 1).If
self.loop
is False and you try to skip back past the beginning of the queue, aQueueError
will be raised. Otherwise, it will loop around to the end of the queue.You probably will not want to call this method directly if this
Queue
is inside aPlayer
instance, because it will not automatically update the player’ssound
property. Instead, use the correspondingPlayer
method,PreviousTrack()
- Forward(count=1)
Move the
position
ahead by the given count (defaults to 1).If
self.loop
is False, and you try to skip past the end of the queue, aQueueError
will be raised Otherwise, it will loop back around to the start of the queue.You probably will not want to call this method directly if this
Queue
is inside aPlayer
instance, because it will not automatically update the player’ssound
property. Instead, use the correspondingPlayer
method,NextTrack()
- MoveSound(oldIndex, newIndex)
Move sound from
oldIndex
tonewIndex
. Negative indices are acceptable.
- Play(*pargs, **kwargs)
This quick-and-dirty method allows you to play a
Queue
. It creates aPlayer
instance in verbose mode, configures it withautoAdvance='play'
by default, then uses it to play a copy of the queue from the beginning, waits for it to finish (or for the user to press ctrl-C), and destroys thePlayer
again.You will get a better user experience, and better performance, if you explicitly create a
Player
instance of your own and work with that.Arguments are passed through to the
Player.Play()
method.
- SwapSounds(firstIndex, secondIndex)
Swap sound at
firstIndex
with sound atsecondIndex
. Negative indices are acceptable.
- add(*sounds, **sound_kwargs)
Add a variable number of sounds to the end of the queue. Since nested lists are not allowed,
add()
,extend()
andappend()
are identical: any of them will accept a singleSound
instance, or a sequence ofSound
instances.Any arguments that are not already
Sound
instances (e.g. filenames) will be passed to theSound
constructor to create such instances, along with any additional keyword arguments.
- append(*sounds, **sound_kwargs)
Add a variable number of sounds to the end of the queue. Since nested lists are not allowed,
add()
,extend()
andappend()
are identical: any of them will accept a singleSound
instance, or a sequence ofSound
instances.Any arguments that are not already
Sound
instances (e.g. filenames) will be passed to theSound
constructor to create such instances, along with any additional keyword arguments.
- clear()
Empty the queue.
- extend(*sounds, **sound_kwargs)
Add a variable number of sounds to the end of the queue. Since nested lists are not allowed,
add()
,extend()
andappend()
are identical: any of them will accept a singleSound
instance, or a sequence ofSound
instances.Any arguments that are not already
Sound
instances (e.g. filenames) will be passed to theSound
constructor to create such instances, along with any additional keyword arguments.
- index(arg)
Given a
Sound
instance that is in the queue, or itslabel
, return its non-negative integer index within the queue. Raise aValueError
if no such instance is found in the queue.
- insert(index, *sounds, **sound_kwargs)
Insert one or more sounds into the queue at given
index
.Any arguments that are not already
Sound
instances (e.g. filenames) will be passed to theSound
constructor to create such instances, along with any additional keyword arguments.
- pop(index, default=Unspecified)
Remove the
Sound
with the given label or index and return it. If it is not found in the list, returndefault
if specified (otherwise raise aKeyError
).
- remove(item_or_index)
Given either a
Sound
instance, its label, or its index within the list, remove it from the queue. Returnself
.
- property position
Zero-based numeric index of
currentSound
within the list.When assigning, you may also use a
Sound
instance or itslabel
, provided that instance is in the list.