def transformCell(cell, harm, prev_note = None): if prev_note == None: prev_note = cell.pits[-1] transformed_already = [] for function in appropriate_function_list: new_cells = functions_list[function](cell, prev_note) random.shuffle(new_cells) transformed_already.append(new_cells[0]) """for new_cell in new_cells: for harmony in harm: if hm.chunkInChord(new_cell, harmony) and pref.fitsPref(new_cell, prev_note, harmony): return new_cell""" #now try transforming already transformed cells for transformed_once in transformed_already: for function in appropriate_function_list: new_cells = functions_list[function](transformed_once, prev_note) random.shuffle(new_cells) for new_cell in new_cells: for harmony in harm: if hm.chunkInChord(new_cell, harmony) and pref.fitsPref(new_cell, prev_note,harmony): if random.uniform(0,1) < 0.8: return random.choice(tfs.subRhythm(new_cell, prev_note, harmony, how_many=1)) else: return new_cell return gc.getCell(2, prev_note, first_note = None, chord = harm[0], durs = cell.durs)
def transposeToChord(chunk, prev_note = 0, chord = [], names = {}): if chunk.depth == 0: #get closest above with chord distance = hm.getClosestAbove(chunk.pits[0], chord) - chunk.pits[0] new_pits = [i + distance for i in chunk.pits] chunk_above = Chunk(sub_chunks=None, pits=new_pits, durs=chunk.durs, ctype=chunk.ctype) distance = chunk.pits[0] - hm.getClosestBelow(chunk.pits[0], chord) new_pits = [i - distance for i in chunk.pits] chunk_below = Chunk(sub_chunks=None, pits=new_pits, durs=chunk.durs, ctype=chunk.ctype) new_chunks = [chunk_below, chunk_above] if hm.chunkInChord(chunk, chord): new_chunks.append(chunk) return new_chunks elif chunk.depth == 1: return [Chunk] else: return [chunk]
def transformCell(transformed_cell, prev_cell = gc.genBlankCell(2.0), chord_choices = [[0,2,4],[4,6,8]], best_chord = [0,2,4]): transform_cell_function_names = ['transpose', 'retrograde', 'toDouble', 'fromDouble', 'switchBeats'] random.shuffle(transform_cell_function_names) transform_cell_function_names = ['addOrnamentation'] + transform_cell_function_names transform_cell_function_names.append('keepRhythm') function_index = -1 while True: function_index += 1 if function_index >= len(transform_cell_function_names): #print('dead') return gc.genCell(length=2.0, chord=best_chord, durs=rhy.alterRhythm(transformed_cell))#(gc.genCell(length=2.0, chord=best_chord, durs=rhy.alterRhythm(transformed_cell), cell_type=transformed_cell.ctype), 'dead') else: #print(transform_cell_function_names[function_index]) attempting_cells = transform_cell_functions[transform_cell_function_names[function_index]](transformed_cell, prev_cell, ct.getFirstNotes(prev_cell, transformed_cell), best_chord) for attempting_cell in attempting_cells: random.shuffle(chord_choices) for chord in chord_choices: if hm.chunkInChord(attempting_cell, chord) and pref.goodCells([prev_cell, attempting_cell]): attempting_cell.chord = chord return attempting_cell#(attempting_cell, transform_cell_function_names[function_index])