FoxDot.lib.Patterns.Main

Contains classes Pattern and PGroup and the base class for GeneratorPattern (see Generators.py).

FoxDot.lib.Patterns.Main.ClassPatternMethod(f)[source]

Decorator that makes a function into a metaPattern class method

FoxDot.lib.Patterns.Main.Convert(*args)[source]

Returns tuples/PGroups as PGroups, and anything else as Patterns

class FoxDot.lib.Patterns.Main.Cycle(*args)[source]

Bases: Pattern

Special Case pattern class for cycling values in “every”

class FoxDot.lib.Patterns.Main.EmptyItem[source]

Bases: object

Can be used in a pattern and and is essentially not there

FoxDot.lib.Patterns.Main.Format(data)

If data is a list, returns Pattern(data). If data is a tuple, returns PGroup(data). Returns data if neither.

class FoxDot.lib.Patterns.Main.GeneratorPattern(**kwargs)[source]

Bases: object

Used for when a Pattern does not generate a set length pattern, e.g. random patterns

property CACHE_HEAD

Returns the last value used if it exists

MAX_SIZE = 65536
copy()[source]

Returns a new Pattern Generator with same inputs

debugging = False
dup(n=2)[source]

Returns a PGroup with n lots of the Generator

static from_func(pattern_generator_func)[source]

Create a generator which invokes a given function to generate items. The given function should take and integer argument and return a pattern item.

func(index)[source]
getitem(index=None, *args)[source]

Calls self.func(index) to get an item if index is not in self.history, otherwise returns self.history[index]

classmethod help()[source]
map(mapping, default=0)[source]

Using .transform() to map values via a dictionary

::

a = PRand([0,1]) b = a.map({0: 16, 1: 25})

new(other, func=<function Nil>)[source]

Creates a new GeneratorPattern that references this pattern but returns a modified value based on func.

transform(func)[source]

Use func, which should take 1 argument, to transform the values in a generator pattern. Trivial example: myGenerator.transform(lambda x: 0 if x in (0,1,2) else 3)

class FoxDot.lib.Patterns.Main.PGroup(seq=[], *args)[source]

Bases: metaPattern

Class to represent any groupings of notes as denoted by brackets. PGroups should only be found within a Pattern object.

WEIGHT = 2
bracket_style = '()'
calculate_sample()[source]
calculate_time(dur)[source]

Returns a PGroup of durations to use as the delay argument when this is a sub-class of PGroupPrime

concat(data)[source]

Concatonates this patterns stream with another

eq(other)[source]

equals operator

flatten()[source]

Returns a nested PGroup as un-nested e.g.

>>> P(0,(3,5)).flatten()
P(0, 3, 5)
get_behaviour()[source]

Returns a function that changes a player event dictionary

get_name()[source]
has_behaviour()[source]

Returns True if this is a PGroupPrime or any elements are instances of PGroupPrime or its sub-classes

ignore = 0
merge(value)[source]

Merge values into one PGroup

ne(other)[source]

Not equals operator

class FoxDot.lib.Patterns.Main.Pattern(*args)[source]

Bases: metaPattern

Base type pattern

class PlayerKey(value, function=None, player=None, attr=None)

Bases: NumberKey

cmp(player, attr)
get_player_attribute()
name()
set(value, time)
update(value, time)

Updates the contents of the PlayerKey if the time value is different to self.last_updated. If they are the same, the the contents become a PGroup of the two values

update_pattern()
class Pvar(values, dur=None, **kwargs)

Bases: TimeVar

A TimeVar that represents Patterns that change over time e.g.

>>> a = Pvar([ [0,1,2,3], [4,5] ], 4)
>>> print a # time is 0
P[0, 1, 2, 3]
>>> print a # time is 4
P[4, 5]
getitem(index, *args, **kwargs)

Returns a TimeVar based on getting the index of this Pattern

new(other)

Returns a new TimeVar object

set_eval(func)
stream

