Пример #1
0
def sevenths(key):
    """Return all the sevenths chords in key in a list."""
    if key in _sevenths_cache:
        return _sevenths_cache[key]
    res = [seventh(x, key) for x in keys.get_notes(key)]
    _sevenths_cache[key] = res
    return res
Пример #2
0
def sevenths(key):
    """Return all the sevenths chords in key in a list."""
    if _sevenths_cache.has_key(key):
        return _sevenths_cache[key]
    res = map(lambda x: seventh(x, key), keys.get_notes(key))
    _sevenths_cache[key] = res
    return res
Пример #3
0
def sevenths(key):
    """Return all the sevenths chords in key in a list."""
    if _sevenths_cache.has_key(key):
        return _sevenths_cache[key]
    res = map(lambda x: seventh(x, key), keys.get_notes(key))
    _sevenths_cache[key] = res
    return res
Пример #4
0
def triads(key):
    """Return all the triads in key.

    Implemented using a cache.
    """
    if _triads_cache.has_key(key):
        return _triads_cache[key]
    res = map(lambda x: triad(x, key), keys.get_notes(key))
    _triads_cache[key] = res
    return res
Пример #5
0
 def descending(self):
     notes = [self.tonic]
     for note in reversed(get_notes(self.key)):
         if intervals.determine(note, notes[-1]) == ("major second"):
             notes.append(reduce_accidentals(diminish(notes[-1])))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
Пример #6
0
 def ascending(self):
     notes = [self.tonic]
     for note in get_notes(self.key)[1:] + [self.tonic]:
         if intervals.determine(notes[-1], note) == ("major second"):
             notes.append(augment(notes[-1]))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
Пример #7
0
 def descending(self):
     notes = [self.tonic]
     for note in reversed(get_notes(self.key)):
         if intervals.determine(note, notes[-1]) == ('major second'):
             notes.append(reduce_accidentals(diminish(notes[-1])))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
Пример #8
0
def triads(key):
    """Return all the triads in key.

    Implemented using a cache.
    """
    if _triads_cache.has_key(key):
        return _triads_cache[key]
    res = map(lambda x: triad(x, key), keys.get_notes(key))
    _triads_cache[key] = res
    return res
Пример #9
0
def triads(key):
    """Return all the triads in key.

    Implemented using a cache.
    """
    if key in _triads_cache:
        return _triads_cache[key]
    res = [triad(x, key) for x in keys.get_notes(key)]
    _triads_cache[key] = res
    return res
Пример #10
0
 def ascending(self):
     notes = [self.tonic]
     for note in get_notes(self.key)[1:] + [self.tonic]:
         if intervals.determine(notes[-1], note) == ('major second'):
             notes.append(augment(notes[-1]))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
Пример #11
0
def determine(notes):
    """Determine the scales containing the notes.

    All major and minor scales are recognized.

    Example:
    >>> determine(['A', 'Bb', 'E', 'F#', 'G'])
    ['G melodic minor', 'G Bachian', 'D harmonic major']
    """
    notes = set(notes)
    res = []

    for key in keys:
        for scale in _Scale.__subclasses__():
            if scale.type == "major":
                if notes <= set(scale(key[0]).ascending()) or notes <= set(scale(key[0]).descending()):
                    res.append(scale(key[0]).name)
            elif scale.type == "minor":
                if notes <= set(scale(get_notes(key[1])[0]).ascending()) or notes <= set(
                    scale(get_notes(key[1])[0]).descending()
                ):
                    res.append(scale(get_notes(key[1])[0]).name)
    return res
