-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3df32bb
commit 83fe05e
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from .scales import CHROMATIC_SCALE | ||
|
||
def construct_fretting(tuning, fret_limit=12): | ||
""" | ||
`tuning` is a string describing the notes sounded by the guitar string when | ||
played in open. No length restrictions are imposed because, hey, whatever | ||
set-up floats your guitar. :) | ||
""" | ||
fretting = [] | ||
|
||
for open_note in tuning: | ||
string = [] | ||
open_norm = open_note.upper() | ||
initial_index = CHROMATIC_SCALE.index(open_norm) | ||
|
||
for i in range(fret_limit + 1): | ||
string.append(CHROMATIC_SCALE[(initial_index + i) % len(CHROMATIC_SCALE)]) | ||
|
||
fretting.append(string) | ||
|
||
return fretting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from ..guitar import construct_fretting | ||
|
||
import unittest | ||
|
||
class GuitarTests(unittest.TestCase): | ||
|
||
def test_construct_fretting(self): | ||
standard_fretting = [ | ||
["E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E"], | ||
["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A"], | ||
["D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D"], | ||
["G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G"], | ||
["B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"], | ||
["E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E"], | ||
] | ||
|
||
self.assertEqual(standard_fretting, construct_fretting("EADGBe")) |