def reset(self, numberOfAgents=15): """ Initializes the simulation with the set number of agents and sets Simulation.resetDone = True. Should be called before starting any simulation run. """ self.agents = [] for i in range(numberOfAgents): new_midi = mid.prepare_initial_midi("../../res/midi_text.txt", "../../res/sample%d.midi" % i, self.defaultTempo) notes = [ event for event in new_midi.tracks[0].eventList if event.type == "note" ] for note in notes: note.volume = self.defaultVolume + random.random() * 0.5 + 0.75 new_midi.tracks[0].addTempo( note.time, self.defaultTempo + random.random() * 0.75 + 0.55) self.agents.append( Agent(i, self.weight_tempo, self.weight_loudness, self.weight_tempo_rules, self.weight_loudness_rules, new_midi, self.defaultTempo, self.defaultVolume)) self.resetDone = True self.__logger.info("Reset.")
def reset(self, numberOfAgents=15): """ Initializes the simulation with the set number of agents and sets Simulation.resetDone = True. Should be called before starting any simulation run. """ self.agents = [] for i in range(numberOfAgents): new_midi = mid.prepare_initial_midi("../../res/midi_text.txt", "../../res/sample%d.midi" % i, self.defaultTempo) notes = [event for event in new_midi.tracks[0].eventList if event.type == "note"] for note in notes: note.volume = self.defaultVolume + random.random() * 0.5 + 0.75 new_midi.tracks[0].addTempo(note.time, self.defaultTempo + random.random() * 0.75 + 0.55) self.agents.append(Agent(i, self.weight_tempo, self.weight_loudness, self.weight_tempo_rules, self.weight_loudness_rules, new_midi, self.defaultTempo, self.defaultVolume)) self.resetDone = True self.__logger.info("Reset.")
if ((tempo - nominal_tempo) - (prev_tempo - nominal_tempo)) * ((tempo - nominal_tempo) - (next_tempo - nominal_tempo)): score += 1 # we may hit the end of the score here except IndexError, err: print "End of score at %d?" % note.time # print err return score if __name__ == '__main__': # performance = mid.prepare_initial_midi("../../../res/midi_text.txt", "../../../res/sample.midi", 15200) import doctest doctest.testmod() exit() performance = mid.prepare_initial_midi("../../../res/midi_rule3_text.txt", "../../../res/sample_rule3.midi", 15200) group_structure = lbdm.getNoteGroups(performance) tempo_events = [(event.time, event.tempo) for event in performance.tracks[0].eventList if event.type == "tempo"] notes = [event for event in performance.tracks[0].eventList if event.type == "note"] nominal_tempo = 3947 nominal_loudness = 100 melodic_accent = melodic_accent.analyze_melodic_accent(performance) metric_structure, metrical_scores = metric_structure.getMetricStructure(performance) key = key_change.analyze_key_change(performance) accentuation = accentuation_curve.accentuation_curve(melodic_accent, metrical_scores, key, notes) print "Rule 1 tempo: %d" % rule1_tempo(group_structure, nominal_tempo, tempo_events) print "Rule 1 loudness: %d" % rule1_loudness(group_structure, nominal_loudness) print "Rule 2: %d" % rule2(group_structure, nominal_tempo, tempo_events) print "Rule 3: %d" % rule3(notes, nominal_loudness, accentuation) print "Rule 4 tempo: %d" % rule4_tempo(notes, accentuation, nominal_tempo, tempo_events) print "Rule 4 loudness: %d" % rule4_loudness(notes, accentuation, nominal_loudness)
def setUp(self): self.MIDI = midi.prepare_initial_midi("/res/midi_text.txt", "/res/midi_text.txt", 19000)
def __init__(self): self.midi = mid.prepare_initial_midi("../../res/midi_text.txt", "../../res/sample.midi", self.defaultTempo) self.__jobServer = pp.Server() self.__logger = log.get_logger(__name__)
for i in range(len(notes)): note = notes[i] # print i, note_find_measure(note) accentuation_curve[i] += w_key_change * keys[note_find_measure(note)] keys_final.append(keys[note_find_measure(note)]) # print keys_final # print accentuation_curve return accentuation_curve if __name__ == "__main__": from tools import midi as mid from tools.analysis import lbdm, metric_structure, melodic_accent, key_change performance = mid.prepare_initial_midi("../../../res/midi_text.txt", "../../../res/sample.midi", 15200) group_structure = lbdm.getNoteGroups(performance) tempo_events = [(event.time, event.tempo) for event in performance.tracks[0].eventList if event.type == "tempo"] notes = [ event for event in performance.tracks[0].eventList if event.type == "note" ] nominal_tempo = 3947 nominal_loudness = 100 melodic_accent = melodic_accent.analyze_melodic_accent(performance) metric_structure, metrical_scores = metric_structure.getMetricStructure( performance) key = key_change.analyze_key_change(performance) accentuation = accentuation_curve(melodic_accent, metrical_scores, key,
vector1_average = sum(vector1)/12. vector2_average = sum(vector2)/12. nominator = 0. denominator1 = denominator2 = 0. for v1, v2 in zip(vector1, vector2): v1diff = v1-vector1_average v2diff = v2-vector2_average nominator += v1diff * v2diff denominator1 += v1diff ** 2 denominator2 += v2diff ** 2 denominator = math.sqrt(denominator1 * denominator2) return nominator / denominator if __name__ == "__main__": # print CMaj # print rotate_array(CMaj,1) # print rotate_array(CMaj,2) from tools import midi as mid midi = mid.prepare_initial_midi("../../../res/midi_text.txt", "../../../res/sample.midi", 15200) track = midi.tracks[0] noteList = [noteEvent for noteEvent in track.eventList if noteEvent.type == "note"] # for i in range(0,6*960,960): # in_measure = notes_in_measure(noteList, i, i + 960) # print [midi_to_note(note.pitch) for note in in_measure] # print determine_key(in_measure, i+960) print analyze_key_change(midi) # for k in sorted(key_vectors.keys()): # print "%012s: %s" % (k,key_vectors[k])