The Queue class
- class audiomath.Queue(*sounds)
Bases:
objectA
list-like container forSoundinstances, which keeps track of, and allows manipulation of, which element is considered “current”.You probably do not need to create a
Queueexplicitly yourself. When you create aPlayerinstancep, the propertyp.queuewill automatically be initialized as a newQueuecontaining whatever sounds you specified in thePlayerconstructor call.- Back(count=1)
Move the
positionbackward by the given count (defaults to 1).If
self.loopis False and you try to skip back past the beginning of the queue, aQueueErrorwill 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
Queueis inside aPlayerinstance, because it will not automatically update the player’ssoundproperty. Instead, use the correspondingPlayermethod,PreviousTrack()
- Forward(count=1)
Move the
positionahead by the given count (defaults to 1).If
self.loopis False, and you try to skip past the end of the queue, aQueueErrorwill 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
Queueis inside aPlayerinstance, because it will not automatically update the player’ssoundproperty. Instead, use the correspondingPlayermethod,NextTrack()
- MoveSound(oldIndex, newIndex)
Move sound from
oldIndextonewIndex. Negative indices are acceptable.
- Play(*pargs, **kwargs)
This quick-and-dirty method allows you to play a
Queue. It creates aPlayerinstance 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 thePlayeragain.You will get a better user experience, and better performance, if you explicitly create a
Playerinstance of your own and work with that.Arguments are passed through to the
Player.Play()method.
- SwapSounds(firstIndex, secondIndex)
Swap sound at
firstIndexwith 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 singleSoundinstance, or a sequence ofSoundinstances.Any arguments that are not already
Soundinstances (e.g. filenames) will be passed to theSoundconstructor 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 singleSoundinstance, or a sequence ofSoundinstances.Any arguments that are not already
Soundinstances (e.g. filenames) will be passed to theSoundconstructor 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 singleSoundinstance, or a sequence ofSoundinstances.Any arguments that are not already
Soundinstances (e.g. filenames) will be passed to theSoundconstructor to create such instances, along with any additional keyword arguments.
- index(arg)
Given a
Soundinstance that is in the queue, or itslabel, return its non-negative integer index within the queue. Raise aValueErrorif 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
Soundinstances (e.g. filenames) will be passed to theSoundconstructor to create such instances, along with any additional keyword arguments.
- pop(index, default=Unspecified)
Remove the
Soundwith the given label or index and return it. If it is not found in the list, returndefaultif specified (otherwise raise aKeyError).
- remove(item_or_index)
Given either a
Soundinstance, its label, or its index within the list, remove it from the queue. Returnself.
- property position
Zero-based numeric index of
currentSoundwithin the list.When assigning, you may also use a
Soundinstance or itslabel, provided that instance is in the list.