Esempio n. 1
0
def main():
    initOSCClient()
    
    gens = [SinOsc(None), SawOsc(None)]
    # sinA = SinOsc(None)
    # sawA = SawOsc(None)
    
    for gen in gens:
        if gen.is_root:
            Patch.dfs_patch_search(gen)
    Patch.osc_send_all_patches()
    
    while (True):
        for gen in gens:
            gen.attrs['gain'] = random()
        Patch.osc_update_all_attrs()
        time.sleep(0.5)
Esempio n. 2
0
def start():
    # init camera
    cam = cv2.VideoCapture(1)
    
    # init osc communication with chuck
    initOSCClient()

    cam_thread = CameraOutThread(cam)
    cam_thread.start()
    
    time.sleep(0.5)
    raw_input("Press Enter when camera is positioned")
    
    # display numbers on regions
    image = cam.read()
    regions = Region.find_regions_by_border_color(image[1])
    for region in regions:
        cam_thread.add_text(TextOutput(str(region.id), (region.centroid_x, region.centroid_y)))
    
    # ask for Gen type for each region
    dac = DAC()
    gen_maps = {}
    for i, region in enumerate(regions):
        while (True):
            try:
                gen_type = raw_input("Please enter UGen type for region %s: " % region.id)
                gen = eval(gen_type)()
                attr_range = [0.0, 1.0]
                if isinstance(gen, Osc):
                    attr_range[0] = float(raw_input("    What is the low frequency on this oscillator? "))
                    attr_range[1] = float(raw_input("    What is the high frequency on this oscillator? "))
                    
                gen_maps[region.id] = GenMap(gen, region, attr_range=attr_range)
                break
            except:
                print 'Invalid UGen, try again.'

    # ask for gen links 
    # dac special to_where
    while (raw_input("Add a patch? (y/n): ") == 'y'):
        from_where = None
        while (True):
            try:
                # NOTE: no range checking
                from_where = int(raw_input('from Region #: '))
                from_where = gen_maps[from_where]
                break
            except ValueError:
                print 'Please enter an integer.'
                
        to_where = None
        while (True):
            try:
                to_where = raw_input('to Region #: ')
                if to_where == 'dac':
                    to_where = dac
                    break
                to_where = int(to_where)
                to_where = gen_maps[to_where]
                break
            except ValueError:
                print 'Please enter an integer.'
        
        # will handle dac later
        # for now, all patch paths assumed end in dac
        if not isinstance(to_where, DAC):
            (from_where.gen).add_patch_to(to_where.gen)
    
    Patch.find_patches([gen_maps[gm_id].gen for gm_id in gen_maps])
    Patch.osc_send_all_patches()
    
    cam_thread.text_outputs = []
    cam_thread.gen_maps = gen_maps