def createChordGraph(flatStream): chords = flatStream.getElementsByClass(chord.Chord) k = flatStream.analyze('key') scaleNotes = k.chord._notes # k.correlationCoefficient listOfChords = [] for i in chords: listOfChords.append(i) for singleChord in listOfChords: listOfRankings = [] listOfRankingsFloat = [] for chordFunction in toneChords: matchingNotes = objects.rational() for tempPitch in singleChord.pitchNames: for scaleDegree in chordFunction: if tempPitch == scaleNotes[scaleDegree].name: if matchingNotes.denominator == -1: matchingNotes.denominator = 1 matchingNotes.numerator += 1 else: matchingNotes.denominator += 1 matchingNotes.numerator += 1 else: matchingNotes.denominator += 1 listOfRankings.append(matchingNotes) for e in listOfRankings: listOfRankingsFloat.append(e.getFloat()) if listOfRankingsFloat.index(max(listOfRankingsFloat)) not in chordDegree: chordDegree[listOfRankingsFloat.index(max(listOfRankingsFloat))] = [] chordDegree[listOfRankingsFloat.index(max(listOfRankingsFloat))].append(singleChord) else: chordDegree[listOfRankingsFloat.index(max(listOfRankingsFloat))].append(singleChord) adjacencyMatrix = [[0 for x in range(len(toneChords))] for x in range(len(toneChords))] for i in range(len(adjacencyMatrix)): for j in range(len(adjacencyMatrix)): adjacencyMatrix[i][j] = objects.rational() return chords
def createRhythmGraph(flatStream): measureNumbers = [] # old stuff # dictOfTime = musicAttributes.getTimeSignatures(flatStream) # dictOfRhythmicDissonances = measureRhythmicDissonance(flatStream, dictOfTime) dictOfRhythmicDissonances = getRhythmicDissonances(flatStream) for i in dictOfRhythmicDissonances: measureNumbers.append(i) measureNumbers.sort() # # first pass create states # for i in measureNumbers: # if dictOfRhythmicDissonances[i] not in states: # states.append(dictOfRhythmicDissonances[i]) states = getRhythmicStates(flatStream) # second pass create edges # adjacency matrix[exit node][enter node] adjacencyMatrix = [[0 for x in range(len(states)+1)] for x in range(len(states)+1)] for i in range(len(adjacencyMatrix)): for j in range(len(adjacencyMatrix)): adjacencyMatrix[i][j] = objects.rational() # should make a square adjacency matrix for i in measureNumbers: if i > 1: try: previousState = dictOfRhythmicDissonances[i-1] currentState = dictOfRhythmicDissonances[i] if adjacencyMatrix[states.index(previousState)][states.index(currentState)].denominator == -1: adjacencyMatrix[states.index(previousState)][states.index(currentState)].numerator += 1 for column in adjacencyMatrix[states.index(previousState)]: column.denominator = 1 else: adjacencyMatrix[states.index(previousState)][states.index(currentState)].numerator += 1 for column in adjacencyMatrix[states.index(previousState)]: column.denominator += 1 except KeyError: print 'damn a key error f**k it' # for row in adjacencyMatrix: # for column in row: # print str(column.numerator) + '/' + str(column.denominator) # print "-----------------------------------------" return adjacencyMatrix
def createNoteGraph(flatStream): listOfNotes = flatStream.getElementsByClass(note.Note) listofMyNotes = [] noteStates = [] # for noteElement in listOfNotes: # listofMyNotes.append(objects.myNote(noteElement, flatStream)) for noteElement in listOfNotes: listofMyNotes.append(noteElement.nameWithOctave) # create note states # for myNote in listofMyNotes: # if myNote not in noteStates: # noteStates.append(myNote) for noteElement in listOfNotes: if noteElement.nameWithOctave not in noteStates: noteStates.append(noteElement.nameWithOctave) # secind pass create adjacency matrix adjacencyMatrix = [[0 for x in range(len(noteStates))] for x in range(len(noteStates))] # make those adjacency matrix cells rationals for i in range(len(adjacencyMatrix)): for j in range(len(adjacencyMatrix)): adjacencyMatrix[i][j] = objects.rational() # create reationals for i in range(1, len(listofMyNotes)): previousState = listofMyNotes[i-1] currentState = listofMyNotes[i] if adjacencyMatrix[noteStates.index(previousState)][noteStates.index(currentState)].denominator == -1: adjacencyMatrix[noteStates.index(previousState)][noteStates.index(currentState)].numerator += 1 for column in adjacencyMatrix[noteStates.index(previousState)]: column.denominator = 1 else: adjacencyMatrix[noteStates.index(previousState)][noteStates.index(currentState)].numerator += 1 for column in adjacencyMatrix[noteStates.index(previousState)]: column.denominator += 1 return adjacencyMatrix, noteStates