=============================================================================
E E||---|---|-G-|---|-A-|---|---|-C-|---|-D-|---|-E-|---|---|-G-|---|-A-|---|---|
B ||-C-|---|-D-|---|-E-|---|---|-G-|---|-A-|---|---|-C-|---|-D-|---|-E-|---|---|
G G||---|-A-|---|---|-C-|---|-D-|---|-E-|---|---|-G-|---|-A-|---|---|-C-|---|-D-|
D D||---|-E-|---|---|-G-|---|-A-|---|---|-C-|---|-D-|---|-E-|---|---|-G-|---|-A-|
A A||---|---|-C-|---|-D-|---|-E-|---|---|-G-|---|-A-|---|---|-C-|---|-D-|---|-E-|
E E||---|---|-G-|---|-A-|---|---|-C-|---|-D-|---|-E-|---|---|-G-|---|-A-|---|---|
=============================================================================
3 5 7 9 12 15 17 19
The fretboard
module is a relatively simple python module for displaying notes and scales relative to a guitar's
fretboard. It currently supports ASCII output.
Before getting to scales and displays, it is useful to know how the module handles representations of musical notes.
The fretboard
module doesn't deal with the acoustic pitch of notes; rather it represents notes in terms of their number of semitones relative to a C reference.
Notes can be created either by naming the note and optionally appending "#" or "b" to indicate a sharp or flat note.
In [1]:
from fretboard import *
c = Note('C')
print (c)
In [2]:
Note('C#')
Out[2]:
In [3]:
Note('Db')
Out[3]:
In [4]:
Note('B#')
Out[4]:
If you like, you can use multiple sharps or flats.
In [5]:
Note('B##'), Note('B###'), Note('B##b')
Out[5]:
In [6]:
f = c + 5
print (f)
Adding 12 semitones gets us back to the same note.
In [7]:
ff = f + 12
print (ff)
In [8]:
print (ff - c)
Note that the interval printed above is the total number of semitones (which can span more than one octave) and can be positive or negative. If we want the to know the simple (within-octave) interval from a note up to the next instance of another note, the interval
method (or function) can be used).
In [9]:
print (c.interval(f))
In [10]:
print (f.interval(c))
In [11]:
c_maj = Major('C')
print (c_maj)
We can also create different modes of the diatonic scale. For example, the minor scale is just the sixth mode of the diatonic scale.
In [12]:
c_min = Diatonic('C', mode=6)
print (c_min)
There is also a Minor
scale class so you can save some typing (and don't have to remember which mode of the major scale it is). In addition to the Major
and Minor
, there are also classes for HarmonicMinor
, Pentatonic
, and Blues
scales.
In [13]:
a_pmin = MinorPentatonic('A')
print (a_pmin)
The Blues
scale adds a flat fifth (the blue note) to the pentatonic minor.
In [14]:
a_blues = Blues('A')
print (a_blues)
To make the scales useful, we have the ability to test for membership.
In [15]:
'C' in a_blues
Out[15]:
In [16]:
'B' in a_blues
Out[16]:
We can also get the interval of a given note with respect to the scale.
In [17]:
print (a_blues.get_interval_name('G'))
In [18]:
console.show_scale(Minor('A'))
In [19]:
console.show_scale(Major('C'), tuning='D A D G A D', fmt='interval')
There are various optional show_scale
arguments that can be used to customize the display. The fmt
argument can be any of the following:
<text char>
- display the specified character (e.g., '*') for each note<callable>
- display the return value of the callable oject applied to each Fret
object of the displayIf a callable object is given for fmt
, it is passed a Fret
object that has the following attributes:
note
- the Note
object associated with the fretstring
- the number of the string associated with the fretnumber
- the number of the fret (zero indicates open string)For example, let's display A Minor Pentatonic with "R" displayed for the root note and "*" for all others.
In [20]:
scale = MinorPentatonic('A')
console.show_scale(scale, fmt=lambda f: 'R' if f.note == scale.root else '*')
Let's display scale intervals for Box 2 of the A Minor Pentatonic scale.
In [21]:
console.show_scale(scale, fmt=lambda f: scale.get_interval_name(f.note) if f.number in range(7, 11) else None)
The show_scale
function is a convenient wrapper around the Console
class. To have greater control
over the display, we can work with a Console object directly. We'll create one and change the fill characters to be just empty space.
In [22]:
c = Console()
c.fret_fill_char = ' '
c.fret_empty_fill_char = ' '
c.display_scale(scale)
c.show()
The Console
class also has a display_fret
method that allows us to control display of individual frets. Let's use that to display a C chord.
In [23]:
c = Console()
for (s, f) in [(1, 0), (2, 1), (3, 0), (4, 2), (5, 3)]:
c.display_fret(s, f)
c.display_fret(6, 0, 'x')
c.show(fmax=5)
Finally, the Console.show
method prints the display to stdout
. To get the display string directly, use the get_display
method instead.
In [24]:
text = c.get_display(fmax=5)
print (text)