def measure(note1, note2): """Return an integer in the range of 0-11, determining the half note steps between note1 and note2. Examples: >>> measure('C', 'D') 2 >>> measure('D', 'C') 10 """ res = notes.note_to_int(note2) - notes.note_to_int(note1) if res < 0: return 12 - res * -1 else: return res
def measure(note1, note2): """Returns an integer in the range of 0-11, determining the half note \ steps between note1 and note2. Examples: {{{ >>> measure("C", "D") 2 >>> measure("D", "C") 10 }}}""" res = notes.note_to_int(note2) - notes.note_to_int(note1) if res < 0: return 12 - (res * (-1)) else: return res
def int_to_note(note_int, key): """A better implementation of int_to_note found in the [refMingusCoreNotes \ notes] module. This version bears the key in mind and thus creates \ theoretically correct notes. Will throw a !RangeError if `note_int` is not \ in range(0,12)""" if note_int not in range(0, 12): raise RangeError, 'Integer not in range 0-11.' intervals = [ 0, 2, 4, 5, 7, 9, 11, ] current = notes.note_to_int(key) known_intervals = map(lambda x: (x + current) % 12, intervals) known_notes = get_notes(key) if note_int in known_intervals: return known_notes[known_intervals.index(note_int)] else: if note_int - 1 in known_intervals: return notes.remove_redundant_accidentals( known_notes[known_intervals.index(note_int - 1)] + '#') elif note_int + 1 in known_intervals: return notes.remove_redundant_accidentals( known_notes[known_intervals.index(note_int + 1)] + 'b')
def int_to_note(note_int, key): """A better implementation of int_to_note found in the [refMingusCoreNotes \ notes] module. This version bears the key in mind and thus creates \ theoretically correct notes. Will throw a !RangeError if `note_int` is not \ in range(0,12)""" if note_int not in range(0, 12): raise RangeError, 'Integer not in range 0-11.' intervals = [ 0, 2, 4, 5, 7, 9, 11, ] current = notes.note_to_int(key) known_intervals = map(lambda x: (x + current) % 12, intervals) known_notes = get_notes(key) if note_int in known_intervals: return known_notes[known_intervals.index(note_int)] else: if note_int - 1 in known_intervals: return notes.remove_redundant_accidentals(known_notes[known_intervals.index(note_int - 1)] + '#') elif note_int + 1 in known_intervals: return notes.remove_redundant_accidentals(known_notes[known_intervals.index(note_int + 1)] + 'b')
def measure(note1, note2): """Returns an integer in the range of 0-11, determining the half note steps \ between note1 and note2. Examples: {{{ >>> measure(\"C\", \"D\") 2 >>> measure(\"D\", \"C\") 10 }}}""" res = notes.note_to_int(note2) - notes.note_to_int(note1) if res < 0: return 12 - res * -1 else: return res
def get_interval(note, interval, key = 'C'): """Gets 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 = diatonic.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:])
def get_interval(note, interval, key='C'): """Gets 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 = diatonic.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:])