This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Finds looping subsets within a progression of chords, listed as a tuple (lick); outputs loop (as tuple) and # of repetitions within lick | |
def findLoops(lick): | |
lickLen = len(lick) | |
for i in range(1, lickLen - 1): | |
testLoop = lick[0:i] #find loop to test as subset | |
loopLen = len(lick[0:i]) #find test loop length | |
testVal = int(lickLen/loopLen) #find divisor, rounded down | |
testValRem= lickLen%loopLen #find remainder | |
if lick == (testLoop * testVal) + testLoop[0:testValRem]: # if lick = a multiple of the loop (including remainder), then loop is valid loop | |
loop = lick[0:i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_chords(chords, music): | |
"""Search for chords within music (O(n) time). | |
:param list chords: chords to look for, in order | |
:param list music: music to search within | |
""" | |
if len(music) < len(chords): | |
return 0 | |
my_chord_i = -1 | |
occurrences = 0 | |
for my_chord in music: |