Added note parsing
This commit is contained in:
@ -4,6 +4,7 @@ import itertools
|
||||
import operator
|
||||
import random
|
||||
from .defaults import DEFAULT_OPTIONS
|
||||
from .scale import note_from_pc
|
||||
|
||||
@dataclass
|
||||
class Meta:
|
||||
@ -79,6 +80,9 @@ class Pitch(Event):
|
||||
octave: int = field(default=None)
|
||||
note: int = field(default=None)
|
||||
|
||||
def set_note(self,note: int):
|
||||
self.note = note
|
||||
|
||||
|
||||
@dataclass
|
||||
class RandomPitch(Event):
|
||||
@ -198,7 +202,15 @@ class Ziffers(Sequence):
|
||||
|
||||
self.current = next(self.iterator) # Skip item
|
||||
|
||||
# Update collected options & default options
|
||||
self.current.update_new(self.options)
|
||||
|
||||
# Resolve note from scale
|
||||
if set(("key","scale")) <= self.options.keys():
|
||||
if isinstance(self.current,(Pitch,RandomPitch)):
|
||||
note = note_from_pc(self.options["key"],self.current.pitch_class,self.options["scale"])
|
||||
self.current.set_note(note)
|
||||
|
||||
self.loop_i += 1
|
||||
return self.current
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ from .classes import (
|
||||
)
|
||||
from .common import flatten, sum_dict
|
||||
from .defaults import DEFAULT_DURS
|
||||
from .scale import note_from_pc, parse_roman
|
||||
from .scale import parse_roman
|
||||
|
||||
|
||||
# pylint: disable=locally-disabled, unused-argument, too-many-public-methods, invalid-name
|
||||
|
||||
@ -29,7 +29,7 @@ def parse_expression(expr: str) -> Ziffers:
|
||||
return ziffers_parser.parse(expr)
|
||||
|
||||
|
||||
def zparse(expr: str, opts: dict = None) -> Ziffers:
|
||||
def zparse(expr: str, **opts) -> Ziffers:
|
||||
"""Parses ziffers expression with options
|
||||
|
||||
Args:
|
||||
@ -48,51 +48,51 @@ def zparse(expr: str, opts: dict = None) -> Ziffers:
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
|
||||
def z0(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z0(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z1(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z1(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z2(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z2(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z3(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z3(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z4(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z4(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z5(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z5(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z6(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z6(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z7(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z7(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z8(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z8(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
|
||||
def z9(expr: str, opts: dict = None) -> Ziffers:
|
||||
def z9(expr: str, **opts) -> Ziffers:
|
||||
"""Shortened method name for zparse"""
|
||||
return zparse(expr, opts)
|
||||
return zparse(expr, **opts)
|
||||
|
||||
Reference in New Issue
Block a user