Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/sources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pyabc2.note import _RE_NOTE as rx\n",
"from pyabc2.note import RE_NOTE as rx\n",
"\n",
"rx"
]
Expand Down
4 changes: 2 additions & 2 deletions pyabc2/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
r"(?P<slash>/+)?"
r"(?P<den>[0-9]+)?"
)
_RE_NOTE = re.compile(_S_RE_NOTE)
RE_NOTE = re.compile(_S_RE_NOTE)


_ACCIDENTAL_ASCII_TO_ABC = {"#": "^", "b": "_", "=": "="}
Expand Down Expand Up @@ -159,7 +159,7 @@ def from_abc(

but this can be adjusted using the keyword arguments.
"""
m = _RE_NOTE.match(abc)
m = RE_NOTE.match(abc)
return cls._from_abc_match(m, key=key, octave_base=octave_base, unit_duration=unit_duration)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions pyabc2/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, Iterator, List, NamedTuple, Optional

from .key import Key
from .note import _RE_NOTE, Note
from .note import RE_NOTE, Note


class InfoField(NamedTuple):
Expand Down Expand Up @@ -180,7 +180,7 @@ def _find_first_chord(s: str) -> Optional[str]:
# NOTE: did see some single notes inside `[]` in The Session data
c = m.group()
assert c.startswith("[") and c.endswith("]")
n = len(_RE_NOTE.findall(c)) # TODO: maybe just letter count would be suff.
n = len(RE_NOTE.findall(c)) # TODO: maybe just letter count would be suff.
if n >= 2:
return c
else:
Expand Down Expand Up @@ -375,7 +375,7 @@ def _extract_measures(self, tune_lines: List[str]) -> None:
# https://abcnotation.com/wiki/abc:standard:v2.1#broken_rhythm

# 3. In note group, find notes
for m_note in _RE_NOTE.finditer(note_group):
for m_note in RE_NOTE.finditer(note_group):
# TODO: parse/store rests, maybe have an additional iterator for "rhythmic elements" or something

if m_note is None:
Expand Down
19 changes: 13 additions & 6 deletions pyabc2/pitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ def _gen_pitch_values() -> Dict[str, int]:

_S_RE_ASCII_ACCIDENTALS = r"(?:##|bb|b|#|=)"
_S_RE_PITCH_CLASS = rf"[A-G]{_S_RE_ASCII_ACCIDENTALS}?"
_S_RE_LOWER_PITCH_CLASS = rf"[a-g]{_S_RE_ASCII_ACCIDENTALS}?"
_RE_PITCH_CLASS = re.compile(_S_RE_PITCH_CLASS)
# _S_RE_PITCH_CLASS_ONE_ACC = r"[A-G][\#|b]?"
_RE_PITCH = re.compile(rf"(?P<pitch_class>{_S_RE_PITCH_CLASS})" r"\s*" r"(?P<octave>[0-9]+)")
_S_RE_LOWER_PITCH_CLASS = rf"[a-g]{_S_RE_ASCII_ACCIDENTALS}?"
RE_PITCH_CLASS = re.compile(_S_RE_PITCH_CLASS)

# fmt: off
RE_PITCH = re.compile(
rf"(?P<pitch_class>{_S_RE_PITCH_CLASS})"
r"\s*"
r"(?P<octave>[0-9]+)"
)
# fmt: on


def pitch_class_value(pitch: str, root: str = "C", *, mod: bool = False) -> int:
Expand All @@ -73,9 +80,9 @@ def pitch_class_value(pitch: str, root: str = "C", *, mod: bool = False) -> int:
"""
pitch = pitch.strip()

if not _RE_PITCH_CLASS.fullmatch(pitch):
if not RE_PITCH_CLASS.fullmatch(pitch):
raise ValueError(
f"invalid pitch class specification '{pitch}'; Should match '{_RE_PITCH_CLASS.pattern}'"
f"invalid pitch class specification '{pitch}'; Should match '{RE_PITCH_CLASS.pattern}'"
)

# Base value
Expand Down Expand Up @@ -648,7 +655,7 @@ def from_name(cls, name: str) -> "Pitch":
"""
name = name.strip()

m = _RE_PITCH.fullmatch(name)
m = RE_PITCH.fullmatch(name)
if m is None:
raise ValueError(f"invalid pitch name '{name}'")

Expand Down