def from_shorthand(note, interval, up=True): """Returns the note on interval up or down. Example: {{{ >>> from_shorthand(\"A\", \"b3\") 'C' >>> from_shorthand(\"D\", \"2\") 'E' >>> from_shorthand(\"E\", \"2\", False) 'D' }}}""" # warning should be a valid note. if not notes.is_valid_note(note): return False # [shorthand, interval function up, interval function down] shorthand_lookup = [ ['1', major_unison, major_unison], ['2', major_second, minor_seventh], ['3', major_third, minor_sixth], ['4', major_fourth, major_fifth], ['5', major_fifth, major_fourth], ['6', major_sixth, minor_third], ['7', major_seventh, minor_second], ] # Looking up last character in interval in shorthand_lookup and calling that # function. val = False for shorthand in shorthand_lookup: if shorthand[0] == interval[-1]: if up: val = shorthand[1](note) else: val = shorthand[2](note) # warning Last character in interval should be 1-7 if val == False: return False # Collect accidentals for x in interval: if x == '#': if up: val = notes.augment(val) else: val = notes.diminish(val) elif x == 'b': if up: val = notes.diminish(val) else: val = notes.augment(val) else: return val
def from_shorthand(note, interval, up = True): """Returns the note on interval up or down. Example: {{{ >>> from_shorthand("A", "b3") 'C' >>> from_shorthand("D", "2") 'E' >>> from_shorthand("E", "2", False) 'D' }}}""" #warning should be a valid note. if not notes.is_valid_note(note): return False # [shorthand, interval function up, interval function down] shorthand_lookup = [ ["1", major_unison, major_unison], ["2", major_second, minor_seventh], ["3", major_third, minor_sixth], ["4", major_fourth, major_fifth], ["5", major_fifth, major_fourth], ["6", major_sixth, minor_third], ["7", major_seventh, minor_second] ] # Looking up last character in interval in shorthand_lookup # and calling that function. val = False for shorthand in shorthand_lookup: if shorthand[0] == interval[-1]: if up: val = shorthand[1](note) else: val = shorthand[2](note) #warning Last character in interval should be 1-7 if val == False: return False # Collect accidentals for x in interval: if x == "#": if up: val = notes.augment(val) else: val = notes.diminish(val) elif x == "b": if up: val = notes.diminish(val) else: val = notes.augment(val) else: return val
def augmented_triad(note): """Build an augmented triad on note. Example: >>> augmented_triad('C') ['C', 'E', 'G#'] """ return [note, intervals.major_third(note), notes.augment(intervals.major_fifth(note))]
def augmented_triad(note): """Builds an augmented triad on note. Example: {{{ >>> augmented_triad("C") ["C", "E", "G#"] }}}""" return [note, intervals.major_third(note),\ notes.augment(intervals.major_fifth(note))]
def lydian_dominant_seventh(note): """Builds the lydian dominant seventh (7#11) on note Example: {{{ >>> lydian_dominant_seventh('C') ['C', 'E', 'G', 'Bb', 'F#'] }}}""" return dominant_seventh(note) + [notes.augment(intervals.perfect_fourth(note))]
def lydian_dominant_seventh(note): """Build the lydian dominant seventh (7#11) on note. Example: >>> lydian_dominant_seventh('C') ['C', 'E', 'G', 'Bb', 'F#'] """ return (dominant_seventh(note) + [notes.augment(intervals.perfect_fourth(note))])
def melodic_minor(note): """Returns the melodic minor scale starting on note. Example: {{{ >>> melodic_minor("A") ["A", "B", "C", "D", "E", "F#", "G#"] }}}""" har = harmonic_minor(note) har[5] = notes.augment(har[5]) return har
def harmonic_minor(note): """Returns the harmonic minor scale starting on note. Example: {{{ >>> harmonic_minor("A") "A", "B", "C", "D", "E", "F", "G#"] }}}""" nat = natural_minor(note) nat[6] = notes.augment(nat[6]) return nat
def dominant_sharp_ninth(note): """Builds a dominant sharp ninth chord on note. Example: {{{ >>> dominant_ninth("C") ['C', 'E', 'G', 'Bb', 'D#'] }}}""" res = dominant_ninth(note) res[4] = notes.augment(intervals.major_second(note)) return res
def augmented_triad(note): """Builds an augmented triad on note. Example: {{{ >>> augmented_triad(\"C\") [\"C\", \"E\", \"G#\"] }}}""" return [note, intervals.major_third(note), notes.augment(intervals.major_fifth(note))]
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]]
def dominant_sharp_ninth(note): """Build a dominant sharp ninth chord on note. Example: >>> dominant_ninth('C') ['C', 'E', 'G', 'Bb', 'D#'] """ res = dominant_ninth(note) res[4] = notes.augment(intervals.major_second(note)) return res
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]]
def augment_or_diminish_until_the_interval_is_right(note1, note2, interval): """A helper function for the minor and major functions. \ You should probably not use this directly.""" cur = measure(note1, note2) while cur != interval: if cur > interval: note2 = notes.diminish(note2) elif cur < interval: note2 = notes.augment(note2) cur = measure(note1, note2) # We are practically done right now, but we need to be able to create # the minor seventh of Cb and get Bbb instead of B######### as the result val =0 for token in note2[1:]: if token == '#': val += 1 elif token == 'b': val -= 1 # These are some checks to see if we have generated too much #'s # or too much b's. In these cases we need to convert #'s to b's # and vice versa. if val > 6: val = val % 12 val = -12 + val elif val < -6: val = val % -12 val = 12 + val # Rebuild the note result = note2[0] while val > 0: result = notes.augment(result) val -= 1 while val < 0: result = notes.diminish(result) val += 1 return result
def augment_or_diminish_until_the_interval_is_right(note1, note2, interval): """A helper function for the minor and major functions. You should probably not \ use this directly.""" cur = measure(note1, note2) while cur != interval: if cur > interval: note2 = notes.diminish(note2) elif cur < interval: note2 = notes.augment(note2) cur = measure(note1, note2) # We are practically done right now, but we need to be able to create the # minor seventh of Cb and get Bbb instead of B######### as the result val = 0 for token in note2[1:]: if token == '#': val += 1 elif token == 'b': val -= 1 # These are some checks to see if we have generated too much #'s or too much # b's. In these cases we need to convert #'s to b's and vice versa. if val > 6: val = val % 12 val = -12 + val elif val < -6: val = val % -12 val = 12 + val # Rebuild the note result = note2[0] while val > 0: result = notes.augment(result) val -= 1 while val < 0: result = notes.diminish(result) val += 1 return result
def harmonic_minor(note): """Returns the harmonic minor scale starting on note. Example: {{{ >>> harmonic_minor(\"A\") \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G#\"] }}}""" nat = natural_minor(note) nat[6] = notes.augment(nat[6]) return nat
def lydian_dominant_seventh(note): """Builds the lydian dominant seventh (7#11) on note Example: {{{ >>> lydian_dominant_seventh('C') ['C', 'E', 'G', 'Bb', 'F#'] }}}""" return dominant_seventh(note)\ + [notes.augment(intervals.perfect_fourth(note))]
def melodic_minor(note): """Returns the melodic minor scale starting on note. Example: {{{ >>> melodic_minor(\"A\") [\"A\", \"B\", \"C\", \"D\", \"E\", \"F#\", \"G#\"] }}}""" har = harmonic_minor(note) har[5] = notes.augment(har[5]) return har
def augmented_triad(note): """Builds an augmented triad on note. Example: {{{ >>> augmented_triad(\"C\") [\"C\", \"E\", \"G#\"] }}}""" return [ note, intervals.major_third(note), notes.augment(intervals.major_fifth(note)) ]
def augmented_unison(note): return notes.augment(note)
def ascending(self): notes = NaturalMinor(self.tonic).ascending()[:-1] notes[5] = augment(notes[5]) notes[6] = augment(notes[6]) return notes * self.octaves + [notes[0]]