From 00ede99bca46949f7aea1e9b30c8ca8a8a290f9e Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Sep 2018 04:53:34 -0400 Subject: [PATCH] fingerings are working --- pytheory/bootstrap.py | 4 ++-- pytheory/chords.py | 10 ++++++++-- pytheory/systems.py | 19 ++++++++++--------- pytheory/tones.py | 35 +++++++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/pytheory/bootstrap.py b/pytheory/bootstrap.py index 33a4470..8812cff 100644 --- a/pytheory/bootstrap.py +++ b/pytheory/bootstrap.py @@ -1,7 +1,7 @@ - +from .tones import Tone # SYSTEMS = {"western": System(tones=TONES["western"], degrees=DEGREES["western"])} -def SYSTEMS(SYSTEMS, DEGREES, TONES, Tone, System): +def SYSTEMS(SYSTEMS, DEGREES, TONES, System): western_tones = [Tone.from_string(t) for t in TONES["western"]] SYSTEMS = {"western": System(tones=western_tones, degrees=DEGREES["western"])} return SYSTEMS diff --git a/pytheory/chords.py b/pytheory/chords.py index 8b345b0..c2b5257 100644 --- a/pytheory/chords.py +++ b/pytheory/chords.py @@ -2,6 +2,10 @@ class Chord: def __init__(self, *, tones): self.tones = tones + def __repr__(self): + l = tuple([tone.full_name for tone in self.tones]) + return f"" + # @property # def harmony(self): # pass @@ -23,6 +27,8 @@ class Fretboard: if not len(positions) == len(self.tones): raise ValueError("The number of positions must match the number of tones (strings).") - results = [] + tones = [] for (i, tone) in enumerate(self.tones): - pass + tones.append(tone.add(positions[i])) + + return Chord(tones=tones) diff --git a/pytheory/systems.py b/pytheory/systems.py index 818c0e9..59bf466 100644 --- a/pytheory/systems.py +++ b/pytheory/systems.py @@ -1,15 +1,10 @@ from ._statics import TEMPERAMENTS, TONES, DEGREES, SCALES, SYSTEMS -from .tones import Tone from . import bootstrap class System: - def __init__(self, *, tones, degrees, scales=None): - self.tones = tones - - # Add current system to tones (a bit of a hack). - for tone in self.tones: - tone.system = self + def __init__(self, *, tone_names, degrees, scales=None): + self.tone_names = tone_names self.degrees = degrees self._scales = scales @@ -19,7 +14,13 @@ class System: @property def semitones(self): - return len(self.tones) + return len(self.tone_names) + + @property + def tones(self): + from . import Tone + return tuple([Tone.from_string(tone) for tone in self.tone_names]) + @property def scales(self): @@ -119,4 +120,4 @@ class System: def __repr__(self): return f"" -SYSTEMS = bootstrap.SYSTEMS(SYSTEMS=SYSTEMS, DEGREES=DEGREES, TONES=TONES, Tone=Tone, System=System) +SYSTEMS = {"western": System(tone_names=TONES["western"], degrees=DEGREES["western"])} diff --git a/pytheory/tones.py b/pytheory/tones.py index d48055a..169f98b 100644 --- a/pytheory/tones.py +++ b/pytheory/tones.py @@ -3,18 +3,30 @@ from ._statics import REFERENCE_A, TEMPERAMENTS class Tone: # __slots__ = ("name", "octave", "system") - def __init__(self, *, name, octave=None, system=None): + def __init__(self, *, name, octave=None, system='western'): self.name = name self.octave = octave - self.system = system - if self.system: - try: - assert self.name in self.system.tones - except AssertionError: - raise ValueError( - f"Tone {self.name!r} was not found in system: {self.system.tones!r}" - ) + if isinstance(system, str): + self.system_name = system + self._system = None + else: + self.system_name = None + self._system = system + + @property + def exists(self): + return self.name in self.system.tones + + @property + def system(self): + from .systems import SYSTEMS + + if self._system: + return self._system + + if self.system_name: + return SYSTEMS[self.system_name] @property def full_name(self): @@ -47,7 +59,10 @@ class Tone: except ValueError: octave = None - return klass(name=tone, octave=octave, system=system) + if system: + return klass(name=tone, octave=octave, system=system) + else: + return klass(name=tone, octave=octave) @classmethod def from_index(klass, i, *, octave, system):