scamp_extensions.rhythm.metric_structure.MeterArithmeticGroup
- class scamp_extensions.rhythm.metric_structure.MeterArithmeticGroup(elements: Sequence[MeterArithmeticGroup | int], operation: str | None)[source]
Bases:
object
This class exists as an aid to parsing arithmetic expressions into MetricStructures. Simply defining __add__ and __mul__ for MetricStructure wasn’t flexible enough, since it was important to differentiate between, say, a “4 + 2 + 3” meter and a “(4 + 2) + 3” meter. The former establishes a flat hierarchy with three groups, whereas the latter establishes a nested hierarchy with two groups, the first of which is split into two smaller groups.
- Parameters:
elements – a list of MeterArithmeticGroups or integers representing simple beat groups
operation – either “+”, “*”, or None, in the case of just a number
Methods
parse
(input_string)Parses an input string containing an arithmetic expression into a (probably nested) MeterArithmeticGroup. For instance an input string of "(3+2)+3*2" will be parsed as::.
to_metric_structure
([break_up_large_numbers])Renders this arithmetic group as a
MetricStructure
.- classmethod parse(input_string: str) MeterArithmeticGroup [source]
Parses an input string containing an arithmetic expression into a (probably nested) MeterArithmeticGroup. For instance an input string of “(3+2)+3*2” will be parsed as:
MeterArithmeticGroup( [MeterArithmeticGroup([MeterArithmeticGroup([3], "None"), MeterArithmeticGroup([2], "None")], "+"), MeterArithmeticGroup([MeterArithmeticGroup([3], "None"), MeterArithmeticGroup([2], "None")], "*")], "+" )
- Parameters:
input_string – input string consisting of integers, plus signs, multiplication signs, and parentheses
- Returns:
a MeterArithmeticGroup
- to_metric_structure(break_up_large_numbers: bool = False) MetricStructure [source]
Renders this arithmetic group as a
MetricStructure
.- Parameters:
break_up_large_numbers – see
MetricStructure