def use_phrase(phrase_list, progression_list, nb_bars, pattern_index, mode='none', key="C"):
    print(str(progression_list))
    t = Track()
    if nb_bars == 1 :
        nb_p = 0
        for progression in progression_list[0] :
            if nb_p%4 == 0 :
                phrase = get_phrase(progression, phrase_list)
                print("boucle phrase doit apparaitre trois fois")
                last_note = None
                nb_bars = 0
                for bars in phrase[1][3] :
                    list_bar = generate_bar(last_note, bars, key, mode, progression, progression_list, nb_p+nb_bars, pattern_index)
                    b = list_bar[0]
                    last_note = list_bar[1]
                    nb_bars+=1
                    t.add_bar(b)
                    last_bar = bars

                if phrase[1][1] < 4 :
                    # composer le reste TODO en attendant on met du vide
                    last_bar_notes = list_bar[2]
                    print("lala "+str(last_bar_notes))

                    next_index = nb_p+4
                    if next_index < 9 :
                        next_progression = progression_list[0][next_index]
                        next_phrase = get_phrase(next_progression, phrase_list)
                        first_bar = next_phrase[1][3][0]
                        first_bar_list = generate_bar(last_note, first_bar, key, mode, next_progression, progression_list, nb_p+4, pattern_index)
                        first_bar_notes = first_bar_list[2]
                        
                        nb_notes_to_generate = get_nb_note_needed(last_bar, first_bar)
                        
                        print "****************** je vais generer la transition ! ****************"
                        transition_bar = generate_transition(first_bar_notes, last_bar_notes, nb_notes_to_generate, pattern_index, key)
                        print "***************************** Fini ! ******************************"
                        
                        for transition in transition_bar :
                            t.add_bar(transition)                        
                        """for i in range(len(transition_bar)):
                            t.add_bar(transition_bar[i])"""
                    else :
                        list_end = generate_end_bars(bars, list_bar[2], pattern_index, key, mode)
                        for end_bar in list_end :
                            t.add_bar(end_bar)
                        
                        break
                    
                nb_p +=1
            else :
                nb_p +=1
                continue
        return t
Example #2
0
def generate_chorus_bars(phrase_list, progression_list, nb_bars, pattern_index, mode='none', key="C"):
    print(str(progression_list))
    chorus = []
    chorus_ordered_bars = []
    transition = []
    if nb_bars == 1 :
        nb_p = 0
        for progression in progression_list[0] :
            if nb_p%4 == 0 and nb_p>3:
                phrase = get_phrase(progression, phrase_list)
                last_note = None
                nb_bars = 0
                for bars in phrase[1][3] :
                    list_bar = generate_bar(last_note, bars, key, mode, progression, progression_list, nb_p+nb_bars, pattern_index)
                    chorus.append(list_bar)
                    chorus_ordered_bars.append(list_bar[0])
                    last_note = list_bar[1]
                    nb_bars+=1
                    last_bar = bars
                
                last_notes = list_bar[2]

                if phrase[1][1] < 4 and nb_p+nb_bars < 10:
                    # composer le reste TODO en attendant on met du vide
                    last_bar_notes = list_bar[2]

                    next_index = nb_p+4
                    if next_index < 9 :
                        next_progression = progression_list[0][next_index]
                        next_phrase = phrase_list[1]
                        first_bar = next_phrase[1][3][0]
                        first_bar_list = generate_bar(last_note, first_bar, key, mode, next_progression, progression_list, nb_p+4, pattern_index)
                        first_bar_notes = first_bar_list[2]
                        
                        nb_notes_to_generate = get_nb_note_needed(last_bar, first_bar)        
                        
                    #gerer si c'est la fin ! TODO
                        print "****************** je vais generer la transition ! ****************"
                        transition_bar = generate_transition(first_bar_notes, last_bar_notes, nb_notes_to_generate, pattern_index, key)
                        print "***************************** Fini ! ******************************"
                                                
                    for i in range(len(transition_bar)):
                        chorus_ordered_bars.append(transition_bar[i])

                nb_p +=1
            else :
                nb_p +=1
                continue
            
            last_bar_chorus = phrase[1][3][len(phrase[1][3])-1]
            
    return (chorus, transition, chorus_ordered_bars, last_bar_chorus, last_notes)