def matchingNotes( self, scoreStream, transcribedScore, notePrediction, lastNotePosition, ): from music21 import audioSearch # Analyzing streams tn_recording = int(len(transcribedScore.flat.notesAndRests)) totScores = [] beginningData = [] lengthData = [] END_OF_SCORE = False # take 10% more of samples tn_window = int(math.ceil(tn_recording * 1.1)) hop = int(math.ceil(tn_window / 4)) if hop == 0: iterations = 1 else: iterations = int((math.floor(len(scoreStream) / hop)) - math.ceil(tn_window / hop)) for i in range(iterations): scNotes = scoreStream[i * hop + 1:i * hop + tn_recording + 1] name = '%d' % i beginningData.append(i * hop + 1) lengthData.append(tn_recording) scNotes.id = name totScores.append(scNotes) listOfParts = search.approximateNoteSearchWeighted( transcribedScore.flat.notesAndRests.stream(), totScores) #decision process if notePrediction > len(scoreStream) - tn_recording - hop - 1: notePrediction = len(scoreStream) - tn_recording - hop - 1 END_OF_SCORE = True environLocal.printDebug('LAST PART OF THE SCORE') #lastCountdown = self.countdown position, self.countdown = audioSearch.decisionProcess( listOfParts, notePrediction, beginningData, lastNotePosition, self.countdown, self.firstNotePage, self.lastNotePage, ) totalLength = 0 number = int(listOfParts[position].id) if self.silencePeriod is True and self.silencePeriodCounter < 5: # print(lastCountdown, self.countdown, lastNotePosition, # beginningData[number], lengthData[number]) environLocal.printDebug('All rest period') self.countdown -= 1 if self.countdown != 0: probabilityHit = 0 else: probabilityHit = listOfParts[position].matchProbability unused_listOfParts2 = search.approximateNoteSearch( transcribedScore.flat.notesAndRests.stream(), totScores) unused_listOfParts3 = search.approximateNoteSearchNoRhythm( transcribedScore.flat.notesAndRests.stream(), totScores) unused_listOfParts4 = search.approximateNoteSearchOnlyRhythm( transcribedScore.flat.notesAndRests.stream(), totScores) # print('PROBABILITIES:',) # print('pitches and durations weighted (current)', listOfParts[position].matchProbability,) # print('pitches and durations without weighting' , listOfParts2[position].matchProbability,) # print('pitches', listOfParts3[position].matchProbability,) # print('durations', listOfParts4[position].matchProbability) for i in range(len(totScores[number])): totalLength = totalLength + totScores[number][i].quarterLength if self.countdown == 0 and self.silencePeriodCounter == 0: lastNotePosition = beginningData[number] + lengthData[number] return totalLength, lastNotePosition, probabilityHit, END_OF_SCORE
def matchingNotes( self, scoreStream, transcribedScore, notePrediction, lastNotePosition, ): from music21 import audioSearch # Analyzing streams tn_recording = int(len(transcribedScore.flat.notesAndRests)) totScores = [] beginningData = [] lengthData = [] END_OF_SCORE = False # take 10% more of samples tn_window = int(math.ceil(tn_recording * 1.1)) hop = int(math.ceil(tn_window / 4)) if hop == 0: iterations = 1 else: iterations = int((math.floor(len(scoreStream) / hop)) - math.ceil(tn_window / hop)) for i in range(iterations): scNotes = scoreStream[i * hop + 1:i * hop + tn_recording + 1] name = "%d" % i beginningData.append(i * hop + 1) lengthData.append(tn_recording) scNotes.id = name totScores.append(scNotes) listOfParts = search.approximateNoteSearchWeighted( transcribedScore.flat.notesAndRests.stream(), totScores) #decision process if notePrediction > len(scoreStream) - tn_recording - hop - 1: notePrediction = len(scoreStream) - tn_recording - hop - 1 END_OF_SCORE = True environLocal.printDebug("LAST PART OF THE SCORE") #lastCountdown = self.countdown position, self.countdown = audioSearch.decisionProcess( listOfParts, notePrediction, beginningData, lastNotePosition, self.countdown, self.firstNotePage, self.lastNotePage, ) totalLength = 0 number = int(listOfParts[position].id) if self.silencePeriod is True and self.silencePeriodCounter < 5: # print(lastCountdown, self.countdown, lastNotePosition, # beginningData[number], lengthData[number]) environLocal.printDebug("All rest period") self.countdown -= 1 if self.countdown != 0: probabilityHit = 0 else: probabilityHit = listOfParts[position].matchProbability unused_listOfParts2 = search.approximateNoteSearch( transcribedScore.flat.notesAndRests.stream(), totScores) unused_listOfParts3 = search.approximateNoteSearchNoRhythm( transcribedScore.flat.notesAndRests.stream(), totScores) unused_listOfParts4 = search.approximateNoteSearchOnlyRhythm( transcribedScore.flat.notesAndRests.stream(), totScores) # print "PROBABILITIES:", # print "pitches and durations weighted (current)",listOfParts[position].matchProbability, # print "pitches and durations without weighting" , listOfParts2[position].matchProbability, # print "pitches", listOfParts3[position].matchProbability, # print "durations",listOfParts4[position].matchProbability for i in range(len(totScores[number])): totalLength = totalLength + totScores[number][i].quarterLength if self.countdown == 0 and self.silencePeriodCounter == 0: lastNotePosition = beginningData[number] + lengthData[number] return totalLength, lastNotePosition, probabilityHit, END_OF_SCORE