Пример #1
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
Пример #2
0
def make_ascending(chord, octave=4):
    reduced_chord = [notes.reduce_accidentals(n) for n in chord]

    new_chord = [_add_octave_to_name(reduced_chord[0], octave)]
    for i in range(1, len(chord)):
        if reduced_chord[i - 1] == 'C' and reduced_chord[i] != 'C':
            pass
        elif intervals.measure(chord[i - 1], chord[i]) == intervals.measure(
                chord[i - 1], 'C') + intervals.measure('C', chord[i]):
            octave += 1
        new_chord.append(_add_octave_to_name(reduced_chord[i], octave))

    return _rewrite_names(new_chord, chord)
Пример #3
0
def interval_class(note_first, note_second):
    """ class 1: minor seconds/major sevenths (1 or 11)
        class 2: major seconds/minor sevenths (2 or 10)
        class 3: minor thirds /major sixths   (3 or 9)
        class 4: major thirds /minor sixths   (4 or 8)
        class 5: perfect fourths & fifths     (5 or 7)
        class 6: tritones                     (6)
    """
    return interval_class_map[intervals.measure(note_first, note_second)]
Пример #4
0
def interval_class(note_first, note_second):
    """ class 1: minor seconds/major sevenths (1 or 11)
        class 2: major seconds/minor sevenths (2 or 10)
        class 3: minor thirds /major sixths   (3 or 9)
        class 4: major thirds /minor sixths   (4 or 8)
        class 5: perfect fourths & fifths     (5 or 7)
        class 6: tritones                     (6)
    """
    return interval_class_map[intervals.measure(note_first, note_second)]
Пример #5
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)
Пример #6
0
notes.augment('C')  # C#
notes.diminish('C#')  # C
#大小调转化(无方法)
#notes.to_minor('C') # A
#notes.to_major('A') # C

#无模块
#import mingus.core.diatonic as diatonic
#十二音
#diatonic.basic_keys
#E调七音
#diatonic.get_notes('E')

import mingus.core.intervals as interval
#间隔半音数
interval.measure('C', 'D')  #2

import mingus.core.scales as scales
#爱奥尼音阶对象
scales.Ionian('C')

#音对象
from mingus.containers import Note
#C4音对象
n = Note('C')
#变为C5
n.set_note('C', 5)
#音对象属性
n.name  #十二音名
n.octave  #第几八度
n.dynamics  #其它属性
Пример #7
0
 def test_valid_measure(self):
     self.assertEqual(0, intervals.measure('C', 'C'))
     self.assertEqual(4, intervals.measure('C', 'E'))
     self.assertEqual(8, intervals.measure('E', 'C'))
Пример #8
0
def inverse(track):
    # Copy value of reference to aviod problems with overwriting
    inversed_track = copy.deepcopy(track)
    transposed = 0

    #"note" generator
    input_notes = inversed_track.get_notes()
    #note[-1] is a note container
    #note[-1][0] is a note

    #take out the first actual note from the "note" generator
    tmp = next(input_notes)[-1]
    while (tmp is None):
        tmp = next(input_notes)[-1]

    start_note = tmp[0]
    #save the note name value without axidentals for camparison with the scale string
    base_note_value = start_note.name[0]

    if not (base_note_value == "C"):
        transposed = intervals.measure(start_note.name[0].split("-")[0], "C")
        inversed_track = transpose_from_halfnote(inversed_track, transposed)
        input_notes = inversed_track.get_notes()
        tmp = next(input_notes)[-1]
        while (tmp is None):
            tmp = next(input_notes)[-1]
        start_note = tmp[0]
        base_note_value = start_note.name[0]

    #create a string with the ordered notes from the cmaj scale starting from the note after
    #the base_note_value until the base_note_value is read again. This is used to calculate the
    #inversed notes later on
    Cmaj_scale = "CDEFGABCDEFGAB"
    scale = Cmaj_scale.split(base_note_value)[1]

    #Its not pretty nut it seems to work
    #For every bar/"note" we get out of the note generator
    for bar in input_notes:

        #Check if the nc contained in the bar/"note" is a pause, then do nothing
        nc = bar[-1]
        if nc is None:
            continue

        #Otherwise
        else:
            #For every actual note in the note containers (important if there is a chord)
            for note in nc:

                #initial value for an offset variable
                diff = 0

                #If the note doesn't have the same note name (eg. "C" or "D") as the base note
                #We calculate how many steps in the major scale we have to take to find
                # A note that corresponds the one we have without accidentals.
                # (eg. base_note_val ="C", note = "Eb" we have to take 2 steps to find "E" in Cmaj)
                if not (note.name[0] == base_note_value):
                    diff = scale.index(note.name[0]) + 1

                #Calculation of octave, a little messy but works
                if base_note_value == "C":
                    if note.name[0] == "C":
                        note.octave = start_note.octave + (start_note.octave -
                                                           note.octave)
                    else:
                        note.octave = start_note.octave + (start_note.octave -
                                                           note.octave - 1)

                else:
                    print("something went wrong with inverse")

                #Use offset to assign the note the correct note value in C-maj
                if not (note.name[0] == base_note_value):
                    note.name = scale[-diff]
                else:
                    note.name = base_note_value

                #TODO Add the right accidentals to the notes depending on the scale

    if not (transposed == 0):
        inversed_track = transpose_from_halfnote(inversed_track, transposed,
                                                 False)

    #return inversed track
    return inversed_track
Пример #9
0
 def test_valid_measure(self):
     self.assertEqual(0, intervals.measure("C", "C"))
     self.assertEqual(4, intervals.measure("C", "E"))
     self.assertEqual(8, intervals.measure("E", "C"))
Пример #10
0
	def test_valid_measure(self):
		self.assertEqual(0, intervals.measure("C", "C"))
		self.assertEqual(4, intervals.measure("C", "E"))
		self.assertEqual(8, intervals.measure("E", "C"))
Пример #11
0
import mingus.core.notes as notes
import mingus.core.keys as keys
import mingus.core.intervals as intervals

print(notes.is_valid_note('C#'))
print(notes.int_to_note(0))  # [0,..,11]

print(keys.get_notes("C"))

print(intervals.second("E", "C"))
print(intervals.determine("Gbb", "Ab"))
print(intervals.determine("Gbb", "Ab", True))
print(intervals.measure("C", "D"))
print(intervals.measure("D", "C"))
Пример #12
0
 def test_valid_measure(self):
     self.assertEqual(0, intervals.measure('C', 'C'))
     self.assertEqual(4, intervals.measure('C', 'E'))
     self.assertEqual(8, intervals.measure('E', 'C'))
Пример #13
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]