def identity(chunk, prev_note = 0, chordal = [], names = {}, name = ''):
    if chordal == []:
        return [chunk]
    else:
        if chunk.depth == 0:
            if chunk.ctype == SCALEWISE:
                a = transposeToChord(chunk, chordal)
                a.setName(name)
                return a
            else:
                above = []
                below = []
                for pit in chunk.pits:
                    above.append(hm.getClosestAbove(pit, chordal))
                    below.append(hm.getClosestBelow(pit, chordal))
                return [Chunk(sub_chunks = None, pits = above, durs = chunk.durs, ctype = chunk.ctype, name = name), Chunk(sub_chunks = None, name=name, pits = below, durs = chunk.durs, ctype=chunk.ctype)]
        elif chunk.depth == 1:
            all_subs = OrderedDict()
            i = 0
            for sub_chunk_name, sub_chunk in chunk.sub_chunks.items():
                new_name = getName(names, sub_chunk_name)
                all_subs[new_name] = (identity(sub_chunk, chordal[i], name=new_name)[random.choice([0,1])])
                i += 1
            return [Chunk(sub_chunks = all_subs, name = name)]
        else:
            new_chunk = copy.deepcopy(chunk)
            new_chunk.setName(name)
            return new_chunk
def identity(chunk, chord = [], prev_note = 0, up_down = random.choice([-1,1])):
    if chords == []:
        return [chunk]
    else:
        if chunk.depth == 0:
            if chunk.ctype == SCALEWISE:
                return [copy.deepcopy(chunk)]
            else:
                above = []
                below = []
                for pit in chunk.pits:
                    above.append(hm.getClosestAbove(pit, chord))
                    below.append(hm.getClosestBelow(pit, chord))
                return [Chunk(sub_chunks=None, pits=above, durs=chunk.durs, ctype = chunk.ctype), Chunk(sub_chunks=None, pits = below, durs = chunk.durs, ctype=chunk.ctype)]
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]