alias of PatternContainer

transform(func)

Returns a Pvar based on a transformation function, as opposed to a mathematical operation

class PvarGenerator(func, *args, **kwargs)

Bases: Pvar

If a TimeVar is used in a Pattern function e.g. PDur(var([3,5]), 8) then a PvarGenerator is returned. Each argument is stored as a TimeVar and the function is called whenever the arguments are changed

info()
new(other)

Returns a new TimeVar object

now()

Returns the value currently represented by this TimeVar

set_eval(func)
class TimeVar(values, dur=None, start=0, **kwargs)

Bases: object

Var(values [,durs=[4]])

static CreatePvarGenerator(func, *args, **kwargs)
all_values()

Displays the values and the dependency value - useful for debugging

calculate(val)

Returns val as modified by its dependencies

check_for_inf(duration)
copy()
depth = 128
extend(values, dur=None)
flag_accessed()
get_current_index(time=None)

Returns the index of the value currently represented

get_current_time(beat=None)

Returns the current beat value

get_durs()
get_inf_index()
get_values()
classmethod help()
i_invert()
info()
invert()
json_value()

Returns data about this TimeVar that can be sent over a network as JSON

lshift(duration)
math_op(other, op)

Performs the mathematical operation between self and other. “op” should be the string name of a dunder method e.g. __mul__

metro = <FoxDot.lib.TempoClock.TempoClock object>
new(other)

Returns a new TimeVar object

now(time=None)

Returns the value currently represented by this TimeVar

rshift(duration)
classmethod set_clock(tempo_clock)
set_eval(func)
set_inf_index(value)
shuf()
static stream(values)
transform(func)

Returns a new TimeVar based on a func

update(values, dur=None, **kwargs)

Updates the TimeVar with new values.

WEIGHT = 0
debug = False
class FoxDot.lib.Patterns.Main.PatternContainer(*args)[source]

Bases: metaPattern

getitem(key, *args)[source]

Called by __getitem__()

FoxDot.lib.Patterns.Main.PatternFormat(data)[source]

If data is a list, returns Pattern(data). If data is a tuple, returns PGroup(data). Returns data if neither.

FoxDot.lib.Patterns.Main.PatternInput(data)[source]
FoxDot.lib.Patterns.Main.PatternMethod(f)[source]

Decorator that makes a function into a metaPattern method

FoxDot.lib.Patterns.Main.StaticPatternMethod(f)[source]

Decorator that makes a function into a metaPattern static method

FoxDot.lib.Patterns.Main.asPattern(item)[source]
FoxDot.lib.Patterns.Main.asStream(data)[source]

Forces any data into a [pattern] form

FoxDot.lib.Patterns.Main.convert_nested_data(data)[source]

Converts a piece of data in a pattern to a PGroup/Pattern as appropriate

FoxDot.lib.Patterns.Main.equal_values(this, that)[source]

Returns True if this == that

FoxDot.lib.Patterns.Main.force_pattern_args(f)[source]

Wrapper for forcing arguments to be a Pattern

FoxDot.lib.Patterns.Main.get_avg_if(item1, item2, func=<function <lambda>>)[source]
FoxDot.lib.Patterns.Main.group_modi(pgroup, index)[source]

Returns value from pgroup that modular indexes nested groups

FoxDot.lib.Patterns.Main.loop_pattern_func(f)[source]

Decorator for allowing any Pattern function to create multiple Patterns by using Patterns or TimeVars as arguments

FoxDot.lib.Patterns.Main.loop_pattern_method(f)[source]

Decorator for allowing any Pattern method to create multiple (or rather, longer) Patterns by using Patterns as arguments

class FoxDot.lib.Patterns.Main.metaPattern(*args)[source]

Bases: object

Abstract base class for Patterns

WEIGHT = -1
abs()[source]
accum(n=None)[source]

Returns a Pattern that is equivalent to list of sums of that Pattern up to that index.

