Exemplo n.º 1
0
def blues_scale(key):
    """Return a blues scale in a given key"""
    major_scale = list(scales.ionian(key))

    #Use mingus.containers.Note to represent notes so we have octave info
    for i, note in enumerate(major_scale):
        major_scale[i] = Note(note)
        if i>0 and major_scale[i]<major_scale[i-1]:
            major_scale[i].octave_up()

    # mingus.Scales is dumb, this is a workaround =/
    fifth = Note(major_scale[4])
    major_scale[2].diminish()
    major_scale[4].diminish()
    major_scale[6].diminish()
    seventh = Note(major_scale[0])
    seventh.octave_up()

    #assemble the blues scale
    blues_scale = [major_scale[0],
                   major_scale[2],
                   major_scale[3],
                   major_scale[4],
                   fifth,
                   major_scale[6],
                   seventh]

    return blues_scale
Exemplo n.º 2
0
def generate_pattern(progression_list, key = "C", pattern_index = 0, nb_bars=1):
    pattern = patterns.PATTERNS[pattern_index]
    t = Track()
    for progression in progression_list:
        progression = progression_to_int(progression)
        for p in progression : # permet d'avancer dans la progression des mesures
            previews_note = None
            p_key = get_progression_key(p, key)
            b = Bar(key, (4, 4))
            position_note = 0
            already_used=[]
            for pattern_note in pattern :
                if position_note not in already_used :
                    is_chord = chord_length(pattern_note, pattern, position_note)
                    if is_chord[2] :
                        note_list = []
                        # c est un accord
                        for p_note in pattern[is_chord[0]:is_chord[1]+1] :
                            note_str = get_note_pattern(p_note, p_key)
                            note = Note(note_str, p_note[5])
                            if previews_note is not None:
                                if p_note[4]=='+':
                                    if int(note) < previews_note :
                                        note.octave_up()
                                elif p_note[4]=='-':
                                    if int(note) > previews_note :
                                        note.octave_down()      
                            previews_note = int(note)
                            note_list.append(note)
                            
                        for n in range(is_chord[0], is_chord[1]+1):
                            already_used.append(n)
                        
                        b.place_notes(note_list, pattern_note[1])
    
                                
                    else :    
                        note_str = get_note_pattern(pattern_note, p_key)
                        note = Note(note_str, pattern_note[5])
                        
                        if previews_note is not None:
                            if pattern_note[4]=='+':
                                if int(note) < previews_note :
                                    note.octave_up()
    
                            elif pattern_note[4]=='-':
                                if int(note) > previews_note :
                                    note.octave_down()
                                    
                        previews_note = int(note)
                        b.place_notes(note, pattern_note[1])
                        already_used.append(position_note)
                position_note+=1
                
            t.add_bar(b)

    return t
Exemplo n.º 3
0
def play_pattern(pattern_index, key):
    pattern = patterns.PATTERNS[pattern_index]
    fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument

    previews_note = None
    b = Bar(key, (4, 4))
    position_note = 0
    already_used=[]
    for pattern_note in pattern :
        if position_note not in already_used :
            is_chord = chord_length(pattern_note, pattern, position_note)
            if is_chord[2] :
                note_list = []
                # c est un accord
                for p_note in pattern[is_chord[0]:is_chord[1]+1] :
                    note_str = get_note_pattern(p_note, key)
                    note = Note(note_str, p_note[5])
                    if previews_note is not None:
                        if p_note[4]=='+':
                            if int(note) < previews_note :
                                note.octave_up()
                        elif p_note[4]=='-':
                            if int(note) > previews_note :
                                note.octave_down()      
                    previews_note = int(note)
                    note_list.append(note)
                    
                for n in range(is_chord[0], is_chord[1]+1):
                    already_used.append(n)
                
                b.place_notes(note_list, pattern_note[1])

                        
            else :    
                note_str = get_note_pattern(pattern_note, key)
                note = Note(note_str, pattern_note[5])
                
                if previews_note is not None:
                    if pattern_note[4]=='+':
                        if int(note) < previews_note :
                            note.octave_up()

                    elif pattern_note[4]=='-':
                        if int(note) > previews_note :
                            note.octave_down()
                            
                previews_note = int(note)
                b.place_notes(note, pattern_note[1])
                already_used.append(position_note)
        position_note+=1
            
    fluidsynth.play_Bar(b, 1, 60)                      
