(motif2, names) = genMotif(prev_note = motif1.pits[-1], harm = harm[1], names=names, name = 'motif')
    if fitsBasicIdeaPref([motif1, motif2]):
        new_sub_chunks = OrderedDict()
        new_sub_chunks[motif1.name] = motif1
        new_sub_chunks[motif2.name] = motif2
        return (Chunk(sub_chunks=new_sub_chunks, name=getName(names, name)), names)
    else:
        return genBasicIdea(prev_note, harm, names, name)

prev_note = 0
new_bis = OrderedDict()
names = {}
for i in range(0, 40):
    new_bi, names = genBasicIdea(prev_note = prev_note, names=names,  name = 'bi')
    if abs(prev_note - new_bi.pits[0]) > 2:
        print('error - too much spread')
        new_bi, names = genBasicIdea(prev_note = prev_note, names=names,  name = 'bi')
    prev_note = new_bi.pits[-1]
    new_bis[new_bi.name] = new_bi
a = Chunk(sub_chunks=new_bis)
mh.writeChunk([a], 'test3.mid')
"""
prev_note = 0
new_motifs = OrderedDict()
new_motif = genMotif(prev_note)[0]
new_motifs[-1] = new_motif
for i in range(0, 40):
    new_motifs[str(i)] = transformMotif(new_motif, prev_note=prev_note)
a = Chunk(sub_chunks=new_motifs)
mh.writeChunk([a], 'test2.mid')
"""
        next_cell_type = "new"
    if next_cell_type == "new":
        cell2 = gc.getCell(2, cell1.pits[-1], None, second_chord, [])
    else:
        cell2 = transformChunk(cell1, cell1.pits[-1], [second_chord])
    return Chunk([cell1, cell2])


def writeChunk(chunk, fname):
    f = open("/Users/halley/Desktop/" + fname, "w+")
    for cell in chunk.cells:
        f.write(str(cell.pits) + "-" + str(cell.durs) + "\n")
    f.close()


"""
prev_note = 0
hphrases = []
for i in range(0,20):
    hphrases.append(genHPhrase(prev_note))
    hphrases.append(transformChunk(hphrases[-1], hphrases[-1].pits[-1], [[0,2,4],[4,6,8],[0,2,4],[4,6,8]]))
    prev_note = hphrases[-1].pits[-1]

chunk = Chunk(hphrases)
mh.writeChunk(chunk, 'test.xml')"""

periods = []
for i in range(0, 10):
    doublePeriod = genDoublePeriod()
    periods.append(doublePeriod)
mh.writeChunk([Chunk(periods)], "periods.xml")