add(other)[source]
all(func=<function metaPattern.<lambda>>)[source]

Returns true if all of the patterns contents satisfies func(x) - default is nonzero

alt(other)[source]

Returns Pattern(other)

amen(size=2)

Merges and laces the first and last two items such that a drum pattern “x-o-” would become “(x[xo])-o([-o]-)”

append(item)[source]

Converts a new item to PGroup etc and appends

arp(arp_pattern)[source]

Return a new Pattern with each item repeated len(arp_pattern) times and incremented by arp_pattern. Useful for arpeggiating. e.g. ` >>> P[0, 1, 2, 3].arp([0, 2]) P[0, 2, 1, 3, 2, 4, 3, 5] `

asGroup()[source]

Returns the Pattern as a PGroup

bracket_style = '[]'
bubble(size=2)

Merges and laces the first and last two items such that a drum pattern “x-o-” would become “(x[xo])-o([-o]-)”

choose()[source]

Returns one randomly selected item

compress(selector)[source]

Removes values from the pattern if the same index in selector is 0. Similar to .select() but maximum length of the new Pattern is the length of the initial Pattern.

concat(data)[source]

Concatonates this patterns stream with another

convert_data(dtype=<function metaPattern.float>, *args, **kwargs)[source]

Makes a true copy and converts the data to a given data type

copy()[source]

Returns a copy of the Pattern such that alterations to the Pattern.data do not affect the original.

count(item)[source]

Returns the number of occurrences of item in the Pattern

debugging = False
deep_shuffle(n=1)[source]

Returns a new Pattern with shuffled contents and shuffles any nested patterns. To shuffle the contents of nested patterns with the rest of the Pattern’s contents, use true_shuffle.

deeprzip(other)[source]
deepzip(other)[source]
duplicate(n)[source]

Repeats this pattern n times but keep nested pattern values

eq(other)[source]
every(n, method, *args, **kwargs)[source]

Returns the pattern looped n-1 times then appended with the version returned when method is called on it.

extend(seq)[source]

Should return None

float()[source]
fromString(string)
get_behaviour()[source]
get_data()[source]

Returns self.data if data is not a single instance of this class, in which case self.data[0].data is returned

classmethod get_methods()[source]

Returns the methods associated with the Pattern class as a list

getitem(key, get_generator=False)[source]

Called by __getitem__()

getslice(start, stop, step=1)[source]

Called when using __getitem__ with slice notation

group()[source]

Returns the Pattern as a PGroup

classmethod help()[source]

Prints the Pattern class docstring to the console

i_reverse()[source]
i_rotate(n=1)[source]
i_shuf()[source]
i_sort()[source]
int()[source]
invert()[source]

Inverts the values with the Pattern.

items()[source]

Returns a generator object equivalent to using enumerate()

iter(n)[source]

Repeats this pattern n times but doesn’t take nested pattern into account for length

layer(method, *args, **kwargs)[source]

Zips a pattern with a modified version of itself. Method argument can be a function that takes this pattern as its first argument, or the name of a Pattern method as a string.

limit(func, value)[source]

Returns a new Pattern generated by adding elements from this Pattern to a new list and repeatedly calling func() on this list until func(l) is greater than value e.g. ` >>> print( P[0, 1, 2, 3].limit(sum, 10) ) P[0, 1, 2, 3, 0, 1, 2] `

loop(n, f=None)[source]

Repeats this pattern n times

ltrim(size)[source]

Like trim but removes items from the start of the pattern

make()[source]

This method automatically laces and groups the data

map(func)[source]

Returns a Pattern that calls func on each item

meta = []
mirror()[source]

Reverses the pattern. Differs to Pattern.reverse() in that all nested patters are also reversed.

ne(other)[source]
new(data)[source]

Returns a new pattern object with this Pattern’s class type

norm()[source]

Returns the pattern with all values between 0 and 1

offadd(value, dur=0.5)
offlayer(method, dur=0.5, *args, **kwargs)

