def generate_blues_scale(key="C"):
    """Returns an ordered list of the notes of the blues scale in this key. \
For example: if the key is set to 'C', this function will return \
`['C', 'D#', 'F', 'F#', 'G', 'A#']`. \
This function will raise an !NoteFormatError if the key isn't recognised"""

    if not (notes.is_valid_note(key)):
        raise NoteFormatError, "Unrecognised format for key '%s'" % key

    result = []

    fifth_index = notes.fifths.index(key[0])

    result.append(intervals.unison(key))
    result.append(notes.diminish(intervals.third(key, key)))
    result.append(intervals.third(key, key))
    result.append(intervals.fourth(key, key))
    result.append(notes.diminish(intervals.fifth(key, key)))
    result.append(intervals.fifth(key, key))
    result.append(notes.diminish(intervals.seventh(key, key)))

    # Remove redundant #'s and b's from the result
    result = map(notes.remove_redundant_accidentals, result)
    tonic = result.index(notes.remove_redundant_accidentals(key))

    result = result[tonic:] + result[:tonic]

    return result
def get_progression_key(note_int, key):
    if note_int == 1 :
        p_key = intervals.unison(key)
    if note_int == 4 :
        p_key = intervals.fourth(key, key)
    if note_int == 5 :
        p_key = intervals.fifth(key, key)
    return p_key
Beispiel #3
0
def get_compatible_notes(pattern_index, right_hand_list, key, time):
    left_hand_list = get_note_list_left_hand(pattern_index, key, time)
    list_notes = []
    if len(left_hand_list)==0 :
        return right_hand_list
    
    for left_note in left_hand_list :
        for right_note in right_hand_list :
            note_str = intervals.unison(right_note.name, right_note.name)   
            if (intervals.measure(left_note, note_str)>2 and intervals.measure(left_note, note_str)<10) or intervals.measure(left_note, note_str)>11  :
                list_notes.append(right_note)
    return list_notes
Beispiel #4
0
def get_note(n, key):
    
    note = intervals.unison(key)
    if n[0] == 1 :
        note = intervals.unison(key)
    elif n[0] == 2 :
        note = intervals.second(key, key)
    elif n[0] == 3 :
        note = intervals.third(key, key)
    elif n[0] == 4 :
        note = intervals.fourth(key, key)
    elif n[0] == 5 :
        note = intervals.fifth(key, key)
    elif n[0] == 6 :
        note = intervals.sixth(key, key)
    elif n[0] == 7 :
        note = intervals.seventh(key, key)

    if n[3] == "bemol":
        note = notes.diminish(note)
    elif n[3] == "diese" :
        note = notes.augment(note)
    return note
Beispiel #5
0
def generate_end_bars(previews_bar, previews_bar_notes, pattern_index, key, mode):
    # on genere deux mesures de fin
    # previews_bar = format de la bdd
    nb_notes = get_nb_notes(previews_bar)
    first_bar = Bar()
    last_bar = Bar()
    last_index = len(previews_bar_notes)-1
    last_note = previews_bar_notes[last_index]
    
    for i in range(1, nb_notes[0]):
        time = first_bar.current_beat + 1
        list_compatible = get_compatible_notes(pattern_index, previews_bar_notes, key, time)
        list_length = get_max_length_note(first_bar, nb_notes[0]-i)
        best_notes = get_best_notes(list_compatible, last_note)
        chosen_note = best_notes[random.randint(0, len(best_notes)-1)]
        chosen_length = list_length[random.randint(0, len(list_length)-1)]
        first_bar.place_notes(chosen_note.name, chosen_length)
        
    if first_bar.length - first_bar.current_beat != 0 : 
        print("ajout de silence")
        space_left = 1.0 / (first_bar.length - first_bar.current_beat)
        first_bar.place_rest(space_left)
    
        
    for i in range(1, nb_notes[1]):
        time = last_bar.current_beat + 1
        list_compatible = get_compatible_notes(pattern_index, previews_bar_notes, key, time)
        list_length = get_max_length_note(last_bar, nb_notes[1]-i)
        best_notes = get_best_notes(list_compatible, last_note)
        chosen_note = best_notes[random.randint(0, len(best_notes)-1)]
        chosen_length = list_length[random.randint(0, len(list_length)-1)]
        #chosen_note.octave
        
        chord_possible = []
        chord_possible.append(intervals.unison(key, key))
        chord_possible.append(intervals.fourth(key, key))
        chord_possible.append(intervals.fifth(key, key))
        
        intervals_last = []
        
        for note_possible in chord_possible :
            test = []
            test.append(intervals.measure(note_possible, last_note.name))
            test.append(intervals.measure(last_note.name, note_possible))
            intervals_last.append(min(test))
        
        for i,j in enumerate(intervals_last) :
            if j == min(intervals_last) :
                index = i
                break
            
        chosen_chord = chord_possible[index] 
        
        if mode == "mixolydien" :
                            
            chord = chords.triad(chosen_chord, key)
            chord_list = []
            for note in chord :
                note_m = Note(note, chosen_note.octave)
                chord_list.append(note_m)
                last_note = note_m
            last_bar.place_notes(chord_list, chosen_length)
        else :
            chord = chords.triad(chosen_chord, key)
            chord_list = []
            for note in chord :
                note_m = Note(note, chosen_note.octave)
                last_note = note_m
                chord_list.append(note_m)
            last_bar.place_notes(chord_list, chosen_length)
            
    if last_bar.length - last_bar.current_beat != 0 : 
        print("ajout de silence")
        space_left = 1.0 / (last_bar.length - last_bar.current_beat)
        last_bar.place_rest(space_left)     
            
    return [first_bar, last_bar]