示例#1
0
 def get_fitness (self):
     notes = self.notes
     original = self.orig_notes
     notes_on_key = 0
     note_density = 0
     num_notes = 0
     non_rest_tatums = 0
     markov_score = 0
     prob = []
     key = sound.get_key(self.notes)
     key_num = key[0]
     isMinor = False
     if key[2] == key[0]+3:
         isMinor = True
         prob = probdata.KP_MINOR_KEY_PROFILE_DATA
     else:
         prob = probdata.KP_MAJOR_KEY_PROFILE_DATA
         
     prev = 0
     for index, i in enumerate(self.notes):
         if len(i)!=0:
             note_val = sound.midival_note(i[0].midi_note)[0]
             non_rest_tatums += 1
             num_notes = num_notes+len(i)
             for note in i:
                 if sound.midival_note(note.midi_note)[0] in key:
                     notes_on_key += 1
             if index == 0:
                 prev = note_val
                 continue
             prob_ind = relative_distance (prev, note_val)
             #print prob_ind
             markov_score = markov_score+prob[prob_ind]*1000
             prev = note_val
         
             
     markov_score = float(markov_score)/float(non_rest_tatums)
     note_density = float(num_notes)/float(non_rest_tatums)
     dense_penalty = note_density - 1.0
     off_key_penalty = (1.0 - float(notes_on_key)/float(num_notes))*100
     print markov_score/float(non_rest_tatums), dense_penalty, off_key_penalty
     fitness = markov_score/float(non_rest_tatums)-dense_penalty-off_key_penalty
     return fitness
示例#2
0
 def mutate_add_minor_third(self):
    # print 'Adding minor third'
     """Add a minor note in the same key to a random tatum"""
     k = []
     while len(k)==0:
         tatum_index =  random.randint(1, (len(self.notes)-1))
         k = self.notes[tatum_index]
     if len(self.notes[tatum_index])>1:
         return
     index_in_tatum = random.randint(0,len(k)-1)
     note = sound.midival_note(self.notes[tatum_index][index_in_tatum].midi_note)[0]
     third = (note+3)%12
     duration = self.notes[tatum_index][0].duration
     self.notes[tatum_index].append(notes.Note(0,72+third,duration))
示例#3
0
 def mutate_add_fifth(self):
     """Add a fifth note in the same key to a random tatum"""
     #print 'Adding Fifth'
     k = []
     while len(k)==0:
         tatum_index =  random.randint(1, (len(self.notes)-1))
         k = self.notes[tatum_index]
     if len(self.notes[tatum_index])>1:
         return
     index_in_tatum = random.randint(0,len(k)-1)
     d = sound.make_scales()
     note = sound.midival_note(self.notes[tatum_index][index_in_tatum].midi_note)[0]
     fifth = d[str(note)][4]
     duration = self.notes[tatum_index][0].duration
     self.notes[tatum_index].append(notes.Note(0,72+fifth,duration))