Zips a pattern with a modified version of itself. Method argument can be a function that takes this pattern as its first argument, or the name of a Pattern method as a string.

offmul(value, dur=0.5)
palindrome(a=0, b=None)[source]

Returns the original pattern with mirrored version of itself appended. a removes values from the middle of the pattern, if positive. b removes values from the end of the pattern, should be negative.

e.g.

>>> P[:4].palindrome()
P[0, 1, 2, 3, 3, 2, 1, 0]
>>> P[:4].palindrome(1)
P[0, 1, 2, 3, 2, 1, 0]
>>> P[:4].palindrome(-1)
P[0, 1, 2, 3, 3, 2, 1]
>>> P[:4].palindrome(1,-1)
P[0, 1, 2, 3, 2, 1]
pivot(i)[source]

Mirrors and rotates the Pattern such that the item at index ‘i’ is in the same place

replace(sub, repl)[source]

Replaces any occurrences of “sub” with “repl”

reverse()[source]

Reverses the contents of the Pattern. Nested patterns are not reversed. To reverse the contents of nester patterns use Pattern.mirror()

rotate(n=1)[source]
sample(n)[source]

Returns an n-length pattern from a sample

select(selector)[source]

Removes values from the pattern if the same index in selector is 0

set(index, value)[source]
setitem(key, value)[source]
shuffle(n=1)[source]

Returns a new Pattern with shuffled contents. Note: nested patterns stay together. To shuffle the contents of nested patterns, use deep_shuffle or true_shuffle.

shufflets(n)[source]

Returns a Pattern of ‘n’ number of PGroups made from shuffled versions of the original Pattern

sort(*args, **kwargs)[source]

Used in place of sorted(pattern) to force type

splice(seq, *seqs)[source]

Takes at least list / Pattern and creates a new Pattern by adding a value from each pattern in turn to the new pattern. e.g. ` >>> P[0,1,2,3].splice([4,5,6,7],[8,9]) P[0,4,8,1,5,9,2,6,8,3,7,9] `

startswith(prefix)[source]

Returns True if the first item in the Pattern is equal to prefix

str()[source]
stretch(size)[source]

Stretches (repeats) the contents until len(Pattern) == size

string()[source]

Returns a PlayString in string format from the Patterns values

stutter(n=2, strict=False)[source]

Returns a new Pattern with each item repeated by n. Use a list of numbers for stutter different items by different amount. e.g. ` >>> P[0, 1, 2, 3].stutter([1,3]) P[0, 1, 1, 1, 2, 3, 3, 3] ` Use strict=True to force generator patterns to return the same value n times in a row.

submap(mapping)[source]

Similar to Pattern.replace, but takes a dictionary of values

swap(n=2)[source]
transform(func)[source]

Recursively transforms values and nested patterns

trim(size)[source]

Shortens a pattern until it’s length is equal to size - cannot be greater than the length of the current pattern

true_copy(new_data=None)[source]

Returns a copy of the Pattern such that items within the Pattern hold the same state as the original.

true_shuffle(n=1)[source]

Returns a new Pattern with completely shuffle contents such that nested Patterns are shuffled within the larger Pattern

undup()[source]

Removes any consecutive duplicate numbers from a Pattern

zip(other, dtype=None)[source]

Zips two patterns together. If one item is a tuple, it extends the tuple / PGroup i.e. arrow_zip([(0,1),3], [2]) -> [(0,1,2),(3,2)]

zipx(other)[source]

Returns a Pattern of PGroups, where each PGroup contains the i-th element from each of the argument sequences. The length of the pattern is the lowest common multiple of the lengths of the two joining patterns.

FoxDot.lib.Patterns.Main.pattern_depth(pat)[source]

Returns the level of nested arrays

FoxDot.lib.Patterns.Main.patternclass(a, b)[source]
FoxDot.lib.Patterns.Main.sum_delays(a, b)[source]