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 testGenerateFirstSpecies(self): ''' A First Species Counterpoint Generator by Jackie Rogoff (MIT 2010) written as part of an UROP (Undergraduate Research Opportunities Program) project at M.I.T. 2007. ''' n101 = Note() n101.duration.type = "quarter" n101.name = "A" aMinor = scale.ConcreteMinorScale(n101) n101b = Note() n101b.duration.type = "quarter" n101b.name = "D" dMinor = scale.ConcreteMinorScale(n101b) counterpoint1 = ModalCounterpoint() (n110, n111, n112, n113) = (Note(), Note(), Note(), Note()) (n114, n115, n116, n117, n118) = (Note(), Note(), Note(), Note(), Note()) (n119, n120, n121, n122, n123) = (Note(), Note(), Note(), Note(), Note()) (n124, n125, n126, n127, n128) = (Note(), Note(), Note(), Note(), Note()) n110.duration.type = "quarter" n111.duration.type = "quarter" n112.duration.type = "quarter" n113.duration.type = "quarter" n114.duration.type = "quarter" n115.duration.type = "quarter" n116.duration.type = "quarter" n117.duration.type = "quarter" n118.duration.type = "quarter" n110.name = "A" n110.octave = 3 n111.name = "C" n111.octave = 4 n112.name = "B" n112.octave = 3 n113.name = "C" n113.octave = 4 n114.name = "D" n115.name = "E" n116.name = "C" n116.octave = 4 n117.name = "B" n117.octave = 3 n118.name = "A" n118.octave = 3 n119.name = "F" n120.name = "E" n121.name = "D" n122.name = "G" n123.name = "F" n124.name = "A" n125.name = "G" n126.name = "F" n127.name = "E" n128.name = "D" cantusFirmus1 = Stream([n110, n111, n112, n113, n114, n115, n116, n117, n118]) cantusFirmus2 = Stream([n110, n115, n114, n119, n120, n113, n121, n116, n117, n118]) cantusFirmus3 = Stream([n114, n119, n115, n121, n122, n123, n124, n125, n126, n127, n128]) choices = [cantusFirmus1, cantusFirmus2, cantusFirmus3, cantusFirmus3, cantusFirmus3, cantusFirmus3] cantusFirmus = random.choice(choices) thisScale = aMinor if cantusFirmus is cantusFirmus3: thisScale = dMinor goodHarmony = False goodMelody = False while (goodHarmony == False or goodMelody == False): try: hopeThisWorks = counterpoint1.generateFirstSpecies(cantusFirmus, thisScale) print [note1.name + str(note1.octave) for note1 in hopeThisWorks.notes] hopeThisWorks2 = counterpoint1.raiseLeadingTone(hopeThisWorks, thisScale) print [note1.name + str(note1.octave) for note1 in hopeThisWorks2.notes]