Example #1
0
def test_relationships():
    assert Note('C') - Note('D') == 10
    assert Note('D') - Note('C') == 2
    assert Note('B') - Note('C') == 11
    assert Note('C') - Note('B') == 1
    assert Note('C') - Note('C') == 0
    assert Note('G') - Note('C') == 7
    assert Note('C') - Note('G') == 5

    assert Note('A#') == Note('Bb')
    assert Note(Note('C')) == 'C'
Example #2
0
def test_alterations():
    assert Note('C♯#') == Note('D')
    assert Note('C##') == 'D'
    assert str(Note('C♯♯')) == 'D'
    assert Note('Dbb') == Note('C')
    assert Note('C##♯♯') == Note('E')
    assert Note('C###').name == 'D♯'
    assert Note('Fbb').name == 'E♭'

    # We want to keep alterations
    assert [Note('C') - alt for alt in range(15)] == \
           ['C', 'B', 'B♭', 'A', 'A♭', 'G', 'G♭', 'F', 'E', 'E♭', 'D', 'D♭', 'C', 'B', 'B♭']
    assert [Note('C') + alt for alt in range(15)] == \
           ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B', 'C', 'C♯', 'D']
Example #3
0
 def relativeMajor(self, asStr=False):
     if self.mode == 'aeo':  # Relative Minor is 1.5 tone above key
         return Scale(Note(self.root) + 3, 'ion').name if asStr else Scale(
             Note(self.root) + 3, 'ion')
     else:
         return None
Example #4
0
 def parallelMajor(self, asStr=False):
     if self.mode == 'aeo':
         return Scale(Note(self.root), 'ion').name if asStr else Scale(
             Note(self.root), 'ion')
     else:
         return None
Example #5
0
def plotNotes(notes, pos=None, name='', ax=0, nbOctaves=1):
    if pos is None:
        pos = [0, 0, 100, 40]

    def plotKey(ax, x, y, w, h, keyType, status):
        lw = .5
        pad = 0.5
        # edgeColor = 'w'
        # parms = dict(
        #     black=dict(color=['skyblue', 'steelblue'], z=1),
        #     white=dict(color=['skyblue', 'steelblue'], z=0)
        # )

        edgeColor = 'k'
        parms = dict(black=dict(color=['k', 'skyblue'], z=1),
                     white=dict(color=['w', 'skyblue'], z=0))

        ax.add_patch(
            FancyBboxPatch((x + pad, y + pad),
                           abs(w) - 2 * pad,
                           abs(h) - 2 * pad,
                           boxstyle="round,pad=" + str(pad),
                           fc=parms[keyType]['color'][status],
                           ec=edgeColor,
                           zorder=parms[keyType]['z'],
                           lw=lw))

    nb = int(np.ceil(len(notes) / (nbOctaves * 12)) * (nbOctaves * 12))
    start = 'C' if notes[0] - Note('C') < notes[0] - Note('F') else 'F'
    chromatic = Note.chrSharp * 4
    chromatic = chromatic[chromatic.index(Note(start)):]
    chromatic = chromatic[:nb]
    whites = [
        n for n in chromatic
        if n in [Note(n) for n in ['C', 'D', 'E', 'F', 'G', 'A', 'B']]
    ]
    whiteWidth = pos[2] / len(whites)
    blackWidth = whiteWidth / 2

    if ax == 0:
        figure(figsize=(3, 1))
        ax = gca()
    axis('off')

    nWhites = 0
    for i, n in enumerate(chromatic):
        if n in whites:
            plotKey(ax,
                    pos[0] + (nWhites) * whiteWidth,
                    pos[1],
                    whiteWidth,
                    pos[3],
                    keyType='white',
                    status=n in notes)
            nWhites += 1
        else:
            plotKey(ax,
                    pos[0] + (nWhites) * whiteWidth - blackWidth / 2,
                    pos[1] + pos[3] / 3,
                    blackWidth,
                    2 * pos[3] / 3,
                    keyType='black',
                    status=n in notes)
    plot(0, 0, '.w', zorder=-1)
    if name:
        text(pos[0],
             pos[1] + pos[3] / 2,
             name,
             ha='right',
             va='center',
             rotation=90)