def fbFeatureExtraction(): exampleFB = converter.parse('ismir2011_fb_example1b.xml') fe1 = features.jSymbolic.PitchClassDistributionFeature(exampleFB) print (fe1.extract().vector) # [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.6666666666666666, 0.0, 0.0, 1.0, 0.0, 0.0] n1 = exampleFB.parts[0][1][5] n1.expressions.append(expressions.Turn()) x = expressions.realizeOrnaments(n1) n2 = exampleFB.parts[0][2][2] n2.expressions.append(expressions.Mordent()) y = expressions.realizeOrnaments(n2) exampleFB.parts[0][1].elements = [exampleFB.parts[0][1][4]] exampleFB.parts[0][1].append(x) exampleFB.parts[0][2].elements = [exampleFB.parts[0][2][0], exampleFB.parts[0][2][1]] exampleFB.parts[0][2].append(y) fb1 = figuredBass.realizer.figuredBassFromStream(exampleFB.parts[1]) #realization = fb1.realize() sol1 = fb1.generateRandomRealization() exampleFBOut = stream.Score() exampleFBOut.insert(0, exampleFB.parts[0]) exampleFBOut.insert(0, sol1.parts[0]) exampleFBOut.insert(0, sol1.parts[1]) fe1.setData(exampleFBOut) print (fe1.extract().vector)
def createSingleTurnMeasure(): ''' Returns a dictionary with the following keys returnDict = { 'name': string, 'midi': measure stream, 'omr': measure stream, 'expected': measure stream, } ''' omrMeasure = stream.Measure() omrNote = note.Note('F') omrNote.duration = duration.Duration('whole') omrMeasure.append(omrNote) expectedFixedOmrMeasure = stream.Stream() expectedOmrNote = deepcopy(omrNote) expectedOmrNote.expressions.append(expressions.Turn()) expectedFixedOmrMeasure.append(expectedOmrNote) midiMeasure = stream.Measure() turn = [note.Note('G'), note.Note('F'), note.Note('E'), note.Note('F')] midiMeasure.append(turn) returnDict = { 'name': 'Single Turn Measure', 'midi': midiMeasure, 'omr': omrMeasure, 'expected': expectedFixedOmrMeasure, } return returnDict
def createSingleTurnMeasure(): ''' Returns a dictionary with the following keys returnDict = { "name": string, "midi": measure stream, "omr": measure stream, "expected": measure stream, } ''' omrMeasure = stream.Measure() omrNote = note.Note("F") omrNote.duration = duration.Duration("whole") omrMeasure.append(omrNote) expectedFixedOmrMeasure = stream.Stream() expectedOmrNote = deepcopy(omrNote) expectedOmrNote.expressions.append(expressions.Turn()) expectedFixedOmrMeasure.append(expectedOmrNote) midiMeasure = stream.Measure() turn = [note.Note("G"), note.Note("F"), note.Note("E"), note.Note("F")] midiMeasure.append(turn) returnDict = { "name": "Single Turn Measure", "midi": midiMeasure, "omr": omrMeasure, "expected": expectedFixedOmrMeasure, } return returnDict
def recognize( self, busyNotes, simpleNotes=None, ) -> Union[bool, expressions.Turn, expressions.InvertedTurn]: ''' Tries to identify the busy notes as a turn or inverted turn. When simple notes is provided, tries to identify busy notes as the turn shortened by simple notes. Currently only supports one simple note in simple notes. Turns and inverted turns have four notes separated by m2, M2, A2. Turns: start above base note go down to base note, go down again, and go back up to base note Inverted Turns: start below base note go up to base note, go up again, and go back down to base note When going up or down, must go to the adjacent note name, so A goes down to G, G#, G flat, G##, etc Returns: False if not possible or the Turn/Inverted Turn Expression ''' # number of notes/ duration of notes ok if len(busyNotes) != 4: return False if simpleNotes: eps = 0.1 totalBusyNotesDuration = 0 for n in busyNotes: totalBusyNotesDuration += n.duration.quarterLength if abs(simpleNotes[0].duration.quarterLength - totalBusyNotesDuration) > eps: return False # pitches ok if busyNotes[1].pitch.midi != busyNotes[3].pitch.midi: return False if simpleNotes and simpleNotes[0].pitch.midi != busyNotes[1].pitch.midi: return False # intervals ok firstInterval = interval.Interval(noteStart=busyNotes[0], noteEnd=busyNotes[1]) if not self.isAcceptableInterval(firstInterval): return False secondInterval = interval.Interval(noteStart=busyNotes[1], noteEnd=busyNotes[2]) if not self.isAcceptableInterval(secondInterval): return False thirdInterval = interval.Interval(noteStart=busyNotes[2], noteEnd=busyNotes[3]) if not self.isAcceptableInterval(thirdInterval): return False # goes in same direction if firstInterval.direction != secondInterval.direction: return False # and then in opposite direction if secondInterval.direction == thirdInterval.direction: return False # decide direction of turn to return if firstInterval.direction == interval.Interval('M-2').direction: # down turn = expressions.Turn() else: turn = expressions.InvertedTurn() turn.quarterLength = self.calculateOrnamentNoteQl(busyNotes, simpleNotes) return turn