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
Esempio n. 2
0
def common_note(phrase1, phrase2, key, mode):
    phrase1_list = []
    percentage = 0
    number_notes = 0
    key1 = key
    key2 = key
    
    if mode != "none" :     
        if phrase1[0]==0 :
            key1 = key
        elif phrase1[0]==4 :
            key1 = intervals.fourth(key, key)
        elif phrase1[0]==5:
            key1 = intervals.fifth(key, key)
            
        if phrase2[0]==0 :
            key2 = key
        elif phrase2[0]==4 :
            key2 = intervals.fourth(key, key)
        elif phrase2[0]==5:
            key2 = intervals.fifth(key, key)

    for bars in  phrase1[1][3] :
        for n in bars :
            notes = get_note(n, key1)
            phrase1_list.append(notes)
        
    for bars in phrase2[1][3] :
        for n in bars :
            number_notes+=1
            if get_note(n, key2) in phrase1_list:
                percentage+=1
    
    return (percentage/number_notes)*100
Esempio n. 3
0
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
Esempio n. 4
0
def second_voice_ending(second_track, key):
    first = key
    fourth = intervals.fourth(key, key)
    fifth = intervals.fifth(key, key)

    second_track.add_notes(Note(first, 3), 2)
    second_track.add_notes(Note(fourth, 3), 2)
    second_track.add_notes(Note(fifth, 3), 2)
    second_track.add_notes(Note(fifth, 3), 1)
Esempio n. 5
0
def triad(note, key):
    """Return the triad on note in key as a list.

    Examples:
    >>> triad('E', 'C')
    ['E', 'G', 'B']
    >>> triad('E', 'B')
    ['E', 'G#', 'B']
    """
    return [note, intervals.third(note, key), intervals.fifth(note, key)]
Esempio n. 6
0
def triad(note, key):
    """Return the triad on note in key as a list.

    Examples:
    >>> triad('E', 'C')
    ['E', 'G', 'B']
    >>> triad('E', 'B')
    ['E', 'G#', 'B']
    """
    return [note, intervals.third(note, key), intervals.fifth(note, key)]
Esempio n. 7
0
def gap_last_first_note(phrase1, phrase2, key, mode): 
    
    key1 = key
    key2 = key
    if mode != "none" : 
        if phrase1[0]==0 :
            key1 = key
        elif phrase1[0]==4 :
            key1 = intervals.fourth(key, key)
        elif phrase1[0]==5:
            key1 = intervals.fifth(key, key)
            
        if phrase2[0]==0 :
            key2 = key
        elif phrase2[0]==4 :
            key2 = intervals.fourth(key, key)
        elif phrase2[0]==5:
            key2 = intervals.fifth(key, key)
          
    last_note_1 = phrase1[1][3][phrase2[1][1]-1][-1:][0]
    last_note_2 = phrase2[1][3][phrase2[1][1]-1][-1:][0]
    last_note_1 = get_note(last_note_1, key1)
    last_note_2 = get_note(last_note_2, key2)
    return intervals.measure(last_note_1, last_note_2)
Esempio n. 8
0
def get_note_pattern(pattern, key):
    if pattern[0] == 1 :
        note = intervals.unison(key)
    elif pattern[0] == 2 :
        note = intervals.second(key, key)
    elif pattern[0] == 3 :
        note = intervals.third(key, key)
    elif pattern[0] == 4 :
        note = intervals.fourth(key, key)
    elif pattern[0] == 5 :
        note = intervals.fifth(key, key)
    elif pattern[0] == 6 :
        note = intervals.sixth(key, key)
    elif pattern[0] == 7 :
        note = intervals.seventh(key, key)

    if pattern[3] == "bemol":
        note = notes.diminish(note)
    elif pattern[3] == "diese" :
        note = notes.augment(note)
    return note
Esempio n. 9
0
'''
Created on Jan 6, 2017

@author: stephenkoh
'''

import mingus.core.intervals as intervals

key = str(input('Please enter a key: '))
note = str(input('Please enter a note: '))
third = intervals.third(note, key)
fifth = intervals.fifth(note, key)
print(note, third, fifth)
Esempio n. 10
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)
Esempio n. 11
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]