-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_types.py
More file actions
62 lines (48 loc) · 1.43 KB
/
complex_types.py
File metadata and controls
62 lines (48 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import operator
from attr import attrs
from .basic_types import BPM, Beat, CheaperFraction, Measure
@attrs(auto_attribs=True)
class MeasureValuePair(object):
"""A duplet, usually used for scripting a chart with freeform data."""
measure: Measure
value: CheaperFraction
@classmethod
def from_string_list(cls, string_pairs: str):
result = (
value.split('=')[:2]
for value in string_pairs
)
return [
cls(Beat(beat).as_measure, value)
for beat, value in result
]
@attrs(auto_attribs=True)
class MeasureMeasurePair(object):
"""A duplet, usually used for define timing sections"""
measure: Measure
value: Measure
@classmethod
def from_string_list(cls, string_pairs: str):
result = (
map(operator.attrgetter('as_measure'), map(Beat, value.split('=')[:2]))
for value in string_pairs
)
return [
cls(*pair)
for pair in result
]
@attrs(auto_attribs=True)
class MeasureBPMPair(object):
"""A duplet, used specifically for BPM sections"""
measure: Measure
bpm: BPM
@classmethod
def from_string_list(cls, string_pairs: str):
result = (
value.split('=')[:2]
for value in string_pairs
)
return [
cls(Beat(beat).as_measure, BPM(value))
for beat, value in result
]