Exemple #1
0
 def mutate_add_note(self):
     """Add a note in the same key to a random tatum"""
     #print 'Adding Note'
     scale = sound.get_key(self.notes)
     tactus_index = random.randint(1, (len(self.notes)-1)/4)
     tatum_index = tactus_index*4 - 1
     if len(self.notes[tatum_index])>1:
         return
     note_index = random.randint(0, (len(scale)-1))
     note = scale[note_index]
     if len(self.notes[tatum_index])==0:
         duration = 1
     else:
         duration = self.notes[tatum_index][0].duration
     self.notes[tatum_index].append(notes.Note(0,48+note,duration))
Exemple #2
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