FoxDot.lib.Patterns.Sequences

Sequences.py

All patterns inherit from Base.Pattern. There are two types of pattern:

  1. Container types
    • Similar to lists but with different mathematical operators

  2. Generator types
    • Similar to generators but can be indexed (returns values based on functions)

FoxDot.lib.Patterns.Sequences.P10(n)[source]

Returns an n-length Pattern of a randomly generated series of 1’s and 0’s

FoxDot.lib.Patterns.Sequences.PAlt(pat1, pat2, *patN)[source]

Returns a Pattern generated by alternating the values in the given sequences

FoxDot.lib.Patterns.Sequences.PBeat(string, start=0, dur=0.5)[source]

Returns a Pattern of durations based on an input string where non-whitespace denote a pulse e.g.

>>> PBeat("x xxx x")
P[1, 0.5, 0.5, 1, 0.5]
FoxDot.lib.Patterns.Sequences.PBern(size=16, ratio=0.5)[source]

Returns a pattern of 1s and 0s based on the ratio value (between 0 and 1). This is called a Bernoulli sequence.

FoxDot.lib.Patterns.Sequences.PDelay(*args)[source]
FoxDot.lib.Patterns.Sequences.PDur(n, k, start=0, dur=0.25)[source]

Returns the actual durations based on Euclidean rhythms (see PEuclid) where dur is the length of each step.

>>> PDur(3, 8)
P[0.75, 0.75, 0.5]
>>> PDur(5, 16)
P[0.75, 0.75, 0.75, 0.75, 1]
FoxDot.lib.Patterns.Sequences.PEuclid(n, k)[source]

Returns the Euclidean rhythm which spreads ‘n’ pulses over ‘k’ steps as evenly as possible. e.g. PEuclid(3, 8) will return P[1, 0, 0, 1, 0, 0, 1, 0]

FoxDot.lib.Patterns.Sequences.PEuclid2(n, k, lo, hi)[source]

Same as PEuclid except it returns an array filled with ‘lo’ value instead of 0 and ‘hi’ value instead of 1. Can be used to generate characters patterns used to play sample like play(PEuclid2(3,8,’-‘,’X’)) will be equivalent to play(P[‘X’, ‘-’, ‘-’, ‘X’, ‘-’, ‘-’, ‘X’, ‘-‘]) that’s like saying play(“X–X–X-“)

FoxDot.lib.Patterns.Sequences.PJoin(patterns)[source]

Joins a list of patterns together

FoxDot.lib.Patterns.Sequences.PPairs(seq, func=<function <lambda>>)[source]

Laces a sequence with a second sequence obtained by performing a function on the original. By default this is lambda n: 8 - n.

FoxDot.lib.Patterns.Sequences.PQuicken(dur=0.5, stepsize=3, steps=6)[source]

Returns a PGroup of delay amounts that gradually decrease

FoxDot.lib.Patterns.Sequences.PRange(start, stop=None, step=1)[source]

Returns a Pattern equivalent to Pattern(range(start, stop, step))

FoxDot.lib.Patterns.Sequences.PRhythm(durations)[source]

Converts all tuples/PGroups into delays calculated using the PDur algorithm. e.g.

PRhythm([1,(3,8)]) -> P[1,(2,0.75,1.5)]

work in progress

FoxDot.lib.Patterns.Sequences.PShuf(seq) Returns a shuffled version of seq[source]
FoxDot.lib.Patterns.Sequences.PSine(n=16)[source]

Returns values of one cycle of sine wave split into ‘n’ parts

FoxDot.lib.Patterns.Sequences.PSq(a=1, b=2, c=3)[source]

Returns a Pattern of square numbers in the range a to a+c

FoxDot.lib.Patterns.Sequences.PStep(n, value, default=0)[source]

Returns a Pattern that every n-term is ‘value’ otherwise ‘default’

FoxDot.lib.Patterns.Sequences.PStretch(seq, size)[source]

Returns ‘seq’ as a Pattern and looped until its length is ‘size’ e.g. PStretch([0,1,2], 5) returns P[0, 1, 2, 0, 1]

FoxDot.lib.Patterns.Sequences.PStrum(n=4)[source]

Returns a pattern of durations similar to how you might strum a guitar

FoxDot.lib.Patterns.Sequences.PStutter(seq, n) -> Creates a pattern such that each item in the array is repeated n times (n can be a pattern)[source]
FoxDot.lib.Patterns.Sequences.PSum(n, total, **kwargs)[source]

Returns a Pattern of length ‘n’ that sums to equal ‘total’

e.g. PSum(3,8) -> P[3, 3, 2]

PSum(5,4) -> P[1, 0.75, 0.75, 0.75, 0.75]

FoxDot.lib.Patterns.Sequences.PTri(start, stop=None, step=1)[source]

Returns a Pattern equivalent to Pattern(range(start, stop, step)) with its reversed form appended.

FoxDot.lib.Patterns.Sequences.PZip(pat1, pat2, *patN)[source]

Creates a Pattern that ‘zips’ together multiple patterns. PZip([0,1,2], [3,4]) will create the Pattern P[(0, 3), (1, 4), (2, 3), (0, 4), (1, 3), (2, 4)]

FoxDot.lib.Patterns.Sequences.PZip2(pat1, pat2, rule=<function <lambda>>)[source]

Like PZip but only uses two Patterns. Zips together values if they satisfy the rule.

class FoxDot.lib.Patterns.Sequences.__pattern__[source]

Bases: object

Used to define lists as patterns:

P[1,2,3] is equivalent to Pattern([1,2,3]) and P(1,2,3) is equivalent to Pattern((1,2,3)) and P+(1,2,3) is equivalient to Pattern((1,2,3)).

Ranges can be created using slicing, e.g. P[1:6:2] will generate the range 1 to 6 in steps of 2, thus creating the Pattern [1, 3, 5]. Slices can be combined with other values in a Pattern such that P[0,2,1:10] will return the Pattern P[0, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]

FoxDot.lib.Patterns.Sequences.MAX_SIZE = 2048

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral. >>> int(‘0b100’, base=0) 4

FoxDot.lib.Patterns.Sequences.P = <FoxDot.lib.Patterns.Sequences.__pattern__ object>

Used to define lists as patterns:

P[1,2,3] is equivalent to Pattern([1,2,3]) and P(1,2,3) is equivalent to Pattern((1,2,3)) and P+(1,2,3) is equivalient to Pattern((1,2,3)).

Ranges can be created using slicing, e.g. P[1:6:2] will generate the range 1 to 6 in steps of 2, thus creating the Pattern [1, 3, 5]. Slices can be combined with other values in a Pattern such that P[0,2,1:10] will return the Pattern P[0, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]