Added modifier
Added modifier and refactored cycles
This commit is contained in:
@ -79,7 +79,7 @@ class Pitch(Event):
|
|||||||
|
|
||||||
pitch_class: int = field(default=None)
|
pitch_class: int = field(default=None)
|
||||||
octave: int = field(default=None)
|
octave: int = field(default=None)
|
||||||
modifier: int = field(default=None)
|
modifier: int = field(default=0)
|
||||||
note: int = field(default=None)
|
note: int = field(default=None)
|
||||||
|
|
||||||
def set_note(self, note: int):
|
def set_note(self, note: int):
|
||||||
@ -228,7 +228,7 @@ class Ziffers(Sequence):
|
|||||||
key = self.options["key"]
|
key = self.options["key"]
|
||||||
scale = self.options["scale"]
|
scale = self.options["scale"]
|
||||||
if isinstance(self.current, (Pitch, RandomPitch)):
|
if isinstance(self.current, (Pitch, RandomPitch)):
|
||||||
note = note_from_pc(key,self.current.pitch_class,scale)
|
note = note_from_pc(root=key,pitch_class=self.current.pitch_class,intervals=scale,modifier=self.current.modifier)
|
||||||
self.current.set_note(note)
|
self.current.set_note(note)
|
||||||
elif isinstance(self.current,Chord):
|
elif isinstance(self.current,Chord):
|
||||||
pcs = self.current.pitch_classes
|
pcs = self.current.pitch_classes
|
||||||
@ -341,18 +341,14 @@ class Cyclic(Sequence):
|
|||||||
wrap_start: str = field(default="<", repr=False)
|
wrap_start: str = field(default="<", repr=False)
|
||||||
wrap_end: str = field(default=">", repr=False)
|
wrap_end: str = field(default=">", repr=False)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __next__(self):
|
||||||
super().__post_init__()
|
yield self.values[self.cycle%len(self.cycle)]
|
||||||
# TODO: Do spaced need to be filtered out?
|
self.cycle+=1
|
||||||
self.values = [val for val in self.values if isinstance(val, Whitespace)]
|
raise StopIteration
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
"""Get the value for the current cycle"""
|
"""Get the value for the current cycle"""
|
||||||
return self.values[self.cycle]
|
return self.values[self.cycle%len(self.cycle)]
|
||||||
|
|
||||||
def next_cycle(self, cycle: int):
|
|
||||||
"""Evaluate next cycle"""
|
|
||||||
self.cycle = self.cycle + 1
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@ -101,10 +101,15 @@ class ZiffersTransformer(Transformer):
|
|||||||
return {"octave": int(value), "text": items[0].value}
|
return {"octave": int(value), "text": items[0].value}
|
||||||
|
|
||||||
def octave(self, items):
|
def octave(self, items):
|
||||||
"""Return octave info"""
|
"""Return octaves ^ and _"""
|
||||||
value = sum(1 if char == "^" else -1 for char in items[0].value)
|
value = sum(1 if char == "^" else -1 for char in items[0].value)
|
||||||
return {"octave": value, "text": items[0].value}
|
return {"octave": value, "text": items[0].value}
|
||||||
|
|
||||||
|
def modifier(self, items):
|
||||||
|
"""Return modifiers # and b"""
|
||||||
|
value = 1 if items[0].value == "#" else -1
|
||||||
|
return {"modifier": value}
|
||||||
|
|
||||||
def chord(self, items):
|
def chord(self, items):
|
||||||
"""Parses chord"""
|
"""Parses chord"""
|
||||||
return Chord(pitch_classes=items, text="".join([val.text for val in items]))
|
return Chord(pitch_classes=items, text="".join([val.text for val in items]))
|
||||||
|
|||||||
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
// Pitch classes
|
// Pitch classes
|
||||||
pitch_class: prefix* pitch
|
pitch_class: prefix* pitch
|
||||||
prefix: (octave | duration_chars | escaped_decimal | escaped_octave)
|
prefix: (octave | duration_chars | escaped_decimal | escaped_octave | modifier)
|
||||||
pitch: /-?[0-9TE]/
|
pitch: /-?[0-9TE]/
|
||||||
escaped_decimal: "<" decimal ">"
|
escaped_decimal: "<" decimal ">"
|
||||||
escaped_octave: /<-?[0-9]>/
|
escaped_octave: /<-?[0-9]>/
|
||||||
octave: /[_^]+/
|
octave: /[_^]+/
|
||||||
|
modifier: /[#b]/
|
||||||
|
|
||||||
// Chords
|
// Chords
|
||||||
chord: pitch_class pitch_class+
|
chord: pitch_class pitch_class+
|
||||||
|
|||||||
Reference in New Issue
Block a user