Exemplo n.º 4
0
def generate_bar(previews_note, bar, key, mode, progression, progression_list, nb_p, pattern_index):
    if mode == 'mixolydien' :
        if progression == 'IV' :
            key = intervals.fourth(key, key)
        elif progression == 'V' :
            key = intervals.fifth(key, key)
        
    b = Bar(key, (4, 4))
    position_note = 0
    already_used=[]
    list_note = []
    
    for bar_note in bar :
        if position_note not in already_used :
            is_chord = chord_length(bar_note, bar, position_note)
            if is_chord[2] :
                note_list = []
                # c est un accord
                for p_note in bar[is_chord[0]:is_chord[1]+1] :
                    note_str = get_note(p_note, key)
                    note = Note(note_str, p_note[5])
                    if previews_note is not None:
                        if p_note[4]=='+':
                            if int(note) < previews_note :
                                note.octave_up()
                        elif p_note[4]=='-':
                            if int(note) > previews_note :
                                note.octave_down()
                    current_progression = progression_list[0][nb_p]
                    note = change_note_if_needed(bar_note[2], note, pattern_index, current_progression, bar_note, key)     
                    previews_note = int(note)
                    
                    #appeler best_note la aussi
                    note_list.append(note)
                    list_note.append(note)
                    
                for n in range(is_chord[0], is_chord[1]+1):
                    already_used.append(n)
                
                b.place_notes(note_list, bar_note[1])

                        
            else :  
                note_str = get_note(bar_note, key)
                note = Note(note_str, bar_note[5])
                
                if previews_note is not None:
                    if bar_note[4]=='+':
                        if int(note) < previews_note :
                            note.octave_up()

                    elif bar_note[4]=='-':
                        if int(note) > previews_note :
                            note.octave_down()
                
                # la un faut appeler le truc pour modifier la note
                current_progression = progression_list[0][nb_p]
                note = change_note_if_needed(bar_note[2], note, pattern_index, current_progression, bar_note, key)
                            
                previews_note = int(note)
                list_note.append(note)
                b.place_notes(note, bar_note[1])
                already_used.append(position_note)
        position_note+=1
     
    return (b, previews_note, list_note)
Exemplo n.º 5
0
def generate_pattern(progression_list, key = "C", pattern = ((1, 4, 1, "none", '=', 3), (3, 4, 2,"none", '+', 3), (5, 4, 3, "none", '+', 3), (6, 4, 4, "none", '+', 3)), nb_bars=1):
    #pattern = ((1, 4, 1, "none", '=', 3), (5, 4, 1, "none", '+', 3), (1, 4, 2, "none", '+', 3), (6, 4, 2, "none", '+', 3), (1, 4, 3, "none", '=', 3), (5, 4, 3, "none", '+', 3), (1, 4, 4, "none", '+', 3), (6, 4, 4, "none", '+', 3))
    #pattern = ((1, 8, 1, "none", '=', 2), (5, 8, 1, "none", '+', 2), (1, 8, 1.5, "none", '=', 2), (5, 8, 1.5, "none", '+', 2), (2, 8, 2, "diese", '=', 2), (3, 8, 2.5, "none", '+', 2), (1, 8, 3, "none", '=', 2), (5, 8, 3, "none", '+', 2), (1, 8, 3.5, "none", '=', 2), (5, 8, 3.5, "none", '+', 2), (2, 8, 4, "diese", '=', 2), (3, 8, 4.5, "none", '+', 2))
    #pattern = ((1, 8, 1, "none", '=', 3), (5, 8, 1, "none", '+', 3), (1, 8, 1.5, "none", '=', 3), (5, 8, 1.5, "none", '+', 3), (2, 8, 2, "diese", '-', 3), (3, 8, 2.5, "none", '+', 3), (1, 8, 3, "none", '=', 3), (5, 8, 3, "none", '+', 3), (1, 8, 3.5, "none", '=', 3), (5, 8, 3.5, "none", '+', 3), (1, 8, 4, "none", '=', 3), (6, 8, 4, "none", '+', 3), (1, 8, 4.5, "none", '=', 3), (6, 8, 4.5, "none", '+', 3))
    t = Track()
    for progression in progression_list:
        progression = progression_to_int(progression)
        for p in progression : # permet d'avancer dans la progression des mesures
            previews_note = None
            p_key = get_progression_key(p, key)
            b = Bar(key, (4, 4))
            position_note = 0
            already_used=[]
            for pattern_note in pattern :
                if position_note not in already_used :
                    is_chord = chord_length(pattern_note, pattern, position_note)
                    if is_chord[2] :
                        note_list = []
                        # c est un accord
                        for p_note in pattern[is_chord[0]:is_chord[1]+1] :
                            note_str = get_note_pattern(p_note, p_key)
                            note = Note(note_str, p_note[5])
                            if previews_note is not None:
                                if p_note[4]=='+':
                                    if int(note) < previews_note :
                                        note.octave_up()
                                elif p_note[4]=='-':
                                    if int(note) > previews_note :
                                        note.octave_down()      
                            previews_note = int(note)
                            note_list.append(note)
                            
                        for n in range(is_chord[0], is_chord[1]+1):
                            already_used.append(n)
                        
                        b.place_notes(note_list, pattern_note[1])
    
                                
                    else :    
                        note_str = get_note_pattern(pattern_note, p_key)
                        note = Note(note_str, pattern_note[5])
                        
                        if previews_note is not None:
                            if pattern_note[4]=='+':
                                if int(note) < previews_note :
                                    note.octave_up()
    
                            elif pattern_note[4]=='-':
                                if int(note) > previews_note :
                                    note.octave_down()
                                    
                        previews_note = int(note)
                        b.place_notes(note, pattern_note[1])
                        already_used.append(position_note)
                position_note+=1
                
            t.add_bar(b)
    print(str(t))
                    
    #track = LilyPond.from_Track(t)
    #test = LilyPond.to_png(track, "left_hand")
    #MidiFileOut.write_Track("test_midi.mid", t)
    return t