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:
PatternSpecial Case pattern class for cycling values in “every”
- class FoxDot.lib.Patterns.Main.EmptyItem[source]¶
Bases:
objectCan 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:
objectUsed 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¶
- debugging = False¶
- 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.
- 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]
- map(mapping, default=0)[source]¶
Using .transform() to map values via a dictionary
- ::
a = PRand([0,1]) b = a.map({0: 16, 1: 25})
- class FoxDot.lib.Patterns.Main.PGroup(seq=[], *args)[source]¶
Bases:
metaPatternClass to represent any groupings of notes as denoted by brackets. PGroups should only be found within a Pattern object.
- WEIGHT = 2¶
- bracket_style = '()'¶
- calculate_time(dur)[source]¶
Returns a PGroup of durations to use as the delay argument when this is a sub-class of PGroupPrime
- has_behaviour()[source]¶
Returns True if this is a PGroupPrime or any elements are instances of PGroupPrime or its sub-classes
- ignore = 0¶
- class FoxDot.lib.Patterns.Main.Pattern(*args)[source]¶
Bases:
metaPatternBase 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:
TimeVarA 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:
PvarIf 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:
objectVar(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
- 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.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.convert_nested_data(data)[source]¶
Converts a piece of data in a pattern to a PGroup/Pattern as appropriate
- FoxDot.lib.Patterns.Main.force_pattern_args(f)[source]¶
Wrapper for forcing arguments to be a Pattern
- 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:
objectAbstract base class for Patterns
- WEIGHT = -1¶
- accum(n=None)[source]¶
Returns a Pattern that is equivalent to list of sums of that Pattern up to that index.
- all(func=<function metaPattern.<lambda>>)[source]¶
Returns true if all of the patterns contents satisfies func(x) - default is nonzero
- 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]-)”
- 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] `
- 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]-)”
- 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.
- 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.
- 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.
- 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.
- fromString(string)¶
- 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
- 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] `
- meta = []¶
- mirror()[source]¶
Reverses the pattern. Differs to Pattern.reverse() in that all nested patters are also reversed.
- 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
- reverse()[source]¶
Reverses the contents of the Pattern. Nested patterns are not reversed. To reverse the contents of nester patterns use Pattern.mirror()
- 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
- 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] `
- 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.
- 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