def genChordalCell(length, prev_note = 0, first_note = None, cord = [], durs = [], key = 0): pitches = [] def strToNum(string): return [int(i) for i in string.split()] if cord == []: cord = strToNum(ph.probDictToChoice({'0 2 4':0.5, '4 6 8':0.3, '3 5 7':0.2})) if durs == []: durs = rhy.randomDuration(length) if first_note != None: pitches = [first_note] elif prev_note % 7 == 6 and cord == [0,2,4]: pitches = [prev_note + 1] elif prev_note % 7 == 3 and cord == [0,2,4]: pitches = [prev_note - 1] else: pitches = [sc.closestNoteDegreeInChord(prev_note, cord, 1, False)] for i in range(1, len(durs)): pitches.append(randomChordNote(pitches[-1], cord, durs[i] == 0.25)) return Chunk(pits=pitches, durs=durs, chord=cord, key = key)
def genUsualCell(length, prev_note = 0, first_note = None, cord = [], durs = [], key=0): pitches = [] def strToNum(string): return [int(i) for i in string.split()] if cord == []: cord = strToNum(ph.probDictToChoice({'0 2 4':0.5, '4 6 8':0.3, '3 5 7':0.2})) if durs == []: durs = rhy.randomDuration(length) if first_note != None: pitches = [first_note] elif prev_note % 7 == 6 and cord == [0,2,4]: pitches = [prev_note + 1] elif prev_note % 7 == 3 and cord == [0,2,4]: pitches = [prev_note - 1] else: pitches = [sc.closestNoteDegreeInChord(prev_note, cord, 1, False)] if durs[0] < 0: pitches.append(sc.closestNoteDegreeInChord(prev_note, cord, 1, False)) i_continue = 2 else: i_continue = 1 tot_durs = [sum(durs[:i]) for i in range(0, len(durs))] for i in range(i_continue, len(durs)): if tot_durs[i] % 1.0 == 0: if prev_note not in cord: pitches.append(sc.closestNoteDegreeInChord(prev_note, cord, True)) else: pitches.append(randomChordNote(prev_note, cord)) elif random.uniform(0,1) < 0.5: if prev_note not in cord: pitches.append(sc.closestNoteDegreeInChord(prev_note, cord, True)) else: pitches.append(randomChordNote(prev_note, cord)) else: pitches.append(randomNextDegree(prev_note, 1)) prev_note = pitches[-1] return_val = Chunk(pitches, durs, chord=cord, key=key) if pref.goodCell(return_val) or random.uniform(0,1) < 0.05: return return_val else: return genUsualCell(length, prev_note, first_note, cord, durs)
def genScalewiseCell(length, prev_note = 0, first_note = None, chord = [], durs = [], key = 0): if durs == []: rhythm = rhy.randomDuration(length) else: rhythm = durs direction = 1 if first_note != None: pitches = [first_note] elif prev_note % 7 == 6 and chord == [0,2,4]: pitches = [prev_note + 1] elif prev_note % 7 == 3 and chord == [0,2,4]: pitches = [prev_note - 1] else: if chord == []: pitches = [prev_note + random.choice([1,-1])] else: pitches = [sc.closestNoteDegreeInChord(prev_note, chord, True, 0)] if rhythm[0] < 0: pitches.append(sc.closestNoteDegreeInChord(prev_note, chord, True, 0)) i_continue = 2 else: i_continue = 1 for i in range(i_continue, len(rhythm)): if pitches[-1] % 7 == 6 and chord == [0,2,4]: pitches.append(pitches[-1] + 1) elif pitches[-1] % 7 == 3 and chord == [0,2,4]: pitches.append(pitches[-1] - 1) else: direction = direction if random.uniform(0,1) < 0.7 else direction * -1 if pitches[i - 1] > 14: direction = -1 elif pitches[i - 1] < 0: direction = 1 pitches.append(pitches[i - 1] + direction) return_val = Chunk(pits=pitches, durs=rhythm, chord=chord, key=key) if pref.goodCell(return_val) or random.uniform(0,1) < 0.05: return return_val else: return genScalewiseCell(length, prev_note, first_note, chord, durs)