def searchCounter(mode, note, cantus, depth, plagal, lastNode=None): # print('starting serch counter '+str(note)) # print(depth) print('\n start search ' + str(depth)) print('sequence ' + str(note)) if depth == 0: # print('generating counter '+str(note)) newNode = Node(note) else: # print('constructing child '+str(note) + ' from :'+str(lastNode.note)) newNode = Node(note, lastNode) if not newNode.isValid(True, mode): print('---invalid melody ' + str(newNode.sequence)) # print(str(note)+' invalid melody') return else: print('---valid melody') print(newNode.sequence) if not newNode.validateVoice1(cantus): # print(str(note)+' invalid counter') print('---invalid counter') return False else: print('---valid counterpoint') if depth + 1 == maxDepth: counterP.append(newNode) return shift = 4 if plagal else 0 # print('generating children') if depth == 0: print('mode is ' + str(Note(mode).name)) searchCounter(mode, mode - 1, cantus, 1, plagal, newNode) return if depth + 2 == maxDepth: searchCounter(mode, mode, cantus, depth + 1, plagal, newNode) searchCounter(mode, mode + 4, cantus, depth + 1, plagal, newNode) return for i in range(mode - shift, mode + 7 - shift): interval = i - cantus[depth + 1] print('index' + str(i)) print('step ' + str(depth)) print('cantus ' + str(cantus[depth])) print('diatonic interval' + str(Note.diatonic(interval))) interval = Note.diatonic(interval) % 12 if interval == 1: continue if interval == 2: continue if interval == 5: continue if interval == 6: continue if interval == 10: continue if interval == 11: continue searchCounter(mode, i, cantus, depth + 1, plagal, newNode)