Esempio n. 1
0
def paginate_sound():
    global sound_pages, sound_page_idx
    print 'start paginate'

    curseg = getseg()
    if curseg:
        print 'curseg', curseg.start, curseg.idx

    sound_pages = []
    sound_page_idx = 0

    if SOUND_ORDERINGS[sound_order_idx] == 'time':
        print 'order by time'
        segs = tape.getSegments()
        segs.sort(cmp=lambda x, y: int(44100 * (x.start - y.start)))
        npages = 10
        npp = len(segs) / npages

        for i in range(npages):
            psegs = segs[i * npp:(i + 1) * npp]
            sound_pages.append(psegs)
            if curseg and curseg in psegs:
                print 'curseg in timepage', i
                sound_page_idx = i
    elif SOUND_ORDERINGS[sound_order_idx] == 'cluster':
        clusters = tape.getClusters()
        for idx, (k, v) in enumerate(sorted(clusters.items())):
            sound_pages.append(v)
            if curseg and curseg in v:
                print 'curseg in cluster', idx
                sound_page_idx = idx
    elif SOUND_ORDERINGS[sound_order_idx] == 'similarity':
        similarity_tape = Tape(tape.path, nbins=9)
        base = curseg
        nsegs = min(len(similarity_tape.getSegments()), 100)
        page = []
        sound_pages.append(page)

        while len(page) < nsegs:
            cluster, idx = similarity_tape.getClosestUnused(base)
            base = similarity_tape.getClusters()[cluster][idx]
            similarity_tape.use(base)
            page.append(base)

    else:
        # closeness
        base = curseg
        page = []
        ordered = tape.orderBySegment(base)
        sound_pages.append(ordered[:100])

    print 'done paginate'
Esempio n. 2
0
def paginate_sound():
    global sound_pages, sound_page_idx
    print 'start paginate'

    curseg = getseg()
    if curseg:
        print 'curseg', curseg.start, curseg.idx

    sound_pages = []
    sound_page_idx = 0

    if SOUND_ORDERINGS[sound_order_idx] == 'time':
        print 'order by time'
        segs = tape.getSegments()
        segs.sort(cmp=lambda x,y: int(44100*(x.start-y.start)))
        npages = 10
        npp = len(segs) / npages

        for i in range(npages):
            psegs = segs[i*npp:(i+1)*npp]
            sound_pages.append(psegs)
            if curseg and curseg in psegs:
                print 'curseg in timepage', i
                sound_page_idx = i
    elif SOUND_ORDERINGS[sound_order_idx] == 'cluster':
        clusters = tape.getClusters()
        for idx,(k,v) in enumerate(sorted(clusters.items())):
            sound_pages.append(v)
            if curseg and curseg in v:
                print 'curseg in cluster', idx
                sound_page_idx = idx
    elif SOUND_ORDERINGS[sound_order_idx] == 'similarity':
        similarity_tape = Tape(tape.path, nbins=9)
        base = curseg
        nsegs = min(len(similarity_tape.getSegments()), 100)
        page = []
        sound_pages.append(page)

        while len(page) < nsegs:
            cluster,idx = similarity_tape.getClosestUnused(base)
            base = similarity_tape.getClusters()[cluster][idx]
            similarity_tape.use(base)
            page.append(base)

    else:
        # closeness
        base = curseg
        page = []
        ordered = tape.orderBySegment(base)
        sound_pages.append(ordered[:100])

    print 'done paginate'
Esempio n. 3
0
    import os

    import numm

    USAGE = 'python bsides.py SOURCE [COMPOSITION]'

    if len(sys.argv) < 2:
        print USAGE
        sys.exit(1)

    source = sys.argv[1]
    comppath = source + '.composition.pkl'
    if len(sys.argv) > 2:
        comppath = sys.argv[2]

    tape = Tape(source, nbins=9)
    # preload array
    tape.getArray()

    composition = Composition([])
    if os.path.exists(comppath):
        composition = Composition.fromfile(comppath)
        for r in composition.rhythms:
            for g in r.groups:
                for s in g:
                    tape.use(s)

    structure_init()

    numm.run(**globals())
Esempio n. 4
0
        percent = t / duration
        x = int(w / 2 + r * np.cos(2 * np.pi * percent))
        y = int(h / 2 + r * np.sin(2 * np.pi * percent))

        cv2.circle(a, (x, y), 5, (255, 0, 0))


def keyboard_in(type, button):
    global arr, arrangement

    cid = button.upper()
    if type == 'key-press' and len(cid) == 1:
        circle.setNSegs(cid, circle.getNSegs(cid) + 1)

    arrangement = circle.getArrangement(tape)
    arr = arrangement.getSequence().getArray()

    print circle.clusters, arr.shape


if __name__ == '__main__':
    import sys
    import numm

    SRC = sys.argv[1]

    tape = Tape(SRC)
    circle = Circle({})

    numm.run(**globals())
Esempio n. 5
0
    stepx = 320 / N
    stepy = 240 / N
    r = int(min(stepx, stepy)/2)
    for i in range(len(segs)):
        row = int(i / N)
        col = i % N

        color = (255,255,255)
        stroke = 1
        if i == cur_idx:
            color = (0,255,0)
            stroke = -1
        elif tape.isUsed(segs[i]):
            color = (255, 0, 0)

        x,y = (col*stepx + r, row*stepy + r)
        cv2.circle(a, (x,y), r, color, stroke)
        cv2.putText(a, str(i), (x,y), cv2.FONT_HERSHEY_PLAIN, 1, (255,255,255))

    cv2.putText(a, cur_cluster, (305,230), cv2.FONT_HERSHEY_PLAIN, 1, (0,255,0))

if __name__=='__main__':
    import sys
    import numm

    tape = Tape(sys.argv[1])
    arr = tape.getArray()
    clusters = tape.getClusters()

    numm.run(**globals())
Esempio n. 6
0
    import os

    import numm

    USAGE = 'python bsides.py SOURCE [COMPOSITION]'

    if len(sys.argv) < 2:
        print USAGE
        sys.exit(1)

    source = sys.argv[1]
    comppath = source + '.composition.pkl'
    if len(sys.argv) > 2:
        comppath = sys.argv[2]

    tape = Tape(source, nbins=9)
    # preload array
    tape.getArray()

    composition = Composition([])
    if os.path.exists(comppath):
        composition = Composition.fromfile(comppath)
        for r in composition.rhythms:
            for g in r.groups:
                for s in g:
                    tape.use(s)

    structure_init()

    numm.run(**globals())