The Queue class

class audiomath.Queue(*sounds)

Bases: object

A list-like container for Sound 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 a Player instance p, the property p.queue will automatically be initialized as a new Queue containing whatever sounds you specified in the Player 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, a QueueError 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 a Player instance, because it will not automatically update the player’s sound property. Instead, use the corresponding Player 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, a QueueError 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 a Player instance, because it will not automatically update the player’s sound property. Instead, use the corresponding Player method, NextTrack()

MoveSound(oldIndex, newIndex)

Move sound from oldIndex to newIndex. Negative indices are acceptable.

Play(*pargs, **kwargs)

This quick-and-dirty method allows you to play a Queue. It creates a Player instance in verbose mode, configures it with autoAdvance='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 the Player 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.

Restart()

Move position back to the first sound.

SetPosition(position, allowNegative=True)

Move position to the specified position.

SwapSounds(firstIndex, secondIndex)

Swap sound at firstIndex with sound at secondIndex. 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() and append() are identical: any of them will accept a single Sound instance, or a sequence of Sound instances.

Any arguments that are not already Sound instances (e.g. filenames) will be passed to the Sound 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() and append() are identical: any of them will accept a single Sound instance, or a sequence of Sound instances.

Any arguments that are not already Sound instances (e.g. filenames) will be passed to the Sound 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() and append() are identical: any of them will accept a single Sound instance, or a sequence of Sound instances.

Any arguments that are not already Sound instances (e.g. filenames) will be passed to the Sound constructor to create such instances, along with any additional keyword arguments.

index(arg)

Given a Sound instance that is in the queue, or its label, return its non-negative integer index within the queue. Raise a ValueError 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 the Sound 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, return default if specified (otherwise raise a KeyError).

remove(item_or_index)

Given either a Sound instance, its label, or its index within the list, remove it from the queue. Return self.

property currentSound

Return the current Sound as indexed by position

property position

Zero-based numeric index of currentSound within the list.

When assigning, you may also use a Sound instance or its label, provided that instance is in the list.