def unifiedTest(self): C4 = Note(); C4.name = "C" D4 = Note(); D4.name = "D" E4 = Note(); E4.name = "E" F4 = Note(); F4.name = "F" G4 = Note(); G4.name = "G" A4 = Note(); A4.name = "A" B4 = Note(); B4.name = "B" C5 = Note(); C5.name = "C"; C5.octave = 5 D5 = Note(); D5.name = "D"; D5.octave = 5 a = VoiceLeadingQuartet(C4, D4, G4, A4) assert a.similarMotion() == True assert a.parallelMotion() == True assert a.antiParallelMotion() == False assert a.obliqueMotion() == False assert a.parallelInterval(interval.stringToInterval("P5")) == True assert a.parallelInterval(interval.stringToInterval("M3")) == False b = VoiceLeadingQuartet(C4, C4, G4, G4) assert b.noMotion() == True assert b.parallelMotion() == False assert b.antiParallelMotion() == False assert b.obliqueMotion() == False c = VoiceLeadingQuartet(C4, G4, C5, G4) assert c.antiParallelMotion() == True assert c.hiddenInterval(interval.stringToInterval("P5")) == False d = VoiceLeadingQuartet(C4, D4, E4, A4) assert d.hiddenInterval(Interval("P5")) == True assert d.hiddenInterval(Interval("A4")) == False assert d.hiddenInterval(Interval("AA4")) == False
def searchForNotes(notesStr): '''the notesStr is a string of notes in the following form: "C4 D4 E4 B3 C4" that's it: name, octave. With no accidentals. If octave is 0 then it means do not bother checking for octaves. Currently octave is ignored anyhow. ''' notesArr = notesStr.split() noteObjArr = [] for tN in notesArr: tNName = tN[0] if tNName.lower() != "r": tNObj = Note() tNObj.name = tN[0] tNObj.octave = int(tN[1]) else: tNObj = Rest() noteObjArr.append(tNObj) ballataObj = cadencebook.BallataSheet() searcher1 = NoteSearcher(noteObjArr) streamLily = "" for thisWork in ballataObj: for thisCadence in thisWork.snippets: if thisCadence is None: continue for i in range(len(thisCadence.parts)): if searcher1.compareToStream(thisCadence.parts[i].flat) is True: notesList = "" for thisNote in thisCadence.parts[i].flat.notesAndRests: #thisNote.editorial.color = "blue" if hasattr(thisNote.lily, "value"): notesList += thisNote.lily.value + " " streamLily += "\\score {" + \ "<< \\time " + str(thisCadence.timeSig) + \ "\n \\new Staff {" + str(thisCadence.parts[i].lily) + "} >>" + \ thisCadence.header() + "\n}\n" print("In piece %r found in stream %d: %s" % (thisWork.title, i, notesList)) if streamLily: lS = lily.lilyString.LilyString(streamLily) lS.showPNG()
def searchForIntervals(notesStr): '''notesStr is the same as above. Now however we check to see if the generic intervals are the same, rather than the note names. Useful if the clef is missing. ''' notesArr = notesStr.split() noteObjArr = [] for tN in notesArr: tNObj = Note() tNObj.name = tN[0] tNObj.octave = int(tN[1]) noteObjArr.append(tNObj) interObjArr = [] for i in range(len(noteObjArr) - 1): int1 = interval.notesToInterval(noteObjArr[i], noteObjArr[i+1]) interObjArr.append(int1) #print interObjArr searcher1 = IntervalSearcher(interObjArr) ballataObj = cadencebook.BallataSheet() streamLily = "" for thisWork in ballataObj: for thisCadence in thisWork.snippets: if (thisCadence is None): continue for i in range(len(thisCadence.parts)): if searcher1.compareToStream(thisCadence.parts[i].flat) is True: notesList = "" for thisNote in thisCadence.parts[i].flat.notes: notesList += thisNote.name + " " #thisNote.editorial.color = "blue" streamLily += "\\score {" + \ "<< \\time " + str(thisCadence.timeSig) + \ "\n \\new Staff {" + str(thisCadence.parts[i].lily) + "} >>" + \ str(thisCadence.header()) + "\n}\n" print("In piece %r found in stream %d: %s" % (thisWork.title, i, notesList)) if streamLily: print(streamLily) lily.lilyString.LilyString(streamLily).showPDF()
def generate(tune, clef=m21.clef.TrebleClef()): # Load in the score score = m21utils.loadScoreForTune(tune) # Some basic preprocessing / cleanup score.parts[0].removeByClass('Instrument') score.parts[0].partName = None m21.harmony.realizeChordSymbolDurations(score) ## Argh!!! # Go measure by measure and build the study measures = score.parts[0].getElementsByClass("Measure") for measure in measures: # print measure # Remove any existing notes in the measure (we're about to add our own) measure.removeByClass('Note') # Grab the list of chord symbols in this measure chordSymbols = measure.getElementsByClass( 'ChordSymbol').matchingElements() # Remove the chord symbols so we can add them back interleaved with the notes # we're about to add measure.removeByClass('ChordSymbol') # Add notes for each chord symbol for symbol in chordSymbols: measure.append(symbol) # print symbol.duration.quarterLength n3 = Note(symbol.third) n3.duration = Duration(symbol.duration.quarterLength * 0.50) n3.octave = 5 n3.lyric = '3' measure.append(n3) if (symbol.containsSeventh()): n7 = m21.note.Note(symbol.seventh) n7.duration = Duration(symbol.duration.quarterLength * 0.50) n7.lyric = '7' n7.octave = 5 measure.append(n7) else: n5 = m21.note.Note(symbol.root()) n5.duration = Duration(symbol.duration.quarterLength * 0.50) n5.lyric = 'R' n5.octave = 5 measure.append(n5) # TODO: don't think this is needed # if measure.number % 4 == 0: # measure.append(m21.layout.SystemLayout(isNew=True)) # for x in range(len(c)): # MyMeasure = Measure() ## Make a measure and put everything inside it # MyMeasure.number = m.number ## give the measure a number # MyMeasure.rightBarline = m.rightBarline # MyMeasure.leftBarline = m.leftBarline # # print("_____________________") # # print("In measure "+ str(m.number) + "(" + str(m.id) + ")" +" of " + str(len(s)) ) #debug monitoring # c = m.getElementsByClass(ChordSymbol) # for x in range(len(c)): # # print(c[x].duration) # # print(c[x].beat) # # print (c[x].figure) # # print("--------------------") # TheFigure = c[x].figure # MyChord = Chord(c[x].pitches) # MySymbol = ChordSymbol() # ######## Fix XML chord symbols ############ # if (TheFigure.find(" alter b9") != -1): # MySymbol = m21utils.writeFlatNine(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" add b9") != -1): # MySymbol = m21utils.writeFlatNine(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" add #9") != -1): # MySymbol = m21utils.writeSharpNine(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" add #7") != -1): # MySymbol = m21utils.writeSharpSeven(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" add #11") != -1): # MySymbol = m21utils.writeSharpEleven(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" add b13") != -1): # MySymbol = m21utils.writeFlatThirteen(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" add b6") != -1): # MySymbol = m21utils.writeFlatSix(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" alter b5") != -1): # MySymbol = m21utils.writeHalfDim(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find(" alter #5") != -1): # MySymbol = m21utils.writeSharpFive(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # elif (TheFigure.find("pedal") != -1): # MySymbol = m21utils.writePedal(MyMeasure, c[x].pitches[0].name,c[x].duration,c[x].chordKind) # else: # if (c[x].duration.type != "zero"): # if (c[x].root().name != c[x].bass().name): # # print (c[x].root().name, c[x].bass().name) # MySymbol = ChordSymbol(root=c[x].root(), bass=c[x].bass(), kind=c[x].chordKind) # else: # MySymbol = ChordSymbol(root=c[x].root(), bass=c[x].root(), kind=c[x].chordKind) # MySymbol.duration = c[x].duration # MyMeasure.append(MySymbol) # # print("Wrote chord " + str(MySymbol.figure) + "...") # n3 = Note(MySymbol.third) # n3.duration = Duration(c[x].duration.quarterLength * 0.50) # # n3.lyric = '3rd' # n3.octave = 5 # MyMeasure.append(n3) # if (MySymbol.containsSeventh()): # n7 = m21.note.Note(MySymbol.seventh) # n7.duration = Duration(c[x].duration.quarterLength * 0.50) # # n7.lyric = '7th' # n7.octave = 5 # MyMeasure.append(n7) # else: # n5 = m21.note.Note(MySymbol.root()) # n5.duration = Duration(c[x].duration.quarterLength * 0.50) # # n5.lyric = 'R' # n5.octave = 5 # MyMeasure.append(n5) # if ((m.number)%4 == 0): # sl = m21.layout.SystemLayout(isNew=True) # MyMeasure.append(sl) # MyScore.append(MyMeasure) # Set metadata title = tune + ' - Guide Tone Study' score.metadata = m21.metadata.Metadata() score.metadata.title = title score.metadata.movementName = ' ' # For some reason this works, None and '' don't... score.metadata.composer = 'Greg Pascale' return score
def generate(tune, clef=m21.clef.TrebleClef()): score = m21utils.loadScoreForTune(tune) # print 'score', score s = score.parts[0].getElementsByClass("Measure") m21.harmony.realizeChordSymbolDurations(s) ## Needed to make this work! MyScore = m21.stream.Score() MyScore.append(s[0].keySignature) ## get key from document MyScore.append(clef) #add clef for m in s: MyMeasure = Measure() ## Make a measure and put everything inside it MyMeasure.number = m.number ## give the measure a number MyMeasure.rightBarline = m.rightBarline MyMeasure.leftBarline = m.leftBarline # print("_____________________") # print("In measure "+ str(m.number) + "(" + str(m.id) + ")" +" of " + str(len(s)) ) #debug monitoring c = m.getElementsByClass(ChordSymbol) for x in range(len(c)): # print(c[x].duration) # print(c[x].beat) # print (c[x].figure) # print("--------------------") TheFigure = c[x].figure MyChord = Chord(c[x].pitches) MySymbol = ChordSymbol() ######## Fix XML chord symbols ############ if (TheFigure.find(" alter b9") != -1): MySymbol = m21utils.writeFlatNine(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" add b9") != -1): MySymbol = m21utils.writeFlatNine(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" add #9") != -1): MySymbol = m21utils.writeSharpNine(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" add #7") != -1): MySymbol = m21utils.writeSharpSeven(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" add #11") != -1): MySymbol = m21utils.writeSharpEleven(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" add b13") != -1): MySymbol = m21utils.writeFlatThirteen(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" add b6") != -1): MySymbol = m21utils.writeFlatSix(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" alter b5") != -1): MySymbol = m21utils.writeHalfDim(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find(" alter #5") != -1): MySymbol = m21utils.writeSharpFive(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) elif (TheFigure.find("pedal") != -1): MySymbol = m21utils.writePedal(MyMeasure, c[x].pitches[0].name, c[x].duration, c[x].chordKind) else: if (c[x].duration.type != "zero"): if (c[x].root().name != c[x].bass().name): # print (c[x].root().name, c[x].bass().name) MySymbol = ChordSymbol(root=c[x].root(), bass=c[x].bass(), kind=c[x].chordKind) else: MySymbol = ChordSymbol(root=c[x].root(), bass=c[x].root(), kind=c[x].chordKind) MySymbol.duration = c[x].duration MyMeasure.append(MySymbol) # print("Wrote chord " + str(MySymbol.figure) + "...") n3 = Note(MySymbol.third) n3.duration = Duration(c[x].duration.quarterLength * 0.50) # n3.lyric = '3rd' n3.octave = 5 MyMeasure.append(n3) if (MySymbol.containsSeventh()): n7 = m21.note.Note(MySymbol.seventh) n7.duration = Duration(c[x].duration.quarterLength * 0.50) # n7.lyric = '7th' n7.octave = 5 MyMeasure.append(n7) else: n5 = m21.note.Note(MySymbol.root()) n5.duration = Duration(c[x].duration.quarterLength * 0.50) # n5.lyric = 'R' n5.octave = 5 MyMeasure.append(n5) if ((m.number) % 4 == 0): sl = m21.layout.SystemLayout(isNew=True) MyMeasure.append(sl) MyScore.append(MyMeasure) # Set metadata title = tune + ' - Guide Tone Study' MyScore.metadata = m21.metadata.Metadata() MyScore.metadata.title = title MyScore.metadata.movementName = ' ' # For some reason this works, None and '' don't... MyScore.metadata.composer = 'Greg Pascale' return MyScore