Ejemplo n.º 1
0
 def format_notes(self, notes):
     """
     Formats the notes into a list of measures.
     
     Input
     - measure: current measure object
     
     Output - None
     """
     measure_counter, time_counter = 0, 0
     curr_measure = Measure(measure_counter, self.time_signature[0],
                            self.time_signature[1])
     for i in range(len(notes)):
         row = notes.iloc[i]
         note = Note(row.given_pitch,
                     row.signal,
                     row.loudness,
                     row.time,
                     duration=row.duration,
                     typ=row.typ)
         if time_counter + row.duration > 4:
             """FIXME: this fills up the rest of the measure with a rest, but it can be better
             Ideally it would be smart enough to wrap up a measure if there's little cutoff or
             tie current note into next measure."""
             curr_measure.wrap_up_time()
             self.addMeasure(curr_measure)
             measure_counter += 1
             time_counter = 0
             curr_measure = Measure(measure_counter, self.time_signature[0],
                                    self.time_signature[1])
         curr_measure.addNote(row)
     curr_measure.wrap_up_time()
     self.addMeasure(curr_measure)
Ejemplo n.º 2
0
    def addMeasure(self, vector, length=4):
        # Takes in a vector and generates a measure based on the features of the vector
        self.current_measure += 1
        if self.binaryProbability(vector.getRepetition()) == True:
            if self.current_measure > 1:
                measure_index = random.choice(range(len(self.measures)))
                the_measure = self.measures[measure_index]
                new_vec = the_measure.getVector(
                )  # If we're repeating, we want the user's opinion to reflect on the randomly selected vector's properties, except for the repetition property. This should reflect upon the current vectors (called 'vector') repetition property. So we make a new vector that has the randomly selected vector's properties except for repetition, which is taken from the current vector that caused us to repeat
                new_vec.setRepetition(vector.getRepetition())
                the_measure.setVector(new_vec)
                self.measures.append(the_measure)  # Add the first measure.
                return
        measure = Measure()
        measure.setVector(vector)
        time_left = float(length)
        self.chanceToChangeOctave(vector.getOctaveChance())
        while time_left > 0:
            pitch_list = self.buildNoteRatioList(vector.getGoodNoteRatio())
            if measure == []:
                # First note in the measure, just choose an item from our possible pitches randomly. <- Could be improved
                pitch = random.choice(pitch_list)
            else:
                # otherwise, incorporate the variety distance weight.
                pitch_list.extend(
                    self.buildDistanceRatio(measure[-1],
                                            vector.getNoteDistance()))
                pitch = random.choice(pitch_list)
            if time_left != 4:
                duration = self.pickDuration(vector.getVarietyDuration(),
                                             time_left, measure)
            else:
                duration = random.choice(
                    [.25, .5, 1, 2,
                     4])  # First note, choose a duration randomly
            note = Note(4 - time_left, 1, pitch, duration, 100)
            measure.addNote(note)

            # Check to see if adding a chord
            if self.binaryProbability(vector.getOneVsChord()):
                # We rolled a chord.
                pitches_in_chord = self.chordList(pitch)
                for chord_pitch in pitches_in_chord:
                    chord_note = Note(4 - time_left, 1, chord_pitch, duration,
                                      100)
                    measure.addNote(chord_note)
            time_left -= duration
        self.measures.append(measure)
Ejemplo n.º 3
0
	def addMeasure(self,vector,length=4):
		# Takes in a vector and generates a measure based on the features of the vector
		self.current_measure +=1	
		if self.binaryProbability(vector.getRepetition()) == True:
			if self.current_measure > 1:
				measure_index = random.choice(range(len(self.measures)))
				the_measure = self.measures[measure_index]
				new_vec = the_measure.getVector() # If we're repeating, we want the user's opinion to reflect on the randomly selected vector's properties, except for the repetition property. This should reflect upon the current vectors (called 'vector') repetition property. So we make a new vector that has the randomly selected vector's properties except for repetition, which is taken from the current vector that caused us to repeat
				new_vec.setRepetition(vector.getRepetition())
				the_measure.setVector(new_vec)
				self.measures.append(the_measure) # Add the first measure.	
				return
		measure = Measure()
		measure.setVector(vector)
		time_left = float(length)
		self.chanceToChangeOctave(vector.getOctaveChance())
		while time_left > 0:
			pitch_list = self.buildNoteRatioList(vector.getGoodNoteRatio())
			if measure == []:
				# First note in the measure, just choose an item from our possible pitches randomly. <- Could be improved
				pitch = random.choice(pitch_list)
			else:
				# otherwise, incorporate the variety distance weight.
				pitch_list.extend(self.buildDistanceRatio(measure[-1],vector.getNoteDistance()))
				pitch = random.choice(pitch_list)
			if time_left != 4:
				duration = self.pickDuration(vector.getVarietyDuration(),time_left,measure)
			else:
				duration = random.choice([.25,.5,1,2,4]) # First note, choose a duration randomly
			note = Note(4-time_left,1,pitch,duration,100)
			measure.addNote(note)

			# Check to see if adding a chord
			if self.binaryProbability(vector.getOneVsChord()):
				# We rolled a chord.
				pitches_in_chord = self.chordList(pitch)
				for chord_pitch in pitches_in_chord:
					chord_note = Note(4-time_left,1,chord_pitch,duration,100)
					measure.addNote(chord_note)	
			time_left -= duration
		self.measures.append(measure)
Ejemplo n.º 4
0
    def testNoteSorting(self):
        measure = Measure()
        class Note(object):
            def __init__(self, start):
                self.start = start

        noteA = Note(start=5)
        noteB = Note(start=6)
        
        measure.addNote(noteB)
        measure.addNote(noteA)
        
        self.assertEqual([5, 6], [note.start for note in measure.orderedNotes()])
        
        noteC = Note(start=17)
        noteD = Note(start=1)
        measure.addNote(noteD)
        measure.addNote(noteC)
        measure.addNote(Note(start=5))
        
        self.assertEqual([1, 5, 5, 6, 17], [note.start for note in measure.orderedNotes()])