示例#1
0
def get_nb_notes(last_bar):
    velocity = get_pattern_velocity(last_bar)

    if velocity == 1 :
        return [len(last_bar), 1]
    elif velocity == 2:
        return [4, 2]
    else :
        return [6, 3]
示例#2
0
def generate_chorus(progression_list, pattern_index, mode, key):
    pattern = patterns.PATTERNS[pattern_index]
    velocity_pattern = get_pattern_velocity(pattern)
    
    phrase_list = []

    list_phrases_4 = choose_chord_4_phrase(mode)
    list_phrases_5 = choose_chord_5_phrase(mode)
    
    if velocity_pattern == 3:
        for phrase in list_phrases_4 :
            if velocity_phrase == 3:
                list_phrases_4.remove(phrase)
                
        for phrase in list_phrases_5 :
            if velocity_phrase == 3:
                list_phrases_5.remove(phrase)

    phrase_4_index = random.randint(0, len(list_phrases_4)-1)

    phrase_4 = list_phrases_4[phrase_4_index]
    phrase_4_chosen = [4, phrase_4]
    phrase_list.append(phrase_4_chosen)
    
    velocity_phrase_4 = velocity_phrase(phrase_4)
    for phrase_5 in list_phrases_5 :
        if abs(velocity_phrase(phrase_5)-velocity_phrase_4)>1 :
            list_phrases_5.remove(phrase_5)
            
            
    compatibility = []
    for phrase_5 in list_phrases_5 :
        phrase_5_to_test = [5, phrase_5]
        compatibility.append(calcul_compatibility(phrase_4_chosen, phrase_5_to_test, key, mode))
    
    list_best_phrase_5 = get_best_options(compatibility)
    index_phrase_5 = random.randint(0, len(list_best_phrase_5)-1)
    
    phrase_5 = list_phrases_5[index_phrase_5]
    phrase_5_chosen = [5, phrase_5]
    phrase_list.append(phrase_5_chosen)

    
    notes_4=[]
    
    chorus = generate_chorus_bars(phrase_list, progression_list, 1, pattern_index, mode, key)
    last_notes = chorus[4]
   
    return (chorus, phrase_4_chosen, phrase_5_chosen, last_notes)
示例#3
0
def choose_first_phrases(nb_bars, key, mode, first_chorus_phrase, last_chorus_phrase, pattern_index):
    list_phrases_1 = choose_chord_1_phrase(mode)
    final_list = []
    pattern = patterns.PATTERNS[pattern_index]
    velocity_pattern = get_pattern_velocity(pattern)
    
    if velocity_pattern == 3:
        for phrase in list_phrases_1 :
            if velocity_phrase == 3:
                list_phrases_1.remove(phrase)
                
    phrase_first = choose_best_phrase(list_phrases_1, first_chorus_phrase, key, mode)
    final_list.append(phrase_first)
    
    for i in range(0, nb_bars-2):
        list_best_options = choose_between_phrase(list_phrases_1, first_chorus_phrase, last_chorus_phrase, key, mode, nb_bars)
        phrase_index = random.randint(0, len(list_best_options)-1)
        final_list.append([1, list_best_options[phrase_index]])
       
    phrase_last = choose_best_phrase(list_phrases_1, last_chorus_phrase, key, mode)

    final_list.append(phrase_last)
    
    return final_list