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 transformChunk(chunk, prev_note, chords):
    # get list of transform functions
    appropriate_function_list = ["identity", "partialTranspose", "retrograde", "partialRetrograde", "subRhythm"]
    functions_list = dict(
        [(o[0], o[1]) for o in getmembers(tfs) if isfunction(o[1])]
    )  # list of all possible transform functions
    functions_list = dict(filter(lambda i: i[0] in appropriate_function_list, functions_list.items()))
    functions_names = functions_list.keys()
    random.shuffle(functions_names)
    have_chunk = False  # haven't created new cell yet
    i = 0
    while not have_chunk and i < len(appropriate_function_list):  # loop until appropriate cell is found
        if chunk.depth == 2:
            print(functions_names[i])
        if chunk.depth <= 1:
            new_variations = functions_list[functions_names[i]](chunk, chords, prev_note)
        elif chunk.depth == 2:
            new_variations = thp.mapToHPhrase(functions_list[functions_names[i]], chunk, chords, prev_note)
        random.shuffle(new_variations)
        for variation in new_variations:
            if pref.fitsPref(variation, prev_note, chords):
                return variation
        i += 1
    if chunk.depth == 0:
        return gc.getCell(2, prev_note, None, chords[0], chunk.durs, chunk.ctype)
    elif chunk.depth == 1:
        cell1 = gc.getCell(2, prev_note, None, chords[0], chunk.sub_chunks[0].durs, chunk.sub_chunks[0].ctype)
        cell2 = transformChunk(cell1, cell1.pits[-1], [chords[1]])
        return Chunk([cell1, cell2])
    else:
        print("sucker")
        motif1 = genMotif(prev_note, chords[0:2])
        motif2 = transformChunk(motif1, motif1.pits[-1], chords[2:])
        return Chunk([motif1, motif2])