beatmachine.effects.base module¶
The base module contains a base effect class as well as a metaclass-based registry for simple, batteries-included deserialization of effects.
-
class
beatmachine.effects.base.EffectABCMeta¶ Bases:
beatmachine.effects.base.EffectRegistry,abc.ABCMetaEffectABCMeta is a metaclass combining EffectRegistry and ABCMeta.
-
class
beatmachine.effects.base.EffectRegistry¶ Bases:
typeThe EffectRegistry is a metaclass that serves to track all loadable effects. Effects may define zero or more of the following two attributes to control how they are loaded:
__effect_name__explicitly sets the name used to recognize an effect. It defaults to the lowercased class name.__effect_schema__is an optional schema describing the effect’s properties. During validation, this is placed within the “properties” field of an object in a Draft 7 JSON schema.-
static
dump_list_schema(root: bool = False) → dict¶ Dumps a Draft 7 JSON schema describing a valid effect chain.
-
static
dump_schema(root: bool = False) → dict¶ Dumps a Draft 7 JSON schema describing a valid effect object. This includes all registered effects, so custom effects that define
__effect_schema__will be included.
-
effects= {'cut': <class 'beatmachine.effects.periodic.CutEveryNth'>, 'randomize': <class 'beatmachine.effects.temporal.RandomizeAllBeats'>, 'remap': <class 'beatmachine.effects.temporal.RemapBeats'>, 'remove': <class 'beatmachine.effects.periodic.RemoveEveryNth'>, 'repeat': <class 'beatmachine.effects.periodic.RepeatEveryNth'>, 'reverse': <class 'beatmachine.effects.periodic.ReverseEveryNth'>, 'silence': <class 'beatmachine.effects.periodic.SilenceEveryNth'>, 'swap': <class 'beatmachine.effects.temporal.SwapBeats'>}¶
-
static
load_effect(effect: dict) → beatmachine.effects.base.LoadableEffect¶ Loads an effect from a key-value definition.
A “type” key is required to determine which effect to load. All other values are passed directly as keyword arguments to the effect constructor. If an effect defines
__effect_schema__, the given schema will be used to validate parameters.Parameters: effect – Effect representation to load. Returns: An effect based on the given definition.
-
static
load_effect_chain(effects: Iterable[dict])¶
-
static
load_effect_from_dict(effect: dict) → beatmachine.effects.base.LoadableEffect¶ Deprecated since version 3.2.0: This will be removed in 4.0.0. Prefer
EffectRegistry.load_effectorbeatmachine.effects.load_effect.
-
schemas= {'cut': {'denominator': {'default': 2, 'description': 'How many pieces to cut each beat into.', 'minimum': 2, 'title': 'Denominator', 'type': 'integer'}, 'offset': {'default': 0, 'description': 'How many beats to wait before applying this effect.', 'minimum': 0, 'title': 'Offset', 'type': 'integer'}, 'period': {'default': 1, 'description': 'How often to apply this effect.', 'minimum': 1, 'title': 'Period', 'type': 'integer'}, 'take_index': {'default': 0, 'description': 'Which piece, starting at 0, to keep.', 'minimum': 0, 'title': 'Take', 'type': 'integer'}}, 'randomize': {}, 'remap': {'mapping': {'description': 'New order of beats, starting at 0. For example, the mapping [0, 3, 2, 1] swaps beats 2 and 4 every 4 beats. The mapping [0, 1, 1, 1] replaces beats 3 and 4 with beat 2.', 'items': {'type': 'number'}, 'title': 'Mapping', 'type': 'array'}}, 'remove': {'offset': {'default': 0, 'description': 'How many beats to wait before applying this effect.', 'minimum': 0, 'title': 'Offset', 'type': 'integer'}, 'period': {'default': 2, 'description': 'How often to apply this effect. For Remove, this must be at least 2.', 'minimum': 2, 'title': 'Period', 'type': 'integer'}}, 'repeat': {'offset': {'default': 0, 'description': 'How many beats to wait before applying this effect.', 'minimum': 0, 'title': 'Offset', 'type': 'integer'}, 'period': {'default': 1, 'description': 'How often to apply this effect.', 'minimum': 1, 'title': 'Period', 'type': 'integer'}, 'times': {'default': 2, 'minimum': 2, 'title': 'How many times each affected beat should be played. Must be at least 2, because a value of 1 would do nothing.', 'type': 'number'}}, 'reverse': {'offset': {'default': 0, 'description': 'How many beats to wait before applying this effect.', 'minimum': 0, 'title': 'Offset', 'type': 'integer'}, 'period': {'default': 1, 'description': 'How often to apply this effect.', 'minimum': 1, 'title': 'Period', 'type': 'integer'}}, 'silence': {'offset': {'default': 0, 'description': 'How many beats to wait before applying this effect.', 'minimum': 0, 'title': 'Offset', 'type': 'integer'}, 'period': {'default': 1, 'description': 'How often to apply this effect.', 'minimum': 1, 'title': 'Period', 'type': 'integer'}}, 'swap': {'group_size': {'default': 4, 'description': 'Beats per measure, or how many beats to wait before swapping again.', 'minimum': 4, 'title': 'Group', 'type': 'number'}, 'offset': {'default': 0, 'description': 'How many beats to wait before the first swap.', 'minimum': 0, 'title': 'Offset', 'type': 'number'}, 'x_period': {'default': 2, 'description': 'First beat to swap, starting at 1.', 'minimum': 1, 'title': 'X', 'type': 'number'}, 'y_period': {'default': 4, 'description': 'Second beat to swap, starting at 1 and not equal to X.', 'minimum': 1, 'title': 'Y', 'type': 'number'}}}¶
-
static
-
class
beatmachine.effects.base.LoadableEffect¶ Bases:
abc.ABCLoadableEffect is an abstract base for a valid effect loadable by the EffectRegistry.