Added ? %

This commit is contained in:
2023-02-01 21:45:37 +02:00
parent 3add48c938
commit c66cc9b8ee
3 changed files with 17 additions and 5 deletions

View File

@ -30,6 +30,10 @@ class Pitch(Event):
class RandomPitch(Event):
pc: int = None
@dataclass
class RandomPercent(Meta):
percent: float = None
@dataclass
class Chord(Event):
pcs: list[Pitch] = None
@ -63,7 +67,7 @@ class Cyclic(Sequence):
cycle: int = 0
@dataclass
class RandomPitch(Meta):
class RandomInteger(Meta):
min: int
max: int

View File

@ -12,9 +12,9 @@ class ZiffersTransformer(Transformer):
values = flatten(items[0].values)
return Sequence(values=values,text="("+"".join([val.text for val in values])+")")
def randompitch(self,s):
def random_integer(self,s):
val = s[0][1:-1].split(",")
return RandomPitch(min=val[0],max=val[1],text=s[0])
return RandomInteger(min=val[0],max=val[1],text=s[0])
def range(self,s):
val = s[0].split("..")
@ -74,6 +74,12 @@ class ZiffersTransformer(Transformer):
val["text"] = "<"+val["text"]+">"
return val
def random_pitch(self,s):
return RandomPitch(text="?")
def random_percent(self,s):
return RandomPercent(text="%")
def duration_chars(self,s):
durations = [val[1] for val in s]
characters = "".join([val[0] for val in s])

View File

@ -1,12 +1,14 @@
?value: root
root: (pc | dur_change | oct_mod | oct_change | WS | chord | cycle | randompitch | range | list | subdivision)*
root: (pc | dur_change | oct_mod | oct_change | WS | chord | cycle | random_integer | random_pitch | random_percent | range | list | subdivision)*
list: "(" root ")"
randompitch: /\(-?[0-9],-?[0-9]\)/
random_integer: /\(-?[0-9]+,-?[0-9]+\)/
range: /-?[0-9]\.\.-?[0-9]/
cycle: "<" root ">"
pc: prefix* pitch
pitch: /-?[0-9TE]/
random_pitch: "?"
random_percent: "%"
prefix: (octave | duration_chars | escaped_decimal | escaped_octave)
oct_change: escaped_octave WS
escaped_octave: /<-?[0-9]>/