improvements

This commit is contained in:
2018-09-06 08:46:26 -04:00
parent 4850131ffc
commit 609b37a8c5
3 changed files with 26 additions and 4 deletions
+2
View File
@@ -47,4 +47,6 @@ This (work in progress) library attempt to make exploring music theory approacha
(0, 0, 0, 3, 3, 3)
```
It can also [generate charts for all known chords](https://gist.github.com/kennethreitz/b363660145064fc330c206294cff92fc) for any instrument (accuracy to be determined!).
✨🍰✨
+23 -3
View File
@@ -4,6 +4,7 @@ from .systems import SYSTEMS
from .tones import Tone
QUALITIES = ('', 'maj', 'm', '5', '7', '9', 'dim', 'm6', 'm7', 'maj7')
MAX_FRET = 7
CHARTS = {}
CHARTS['western'] = []
@@ -72,7 +73,7 @@ class NamedChord:
def _possible_fingerings(self, *, fretboard):
def find_fingerings(tone):
fingerings = []
for j in range(7):
for j in range(MAX_FRET):
fingered_tone = tone.add(j)
for acceptable_tone in self.acceptable_tones:
if fingered_tone.name == acceptable_tone:
@@ -83,6 +84,19 @@ class NamedChord:
fingering = []
for i, tone in enumerate(fretboard.tones):
fingering.append(find_fingerings(tone))
for i, finger in enumerate(fingering):
if finger == ():
fingering[i] = (-1,)
return tuple(fingering)
@staticmethod
def fix_fingering(fingering):
fingering = list(fingering)
for i, finger in enumerate(fingering):
if finger == -1:
fingering[i] = None
return tuple(fingering)
def fingerings(self, *, fretboard):
@@ -117,9 +131,9 @@ class NamedChord:
best_fingerings = tuple([g for g in gen()])
if not multiple:
return best_fingerings[0]
return self.fix_fingering(best_fingerings[0])
else:
return best_fingerings
return tuple([self.fix_fingering(f) for f in best_fingerings])
@@ -136,3 +150,9 @@ for tone_titles in SYSTEMS['western'].tone_names:
western_chart.update({f"{tone_name}{quality}": named_chord})
CHARTS['western'] = western_chart
def charts_for_fretboard(*, chart=CHARTS['western'], fretboard):
super_chart = {}
for chord in chart:
super_chart[chord] = chart[chord].fingering(fretboard=fretboard)
return super_chart
+1 -1
View File
@@ -4,4 +4,4 @@ from .tones import Tone
from .systems import System, SYSTEMS
from .scales import Scale, TonedScale
from .chords import Chord, Fretboard
from .charts import CHARTS
from .charts import CHARTS, charts_for_fretboard