music.PlainChanges

class music.PlainChanges(nelements=4, nhunts=None, hunts=None)[source]

Bases: object

Presents plain changes as swaps and acts in domains to make peals.

Examples

>>> peal = PlainChanges(4)
>>> len(peal.peal_direct)          # every permutation of four bells, once
24
>>> rows = peal.act([220, 275, 330, 440])
>>> len(rows), len(rows[0])
(24, 4)
>>> notes = [note(freq, duration=0.15) for row in rows for freq in row]
>>> write_wav_mono(horizontal_stack(*notes), "peal.wav")
__init__(nelements=4, nhunts=None, hunts=None)[source]

Initializes a PlainChanges object.

Parameters:
nelementsint, optional

The number of elements. Defaults to 4.

nhuntsint, optional

The number of hunts. Defaults to saturating_hunts(), which rings every row once.

huntsdict, optional

Not read. It was meant for hunts that start somewhere other than the lead, which was never implemented, and was always replaced by the layout nhunts gives. Passing it warns.

Raises:
ValueError

If there are fewer than two elements, or the number of hunts is negative or not fewer than the elements.

Methods

__init__([nelements, nhunts, hunts])

Initializes a PlainChanges object.

act([domain, peal])

Acts in a domain using a peal.

act_all([domain])

Acts in all peals using a domain.

initialize_hunts([nelements, nhunts])

Initializes the hunts dictionary.

perform_change(nelements, hunts[, hunt])

Performs a change procedure.

perform_peal(nelements[, hunts])

Performs a peal.

saturating_hunts(nelements)

Number of hunts that yields a peal over the whole symmetric group.

Attributes

peal_direct: list
peal_sequence: list
peals: dict
static saturating_hunts(nelements)[source]

Number of hunts that yields a peal over the whole symmetric group.

For nelements bells this is nelements - 3, floored at one. Below it the peal is a proper subset of the permutations: with the old default of two hunts, PlainChanges(6) produced 120 of the 720 rows and PlainChanges(8) produced 224 of 40320. Above it nothing is gained, which is what the warning in initialize_hunts reports.

Parameters:
nelementsint

The number of elements.

Returns:
int

The saturating number of hunts.

initialize_hunts(nelements=4, nhunts=None)[source]

Initializes the hunts dictionary.

Parameters:
nelementsint, optional

The number of elements. Defaults to 4.

nhuntsint, optional

The number of hunts. Defaults to the value of saturating_hunts(nelements), which is the number that makes the peal traverse every permutation exactly once. Pass a smaller value deliberately for a shorter peal.

Returns:
dict

The hunts dictionary.

Raises:
ValueError

If there are fewer than two elements, or the number of hunts is negative or not fewer than the elements. A change swaps two bells, so one bell has none: it failed with an IndexError looking for its swap, and a negative number of hunts with a KeyError looking for the first. As many hunts as bells leave the last hunt no bell to pass, and failed with an IndexError too, though only more than that was refused.

perform_peal(nelements, hunts=None)[source]

Performs a peal.

Parameters:
nelementsint

The number of elements.

huntsdict, optional

The hunts dictionary. Defaults to None.

Returns:
dict

The updated hunts dictionary.

perform_change(nelements, hunts, hunt=None)[source]

Performs a change procedure.

Parameters:
nelementsint

The number of elements.

huntsdict

The hunts dictionary.

huntstr, optional

The current hunt. Defaults to None.

Returns:
Permutation

The permutation of the change.

dict

The updated hunts dictionary.

act(domain=None, peal=None)[source]

Acts in a domain using a peal.

Parameters:
domainlist, optional

The domain. Defaults to None.

peallist, optional

The peal. Defaults to None.

Returns:
list

The acted domain.

act_all(domain=None)[source]

Acts in all peals using a domain.

Parameters:
domainlist, optional

The domain. Defaults to None.