FoxDot.lib.Patterns¶
A Pattern object is a container-like object, similar to Python lists, but with slightly different behaviour. The two most notable differences are how they behave when used with arithmetic operators and how they behave when indexed. A Pattern can be created by instantiating the class like so:
myPattern = Pattern([0,1,2,3])
This returns an a Pattern with the contents [0,1,2,3]. This is simply written as P[0,1,2,3]. You can also use this shorthand to create a pattern:
myPattern = P[0,1,2,3]
When using this method of instantiating a Pattern you can use Python slices to generate a range of numbers. The following creates the pattern P[0,1,2,3,4,6,8,10]:
myPattern = P[0:4,4:12:2]
Nested lists in a Pattern are treated not as single elements but as alternating values when indexing the Pattern with values greater than the apparent length of the Pattern. The following two Pattern objects are identical:
>>> a = P[0,1,2,[3,4]]
>>> b = P[0,1,2,3,0,1,2,4]
>>> a[3], b[3]
3, 3
>>> a[7], b[7]
4, 4
>>> a == b
True
No matter what the index, the Pattern will return a value, usually pat[i % len(pat)] where i is the index and pat is a Pattern. Nested values are accessed in turn depending on how large the index is.
Nested tuples become instances of the PGroup class when used in a Pattern, which are containers with similar behaviour to the Pattern class but are not accessed alternatively when nested, but all values are returned. You can instantiate a PGroup in similar manner to instantiating a Pattern
myGroup1 = PGroup([0,1,2]) myGroup2 = P(0,1,2)
If I try and instantiate a PGroup with a list or Pattern as an element then a Pattern of PGroups is returned instead, alternating the values in the slot that was a list:
>>> P(0,1,[2,3,4])
P[P(0, 1, 2), P(0, 1, 3), P(0, 1, 4)]
Similar to numpy arrays, arithmetic operations are performed on all elements of a Pattern, including nested Patterns and PGroups. If I use a list or Pattern of values in an operation (we will use addition as an example) then each value is added in sequence until all values are added together:
# Basic addition >>> P[0, 1, [2, 3], 4, (5,6)] + 2 P[2, 3, P[4, 5], 6, P(7, 8)]
# Using a Pattern of values >>> P[0, 1, [2, 3], 4, (5,6)] + P[2, 4] P[2, 5, P[4, 5], 8, P(7, 8), 4, 3, P[6, 7], 6, P(9, 10)]
Patterns also have many useful methods for manipulating the order of values, such as palindrome or rotate, and can be “chained” together as these don’t affect the order in place and return the augmented version of the Pattern.
- FoxDot.lib.Patterns.Generators
- FoxDot.lib.Patterns.Main
ClassPatternMethod()Convert()CycleEmptyItemFormat()GeneratorPatternGeneratorPattern.CACHE_HEADGeneratorPattern.MAX_SIZEGeneratorPattern.copy()GeneratorPattern.debuggingGeneratorPattern.dup()GeneratorPattern.from_func()GeneratorPattern.func()GeneratorPattern.getitem()GeneratorPattern.help()GeneratorPattern.map()GeneratorPattern.new()GeneratorPattern.transform()
PGroupPatternPattern.PlayerKeyPattern.PvarPattern.PvarGeneratorPattern.TimeVarPattern.TimeVar.CreatePvarGenerator()Pattern.TimeVar.all_values()Pattern.TimeVar.calculate()Pattern.TimeVar.check_for_inf()Pattern.TimeVar.copy()Pattern.TimeVar.depthPattern.TimeVar.extend()Pattern.TimeVar.flag_accessed()Pattern.TimeVar.get_current_index()Pattern.TimeVar.get_current_time()Pattern.TimeVar.get_durs()Pattern.TimeVar.get_inf_index()Pattern.TimeVar.get_values()Pattern.TimeVar.help()Pattern.TimeVar.i_invert()Pattern.TimeVar.info()Pattern.TimeVar.invert()Pattern.TimeVar.json_value()Pattern.TimeVar.lshift()Pattern.TimeVar.math_op()Pattern.TimeVar.metroPattern.TimeVar.new()Pattern.TimeVar.now()Pattern.TimeVar.rshift()Pattern.TimeVar.set_clock()Pattern.TimeVar.set_eval()Pattern.TimeVar.set_inf_index()Pattern.TimeVar.shuf()Pattern.TimeVar.stream()Pattern.TimeVar.transform()Pattern.TimeVar.update()
Pattern.WEIGHTPattern.debug
PatternContainerPatternFormat()PatternInput()PatternMethod()StaticPatternMethod()asPattern()asStream()convert_nested_data()equal_values()force_pattern_args()get_avg_if()group_modi()loop_pattern_func()loop_pattern_method()metaPatternmetaPattern.WEIGHTmetaPattern.abs()metaPattern.accum()metaPattern.add()metaPattern.all()metaPattern.alt()metaPattern.amen()metaPattern.append()metaPattern.arp()metaPattern.asGroup()metaPattern.bracket_stylemetaPattern.bubble()metaPattern.choose()metaPattern.compress()metaPattern.concat()metaPattern.convert_data()metaPattern.copy()metaPattern.count()metaPattern.debuggingmetaPattern.deep_shuffle()metaPattern.deeprzip()metaPattern.deepzip()metaPattern.duplicate()metaPattern.eq()metaPattern.every()metaPattern.extend()metaPattern.float()metaPattern.fromString()metaPattern.get_behaviour()metaPattern.get_data()metaPattern.get_methods()metaPattern.getitem()metaPattern.getslice()metaPattern.group()metaPattern.help()metaPattern.i_reverse()metaPattern.i_rotate()metaPattern.i_shuf()metaPattern.i_sort()metaPattern.int()metaPattern.invert()metaPattern.items()metaPattern.iter()metaPattern.layer()metaPattern.limit()metaPattern.loop()metaPattern.ltrim()metaPattern.make()metaPattern.map()metaPattern.metametaPattern.mirror()metaPattern.ne()metaPattern.new()metaPattern.norm()metaPattern.offadd()metaPattern.offlayer()metaPattern.offmul()metaPattern.palindrome()metaPattern.pivot()metaPattern.replace()metaPattern.reverse()metaPattern.rotate()metaPattern.sample()metaPattern.select()metaPattern.set()metaPattern.setitem()metaPattern.shuffle()metaPattern.shufflets()metaPattern.sort()metaPattern.splice()metaPattern.startswith()metaPattern.str()metaPattern.stretch()metaPattern.string()metaPattern.stutter()metaPattern.submap()metaPattern.swap()metaPattern.transform()metaPattern.trim()metaPattern.true_copy()metaPattern.true_shuffle()metaPattern.undup()metaPattern.zip()metaPattern.zipx()
pattern_depth()patternclass()sum_delays()
- FoxDot.lib.Patterns.Operations
- FoxDot.lib.Patterns.PGroups
- FoxDot.lib.Patterns.Parse
- FoxDot.lib.Patterns.PlayString
- FoxDot.lib.Patterns.Sequences
- FoxDot.lib.Patterns.Utils