Beispiel #1
0
 def gimme_pad_handler(cls, addr, tags, data, source):
     with cls.pool_lock:
         pad_infos = cls.pool.values().pop(0)
         cls.pool.pop(pad_infos['pad_id'])
     logger.info('sending new pad %s, still %s in pool' % (pad_infos['path'], len(cls.pool)))
     send_msg('/new_pad', pad_infos['path'])
     if len(PadScraper.pool) < PadScraper.pool_min_size: PadScraper.wake_up_scrapers()
Beispiel #2
0
def sendToUPS_th(socket_UPS, conn):
    while True:
        # select an AMsg to send
        time.sleep(1)
        with tools.toUPS_lock:
            if (len(tools.toUPS) > 0):
                keys = list(tools.toUPS)
                for key in keys:
                    #for key in tools.toUPS.keys():
                    if key in tools.toUPS:
                        tools.send_msg(socket_UPS, tools.toUPS[key])
Beispiel #3
0
    def gimme_loop_handler(cls, addr, tags, data, source):
        # time in seconds; key between 0 (for C) and 11 (for B)
        pd_looper_id, required_tempo, required_key = data[0], data[1], data[2]
        
        # If the track hasn't been registered yet, we do that
        pd_looper_infos = cls.pd_loopers.setdefault(pd_looper_id, {
            'current_loop_id': None,
            'track_ids': [],
            'tempo': None,
        })
        current_loop_id = pd_looper_infos['current_loop_id']

        # Picking the new loop in the pool
        with cls.pool_lock:

            # prefilter available loops (those whose track haven't been picked already)
            available_loops = cls.pool.values()
            forbidden_tracks = cls.forbidden_tracks(pd_looper_id)
            available_loops = filter(lambda l: l['track_id'] not in forbidden_tracks, available_loops)

            # Select the most suitable next loop according to the current loop.
            if current_loop_id is not None:
                def sort_key(l):
                    timbre_dist = loop_distance(cls.old_loops[current_loop_id], l)
                    tempo_dist = abs(1 - l['tempo'] / float(required_tempo)) * 40
                    return timbre_dist + tempo_dist
                loop_infos = sorted(available_loops, key=lambda l: sort_key)[0]
            else:
                loop_infos = available_loops[0]

            # Remove the loop from the pool, reserving the loop's track for this looper
            cls.pool.pop(loop_infos['loop_id'])
            pd_looper_infos['track_ids'].append(loop_infos['track_id'])
        pd_looper_infos['current_loop_id'] = loop_infos['loop_id']

        # Adding the picked looped to `old_loops`, so that we remember it
        # but it cannot be used again.
        with cls.old_loops_lock:
            cls.old_loops[loop_infos['loop_id']] = loop_infos
            if current_loop_id is not None: cls.old_loops.pop(current_loop_id)

        # Preparing the loop
        logger.info('sending new loop %s to looper %s, left : %s' % (loop_infos['path'], pd_looper_id, len(cls.pool)))
        loop = Sound.from_file(loop_infos['path'])
        required_length = loop.length * float(required_tempo) / loop_infos['tempo']
        beat_length = 60.0 / required_tempo
        required_length = round(required_length / beat_length) * beat_length
        loop = loop.time_stretch(required_length).fade(in_dur=0.002, out_dur=0.002)
        loop.to_file(loop_infos['path'])

        # Sending loop, and fill-up the pool if necessary.
        send_msg('/new_loop', pd_looper_id, loop_infos['path'], int(round(loop.length * 1000)), loop_infos['loop_id'])
        if len(LoopScraper.pool) < LoopScraper.pool_min_size: LoopScraper.wake_up_scrapers()
Beispiel #4
0
def sendToWorld_th(socket_world, conn):
    while True:
        #time.sleep(1)
        #add one purchasemore command to the toWorld if there are orders that is_enough field is false
        with tools.seq_lock:
            APurchasemore = tools.generate_buy(conn)
            if APurchasemore:
                tools.add_toWorld(APurchasemore)
        # select an AMsg to send
        time.sleep(1)
        with tools.toworld_lock:
            if (len(tools.toWorld) > 0):
                keys = list(tools.toWorld)
                for key in keys:
                    #for key in tools.toWorld.keys():
                    if key in tools.toWorld:
                        tools.send_msg(socket_world, tools.toWorld[key])
Beispiel #5
0
 def init_handler(addr, tags, data, source):
     logger.info('*INIT* send init infos to the pd patch')
     send_msg('/init/pwd', settings.icecast_password)
Beispiel #6
0
    osc_server_thread = threading.Thread(target=init_server)
    osc_server_thread.daemon = True
    osc_server_thread.start()

    # starting the pd patch
    logger.info('*INIT* starting pd patch')
    subprocess.Popen(['pd-extended', '-nrt', settings.app_root + 'patch/main.pd'],
        stdout=open(os.devnull, 'w'),
        stderr=sys.stderr)

    # Hack to have a passive "sleep" that can be interrupted with ctrl-c
    # ... with `threading.Timer` it doesn't work.
    from Queue import Queue, Empty

    # Pre-downloading some sounds, and sending a message to the patch
    # when this is done.
    while(len(PadScraper.pool) < PadScraper.pool_min_size
          or len(LoopScraper.pool) < LoopScraper.pool_min_size / 30.0):
        q = Queue()
        try: q.get(True, 2)
        except Empty: pass
    send_msg('/init/ready')
    logger.info('*INIT* telling the patch things are ready')

    #from guppy import hpy; hp=hpy()
    while(True):
        q = Queue()
        try: q.get(True, 30)
        except Empty: pass
        #print hp.heap()