Пример #12
0
def determine(notes):
    """Determine the scales containing the notes.

    All major and minor scales are recognized.

    Example:
    >>> determine(['A', 'Bb', 'E', 'F#', 'G'])
    ['G melodic minor', 'G Bachian', 'D harmonic major']
    """
    notes = set(notes)
    res = []

    for key in keys:
        for scale in _Scale.__subclasses__():
            if scale.type == 'major':
                if (notes <= set(scale(key[0]).ascending())
                        or notes <= set(scale(key[0]).descending())):
                    res.append(scale(key[0]).name)
            elif scale.type == 'minor':
                if (notes <= set(scale(get_notes(key[1])[0]).ascending())
                        or notes <= set(
                            scale(get_notes(key[1])[0]).descending())):
                    res.append(scale(get_notes(key[1])[0]).name)
    return res
Пример #13
0
def interval(key, start_note, interval):
    """Return the note found at the interval starting from start_note in the
    given key.

    Raise a KeyError exception if start_note is not a valid note.

    Example:
    >>> interval('C', 'D', 1)
    'E'
    """
    if not notes.is_valid_note(start_note):
        raise KeyError("The start note '%s' is not a valid note" % start_note)
    notes_in_key = keys.get_notes(key)
    for n in notes_in_key:
        if n[0] == start_note[0]:
            index = notes_in_key.index(n)
    return notes_in_key[(index + interval) % 7]
Пример #14
0
def interval(key, start_note, interval):
    """Return the note found at the interval starting from start_note in the
    given key.

    Raise a KeyError exception if start_note is not a valid note.

    Example:
    >>> interval('C', 'D', 1)
    'E'
    """
    if not notes.is_valid_note(start_note):
        raise KeyError("The start note '%s' is not a valid note" % start_note)
    notes_in_key = keys.get_notes(key)
    for n in notes_in_key:
        if n[0] == start_note[0]:
            index = notes_in_key.index(n)
    return notes_in_key[(index + interval) % 7]
Пример #15
0
def get_interval(note, interval, key='C'):
    """Return the note an interval (in half notes) away from the given note.

    This will produce mostly theoretical sound results, but you should use
    the minor and major functions to work around the corner cases.
    """
    intervals = map(lambda x: (notes.note_to_int(key) + x) % 12, [
        0,
        2,
        4,
        5,
        7,
        9,
        11,
        ])
    key_notes = keys.get_notes(key)
    for x in key_notes:
        if x[0] == note[0]:
            result = (intervals[key_notes.index(x)] + interval) % 12
    if result in intervals:
        return key_notes[intervals.index(result)] + note[1:]
    else:
        return notes.diminish(key_notes[intervals.index((result + 1) % 12)]
                               + note[1:])
Пример #16
0
def get_interval(note, interval, key='C'):
    """Return the note an interval (in half notes) away from the given note.

    This will produce mostly theoretical sound results, but you should use
    the minor and major functions to work around the corner cases.
    """
    intervals = [(notes.note_to_int(key) + x) % 12 for x in [
        0,
        2,
        4,
        5,
        7,
        9,
        11,
    ]]
    key_notes = keys.get_notes(key)
    for x in key_notes:
        if x[0] == note[0]:
            result = (intervals[key_notes.index(x)] + interval) % 12
    if result in intervals:
        return key_notes[intervals.index(result)] + note[1:]
    else:
        return notes.diminish(key_notes[intervals.index((result + 1) % 12)] +
                              note[1:])
Пример #17
0
 def ascending(self):
     notes = get_notes(self.tonic.lower())
     return notes * self.octaves + [notes[0]]
Пример #18
0
 def __init__(self, key, octaves=1):
     """Create the chromatic scale in the chosen key."""
     self.key = key
     self.tonic = get_notes(key)[0]
     self.octaves = octaves
     self.name = "{0} chromatic".format(self.tonic)
Пример #19
0
 def __init__(self, key, octaves=1):
     """Create the chromatic scale in the chosen key."""
     self.key = key
     self.tonic = get_notes(key)[0]
     self.octaves = octaves
     self.name = '{0} chromatic'.format(self.tonic)
Пример #20
0
 def ascending(self):
     notes = get_notes(self.tonic.lower())
     return notes * self.octaves + [notes[0]]